Advertisement
Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.62 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: StatPress
  4. Plugin URI: http://www.statpress.org
  5. Description: Real time stats for your Wordpress blog
  6. Version: 1.4.3
  7. Author: Daniele Lippi
  8. Author URI: http://www.danielelippi.it
  9. */
  10.  
  11. $_STATPRESS['version']='1.x';
  12. $_STATPRESS['feedtype']='';
  13.  
  14. include ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/includes/charts.php';
  15.  
  16. function iri_add_pages() {
  17. # Crea/aggiorna tabella se non esiste
  18. global $wpdb;
  19. $table_name = $wpdb->prefix . "statpress";
  20. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  21. iri_StatPress_CreateTable();
  22. }
  23. # add submenu
  24. $mincap=get_option('statpress_mincap');
  25. if($mincap == '') {
  26. $mincap="level_8";
  27. }
  28. // ORIG add_submenu_page('index.php', 'StatPress', 'StatPress', 8, 'statpress', 'iriStatPress');
  29.  
  30. add_menu_page('StatPress', 'StatPress', $mincap, __FILE__, 'iriStatPress');
  31. add_submenu_page(__FILE__, __('Overview','statpress'), __('Overview','statpress'), $mincap, __FILE__, 'iriStatPress');
  32. add_submenu_page(__FILE__, __('Details','statpress'), __('Details','statpress'), $mincap, __FILE__ . '&statpress_action=details', 'iriStatPress');
  33. add_submenu_page(__FILE__, __('Spy','statpress'), __('Spy','statpress'), $mincap, __FILE__ . '&statpress_action=spy', 'iriStatPress');
  34. add_submenu_page(__FILE__, __('Search','statpress'), __('Search','statpress'), $mincap, __FILE__ . '&statpress_action=search', 'iriStatPress');
  35. add_submenu_page(__FILE__, __('Export','statpress'), __('Export','statpress'), $mincap, __FILE__ . '&statpress_action=export', 'iriStatPress');
  36. add_submenu_page(__FILE__, __('Options','statpress'), __('Options','statpress'), $mincap, __FILE__ . '&statpress_action=options', 'iriStatPress');
  37. add_submenu_page(__FILE__, __('StatPressUpdate','statpress'), __('StatPressUpdate','statpress'), $mincap, __FILE__ . '&statpress_action=up', 'iriStatPress');
  38. add_submenu_page(__FILE__, __('Statpress blog','statpress'), __('Statpress blog','statpress'), $mincap, 'http://www.statpress.org');
  39.  
  40. }
  41.  
  42.  
  43. function iriStatPress() {
  44. ?>
  45. <?php
  46. if ($_GET['statpress_action'] == 'export') {
  47. iriStatPressExport();
  48. } elseif ($_GET['statpress_action'] == 'up') {
  49. iriStatPressUpdate();
  50. } elseif ($_GET['statpress_action'] == 'spy') {
  51. iriStatPressSpy();
  52. } elseif ($_GET['statpress_action'] == 'search') {
  53. iriStatPressSearch();
  54. } elseif ($_GET['statpress_action'] == 'details') {
  55. iriStatPressDetails();
  56. } elseif ($_GET['statpress_action'] == 'options') {
  57. iriStatPressOptions();
  58. } elseif(1) {
  59. iriStatPressMain();
  60. }
  61. }
  62.  
  63. function iriStatPressOptions() {
  64. if($_POST['saveit'] == 'yes') {
  65. update_option('statpress_collectloggeduser', $_POST['statpress_collectloggeduser']);
  66. update_option('statpress_autodelete', $_POST['statpress_autodelete']);
  67. update_option('statpress_daysinoverviewgraph', $_POST['statpress_daysinoverviewgraph']);
  68. update_option('statpress_mincap', $_POST['statpress_mincap']);
  69. update_option('statpress_donotcollectspider', $_POST['statpress_donotcollectspider']);
  70. update_option('statpress_cryptip', $_POST['statpress_cryptip']);
  71.  
  72. # update database too
  73. iri_StatPress_CreateTable();
  74. print "<br /><div class='updated'><p>".__('Saved','statpress')."!</p></div>";
  75. } else {
  76. ?>
  77. <div class='wrap'><h2><?php _e('Options','statpress'); ?></h2>
  78. <form method=post><table width=100%>
  79. <?php
  80. print "<tr><td><input type=checkbox name='statpress_collectloggeduser' value='checked' ".get_option('statpress_collectloggeduser')."> ".__('Collect data about logged users, too.','statpress')."</td></tr>";
  81. print "<tr><td><input type=checkbox name='statpress_donotcollectspider' value='checked' ".get_option('statpress_donotcollectspider')."> ".__('Do not collect spiders visits','statpress')."</td></tr>";
  82. print "<tr><td><input type=checkbox name='statpress_cryptip' value='checked' ".get_option('statpress_cryptip')."> ".__('Crypt IP addresses','statpress')."</td></tr>";
  83.  
  84. ?>
  85. <tr><td><?php _e('Automatically delete visits older than','statpress'); ?>
  86. <select name="statpress_autodelete">
  87. <option value="" <?php if(get_option('statpress_autodelete') =='' ) print "selected"; ?>><?php _e('Never delete!','statpress'); ?></option>
  88. <option value="1 month" <?php if(get_option('statpress_autodelete') == "1 month") print "selected"; ?>>1 <?php _e('month','statpress'); ?></option>
  89. <option value="3 months" <?php if(get_option('statpress_autodelete') == "3 months") print "selected"; ?>>3 <?php _e('months','statpress'); ?></option>
  90. <option value="6 months" <?php if(get_option('statpress_autodelete') == "6 months") print "selected"; ?>>6 <?php _e('months','statpress'); ?></option>
  91. <option value="1 year" <?php if(get_option('statpress_autodelete') == "1 year") print "selected"; ?>>1 <?php _e('year','statpress'); ?></option>
  92. </select></td></tr>
  93.  
  94. <tr><td><?php _e('Days in Overview graph','statpress'); ?>
  95. <select name="statpress_daysinoverviewgraph">
  96. <option value="7" <?php if(get_option('statpress_daysinoverviewgraph') == 7) print "selected"; ?>>7</option>
  97. <option value="10" <?php if(get_option('statpress_daysinoverviewgraph') == 10) print "selected"; ?>>10</option>
  98. <option value="20" <?php if(get_option('statpress_daysinoverviewgraph') == 20) print "selected"; ?>>20</option>
  99. <option value="30" <?php if(get_option('statpress_daysinoverviewgraph') == 30) print "selected"; ?>>30</option>
  100. <option value="50" <?php if(get_option('statpress_daysinoverviewgraph') == 50) print "selected"; ?>>50</option>
  101. </select></td></tr>
  102.  
  103. <tr><td><?php _e('Minimum capability to view stats','statpress'); ?>
  104. <select name="statpress_mincap">
  105. <?php iri_dropdown_caps(get_option('statpress_mincap')); ?>
  106. </select>
  107. <a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_blank"><?php _e("more info",'statpress'); ?></a>
  108. </td></tr>
  109.  
  110. <tr><td><br><input type=submit value="<?php _e('Save options','statpress'); ?>"></td></tr>
  111. </tr>
  112. </table>
  113. <input type=hidden name=saveit value=yes>
  114. <input type=hidden name=page value=statpress><input type=hidden name=statpress_action value=options>
  115. </form>
  116. </div>
  117. <?php
  118.  
  119. } # chiude saveit
  120. }
  121.  
  122.  
  123. function iri_dropdown_caps( $default = false ) {
  124. global $wp_roles;
  125. $role = get_role('administrator');
  126. foreach($role->capabilities as $cap => $grant) {
  127. print "<option ";
  128. if($default == $cap) { print "selected "; }
  129. print ">$cap</option>";
  130. }
  131. }
  132.  
  133.  
  134. function iriStatPressExport() {
  135. ?>
  136. <div class='wrap'><h2><?php _e('Export stats to text file','statpress'); ?> (csv)</h2>
  137. <form method=get><table>
  138. <tr><td><?php _e('From','statpress'); ?></td><td><input type=text name=from> (YYYYMMDD)</td></tr>
  139. <tr><td><?php _e('To','statpress'); ?></td><td><input type=text name=to> (YYYYMMDD)</td></tr>
  140. <tr><td><?php _e('Fields delimiter','statpress'); ?></td><td><select name=del><option>,</option><option>;</option><option>|</option></select></tr>
  141. <tr><td></td><td><input type=submit value=<?php _e('Export','statpress'); ?>></td></tr>
  142. <input type=hidden name=page value=statpress><input type=hidden name=statpress_action value=exportnow>
  143. </table></form>
  144. </div>
  145. <?php
  146. }
  147.  
  148. function iri_checkExport(){
  149. if ($_GET['statpress_action'] == 'exportnow') {
  150. $mincap=get_option('statpress_mincap');
  151. if ($mincap == '')
  152. $mincap = "level_8";
  153. if ( current_user_can( $mincap ) ) {
  154. iriStatPressExportNow();
  155. }
  156. }
  157. }
  158.  
  159. function iriStatPressExportNow() {
  160. global $wpdb;
  161. $table_name = $wpdb->prefix . "statpress";
  162. $filename=get_bloginfo('title' )."-statpress_".$_GET['from']."-".$_GET['to'].".csv";
  163. header('Content-Description: File Transfer');
  164. header("Content-Disposition: attachment; filename=$filename");
  165. header('Content-Type: text/plain charset=' . get_option('blog_charset'), true);
  166. $qry = $wpdb->get_results("SELECT * FROM $table_name WHERE date>='".(date("Ymd",strtotime(substr($_GET['from'],0,8))))."' AND date<='".(date("Ymd",strtotime(substr($_GET['to'],0,8))))."';");
  167. $del=substr($_GET['del'],0,1);
  168. 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";
  169. foreach ($qry as $rk) {
  170. 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";
  171.  
  172. }
  173. die();
  174. }
  175.  
  176. function iriStatPressMain() {
  177. global $wpdb;
  178. $table_name = $wpdb->prefix . "statpress";
  179.  
  180. # Tabella OVERVIEW
  181. $unique_color="#114477";
  182. $web_color="#3377B6";
  183. $rss_color="#f38f36";
  184. $spider_color="#83b4d8";
  185. $lastmonth = iri_StatPress_lastmonth();
  186. $thismonth = gmdate('Ym', current_time('timestamp'));
  187. $yesterday = gmdate('Ymd', current_time('timestamp')-86400);
  188. $today = gmdate('Ymd', current_time('timestamp'));
  189. $tlm[0]=substr($lastmonth,0,4); $tlm[1]=substr($lastmonth,4,2);
  190.  
  191. print "<div class='wrap'><h2>". __('Overview','statpress'). "</h2>";
  192. print "<table class='widefat'><thead><tr>
  193. <th scope='col'></th>
  194. <th scope='col'>". __('Total','statpress'). "</th>
  195. <th scope='col'>". __('Last month','statpress'). "<br /><font size=1>" . gmdate('M, Y',gmmktime(0,0,0,$tlm[1],1,$tlm[0])) ."</font></th>
  196. <th scope='col'>". __('This month','statpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  197. <th scope='col'>Target ". __('This month','statpress'). "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) ."</font></th>
  198. <th scope='col'>". __('Yesterday','statpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')-86400) ."</font></th>
  199. <th scope='col'>". __('Today','statpress'). "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) ."</font></th>
  200. </tr></thead>
  201. <tbody id='the-list'>";
  202.  
  203. ################################################################################################
  204. # VISITORS ROW
  205. print "<tr><td><div style='background:$unique_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Visitors','statpress'). "</td>";
  206.  
  207. #TOTAL
  208. $qry_total = $wpdb->get_row("
  209. SELECT count(DISTINCT ip) AS visitors
  210. FROM $table_name
  211. WHERE feed=''
  212. AND spider=''
  213. ");
  214. print "<td>" . $qry_total->visitors . "</td>\n";
  215.  
  216. #LAST MONTH
  217. $qry_lmonth = $wpdb->get_row("
  218. SELECT count(DISTINCT ip) AS visitors
  219. FROM $table_name
  220. WHERE feed=''
  221. AND spider=''
  222. AND date LIKE '" . $lastmonth . "%'
  223. ");
  224. print "<td>" . $qry_lmonth->visitors . "</td>\n";
  225.  
  226. #THIS MONTH
  227. $qry_tmonth = $wpdb->get_row("
  228. SELECT count(DISTINCT ip) AS visitors
  229. FROM $table_name
  230. WHERE feed=''
  231. AND spider=''
  232. AND date LIKE '" . $thismonth . "%'
  233. ");
  234. if($qry_lmonth->visitors <> 0) {
  235. $pc = round( 100 * ($qry_tmonth->visitors / $qry_lmonth->visitors ) - 100,1);
  236. if($pc >= 0) $pc = "+" . $pc;
  237. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  238. }
  239. print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
  240.  
  241. #TARGET
  242. $qry_tmonth->target = round($qry_tmonth->visitors / date("d", current_time('timestamp')) * 30);
  243. if($qry_lmonth->visitors <> 0) {
  244. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->visitors ) - 100,1);
  245. if($pt >= 0) $pt = "+" . $pt;
  246. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  247. }
  248. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  249.  
  250. #YESTERDAY
  251. $qry_y = $wpdb->get_row("
  252. SELECT count(DISTINCT ip) AS visitors
  253. FROM $table_name
  254. WHERE feed=''
  255. AND spider=''
  256. AND date = '$yesterday'
  257. ");
  258. print "<td>" . $qry_y->visitors . "</td>\n";
  259.  
  260. #TODAY
  261. $qry_t = $wpdb->get_row("
  262. SELECT count(DISTINCT ip) AS visitors
  263. FROM $table_name
  264. WHERE feed=''
  265. AND spider=''
  266. AND date = '$today'
  267. ");
  268. print "<td>" . $qry_t->visitors . "</td>\n";
  269. print "</tr>";
  270.  
  271. ################################################################################################
  272. # PAGEVIEWS ROW
  273. print "<tr><td><div style='background:$web_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>". __('Pageviews','statpress'). "</td>";
  274.  
  275. #TOTAL
  276. $qry_total = $wpdb->get_row("
  277. SELECT count(date) as pageview
  278. FROM $table_name
  279. WHERE feed=''
  280. AND spider=''
  281. ");
  282. print "<td>" . $qry_total->pageview . "</td>\n";
  283.  
  284. #LAST MONTH
  285. $prec=0;
  286. $qry_lmonth = $wpdb->get_row("
  287. SELECT count(date) as pageview
  288. FROM $table_name
  289. WHERE feed=''
  290. AND spider=''
  291. AND date LIKE '" . $lastmonth . "%'
  292. ");
  293. print "<td>".$qry_lmonth->pageview."</td>\n";
  294.  
  295. #THIS MONTH
  296. $qry_tmonth = $wpdb->get_row("
  297. SELECT count(date) as pageview
  298. FROM $table_name
  299. WHERE feed=''
  300. AND spider=''
  301. AND date LIKE '" . $thismonth . "%'
  302. ");
  303. if($qry_lmonth->pageview <> 0) {
  304. $pc = round( 100 * ($qry_tmonth->pageview / $qry_lmonth->pageview ) - 100,1);
  305. if($pc >= 0) $pc = "+" . $pc;
  306. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  307. }
  308. print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
  309.  
  310. #TARGET
  311. $qry_tmonth->target = round($qry_tmonth->pageview / date("d", current_time('timestamp')) * 30);
  312. if($qry_lmonth->pageview <> 0) {
  313. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->pageview ) - 100,1);
  314. if($pt >= 0) $pt = "+" . $pt;
  315. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  316. }
  317. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  318.  
  319. #YESTERDAY
  320. $qry_y = $wpdb->get_row("
  321. SELECT count(date) as pageview
  322. FROM $table_name
  323. WHERE feed=''
  324. AND spider=''
  325. AND date = '$yesterday'
  326. ");
  327. print "<td>" . $qry_y->pageview . "</td>\n";
  328.  
  329. #TODAY
  330. $qry_t = $wpdb->get_row("
  331. SELECT count(date) as pageview
  332. FROM $table_name
  333. WHERE feed=''
  334. AND spider=''
  335. AND date = '$today'
  336. ");
  337. print "<td>" . $qry_t->pageview . "</td>\n";
  338. print "</tr>";
  339. ################################################################################################
  340. # SPIDERS ROW
  341. print "<tr><td><div style='background:$spider_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Spiders</td>";
  342. #TOTAL
  343. $qry_total = $wpdb->get_row("
  344. SELECT count(date) as spiders
  345. FROM $table_name
  346. WHERE feed=''
  347. AND spider<>''
  348. ");
  349. print "<td>" . $qry_total->spiders . "</td>\n";
  350. #LAST MONTH
  351. $prec=0;
  352. $qry_lmonth = $wpdb->get_row("
  353. SELECT count(date) as spiders
  354. FROM $table_name
  355. WHERE feed=''
  356. AND spider<>''
  357. AND date LIKE '" . $lastmonth . "%'
  358. ");
  359. print "<td>" . $qry_lmonth->spiders. "</td>\n";
  360.  
  361. #THIS MONTH
  362. $prec=$qry_lmonth->spiders;
  363. $qry_tmonth = $wpdb->get_row("
  364. SELECT count(date) as spiders
  365. FROM $table_name
  366. WHERE feed=''
  367. AND spider<>''
  368. AND date LIKE '" . $thismonth . "%'
  369. ");
  370. if($qry_lmonth->spiders <> 0) {
  371. $pc = round( 100 * ($qry_tmonth->spiders / $qry_lmonth->spiders ) - 100,1);
  372. if($pc >= 0) $pc = "+" . $pc;
  373. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  374. }
  375. print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
  376.  
  377. #TARGET
  378. $qry_tmonth->target = round($qry_tmonth->spiders / date("d", current_time('timestamp')) * 30);
  379. if($qry_lmonth->spiders <> 0) {
  380. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->spiders ) - 100,1);
  381. if($pt >= 0) $pt = "+" . $pt;
  382. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  383. }
  384. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  385.  
  386. #YESTERDAY
  387. $qry_y = $wpdb->get_row("
  388. SELECT count(date) as spiders
  389. FROM $table_name
  390. WHERE feed=''
  391. AND spider<>''
  392. AND date = '$yesterday'
  393. ");
  394. print "<td>" . $qry_y->spiders . "</td>\n";
  395.  
  396. #TODAY
  397. $qry_t = $wpdb->get_row("
  398. SELECT count(date) as spiders
  399. FROM $table_name
  400. WHERE feed=''
  401. AND spider<>''
  402. AND date = '$today'
  403. ");
  404. print "<td>" . $qry_t->spiders . "</td>\n";
  405. print "</tr>";
  406. ################################################################################################
  407. # FEEDS ROW
  408. print "<tr><td><div style='background:$rss_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Feeds</td>";
  409. #TOTAL
  410. $qry_total = $wpdb->get_row("
  411. SELECT count(date) as feeds
  412. FROM $table_name
  413. WHERE feed<>''
  414. AND spider=''
  415. ");
  416. print "<td>".$qry_total->feeds."</td>\n";
  417.  
  418. #LAST MONTH
  419. $qry_lmonth = $wpdb->get_row("
  420. SELECT count(date) as feeds
  421. FROM $table_name
  422. WHERE feed<>''
  423. AND spider=''
  424. AND date LIKE '" . $lastmonth . "%'
  425. ");
  426. print "<td>".$qry_lmonth->feeds."</td>\n";
  427.  
  428. #THIS MONTH
  429. $qry_tmonth = $wpdb->get_row("
  430. SELECT count(date) as feeds
  431. FROM $table_name
  432. WHERE feed<>''
  433. AND spider=''
  434. AND date LIKE '" . $thismonth . "%'
  435. ");
  436. if($qry_lmonth->feeds <> 0) {
  437. $pc = round( 100 * ($qry_tmonth->feeds / $qry_lmonth->feeds ) - 100,1);
  438. if($pc >= 0) $pc = "+" . $pc;
  439. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  440. }
  441. print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
  442.  
  443. #TARGET
  444. $qry_tmonth->target = round($qry_tmonth->feeds / date("d", current_time('timestamp')) * 30);
  445. if($qry_lmonth->feeds <> 0) {
  446. $pt = round( 100 * ($qry_tmonth->target / $qry_lmonth->feeds ) - 100,1);
  447. if($pt >= 0) $pt = "+" . $pt;
  448. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  449. }
  450. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  451.  
  452. $qry_y = $wpdb->get_row("
  453. SELECT count(date) as feeds
  454. FROM $table_name
  455. WHERE feed<>''
  456. AND spider=''
  457. AND date = '".$yesterday."'
  458. ");
  459. print "<td>".$qry_y->feeds."</td>\n";
  460.  
  461. $qry_t = $wpdb->get_row("
  462. SELECT count(date) as feeds
  463. FROM $table_name
  464. WHERE feed<>''
  465. AND spider=''
  466. AND date = '$today'
  467. ");
  468. print "<td>".$qry_t->feeds."</td>\n";
  469.  
  470. print "</tr></table><br />\n\n";
  471.  
  472. ################################################################################################
  473. ################################################################################################
  474. # THE GRAPHS
  475.  
  476. # last "N" days graph NEW
  477. $gdays=get_option('statpress_daysinoverviewgraph'); if($gdays == 0) { $gdays=20; }
  478. // $start_of_week = get_settings('start_of_week');
  479. $start_of_week = get_option('start_of_week');
  480. print '<table width="100%" border="0"><tr>';
  481. $qry = $wpdb->get_row("
  482. SELECT count(date) as pageview, date
  483. FROM $table_name
  484. GROUP BY date HAVING date >= '".gmdate('Ymd', current_time('timestamp')-86400*$gdays)."'
  485. ORDER BY pageview DESC
  486. LIMIT 1
  487. ");
  488. $maxxday=$qry->pageview;
  489. if($maxxday == 0) { $maxxday = 1; }
  490. # Y
  491. $gd=(90/$gdays).'%';
  492. for($gg=$gdays-1;$gg>=0;$gg--)
  493. {
  494. #TOTAL VISITORS
  495. $qry_visitors = $wpdb->get_row("
  496. SELECT count(DISTINCT ip) AS total
  497. FROM $table_name
  498. WHERE feed=''
  499. AND spider=''
  500. AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  501. ");
  502. $px_visitors = round($qry_visitors->total*100/$maxxday);
  503.  
  504. #TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
  505. $qry_pageviews = $wpdb->get_row("
  506. SELECT count(date) as total
  507. FROM $table_name
  508. WHERE feed=''
  509. AND spider=''
  510. AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  511. ");
  512. $px_pageviews = round($qry_pageviews->total*100/$maxxday);
  513.  
  514. #TOTAL SPIDERS
  515. $qry_spiders = $wpdb->get_row("
  516. SELECT count(ip) AS total
  517. FROM $table_name
  518. WHERE feed=''
  519. AND spider<>''
  520. AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  521. ");
  522. $px_spiders = round($qry_spiders->total*100/$maxxday);
  523.  
  524. #TOTAL FEEDS
  525. $qry_feeds = $wpdb->get_row("
  526. SELECT count(ip) AS total
  527. FROM $table_name
  528. WHERE feed<>''
  529. AND spider=''
  530. AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
  531. ");
  532. $px_feeds = round($qry_feeds->total*100/$maxxday);
  533.  
  534. $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
  535.  
  536. print '<td width="'.$gd.'" valign="bottom"';
  537. if($start_of_week == gmdate('w',current_time('timestamp')-86400*$gg)) { print ' style="border-left:2px dotted gray;"'; } # week-cut
  538. print "><div style='float:left;height: 100%;width:100%;font-family:Helvetica;font-size:7pt;text-align:center;border-right:1px solid white;color:black;'>
  539. <div style='background:#ffffff;width:100%;height:".$px_white."px;'></div>
  540. <div style='background:$unique_color;width:100%;height:".$px_visitors."px;' title='".$qry_visitors->total." visitors'></div>
  541. <div style='background:$web_color;width:100%;height:".$px_pageviews."px;' title='".$qry_pageviews->total." pageviews'></div>
  542. <div style='background:$spider_color;width:100%;height:".$px_spiders."px;' title='".$qry_spiders->total." spiders'></div>
  543. <div style='background:$rss_color;width:100%;height:".$px_feeds."px;' title='".$qry_feeds->total." feeds'></div>
  544. <div style='background:gray;width:100%;height:1px;'></div>
  545. <br />".gmdate('d', current_time('timestamp')-86400*$gg) . ' ' . gmdate('M', current_time('timestamp')-86400*$gg) . "</div></td>\n";
  546. }
  547. print '</tr></table>';
  548.  
  549. print '</div>';
  550. # END OF OVERVIEW
  551. ####################################################################################################
  552.  
  553.  
  554.  
  555.  
  556. $querylimit="LIMIT 10";
  557.  
  558. # Tabella Last hits
  559. print "<div class='wrap'><h2>". __('Last hits','statpress'). "</h2><table class='widefat'><thead><tr><th scope='col'>". __('Date','statpress'). "</th><th scope='col'>". __('Time','statpress'). "</th><th scope='col'>IP</th><th scope='col'>". __('Country','statpress').'/'.__('Language','statpress'). "</th><th scope='col'>". __('Page','statpress'). "</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>";
  560. print "<tbody id='the-list'>";
  561.  
  562. $fivesdrafts = $wpdb->get_results("SELECT * FROM $table_name WHERE (os<>'' OR feed<>'') order by id DESC $querylimit");
  563. foreach ($fivesdrafts as $fivesdraft) {
  564. print "<tr>";
  565. print "<td>". irihdate($fivesdraft->date) ."</td>";
  566. print "<td>". $fivesdraft->time ."</td>";
  567. print "<td>". $fivesdraft->ip ."</td>";
  568. print "<td>". $fivesdraft->nation ."</td>";
  569. print "<td>". iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested),30) ."</td>";
  570. print "<td>". $fivesdraft->feed . "</td>";
  571. if($fivesdraft->os != '') {
  572. $img=str_replace(" ","_",strtolower($fivesdraft->os)).".png";
  573. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/os/$img'> </td>";
  574. } else {
  575. print "<td></td>";
  576. }
  577. print "<td>". $fivesdraft->os . "</td>";
  578. if($fivesdraft->browser != '') {
  579. $img=str_replace(" ","",strtolower($fivesdraft->browser)).".png";
  580. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/browsers/$img'></td>";
  581. } else {
  582. print "<td></td>";
  583. }
  584. print "<td>".$fivesdraft->browser."</td></tr>\n";
  585. print "</tr>";
  586. }
  587. print "</table></div>";
  588.  
  589.  
  590. # Last Search terms
  591. print "<div class='wrap'><h2>" . __('Last search terms','statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','statpress')."</th><th scope='col'>".__('Time','statpress')."</th><th scope='col'>".__('Terms','statpress')."</th><th scope='col'>". __('Engine','statpress'). "</th><th scope='col'>". __('Result','statpress'). "</th></tr></thead>";
  592. print "<tbody id='the-list'>";
  593. $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM $table_name WHERE search<>'' ORDER BY id DESC $querylimit");
  594. foreach ($qry as $rk) {
  595. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td><a href='".$rk->referrer."'>".$rk->search."</a></td><td>".$rk->searchengine."</td><td><a href='".get_bloginfo('url')."/?".$rk->urlrequested."'>". __('page viewed','statpress'). "</a></td></tr>\n";
  596. }
  597. print "</table></div>";
  598.  
  599. # Referrer
  600. print "<div class='wrap'><h2>".__('Last referrers','statpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','statpress')."</th><th scope='col'>".__('Time','statpress')."</th><th scope='col'>".__('URL','statpress')."</th><th scope='col'>".__('Result','statpress')."</th></tr></thead>";
  601. print "<tbody id='the-list'>";
  602. $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested FROM $table_name WHERE ((referrer NOT LIKE '".get_option('home')."%') AND (referrer <>'') AND (searchengine='')) ORDER BY id DESC $querylimit");
  603. foreach ($qry as $rk) {
  604. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td><a href='".$rk->referrer."'>".iri_StatPress_Abbrevia($rk->referrer,80)."</a></td><td><a href='".get_bloginfo('url')."/?".$rk->urlrequested."'>". __('page viewed','statpress'). "</a></td></tr>\n";
  605. }
  606. print "</table></div>";
  607.  
  608.  
  609. # Last Agents
  610. print "<div class='wrap'><h2>".__('Last agents','statpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Agent','statpress')."</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>";
  611. print "<tbody id='the-list'>";
  612. $qry = $wpdb->get_results("SELECT agent,os,browser,spider FROM $table_name GROUP BY agent,os,browser,spider ORDER BY id DESC $querylimit");
  613. foreach ($qry as $rk) {
  614. print "<tr><td>".$rk->agent."</td>";
  615. if($rk->os != '') {
  616. $img=str_replace(" ","_",strtolower($rk->os)).".png";
  617. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/os/$img'> </td>";
  618. } else {
  619. print "<td></td>";
  620. }
  621. print "<td>". $rk->os . "</td>";
  622. if($rk->browser != '') {
  623. $img=str_replace(" ","",strtolower($rk->browser)).".png";
  624. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/browsers/$img'></td>";
  625. } else {
  626. print "<td></td>";
  627. }
  628. print "<td>".$rk->browser." ".$rk->spider."</td></tr>\n";
  629. }
  630. print "</table></div>";
  631.  
  632.  
  633. # Last pages
  634. print "<div class='wrap'><h2>".__('Last pages','statpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','statpress')."</th><th scope='col'>".__('Time','statpress')."</th><th scope='col'>".__('Page','statpress')."</th><th scope='col' style='width:17px;'></th><th scope='col' style='width:120px;'>".__('OS','statpress')."</th><th style='width:17px;'></th><th scope='col' style='width:120px;'>".__('Browser','statpress')."</th></tr></thead>";
  635. print "<tbody id='the-list'>";
  636. $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM $table_name WHERE (spider='' AND feed='') ORDER BY id DESC $querylimit");
  637. foreach ($qry as $rk) {
  638. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td>".iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested),60)."</td>";
  639. if($rk->os != '') {
  640. $img=str_replace(" ","_",strtolower($rk->os)).".png";
  641. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/os/$img'> </td>";
  642. } else {
  643. print "<td></td>";
  644. }
  645. print "<td>". $rk->os . "</td>";
  646. if($rk->browser != '') {
  647. $img=str_replace(" ","",strtolower($rk->browser)).".png";
  648. print "<td><IMG style='border:0px;width:16px;height:16px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/browsers/$img'></td>";
  649. } else {
  650. print "<td></td>";
  651. }
  652. print "<td>".$rk->browser." ".$rk->spider."</td></tr>\n";
  653.  
  654. }
  655. print "</table></div>";
  656.  
  657.  
  658. # Last Spiders
  659. print "<div class='wrap'><h2>".__('Last spiders','statpress')."</h2><table class='widefat'><thead><tr><th scope='col'>".__('Date','statpress')."</th><th scope='col'>".__('Time','statpress')."</th><th scope='col'>".__('Spider','statpress')."</th><th scope='col'>".__('Agent','statpress')."</th></tr></thead>";
  660. print "<tbody id='the-list'>";
  661. $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM $table_name WHERE (spider<>'') ORDER BY id DESC $querylimit");
  662. foreach ($qry as $rk) {
  663. print "<tr><td>".irihdate($rk->date)."</td><td>".$rk->time."</td><td>".$rk->spider."</td><td> ".$rk->agent."</td></tr>\n";
  664. }
  665. print "</table></div>";
  666.  
  667.  
  668. print "<br />";
  669. print "&nbsp;<i>StatPress table size: <b>".iritablesize($wpdb->prefix . "statpress")."</b></i><br />";
  670. print "&nbsp;<i>StatPress current time: <b>".current_time('mysql')."</b></i><br />";
  671. print "&nbsp;<i>RSS2 url: <b>".get_bloginfo('rss2_url').' ('.iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')).")</b></i><br />";
  672.  
  673. }
  674.  
  675.  
  676. function iri_StatPress_extractfeedreq($url) {
  677. list($null,$q)=explode("?",$url);
  678. list($res,$null)=explode("&",$q);
  679. return $res;
  680. }
  681.  
  682. function iriStatPressDetails() {
  683. global $wpdb;
  684. $table_name = $wpdb->prefix . "statpress";
  685.  
  686. $querylimit="LIMIT 10";
  687.  
  688. # Top days
  689. iriValueTable2("date","Top days",5);
  690.  
  691. # O.S.
  692. iriValueTable2("os","O.S.",10,"","","AND feed='' AND spider='' AND os<>''");
  693.  
  694. # Browser
  695. iriValueTable2("browser","Browser",10,"","","AND feed='' AND spider='' AND browser<>''");
  696.  
  697. # Feeds
  698. iriValueTable2("feed","Feeds",5,"","","AND feed<>''");
  699.  
  700. # SE
  701. iriValueTable2("searchengine","Search engines",10,"","","AND searchengine<>''");
  702.  
  703. # Search terms
  704. iriValueTable2("search","Top search terms",20,"","","AND search<>''");
  705.  
  706. # Top referrer
  707. iriValueTable2("referrer","Top referrer",10,"","","AND referrer<>'' AND referrer NOT LIKE '%".get_bloginfo('url')."%'");
  708.  
  709. # Languages
  710. iriValueTable2("nation","Countries/Languages",20,"","","AND nation<>'' AND spider=''");
  711.  
  712. # Spider
  713. iriValueTable2("spider","Spiders",10,"","","AND spider<>''");
  714.  
  715. # Top Pages
  716. iriValueTable2("urlrequested","Top pages",5,"","urlrequested","AND feed='' and spider=''");
  717.  
  718.  
  719. # Top Days - Unique visitors
  720. iriValueTable2("date","Top Days - Unique visitors",5,"distinct","ip","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  721.  
  722. # Top Days - Pageviews
  723. iriValueTable2("date","Top Days - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  724.  
  725. # Top IPs - Pageviews
  726. iriValueTable2("ip","Top IPs - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
  727. }
  728.  
  729.  
  730. function iriStatPressSpy() {
  731. global $wpdb;
  732. $table_name = $wpdb->prefix . "statpress";
  733.  
  734. # Spy
  735. $today = gmdate('Ymd', current_time('timestamp'));
  736. $yesterday = gmdate('Ymd', current_time('timestamp')-86400);
  737. print "<div class='wrap'><h2>".__('Spy','statpress')."</h2>";
  738. $sql="SELECT ip,nation,os,browser,agent FROM $table_name WHERE (spider='' AND feed='') AND (date BETWEEN '$yesterday' AND '$today') GROUP BY ip ORDER BY id DESC LIMIT 20";
  739. $qry = $wpdb->get_results($sql);
  740.  
  741. ?>
  742. <script>
  743. function ttogle(thediv){
  744. if (document.getElementById(thediv).style.display=="inline") {
  745. document.getElementById(thediv).style.display="none"
  746. } else {document.getElementById(thediv).style.display="inline"}
  747. }
  748. </script>
  749. <div align="center">
  750. <table id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">
  751. <?php
  752. foreach ($qry as $rk) {
  753. print "<tr><td colspan='2' bgcolor='#dedede'><div align='left'>";
  754. print "<IMG SRC='http://api.hostip.info/flag.php?ip=".$rk->ip."' border=0 width=18 height=12>";
  755. print " <strong><span><font size='2' color='#7b7b7b'>".$rk->ip."</font></span></strong> ";
  756. print "<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;' onClick=ttogle('".$rk->ip."');>".__('more info','statpress')."</span></div>";
  757. print "<div id='".$rk->ip."' name='".$rk->ip."'>".$rk->os.", ".$rk->browser;
  758. if(get_option('statpress_cryptip')!='checked') {
  759. print "<br><iframe style='overflow:hide;border:0px;width:100%;height:30px;font-family:helvetica;paddng:0;' scrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=".$rk->ip."></iframe>";
  760. }
  761. print "<br><small>".gethostbyaddr($rk->ip)."</small>";
  762. print "<br><small>".$rk->agent."</small>";
  763. print "</div>";
  764. print "<script>document.getElementById('".$rk->ip."').style.display='none';</script>";
  765. print "</td></tr>";
  766. $qry2=$wpdb->get_results("SELECT * FROM $table_name WHERE ip='".$rk->ip."' AND (date BETWEEN '$yesterday' AND '$today') order by id LIMIT 10");
  767. foreach ($qry2 as $details) {
  768. print "<tr>";
  769. print "<td valign='top' width='151'><div><font size='1' color='#3B3B3B'><strong>".irihdate($details->date)." ".$details->time."</strong></font></div></td>";
  770. print "<td><div><a href='".get_bloginfo('url')."/?".$details->urlrequested."' target='_blank'>".iri_StatPress_Decode($details->urlrequested)."</a>";
  771. if($details->searchengine != '') {
  772. print "<br><small>".__('arrived from','statpress')." <b>".$details->searchengine."</b> ".__('searching','statpress')." <a href='".$details->referrer."' target=_blank>".$details->search."</a></small>";
  773. } elseif($details->referrer != '' && strpos($details->referrer,get_option('home'))===FALSE) {
  774. print "<br><small>".__('arrived from','statpress')." <a href='".$details->referrer."' target=_blank>".$details->referrer."</a></small>";
  775. }
  776. print "</div></td>";
  777. print "</tr>\n";
  778. }
  779. }
  780. ?>
  781. </table>
  782. </div>
  783. <?php
  784. }
  785.  
  786.  
  787.  
  788. function iri_CheckIP($ip) {
  789. return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
  790. }
  791.  
  792. function iriStatPressSearch($what='') {
  793. global $wpdb;
  794. $table_name = $wpdb->prefix . "statpress";
  795.  
  796. $f['urlrequested']=__('URL Requested','statpress');
  797. $f['agent']=__('Agent','statpress');
  798. $f['referrer']=__('Referrer','statpress');
  799. $f['search']=__('Search terms','statpress');
  800. $f['searchengine']=__('Search engine','statpress');
  801. $f['os']=__('Operative system','statpress');
  802. $f['browser']="Browser";
  803. $f['spider']="Spider";
  804. $f['ip']="IP";
  805. ?>
  806. <div class='wrap'><h2><?php _e('Search','statpress'); ?></h2>
  807. <form method=get><table>
  808. <?php
  809. for($i=1;$i<=3;$i++) {
  810. print "<tr>";
  811. print "<td>".__('Field','statpress')." <select name=where$i><option value=''></option>";
  812. foreach ( array_keys($f) as $k ) {
  813. print "<option value='$k'";
  814. if($_GET["where$i"] == $k) { print " SELECTED "; }
  815. print ">".$f[$k]."</option>";
  816. }
  817. print "</select></td>";
  818. print "<td><input type=checkbox name=groupby$i value='checked' ".$_GET["groupby$i"]."> ".__('Group by','statpress')."</td>";
  819. print "<td><input type=checkbox name=sortby$i value='checked' ".$_GET["sortby$i"]."> ".__('Sort by','statpress')."</td>";
  820. print "<td>, ".__('if contains','statpress')." <input type=text name=what$i value='".$_GET["what$i"]."'></td>";
  821. print "</tr>";
  822. }
  823. ?>
  824. </table>
  825. <br>
  826. <table>
  827. <tr>
  828. <td>
  829. <table>
  830. <tr><td><input type=checkbox name=oderbycount value=checked <?php print $_GET['oderbycount'] ?>> <?php _e('sort by count if grouped','statpress'); ?></td></tr>
  831. <tr><td><input type=checkbox name=spider value=checked <?php print $_GET['spider'] ?>> <?php _e('include spiders/crawlers/bot','statpress'); ?></td></tr>
  832. <tr><td><input type=checkbox name=feed value=checked <?php print $_GET['feed'] ?>> <?php _e('include feed','statpress'); ?></td></tr>
  833. </table>
  834. </td>
  835. <td width=15> </td>
  836. <td>
  837. <table>
  838. <tr>
  839. <td><?php _e('Limit results to','statpress'); ?>
  840. <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>
  841. </td>
  842. </tr>
  843. <tr><td>&nbsp;</td></tr>
  844. <tr>
  845. <td align=right><input type=submit value=<?php _e('Search','statpress'); ?> name=searchsubmit></td>
  846. </tr>
  847. </table>
  848. </td>
  849. </tr>
  850. </table>
  851. <input type=hidden name=page value='wp-statpress/statpress.php'><input type=hidden name=statpress_action value=search>
  852. </form><br>
  853. <?php
  854.  
  855. if(isset($_GET['searchsubmit'])) {
  856. # query builder
  857. $qry="";
  858. # FIELDS
  859. $fields="";
  860. for($i=1;$i<=3;$i++) {
  861. if($_GET["where$i"] != '') {
  862. $fields.=$_GET["where$i"].",";
  863. }
  864. }
  865. $fields=rtrim($fields,",");
  866. # WHERE
  867. $where="WHERE 1=1";
  868. if($_GET['spider'] != 'checked') { $where.=" AND spider=''"; }
  869. if($_GET['feed'] != 'checked') { $where.=" AND feed=''"; }
  870. for($i=1;$i<=3;$i++) {
  871. if(($_GET["what$i"] != '') && ($_GET["where$i"] != '')) {
  872. $where.=" AND ".$_GET["where$i"]." LIKE '%".$_GET["what$i"]."%'";
  873. }
  874. }
  875. # ORDER BY
  876. $orderby="";
  877. for($i=1;$i<=3;$i++) {
  878. if(($_GET["sortby$i"] == 'checked') && ($_GET["where$i"] != '')) {
  879. $orderby.=$_GET["where$i"].',';
  880. }
  881. }
  882.  
  883. # GROUP BY
  884. $groupby="";
  885. for($i=1;$i<=3;$i++) {
  886. if(($_GET["groupby$i"] == 'checked') && ($_GET["where$i"] != '')) {
  887. $groupby.=$_GET["where$i"].',';
  888. }
  889. }
  890. if($groupby != '') {
  891. $groupby="GROUP BY ".rtrim($groupby,',');
  892. $fields.=",count(*) as totale";
  893. if($_GET['oderbycount'] == 'checked') { $orderby="totale DESC,".$orderby; }
  894. }
  895.  
  896. if($orderby != '') { $orderby="ORDER BY ".rtrim($orderby,','); }
  897.  
  898.  
  899. $limit="LIMIT ".$_GET['limitquery'];
  900.  
  901. # Results
  902. print "<h2>".__('Results','statpress')."</h2>";
  903. $sql="SELECT $fields FROM $table_name $where $groupby $orderby $limit;";
  904. // print "$sql<br>";
  905. print "<table class='widefat'><thead><tr>";
  906. for($i=1;$i<=3;$i++) {
  907. if($_GET["where$i"] != '') { print "<th scope='col'>".ucfirst($_GET["where$i"])."</th>"; }
  908. }
  909. if($groupby != '') { print "<th scope='col'>".__('Count','statpress')."</th>"; }
  910. print "</tr></thead><tbody id='the-list'>";
  911. $qry=$wpdb->get_results($sql,ARRAY_N);
  912. foreach ($qry as $rk) {
  913. print "<tr>";
  914. for($i=1;$i<=3;$i++) {
  915. print "<td>";
  916. if($_GET["where$i"] == 'urlrequested') { print iri_StatPress_Decode($rk[$i-1]); } else { print $rk[$i-1]; }
  917. print "</td>";
  918. }
  919. print "</tr>";
  920. }
  921. print "</table>";
  922. print "<br /><br /><font size=1 color=gray>sql: $sql</font></div>";
  923. }
  924.  
  925. }
  926.  
  927. function iri_StatPress_Abbrevia($s,$c) {
  928. $res=""; if(strlen($s)>$c) { $res="..."; }
  929. return substr($s,0,$c).$res;
  930.  
  931. }
  932.  
  933.  
  934. function iri_StatPress_Decode($out_url) {
  935. if($out_url == '') { $out_url=__('Page','statpress').": Home"; }
  936. if(substr($out_url,0,4)=="cat=") { $out_url=__('Category','statpress').": ".get_cat_name(substr($out_url,4)); }
  937. if(substr($out_url,0,2)=="m=") { $out_url=__('Calendar','statpress').": ".substr($out_url,6,2)."/".substr($out_url,2,4); }
  938. if(substr($out_url,0,2)=="s=") { $out_url=__('Search','statpress').": ".substr($out_url,2); }
  939. if(substr($out_url,0,2)=="p=") {
  940. $post_id_7 = get_post(substr($out_url,2), ARRAY_A);
  941. $out_url = $post_id_7['post_title'];
  942. }
  943. if(substr($out_url,0,8)=="page_id=") {
  944. $post_id_7=get_page(substr($out_url,8), ARRAY_A);
  945. $out_url = __('Page','statpress').": ".$post_id_7['post_title'];
  946. }
  947. return $out_url;
  948. }
  949.  
  950.  
  951. function iri_StatPress_URL() {
  952. $urlRequested = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '' );
  953. if ( $urlRequested == "" ) { // SEO problem!
  954. $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '' );
  955. }
  956. if(substr($urlRequested,0,2) == '/?') { $urlRequested=substr($urlRequested,2); }
  957. if($urlRequested == '/') { $urlRequested=''; }
  958. return $urlRequested;
  959. }
  960.  
  961.  
  962. # Converte da data us to default format di Wordpress
  963. function irihdate($dt = "00000000") {
  964. return mysql2date(get_option('date_format'), substr($dt,0,4)."-".substr($dt,4,2)."-".substr($dt,6,2));
  965. }
  966.  
  967.  
  968. function iritablesize($table) {
  969. global $wpdb;
  970. $res = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table'");
  971. foreach ($res as $fstatus) {
  972. $data_lenght = $fstatus->Data_length;
  973. $data_rows = $fstatus->Rows;
  974. }
  975. return number_format(($data_lenght/1024/1024), 2, ",", " ")." Mb ($data_rows records)";
  976. }
  977.  
  978.  
  979. function iriValueTable2($fld,$fldtitle,$limit = 0,$param = "", $queryfld = "", $exclude= "") {
  980. global $wpdb;
  981. $table_name = $wpdb->prefix . "statpress";
  982.  
  983. if ($queryfld == '') { $queryfld = $fld; }
  984. print "<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','statpress')."</th><th></th></tr></thead>";
  985. $rks = $wpdb->get_var("SELECT count($param $queryfld) as rks FROM $table_name WHERE 1=1 $exclude;");
  986. if($rks > 0) {
  987. $sql="SELECT count($param $queryfld) as pageview, $fld FROM $table_name WHERE 1=1 $exclude GROUP BY $fld ORDER BY pageview DESC";
  988. if($limit > 0) { $sql=$sql." LIMIT $limit"; }
  989. $qry = $wpdb->get_results($sql);
  990. $tdwidth=450;
  991.  
  992. // Collects data
  993. $data=array();
  994. foreach ($qry as $rk) {
  995. $pc=round(($rk->pageview*100/$rks),1);
  996. if($fld == 'nation') { $rk->$fld = strtoupper($rk->$fld); }
  997. if($fld == 'date') { $rk->$fld = irihdate($rk->$fld); }
  998. if($fld == 'urlrequested') { $rk->$fld = iri_StatPress_Decode($rk->$fld); }
  999. $data[substr($rk->$fld,0,50)]=$rk->pageview;
  1000. }
  1001. }
  1002.  
  1003. // Draw table body
  1004. print "<tbody id='the-list'>";
  1005. if($rks > 0) { // Chart!
  1006. if($fld == 'nation') {
  1007. $chart=iriGoogleGeo("","",$data);
  1008. } else {
  1009. $chart=iriGoogleChart("","500x200",$data);
  1010. }
  1011. print "<tr><td></td><td></td><td rowspan='".($limit+2)."'>$chart</td></tr>";
  1012. foreach ($data as $key => $value) {
  1013. print "<tr><td style='width:500px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>".$key;
  1014. print "</td><td style='width:100px;text-align:center;'>".$value."</td>";
  1015. print "</tr>";
  1016. }
  1017. }
  1018. print "</tbody></table></div><br>\n";
  1019.  
  1020. }
  1021.  
  1022.  
  1023. function iriGetLanguage($accepted) {
  1024. return substr($accepted,0,2);
  1025. }
  1026.  
  1027.  
  1028. function iriGetQueryPairs($url){
  1029. $parsed_url = parse_url($url);
  1030. $tab=parse_url($url);
  1031. $host = $tab['host'];
  1032. if(key_exists("query",$tab)){
  1033. $query=$tab["query"];
  1034. return explode("&",$query);
  1035. }
  1036. else{return null;}
  1037. }
  1038.  
  1039.  
  1040. function iriGetOS($arg){
  1041. $arg=str_replace(" ","",$arg);
  1042. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/os.dat');
  1043. foreach($lines as $line_num => $os) {
  1044. list($nome_os,$id_os)=explode("|",$os);
  1045. if(strpos($arg,$id_os)===FALSE) continue;
  1046. return $nome_os; // riconosciuto
  1047. }
  1048. return '';
  1049. }
  1050.  
  1051.  
  1052. function iriGetBrowser($arg){
  1053. $arg=str_replace(" ","",$arg);
  1054. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/browser.dat');
  1055. foreach($lines as $line_num => $browser) {
  1056. list($nome,$id)=explode("|",$browser);
  1057. if(strpos($arg,$id)===FALSE) continue;
  1058. return $nome; // riconosciuto
  1059. }
  1060. return '';
  1061. }
  1062.  
  1063. function iriCheckBanIP($arg){
  1064. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/banips.dat');
  1065. foreach($lines as $line_num => $banip) {
  1066. if(strpos($arg,rtrim($banip,"\n"))===FALSE) continue;
  1067. return ''; // riconosciuto, da scartare
  1068. }
  1069. return $arg;
  1070. }
  1071.  
  1072. function iriGetSE($referrer = null){
  1073. $key = null;
  1074. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/searchengines.dat');
  1075. foreach($lines as $line_num => $se) {
  1076. list($nome,$url,$key)=explode("|",$se);
  1077. if(strpos($referrer,$url)===FALSE) continue;
  1078. # trovato se
  1079. $variables = iriGetQueryPairs(html_entity_decode($referrer));
  1080. $i = count($variables);
  1081. while($i--){
  1082. $tab=explode("=",$variables[$i]);
  1083. if($tab[0] == $key){return ($nome."|".urldecode($tab[1]));}
  1084. }
  1085. }
  1086. return null;
  1087. }
  1088.  
  1089. function iriGetSpider($agent = null){
  1090. $agent=str_replace(" ","",$agent);
  1091. $key = null;
  1092. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/spider.dat');
  1093. foreach($lines as $line_num => $spider) {
  1094. list($nome,$key)=explode("|",$spider);
  1095. if(strpos($agent,$key)===FALSE) continue;
  1096. # trovato
  1097. return $nome;
  1098. }
  1099. return null;
  1100. }
  1101.  
  1102.  
  1103. function iri_StatPress_lastmonth() {
  1104. $ta = getdate(current_time('timestamp'));
  1105.  
  1106. $year = $ta['year'];
  1107. $month = $ta['mon'];
  1108.  
  1109. --$month; // go back 1 month
  1110.  
  1111. if( $month === 0 ): // if this month is Jan
  1112. --$year; // go back a year
  1113. $month = 12; // last month is Dec
  1114. endif;
  1115.  
  1116. // return in format 'YYYYMM'
  1117. return sprintf( $year.'%02d', $month);
  1118. }
  1119.  
  1120.  
  1121. function iri_StatPress_CreateTable() {
  1122. global $wpdb;
  1123. global $wp_db_version;
  1124. $table_name = $wpdb->prefix . "statpress";
  1125. $sql_createtable = "CREATE TABLE " . $table_name . " (
  1126. id mediumint(9) NOT NULL AUTO_INCREMENT,
  1127. date char(8),
  1128. time char(8),
  1129. ip char(15),
  1130. urlrequested varchar(250),
  1131. agent varchar(250),
  1132. referrer varchar(250),
  1133. search varchar(250),
  1134. nation varchar(2),
  1135. os varchar(30),
  1136. browser varchar(32),
  1137. searchengine varchar(16),
  1138. spider varchar(32),
  1139. feed varchar(8),
  1140. user varchar(16),
  1141. timestamp varchar(10),
  1142. UNIQUE KEY id (id)
  1143. );";
  1144. if($wp_db_version >= 5540) $page = 'wp-admin/includes/upgrade.php';
  1145. else $page = 'wp-admin/upgrade'.'-functions.php';
  1146. require_once(ABSPATH . $page);
  1147. dbDelta($sql_createtable);
  1148. }
  1149.  
  1150. function iri_StatPress_is_feed($url) {
  1151. if (stristr($url,get_bloginfo('rdf_url')) != FALSE) { return 'RDF'; }
  1152. if (stristr($url,get_bloginfo('rss2_url')) != FALSE) { return 'RSS2'; }
  1153. if (stristr($url,get_bloginfo('rss_url')) != FALSE) { return 'RSS'; }
  1154. if (stristr($url,get_bloginfo('atom_url')) != FALSE) { return 'ATOM'; }
  1155. if (stristr($url,get_bloginfo('comments_rss2_url')) != FALSE) { return 'COMMENT'; }
  1156. if (stristr($url,get_bloginfo('comments_atom_url')) != FALSE) { return 'COMMENT'; }
  1157. if (stristr($url,'wp-feed.php') != FALSE) { return 'RSS2'; }
  1158. if (stristr($url,'/feed/') != FALSE) { return 'RSS2'; }
  1159. return '';
  1160. }
  1161.  
  1162. function iriStatAppend() {
  1163. global $wpdb;
  1164. $table_name = $wpdb->prefix . "statpress";
  1165. global $userdata;
  1166. global $_STATPRESS;
  1167. get_currentuserinfo();
  1168. $feed='';
  1169.  
  1170. // Time
  1171. $timestamp = current_time('timestamp');
  1172. $vdate = gmdate("Ymd",$timestamp);
  1173. $vtime = gmdate("H:i:s",$timestamp);
  1174.  
  1175. // IP
  1176. $ipAddress = $_SERVER['REMOTE_ADDR'];
  1177. if(iriCheckBanIP($ipAddress) == '') { return ''; }
  1178. if(get_option('statpress_cryptip')=='checked') {
  1179. $ipAddress = crypt($ipAddress,'statpress');
  1180. }
  1181.  
  1182. // URL (requested)
  1183. $urlRequested=iri_StatPress_URL();
  1184. if (eregi(".ico$", $urlRequested)) { return ''; }
  1185. if (eregi("favicon.ico", $urlRequested)) { return ''; }
  1186. if (eregi(".css$", $urlRequested)) { return ''; }
  1187. if (eregi(".js$", $urlRequested)) { return ''; }
  1188. if (stristr($urlRequested,"/wp-content/plugins") != FALSE) { return ''; }
  1189. if (stristr($urlRequested,"/wp-content/themes") != FALSE) { return ''; }
  1190. if (stristr($urlRequested,"/wp-admin/") != FALSE) { return ''; }
  1191. $urlRequested=mysql_real_escape_string($urlRequested);
  1192.  
  1193. $referrer = (isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '');
  1194. $referrer=mysql_real_escape_string($referrer);
  1195.  
  1196. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '');
  1197. $userAgent=mysql_real_escape_string($userAgent);
  1198.  
  1199. $spider=iriGetSpider($userAgent);
  1200.  
  1201. if(($spider != '') and (get_option('statpress_donotcollectspider')=='checked')) { return ''; }
  1202.  
  1203. if($spider != '') {
  1204. $os=''; $browser='';
  1205. } else {
  1206. // Trap feeds
  1207. $feed=iri_StatPress_is_feed(get_bloginfo('url').$_SERVER['REQUEST_URI']);
  1208. // Get OS and browser
  1209. $os=iriGetOS($userAgent);
  1210. $browser=iriGetBrowser($userAgent);
  1211. list($searchengine,$search_phrase)=explode("|",iriGetSE($referrer));
  1212. }
  1213. // Country (ip2nation table) or language
  1214. $countrylang="";
  1215. if($wpdb->get_var("SHOW TABLES LIKE 'ip2nation'") == 'ip2nation') {
  1216. $sql='SELECT * FROM ip2nation WHERE ip < INET_ATON("'.$ipAddress.'") ORDER BY ip DESC LIMIT 0,1';
  1217. $qry = $wpdb->get_row($sql);
  1218. $countrylang=$qry->country;
  1219. }
  1220. if($countrylang == '') {
  1221. $countrylang=iriGetLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  1222. }
  1223. // Auto-delete visits if...
  1224. if(get_option('statpress_autodelete') != '') {
  1225. $t=gmdate("Ymd",strtotime('-'.get_option('statpress_autodelete')));
  1226. $results = $wpdb->query( "DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
  1227. }
  1228. if ((!is_user_logged_in()) OR (get_option('statpress_collectloggeduser')=='checked')) {
  1229. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  1230. iri_StatPress_CreateTable();
  1231. }
  1232. $insert = "INSERT INTO " . $table_name .
  1233. " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,timestamp) " .
  1234. "VALUES ('$vdate','$vtime','$ipAddress','$urlRequested','".addslashes(strip_tags($userAgent))."','$referrer','" .
  1235. addslashes(strip_tags($search_phrase))."','".$countrylang."','$os','$browser','$searchengine','$spider','$feed','$userdata->user_login','$timestamp')";
  1236. $results = $wpdb->query( $insert );
  1237. }
  1238. }
  1239.  
  1240.  
  1241. function iriStatPressUpdate() {
  1242. global $wpdb;
  1243. $table_name = $wpdb->prefix . "statpress";
  1244.  
  1245. $wpdb->show_errors();
  1246.  
  1247. print "<div class='wrap'><table class='widefat'><thead><tr><th scope='col'><h2>".__('Updating...','statpress')."</h2></th><th scope='col' style='width:150px;'>".__('Size','statpress')."</th><th scope='col' style='width:100px;'>".__('Result','statpress')."</th><th></th></tr></thead>";
  1248. print "<tbody id='the-list'>";
  1249.  
  1250. # check if ip2nation .sql file exists
  1251. if(file_exists(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql')) {
  1252. print "<tr><td>ip2nation.sql</td>";
  1253. $FP = fopen (ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql', 'r' );
  1254. $READ = fread ( $FP, filesize (ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/ip2nation.sql') );
  1255. $READ = explode ( ";\n", $READ );
  1256. foreach ( $READ as $RED ) {
  1257. if($RES != '') { $wpdb->query($RED); }
  1258. }
  1259. print "<td>".iritablesize("ip2nation")."</td>";
  1260. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1261. }
  1262.  
  1263. # update table
  1264. print "<tr><td>Struct $table_name</td>";
  1265. iri_StatPress_CreateTable();
  1266. print "<td>".iritablesize($wpdb->prefix."statpress")."</td>";
  1267. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1268.  
  1269. # Update Feed
  1270. print "<tr><td>Feeds</td>";
  1271. $wpdb->query("UPDATE $table_name SET feed='';");
  1272. # not standard
  1273. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%/feed/%';");
  1274. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%wp-feed.php%';");
  1275. # standard blog info urls
  1276. $s=iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url'));
  1277. if($s != '') {
  1278. $wpdb->query("UPDATE $table_name SET feed='COMMENT' WHERE INSTR(urlrequested,'$s')>0;");
  1279. }
  1280. $s=iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url'));
  1281. if($s != '') {
  1282. $wpdb->query("UPDATE $table_name SET feed='COMMENT' WHERE INSTR(urlrequested,'$s')>0;");
  1283. }
  1284. $s=iri_StatPress_extractfeedreq(get_bloginfo('atom_url'));
  1285. if($s != '') {
  1286. $wpdb->query("UPDATE $table_name SET feed='ATOM' WHERE INSTR(urlrequested,'$s')>0;");
  1287. }
  1288. $s=iri_StatPress_extractfeedreq(get_bloginfo('rdf_url'));
  1289. if($s != '') {
  1290. $wpdb->query("UPDATE $table_name SET feed='RDF' WHERE INSTR(urlrequested,'$s')>0;");
  1291. }
  1292. $s=iri_StatPress_extractfeedreq(get_bloginfo('rss_url'));
  1293. if($s != '') {
  1294. $wpdb->query("UPDATE $table_name SET feed='RSS' WHERE INSTR(urlrequested,'$s')>0;");
  1295. }
  1296. $s=iri_StatPress_extractfeedreq(get_bloginfo('rss2_url'));
  1297. if($s != '') {
  1298. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE INSTR(urlrequested,'$s')>0;");
  1299. }
  1300.  
  1301. $wpdb->query("UPDATE $table_name SET feed = '' WHERE isnull(feed);");
  1302.  
  1303. print "<td></td>";
  1304. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1305.  
  1306. # Update OS
  1307. print "<tr><td>OSes</td>";
  1308. $wpdb->query("UPDATE $table_name SET os = '';");
  1309. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/os.dat');
  1310. foreach($lines as $line_num => $os) {
  1311. list($nome_os,$id_os)=explode("|",$os);
  1312. $qry="UPDATE $table_name SET os = '$nome_os' WHERE os='' AND replace(agent,' ','') LIKE '%".$id_os."%';";
  1313. $wpdb->query($qry);
  1314. }
  1315. print "<td></td>";
  1316. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1317.  
  1318.  
  1319. # Update Browser
  1320. print "<tr><td>Browsers</td>";
  1321. $wpdb->query("UPDATE $table_name SET browser = '';");
  1322. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/browser.dat');
  1323. foreach($lines as $line_num => $browser) {
  1324. list($nome,$id)=explode("|",$browser);
  1325. $qry="UPDATE $table_name SET browser = '$nome' WHERE browser='' AND replace(agent,' ','') LIKE '%".$id."%';";
  1326. $wpdb->query($qry);
  1327. }
  1328. print "<td></td>";
  1329. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1330.  
  1331.  
  1332. # Update Spider
  1333. print "<tr><td>Spiders</td>";
  1334. $wpdb->query("UPDATE $table_name SET spider = '';");
  1335. $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/spider.dat');
  1336. foreach($lines as $line_num => $spider) {
  1337. list($nome,$id)=explode("|",$spider);
  1338. $qry="UPDATE $table_name SET spider = '$nome',os='',browser='' WHERE spider='' AND replace(agent,' ','') LIKE '%".$id."%';";
  1339. $wpdb->query($qry);
  1340. }
  1341. print "<td></td>";
  1342. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1343.  
  1344.  
  1345. # Update Search engine
  1346. print "<tr><td>Search engines</td>";
  1347. $wpdb->query("UPDATE $table_name SET searchengine = '', search='';");
  1348. $qry = $wpdb->get_results("SELECT id, referrer FROM $table_name");
  1349. foreach ($qry as $rk) {
  1350. list($searchengine,$search_phrase)=explode("|",iriGetSE($rk->referrer));
  1351. if($searchengine <> '') {
  1352. $q="UPDATE $table_name SET searchengine = '$searchengine', search='".addslashes($search_phrase)."' WHERE id=".$rk->id;
  1353. $wpdb->query($q);
  1354. }
  1355. }
  1356. print "<td></td>";
  1357. print "<td><IMG style='border:0px;width:20px;height:20px;' SRC='/wp-content/plugins/".dirname(plugin_basename(__FILE__))."/images/ok.gif'></td></tr>";
  1358.  
  1359.  
  1360. print "</tbody></table></div><br>\n";
  1361. $wpdb->hide_errors();
  1362. }
  1363.  
  1364.  
  1365. function StatPress_Widget($w='') {
  1366.  
  1367. }
  1368.  
  1369. function StatPress_Print($body='') {
  1370. print iri_StatPress_Vars($body);
  1371. }
  1372.  
  1373.  
  1374. function iri_StatPress_Vars($body) {
  1375. global $wpdb;
  1376. $table_name = $wpdb->prefix . "statpress";
  1377. if(strpos(strtolower($body),"%visits%") !== FALSE) {
  1378. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE date = '".gmdate("Ymd",current_time('timestamp'))."' and spider='' and feed='';");
  1379. $body = str_replace("%visits%", $qry[0]->pageview, $body);
  1380. }
  1381. if(strpos(strtolower($body),"%totalvisits%") !== FALSE) {
  1382. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='';");
  1383. $body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
  1384. }
  1385. if(strpos(strtolower($body),"%thistotalvisits%") !== FALSE) {
  1386. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='".iri_StatPress_URL()."';");
  1387. $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
  1388. }
  1389. if(strpos(strtolower($body),"%since%") !== FALSE) {
  1390. $qry = $wpdb->get_results("SELECT date FROM $table_name ORDER BY date LIMIT 1;");
  1391. $body = str_replace("%since%", irihdate($qry[0]->date), $body);
  1392. }
  1393. if(strpos(strtolower($body),"%os%") !== FALSE) {
  1394. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  1395. $os=iriGetOS($userAgent);
  1396. $body = str_replace("%os%", $os, $body);
  1397. }
  1398. if(strpos(strtolower($body),"%browser%") !== FALSE) {
  1399. $browser=iriGetBrowser($userAgent);
  1400. $body = str_replace("%browser%", $browser, $body);
  1401. }
  1402. if(strpos(strtolower($body),"%ip%") !== FALSE) {
  1403. $ipAddress = $_SERVER['REMOTE_ADDR'];
  1404. $body = str_replace("%ip%", $ipAddress, $body);
  1405. }
  1406. if(strpos(strtolower($body),"%visitorsonline%") !== FALSE) {
  1407. $to_time = current_time('timestamp');
  1408. $from_time = strtotime('-4 minutes', $to_time);
  1409. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as visitors FROM $table_name WHERE spider='' and feed='' AND timestamp BETWEEN $from_time AND $to_time;");
  1410. $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
  1411. }
  1412. if(strpos(strtolower($body),"%usersonline%") !== FALSE) {
  1413. $to_time = current_time('timestamp');
  1414. $from_time = strtotime('-4 minutes', $to_time);
  1415. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as users FROM $table_name WHERE spider='' and feed='' AND user<>'' AND timestamp BETWEEN $from_time AND $to_time;");
  1416. $body = str_replace("%usersonline%", $qry[0]->users, $body);
  1417. }
  1418. if(strpos(strtolower($body),"%toppost%") !== FALSE) {
  1419. $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM $table_name WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT 1;");
  1420. $body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body);
  1421. }
  1422. if(strpos(strtolower($body),"%topbrowser%") !== FALSE) {
  1423. $qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY browser ORDER BY totale DESC LIMIT 1;");
  1424. $body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body);
  1425. }
  1426. if(strpos(strtolower($body),"%topos%") !== FALSE) {
  1427. $qry = $wpdb->get_results("SELECT os,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY os ORDER BY totale DESC LIMIT 1;");
  1428. $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body);
  1429. }
  1430. return $body;
  1431. }
  1432.  
  1433.  
  1434. function iri_StatPress_TopPosts($limit=5, $showcounts='checked') {
  1435. global $wpdb;
  1436. $res="\n<ul>\n";
  1437. $table_name = $wpdb->prefix . "statpress";
  1438. $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM $table_name WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT $limit;");
  1439. foreach ($qry as $rk) {
  1440. $res.="<li><a href='?".$rk->urlrequested."'>".iri_StatPress_Decode($rk->urlrequested)."</a></li>\n";
  1441. if(strtolower($showcounts) == 'checked') { $res.=" (".$rk->totale.")"; }
  1442. }
  1443. return "$res</ul>\n";
  1444. }
  1445.  
  1446.  
  1447. function widget_statpress_init($args) {
  1448. if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
  1449. return;
  1450. // Multifunctional StatPress pluging
  1451. function widget_statpress_control() {
  1452. $options = get_option('widget_statpress');
  1453. if ( !is_array($options) )
  1454. $options = array('title'=>'StatPress', 'body'=>'Visits today: %visits%');
  1455. if ( $_POST['statpress-submit'] ) {
  1456. $options['title'] = strip_tags(stripslashes($_POST['statpress-title']));
  1457. $options['body'] = stripslashes($_POST['statpress-body']);
  1458. update_option('widget_statpress', $options);
  1459. }
  1460. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1461. $body = htmlspecialchars($options['body'], ENT_QUOTES);
  1462. // the form
  1463. echo '<p style="text-align:right;"><label for="statpress-title">' . __('Title:') . ' <input style="width: 250px;" id="statpress-title" name="statpress-title" type="text" value="'.$title.'" /></label></p>';
  1464. echo '<p style="text-align:right;"><label for="statpress-body"><div>' . __('Body:', 'widgets') . '</div><textarea style="width: 288px;height:100px;" id="statpress-body" name="statpress-body" type="textarea">'.$body.'</textarea></label></p>';
  1465. echo '<input type="hidden" id="statpress-submit" name="statpress-submit" value="1" /><div style="font-size:7pt;">%totalvisits% %visits% %thistotalvisits% %os% %browser% %ip% %since% %visitorsonline% %usersonline% %toppost% %topbrowser% %topos%</div>';
  1466. }
  1467. function widget_statpress($args) {
  1468. extract($args);
  1469. $options = get_option('widget_statpress');
  1470. $title = $options['title'];
  1471. $body = $options['body'];
  1472. echo $before_widget;
  1473. print($before_title . $title . $after_title);
  1474. print iri_StatPress_Vars($body);
  1475. echo $after_widget;
  1476. }
  1477. register_sidebar_widget('StatPress', 'widget_statpress');
  1478. register_widget_control(array('StatPress','widgets'), 'widget_statpress_control', 300, 210);
  1479.  
  1480. // Top posts
  1481. function widget_statpresstopposts_control() {
  1482. $options = get_option('widget_statpresstopposts');
  1483. if ( !is_array($options) ) {
  1484. $options = array('title'=>'StatPress TopPosts', 'howmany'=>'5', 'showcounts'=>'checked');
  1485. }
  1486. if ( $_POST['statpresstopposts-submit'] ) {
  1487. $options['title'] = strip_tags(stripslashes($_POST['statpresstopposts-title']));
  1488. $options['howmany'] = stripslashes($_POST['statpresstopposts-howmany']);
  1489. $options['showcounts'] = stripslashes($_POST['statpresstopposts-showcounts']);
  1490. if($options['showcounts'] == "1") {$options['showcounts']='checked';}
  1491. update_option('widget_statpresstopposts', $options);
  1492. }
  1493. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1494. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  1495. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  1496. // the form
  1497. echo '<p style="text-align:right;"><label for="statpresstopposts-title">' . __('Title','statpress') . ' <input style="width: 250px;" id="statpress-title" name="statpresstopposts-title" type="text" value="'.$title.'" /></label></p>';
  1498. echo '<p style="text-align:right;"><label for="statpresstopposts-howmany">' . __('Limit results to','statpress') . ' <input style="width: 100px;" id="statpresstopposts-howmany" name="statpresstopposts-howmany" type="text" value="'.$howmany.'" /></label></p>';
  1499. echo '<p style="text-align:right;"><label for="statpresstopposts-showcounts">' . __('Visits','statpress') . ' <input id="statpresstopposts-showcounts" name="statpresstopposts-showcounts" type=checkbox value="checked" '.$showcounts.' /></label></p>';
  1500. echo '<input type="hidden" id="statpress-submitTopPosts" name="statpresstopposts-submit" value="1" />';
  1501. }
  1502. function widget_statpresstopposts($args) {
  1503. extract($args);
  1504. $options = get_option('widget_statpresstopposts');
  1505. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1506. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  1507. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  1508. echo $before_widget;
  1509. print($before_title . $title . $after_title);
  1510. print iri_StatPress_TopPosts($howmany,$showcounts);
  1511. echo $after_widget;
  1512. }
  1513. register_sidebar_widget('StatPress TopPosts', 'widget_statpresstopposts');
  1514. register_widget_control(array('StatPress TopPosts','widgets'), 'widget_statpresstopposts_control', 300, 110);
  1515. }
  1516.  
  1517.  
  1518. load_plugin_textdomain('statpress', 'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/locale');
  1519.  
  1520. add_action('admin_menu', 'iri_add_pages');
  1521. add_action('plugins_loaded', 'widget_statpress_init');
  1522. add_action('send_headers', 'iriStatAppend'); //add_action('wp_head', 'iriStatAppend');
  1523. add_action('init','iri_checkExport');
  1524.  
  1525. register_activation_hook(__FILE__,'iri_StatPress_CreateTable');
  1526.  
  1527. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement