PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/anonymous_data.php

http://get-simple-cms.googlecode.com/
PHP | 199 lines | 166 code | 20 blank | 13 comment | 21 complexity | b44702740a1f2e4acf9a1f1f770e6a70 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: Send Anonymous Data
  4. Description: GetSimple needs your anonymous data so we can understand our users better
  5. Version: 1.0
  6. Author: Chris Cagle
  7. Author URI: http://get-simple.info/
  8. */
  9. # get correct id for plugin
  10. $thisfile_anony=basename(__FILE__, ".php");
  11. # add in this plugin's language file
  12. i18n_merge($thisfile_anony) || i18n_merge($thisfile_anony, 'en_US');
  13. # register plugin
  14. register_plugin(
  15. $thisfile_anony,
  16. i18n_r($thisfile_anony.'/ANONY_TITLE'),
  17. '1.0',
  18. 'Chris Cagle',
  19. 'http://get-simple.info/',
  20. i18n_r($thisfile_anony.'/ANONY_DESC'),
  21. 'plugin',
  22. 'gs_anonymousdata'
  23. );
  24. # activate hooks
  25. add_action('plugins-sidebar','createSideMenu',array($thisfile_anony,i18n_r($thisfile_anony.'/ANONY_TITLE')));
  26. if ( ! function_exists('get_tld_from_url')){
  27. function get_tld_from_url( $url ){
  28. $tld = null;
  29. $url_parts = parse_url( (string) $url );
  30. if( is_array( $url_parts ) && isset( $url_parts[ 'host' ] ) ) {
  31. $host_parts = explode( '.', $url_parts[ 'host' ] );
  32. if( is_array( $host_parts ) && count( $host_parts ) > 0 ) {
  33. $tld = array_pop( $host_parts );
  34. }
  35. }
  36. return $tld;
  37. }
  38. }
  39. if ( ! function_exists('glob_recursive')){
  40. function glob_recursive($pattern, $flags = 0) {
  41. $files = glob($pattern, $flags);
  42. foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
  43. $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
  44. }
  45. return $files;
  46. }
  47. }
  48. function gs_anonymousdata() {
  49. #grab data from this installation
  50. if(isset($_POST['preview'])) {
  51. global $LANG, $TIMEZONE, $SITEURL, $live_plugins, $thisfile_anony;
  52. $php_modules = get_loaded_extensions();
  53. if (! in_arrayi('curl', $php_modules) ) {
  54. $missing_modules[] = 'curl';
  55. $email_not_curl = true;
  56. } else {
  57. $email_not_curl = false;
  58. }
  59. if (! in_arrayi('gd', $php_modules) ) {
  60. $missing_modules[] = 'GD';
  61. }
  62. if (! in_arrayi('zip', $php_modules) ) {
  63. $missing_modules[] = 'ZipArchive';
  64. }
  65. if (! in_arrayi('SimpleXML', $php_modules) ) {
  66. $missing_modules[] = 'SimpleXML';
  67. }
  68. if ( function_exists('apache_get_modules') ) {
  69. if(! in_arrayi('mod_rewrite',apache_get_modules())) {
  70. $missing_modules[] = 'mod_rewrite';
  71. }
  72. }
  73. $preview_data = @new SimpleXMLExtended('<data></data>');
  74. $preview_data->addChild('submission_date', date('c'));
  75. $preview_data->addChild('getsimple_version', get_site_version(false));
  76. $preview_data->addChild('language', $LANG);
  77. $preview_data->addChild('timezone', $TIMEZONE);
  78. $preview_data->addChild('php_version', PHP_VERSION);
  79. $preview_data->addChild('server_type', PHP_OS);
  80. $preview_data->addChild('modules_missing', json_encode($missing_modules));
  81. $preview_data->addChild('number_pages', folder_items(GSDATAPAGESPATH)-1);
  82. $preview_data->addChild('number_plugins', count($live_plugins));
  83. $preview_data->addChild('number_files', count(glob_recursive(GSDATAUPLOADPATH.'*')));
  84. $preview_data->addChild('number_themes', folder_items(GSTHEMESPATH));
  85. $preview_data->addChild('number_backups', count(getFiles(GSBACKUPSPATH.'zip')));
  86. $preview_data->addChild('number_users', folder_items(GSUSERSPATH)-1);
  87. $preview_data->addChild('domain_tld', get_tld_from_url($SITEURL));
  88. $preview_data->addChild('install_date', date('m-d-Y', filemtime(GSDATAOTHERPATH .'.htaccess')));
  89. $preview_data->addChild('category', $_POST['category']);
  90. $preview_data->addChild('link_back', $_POST['link_back']);
  91. XMLsave($preview_data, GSDATAOTHERPATH . 'anonymous_data.xml');
  92. }
  93. # post data to server
  94. if(isset($_POST['send'])) {
  95. global $thisfile_anony;
  96. $xml = file_get_contents(GSDATAOTHERPATH . 'anonymous_data.xml');
  97. $success = i18n_r($thisfile_anony.'/ANONY_SUCCESS');
  98. $php_modules = get_loaded_extensions();
  99. if (in_arrayi('curl', $php_modules)) {
  100. $ch = curl_init();
  101. curl_setopt($ch, CURLOPT_TIMEOUT, 4);
  102. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  103. curl_setopt($ch, CURLOPT_URL, 'http://get-simple.info/api/anonymous/?data='.urlencode($xml));
  104. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
  105. $result = curl_exec($ch);
  106. curl_close($ch);
  107. } else {
  108. sendmail('chris@get-simple.info','Anonymous Data Submission',$xml);
  109. }
  110. }
  111. global $thisfile_anony;
  112. ?>
  113. <style>
  114. form#anondata p {margin-bottom:5px;}
  115. form#anondata label {display:block;width:220px;float:left;line-height:35px;}
  116. form#anondata select.text {width:auto;float:left;}
  117. </style>
  118. <h3><?php i18n($thisfile_anony.'/ANONY_TITLE'); ?></h3>
  119. <?php
  120. if(isset($success)) {
  121. echo '<p style="color:#669933;"><b>'. $success .'</b></p>';
  122. }
  123. ?>
  124. <form method="post" id="anondata" action="<?php echo $_SERVER ['REQUEST_URI']?>">
  125. <?php if(isset($preview_data)) { ?>
  126. <p><?php i18n($thisfile_anony.'/ANONY_CONFIRM'); ?></p>
  127. <pre><code><?php echo htmlentities(formatXmlString(file_get_contents(GSDATAOTHERPATH . 'anonymous_data.xml')));?></code></pre>
  128. <p class="submit"><br /><input type="submit" class="submit" value="<?php i18n($thisfile_anony.'/ANONY_SEND_BTN'); ?>" name="send" /> &nbsp;&nbsp;<?php i18n('OR'); ?>&nbsp;&nbsp; <a class="cancel" href="plugins.php?cancel"><?php i18n('CANCEL'); ?></p>
  129. <?php } else { ?>
  130. <p><?php i18n($thisfile_anony.'/ANONY_PARAGRAPH'); ?></p>
  131. <p><?php i18n($thisfile_anony.'/ANONY_PARAGRAPH2'); ?></p>
  132. <p class="clearfix" ><label><?php i18n($thisfile_anony.'/ANONY_CATEGORY'); ?>:</label>
  133. <select name="category" class="text">
  134. <option value=""></option>
  135. <option value="Arts"><?php i18n($thisfile_anony.'/ANONY_ARTS'); ?></option>
  136. <option value="Business"><?php i18n($thisfile_anony.'/ANONY_BUSINESS'); ?></option>
  137. <option value="Children"><?php i18n($thisfile_anony.'/ANONY_CHILDREN'); ?></option>
  138. <option value="Computer &amp; Internet"><?php i18n($thisfile_anony.'/ANONY_INTERNET'); ?></option>
  139. <option value="Culture &amp; Religion"><?php i18n($thisfile_anony.'/ANONY_RELIGION'); ?></option>
  140. <option value="Education"><?php i18n($thisfile_anony.'/ANONY_EDUCATION'); ?></option>
  141. <option value="Employment"><?php i18n($thisfile_anony.'/ANONY_EMPLOYMENT'); ?></option>
  142. <option value="Entertainment"><?php i18n($thisfile_anony.'/ANONY_ENTERTAINMENT'); ?></option>
  143. <option value="Money &amp; Finance"><?php i18n($thisfile_anony.'/ANONY_FINANCE'); ?></option>
  144. <option value="Food"><?php i18n($thisfile_anony.'/ANONY_FOOD'); ?></option>
  145. <option value="Games"><?php i18n($thisfile_anony.'/ANONY_GAMES'); ?></option>
  146. <option value="Government"><?php i18n($thisfile_anony.'/ANONY_GOVERNMENT'); ?></option>
  147. <option value="Health &amp; Fitness"><?php i18n($thisfile_anony.'/ANONY_HEALTHFITNESS'); ?></option>
  148. <option value="HighTech"><?php i18n($thisfile_anony.'/ANONY_HIGHTECH'); ?></option>
  149. <option value="Hobbies &amp; Interests"><?php i18n($thisfile_anony.'/ANONY_HOBBIES'); ?></option>
  150. <option value="Law"><?php i18n($thisfile_anony.'/ANONY_LAW'); ?></option>
  151. <option value="Life Family Issues"><?php i18n($thisfile_anony.'/ANONY_LIFEFAMILY'); ?></option>
  152. <option value="Marketing"><?php i18n($thisfile_anony.'/ANONY_MARKETING'); ?></option>
  153. <option value="Media"><?php i18n($thisfile_anony.'/ANONY_MEDIA'); ?></option>
  154. <option value="Misc"><?php i18n($thisfile_anony.'/ANONY_MISC'); ?></option>
  155. <option value="Movies &amp; Television"><?php i18n($thisfile_anony.'/ANONY_MOVIES'); ?></option>
  156. <option value="Music &amp; Radio"><?php i18n($thisfile_anony.'/ANONY_MUSIC'); ?></option>
  157. <option value="Nature"><?php i18n($thisfile_anony.'/ANONY_NATURE'); ?></option>
  158. <option value="Non-Profit"><?php i18n($thisfile_anony.'/ANONY_NONPROFIT'); ?></option>
  159. <option value="Personal Homepages"><?php i18n($thisfile_anony.'/ANONY_PERSONAL'); ?></option>
  160. <option value="Pets"><?php i18n($thisfile_anony.'/ANONY_PETS'); ?></option>
  161. <option value="Home &amp; Garden"><?php i18n($thisfile_anony.'/ANONY_HOMEGARDEN'); ?></option>
  162. <option value="Real Estate"><?php i18n($thisfile_anony.'/ANONY_REALESTATE'); ?></option>
  163. <option value="Science &amp; Technology"><?php i18n($thisfile_anony.'/ANONY_SCIENCE'); ?></option>
  164. <option value="Shopping &amp; Services"><?php i18n($thisfile_anony.'/ANONY_SHOPPING'); ?></option>
  165. <option value="Society"><?php i18n($thisfile_anony.'/ANONY_SOCIETY'); ?></option>
  166. <option value="Sports"><?php i18n($thisfile_anony.'/ANONY_SPORTS'); ?></option>
  167. <option value="Tourism"><?php i18n($thisfile_anony.'/ANONY_TOURISM'); ?></option>
  168. <option value="Transportation"><?php i18n($thisfile_anony.'/ANONY_TRANSPORTATION'); ?></option>
  169. <option value="Travel"><?php i18n($thisfile_anony.'/ANONY_TRAVEL'); ?></option>
  170. <option value="X-rated"><?php i18n($thisfile_anony.'/ANONY_XRATED'); ?></option>
  171. </select>
  172. </p>
  173. <p class="clearfix" ><label><?php i18n($thisfile_anony.'/ANONY_LINK'); ?></label><select class="text" name="link_back"><option></option><option value="yes" ><?php i18n($thisfile_anony.'/ANONY_YES'); ?></option><option value="no" ><?php i18n($thisfile_anony.'/ANONY_NO'); ?></option></select></p>
  174. <p style="color:#cc0000;font-size:11px;" >* <?php i18n($thisfile_anony.'/ANONY_DISCLAIMER'); ?></p>
  175. <p class="submit"><br /><input type="submit" class="submit" value="<?php i18n($thisfile_anony.'/ANONY_PREVIEW_BTN'); ?>" name="preview" /> &nbsp;&nbsp;<?php i18n('OR'); ?>&nbsp;&nbsp; <a class="cancel" href="plugins.php?cancel"><?php i18n('CANCEL'); ?></p>
  176. <?php } ?>
  177. </form>
  178. <?php
  179. }