PageRenderTime 64ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/newstatpress/newstatpress.php

https://bitbucket.org/lgorence/quickpress
PHP | 3334 lines | 2753 code | 269 blank | 312 comment | 380 complexity | d0f5ca5e121e2cf049afb43acdb4832b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: NewStatPress
  4. Plugin URI: http://newstatpress.altervista.org
  5. Description: Real time stats for your Wordpress blog
  6. Version: 0.4.4
  7. Author: Stefano Tognon (from Daniele Lippi works)
  8. Author URI: http://newstatpress.altervista.org
  9. */
  10. $_NEWSTATPRESS['version']='0.4.4';
  11. $_NEWSTATPRESS['feedtype']='';
  12. include ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/includes/charts.php';
  13. /**
  14. * Get the url of the plugin
  15. *
  16. * @return the url of the plugin
  17. */
  18. function PluginUrl() {
  19. //Try to use WP API if possible, introduced in WP 2.6
  20. if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
  21. //Try to find manually... can't work if wp-content was renamed or is redirected
  22. $path = dirname(__FILE__);
  23. $path = str_replace("\\","/",$path);
  24. $path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
  25. return $path;
  26. }
  27. /**
  28. * Add pages with NewStatPress commands
  29. */
  30. function iri_add_pages() {
  31. # Create/update table if it not exists
  32. global $wpdb;
  33. $table_name = $wpdb->prefix . "statpress";
  34. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  35. iri_NewStatPress_CreateTable();
  36. }
  37. # add submenu
  38. $mincap=get_option('newstatpress_mincap');
  39. if($mincap == '') {
  40. $mincap="level_8";
  41. }
  42. // ORIG add_submenu_page('index.php', 'StatPress', 'StatPress', 8, 'statpress', 'iriNewStatPress');
  43. add_menu_page('NewStatPress', 'NewStatPress', $mincap, __FILE__, 'iriNewStatPress', plugins_url('newstatpress/images/stat.png',dirname(plugin_basename(__FILE__))));
  44. add_submenu_page(__FILE__, __('Overview','newstatpress'), __('Overview','newstatpress'), $mincap, __FILE__, 'iriNewStatPress');
  45. add_submenu_page(__FILE__, __('Details','newstatpress'), __('Details','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=details', 'iriNewStatPress');
  46. add_submenu_page(__FILE__, __('Spy','newstatpress'), __('Spy','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=spy', 'iriNewStatPress');
  47. add_submenu_page(__FILE__, __('New Spy','newstatpress'), __('New Spy','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=newspy', 'iriNewStatPress');
  48. add_submenu_page(__FILE__, __('Spy Bot','newstatpress'), __('Spy Bot','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=spybot', 'iriNewStatPress');
  49. add_submenu_page(__FILE__, __('Search','newstatpress'), __('Search','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=search', 'iriNewStatPress');
  50. add_submenu_page(__FILE__, __('Export','newstatpress'), __('Export','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=export', 'iriNewStatPress');
  51. add_submenu_page(__FILE__, __('Options','newstatpress'), __('Options','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=options', 'iriNewStatPress');
  52. add_submenu_page(__FILE__, __('NewStatPressUpdate','newstatpress'), __('NewStatPressUpdate','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=up', 'iriNewStatPress');
  53. add_submenu_page(__FILE__, __('NewStatpress blog','newstatpress'), __('NewStatpress blog','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=redirect', 'iriNewStatPress');
  54. add_submenu_page(__FILE__, __('Credits','newstatpress'), __('Credits','newstatpress'), $mincap, __FILE__ . '&newstatpress_action=credits', 'iriNewStatPress');
  55. }
  56. /**
  57. * General function for calling the action that user had choice
  58. */
  59. function iriNewStatPress() {
  60. ?>
  61. <?php
  62. if(isset($_GET['newstatpress_action'])){
  63. if ($_GET['newstatpress_action'] == 'export') {
  64. iriNewStatPressExport();
  65. } elseif ($_GET['newstatpress_action'] == 'up') {
  66. iriNewStatPressUpdate();
  67. } elseif ($_GET['newstatpress_action'] == 'spy') {
  68. iriNewStatPressSpy();
  69. } elseif ($_GET['newstatpress_action'] == 'newspy') {
  70. iriNewStatPressNewSpy();
  71. } elseif ($_GET['newstatpress_action'] == 'spybot') {
  72. iriNewStatPressSpyBot();
  73. } elseif ($_GET['newstatpress_action'] == 'search') {
  74. iriNewStatPressSearch();
  75. } elseif ($_GET['newstatpress_action'] == 'details') {
  76. iriNewStatPressDetails();
  77. } elseif ($_GET['newstatpress_action'] == 'options') {
  78. iriNewStatPressOptions();
  79. } elseif ($_GET['newstatpress_action'] == 'redirect') {
  80. iriNewStatPressRedirect();
  81. } elseif ($_GET['newstatpress_action'] == 'credits') {
  82. iriNewStatPressCredits();
  83. }
  84. } else iriNewStatPressMain();
  85. }
  86. /**
  87. * Redirect the wordpress page to the newstatpress blog
  88. */
  89. function iriNewStatPressRedirect() {
  90. echo "<script language=javascript>window.location.href= 'http://newstatpress.altervista.org'</script>";
  91. }
  92. /**
  93. * Filter the given value for preventing XSS attacks
  94. *
  95. * @param _value the value to filter
  96. * @return filtered value
  97. */
  98. function iriNewStatPress_filter_for_xss($_value){
  99. $_value=trim($_value);
  100. // Avoid XSS attacks
  101. $clean_value = preg_replace('/[^a-zA-Z0-9\,\.\/\ \-\_\?=&;]/', '', $_value);
  102. if (strlen($_value)==0){
  103. return array();
  104. } else {
  105. $array_values = explode(',',$clean_value);
  106. array_walk($array_values, 'iriNewStatPress_trim_value');
  107. return $array_values;
  108. }
  109. }
  110. /**
  111. * Trim the given string
  112. */
  113. function iriNewStatPress_trim_value(&$value) {
  114. $value = trim($value);
  115. }
  116. /**
  117. * Generate HTML for option menu in Wordpress
  118. */
  119. function iriNewStatPressOptions() {
  120. if(isset($_POST['saveit']) && $_POST['saveit'] == 'yes') {
  121. if (isset($_POST['newstatpress_collectloggeduser'])) update_option('newstatpress_collectloggeduser', $_POST['newstatpress_collectloggeduser']);
  122. else update_option('newstatpress_collectloggeduser', null);
  123. update_option('newstatpress_ip_per_page_newspy', $_POST['newstatpress_ip_per_page_newspy']);
  124. update_option('newstatpress_visits_per_ip_newspy', $_POST['newstatpress_visits_per_ip_newspy']);
  125. update_option('newstatpress_bot_per_page_spybot', $_POST['newstatpress_bot_per_page_spybot']);
  126. update_option('newstatpress_visits_per_bot_spybot', $_POST['newstatpress_visits_per_bot_spybot']);
  127. update_option('newstatpress_autodelete', $_POST['newstatpress_autodelete']);
  128. update_option('newstatpress_daysinoverviewgraph', $_POST['newstatpress_daysinoverviewgraph']);
  129. update_option('newstatpress_mincap', $_POST['newstatpress_mincap']);
  130. if (isset($_POST['newstatpress_donotcollectspider'])) update_option('newstatpress_donotcollectspider', $_POST['newstatpress_donotcollectspider']);
  131. else update_option('newstatpress_donotcollectspider', null);
  132. if (isset($_POST['newstatpress_cryptip'])) update_option('newstatpress_cryptip', $_POST['newstatpress_cryptip']);
  133. else update_option('newstatpress_cryptip', null);
  134. if (isset($_POST['newstatpress_dashboard'])) update_option('newstatpress_dashboard', $_POST['newstatpress_dashboard']);
  135. else update_option('newstatpress_dashboard', null);
  136. update_option('newstatpress_ignore_users', iriNewStatPress_filter_for_xss($_POST['newstatpress_ignore_users']));
  137. update_option('newstatpress_ignore_ip', iriNewStatPress_filter_for_xss($_POST['newstatpress_ignore_ip']));
  138. update_option('newstatpress_ignore_permalink', iriNewStatPress_filter_for_xss($_POST['newstatpress_ignore_permalink']));
  139. update_option('newstatpress_el_top_days', $_POST['newstatpress_el_top_days']);
  140. update_option('newstatpress_el_os', $_POST['newstatpress_el_os']);
  141. update_option('newstatpress_el_browser', $_POST['newstatpress_el_browser']);
  142. update_option('newstatpress_el_feed', $_POST['newstatpress_el_feed']);
  143. update_option('newstatpress_el_searchengine', $_POST['newstatpress_el_searchengine']);
  144. update_option('newstatpress_el_search', $_POST['newstatpress_el_search']);
  145. update_option('newstatpress_el_referrer', $_POST['newstatpress_el_referrer']);
  146. update_option('newstatpress_el_languages', $_POST['newstatpress_el_languages']);
  147. update_option('newstatpress_el_spiders', $_POST['newstatpress_el_spiders']);
  148. update_option('newstatpress_el_pages', $_POST['newstatpress_el_pages']);
  149. update_option('newstatpress_el_visitors', $_POST['newstatpress_el_visitors']);
  150. update_option('newstatpress_el_daypages', $_POST['newstatpress_el_daypages']);
  151. update_option('newstatpress_el_ippages', $_POST['newstatpress_el_ippages']);
  152. update_option('newstatpress_updateint', $_POST['newstatpress_updateint']);
  153. # update database too
  154. iri_NewStatPress_CreateTable();
  155. print "<br /><div class='updated'><p>".__('Saved','newstatpress')."!</p></div>";
  156. } else {
  157. ?>
  158. <div class='wrap'><h2><?php _e('Options','newstatpress'); ?></h2>
  159. <form method=post><table width=100%>
  160. <?php
  161. print "<tr><td><input type=checkbox name='newstatpress_collectloggeduser' value='checked' ".get_option('newstatpress_collectloggeduser')."> ".__('Collect data about logged users, too.','newstatpress')."</td></tr>";
  162. print "<tr><td><input type=checkbox name='newstatpress_donotcollectspider' value='checked' ".get_option('newstatpress_donotcollectspider')."> ".__('Do not collect spiders visits','newstatpress')."</td></tr>";
  163. print "<tr><td><input type=checkbox name='newstatpress_cryptip' value='checked' ".get_option('newstatpress_cryptip')."> ".__('Crypt IP addresses','newstatpress')."</td></tr>";
  164. print "<tr><td><input type=checkbox name='newstatpress_dashboard' value='checked' ".get_option('newstatpress_dashboard')."> ".__('Show NewStatPress dashboard widget','newstatpress')."</td></tr>";
  165. ?>
  166. <tr><td><?php _e('New Spy: number of IP per page','newstatpress'); ?>
  167. <select name="newstatpress_ip_per_page_newspy">
  168. <option value="20" <?php if(get_option('newstatpress_ip_per_page_newspy') == "20") print "selected"; ?>>20</option>
  169. <option value="50" <?php if(get_option('newstatpress_ip_per_page_newspy') == "50") print "selected"; ?>>50</option>
  170. <option value="100" <?php if(get_option('newstatpress_ip_per_page_newspy') == "100") print "selected"; ?>>100</option>
  171. </select></td></tr>
  172. <tr><td><?php _e('New Spy: number of visits for IP','newstatpress'); ?>
  173. <select name="newstatpress_visits_per_ip_newspy">
  174. <option value="20" <?php if(get_option('newstatpress_visits_per_ip_newspy') == "20") print "selected"; ?>>20</option>
  175. <option value="50" <?php if(get_option('newstatpress_visits_per_ip_newspy') == "50") print "selected"; ?>>50</option>
  176. <option value="100" <?php if(get_option('newstatpress_visits_per_ip_newspy') == "100") print "selected"; ?>>100</option>
  177. </select></td></tr>
  178. <tr><td><?php _e('Spy Bot: number of bot per page','newstatpress'); ?>
  179. <select name="newstatpress_bot_per_page_spybot">
  180. <option value="20" <?php if(get_option('newstatpress_bot_per_page_spybot') == "20") print "selected"; ?>>20</option>
  181. <option value="50" <?php if(get_option('newstatpress_bot_per_page_spybot') == "50") print "selected"; ?>>50</option>
  182. <option value="100" <?php if(get_option('newstatpress_bot_per_page_spybot') == "100") print "selected"; ?>>100</option>
  183. </select></td></tr>
  184. <tr><td><?php _e('Spy Bot: number of bot for IP','newstatpress'); ?>
  185. <select name="newstatpress_visits_per_bot_spybot">
  186. <option value="20" <?php if(get_option('newstatpress_visits_per_bot_spybot') == "20") print "selected"; ?>>20</option>
  187. <option value="50" <?php if(get_option('newstatpress_visits_per_bot_spybot') == "50") print "selected"; ?>>50</option>
  188. <option value="100" <?php if(get_option('newstatpress_visits_per_bot_spybot') == "100") print "selected"; ?>>100</option>
  189. </select></td></tr>
  190. <tr><td><?php _e('Automatically delete visits older than','newstatpress'); ?>
  191. <select name="newstatpress_autodelete">
  192. <option value="" <?php if(get_option('newstatpress_autodelete') =='' ) print "selected"; ?>><?php _e('Never delete!','newstatpress'); ?></option>
  193. <option value="1 month" <?php if(get_option('newstatpress_autodelete') == "1 month") print "selected"; ?>>1 <?php _e('month','newstatpress'); ?></option>
  194. <option value="3 months" <?php if(get_option('newstatpress_autodelete') == "3 months") print "selected"; ?>>3 <?php _e('months','newstatpress'); ?></option>
  195. <option value="6 months" <?php if(get_option('newstatpress_autodelete') == "6 months") print "selected"; ?>>6 <?php _e('months','newstatpress'); ?></option>
  196. <option value="1 year" <?php if(get_option('newstatpress_autodelete') == "1 year") print "selected"; ?>>1 <?php _e('year','newstatpress'); ?></option>
  197. </select></td></tr>
  198. <tr><td><?php _e('Days in Overview graph','newstatpress'); ?>
  199. <select name="newstatpress_daysinoverviewgraph">
  200. <option value="7" <?php if(get_option('newstatpress_daysinoverviewgraph') == 7) print "selected"; ?>>7</option>
  201. <option value="10" <?php if(get_option('newstatpress_daysinoverviewgraph') == 10) print "selected"; ?>>10</option>
  202. <option value="20" <?php if(get_option('newstatpress_daysinoverviewgraph') == 20) print "selected"; ?>>20</option>
  203. <option value="30" <?php if(get_option('newstatpress_daysinoverviewgraph') == 30) print "selected"; ?>>30</option>
  204. <option value="50" <?php if(get_option('newstatpress_daysinoverviewgraph') == 50) print "selected"; ?>>50</option>
  205. </select></td></tr>
  206. <tr><td><?php _e('Minimum capability to view stats','newstatpress'); ?>
  207. <select name="newstatpress_mincap">
  208. <?php iri_dropdown_caps(get_option('newstatpress_mincap')); ?>
  209. </select>
  210. <a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_blank"><?php _e("more info",'newstatpress'); ?></a>
  211. </td></tr>
  212. <tr><td><hr></hr></td></tr>
  213. <tr><td>
  214. <h3><label for="newstatpress_ignore_users"><?php _e('Logged users to ignore','newstatpress') ?></label></h3>
  215. <p><?php _e("Enter a list of users you don't want to track, separated by commas, even if collect data about logged users is on",'newstatpress') ?></p>
  216. <p><textarea class="large-text code" cols="50" rows="1" name="newstatpress_ignore_users" id="newstatpress_ignore_users">
  217. <?php echo implode(',', get_option('newstatpress_ignore_users',array())) ?>
  218. </textarea></p>
  219. </td></tr>
  220. <tr><td>
  221. <h3><label for="newstatpress_ignore_ip"><?php _e('IP addresses to ignore','newstatpress') ?></label></h3>
  222. <p><?php _e("Enter a list of networks you don't want to track, separated by commas. Each network <strong>must</strong> be defined using the CIDR notation (i.e. <em>192.168.1.1/24</em>). If the format is incorrect, NewStatPress may not track pageviews properly.",'newstatpress') ?></p>
  223. <p><textarea class="large-text code" cols="50" rows="1" name="newstatpress_ignore_ip" id="newstatpress_ignore_ip">
  224. <?php echo implode(',', get_option('newstatpress_ignore_ip',array())) ?>
  225. </textarea></p>
  226. </td></tr>
  227. <tr><td>
  228. <h3><label for="newstatpress_ignore_permalink"><?php _e('Pages and posts to ignore','newstatpress') ?></label></h3>
  229. <p><?php _e("Enter a list of permalinks you don't want to track, separated by commas. You should omit the domain name from these resources: <em>/about, p=1</em>, etc. NewStatPress will ignore all the pageviews whose permalink <strong>contains</strong> at least one of them.",'newstatpress') ?></p>
  230. <p><textarea class="large-text code" cols="50" rows="1" name="newstatpress_ignore_permalink" id="newstatpress_ignore_permalink">
  231. <?php echo implode(',', get_option('newstatpress_ignore_permalink',array())) ?>
  232. </textarea></p>
  233. </td></tr>
  234. <tr><td><hr></hr></td></tr>
  235. <tr>
  236. <td>
  237. <h3><label for="newstatpress_details_options"><?php _e('Details options','newstatpress') ?></label></h3>
  238. </td></tr>
  239. <tr>
  240. <td>
  241. <label for="newstatpress_el_top_days"><?php _e('Elements in Top days (default 5)','newstatpress') ?></label>
  242. <input type="text" name="newstatpress_el_top_days" value="<?php echo (get_option('newstatpress_el_top_days')=='') ? 5:get_option('newstatpress_el_top_days'); ?>" size="3" maxlength="3" />
  243. </td></tr>
  244. <tr>
  245. <td>
  246. <label for="newstatpress_el_os"><?php _e('Elements in O.S. (default 10)','newstatpress') ?></label>
  247. <input type="text" name="newstatpress_el_os" value="<?php echo (get_option('newstatpress_el_os')=='') ? 10:get_option('newstatpress_el_os'); ?>" size="3" maxlength="3" />
  248. </td></tr>
  249. <tr>
  250. <td>
  251. <label for="newstatpress_el_browser"><?php _e('Elements in Browser (default 10)','newstatpress') ?></label>
  252. <input type="text" name="newstatpress_el_browser" value="<?php echo (get_option('newstatpress_el_browser')=='') ? 10:get_option('newstatpress_el_browser'); ?>" size="3" maxlength="3" />
  253. </td></tr>
  254. <tr>
  255. <td>
  256. <label for="newstatpress_el_feed"><?php _e('Elements in Feed (default 5)','newstatpress') ?></label>
  257. <input type="text" name="newstatpress_el_feed" value="<?php echo (get_option('newstatpress_el_feed')=='') ? 5:get_option('newstatpress_el_feed'); ?>" size="3" maxlength="3" />
  258. </td></tr>
  259. <tr>
  260. <td>
  261. <label for="newstatpress_el_searchengine"><?php _e('Elements in Search Engines (default 10)','newstatpress') ?></label>
  262. <input type="text" name="newstatpress_el_searchengine" value="<?php echo (get_option('newstatpress_el_searchengine')=='') ? 10:get_option('newstatpress_el_searchengine'); ?>" size="3" maxlength="3" />
  263. </td></tr>
  264. <tr>
  265. <td>
  266. <label for="newstatpress_el_search"><?php _e('Elements in Top Search Terms (default 20)','newstatpress') ?></label>
  267. <input type="text" name="newstatpress_el_search" value="<?php echo (get_option('newstatpress_el_search')=='') ? 20:get_option('newstatpress_el_search'); ?>" size="3" maxlength="3" />
  268. </td></tr>
  269. <tr>
  270. <td>
  271. <label for="newstatpress_el_referrer"><?php _e('Elements in Top Refferer (default 10)','newstatpress') ?></label>
  272. <input type="text" name="newstatpress_el_referrer" value="<?php echo (get_option('newstatpress_el_referrer')=='') ? 10:get_option('newstatpress_el_referrer'); ?>" size="3" maxlength="3" />
  273. </td></tr>
  274. <tr>
  275. <td>
  276. <label for="newstatpress_el_languages"><?php _e('Elements in Countries/Languages (default 20)','newstatpress') ?></label>
  277. <input type="text" name="newstatpress_el_languages" value="<?php echo (get_option('newstatpress_el_languages')=='') ? 20:get_option('newstatpress_el_languages'); ?>" size="3" maxlength="3" />
  278. </td></tr>
  279. <tr>
  280. <td>
  281. <label for="newstatpress_el_spiders"><?php _e('Elements in Spiders (default 10)','newstatpress') ?></label>
  282. <input type="text" name="newstatpress_el_spiders" value="<?php echo (get_option('newstatpress_el_spiders')=='') ? 10:get_option('newstatpress_el_spiders'); ?>" size="3" maxlength="3" />
  283. </td></tr>
  284. <tr>
  285. <td>
  286. <label for="newstatpress_el_pages"><?php _e('Elements in Top Pages (default 5)','newstatpress') ?></label>
  287. <input type="text" name="newstatpress_el_pages" value="<?php echo (get_option('newstatpress_el_pages')=='') ? 5:get_option('newstatpress_el_pages'); ?>" size="3" maxlength="3" />
  288. </td></tr>
  289. <tr>
  290. <td>
  291. <label for="newstatpress_el_visitors"><?php _e('Elements in Top Days - Unique visitors (default 5)','newstatpress') ?></label>
  292. <input type="text" name="newstatpress_el_visitors" value="<?php echo (get_option('newstatpress_el_visitors')=='') ? 5:get_option('newstatpress_el_visitors'); ?>" size="3" maxlength="3" />
  293. </td></tr>
  294. <tr>
  295. <td>
  296. <label for="newstatpress_el_daypages"><?php _e('Elements in Top Days - Pageviews (default 5)','newstatpress') ?></label>
  297. <input type="text" name="newstatpress_el_daypages" value="<?php echo (get_option('newstatpress_el_daypages')=='') ? 5:get_option('newstatpress_el_daypages'); ?>" size="3" maxlength="3" />
  298. </td></tr>
  299. <tr>
  300. <td>
  301. <label for="newstatpress_el_ippages"><?php _e('Elements in Top IPs - Pageviews (default 5)','newstatpress') ?></label>
  302. <input type="text" name="newstatpress_el_ippages" value="<?php echo (get_option('newstatpress_el_ippages')=='') ? 5:get_option('newstatpress_el_ippages'); ?>" size="3" maxlength="3" />
  303. </td></tr>
  304. <tr><td><hr></hr></td></tr>
  305. <tr>
  306. <td>
  307. <h2><?php _e('Database update option','newstatpress'); ?></h3>
  308. </td></tr>
  309. <tr>
  310. <td>
  311. <p><?php _e("Select the interval of date from today you want to use for updating your database with new definitions. More it is big and more times and resources it require. You can choose to not update some fields if you want.",'newstatpress') ?></p>
  312. </td></tr>
  313. <tr>
  314. <td>
  315. <?php _e('Update data in the given period','newstatpress'); ?>
  316. <select name="newstatpress_updateint">
  317. <option value="" <?php if(get_option('newstatpress_updateint') =='' ) print "selected"; ?>><?php _e('All!','newstatpress'); ?></option>
  318. <option value="1 week" <?php if(get_option('newstatpress_updateint') == "1 week") print "selected"; ?>>1 <?php _e('week','newstatpress'); ?></option>
  319. <option value="2 weeks" <?php if(get_option('newstatpress_updateint') == "2 weeks") print "selected"; ?>>2 <?php _e('weeks','newstatpress'); ?></option>
  320. <option value="3 weeks" <?php if(get_option('newstatpress_updateint') == "3 weeks") print "selected"; ?>>3 <?php _e('weeks','newstatpress'); ?></option>
  321. <option value="1 month" <?php if(get_option('newstatpress_updateint') == "1 month") print "selected"; ?>>1 <?php _e('month','newstatpress'); ?></option>
  322. <option value="2 months" <?php if(get_option('newstatpress_updateint') == "2 months") print "selected"; ?>>2 <?php _e('months','newstatpress'); ?></option>
  323. <option value="3 months" <?php if(get_option('newstatpress_updateint') == "3 months") print "selected"; ?>>3 <?php _e('months','newstatpress'); ?></option>
  324. <option value="6 months" <?php if(get_option('newstatpress_updateint') == "6 months") print "selected"; ?>>6 <?php _e('months','newstatpress'); ?></option>
  325. <option value="9 months" <?php if(get_option('newstatpress_updateint') == "9 months") print "selected"; ?>>9 <?php _e('months','newstatpress'); ?></option>
  326. <option value="1 year" <?php if(get_option('newstatpress_updateint') == "1 year") print "selected"; ?>>1 <?php _e('year','newstatpress'); ?></option>
  327. </select></td></tr>
  328. </td></tr>
  329. <tr><td><hr></hr></td></tr>
  330. <tr><td><br><input type=submit value="<?php _e('Save options','newstatpress'); ?>"></td></tr>
  331. </tr>
  332. </table>
  333. <input type=hidden name=saveit value=yes>
  334. <input type=hidden name=page value=newstatpress><input type=hidden name=newstatpress_action value=options>
  335. </form>
  336. </div>
  337. <?php
  338. }
  339. }
  340. function iri_dropdown_caps( $default = false ) {
  341. global $wp_roles;
  342. $role = get_role('administrator');
  343. foreach($role->capabilities as $cap => $grant) {
  344. print "<option ";
  345. if($default == $cap) { print "selected "; }
  346. print ">$cap</option>";
  347. }
  348. }
  349. /**
  350. * Show credits about this plugin
  351. */
  352. function iriNewStatPressCredits() {
  353. ?>
  354. <div class='wrap'><h2><?php _e('Credits','newstatpress'); ?></h2>
  355. <table border="1">
  356. <tr>
  357. <th>People</th>
  358. <th>Description</th>
  359. <th>Link</th>
  360. </tr>
  361. <tr>
  362. <td>Stefano Tognon</td>
  363. <td>NewStatPress develoup</td>
  364. <td><a href="http://newstatpress.altervista.org">NewStatPress site</a></td>
  365. </tr>
  366. <tr>
  367. <td>Daniele Lippi</td>
  368. <td>Original StatPress develoup</td>
  369. <td><a href="http://wordpress.org/extend/plugins/statpress/">StatPress site</a></td>
  370. </tr>
  371. <tr>
  372. <td>Pawel Dworniak</td>
  373. <td>Better polish translation</td>
  374. <td></td>
  375. </tr>
  376. <tr>
  377. <td>Sisko</td>
  378. <td>Open link in new tab/window<br>
  379. New displays of data for spy function<br>
  380. </td>
  381. <td></td>
  382. </tr>
  383. <tr>
  384. <td>from wp_slimstat</td>
  385. <td>Add option for not track given IPs<br>
  386. Add option for not track given permalinks
  387. </td>
  388. <td></td>
  389. </tr>
  390. <tr>
  391. <td>Ladislav</td>
  392. <td>Let Search function to works again</td>
  393. <td></td>
  394. </tr>
  395. <tr>
  396. <td>from statpress-visitors</td>
  397. <td>Add new OS (+44), browsers (+52) and spiders (+71)<br>
  398. Add in the option the ability to update in a range of date<br>
  399. New spy and bot
  400. </td>
  401. <td></td>
  402. </tr>
  403. <tr>
  404. <td>Christopher Meng</td>
  405. <td>Add Simplified Chinese translation</td>
  406. <td><a href="http://cicku.me">cicku.me</a></td>
  407. </tr>
  408. <tr>
  409. <td>Maurice Cramer</td>
  410. <td>Add dashboard widget<br>
  411. Fix total since in overwiew<br>
  412. Fix missing browser image and IE aligment failure in spy section<br>
  413. Fix nation image display in spy
  414. </td>
  415. <td></td>
  416. </tr>
  417. <tr>
  418. <td>shilom</td>
  419. <td>Updating French translation</td>
  420. <td></td>
  421. </tr>
  422. <tr>
  423. <td>Vincent G</td>
  424. <td>Add Lithuanian translation</td>
  425. <td><a href="http://www.Host1Free.com">Host1Free (Free Hosting)</a></td>
  426. </tr>
  427. <tr>
  428. <td>Ruud van der Veen</td>
  429. <td>Add tab delimiter for exporting data</td>
  430. <td></td>
  431. </tr>
  432. </table>
  433. </div>
  434. <?php
  435. }
  436. function iriNewStatPressExport() {
  437. ?>
  438. <div class='wrap'><h2><?php _e('Export stats to text file','newstatpress'); ?> (csv)</h2>
  439. <form method=get><table>
  440. <tr><td><?php _e('From','newstatpress'); ?></td><td><input type=text name=from> (YYYYMMDD)</td></tr>
  441. <tr><td><?php _e('To','newstatpress'); ?></td><td><input type=text name=to> (YYYYMMDD)</td></tr>
  442. <tr><td><?php _e('Fields delimiter','newstatpress'); ?></td><td><select name=del><option>,</option><option>tab</option><option>;</option><option>|</option></select></tr>
  443. <tr><td></td><td><input type=submit value=<?php _e('Export','newstatpress'); ?>></td></tr>
  444. <input type=hidden name=page value=newstatpress><input type=hidden name=newstatpress_action value=exportnow>
  445. </table></form>
  446. </div>
  447. <?php
  448. }
  449. /**
  450. * Check and export if capability of user allow that
  451. */
  452. function iri_checkExport(){
  453. if (isset($_GET['newstatpress_action']) && $_GET['newstatpress_action'] == 'exportnow') {
  454. $mincap=get_option('newstatpress_mincap');
  455. if ($mincap == '') $mincap = "level_8";
  456. if ( current_user_can( $mincap ) ) {
  457. iriNewStatPressExportNow();
  458. }
  459. }
  460. }
  461. /**
  462. * Export the NewStatPress data
  463. */
  464. function iriNewStatPressExportNow() {
  465. global $wpdb;
  466. $table_name = $wpdb->prefix . "statpress";
  467. $filename=get_bloginfo('title' )."-newstatpress_".$_GET['from']."-".$_GET['to'].".csv";
  468. header('Content-Description: File Transfer');
  469. header("Content-Disposition: attachment; filename=$filename");
  470. header('Content-Type: text/plain charset=' . get_option('blog_charset'), true);
  471. $qry = $wpdb->get_results(
  472. "SELECT *
  473. FROM $table_name
  474. WHERE
  475. date>='".(date("Ymd",strtotime(substr($_GET['from'],0,8))))."' AND
  476. date<='".(date("Ymd",strtotime(substr($_GET['to'],0,8))))."';
  477. ");
  478. $del=substr($_GET['del'],0,1);
  479. if ($del=="t") {
  480. $del="\t";
  481. }
  482. print "date".$del."time".$del."ip".$del."urlrequested".$del."agent".$del."referrer".$del."search".$del."nation".$del."os".$del."browser".$del."searchengine".$del."spider".$del."feed\n";
  483. foreach ($qry as $rk) {
  484. print '"'.$rk->date.'"'.$del.'"'.$rk->time.'"'.$del.'"'.$rk->ip.'"'.$del.'"'.$rk->urlrequested.'"'.$del.'"'.$rk->agent.'"'.$del.'"'.$rk->referrer.'"'.$del.'"'.$rk->search.'"'.$del.'"'.$rk->nation.'"'.$del.'"'.$rk->os.'"'.$del.'"'.$rk->browser.'"'.$del.'"'.$rk->searchengine.'"'.$del.'"'.$rk->spider.'"'.$del.'"'.$rk->feed.'"'."\n";
  485. }
  486. die();
  487. }
  488. /**
  489. * Show overwiew
  490. */
  491. function iriNewStatPressMain() {
  492. global $wpdb;
  493. $table_name = $wpdb->prefix . "statpress";
  494. iriOverview();
  495. $_newstatpress_url=PluginUrl();
  496. $querylimit="LIMIT 10";
  497. # Tabella Last hits
  498. print "<div class='wrap'><h2>". __('Last hits','newstatpress'). "</h2><table class='widefat'><thead><tr><th scope='col'>". __('Date','newstatpress'). "</th><th scope='col'>". __('Time','newstatpress'). "</th><th scope='col'>IP</th><th scope='col'>". __('Country','newstatpress').'/'.__('Language','newstatpress'). "</th><th scope='col'>". __('Page','newstatpress'). "</th><th scope='col'>Feed</th><th></th><th scope='col' style='width:120px;'>OS</th><th></th><th scope='col' style='width:120px;'>Browser</th></tr></thead>";
  499. print "<tbody id='the-list'>";
  500. $fivesdrafts = $wpdb->get_results("
  501. SELECT *
  502. FROM $table_name
  503. WHERE (os<>'' OR feed<>'')
  504. ORDER bY id DESC $querylimit
  505. ");
  506. foreach ($fivesdrafts as $fivesdraft) {
  507. print "<tr>";
  508. print "<td>". irihdate($fivesdraft->date) ."</td>";
  509. print "<td>". $fivesdraft->time ."</td>";
  510. print "<td>". $fivesdraft->ip ."</td>";
  511. print "<td>". $fivesdraft->nation ."</td>";
  512. print "<td>". iri_NewStatPress_Abbrevia(iri_NewStatPress_Decode($fivesdraft->urlrequested),30) ."</td>";
  513. print "<td>". $fivesdraft->feed . "</td>";
  514. if($fivesdraft->os != '') {
  515. $img=str_replace(" ","_",strtolower($fivesdraft->os)).".png";
  516. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/os/$img'> </td>";
  517. } else {
  518. print "<td></td>";
  519. }
  520. print "<td>". $fivesdraft->os . "</td>";
  521. if($fivesdraft->browser != '') {
  522. $img=str_replace(" ","",strtolower($fivesdraft->browser)).".png";
  523. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/browsers/$img'></td>";
  524. } else {
  525. print "<td></td>";
  526. }
  527. print "<td>".$fivesdraft->browser."</td></tr>\n";
  528. print "</tr>";
  529. }
  530. print "</table></div>";
  531. # Last Search terms
  532. print "<div class='wrap'><h2>" . __('Last search terms','newstatpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','newstatpress')."</th><th scope='col'>".__('Time','newstatpress')."</th><th scope='col'>".__('Terms','newstatpress')."</th><th scope='col'>". __('Engine','newstatpress'). "</th><th scope='col'>". __('Result','newstatpress'). "</th></tr></thead>";
  533. print "<tbody id='the-list'>";
  534. $qry = $wpdb->get_results("
  535. SELECT date,time,referrer,urlrequested,search,searchengine
  536. FROM $table_name
  537. WHERE search<>''
  538. ORDER BY id DESC $querylimit
  539. ");
  540. foreach ($qry as $rk) {
  541. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td><a href='".$rk->referrer."' target='_blank'>".$rk->search."</a></td><td>".$rk->searchengine."</td><td><a href='".get_bloginfo('url')."/?".$rk->urlrequested."' target='_blank'>". __('page viewed','newstatpress'). "</a></td></tr>\n";
  542. }
  543. print "</table></div>";
  544. # Referrer
  545. print "<div class='wrap'><h2>".__('Last referrers','newstatpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','newstatpress')."</th><th scope='col'>".__('Time','newstatpress')."</th><th scope='col'>".__('URL','newstatpress')."</th><th scope='col'>".__('Result','newstatpress')."</th></tr></thead>";
  546. print "<tbody id='the-list'>";
  547. $qry = $wpdb->get_results("
  548. SELECT date,time,referrer,urlrequested
  549. FROM $table_name
  550. WHERE
  551. ((referrer NOT LIKE '".get_option('home')."%') AND
  552. (referrer <>'') AND
  553. (searchengine='')
  554. ) ORDER BY id DESC $querylimit
  555. ");
  556. foreach ($qry as $rk) {
  557. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td><a href='".$rk->referrer."' target='_blank'>".iri_NewStatPress_Abbrevia($rk->referrer,80)."</a></td><td><a href='".get_bloginfo('url')."/?".$rk->urlrequested."' target='_blank'>". __('page viewed','newstatpress'). "</a></td></tr>\n";
  558. }
  559. print "</table></div>";
  560. # Last Agents
  561. print "<div class='wrap'><h2>".__('Last agents','newstatpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Agent','newstatpress')."</th><th scope='col'></th><th scope='col' style='width:120px;'>OS</th><th scope='col'></th><th scope='col' style='width:120px;'>Browser/Spider</th></tr></thead>";
  562. print "<tbody id='the-list'>";
  563. $qry = $wpdb->get_results("
  564. SELECT agent,os,browser,spider
  565. FROM $table_name
  566. GROUP BY agent,os,browser,spider
  567. ORDER BY id DESC $querylimit
  568. ");
  569. foreach ($qry as $rk) {
  570. print "<tr><td>".$rk->agent."</td>";
  571. if($rk->os != '') {
  572. $img=str_replace(" ","_",strtolower($rk->os)).".png";
  573. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/os/$img'> </td>";
  574. } else {
  575. print "<td></td>";
  576. }
  577. print "<td>". $rk->os . "</td>";
  578. if($rk->browser != '') {
  579. $img=str_replace(" ","",strtolower($rk->browser)).".png";
  580. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/browsers/$img'></td>";
  581. } else {
  582. print "<td></td>";
  583. }
  584. print "<td>".$rk->browser." ".$rk->spider."</td></tr>\n";
  585. }
  586. print "</table></div>";
  587. # Last pages
  588. print "<div class='wrap'><h2>".__('Last pages','newstatpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','newstatpress')."</th><th scope='col'>".__('Time','newstatpress')."</th><th scope='col'>".__('Page','newstatpress')."</th><th scope='col' style='width:17px;'></th><th scope='col' style='width:120px;'>".__('OS','newstatpress')."</th><th style='width:17px;'></th><th scope='col' style='width:120px;'>".__('Browser','newstatpress')."</th></tr></thead>";
  589. print "<tbody id='the-list'>";
  590. $qry = $wpdb->get_results("
  591. SELECT date,time,urlrequested,os,browser,spider
  592. FROM $table_name
  593. WHERE (spider='' AND feed='')
  594. ORDER BY id DESC $querylimit
  595. ");
  596. foreach ($qry as $rk) {
  597. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td>".iri_NewStatPress_Abbrevia(iri_NewStatPress_Decode($rk->urlrequested),60)."</td>";
  598. if($rk->os != '') {
  599. $img=str_replace(" ","_",strtolower($rk->os)).".png";
  600. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/os/$img'> </td>";
  601. } else {
  602. print "<td></td>";
  603. }
  604. print "<td>". $rk->os . "</td>";
  605. if($rk->browser != '') {
  606. $img=str_replace(" ","",strtolower($rk->browser)).".png";
  607. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='".$_newstatpress_url."/images/browsers/$img'></td>";
  608. } else {
  609. print "<td></td>";
  610. }
  611. print "<td>".$rk->browser." ".$rk->spider."</td></tr>\n";
  612. }
  613. print "</table></div>";
  614. # Last Spiders
  615. print "<div class='wrap'><h2>".__('Last spiders','newstatpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','newstatpress')."</th><th scope='col'>".__('Time','newstatpress')."</th><th scope='col'></th><th scope='col'>".__('Spider','newstatpress')."</th><th scope='col'>".__('Agent','newstatpress')."</th></tr></thead>";
  616. print "<tbody id='the-list'>";
  617. $qry = $wpdb->get_results("
  618. SELECT date,time,agent,os,browser,spider
  619. FROM $table_name
  620. WHERE (spider<>'')
  621. ORDER BY id DESC $querylimit
  622. ");
  623. foreach ($qry as $rk) {
  624. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td>";
  625. if($rk->spider != '') {
  626. $img=str_replace(" ","_",strtolower($rk->spider)).".png";
  627. print "<td><IMG style='border:0px;height:16px;' SRC='".$_newstatpress_url."/images/spider/$img'> </td>";
  628. } else print "<td></td>";
  629. print "<td>".$rk->spider."</td><td> ".$rk->agent."</td></tr>\n";
  630. }
  631. print "</table></div>";
  632. print "<br />";
  633. print "&nbsp;<i>StatPress table size: <b>".iritablesize($wpdb->prefix . "statpress")."</b></i><br />";
  634. print "&nbsp;<i>StatPress current time: <b>".current_time('mysql')."</b></i><br />";
  635. print "&nbsp;<i>RSS2 url: <b>".get_bloginfo('rss2_url').' ('.iriNewStatPress_extractfeedreq(get_bloginfo('rss2_url')).")</b></i><br />";
  636. }
  637. /**
  638. * Extract the feed from the given url
  639. *
  640. * @param url the url to parse
  641. * @return the extracted url
  642. */
  643. function iriNewStatPress_extractfeedreq($url) {
  644. list($null,$q)=explode("?",$url);
  645. if (strpos($q, "&")!== false) list($res,$null)=explode("&",$q);
  646. else $res=$q;
  647. return $res;
  648. }
  649. function iriNewStatPressDetails() {
  650. global $wpdb;
  651. $table_name = $wpdb->prefix . "statpress";
  652. $querylimit="LIMIT 10";
  653. # Top days
  654. iriValueTable2("date","Top days",(get_option('newstatpress_el_top_days')=='') ? 5:get_option('newstatpress_el_top_days'));
  655. # O.S.
  656. iriValueTable2("os","O.S.",(get_option('newstatpress_el_os')=='') ? 10:get_option('newstatpress_el_os'),"","","AND feed='' AND spider='' AND os<>''");
  657. # Browser
  658. iriValueTable2("browser","Browser",(get_option('newstatpress_el_browser')=='') ? 10:get_option('newstatpress_el_browser'),"","","AND feed='' AND spider='' AND browser<>''");
  659. # Feeds
  660. iriValueTable2("feed","Feeds",(get_option('newstatpress_el_feed')=='') ? 5:get_option('newstatpress_el_feed'),"","","AND feed<>''");
  661. # SE
  662. iriValueTable2("searchengine","Search engines",(get_option('newstatpress_el_searchengine')=='') ? 10:get_option('newstatpress_el_searchengine'),"","","AND searchengine<>''");
  663. # Search terms
  664. iriValueTable2("search","Top search terms",(get_option('newstatpress_el_search')=='') ? 20:get_option('newstatpress_el_search'),"","","AND search<>''");
  665. # Top referrer
  666. iriValueTable2("referrer","Top referrer",(get_option('newstatpress_el_referrer')=='') ? 10:get_option('newstatpress_el_referrer'),"","","AND referrer<>'' AND referrer NOT LIKE '%".get_bloginfo('url')."%'");
  667. # Languages
  668. iriValueTable2("nation","Countries/Languages",(get_option('newstatpress_el_languages')=='') ? 20:get_option('newstatpress_el_languages'),"","","AND nation<>'' AND spider=''");
  669. # Spider
  670. iriValueTable2("spider","Spiders",(get_option('newstatpress_el_spiders')=='') ? 10:get_option('newstatpress_el_spiders'),"","","AND spider<>''");
  671. # Top Pages
  672. iriValueTable2("urlrequested","Top pages",(get_option('newstatpress_el_pages')=='') ? 5:get_option('newstatpress_el_pages'),"","urlrequested","AND feed='' and spider=''");
  673. # Top Days - Unique visitors
  674. iriValueTable2("date","Top Days - Unique visitors",(get_option('newstatpress_el_visitors')=='') ? 5:get_option('newstatpress_el_visitors'),"distinct","ip","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  675. # Top Days - Pageviews
  676. iriValueTable2("date","Top Days - Pageviews",(get_option('newstatpress_el_daypages')=='') ? 5:get_option('newstatpress_el_daypages'),"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  677. # Top IPs - Pageviews
  678. iriValueTable2("ip","Top IPs - Pageviews",(get_option('newstatpress_el_ippages')=='') ? 5:get_option('newstatpress_el_ippages'),"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  679. }
  680. /**
  681. * Converte da data us to default format di Wordpress
  682. *
  683. * @param dt the date to convert
  684. * @return converted data
  685. */
  686. function newstatpress_hdate($dt = "00000000") {
  687. return mysql2date(get_option('date_format'), my_substr($dt, 0, 4) . "-" . my_substr($dt, 4, 2) . "-" . my_substr($dt, 6, 2));
  688. }
  689. /**
  690. * Decode the url in a better manner
  691. */
  692. function newstatpress_Decode($out_url) {
  693. if(!permalinksEnabled()) {
  694. if ($out_url == '') $out_url = __('Page', 'newstatpress') . ": Home";
  695. if (my_substr($out_url, 0, 4) == "cat=") $out_url = __('Category', 'statpress') . ": " . get_cat_name(my_substr($out_url, 4));
  696. if (my_substr($out_url, 0, 2) == "m=") $out_url = __('Calendar', 'newstatpress') . ": " . my_substr($out_url, 6, 2) . "/" . my_substr($out_url, 2, 4);
  697. if (my_substr($out_url, 0, 2) == "s=") $out_url = __('Search', 'newstatpress') . ": " . my_substr($out_url, 2);
  698. if (my_substr($out_url, 0, 2) == "p=") {
  699. $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A);
  700. $out_url = $post_id_7['post_title'];
  701. }
  702. if (my_substr($out_url, 0, 8) == "page_id=") {
  703. $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A);
  704. $out_url = __('Page', 'newstatpress') . ": " . $post_id_7['post_title'];
  705. }
  706. } else {
  707. if ($out_url == '') $out_url = __('Page', 'newstatpress') . ": Home";
  708. else if (my_substr($out_url, 0, 9) == "category/") $out_url = __('Category', 'newstatpress') . ": " . get_cat_name(my_substr($out_url, 9));
  709. else if (my_substr($out_url, 0, 2) == "s=") $out_url = __('Search', 'newstatpress') . ": " . my_substr($out_url, 2);
  710. else if (my_substr($out_url, 0, 2) == "p=") {
  711. // not working yet
  712. $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A);
  713. $out_url = $post_id_7['post_title'];
  714. } else if (my_substr($out_url, 0, 8) == "page_id=") {
  715. // not working yet
  716. $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A);
  717. $out_url = __('Page', 'newstatpress') . ": " . $post_id_7['post_title'];
  718. }
  719. }
  720. return $out_url;
  721. }
  722. /**
  723. * Get true if permalink is enabled in Wordpress
  724. * (taken in statpress-visitors)
  725. *
  726. * @return true if permalink is enabled in Wordpress
  727. */
  728. function permalinksEnabled() {
  729. global $wpdb;
  730. $result = $wpdb->get_row('SELECT `option_value` FROM `' . $wpdb->prefix . 'options` WHERE `option_name` = "permalink_structure"');
  731. if ($result->option_value != '') return true;
  732. else return false;
  733. }
  734. /**
  735. * PHP 4 compatible mb_substr function
  736. * (taken in statpress-visitors)
  737. */
  738. function my_substr($str, $x, $y = 0) {
  739. if($y == 0) $y = strlen($str) - $x;
  740. if(function_exists('mb_substr'))
  741. return mb_substr($str, $x, $y);
  742. else
  743. return substr($str, $x, $y);
  744. }
  745. /**
  746. * Display links for group of pages
  747. *
  748. * @param NP the group of pages
  749. * @param pp the page to show
  750. * @param action the action
  751. */
  752. function newstatpress_print_pp_link($NP,$pp,$action) {
  753. // For all pages ($NP) Display first 3 pages, 3 pages before current page($pp), 3 pages after current page , each 25 pages and the 3 last pages for($action)
  754. $GUIL1 = FALSE;
  755. $GUIL2 = FALSE;// suspension points not writed style='border:0px;width:16px;height:16px; style="border:0px;width:16px;height:16px;"
  756. if ($NP >1) {
  757. print "<font size='1'>".__('period of days','newstatpress')." : </font>";
  758. for ($i = 1; $i <= $NP; $i++) {
  759. if ($i <= $NP) {
  760. // $page is not the last page
  761. if($i == $pp) echo " [{$i}] "; // $page is current page
  762. else {
  763. // Not the current page Hyperlink them
  764. if (($i <= 3) or (($i >= $pp-3) and ($i <= $pp+3)) or ($i >= $NP-3) or is_int($i/100)) {
  765. echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?page=newstatpress/newstatpress.php&newstatpress_action='.$action.'&pp=' . $i .'">' . $i . '</a> ';
  766. } else {
  767. if (($GUIL1 == FALSE) OR ($i==$pp+4)) {
  768. echo "...";
  769. $GUIL1 = TRUE;
  770. }
  771. if ($i == $pp-4) echo "..";
  772. if (is_int(($i-1)/100)) echo ".";
  773. if ($i == $NP-4) echo "..";
  774. // suspension points writed
  775. }
  776. }
  777. }
  778. }
  779. }
  780. }
  781. /**
  782. * Display links for group of pages
  783. *
  784. * @param NP the group of pages
  785. * @param pp the page to show
  786. * @param action the action
  787. * @param NA group
  788. * @param pa current page
  789. */
  790. function newstatpress_print_pp_pa_link($NP,$pp,$action,$NA,$pa) {
  791. if ($NP<>0) newstatpress_print_pp_link($NP,$pp,$action);
  792. // For all pages ($NP) display first 5 pages, 3 pages before current page($pa), 3 pages after current page , 3 last pages
  793. $GUIL1 = FALSE;// suspension points not writed
  794. $GUIL2 = FALSE;
  795. echo '<table width="100%" border="0"><tr></tr></table>';
  796. if ($NA >1 ) {
  797. echo "<font size='1'>".__('Pages','newstatpress')." : </font>";
  798. for ($j = 1; $j <= $NA; $j++) {
  799. if ($j <= $NA) { // $i is not the last Articles page
  800. if($j == $pa) // $i is current page
  801. echo " [{$j}] ";
  802. else { // Not the current page Hyperlink them
  803. if (($j <= 5) or (( $j>=$pa-2) and ($j <= $pa+2)) or ($j >= $NA-2))
  804. echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?page=newstatpress/newstatpress.php&newstatpress_action='.$action.'&pp=' . $pp . '&pa='. $j . '">' . $j . '</a> ';
  805. else {
  806. if ($GUIL1 == FALSE) echo "... "; $GUIL1 = TRUE;
  807. if (($j == $pa+4) and ($GUIL2 == FALSE)) {
  808. echo " ... ";
  809. $GUIL2 = TRUE;
  810. }
  811. // suspension points writed
  812. }
  813. }
  814. }
  815. }
  816. }
  817. }
  818. /**
  819. * Get page period taken in statpress-visitors
  820. */
  821. function newstatpress_page_periode() {
  822. // pp is the display page periode
  823. if(isset($_GET['pp'])) {
  824. // Get Current page periode from URL
  825. $periode = $_GET['pp'];
  826. if($periode <= 0)
  827. // Periode is less than 0 then set it to 1
  828. $periode = 1;
  829. } else
  830. // URL does not show the page set it to 1
  831. $periode = 1;
  832. return $periode;
  833. }
  834. /**
  835. * Get page post taken in statprss-visitors
  836. */
  837. function newstatpress_page_posts() {
  838. global $wpdb;
  839. // pa is the display pages Articles
  840. if(isset($_GET['pa'])) {
  841. // Get Current page Articles from URL
  842. $pageA = $_GET['pa'];
  843. if($pageA <= 0)
  844. // Article is less than 0 then set it to 1
  845. $pageA = 1;
  846. } else
  847. // URL does not show the Article set it to 1
  848. $pageA = 1;
  849. return $pageA;
  850. }
  851. /**
  852. * New spy function taken in statpress-visitors
  853. */
  854. function iriNewStatPressNewSpy() {
  855. global $wpdb;
  856. $action="newspy";
  857. $table_name = $wpdb->prefix . "statpress";
  858. // number of IP or bot by page
  859. $LIMIT = get_option('newstatpress_ip_per_page_newspy');
  860. $LIMIT_PROOF = get_option('newstatpress_visits_per_ip_newspy');
  861. if ($LIMIT == 0) $LIMIT = 20;
  862. if ($LIMIT_PROOF == 0) $LIMIT_PROOF = 20;
  863. $pp = newstatpress_page_periode();
  864. // Number of distinct ip (unique visitors)
  865. $NumIP = $wpdb->get_var("
  866. SELECT count(distinct ip)
  867. FROM $table_name
  868. WHERE spider=''"
  869. );
  870. $NP = ceil($NumIP/$LIMIT);
  871. $LimitValue = ($pp * $LIMIT) - $LIMIT;
  872. $sql = "
  873. SELECT *
  874. FROM $table_name as T1
  875. JOIN
  876. (SELECT max(id) as MaxId,min(id) as MinId,ip, nation
  877. FROM $table_name
  878. WHERE spider=''
  879. GROUP BY ip
  880. ORDER BY MaxId
  881. DESC LIMIT $LimitValue, $LIMIT ) as T2
  882. ON T1.ip = T2.ip
  883. WHERE id BETWEEN MinId AND MaxId
  884. ORDER BY MaxId DESC, id DESC
  885. ";
  886. $qry = $wpdb->get_results($sql);
  887. echo "<div class='wrap'><h2>" . __('Visitor Spy', 'newstatpress') . "</h2>";
  888. ?>
  889. <script>
  890. function ttogle(thediv){
  891. if (document.getElementById(thediv).style.display=="inline") {
  892. document.getElementById(thediv).style.display="none"
  893. } else {document.getElementById(thediv).style.display="inline"}
  894. }
  895. </script>
  896. <?php
  897. $ip = 0;
  898. $num_row=0;
  899. echo'<div id="paginating" align="center">';
  900. newstatpress_print_pp_link($NP,$pp,$action);
  901. echo'</div><table id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">';
  902. foreach ($qry as $rk) {
  903. // Visitor Spy
  904. if ($ip <> $rk->ip) {
  905. //this is the first time these ip appear, print informations
  906. echo "<tr><td colspan='2' bgcolor='#dedede'><div align='left'>";
  907. $title='';
  908. $id ='';
  909. ///if ($rk->country <> '') {
  910. /// $img=strtolower($rk->country).".png";
  911. /// $lines = file(ABSPATH.'wp-content/plugins/'.dirname(dirname(dirname(plugin_basename(__FILE__)))) .'/def/domain.dat');
  912. /// foreach($lines as $line_num => $country) {
  913. /// list($id,$title)=explode("|",$country);
  914. /// if($id===strtolower($rk->country)) break;
  915. /// }
  916. /// echo "http country <IMG style='border:0px;height:16px;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/domain/'.$img, dirname(dirname(dirname(__FILE__)))). "'> ";
  917. ///} else
  918. if($rk->nation <> '') {
  919. // the nation exist
  920. $img=strtolower($rk->nation).".png";
  921. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/domain.dat');
  922. foreach($lines as $line_num => $nation) {
  923. list($id,$title)=explode("|",$nation);
  924. if($id===$rk->nation) break;
  925. }
  926. print "".__('Http domain', 'newstatpress')." <IMG style='border:0px;height:16px;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/domain/'.$img, dirname(plugin_basename(__FILE__))). "'> ";
  927. } else {
  928. $ch = curl_init('http://api.hostip.info/country.php?ip='.$rk->ip);
  929. curl_setopt($ch, CURLOPT_HEADER, 0);
  930. curl_setopt($ch, CURLOPT_POST, 1);
  931. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  932. $output = curl_exec($ch);
  933. $output .=".png";
  934. $output = strtolower($output);
  935. curl_close($ch);
  936. print "".__('Hostip country','newstatpress'). "<IMG style='border:0px;width:18;height:12px;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/domain/'.$output, dirname(plugin_basename(__FILE__))). "'> ";
  937. }
  938. print "<strong><span><font size='2' color='#7b7b7b'>".$rk->ip."</font></span></strong> ";
  939. print "<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;' onClick=ttogle('".$rk->ip."');>".__('more info','newstatpress')."</s…

Large files files are truncated, but you can click here to view the full file