/wordpress/wp-content/plugins/contact-form-7-to-database-extension/CF7DBPluginExporter.php

https://bitbucket.org/gfelizola/pacaembu-institucional · PHP · 164 lines · 131 code · 10 blank · 23 comment · 9 complexity · b5bc1f2c44673bff7711a3ddb3f2453b MD5 · raw file

  1. <?php
  2. /*
  3. "Contact Form to Database" Copyright (C) 2011-2012 Michael Simpson (email : michael.d.simpson@gmail.com)
  4. This file is part of Contact Form to Database.
  5. Contact Form to Database is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Contact Form to Database is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Contact Form to Database.
  15. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. class CF7DBPluginExporter {
  18. static function doExportFromPost() {
  19. // Consolidate GET and POST parameters. Allow GET to override POST.
  20. $params = array_merge($_POST, $_GET);
  21. //print_r($params);
  22. // Assumes coming from CF7DBPlugin::whatsInTheDBPage()
  23. $key = '3fde789a'; //substr($_COOKIE['PHPSESSID'], - 5); // session_id() doesn't work
  24. if (isset($params['guser'])) {
  25. $params['guser'] = mcrypt_decrypt(MCRYPT_3DES, $key, CF7DBPluginExporter::hexToStr($params['guser']), 'ecb');
  26. }
  27. if (isset($params['gpwd'])) {
  28. $params['gpwd'] = mcrypt_decrypt(MCRYPT_3DES, $key, CF7DBPluginExporter::hexToStr($params['gpwd']), 'ecb');
  29. }
  30. if (!isset($params['enc'])) {
  31. $params['enc'] = 'CSVUTF8';
  32. }
  33. CF7DBPluginExporter::export(
  34. $params['form'],
  35. $params['enc'],
  36. $params);
  37. }
  38. // Taken from http://ditio.net/2008/11/04/php-string-to-hex-and-hex-to-string-functions/
  39. static function hexToStr($hex) {
  40. $string = '';
  41. for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
  42. $string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
  43. }
  44. return $string;
  45. }
  46. static function export($formName, $encoding, $options) {
  47. switch ($encoding) {
  48. case 'HTML':
  49. require_once('ExportToHtmlTable.php');
  50. $exporter = new ExportToHtmlTable();
  51. $exporter->export($formName, $options);
  52. break;
  53. case 'HTMLBOM': // IQY callback
  54. require_once('ExportToHtmlTable.php');
  55. $exporter = new ExportToHtmlTable();
  56. $exporter->setUseBom(true);
  57. $exporter->export($formName, $options);
  58. break;
  59. case 'DT':
  60. require_once('ExportToHtmlTable.php');
  61. if (!is_array($options)) {
  62. $options = array();
  63. }
  64. $options['useDT'] = true;
  65. if (!isset($options['printScripts'])) {
  66. $options['printScripts'] = true;
  67. }
  68. if (!isset($options['printStyles'])) {
  69. $options['printStyles'] = 'true';
  70. }
  71. $exporter = new ExportToHtmlTable();
  72. $exporter->export($formName, $options);
  73. break;
  74. case 'HTMLTemplate':
  75. require_once('ExportToHtmlTemplate.php');
  76. $exporter = new ExportToHtmlTemplate();
  77. $exporter->export($formName, $options);
  78. break;
  79. case 'IQY':
  80. require_once('ExportToIqy.php');
  81. $exporter = new ExportToIqy();
  82. $exporter->export($formName, $options);
  83. break;
  84. case 'CSVUTF8BOM':
  85. $options['unbuffered'] = 'true';
  86. require_once('ExportToCsvUtf8.php');
  87. $exporter = new ExportToCsvUtf8();
  88. $exporter->setUseBom(true);
  89. $exporter->export($formName, $options);
  90. break;
  91. case 'TSVUTF16LEBOM':
  92. $options['unbuffered'] = 'true';
  93. require_once('ExportToCsvUtf16le.php');
  94. $exporter = new ExportToCsvUtf16le();
  95. $exporter->export($formName, $options);
  96. break;
  97. case 'GLD':
  98. require_once('ExportToGoogleLiveData.php');
  99. $exporter = new ExportToGoogleLiveData();
  100. $exporter->export($formName, $options);
  101. break;
  102. case 'GSS':
  103. $options['unbuffered'] = 'true';
  104. require_once('ExportToGoogleSS.php');
  105. $exporter = new ExportToGoogleSS();
  106. $exporter->export($formName, $options);
  107. break;
  108. case 'JSON':
  109. require_once('ExportToJson.php');
  110. $exporter = new ExportToJson();
  111. $exporter->export($formName, $options);
  112. break;
  113. case 'VALUE':
  114. require_once('ExportToValue.php');
  115. $exporter = new ExportToValue();
  116. $exporter->export($formName, $options);
  117. break;
  118. case 'COUNT':
  119. require_once('ExportToValue.php');
  120. if (!is_array($options)) {
  121. $options = array();
  122. }
  123. $options['function'] = 'count';
  124. unset($options['show']);
  125. unset($options['hide']);
  126. $exporter = new ExportToValue();
  127. $exporter->export($formName, $options);
  128. break;
  129. case 'CSVSJIS':
  130. require_once('ExportToCsvUtf8.php');
  131. $exporter = new ExportToCsvUtf8();
  132. $exporter->setUseBom(false);
  133. $exporter->setUseShiftJIS(true);
  134. $exporter->export($formName, $options);
  135. break;
  136. case 'RSS':
  137. require_once('ExportToRSS.php');
  138. $exporter = new ExportToRSS();
  139. $exporter->export($formName, $options);
  140. break;
  141. case 'CSVUTF8':
  142. default:
  143. require_once('ExportToCsvUtf8.php');
  144. $exporter = new ExportToCsvUtf8();
  145. $exporter->setUseBom(false);
  146. $exporter->export($formName, $options);
  147. break;
  148. }
  149. }
  150. }