PageRenderTime 73ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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')."</span></div>";
  940. print "<div id='".$rk->ip."' name='".$rk->ip."'>";
  941. if(get_option('newstatpress_cryptip')!='checked') {
  942. print "<br><iframe style='overflow:hidden;border:0px;width:100%;height:60px;font-family:helvetica;padding:0;' scrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=".$rk->ip."></iframe>";
  943. }
  944. print "<br><small><span style='font-weight:700;'>OS or device:</span> ".$rk->os."</small>";
  945. print "<br><small><span style='font-weight:700;'>DNS Name:</span> ".gethostbyaddr($rk->ip)."</small>";
  946. print "<br><small><span style='font-weight:700;'>Browser:</span> ".$rk->browser."</small>";
  947. print "<br><small><span style='font-weight:700;'>Browser Detail:</span> ".$rk->agent."</small>";
  948. print "<br><br></div>";
  949. print "<script>document.getElementById('".$rk->ip."').style.display='none';</script>";
  950. print "</td></tr>";
  951. echo "<td valign='top' width='151'><div><font size='1' color='#3B3B3B'><strong>" . newstatpress_hdate($rk->date) . " " . $rk->time . "</strong></font></div></td>
  952. <td>" . newstatpress_Decode($rk->urlrequested) ."";
  953. if ($rk->searchengine != '') print "<br><small>".__('arrived from','newstatpress')." <b>" . $rk->searchengine . "</b> ".__('searching','newstatpress')." <a href='" . $rk->referrer . "' target=_blank>" . urldecode($rk->search) . "</a></small>";
  954. elseif ($rk->referrer != '' && strpos($rk->referrer, get_option('home')) === false) print "<br><small>".__('arrived from','newstatpress')." <a href='" . $rk->referrer . "' target=_blank>" . $rk->referrer . "</a></small>";
  955. echo "</div></td></tr>\n";
  956. $ip=$rk->ip;
  957. $num_row = 1;
  958. } elseif ($num_row < $LIMIT_PROOF) {
  959. echo "<tr><td valign='top' width='151'><div><font size='1' color='#3B3B3B'><strong>" . newstatpress_hdate($rk->date) . " " . $rk->time . "</strong></font></div></td>
  960. <td><div>" . newstatpress_Decode($rk->urlrequested) . "";
  961. if ($rk->searchengine != '') print "<br><small>".__('arrived from','newstatpress')." <b>" . $rk->searchengine . "</b> ".__('searching','newstatpress')." <a href='" . $rk->referrer . "' target=_blank>" . urldecode($rk->search) . "</a></small>";
  962. elseif ($rk->referrer != '' && strpos($rk->referrer, get_option('home')) === false) print "<br><small>".__('arrived from','newstatpress')." <a href='" . $rk->referrer . "' target=_blank>" . $rk->referrer . "</a></small>";
  963. $num_row += 1;
  964. echo "</div></td></tr>\n";
  965. }
  966. }
  967. echo "</div></td></tr>\n</table>";
  968. newstatpress_print_pp_link($NP,$pp,$action);
  969. echo "</div>";
  970. }
  971. /**
  972. * New spy bot function taken in statpress-visitors
  973. */
  974. function iriNewStatPressSpyBot() {
  975. global $wpdb;
  976. $action="spybot";
  977. $table_name = $wpdb->prefix . "statpress";
  978. $LIMIT = get_option('newstatpress_bot_per_page_spybot');
  979. $LIMIT_PROOF = get_option('newstatpress_visits_per_bot_spybot');
  980. if ($LIMIT ==0) $LIMIT = 10;
  981. if ($LIMIT_PROOF == 0) $LIMIT_PROOF = 30;
  982. $pa = newstatpress_page_posts();
  983. $LimitValue = ($pa * $LIMIT) - $LIMIT;
  984. // limit the search 7 days ago
  985. $day_ago = gmdate('Ymd', current_time('timestamp') - 7*86400);
  986. $MinId = $wpdb->get_var("
  987. SELECT min(id) as MinId
  988. FROM $table_name
  989. WHERE date > $day_ago
  990. ");
  991. // Number of distinct spiders after $day_ago
  992. $Num = $wpdb->get_var("
  993. SELECT count(distinct spider)
  994. FROM $table_name
  995. WHERE
  996. spider<>'' AND
  997. id >$MinId
  998. ");
  999. $NA = ceil($Num/$LIMIT);
  1000. echo "<div class='wrap'><h2>" . __('Spy Bot', 'newstatpress') . "</h2>";
  1001. // selection of spider, group by spider, order by most recently visit (last id in the table)
  1002. $sql = "
  1003. SELECT *
  1004. FROM $table_name as T1
  1005. JOIN
  1006. (SELECT spider,max(id) as MaxId
  1007. FROM $table_name
  1008. WHERE spider<>''
  1009. GROUP BY spider
  1010. ORDER BY MaxId
  1011. DESC LIMIT $LimitValue, $LIMIT
  1012. ) as T2
  1013. ON T1.spider = T2.spider
  1014. WHERE T1.id > $MinId
  1015. ORDER BY MaxId DESC, id DESC
  1016. ";
  1017. $qry = $wpdb->get_results($sql);
  1018. echo '<div align="center">';
  1019. newstatpress_print_pp_pa_link (0,0,$action,$NA,$pa);
  1020. echo '</div><div align="left">';
  1021. ?>
  1022. <script>
  1023. function ttogle(thediv){
  1024. if (document.getElementById(thediv).style.display=="inline") {
  1025. document.getElementById(thediv).style.display="none"
  1026. } else {document.getElementById(thediv).style.display="inline"}
  1027. }
  1028. </script>
  1029. <table id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4"><div align='left'>
  1030. <?php
  1031. $spider="robot";
  1032. $num_row=0;
  1033. foreach ($qry as $rk) { // Bot Spy
  1034. if ($robot <> $rk->spider) {
  1035. echo "<div align='left'>
  1036. <tr>
  1037. <td colspan='2' bgcolor='#dedede'>";
  1038. $img=str_replace(" ","_",strtolower($rk->spider));
  1039. $img=str_replace('.','',$img).".png";
  1040. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/spider.dat');
  1041. foreach($lines as $line_num => $spider) { //seeks the tooltip corresponding to the photo
  1042. list($title,$id)=explode("|",$spider);
  1043. if($title==$rk->spider) break; // break, the tooltip ($title) is found
  1044. }
  1045. echo "<IMG style='border:0px;height:16px;align:left;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/spider/'.$img, dirname(plugin_basename(__FILE__))). "'>
  1046. <span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;' onClick=ttogle('" . $img . "');>http more info</span>
  1047. <div id='" . $img . "' name='" . $img . "'><br /><small>" . $rk->ip . "</small><br><small>" . $rk->agent . "<br /></small></div>
  1048. <script>document.getElementById('" . $img . "').style.display='none';</script>
  1049. </tr>
  1050. <tr><td valign='top' width='170'><div><font size='1' color='#3B3B3B'><strong>" . newstatpress_hdate($rk->date) . " " . $rk->time . "</strong></font></div></td>
  1051. <td><div>" . newstatpress_Decode($rk->urlrequested) . "</div></td></tr>";
  1052. $robot=$rk->spider;
  1053. $num_row=1;
  1054. } elseif ($num_row < $LIMIT_PROOF) {
  1055. echo "<tr>
  1056. <td valign='top' width='170'><div><font size='1' color='#3B3B3B'><strong>" . newstatpress_hdate($rk->date) . " " . $rk->time . "</strong></font></div></td>
  1057. <td><div>" . newstatpress_Decode($rk->urlrequested) . "</div></td></tr>";
  1058. $num_row+=1;
  1059. }
  1060. echo "</div></td></tr>\n";
  1061. }
  1062. echo "</table>";
  1063. newstatpress_print_pp_pa_link (0,0,$action,$NA,$pa);
  1064. echo "</div>";
  1065. }
  1066. /**
  1067. * Newstatpress spy function
  1068. */
  1069. function iriNewStatPressSpy() {
  1070. global $wpdb;
  1071. $table_name = $wpdb->prefix . "statpress";
  1072. # Spy
  1073. $today = gmdate('Ymd', current_time('timestamp'));
  1074. $yesterday = gmdate('Ymd', current_time('timestamp')-86400);
  1075. print "<div class='wrap'><h2>".__('Spy','newstatpress')."</h2>";
  1076. $sql="
  1077. SELECT ip,nation,os,browser,agent
  1078. FROM $table_name
  1079. WHERE
  1080. spider='' AND
  1081. feed='' AND
  1082. date BETWEEN '$yesterday' AND '$today'
  1083. GROUP BY ip ORDER BY id DESC LIMIT 20";
  1084. $qry = $wpdb->get_results($sql);
  1085. ?>
  1086. <script>
  1087. function ttogle(thediv){
  1088. if (document.getElementById(thediv).style.display=="inline") {
  1089. document.getElementById(thediv).style.display="none"
  1090. } else {document.getElementById(thediv).style.display="inline"}
  1091. }
  1092. </script>
  1093. <div>
  1094. <table id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">
  1095. <?php
  1096. foreach ($qry as $rk) {
  1097. print "<tr><td colspan='2' bgcolor='#dedede'><div align='left'>";
  1098. if($rk->nation <> '') {
  1099. // the nation exist
  1100. $img=strtolower($rk->nation).".png";
  1101. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/domain.dat');
  1102. foreach($lines as $line_num => $nation) {
  1103. list($id,$title)=explode("|",$nation);
  1104. if($id===$rk->nation) break;
  1105. }
  1106. echo "<IMG style='border:0px;height:16px;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/domain/'.$img, dirname(plugin_basename(__FILE__))). "'> ";
  1107. } else {
  1108. $ch = curl_init('http://api.hostip.info/country.php?ip='.$rk->ip);
  1109. curl_setopt($ch, CURLOPT_HEADER, 0);
  1110. curl_setopt($ch, CURLOPT_POST, 1);
  1111. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1112. $output = curl_exec($ch);
  1113. $output .=".png";
  1114. $output = strtolower($output);
  1115. curl_close($ch);
  1116. echo "<IMG style='border:0px;width:18;height:12px;' alt='".$title."' title='".$title."' SRC='" .plugins_url('newstatpress/images/domain/'.$output, dirname(plugin_basename(__FILE__))). "'> ";
  1117. }
  1118. print " <strong><span><font size='2' color='#7b7b7b'>".$rk->ip."</font></span></strong> ";
  1119. print "<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;' onClick=ttogle('".$rk->ip."');>".__('more info','newstatpress')."</span></div>";
  1120. print "<div id='".$rk->ip."' name='".$rk->ip."'>";
  1121. if(get_option('newstatpress_cryptip')!='checked') {
  1122. print "<br><iframe style='overflow:hidden;border:0px;width:100%;height:60px;font-family:helvetica;padding:0;' scrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=".$rk->ip."></iframe>";
  1123. }
  1124. print "<br><small><span style='font-weight:700;'>OS or device:</span> ".$rk->os."</small>";
  1125. print "<br><small><span style='font-weight:700;'>DNS Name:</span> ".gethostbyaddr($rk->ip)."</small>";
  1126. print "<br><small><span style='font-weight:700;'>Browser:</span> ".$rk->browser."</small>";
  1127. print "<br><small><span style='font-weight:700;'>Browser Detail:</span> ".$rk->agent."</small>";
  1128. print "<br><br></div>";
  1129. print "<script>document.getElementById('".$rk->ip."').style.display='none';</script>";
  1130. print "</td></tr>";
  1131. $qry2=$wpdb->get_results("
  1132. SELECT *
  1133. FROM $table_name
  1134. WHERE
  1135. ip='".$rk->ip."' AND
  1136. (date BETWEEN '$yesterday' AND '$today')
  1137. ORDER BY id
  1138. LIMIT 10"
  1139. );
  1140. foreach ($qry2 as $details) {
  1141. print "<tr>";
  1142. print "<td valign='top' width='151'><div><font size='1' color='#3B3B3B'><strong>".irihdate($details->date)." ".$details->time."</strong></font></div></td>";
  1143. print "<td><div><a href='".get_bloginfo('url')."/?".$details->urlrequested."' target='_blank'>".iri_NewStatPress_Decode($details->urlrequested)."</a>";
  1144. if($details->searchengine != '') {
  1145. print "<br><small>".__('arrived from','newstatpress')." <b>".$details->searchengine."</b> ".__('searching','newstatpress')." <a href='".$details->referrer."' target='_blank'>".$details->search."</a></small>";
  1146. } elseif($details->referrer != '' && strpos($details->referrer,get_option('home'))===FALSE) {
  1147. print "<br><small>".__('arrived from','newstatpress')." <a href='".$details->referrer."' target='_blank'>".$details->referrer."</a></small>";
  1148. }
  1149. print "</div></td>";
  1150. print "</tr>\n";
  1151. }
  1152. }
  1153. ?>
  1154. </table>
  1155. </div>
  1156. <?php
  1157. }
  1158. /**
  1159. * Check if the argoument is an IP addresses
  1160. *
  1161. * @param ip the ip to check
  1162. * @return TRUE if it is an ip
  1163. */
  1164. function iri_CheckIP($ip) {
  1165. return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
  1166. }
  1167. function iriNewStatPressSearch($what='') {
  1168. global $wpdb;
  1169. $table_name = $wpdb->prefix . "statpress";
  1170. $f['urlrequested']=__('URL Requested','newstatpress');
  1171. $f['agent']=__('Agent','newstatpress');
  1172. $f['referrer']=__('Referrer','newstatpress');
  1173. $f['search']=__('Search terms','newstatpress');
  1174. $f['searchengine']=__('Search engine','newstatpress');
  1175. $f['os']=__('Operative system','newstatpress');
  1176. $f['browser']="Browser";
  1177. $f['spider']="Spider";
  1178. $f['ip']="IP";
  1179. ?>
  1180. <div class='wrap'><h2><?php _e('Search','newstatpress'); ?></h2>
  1181. <form method=get><table>
  1182. <?php
  1183. for($i=1;$i<=3;$i++) {
  1184. print "<tr>";
  1185. print "<td>".__('Field','newstatpress')." <select name=where$i><option value=''></option>";
  1186. foreach ( array_keys($f) as $k ) {
  1187. print "<option value='$k'";
  1188. if($_GET["where$i"] == $k) { print " SELECTED "; }
  1189. print ">".$f[$k]."</option>";
  1190. }
  1191. print "</select></td>";
  1192. if (isset($_GET["groupby$i"])) print "<td><input type=checkbox name=groupby$i value='checked' ".$_GET["groupby$i"]."> ".__('Group by','newstatpress')."</td>";
  1193. else print "<td><input type=checkbox name=groupby$i value='checked' "."> ".__('Group by','newstatpress')."</td>";
  1194. if (isset($_GET["sortby$i"])) print "<td><input type=checkbox name=sortby$i value='checked' ".$_GET["sortby$i"]."> ".__('Sort by','newstatpress')."</td>";
  1195. else print "<td><input type=checkbox name=sortby$i value='checked' "."> ".__('Sort by','newstatpress')."</td>";
  1196. print "<td>, ".__('if contains','newstatpress')." <input type=text name=what$i value='".$_GET["what$i"]."'></td>";
  1197. print "</tr>";
  1198. }
  1199. ?>
  1200. </table>
  1201. <br>
  1202. <table>
  1203. <tr>
  1204. <td>
  1205. <table>
  1206. <tr><td><input type=checkbox name=oderbycount value=checked <?php print $_GET['oderbycount'] ?>> <?php _e('sort by count if grouped','newstatpress'); ?></td></tr>
  1207. <tr><td><input type=checkbox name=spider value=checked <?php print $_GET['spider'] ?>> <?php _e('include spiders/crawlers/bot','newstatpress'); ?></td></tr>
  1208. <tr><td><input type=checkbox name=feed value=checked <?php print $_GET['feed'] ?>> <?php _e('include feed','newstatpress'); ?></td></tr>
  1209. </table>
  1210. </td>
  1211. <td width=15> </td>
  1212. <td>
  1213. <table>
  1214. <tr>
  1215. <td><?php _e('Limit results to','newstatpress'); ?>
  1216. <select name=limitquery><?php if($_GET['limitquery'] >0) { print "<option>".$_GET['limitquery']."</option>";} ?><option>1</option><option>5</option><option>10</option><option>20</option><option>50</option></select>
  1217. </td>
  1218. </tr>
  1219. <tr><td>&nbsp;</td></tr>
  1220. <tr>
  1221. <td align=right><input type=submit value=<?php _e('Search','newstatpress'); ?> name=searchsubmit></td>
  1222. </tr>
  1223. </table>
  1224. </td>
  1225. </tr>
  1226. </table>
  1227. <input type=hidden name=page value='newstatpress/newstatpress.php'><input type=hidden name=newstatpress_action value=search>
  1228. </form><br>
  1229. <?php
  1230. if(isset($_GET['searchsubmit'])) {
  1231. # query builder
  1232. $qry="";
  1233. # FIELDS
  1234. $fields="";
  1235. for($i=1;$i<=3;$i++) {
  1236. if($_GET["where$i"] != '') {
  1237. $fields.=$_GET["where$i"].",";
  1238. }
  1239. }
  1240. $fields=rtrim($fields,",");
  1241. # WHERE
  1242. $where="WHERE 1=1";
  1243. if (!isset($_GET['spider'])) { $where.=" AND spider=''"; }
  1244. else if($_GET['spider'] != 'checked') { $where.=" AND spider=''"; }
  1245. if (!isset($_GET['feed'])) { $where.=" AND feed=''"; }
  1246. else if($_GET['feed'] != 'checked') { $where.=" AND feed=''"; }
  1247. for($i=1;$i<=3;$i++) {
  1248. if(($_GET["what$i"] != '') && ($_GET["where$i"] != '')) {
  1249. $where.=" AND ".$_GET["where$i"]." LIKE '%".$_GET["what$i"]."%'";
  1250. }
  1251. }
  1252. # ORDER BY
  1253. $orderby="";
  1254. for($i=1;$i<=3;$i++) {
  1255. if (isset($_GET["sortby$i"]) && ($_GET["sortby$i"] == 'checked') && ($_GET["where$i"] != '')) {
  1256. $orderby.=$_GET["where$i"].',';
  1257. }
  1258. }
  1259. # GROUP BY
  1260. $groupby="";
  1261. for($i=1;$i<=3;$i++) {
  1262. if(isset($_GET["groupby$i"]) && ($_GET["groupby$i"] == 'checked') && ($_GET["where$i"] != '')) {
  1263. $groupby.=$_GET["where$i"].',';
  1264. }
  1265. }
  1266. if($groupby != '') {
  1267. $groupby="GROUP BY ".rtrim($groupby,',');
  1268. $fields.=",count(*) as totale";
  1269. if(isset($_GET["oderbycount"]) && $_GET['oderbycount'] == 'checked') { $orderby="totale DESC,".$orderby; }
  1270. }
  1271. if($orderby != '') { $orderby="ORDER BY ".rtrim($orderby,','); }
  1272. $limit="LIMIT ".$_GET['limitquery'];
  1273. # Results
  1274. print "<h2>".__('Results','newstatpress')."</h2>";
  1275. $sql="SELECT $fields FROM $table_name $where $groupby $orderby $limit;";
  1276. //print "$sql<br>";
  1277. print "<table class='widefat'><thead><tr>";
  1278. for($i=1;$i<=3;$i++) {
  1279. if($_GET["where$i"] != '') { print "<th scope='col'>".ucfirst($_GET["where$i"])."</th>"; }
  1280. }
  1281. if($groupby != '') { print "<th scope='col'>".__('Count','newstatpress')."</th>"; }
  1282. print "</tr></thead><tbody id='the-list'>";
  1283. $qry=$wpdb->get_results($sql,ARRAY_N);
  1284. foreach ($qry as $rk) {
  1285. print "<tr>";
  1286. for($i=1;$i<=3;$i++) {
  1287. print "<td>";
  1288. if($_GET["where$i"] == 'urlrequested') { print iri_NewStatPress_Decode($rk[$i-1]); }
  1289. else { if(isset($rk[$i-1])) print $rk[$i-1]; }
  1290. print "</td>";
  1291. }
  1292. print "</tr>";
  1293. }
  1294. print "</table>";
  1295. print "<br /><br /><font size=1 color=gray>sql: $sql</font></div>";
  1296. }
  1297. }
  1298. function iri_NewStatPress_Abbrevia($s,$c) {
  1299. $res=""; if(strlen($s)>$c) { $res="..."; }
  1300. return substr($s,0,$c).$res;
  1301. }
  1302. function iri_NewStatPress_Decode($out_url) {
  1303. if($out_url == '') { $out_url=__('Page','newstatpress').": Home"; }
  1304. if(substr($out_url,0,4)=="cat=") { $out_url=__('Category','newstatpress').": ".get_cat_name(substr($out_url,4)); }
  1305. if(substr($out_url,0,2)=="m=") { $out_url=__('Calendar','newstatpress').": ".substr($out_url,6,2)."/".substr($out_url,2,4); }
  1306. if(substr($out_url,0,2)=="s=") { $out_url=__('Search','newstatpress').": ".substr($out_url,2); }
  1307. if(substr($out_url,0,2)=="p=") {
  1308. $post_id_7 = get_post(substr($out_url,2), ARRAY_A);
  1309. $out_url = $post_id_7['post_title'];
  1310. }
  1311. if(substr($out_url,0,8)=="page_id=") {
  1312. $post_id_7=get_page(substr($out_url,8), ARRAY_A);
  1313. $out_url = __('Page','newstatpress').": ".$post_id_7['post_title'];
  1314. }
  1315. return $out_url;
  1316. }
  1317. function iri_NewStatPress_URL() {
  1318. $urlRequested = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '' );
  1319. if ( $urlRequested == "" ) { // SEO problem!
  1320. $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '' );
  1321. }
  1322. if(substr($urlRequested,0,2) == '/?') { $urlRequested=substr($urlRequested,2); }
  1323. if($urlRequested == '/') { $urlRequested=''; }
  1324. return $urlRequested;
  1325. }
  1326. # Converte da data us to default format di Wordpress
  1327. function irihdate($dt = "00000000") {
  1328. return mysql2date(get_option('date_format'), substr($dt,0,4)."-".substr($dt,4,2)."-".substr($dt,6,2));
  1329. }
  1330. function iritablesize($table) {
  1331. global $wpdb;
  1332. $res = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table'");
  1333. foreach ($res as $fstatus) {
  1334. $data_lenght = $fstatus->Data_length;
  1335. $data_rows = $fstatus->Rows;
  1336. }
  1337. return number_format(($data_lenght/1024/1024), 2, ",", " ")." Mb ($data_rows records)";
  1338. }
  1339. function iriindextablesize($table) {
  1340. global $wpdb;
  1341. $res = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table'");
  1342. foreach ($res as $fstatus) {
  1343. $index_lenght = $fstatus->Index_length;
  1344. }
  1345. return number_format(($index_lenght/1024/1024), 2, ",", " ")." Mb";
  1346. }
  1347. function iriValueTable2($fld,$fldtitle,$limit = 0,$param = "", $queryfld = "", $exclude= "", $print = TRUE) {
  1348. global $wpdb;
  1349. $table_name = $wpdb->prefix . "statpress";
  1350. if ($queryfld == '') {
  1351. $queryfld = $fld;
  1352. }
  1353. $text = "<div class='wrap'><table class='widefat'><thead><tr><th scope='col' style='width:400px;'><h2>$fldtitle</h2></th><th scope='col' style='width:100px;'>".__('Visits','newstatpress')."</th><th></th></tr></thead>";
  1354. $rks = $wpdb->get_var("
  1355. SELECT count($param $queryfld) as rks
  1356. FROM $table_name
  1357. WHERE 1=1 $exclude;
  1358. ");
  1359. if($rks > 0) {
  1360. $sql="
  1361. SELECT count($param $queryfld) as pageview, $fld
  1362. FROM $table_name
  1363. WHERE 1=1 $exclude
  1364. GROUP BY $fld
  1365. ORDER BY pageview DESC
  1366. ";
  1367. if($limit > 0) {
  1368. $sql=$sql." LIMIT $limit";
  1369. }
  1370. $qry = $wpdb->get_results($sql);
  1371. $tdwidth=450;
  1372. // Collects data
  1373. $data=array();
  1374. foreach ($qry as $rk) {
  1375. $pc=round(($rk->pageview*100/$rks),1);
  1376. if($fld == 'nation') { $rk->$fld = strtoupper($rk->$fld); }
  1377. if($fld == 'date') { $rk->$fld = irihdate($rk->$fld); }
  1378. if($fld == 'urlrequested') { $rk->$fld = iri_NewStatPress_Decode($rk->$fld); }
  1379. $data[substr($rk->$fld,0,50)]=$rk->pageview;
  1380. }
  1381. }
  1382. // Draw table body
  1383. $text = $text."<tbody id='the-list'>";
  1384. if($rks > 0) { // Chart!
  1385. if($fld == 'nation') {
  1386. $chart=iriGoogleGeo("","",$data);
  1387. } else {
  1388. $chart=iriGoogleChart("","500x200",$data);
  1389. }
  1390. $text = $text. "<tr><td></td><td></td><td rowspan='".($limit+2)."'>$chart</td></tr>";
  1391. foreach ($data as $key => $value) {
  1392. $text = $text."<tr><td style='width:500px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>".$key;
  1393. $text = $text."</td><td style='width:100px;text-align:center;'>".$value."</td>";
  1394. $text = $text."</tr>";
  1395. }
  1396. }
  1397. $text = $text."</tbody></table></div><br>\n";
  1398. if ($print) print $text;
  1399. else return $text;
  1400. }
  1401. function iriGetLanguage($accepted) {
  1402. return substr($accepted,0,2);
  1403. }
  1404. function iriGetQueryPairs($url){
  1405. $parsed_url = parse_url($url);
  1406. $tab=parse_url($url);
  1407. $host = $tab['host'];
  1408. if(key_exists("query",$tab)){
  1409. $query=$tab["query"];
  1410. return explode("&",$query);
  1411. }
  1412. else{return null;}
  1413. }
  1414. /**
  1415. * Get OS from the given argument
  1416. *
  1417. * @param arg the argument to parse for OS
  1418. * @return the OS find in configuration file
  1419. */
  1420. function iriGetOS($arg) {
  1421. $arg=str_replace(" ","",$arg);
  1422. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/os.dat');
  1423. foreach($lines as $line_num => $os) {
  1424. list($nome_os,$id_os)=explode("|",$os);
  1425. if(strpos($arg,$id_os)===FALSE) continue;
  1426. return $nome_os; // fount
  1427. }
  1428. return '';
  1429. }
  1430. /**
  1431. * Get Browser from the given argument
  1432. *
  1433. * @param arg the argument to parse for Brower
  1434. * @return the Browser find in configuration file
  1435. */
  1436. function iriGetBrowser($arg) {
  1437. $arg=str_replace(" ","",$arg);
  1438. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/browser.dat');
  1439. foreach($lines as $line_num => $browser) {
  1440. list($nome,$id)=explode("|",$browser);
  1441. if(strpos($arg,$id)===FALSE) continue;
  1442. return $nome; // fount
  1443. }
  1444. return '';
  1445. }
  1446. function iriCheckBanIP($arg){
  1447. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/banips.dat');
  1448. foreach($lines as $line_num => $banip) {
  1449. if(strpos($arg,rtrim($banip,"\n"))===FALSE) continue;
  1450. return ''; // riconosciuto, da scartare
  1451. }
  1452. return $arg;
  1453. }
  1454. function iriGetSE($referrer = null){
  1455. $key = null;
  1456. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/searchengines.dat');
  1457. foreach($lines as $line_num => $se) {
  1458. list($nome,$url,$key)=explode("|",$se);
  1459. if(strpos($referrer,$url)===FALSE) continue;
  1460. # trovato se
  1461. $variables = iriGetQueryPairs(html_entity_decode($referrer));
  1462. $i = count($variables);
  1463. while($i--){
  1464. $tab=explode("=",$variables[$i]);
  1465. if($tab[0] == $key){return ($nome."|".urldecode($tab[1]));}
  1466. }
  1467. }
  1468. return null;
  1469. }
  1470. /**
  1471. * Get the spider from the given agent
  1472. *
  1473. * @param agent the agent string
  1474. * @return agent the fount agent
  1475. */
  1476. function iriGetSpider($agent = null){
  1477. $agent=str_replace(" ","",$agent);
  1478. $key = null;
  1479. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/spider.dat');
  1480. foreach($lines as $line_num => $spider) {
  1481. list($nome,$key)=explode("|",$spider);
  1482. if(strpos($agent,$key)===FALSE) continue;
  1483. # fount
  1484. return $nome;
  1485. }
  1486. return null;
  1487. }
  1488. function iri_NewStatPress_lastmonth() {
  1489. $ta = getdate(current_time('timestamp'));
  1490. $year = $ta['year'];
  1491. $month = $ta['mon'];
  1492. --$month; // go back 1 month
  1493. if( $month === 0 ): // if this month is Jan
  1494. --$year; // go back a year
  1495. $month = 12; // last month is Dec
  1496. endif;
  1497. // return in format 'YYYYMM'
  1498. return sprintf( $year.'%02d', $month);
  1499. }
  1500. /**
  1501. * Create or update the table
  1502. */
  1503. function iri_NewStatPress_CreateTable() {
  1504. global $wpdb;
  1505. global $wp_db_version;
  1506. $table_name = $wpdb->prefix . "statpress";
  1507. $sql_createtable = "
  1508. CREATE TABLE " . $table_name . " (
  1509. id mediumint(9) NOT NULL AUTO_INCREMENT,
  1510. date int(8),
  1511. time time,
  1512. ip varchar(15),
  1513. urlrequested varchar(250),
  1514. agent varchar(250),
  1515. referrer varchar(250),
  1516. search varchar(250),
  1517. nation varchar(2),
  1518. os varchar(30),
  1519. browser varchar(32),
  1520. searchengine varchar(16),
  1521. spider varchar(32),
  1522. feed varchar(8),
  1523. user varchar(16),
  1524. timestamp timestamp DEFAULT 0,
  1525. UNIQUE KEY id (id),
  1526. index spider_nation (spider, nation),
  1527. index ip_date (ip, date),
  1528. index agent (agent),
  1529. index search (search),
  1530. index referrer (referrer),
  1531. index feed_spider_os (feed, spider, os),
  1532. index os (os),
  1533. index date_feed_spider (date, feed, spider),
  1534. index feed_spider_browser (feed, spider, browser),
  1535. index browser (browser)
  1536. );";
  1537. if($wp_db_version >= 5540) $page = 'wp-admin/includes/upgrade.php';
  1538. else $page = 'wp-admin/upgrade'.'-functions.php';
  1539. require_once(ABSPATH . $page);
  1540. dbDelta($sql_createtable);
  1541. }
  1542. function iri_NewStatPress_is_feed($url) {
  1543. if (stristr($url,get_bloginfo('rdf_url')) != FALSE) { return 'RDF'; }
  1544. if (stristr($url,get_bloginfo('rss2_url')) != FALSE) { return 'RSS2'; }
  1545. if (stristr($url,get_bloginfo('rss_url')) != FALSE) { return 'RSS'; }
  1546. if (stristr($url,get_bloginfo('atom_url')) != FALSE) { return 'ATOM'; }
  1547. if (stristr($url,get_bloginfo('comments_rss2_url')) != FALSE) { return 'COMMENT'; }
  1548. if (stristr($url,get_bloginfo('comments_atom_url')) != FALSE) { return 'COMMENT'; }
  1549. if (stristr($url,'wp-feed.php') != FALSE) { return 'RSS2'; }
  1550. if (stristr($url,'/feed/') != FALSE) { return 'RSS2'; }
  1551. return '';
  1552. }
  1553. /**
  1554. * Insert statistic into the database
  1555. */
  1556. function iriStatAppend() {
  1557. global $wpdb;
  1558. $table_name = $wpdb->prefix . "statpress";
  1559. global $userdata;
  1560. global $_STATPRESS;
  1561. get_currentuserinfo();
  1562. $feed='';
  1563. // Time
  1564. $timestamp = current_time('timestamp');
  1565. $vdate = gmdate("Ymd",$timestamp);
  1566. $vtime = gmdate("H:i:s",$timestamp);
  1567. $timestamp = date('Y-m-d H:i:s', $timestamp);
  1568. // IP
  1569. $ipAddress = $_SERVER['REMOTE_ADDR'];
  1570. // Is this IP blacklisted from file?
  1571. if(iriCheckBanIP($ipAddress) == '') { return ''; }
  1572. // Is this IP blacklisted from user?
  1573. $to_ignore = get_option('newstatpress_ignore_ip', array());
  1574. foreach($to_ignore as $a_ip_range){
  1575. list ($ip_to_ignore, $mask) = @explode("/", trim($a_ip_range));
  1576. if (empty($mask)) $mask = 32;
  1577. $long_ip_to_ignore = ip2long($ip_to_ignore);
  1578. $long_mask = bindec( str_pad('', $mask, '1') . str_pad('', 32-$mask, '0') );
  1579. $long_masked_user_ip = $ipAddress & $long_mask;
  1580. $long_masked_ip_to_ignore = $long_ip_to_ignore & $long_mask;
  1581. if ($long_masked_user_ip == $long_masked_ip_to_ignore) { return ''; }
  1582. }
  1583. if(get_option('newstatpress_cryptip')=='checked') {
  1584. $ipAddress = crypt($ipAddress,'newstatpress');
  1585. }
  1586. // URL (requested)
  1587. $urlRequested=iri_NewStatPress_URL();
  1588. if (preg_match("/.ico$/i", $urlRequested)) { return ''; }
  1589. if (preg_match("/favicon.ico/i", $urlRequested)) { return ''; }
  1590. if (preg_match("/.css$/i", $urlRequested)) { return ''; }
  1591. if (preg_match("/.js$/i", $urlRequested)) { return ''; }
  1592. if (stristr($urlRequested,"/wp-content/plugins") != FALSE) { return ''; }
  1593. if (stristr($urlRequested,"/wp-content/themes") != FALSE) { return ''; }
  1594. if (stristr($urlRequested,"/wp-admin/") != FALSE) { return ''; }
  1595. // Is a given permalink blacklisted?
  1596. $to_ignore = get_option('newstatpress_ignore_permalink', array());
  1597. foreach($to_ignore as $a_filter){
  1598. if (!empty($urlRequested) && strpos($urlRequested, $a_filter) === 0) { return ''; }
  1599. }
  1600. $referrer = (isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '');
  1601. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '');
  1602. $spider=iriGetSpider($userAgent);
  1603. if(($spider != '') and (get_option('newstatpress_donotcollectspider')=='checked')) { return ''; }
  1604. if($spider != '') {
  1605. $os=''; $browser='';
  1606. } else {
  1607. // Trap feeds
  1608. $feed=iri_NewStatPress_is_feed(get_bloginfo('url').$_SERVER['REQUEST_URI']);
  1609. // Get OS and browser
  1610. $os=iriGetOS($userAgent);
  1611. $browser=iriGetBrowser($userAgent);
  1612. list($searchengine,$search_phrase)=explode("|",iriGetSE($referrer));
  1613. }
  1614. // Country (ip2nation table) or language
  1615. $countrylang="";
  1616. if($wpdb->get_var("SHOW TABLES LIKE 'ip2nation'") == 'ip2nation') {
  1617. $sql='SELECT *
  1618. FROM ip2nation
  1619. WHERE ip < INET_ATON("'.$ipAddress.'")
  1620. ORDER BY ip DESC
  1621. LIMIT 0,1';
  1622. $qry = $wpdb->get_row($sql);
  1623. $countrylang=$qry->country;
  1624. }
  1625. if($countrylang == '') {
  1626. $countrylang=iriGetLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  1627. }
  1628. // Auto-delete visits if...
  1629. if(get_option('newstatpress_autodelete') != '') {
  1630. $t=gmdate("Ymd",strtotime('-'.get_option('newstatpress_autodelete')));
  1631. $results =$wpdb->query( "DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
  1632. }
  1633. if ((!is_user_logged_in()) OR (get_option('newstatpress_collectloggeduser')=='checked')) {
  1634. if (is_user_logged_in() AND (get_option('newstatpress_collectloggeduser')=='checked')) {
  1635. $current_user = wp_get_current_user();
  1636. // Is a given name to ignore?
  1637. $to_ignore = get_option('newstatpress_ignore_users', array());
  1638. foreach($to_ignore as $a_filter) {
  1639. if ($current_user->user_login == $a_filter) { return ''; }
  1640. }
  1641. }
  1642. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  1643. iri_NewStatPress_CreateTable();
  1644. }
  1645. $insert =
  1646. "INSERT INTO " . $table_name . "(
  1647. date,
  1648. time,
  1649. ip,
  1650. urlrequested,
  1651. agent,
  1652. referrer,
  1653. search,
  1654. nation,
  1655. os,
  1656. browser,
  1657. searchengine,
  1658. spider,
  1659. feed,
  1660. user,
  1661. timestamp
  1662. ) VALUES (
  1663. '$vdate',
  1664. '$vtime',
  1665. '$ipAddress',
  1666. '$urlRequested',
  1667. '".addslashes(strip_tags($userAgent))."',
  1668. '$referrer','" .
  1669. addslashes(strip_tags($search_phrase))."',
  1670. '".$countrylang."',
  1671. '$os',
  1672. '$browser',
  1673. '$searchengine',
  1674. '$spider',
  1675. '$feed',
  1676. '$userdata->user_login',
  1677. '$timestamp'
  1678. )";
  1679. $results = $wpdb->query( $insert );
  1680. }
  1681. }
  1682. /**
  1683. * Get the days a use has choice for updating the database
  1684. *
  1685. * @return the number of days of -1 for all days
  1686. */
  1687. function iriNewStatPressDays() {
  1688. $days=-1; // infinite in the past
  1689. // Get Current page periode from URL
  1690. $updateint =get_option('newstatpress_updateint');
  1691. if ($updateint=="1 week") $days=7;
  1692. elseif ($updateint=="2 weeks") $days=14;
  1693. elseif ($updateint=="3 weeks") $days=21;
  1694. elseif ($updateint=="1 month") $days=30;
  1695. elseif ($updateint=="2 months") $days=60;
  1696. elseif ($updateint=="3 months") $days=90;
  1697. elseif ($updateint=="6 months") $days=180;
  1698. elseif ($updateint=="9 months") $days=270;
  1699. elseif ($updateint=="1 year") $days=365;
  1700. return $days;
  1701. }
  1702. /**
  1703. * Performes database update with new definitions
  1704. */
  1705. function iriNewStatPressUpdate() {
  1706. global $wpdb;
  1707. $table_name = $wpdb->prefix . "statpress";
  1708. $wpdb->flush(); // flush for counting right the queries
  1709. $start_time = microtime(true);
  1710. $days=iriNewStatPressDays(); // get the number of days for the update
  1711. $to_date = gmdate("Ymd",current_time('timestamp'));
  1712. if ($days==-1) $from_date= "19990101"; // use a date where this plugin was not present
  1713. else $from_date = gmdate('Ymd', current_time('timestamp')-86400*$days);
  1714. $_newstatpress_url=PluginUrl();
  1715. $wpdb->show_errors();
  1716. print "<div class='wrap'><table class='widefat'><thead><tr><th scope='col'><h2>".__('Updating...','newstatpress')."</h2></th><th scope='col' style='width:150px;'>".__('Size','newstatpress')."</th><th scope='col' style='width:100px;'>".__('Result','newstatpress')."</th><th></th></tr></thead>";
  1717. print "<tbody id='the-list'>";
  1718. # check if ip2nation .sql file exists
  1719. if(file_exists(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql')) {
  1720. print "<tr><td>ip2nation.sql</td>";
  1721. $FP = fopen (ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql', 'r' );
  1722. $READ = fread ( $FP, filesize (ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql') );
  1723. $READ = explode ( ";\n", $READ );
  1724. foreach ( $READ as $RED ) {
  1725. if($RES != '') { $wpdb->query($RED); }
  1726. }
  1727. print "<td>".iritablesize("ip2nation")."</td>";
  1728. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1729. }
  1730. # update table
  1731. print "<tr><td>Struct $table_name</td>";
  1732. iri_NewStatPress_CreateTable();
  1733. print "<td>".iritablesize($wpdb->prefix."statpress")."</td>";
  1734. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1735. print "<tr><td>Index $table_name</td>";
  1736. print "<td>".iriindextablesize($wpdb->prefix."statpress")."</td>";
  1737. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1738. # Update Feed
  1739. print "<tr><td>Feeds</td>";
  1740. $wpdb->query("
  1741. UPDATE $table_name
  1742. SET feed=''
  1743. WHERE date BETWEEN $from_date AND $to_date;"
  1744. );
  1745. # not standard
  1746. $wpdb->query("
  1747. UPDATE $table_name
  1748. SET feed='RSS2'
  1749. WHERE
  1750. urlrequested LIKE '%/feed/%' AND
  1751. date BETWEEN $from_date AND $to_date;"
  1752. );
  1753. $wpdb->query("
  1754. UPDATE $table_name
  1755. SET feed='RSS2'
  1756. WHERE
  1757. urlrequested LIKE '%wp-feed.php%' AND
  1758. date BETWEEN $from_date AND $to_date;"
  1759. );
  1760. # standard blog info urls
  1761. $s=iriNewStatPress_extractfeedreq(get_bloginfo('comments_atom_url'));
  1762. if($s != '') {
  1763. $wpdb->query("
  1764. UPDATE $table_name
  1765. SET feed='COMMENT'
  1766. WHERE
  1767. INSTR(urlrequested,'$s')>0 AND
  1768. date BETWEEN $from_date AND $to_date;"
  1769. );
  1770. }
  1771. $s=iriNewStatPress_extractfeedreq(get_bloginfo('comments_rss2_url'));
  1772. if($s != '') {
  1773. $wpdb->query("
  1774. UPDATE $table_name
  1775. SET feed='COMMENT'
  1776. WHERE
  1777. INSTR(urlrequested,'$s')>0 AND
  1778. date BETWEEN $from_date AND $to_date;"
  1779. );
  1780. }
  1781. $s=iriNewStatPress_extractfeedreq(get_bloginfo('atom_url'));
  1782. if($s != '') {
  1783. $wpdb->query("
  1784. UPDATE $table_name
  1785. SET feed='ATOM'
  1786. WHERE
  1787. INSTR(urlrequested,'$s')>0 AND
  1788. date BETWEEN $from_date AND $to_date;"
  1789. );
  1790. }
  1791. $s=iriNewStatPress_extractfeedreq(get_bloginfo('rdf_url'));
  1792. if($s != '') {
  1793. $wpdb->query("
  1794. UPDATE $table_name
  1795. SET feed='RDF'
  1796. WHERE
  1797. INSTR(urlrequested,'$s')>0 AND
  1798. date BETWEEN $from_date AND $to_date;"
  1799. );
  1800. }
  1801. $s=iriNewStatPress_extractfeedreq(get_bloginfo('rss_url'));
  1802. if($s != '') {
  1803. $wpdb->query("
  1804. UPDATE $table_name
  1805. SET feed='RSS'
  1806. WHERE
  1807. INSTR(urlrequested,'$s')>0 AND
  1808. date BETWEEN $from_date AND $to_date;"
  1809. );
  1810. }
  1811. $s=iriNewStatPress_extractfeedreq(get_bloginfo('rss2_url'));
  1812. if($s != '') {
  1813. $wpdb->query("
  1814. UPDATE $table_name
  1815. SET feed='RSS2'
  1816. WHERE
  1817. INSTR(urlrequested,'$s')>0 AND
  1818. date BETWEEN $from_date AND $to_date;"
  1819. );
  1820. }
  1821. $wpdb->query("
  1822. UPDATE $table_name
  1823. SET feed = ''
  1824. WHERE
  1825. isnull(feed) AND
  1826. date BETWEEN $from_date AND $to_date;"
  1827. );
  1828. print "<td></td>";
  1829. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1830. # Update OS
  1831. print "<tr><td>OSes</td>";
  1832. $wpdb->query("
  1833. UPDATE $table_name
  1834. SET os = ''
  1835. WHERE date BETWEEN $from_date AND $to_date;"
  1836. );
  1837. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/os.dat');
  1838. foreach($lines as $line_num => $os) {
  1839. list($nome_os,$id_os)=explode("|",$os);
  1840. $qry="
  1841. UPDATE $table_name
  1842. SET os = '$nome_os'
  1843. WHERE
  1844. os='' AND
  1845. replace(agent,' ','') LIKE '%".$id_os."%' AND
  1846. date BETWEEN $from_date AND $to_date;";
  1847. $wpdb->query($qry);
  1848. }
  1849. print "<td></td>";
  1850. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1851. # Update Browser
  1852. print "<tr><td>Browsers</td>";
  1853. $wpdb->query("
  1854. UPDATE $table_name
  1855. SET browser = ''
  1856. WHERE date BETWEEN $from_date AND $to_date;"
  1857. );
  1858. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/browser.dat');
  1859. foreach($lines as $line_num => $browser) {
  1860. list($nome,$id)=explode("|",$browser);
  1861. $qry="
  1862. UPDATE $table_name
  1863. SET browser = '$nome'
  1864. WHERE
  1865. browser='' AND
  1866. replace(agent,' ','') LIKE '%".$id."%' AND
  1867. date BETWEEN $from_date AND $to_date;";
  1868. $wpdb->query($qry);
  1869. }
  1870. print "<td></td>";
  1871. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1872. # Update Spider
  1873. print "<tr><td>Spiders</td>";
  1874. $wpdb->query("
  1875. UPDATE $table_name
  1876. SET spider = ''
  1877. WHERE date BETWEEN $from_date AND $to_date;"
  1878. );
  1879. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/spider.dat');
  1880. foreach($lines as $line_num => $spider) {
  1881. list($nome,$id)=explode("|",$spider);
  1882. $qry="
  1883. UPDATE $table_name
  1884. SET spider = '$nome',os='',browser=''
  1885. WHERE
  1886. spider='' AND
  1887. replace(agent,' ','') LIKE '%".$id."%' AND
  1888. date BETWEEN $from_date AND $to_date;";
  1889. $wpdb->query($qry);
  1890. }
  1891. print "<td></td>";
  1892. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1893. # Update Search engine
  1894. print "<tr><td>Search engines</td>";
  1895. $wpdb->query("
  1896. UPDATE $table_name
  1897. SET searchengine = '', search=''
  1898. WHERE date BETWEEN $from_date AND $to_date;");
  1899. $qry = $wpdb->get_results("
  1900. SELECT id, referrer
  1901. FROM $table_name
  1902. WHERE
  1903. length(referrer)!=0 AND
  1904. date BETWEEN $from_date AND $to_date");
  1905. foreach ($qry as $rk) {
  1906. list($searchengine,$search_phrase)=explode("|",iriGetSE($rk->referrer));
  1907. if($searchengine <> '') {
  1908. $q="
  1909. UPDATE $table_name
  1910. SET searchengine = '$searchengine', search='".addslashes($search_phrase)."'
  1911. WHERE
  1912. id=".$rk->id." AND
  1913. date BETWEEN $from_date AND $to_date;";
  1914. $wpdb->query($q);
  1915. }
  1916. }
  1917. print "<td></td>";
  1918. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1919. $end_time = microtime(true);
  1920. $sql_queries=$wpdb->num_queries;
  1921. # Final statistics
  1922. print "<tr><td>Final Struct $table_name</td>";
  1923. print "<td>".iritablesize($wpdb->prefix."statpress")."</td>";
  1924. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1925. print "<tr><td>Final Index $table_name</td>";
  1926. print "<td>".iriindextablesize($wpdb->prefix."statpress")."</td>";
  1927. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1928. print "<tr><td>Duration of the update</td>";
  1929. print "<td>".round($end_time - $start_time, 2)." sec</td>";
  1930. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1931. print "<tr><td>This update was done in</td>";
  1932. print "<td>".$sql_queries." SQL queries.</td>";
  1933. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='".$_newstatpress_url."/images/ok.gif'></td></tr>";
  1934. print "</tbody></table></div><br>\n";
  1935. $wpdb->hide_errors();
  1936. }
  1937. function NewStatPress_Widget($w='') {
  1938. }
  1939. /**
  1940. * Return the expanded vars into the give code. Wrapper for internal use
  1941. */
  1942. function NewStatPress_Print($body='') {
  1943. return iri_NewStatPress_Vars($body);
  1944. }
  1945. /**
  1946. * Expand vars into the give code
  1947. *
  1948. * @param boby the code where to look for variables to expand
  1949. * @return the modified code
  1950. */
  1951. function iri_NewStatPress_Vars($body) {
  1952. global $wpdb;
  1953. $table_name = $wpdb->prefix . "statpress";
  1954. # look for %visits%
  1955. if(strpos(strtolower($body),"%visits%") !== FALSE) {
  1956. $qry = $wpdb->get_results(
  1957. "SELECT count(DISTINCT(ip)) AS pageview
  1958. FROM $table_name
  1959. WHERE
  1960. date = '".gmdate("Ymd",current_time('timestamp'))."' AND
  1961. spider='' and feed='';
  1962. ");
  1963. $body = str_replace("%visits%", $qry[0]->pageview, $body);
  1964. }
  1965. # look for %totalvisits%
  1966. if(strpos(strtolower($body),"%totalvisits%") !== FALSE) {
  1967. $qry = $wpdb->get_results(
  1968. "SELECT count(DISTINCT(ip)) AS pageview
  1969. FROM $table_name
  1970. WHERE
  1971. spider='' AND
  1972. feed='';
  1973. ");
  1974. $body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
  1975. }
  1976. # look for %totalpageviews%
  1977. if(strpos(strtolower($body),"%totalpageviews%") !== FALSE) {
  1978. $qry = $wpdb->get_results(
  1979. "SELECT count(id) AS pageview
  1980. FROM $table_name
  1981. WHERE
  1982. spider='' AND
  1983. feed='';
  1984. ");
  1985. $body = str_replace("%totalpageviews%", $qry[0]->pageview, $body);
  1986. }
  1987. # look for %thistotalvisits%
  1988. if(strpos(strtolower($body),"%thistotalvisits%") !== FALSE) {
  1989. $qry = $wpdb->get_results(
  1990. "SELECT count(DISTINCT(ip)) AS pageview
  1991. FROM $table_name
  1992. WHERE
  1993. spider='' AND
  1994. feed='' AND
  1995. urlrequested='".iri_NewStatPress_URL()."';
  1996. ");
  1997. $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
  1998. }
  1999. # look for %alltotalvisits%
  2000. if(strpos(strtolower($body),"%alltotalvisits%") !== FALSE) {
  2001. $qry = $wpdb->get_results(
  2002. "SELECT SUM(pageview) AS pageview
  2003. FROM (
  2004. SELECT count(DISTINCT(ip)) AS pageview
  2005. FROM $table_name AS t1
  2006. WHERE
  2007. spider='' AND
  2008. feed='' AND
  2009. urlrequested!=''
  2010. GROUP BY urlrequested
  2011. ) AS t2;
  2012. ");
  2013. $body = str_replace("%alltotalvisits%", $qry[0]->pageview, $body);
  2014. }
  2015. # look for %since%
  2016. if(strpos(strtolower($body),"%since%") !== FALSE) {
  2017. $qry = $wpdb->get_results(
  2018. "SELECT date
  2019. FROM $table_name
  2020. ORDER BY date
  2021. LIMIT 1;
  2022. ");
  2023. $body = str_replace("%since%", irihdate($qry[0]->date), $body);
  2024. }
  2025. # look for %os%
  2026. if(strpos(strtolower($body),"%os%") !== FALSE) {
  2027. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  2028. $os=iriGetOS($userAgent);
  2029. $body = str_replace("%os%", $os, $body);
  2030. }
  2031. # look for %browser%
  2032. if(strpos(strtolower($body),"%browser%") !== FALSE) {
  2033. $browser=iriGetBrowser($userAgent);
  2034. $body = str_replace("%browser%", $browser, $body);
  2035. }
  2036. # look for %ip%
  2037. if(strpos(strtolower($body),"%ip%") !== FALSE) {
  2038. $ipAddress = $_SERVER['REMOTE_ADDR'];
  2039. $body = str_replace("%ip%", $ipAddress, $body);
  2040. }
  2041. # look for %visitorsonline%
  2042. if(strpos(strtolower($body),"%visitorsonline%") !== FALSE) {
  2043. $to_time = current_time('timestamp');
  2044. $from_time = date('Y-m-d H:i:s', strtotime('-4 minutes', $to_time));
  2045. $to_time = date('Y-m-d H:i:s', $to_time);
  2046. $qry = $wpdb->get_results(
  2047. "SELECT count(DISTINCT(ip)) AS visitors
  2048. FROM $table_name
  2049. WHERE
  2050. spider='' AND
  2051. feed='' AND
  2052. timestamp BETWEEN '$from_time' AND '$to_time';
  2053. ");
  2054. $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
  2055. }
  2056. # look for %usersonline%
  2057. if(strpos(strtolower($body),"%usersonline%") !== FALSE) {
  2058. $to_time = current_time('timestamp');
  2059. $from_time = date('Y-m-d H:i:s', strtotime('-4 minutes', $to_time));
  2060. $to_time = date('Y-m-d H:i:s', $to_time);
  2061. $qry = $wpdb->get_results(
  2062. "SELECT count(DISTINCT(ip)) AS users
  2063. FROM $table_name
  2064. WHERE
  2065. spider='' AND
  2066. feed='' AND
  2067. user<>'' AND
  2068. timestamp BETWEEN '$from_time' AND '$to_time';
  2069. ");
  2070. $body = str_replace("%usersonline%", $qry[0]->users, $body);
  2071. }
  2072. # look for %toppost%
  2073. if(strpos(strtolower($body),"%toppost%") !== FALSE) {
  2074. $qry = $wpdb->get_results(
  2075. "SELECT urlrequested,count(*) AS totale
  2076. FROM $table_name
  2077. WHERE
  2078. spider='' AND
  2079. feed='' AND
  2080. urlrequested LIKE '%p=%'
  2081. GROUP BY urlrequested
  2082. ORDER BY totale DESC
  2083. LIMIT 1;
  2084. ");
  2085. $body = str_replace("%toppost%", iri_NewStatPress_Decode($qry[0]->urlrequested), $body);
  2086. }
  2087. # look for %topbrowser%
  2088. if(strpos(strtolower($body),"%topbrowser%") !== FALSE) {
  2089. $qry = $wpdb->get_results(
  2090. "SELECT browser,count(*) AS totale
  2091. FROM $table_name
  2092. WHERE
  2093. spider='' AND
  2094. feed=''
  2095. GROUP BY browser
  2096. ORDER BY totale DESC
  2097. LIMIT 1;
  2098. ");
  2099. $body = str_replace("%topbrowser%", iri_NewStatPress_Decode($qry[0]->browser), $body);
  2100. }
  2101. # look for %topos%
  2102. if(strpos(strtolower($body),"%topos%") !== FALSE) {
  2103. $qry = $wpdb->get_results(
  2104. "SELECT os,count(*) AS totale
  2105. FROM $table_name
  2106. WHERE
  2107. spider='' AND
  2108. feed=''
  2109. GROUP BY os
  2110. ORDER BY totale DESC
  2111. LIMIT 1;
  2112. ");
  2113. $body = str_replace("%topos%", iri_NewStatPress_Decode($qry[0]->os), $body);
  2114. }
  2115. return $body;
  2116. }
  2117. /**
  2118. * Get top posts
  2119. *
  2120. * @param limit the number of post to show
  2121. * @param showcounts if checked show totals
  2122. * @return result of extraction
  2123. */
  2124. function iri_NewStatPress_TopPosts($limit=5, $showcounts='checked') {
  2125. global $wpdb;
  2126. $res="\n<ul>\n";
  2127. $table_name = $wpdb->prefix . "statpress";
  2128. $qry = $wpdb->get_results(
  2129. "SELECT urlrequested,count(*) as totale
  2130. FROM $table_name
  2131. WHERE
  2132. spider='' AND
  2133. feed='' AND
  2134. urlrequested LIKE '%p=%'
  2135. GROUP BY urlrequested
  2136. ORDER BY totale DESC LIMIT $limit;
  2137. ");
  2138. foreach ($qry as $rk) {
  2139. $res.="<li><a href='?".$rk->urlrequested."' target='_blank'>".iri_NewStatPress_Decode($rk->urlrequested)."</a></li>\n";
  2140. if(strtolower($showcounts) == 'checked') { $res.=" (".$rk->totale.")"; }
  2141. }
  2142. return "$res</ul>\n";
  2143. }
  2144. function widget_newstatpress_init($args) {
  2145. if ( !function_exists('wp_register_sidebar_widget') || !function_exists('wp_register_widget_control') ) return;
  2146. // Multifunctional StatPress pluging
  2147. function widget_newstatpress_control() {
  2148. $options = get_option('widget_newstatpress');
  2149. if ( !is_array($options) ) $options = array('title'=>'NewStatPress', 'body'=>'Visits today: %visits%');
  2150. if ( isset($_POST['newstatpress-submit']) && $_POST['newstatpress-submit'] ) {
  2151. $options['title'] = strip_tags(stripslashes($_POST['newstatpress-title']));
  2152. $options['body'] = stripslashes($_POST['newstatpress-body']);
  2153. update_option('widget_newstatpress', $options);
  2154. }
  2155. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  2156. $body = htmlspecialchars($options['body'], ENT_QUOTES);
  2157. // the form
  2158. echo '<p style="text-align:right;"><label for="newstatpress-title">' . __('Title:') . ' <input style="width: 250px;" id="newstatpress-title" name="newstatpress-title" type="text" value="'.$title.'" /></label></p>';
  2159. echo '<p style="text-align:right;"><label for="newstatpress-body"><div>' . __('Body:', 'widgets') . '</div><textarea style="width: 288px;height:100px;" id="newstatpress-body" name="newstatpress-body" type="textarea">'.$body.'</textarea></label></p>';
  2160. echo '<input type="hidden" id="newstatpress-submit" name="newstatpress-submit" value="1" /><div style="font-size:7pt;">%totalvisits% %visits% %thistotalvisits% %os% %browser% %ip% %since% %visitorsonline% %usersonline% %toppost% %topbrowser% %topos%</div>';
  2161. }
  2162. function widget_newstatpress($args) {
  2163. extract($args);
  2164. $options = get_option('widget_newstatpress');
  2165. $title = $options['title'];
  2166. $body = $options['body'];
  2167. echo $before_widget;
  2168. print($before_title . $title . $after_title);
  2169. print iri_NewStatPress_Vars($body);
  2170. echo $after_widget;
  2171. }
  2172. wp_register_sidebar_widget('NewStatPress', 'NewStatPress', 'widget_newstatpress');
  2173. wp_register_widget_control('NewStatPress', array('NewStatPress','widgets'), 'widget_newstatpress_control', 300, 210);
  2174. // Top posts
  2175. function widget_newstatpresstopposts_control() {
  2176. $options = get_option('widget_newstatpresstopposts');
  2177. if ( !is_array($options) ) {
  2178. $options = array('title'=>'NewStatPress TopPosts', 'howmany'=>'5', 'showcounts'=>'checked');
  2179. }
  2180. if ( isset($_POST['newstatpresstopposts-submit']) && $_POST['newstatpresstopposts-submit'] ) {
  2181. $options['title'] = strip_tags(stripslashes($_POST['newstatpresstopposts-title']));
  2182. $options['howmany'] = stripslashes($_POST['newstatpresstopposts-howmany']);
  2183. $options['showcounts'] = stripslashes($_POST['newstatpresstopposts-showcounts']);
  2184. if($options['showcounts'] == "1") {
  2185. $options['showcounts']='checked';
  2186. }
  2187. update_option('widget_newstatpresstopposts', $options);
  2188. }
  2189. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  2190. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  2191. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  2192. // the form
  2193. echo '<p style="text-align:right;"><label for="newstatpresstopposts-title">' . __('Title','newstatpress') . ' <input style="width: 250px;" id="newstatpress-title" name="newstatpresstopposts-title" type="text" value="'.$title.'" /></label></p>';
  2194. echo '<p style="text-align:right;"><label for="newstatpresstopposts-howmany">' . __('Limit results to','newstatpress') . ' <input style="width: 100px;" id="newstatpresstopposts-howmany" name="newstatpresstopposts-howmany" type="text" value="'.$howmany.'" /></label></p>';
  2195. echo '<p style="text-align:right;"><label for="newstatpresstopposts-showcounts">' . __('Visits','newstatpress') . ' <input id="newstatpresstopposts-showcounts" name="newstatpresstopposts-showcounts" type=checkbox value="checked" '.$showcounts.' /></label></p>';
  2196. echo '<input type="hidden" id="newstatpress-submitTopPosts" name="newstatpresstopposts-submit" value="1" />';
  2197. }
  2198. function widget_newstatpresstopposts($args) {
  2199. extract($args);
  2200. $options = get_option('widget_newstatpresstopposts');
  2201. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  2202. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  2203. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  2204. echo $before_widget;
  2205. print($before_title . $title . $after_title);
  2206. print iri_NewStatPress_TopPosts($howmany,$showcounts);
  2207. echo $after_widget;
  2208. }
  2209. wp_register_sidebar_widget('NewStatPress TopPosts', 'NewStatPress TopPosts', 'widget_newstatpresstopposts');
  2210. wp_register_widget_control('NewStatPress TopPosts', array('NewStatPress TopPosts','widgets'), 'widget_newstatpresstopposts_control', 300, 110);
  2211. }
  2212. /**
  2213. * Replace a content in page with NewStatPress output
  2214. * Used format is: [NewStatPress: type]
  2215. * Type can be:
  2216. * [NewStatPress: Overview]
  2217. * [NewStatPress: Top days]
  2218. * [NewStatPress: O.S.]
  2219. * [NewStatPress: Browser]
  2220. * [NewStatPress: Feeds]
  2221. * [NewStatPress: Search Engine]
  2222. * [NewStatPress: Search terms]
  2223. * [NewStatPress: Top referrer]
  2224. * [NewStatPress: Languages]
  2225. * [NewStatPress: Spider]
  2226. * [NewStatPress: Top Pages]
  2227. * [NewStatPress: Top Days - Unique visitors]
  2228. * [NewStatPress: Top Days - Pageviews]
  2229. * [NewStatPress: Top IPs - Pageviews]
  2230. *
  2231. * @param content the content of page
  2232. */
  2233. function content_newstatpress($content = '') {
  2234. ob_start();
  2235. $TYPEs = array();
  2236. $TYPE = preg_match_all('/\[NewStatPress: (.*)\]/Ui', $content, $TYPEs);
  2237. foreach ($TYPEs[1] as $k => $TYPE) {
  2238. switch ($TYPE) {
  2239. case "Overview":
  2240. $replacement=iriOverview(FALSE);
  2241. break;
  2242. case "Top days":
  2243. $replacement=iriValueTable2("date","Top days", (get_option('newstatpress_el_top_days')=='') ? 5:get_option('newstatpress_el_top_days'), FALSE);
  2244. break;
  2245. case "O.S.":
  2246. $replacement=iriValueTable2("os","O.S.",(get_option('newstatpress_el_os')=='') ? 10:get_option('newstatpress_el_os'),"","","AND feed='' AND spider='' AND os<>''", FALSE);
  2247. break;
  2248. case "Browser":
  2249. $replacement=iriValueTable2("browser","Browser",(get_option('newstatpress_el_browser')=='') ? 10:get_option('newstatpress_el_browser'),"","","AND feed='' AND spider='' AND browser<>''", FALSE);
  2250. break;
  2251. case "Feeds":
  2252. $replacement=iriValueTable2("feed","Feeds",(get_option('newstatpress_el_feed')=='') ? 5:get_option('newstatpress_el_feed'),"","","AND feed<>''", FALSE);
  2253. break;
  2254. case "Search Engine":
  2255. $replacement=iriValueTable2("searchengine","Search engines",(get_option('newstatpress_el_searchengine')=='') ? 10:get_option('newstatpress_el_searchengine'),"","","AND searchengine<>''", FALSE);
  2256. break;
  2257. case "Search terms":
  2258. $replacement=iriValueTable2("search","Top search terms",(get_option('newstatpress_el_search')=='') ? 20:get_option('newstatpress_el_search'),"","","AND search<>''", FALSE);
  2259. break;
  2260. case "Top referrer":
  2261. $replacement= iriValueTable2("referrer","Top referrer",(get_option('newstatpress_el_referrer')=='') ? 10:get_option('newstatpress_el_referrer'),"","","AND referrer<>'' AND referrer NOT LIKE '%".get_bloginfo('url')."%'", FALSE);
  2262. break;
  2263. case "Languages":
  2264. $replacement=iriValueTable2("nation","Countries/Languages",(get_option('newstatpress_el_languages')=='') ? 20:get_option('newstatpress_el_languages'),"","","AND nation<>'' AND spider=''", FALSE);
  2265. break;
  2266. case "Spider":
  2267. $replacement=iriValueTable2("spider","Spiders",(get_option('newstatpress_el_spiders')=='') ? 10:get_option('newstatpress_el_spiders'),"","","AND spider<>''", FALSE);
  2268. break;
  2269. case "Top Pages":
  2270. $replacement=iriValueTable2("urlrequested","Top pages",(get_option('newstatpress_el_pages')=='') ? 5:get_option('newstatpress_el_pages'),"","urlrequested","AND feed='' and spider=''", FALSE);
  2271. break;
  2272. case "Top Days - Unique visitors":
  2273. $replacement=iriValueTable2("date","Top Days - Unique visitors",(get_option('newstatpress_el_visitors')=='') ? 5:get_option('newstatpress_el_visitors'),"distinct","ip","AND feed='' and spider=''", FALSE);
  2274. break;
  2275. case "Top Days - Pageviews":
  2276. $replacement=iriValueTable2("date","Top Days - Pageviews",(get_option('newstatpress_el_daypages')=='') ? 5:get_option('newstatpress_el_daypages'),"","urlrequested","AND feed='' and spider=''", FALSE);
  2277. break;
  2278. case "Top IPs - Pageviews":
  2279. $replacement=iriValueTable2("ip","Top IPs - Pageviews",(get_option('newstatpress_el_ippages')=='') ? 5:get_option('newstatpress_el_ippages'),"","urlrequested","AND feed='' and spider=''", FALSE);
  2280. break;
  2281. default:
  2282. $replacement="";
  2283. }
  2284. $content = str_replace($TYPEs[0][$k], $replacement, $content);
  2285. }
  2286. ob_get_clean();
  2287. return $content;
  2288. }
  2289. /**
  2290. * Show statistics in dashboard
  2291. */
  2292. function iri_dashboard_widget_function() {
  2293. global $wpdb;
  2294. $table_name = $wpdb->prefix . "statpress";
  2295. # Tabella OVERVIEW
  2296. $unique_color="#114477";
  2297. $web_color="#3377B6";
  2298. $rss_color="#f38f36";
  2299. $spider_color="#83b4d8";
  2300. $lastmonth = iri_NewStatPress_lastmonth();
  2301. $thismonth = gmdate('Ym', current_time('timestamp'));
  2302. $yesterday = gmdate('Ymd', current_time('timestamp')-86400);
  2303. $today = gmdate('Ymd', current_time('timestamp'));
  2304. $tlm[0]=substr($lastmonth,0,4); $tlm[1]=substr($lastmonth,4,2);
  2305. //print "<div class='wrap'><h2>". __('Overview','NewStatPress'). "</h2>";
  2306. print "<table class='widefat'><thead><tr>
  2307. <th scope='col'></th>
  2308. <th scope='col'>". __('Total since','newstatpress'). "<br /><font size=1>";
  2309. print NewStatPress_Print('%since%');
  2310. print "</font></th>
  2311. <th scope='col'>". __('Last month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y',gmmktime(0,0,0,$tlm[1],1,$tlm[0])) ."</font></th>
  2312. <th scope='col'>". __('This month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  2313. <th scope='col'>Target ". __('This month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  2314. <th scope='col'>". __('Yesterday','newstatpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')-86400) ."</font></th>
  2315. <th scope='col'>". __('Today','newstatpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) ."</font></th>
  2316. </tr></thead>
  2317. <tbody id='the-list'>";
  2318. ################################################################################################
  2319. # VISITORS ROW
  2320. print "<tr><td><div style='background:$unique_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Visitors','newstatpress'). "</td>";
  2321. #TOTAL
  2322. $qry_total = $wpdb->get_row("
  2323. SELECT count(DISTINCT ip) AS visitors
  2324. FROM $table_name
  2325. WHERE
  2326. feed='' AND
  2327. spider=''
  2328. ");
  2329. print "<td>" . $qry_total->visitors . "</td>\n";
  2330. #LAST MONTH
  2331. $qry_lmonth = $wpdb->get_row("
  2332. SELECT count(DISTINCT ip) AS visitors
  2333. FROM $table_name
  2334. WHERE
  2335. feed='' AND
  2336. spider='' AND
  2337. date LIKE '" . $lastmonth . "%'
  2338. ");
  2339. print "<td>" . $qry_lmonth->visitors . "</td>\n";
  2340. #THIS MONTH
  2341. $qry_tmonth = $wpdb->get_row("
  2342. SELECT count(DISTINCT ip) AS visitors
  2343. FROM $table_name
  2344. WHERE
  2345. feed='' AND
  2346. spider='' AND
  2347. date LIKE '" . $thismonth . "%'
  2348. ");
  2349. $qry_tmonth->change = null;
  2350. $qry_tmonth->added = null;
  2351. if($qry_lmonth->visitors <> 0) {
  2352. $pc = round( 100 * ($qry_tmonth->visitors / $qry_lmonth->visitors ) - 100,1);
  2353. if($pc >= 0) $pc = "+" . $pc;
  2354. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2355. }
  2356. print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
  2357. #TARGET
  2358. $qry_tmonth->target = round($qry_tmonth->visitors / date("d", current_time('timestamp')) * 30);
  2359. if($qry_lmonth->visitors <> 0) {
  2360. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->visitors ) - 100,1);
  2361. if($pt >= 0) $pt = "+" . $pt;
  2362. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2363. }
  2364. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2365. #YESTERDAY
  2366. $qry_y = $wpdb->get_row("
  2367. SELECT count(DISTINCT ip) AS visitors
  2368. FROM $table_name
  2369. WHERE
  2370. feed='' AND
  2371. spider='' AND
  2372. date = '$yesterday'
  2373. ");
  2374. print "<td>" . $qry_y->visitors . "</td>\n";
  2375. #TODAY
  2376. $qry_t = $wpdb->get_row("
  2377. SELECT count(DISTINCT ip) AS visitors
  2378. FROM $table_name
  2379. WHERE
  2380. feed='' AND
  2381. spider='' AND
  2382. date = '$today'
  2383. ");
  2384. print "<td>" . $qry_t->visitors . "</td>\n";
  2385. print "</tr>";
  2386. ################################################################################################
  2387. # PAGEVIEWS ROW
  2388. print "<tr><td><div style='background:$web_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Pageviews','newstatpress'). "</td>";
  2389. #TOTAL
  2390. $qry_total = $wpdb->get_row("
  2391. SELECT count(date) as pageview
  2392. FROM $table_name
  2393. WHERE
  2394. feed='' AND
  2395. spider=''
  2396. ");
  2397. print "<td>" . $qry_total->pageview . "</td>\n";
  2398. #LAST MONTH
  2399. $prec=0;
  2400. $qry_lmonth = $wpdb->get_row("
  2401. SELECT count(date) as pageview
  2402. FROM $table_name
  2403. WHERE
  2404. feed='' AND
  2405. spider='' AND
  2406. date LIKE '" . $lastmonth . "%'
  2407. ");
  2408. print "<td>".$qry_lmonth->pageview."</td>\n";
  2409. #THIS MONTH
  2410. $qry_tmonth = $wpdb->get_row("
  2411. SELECT count(date) as pageview
  2412. FROM $table_name
  2413. WHERE
  2414. feed='' AND
  2415. spider='' AND
  2416. date LIKE '" . $thismonth . "%'
  2417. ");
  2418. $qry_tmonth->change = null;
  2419. $qry_tmonth->added = null;
  2420. if($qry_lmonth->pageview <> 0) {
  2421. $pc = round( 100 * ($qry_tmonth->pageview / $qry_lmonth->pageview ) - 100,1);
  2422. if($pc >= 0) $pc = "+" . $pc;
  2423. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2424. }
  2425. print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
  2426. #TARGET
  2427. $qry_tmonth->target = round($qry_tmonth->pageview / date("d", current_time('timestamp')) * 30);
  2428. if($qry_lmonth->pageview <> 0) {
  2429. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->pageview ) - 100,1);
  2430. if($pt >= 0) $pt = "+" . $pt;
  2431. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2432. }
  2433. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2434. #YESTERDAY
  2435. $qry_y = $wpdb->get_row("
  2436. SELECT count(date) as pageview
  2437. FROM $table_name
  2438. WHERE
  2439. feed='' AND
  2440. spider='' AND
  2441. date = '$yesterday'
  2442. ");
  2443. print "<td>" . $qry_y->pageview . "</td>\n";
  2444. #TODAY
  2445. $qry_t = $wpdb->get_row("
  2446. SELECT count(date) as pageview
  2447. FROM $table_name
  2448. WHERE
  2449. feed='' AND
  2450. spider='' AND
  2451. date = '$today'
  2452. ");
  2453. print "<td>" . $qry_t->pageview . "</td>\n";
  2454. print "</tr>";
  2455. ################################################################################################
  2456. # SPIDERS ROW
  2457. print "<tr><td><div style='background:$spider_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Spiders</td>";
  2458. #TOTAL
  2459. $qry_total = $wpdb->get_row("
  2460. SELECT count(date) as spiders
  2461. FROM $table_name
  2462. WHERE
  2463. feed='' AND
  2464. spider<>''
  2465. ");
  2466. print "<td>" . $qry_total->spiders . "</td>\n";
  2467. #LAST MONTH
  2468. $prec=0;
  2469. $qry_lmonth = $wpdb->get_row("
  2470. SELECT count(date) as spiders
  2471. FROM $table_name
  2472. WHERE
  2473. feed='' AND
  2474. spider<>'' AND
  2475. date LIKE '" . $lastmonth . "%'
  2476. ");
  2477. print "<td>" . $qry_lmonth->spiders. "</td>\n";
  2478. #THIS MONTH
  2479. $prec=$qry_lmonth->spiders;
  2480. $qry_tmonth = $wpdb->get_row("
  2481. SELECT count(date) as spiders
  2482. FROM $table_name
  2483. WHERE
  2484. feed='' AND
  2485. spider<>'' AND
  2486. date LIKE '" . $thismonth . "%'
  2487. ");
  2488. $qry_tmonth->change = null;
  2489. $qry_tmonth->added = null;
  2490. if($qry_lmonth->spiders <> 0) {
  2491. $pc = round( 100 * ($qry_tmonth->spiders / $qry_lmonth->spiders ) - 100,1);
  2492. if($pc >= 0) $pc = "+" . $pc;
  2493. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2494. }
  2495. print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
  2496. #TARGET
  2497. $qry_tmonth->target = round($qry_tmonth->spiders / date("d", current_time('timestamp')) * 30);
  2498. if($qry_lmonth->spiders <> 0) {
  2499. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->spiders ) - 100,1);
  2500. if($pt >= 0) $pt = "+" . $pt;
  2501. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2502. }
  2503. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2504. #YESTERDAY
  2505. $qry_y = $wpdb->get_row("
  2506. SELECT count(date) as spiders
  2507. FROM $table_name
  2508. WHERE
  2509. feed='' AND
  2510. spider<>'' AND
  2511. date = '$yesterday'
  2512. ");
  2513. print "<td>" . $qry_y->spiders . "</td>\n";
  2514. #TODAY
  2515. $qry_t = $wpdb->get_row("
  2516. SELECT count(date) as spiders
  2517. FROM $table_name
  2518. WHERE
  2519. feed='' AND
  2520. spider<>'' AND
  2521. date = '$today'
  2522. ");
  2523. print "<td>" . $qry_t->spiders . "</td>\n";
  2524. print "</tr>";
  2525. ################################################################################################
  2526. # FEEDS ROW
  2527. print "<tr><td><div style='background:$rss_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Feeds</td>";
  2528. #TOTAL
  2529. $qry_total = $wpdb->get_row("
  2530. SELECT count(date) as feeds
  2531. FROM $table_name
  2532. WHERE
  2533. feed<>'' AND
  2534. spider=''
  2535. ");
  2536. print "<td>".$qry_total->feeds."</td>\n";
  2537. #LAST MONTH
  2538. $qry_lmonth = $wpdb->get_row("
  2539. SELECT count(date) as feeds
  2540. FROM $table_name
  2541. WHERE
  2542. feed<>'' AND
  2543. spider='' AND
  2544. date LIKE '" . $lastmonth . "%'
  2545. ");
  2546. print "<td>".$qry_lmonth->feeds."</td>\n";
  2547. #THIS MONTH
  2548. $qry_tmonth = $wpdb->get_row("
  2549. SELECT count(date) as feeds
  2550. FROM $table_name
  2551. WHERE
  2552. feed<>'' AND
  2553. spider='' AND
  2554. date LIKE '" . $thismonth . "%'
  2555. ");
  2556. $qry_tmonth->change = null;
  2557. $qry_tmonth->added = null;
  2558. if($qry_lmonth->feeds <> 0) {
  2559. $pc = round( 100 * ($qry_tmonth->feeds / $qry_lmonth->feeds ) - 100,1);
  2560. if($pc >= 0) $pc = "+" . $pc;
  2561. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2562. }
  2563. print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
  2564. #TARGET
  2565. $qry_tmonth->target = round($qry_tmonth->feeds / date("d", current_time('timestamp')) * 30);
  2566. if($qry_lmonth->feeds <> 0) {
  2567. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->feeds ) - 100,1);
  2568. if($pt >= 0) $pt = "+" . $pt;
  2569. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2570. }
  2571. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2572. $qry_y = $wpdb->get_row("
  2573. SELECT count(date) as feeds
  2574. FROM $table_name
  2575. WHERE
  2576. feed<>'' AND
  2577. spider='' AND
  2578. date = '".$yesterday."'
  2579. ");
  2580. print "<td>".$qry_y->feeds."</td>\n";
  2581. $qry_t = $wpdb->get_row("
  2582. SELECT count(date) as feeds
  2583. FROM $table_name
  2584. WHERE
  2585. feed<>'' AND
  2586. spider='' AND
  2587. date = '$today'
  2588. ");
  2589. print "<td>".$qry_t->feeds."</td>\n";
  2590. print "</tr></table><br />\n\n";
  2591. print '</tr></table>';
  2592. print '</div>';
  2593. # END OF OVERVIEW
  2594. ####################################################################################################
  2595. print "<div class='wrap'><h4><a href='admin.php?page=newstatpress/newstatpress.php'>". __('More details','newstatpress'). " &raquo;</a></h4>";
  2596. }
  2597. /**
  2598. * Make the overwiew
  2599. *
  2600. * @param print true if to print
  2601. * @return the printing represetnation if print is false
  2602. */
  2603. function iriOverview($print = TRUE) {
  2604. global $wpdb;
  2605. $table_name = $wpdb->prefix . "statpress";
  2606. $result="";
  2607. # Tabella OVERVIEW
  2608. $unique_color="#114477";
  2609. $web_color="#3377B6";
  2610. $rss_color="#f38f36";
  2611. $spider_color="#83b4d8";
  2612. $lastmonth = iri_NewStatPress_lastmonth();
  2613. $thismonth = gmdate('Ym', current_time('timestamp'));
  2614. $yesterday = gmdate('Ymd', current_time('timestamp')-86400);
  2615. $today = gmdate('Ymd', current_time('timestamp'));
  2616. $tlm[0]=substr($lastmonth,0,4); $tlm[1]=substr($lastmonth,4,2);
  2617. $result = $result. "<div class='wrap'><h2>". __('Overview','newstatpress'). "</h2>";
  2618. $result = $result. "<table class='widefat'><thead><tr>
  2619. <th scope='col'></th>
  2620. <th scope='col'>". __('Total since','newstatpress'). "<br /><font size=1>";
  2621. $result = $result. NewStatPress_Print('%since%');
  2622. $result = $result. "</font></th>
  2623. <th scope='col'>". __('Last month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y',gmmktime(0,0,0,$tlm[1],1,$tlm[0])) ."</font></th>
  2624. <th scope='col'>". __('This month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  2625. <th scope='col'>Target ". __('This month','newstatpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  2626. <th scope='col'>". __('Yesterday','newstatpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')-86400) ."</font></th>
  2627. <th scope='col'>". __('Today','newstatpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) ."</font></th>
  2628. </tr></thead>
  2629. <tbody id='the-list'>";
  2630. ################################################################################################
  2631. # VISITORS ROW
  2632. $result = $result. "<tr><td><div style='background:$unique_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Visitors','newstatpress'). "</td>";
  2633. #TOTAL
  2634. $qry_total = $wpdb->get_row("
  2635. SELECT count(DISTINCT ip) AS visitors
  2636. FROM $table_name
  2637. WHERE
  2638. feed='' AND
  2639. spider=''
  2640. ");
  2641. $result = $result. "<td>" . $qry_total->visitors . "</td>\n";
  2642. #LAST MONTH
  2643. $qry_lmonth = $wpdb->get_row("
  2644. SELECT count(DISTINCT ip) AS visitors
  2645. FROM $table_name
  2646. WHERE
  2647. feed='' AND
  2648. spider='' AND
  2649. date LIKE '" . $lastmonth . "%'
  2650. ");
  2651. $result = $result. "<td>" . $qry_lmonth->visitors . "</td>\n";
  2652. #THIS MONTH
  2653. $qry_tmonth = $wpdb->get_row("
  2654. SELECT count(DISTINCT ip) AS visitors
  2655. FROM $table_name
  2656. WHERE
  2657. feed='' AND
  2658. spider='' AND
  2659. date LIKE '" . $thismonth . "%'
  2660. ");
  2661. $qry_tmonth->change = null;
  2662. $qry_tmonth->added = null;
  2663. if($qry_lmonth->visitors <> 0) {
  2664. $pc = round( 100 * ($qry_tmonth->visitors / $qry_lmonth->visitors ) - 100,1);
  2665. if($pc >= 0) $pc = "+" . $pc;
  2666. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2667. }
  2668. $result = $result. "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
  2669. #TARGET
  2670. $qry_tmonth->target = round($qry_tmonth->visitors / date("d", current_time('timestamp')) * 30);
  2671. if($qry_lmonth->visitors <> 0) {
  2672. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->visitors ) - 100,1);
  2673. if($pt >= 0) $pt = "+" . $pt;
  2674. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2675. }
  2676. $result = $result. "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2677. #YESTERDAY
  2678. $qry_y = $wpdb->get_row("
  2679. SELECT count(DISTINCT ip) AS visitors
  2680. FROM $table_name
  2681. WHERE
  2682. feed='' AND
  2683. spider='' AND
  2684. date = '$yesterday'
  2685. ");
  2686. $result = $result. "<td>" . $qry_y->visitors . "</td>\n";
  2687. #TODAY
  2688. $qry_t = $wpdb->get_row("
  2689. SELECT count(DISTINCT ip) AS visitors
  2690. FROM $table_name
  2691. WHERE
  2692. feed='' AND
  2693. spider='' AND
  2694. date = '$today'
  2695. ");
  2696. $result = $result. "<td>" . $qry_t->visitors . "</td>\n";
  2697. $result = $result. "</tr>";
  2698. ################################################################################################
  2699. # PAGEVIEWS ROW
  2700. $result = $result. "<tr><td><div style='background:$web_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Pageviews','newstatpress'). "</td>";
  2701. #TOTAL
  2702. $qry_total = $wpdb->get_row("
  2703. SELECT count(date) as pageview
  2704. FROM $table_name
  2705. WHERE
  2706. feed='' AND
  2707. spider=''
  2708. ");
  2709. $result = $result. "<td>" . $qry_total->pageview . "</td>\n";
  2710. #LAST MONTH
  2711. $prec=0;
  2712. $qry_lmonth = $wpdb->get_row("
  2713. SELECT count(date) as pageview
  2714. FROM $table_name
  2715. WHERE
  2716. feed='' AND
  2717. spider='' AND
  2718. date LIKE '" . $lastmonth . "%'
  2719. ");
  2720. $result = $result. "<td>".$qry_lmonth->pageview."</td>\n";
  2721. #THIS MONTH
  2722. $qry_tmonth = $wpdb->get_row("
  2723. SELECT count(date) as pageview
  2724. FROM $table_name
  2725. WHERE
  2726. feed='' AND
  2727. spider='' AND
  2728. date LIKE '" . $thismonth . "%'
  2729. ");
  2730. $qry_tmonth->change = null;
  2731. $qry_tmonth->added = null;
  2732. if($qry_lmonth->pageview <> 0) {
  2733. $pc = round( 100 * ($qry_tmonth->pageview / $qry_lmonth->pageview ) - 100,1);
  2734. if($pc >= 0) $pc = "+" . $pc;
  2735. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2736. }
  2737. $result = $result. "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
  2738. #TARGET
  2739. $qry_tmonth->target = round($qry_tmonth->pageview / date("d", current_time('timestamp')) * 30);
  2740. if($qry_lmonth->pageview <> 0) {
  2741. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->pageview ) - 100,1);
  2742. if($pt >= 0) $pt = "+" . $pt;
  2743. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2744. }
  2745. $result = $result. "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2746. #YESTERDAY
  2747. $qry_y = $wpdb->get_row("
  2748. SELECT count(date) as pageview
  2749. FROM $table_name
  2750. WHERE
  2751. feed='' AND
  2752. spider='' AND
  2753. date = '$yesterday'
  2754. ");
  2755. $result = $result."<td>" . $qry_y->pageview . "</td>\n";
  2756. #TODAY
  2757. $qry_t = $wpdb->get_row("
  2758. SELECT count(date) as pageview
  2759. FROM $table_name
  2760. WHERE
  2761. feed='' AND
  2762. spider='' AND
  2763. date = '$today'
  2764. ");
  2765. $result = $result."<td>" . $qry_t->pageview . "</td>\n";
  2766. $result = $result."</tr>";
  2767. ################################################################################################
  2768. # SPIDERS ROW
  2769. $result = $result."<tr><td><div style='background:$spider_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Spiders</td>";
  2770. #TOTAL
  2771. $qry_total = $wpdb->get_row("
  2772. SELECT count(date) as spiders
  2773. FROM $table_name
  2774. WHERE
  2775. feed='' AND
  2776. spider<>''
  2777. ");
  2778. $result = $result."<td>" . $qry_total->spiders . "</td>\n";
  2779. #LAST MONTH
  2780. $prec=0;
  2781. $qry_lmonth = $wpdb->get_row("
  2782. SELECT count(date) as spiders
  2783. FROM $table_name
  2784. WHERE
  2785. feed='' AND
  2786. spider<>'' AND
  2787. date LIKE '" . $lastmonth . "%'
  2788. ");
  2789. $result = $result. "<td>" . $qry_lmonth->spiders. "</td>\n";
  2790. #THIS MONTH
  2791. $prec=$qry_lmonth->spiders;
  2792. $qry_tmonth = $wpdb->get_row("
  2793. SELECT count(date) as spiders
  2794. FROM $table_name
  2795. WHERE
  2796. feed='' AND
  2797. spider<>'' AND
  2798. date LIKE '" . $thismonth . "%'
  2799. ");
  2800. $qry_tmonth->change = null;
  2801. $qry_tmonth->added = null;
  2802. if($qry_lmonth->spiders <> 0) {
  2803. $pc = round( 100 * ($qry_tmonth->spiders / $qry_lmonth->spiders ) - 100,1);
  2804. if($pc >= 0) $pc = "+" . $pc;
  2805. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2806. }
  2807. $result = $result. "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
  2808. #TARGET
  2809. $qry_tmonth->target = round($qry_tmonth->spiders / date("d", current_time('timestamp')) * 30);
  2810. if($qry_lmonth->spiders <> 0) {
  2811. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->spiders ) - 100,1);
  2812. if($pt >= 0) $pt = "+" . $pt;
  2813. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2814. }
  2815. $result = $result. "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2816. #YESTERDAY
  2817. $qry_y = $wpdb->get_row("
  2818. SELECT count(date) as spiders
  2819. FROM $table_name
  2820. WHERE
  2821. feed='' AND
  2822. spider<>'' AND
  2823. date = '$yesterday'
  2824. ");
  2825. $result = $result. "<td>" . $qry_y->spiders . "</td>\n";
  2826. #TODAY
  2827. $qry_t = $wpdb->get_row("
  2828. SELECT count(date) as spiders
  2829. FROM $table_name
  2830. WHERE
  2831. feed='' AND
  2832. spider<>'' AND
  2833. date = '$today'
  2834. ");
  2835. $result = $result. "<td>" . $qry_t->spiders . "</td>\n";
  2836. $result = $result. "</tr>";
  2837. ################################################################################################
  2838. # FEEDS ROW
  2839. $result = $result. "<tr><td><div style='background:$rss_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Feeds</td>";
  2840. #TOTAL
  2841. $qry_total = $wpdb->get_row("
  2842. SELECT count(date) as feeds
  2843. FROM $table_name
  2844. WHERE
  2845. feed<>'' AND spider=''
  2846. ");
  2847. $result = $result. "<td>".$qry_total->feeds."</td>\n";
  2848. #LAST MONTH
  2849. $qry_lmonth = $wpdb->get_row("
  2850. SELECT count(date) as feeds
  2851. FROM $table_name
  2852. WHERE
  2853. feed<>'' AND
  2854. spider='' AND
  2855. date LIKE '" . $lastmonth . "%'
  2856. ");
  2857. $result = $result. "<td>".$qry_lmonth->feeds."</td>\n";
  2858. #THIS MONTH
  2859. $qry_tmonth = $wpdb->get_row("
  2860. SELECT count(date) as feeds
  2861. FROM $table_name
  2862. WHERE
  2863. feed<>'' AND
  2864. spider='' AND
  2865. date LIKE '" . $thismonth . "%'
  2866. ");
  2867. $qry_tmonth->change = null;
  2868. $qry_tmonth->added = null;
  2869. if($qry_lmonth->feeds <> 0) {
  2870. $pc = round( 100 * ($qry_tmonth->feeds / $qry_lmonth->feeds ) - 100,1);
  2871. if($pc >= 0) $pc = "+" . $pc;
  2872. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  2873. }
  2874. $result = $result. "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
  2875. #TARGET
  2876. $qry_tmonth->target = round($qry_tmonth->feeds / date("d", current_time('timestamp')) * 30);
  2877. if($qry_lmonth->feeds <> 0) {
  2878. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->feeds ) - 100,1);
  2879. if($pt >= 0) $pt = "+" . $pt;
  2880. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  2881. }
  2882. $result = $result. "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  2883. $qry_y = $wpdb->get_row("
  2884. SELECT count(date) as feeds
  2885. FROM $table_name
  2886. WHERE
  2887. feed<>'' AND
  2888. spider='' AND
  2889. date = '".$yesterday."'
  2890. ");
  2891. $result = $result. "<td>".$qry_y->feeds."</td>\n";
  2892. $qry_t = $wpdb->get_row("
  2893. SELECT count(date) as feeds
  2894. FROM $table_name
  2895. WHERE
  2896. feed<>'' AND
  2897. spider='' AND
  2898. date = '$today'
  2899. ");
  2900. $result = $result. "<td>".$qry_t->feeds."</td>\n";
  2901. $result = $result. "</tr></table><br />\n\n";
  2902. ################################################################################################
  2903. ################################################################################################
  2904. # THE GRAPHS
  2905. # last "N" days graph NEW
  2906. $gdays=get_option('newstatpress_daysinoverviewgraph'); if($gdays == 0) { $gdays=20; }
  2907. $start_of_week = get_option('start_of_week');
  2908. $result = $result. '<table width="100%" border="0"><tr>';
  2909. $qry = $wpdb->get_row("
  2910. SELECT count(date) as pageview, date
  2911. FROM $table_name
  2912. GROUP BY date HAVING date >= '".gmdate('Ymd', current_time('timestamp')-86400*$gdays)."'
  2913. ORDER BY pageview DESC
  2914. LIMIT 1
  2915. ");
  2916. $maxxday=$qry->pageview;
  2917. if($maxxday == 0) { $maxxday = 1; }
  2918. # Y
  2919. $gd=(90/$gdays).'%';
  2920. for($gg=$gdays-1;$gg>=0;$gg--) {
  2921. #TOTAL VISITORS
  2922. $qry_visitors = $wpdb->get_row("
  2923. SELECT count(DISTINCT ip) AS total
  2924. FROM $table_name
  2925. WHERE
  2926. feed='' AND
  2927. spider='' AND
  2928. date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  2929. ");
  2930. $px_visitors = round($qry_visitors->total*100/$maxxday);
  2931. #TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
  2932. $qry_pageviews = $wpdb->get_row("
  2933. SELECT count(date) as total
  2934. FROM $table_name
  2935. WHERE
  2936. feed='' AND
  2937. spider='' AND
  2938. date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  2939. ");
  2940. $px_pageviews = round($qry_pageviews->total*100/$maxxday);
  2941. #TOTAL SPIDERS
  2942. $qry_spiders = $wpdb->get_row("
  2943. SELECT count(ip) AS total
  2944. FROM $table_name
  2945. WHERE
  2946. feed='' AND
  2947. spider<>'' AND
  2948. date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  2949. ");
  2950. $px_spiders = round($qry_spiders->total*100/$maxxday);
  2951. #TOTAL FEEDS
  2952. $qry_feeds = $wpdb->get_row("
  2953. SELECT count(ip) AS total
  2954. FROM $table_name
  2955. WHERE
  2956. feed<>'' AND
  2957. spider='' AND
  2958. date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  2959. ");
  2960. $px_feeds = round($qry_feeds->total*100/$maxxday);
  2961. $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
  2962. $result = $result.'<td width="'.$gd.'" valign="bottom"';
  2963. if($start_of_week == gmdate('w',current_time('timestamp')-86400*$gg)) {
  2964. $result = $result.' style="border-left:2px dotted gray;"';
  2965. } # week-cut
  2966. $result = $result. "><div style='float:left;height: 100%;width:100%;font-family:Helvetica;font-size:7pt;text-align:center;border-right:1px solid white;color:black;'>
  2967. <div style='background:#ffffff;width:100%;height:".$px_white."px;'></div>
  2968. <div style='background:$unique_color;width:100%;height:".$px_visitors."px;' title='".$qry_visitors->total." visitors'></div>
  2969. <div style='background:$web_color;width:100%;height:".$px_pageviews."px;' title='".$qry_pageviews->total." pageviews'></div>
  2970. <div style='background:$spider_color;width:100%;height:".$px_spiders."px;' title='".$qry_spiders->total." spiders'></div>
  2971. <div style='background:$rss_color;width:100%;height:".$px_feeds."px;' title='".$qry_feeds->total." feeds'></div>
  2972. <div style='background:gray;width:100%;height:1px;'></div>
  2973. <br />".gmdate('d', current_time('timestamp')-86400*$gg) . ' ' . gmdate('M', current_time('timestamp')-86400*$gg) . "</div></td>\n";
  2974. }
  2975. $result = $result.'</tr></table>';
  2976. $result = $result.'</div>';
  2977. # END OF OVERVIEW
  2978. ####################################################################################################
  2979. if ($print) print $result;
  2980. else return $result;
  2981. }
  2982. // Create the function use in the action hook
  2983. function iri_add_dashboard_widgets() {
  2984. global $wp_meta_boxes;
  2985. if (get_option('newstatpress_dashboard')=='checked') {
  2986. wp_add_dashboard_widget('iri_dashboard_widget', 'NewStatPress Overview', 'iri_dashboard_widget_function');
  2987. } else unset($wp_meta_boxes['dashboard']['side']['core']['wp_dashboard_setup']);
  2988. }
  2989. load_plugin_textdomain('newstatpress', 'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/locale', '/'.dirname(plugin_basename(__FILE__)).'/locale');
  2990. add_action('admin_menu', 'iri_add_pages');
  2991. add_action('plugins_loaded', 'widget_newstatpress_init');
  2992. add_action('send_headers', 'iriStatAppend'); //add_action('wp_head', 'iriStatAppend');
  2993. add_action('init','iri_checkExport');
  2994. // Hoook into the 'wp_dashboard_setup' action to register our other functions
  2995. add_action('wp_dashboard_setup', 'iri_add_dashboard_widgets' );
  2996. add_filter('the_content', 'content_newstatpress');
  2997. register_activation_hook(__FILE__,'iri_NewStatPress_CreateTable');
  2998. ?>