PageRenderTime 95ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/statpress-reloaded/statpress.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 2143 lines | 1802 code | 196 blank | 145 comment | 297 complexity | dc13578254ba6f93217fd565059f1d82 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. /*
  3. Plugin Name: StatPress Reloaded
  4. Plugin URI: http://blog.matrixagents.org/wp-plugins/
  5. Description: Improved real time stats for your blog
  6. Version: 1.5.21
  7. Author: Manuel Grabowski
  8. Author URI: http://blog.matrixagents.org/
  9. */
  10. $_STATPRESS['version'] = '1.5.21';
  11. $_STATPRESS['feedtype'] = '';
  12. if ($_GET['statpress_action'] == 'exportnow')
  13. {
  14. iriStatPressExportNow();
  15. }
  16. function iri_add_pages()
  17. {
  18. // Create table if it doesn't exist
  19. global $wpdb;
  20. $table_name = $wpdb->prefix . 'statpress';
  21. if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
  22. {
  23. iri_StatPress_CreateTable();
  24. }
  25. // add submenu
  26. $mincap = get_option('statpress_mincap');
  27. if ($mincap == '')
  28. {
  29. $mincap = 'level_8';
  30. }
  31. add_menu_page('StatPress Reloaded', 'StatPress', $mincap, __FILE__, 'iriStatPress');
  32. add_submenu_page(__FILE__, __('Details', 'statpress'), __('Details', 'statpress'), $mincap, __FILE__ . '&statpress_action=details', 'iriStatPressDetails');
  33. add_submenu_page(__FILE__, __('Spy', 'statpress'), __('Spy', 'statpress'), $mincap, __FILE__ . '&statpress_action=spy', 'iriStatPressSpy');
  34. add_submenu_page(__FILE__, __('Search', 'statpress'), __('Search', 'statpress'), $mincap, __FILE__ . '&statpress_action=search', 'iriStatPressSearch');
  35. add_submenu_page(__FILE__, __('Export', 'statpress'), __('Export', 'statpress'), $mincap, __FILE__ . '&statpress_action=export', 'iriStatPressExport');
  36. add_submenu_page(__FILE__, __('Options', 'statpress'), __('Options', 'statpress'), $mincap, __FILE__ . '&statpress_action=options', 'iriStatPressOptions');
  37. add_submenu_page(__FILE__, __('User Agents', 'statpress'), __('User Agents', 'statpress'), $mincap, __FILE__ . '&statpress_action=agents', 'iriStatPressAgents');
  38. add_submenu_page(__FILE__, __('StatPressUpdate', 'statpress'), __('StatPressUpdate', 'statpress'), $mincap, __FILE__ . '&statpress_action=up', 'iriStatPressUpdate');
  39. //add_submenu_page(__FILE__, __('Support','statpress'), __('Support','statpress'), $mincap, 'http://matrixagents.org/phpBB/viewforum.php?f=3');
  40. }
  41. function permalinksEnabled()
  42. {
  43. global $wpdb;
  44. $result = $wpdb->get_row('SELECT `option_value` FROM `' . $wpdb->prefix . 'options` WHERE `option_name` = "permalink_structure"');
  45. if ($result->option_value != '')
  46. {
  47. return true;
  48. }
  49. else
  50. {
  51. return false;
  52. }
  53. }
  54. function my_substr($str, $x, $y = 0)
  55. {
  56. if($y == 0)
  57. {
  58. $y = strlen($str) - $x;
  59. }
  60. if(function_exists('mb_substr'))
  61. {
  62. return mb_substr($str, $x, $y);
  63. }
  64. else
  65. {
  66. return substr($str, $x, $y);
  67. }
  68. }
  69. function iriStatPress()
  70. {
  71. if ($_GET['statpress_action'] == 'export')
  72. {
  73. iriStatPressExport();
  74. }
  75. elseif ($_GET['statpress_action'] == 'up')
  76. {
  77. iriStatPressUpdate();
  78. }
  79. elseif ($_GET['statpress_action'] == 'spy')
  80. {
  81. iriStatPressSpy();
  82. }
  83. elseif ($_GET['statpress_action'] == 'search')
  84. {
  85. iriStatPressSearch();
  86. }
  87. elseif ($_GET['statpress_action'] == 'details')
  88. {
  89. iriStatPressDetails();
  90. }
  91. elseif ($_GET['statpress_action'] == 'options')
  92. {
  93. iriStatPressOptions();
  94. }
  95. elseif ($_GET['statpress_action'] == 'overview')
  96. {
  97. iriStatPressMain();
  98. }
  99. elseif ($_GET['statpress_action'] == 'agents')
  100. {
  101. iriStatPressAgents();
  102. }
  103. else
  104. {
  105. iriStatPressMain();
  106. }
  107. }
  108. function iriStatPressOptions()
  109. {
  110. if ($_POST['saveit'] == 'yes')
  111. {
  112. update_option('statpress_collectloggeduser', $_POST['statpress_collectloggeduser']);
  113. update_option('statpress_autodelete', $_POST['statpress_autodelete']);
  114. update_option('statpress_daysinoverviewgraph', $_POST['statpress_daysinoverviewgraph']);
  115. update_option('statpress_mincap', $_POST['statpress_mincap']);
  116. update_option('statpress_donotcollectspider', $_POST['statpress_donotcollectspider']);
  117. update_option('statpress_autodelete_spider', $_POST['statpress_autodelete_spider']);
  118. // update database too
  119. iri_StatPress_CreateTable();
  120. print "<br /><div class='updated'><p>" . __('Saved', 'statpress') . "!</p></div>";
  121. }
  122. else
  123. {
  124. ?>
  125. <div class='wrap'><h2><?php
  126. _e('Options', 'statpress');
  127. ?></h2>
  128. <form method=post><table width=100%>
  129. <?php
  130. print "<tr><td><input type=checkbox name='statpress_collectloggeduser' value='checked' " . get_option('statpress_collectloggeduser') . "> " . __('Collect data about logged users, too.', 'statpress') . "</td></tr>";
  131. print "<tr><td><input type=checkbox name='statpress_donotcollectspider' value='checked' " . get_option('statpress_donotcollectspider') . "> " . __('Do not collect spiders visits', 'statpress') . "</td></tr>";
  132. ?>
  133. <tr><td><?php
  134. _e('Automatically delete visits older than', 'statpress');
  135. ?>
  136. <select name="statpress_autodelete">
  137. <option value="" <?php
  138. if (get_option('statpress_autodelete') == '')
  139. print "selected";
  140. ?>><?php
  141. _e('Never delete!', 'statpress');
  142. ?></option>
  143. <option value="1 month" <?php
  144. if (get_option('statpress_autodelete') == "1 month")
  145. print "selected";
  146. ?>>1 <?php
  147. _e('month', 'statpress');
  148. ?></option>
  149. <option value="3 months" <?php
  150. if (get_option('statpress_autodelete') == "3 months")
  151. print "selected";
  152. ?>>3 <?php
  153. _e('months', 'statpress');
  154. ?></option>
  155. <option value="6 months" <?php
  156. if (get_option('statpress_autodelete') == "6 months")
  157. print "selected";
  158. ?>>6 <?php
  159. _e('months', 'statpress');
  160. ?></option>
  161. <option value="1 year" <?php
  162. if (get_option('statpress_autodelete') == "1 year")
  163. print "selected";
  164. ?>>1 <?php
  165. _e('year', 'statpress');
  166. ?></option>
  167. </select></td></tr>
  168. <tr><td><?php _e('Automatically delete spider visits older than','statpress'); ?>
  169. <select name="statpress_autodelete_spider">
  170. <option value="" <?php if(get_option('statpress_autodelete_spider') =='' ) print "selected"; ?>><?php _e('Never delete!','statpress'); ?></option>
  171. <option value="1 day" <?php if(get_option('statpress_autodelete_spider') == "1 day") print "selected"; ?>>1 <?php _e('day','statpress'); ?></option>
  172. <option value="1 week" <?php if(get_option('statpress_autodelete_spider') == "1 week") print "selected"; ?>>1 <?php _e('week','statpress'); ?></option>
  173. <option value="1 month" <?php if(get_option('statpress_autodelete_spider') == "1 month") print "selected"; ?>>1 <?php _e('month','statpress'); ?></option>
  174. <option value="1 year" <?php if(get_option('statpress_autodelete_spider') == "1 year") print "selected"; ?>>1 <?php _e('year','statpress'); ?></option>
  175. </select></td></tr>
  176. <tr><td><?php
  177. _e('Days in Overview graph', 'statpress');
  178. ?>
  179. <select name="statpress_daysinoverviewgraph">
  180. <option value="7" <?php
  181. if (get_option('statpress_daysinoverviewgraph') == 7)
  182. print "selected";
  183. ?>>7</option>
  184. <option value="10" <?php
  185. if (get_option('statpress_daysinoverviewgraph') == 10)
  186. print "selected";
  187. ?>>10</option>
  188. <option value="20" <?php
  189. if (get_option('statpress_daysinoverviewgraph') == 20)
  190. print "selected";
  191. ?>>20</option>
  192. <option value="30" <?php
  193. if (get_option('statpress_daysinoverviewgraph') == 30)
  194. print "selected";
  195. ?>>30</option>
  196. <option value="50" <?php
  197. if (get_option('statpress_daysinoverviewgraph') == 50)
  198. print "selected";
  199. ?>>50</option>
  200. </select></td></tr>
  201. <tr><td><?php
  202. _e('Minimum capability to view stats', 'statpress');
  203. ?>
  204. <select name="statpress_mincap">
  205. <?php
  206. iri_dropdown_caps(get_option('statpress_mincap'));
  207. ?>
  208. </select>
  209. <a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_blank"><?php
  210. _e("more info", 'statpress');
  211. ?></a>
  212. </td></tr>
  213. <tr><td><br><input type=submit value="<?php
  214. _e('Save options', 'statpress');
  215. ?>"></td></tr>
  216. </tr>
  217. </table>
  218. <input type=hidden name=saveit value=yes>
  219. <input type=hidden name=page value=statpress><input type=hidden name=statpress_action value=options>
  220. </form>
  221. </div>
  222. <?php
  223. } // chiude saveit
  224. }
  225. function iri_dropdown_caps($default = false)
  226. {
  227. global $wp_roles;
  228. $role = get_role('administrator');
  229. foreach ($role->capabilities as $cap => $grant)
  230. {
  231. print "<option ";
  232. if ($default == $cap)
  233. {
  234. print "selected ";
  235. }
  236. print ">$cap</option>";
  237. }
  238. }
  239. function iriStatPressExport()
  240. {
  241. ?>
  242. <div class='wrap'><h2><?php
  243. _e('Export stats to text file', 'statpress');
  244. ?> (csv)</h2>
  245. <form method=get><table>
  246. <tr><td><?php
  247. _e('From', 'statpress');
  248. ?></td><td><input type=text name=from> (YYYYMMDD)</td></tr>
  249. <tr><td><?php
  250. _e('To', 'statpress');
  251. ?></td><td><input type=text name=to> (YYYYMMDD)</td></tr>
  252. <tr><td><?php
  253. _e('Fields delimiter', 'statpress');
  254. ?></td><td><select name=del><option>,</option><option>;</option><option>|</option></select></tr>
  255. <tr><td></td><td><input type=submit value=<?php
  256. _e('Export', 'statpress');
  257. ?>></td></tr>
  258. <input type=hidden name=page value=statpress><input type=hidden name=statpress_action value=exportnow>
  259. </table></form>
  260. </div>
  261. <?php
  262. }
  263. function iriStatPressExportNow()
  264. {
  265. global $wpdb;
  266. $table_name = $wpdb->prefix . "statpress";
  267. $filename = get_bloginfo('title') . "-statpress_" . $_GET['from'] . "-" . $_GET['to'] . ".csv";
  268. header('Content-Description: File Transfer');
  269. header("Content-Disposition: attachment; filename=$filename");
  270. header('Content-Type: text/plain charset=' . get_option('blog_charset'), true);
  271. $qry = $wpdb->get_results("SELECT * FROM $table_name WHERE date>='" . (date("Ymd", strtotime(my_substr($_GET['from'], 0, 8)))) . "' AND date<='" . (date("Ymd", strtotime(my_substr($_GET['to'], 0, 8)))) . "';");
  272. $del = my_substr($_GET['del'], 0, 1);
  273. 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";
  274. foreach ($qry as $rk)
  275. {
  276. print '"' . $rk->date . '"' . $del . '"' . $rk->time . '"' . $del . '"' . $rk->ip . '"' . $del . '"' . $rk->urlrequested . '"' . $del . '"' . $rk->agent . '"' . $del . '"' . $rk->referrer . '"' . $del . '"' . urldecode($rk->search) . '"' . $del . '"' . $rk->nation . '"' . $del . '"' . $rk->os . '"' . $del . '"' . $rk->browser . '"' . $del . '"' . $rk->searchengine . '"' . $del . '"' . $rk->spider . '"' . $del . '"' . $rk->feed . '"' . "\n";
  277. }
  278. die();
  279. }
  280. function iriStatPressMain()
  281. {
  282. global $wpdb;
  283. $table_name = $wpdb->prefix . "statpress";
  284. // OVERVIEW table
  285. $unique_color = "#114477";
  286. $web_color = "#3377B6";
  287. $rss_color = "#f38f36";
  288. $spider_color = "#83b4d8";
  289. $lastmonth = iri_StatPress_lastmonth();
  290. $thismonth = gmdate('Ym', current_time('timestamp'));
  291. $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
  292. $today = gmdate('Ymd', current_time('timestamp'));
  293. $tlm[0] = my_substr($lastmonth, 0, 4);
  294. $tlm[1] = my_substr($lastmonth, 4, 2);
  295. print "<div class='wrap'><h2>" . __('Overview', 'statpress') . "</h2>";
  296. print "<table class='widefat'><thead><tr>
  297. <th scope='col'></th>
  298. <th scope='col'>" . __('Total', 'statpress') . "</th>
  299. <th scope='col'>" . __('Last month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', gmmktime(0, 0, 0, $tlm[1], 1, $tlm[0])) . "</font></th>
  300. <th scope='col'>" . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>
  301. <th scope='col'>" . __('Target', 'statpress') . " " . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>
  302. <th scope='col'>" . __('Yesterday', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp') - 86400) . "</font></th>
  303. <th scope='col'>" . __('Today', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) . "</font></th>
  304. </tr></thead>
  305. <tbody id='the-list'>";
  306. //###############################################################################################
  307. // VISITORS ROW
  308. print "<tr><td><div style='background:$unique_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Visitors', 'statpress') . "</td>";
  309. //TOTAL
  310. $qry_total = $wpdb->get_row("
  311. SELECT count(DISTINCT ip) AS visitors
  312. FROM $table_name
  313. WHERE feed=''
  314. AND spider=''
  315. ");
  316. print "<td>" . $qry_total->visitors . "</td>\n";
  317. //LAST MONTH
  318. $qry_lmonth = $wpdb->get_row("
  319. SELECT count(DISTINCT ip) AS visitors
  320. FROM $table_name
  321. WHERE feed=''
  322. AND spider=''
  323. AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'
  324. ");
  325. print "<td>" . $qry_lmonth->visitors . "</td>\n";
  326. //THIS MONTH
  327. $qry_tmonth = $wpdb->get_row("
  328. SELECT count(DISTINCT ip) AS visitors
  329. FROM $table_name
  330. WHERE feed=''
  331. AND spider=''
  332. AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'
  333. ");
  334. if ($qry_lmonth->visitors <> 0)
  335. {
  336. $pc = round(100 * ($qry_tmonth->visitors / $qry_lmonth->visitors) - 100, 1);
  337. if ($pc >= 0)
  338. $pc = "+" . $pc;
  339. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  340. }
  341. print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
  342. //TARGET
  343. $qry_tmonth->target = round($qry_tmonth->visitors / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t')));
  344. if ($qry_lmonth->visitors <> 0)
  345. {
  346. $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->visitors) - 100, 1);
  347. if ($pt >= 0)
  348. $pt = "+" . $pt;
  349. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  350. }
  351. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  352. //YESTERDAY
  353. $qry_y = $wpdb->get_row("
  354. SELECT count(DISTINCT ip) AS visitors
  355. FROM $table_name
  356. WHERE feed=''
  357. AND spider=''
  358. AND date = '" . mysql_real_escape_string($yesterday) . "'
  359. ");
  360. print "<td>" . $qry_y->visitors . "</td>\n";
  361. //TODAY
  362. $qry_t = $wpdb->get_row("
  363. SELECT count(DISTINCT ip) AS visitors
  364. FROM $table_name
  365. WHERE feed=''
  366. AND spider=''
  367. AND date = '" . mysql_real_escape_string($today) . "'
  368. ");
  369. print "<td>" . $qry_t->visitors . "</td>\n";
  370. print "</tr>";
  371. //###############################################################################################
  372. // PAGEVIEWS ROW
  373. print "<tr><td><div style='background:$web_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Pageviews', 'statpress') . "</td>";
  374. //TOTAL
  375. $qry_total = $wpdb->get_row("
  376. SELECT count(date) as pageview
  377. FROM $table_name
  378. WHERE feed=''
  379. AND spider=''
  380. ");
  381. print "<td>" . $qry_total->pageview . "</td>\n";
  382. //LAST MONTH
  383. $prec = 0;
  384. $qry_lmonth = $wpdb->get_row("
  385. SELECT count(date) as pageview
  386. FROM $table_name
  387. WHERE feed=''
  388. AND spider=''
  389. AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'
  390. ");
  391. print "<td>" . $qry_lmonth->pageview . "</td>\n";
  392. //THIS MONTH
  393. $qry_tmonth = $wpdb->get_row("
  394. SELECT count(date) as pageview
  395. FROM $table_name
  396. WHERE feed=''
  397. AND spider=''
  398. AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'
  399. ");
  400. if ($qry_lmonth->pageview <> 0)
  401. {
  402. $pc = round(100 * ($qry_tmonth->pageview / $qry_lmonth->pageview) - 100, 1);
  403. if ($pc >= 0)
  404. $pc = "+" . $pc;
  405. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  406. }
  407. print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
  408. //TARGET
  409. $qry_tmonth->target = round($qry_tmonth->pageview / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t')));
  410. if ($qry_lmonth->pageview <> 0)
  411. {
  412. $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->pageview) - 100, 1);
  413. if ($pt >= 0)
  414. $pt = "+" . $pt;
  415. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  416. }
  417. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  418. //YESTERDAY
  419. $qry_y = $wpdb->get_row("
  420. SELECT count(date) as pageview
  421. FROM $table_name
  422. WHERE feed=''
  423. AND spider=''
  424. AND date = '" . mysql_real_escape_string($yesterday) . "'
  425. ");
  426. print "<td>" . $qry_y->pageview . "</td>\n";
  427. //TODAY
  428. $qry_t = $wpdb->get_row("
  429. SELECT count(date) as pageview
  430. FROM $table_name
  431. WHERE feed=''
  432. AND spider=''
  433. AND date = '" . mysql_real_escape_string($today) . "'
  434. ");
  435. print "<td>" . $qry_t->pageview . "</td>\n";
  436. print "</tr>";
  437. //###############################################################################################
  438. // SPIDERS ROW
  439. print "<tr><td><div style='background:$spider_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Spiders', 'statpress') . "</td>";
  440. //TOTAL
  441. $qry_total = $wpdb->get_row("
  442. SELECT count(date) as spiders
  443. FROM $table_name
  444. WHERE feed=''
  445. AND spider<>''
  446. ");
  447. print "<td>" . $qry_total->spiders . "</td>\n";
  448. //LAST MONTH
  449. $prec = 0;
  450. $qry_lmonth = $wpdb->get_row("
  451. SELECT count(date) as spiders
  452. FROM $table_name
  453. WHERE feed=''
  454. AND spider<>''
  455. AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'
  456. ");
  457. print "<td>" . $qry_lmonth->spiders . "</td>\n";
  458. //THIS MONTH
  459. $prec = $qry_lmonth->spiders;
  460. $qry_tmonth = $wpdb->get_row("
  461. SELECT count(date) as spiders
  462. FROM $table_name
  463. WHERE feed=''
  464. AND spider<>''
  465. AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'
  466. ");
  467. if ($qry_lmonth->spiders <> 0)
  468. {
  469. $pc = round(100 * ($qry_tmonth->spiders / $qry_lmonth->spiders) - 100, 1);
  470. if ($pc >= 0)
  471. $pc = "+" . $pc;
  472. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  473. }
  474. print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
  475. //TARGET
  476. $qry_tmonth->target = round($qry_tmonth->spiders / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t')));
  477. if ($qry_lmonth->spiders <> 0)
  478. {
  479. $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->spiders) - 100, 1);
  480. if ($pt >= 0)
  481. $pt = "+" . $pt;
  482. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  483. }
  484. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  485. //YESTERDAY
  486. $qry_y = $wpdb->get_row("
  487. SELECT count(date) as spiders
  488. FROM $table_name
  489. WHERE feed=''
  490. AND spider<>''
  491. AND date = '" . mysql_real_escape_string($yesterday) . "'
  492. ");
  493. print "<td>" . $qry_y->spiders . "</td>\n";
  494. //TODAY
  495. $qry_t = $wpdb->get_row("
  496. SELECT count(date) as spiders
  497. FROM $table_name
  498. WHERE feed=''
  499. AND spider<>''
  500. AND date = '" . mysql_real_escape_string($today) . "'
  501. ");
  502. print "<td>" . $qry_t->spiders . "</td>\n";
  503. print "</tr>";
  504. //###############################################################################################
  505. // FEEDS ROW
  506. print "<tr><td><div style='background:$rss_color;width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Feeds', 'statpress') . "</td>";
  507. //TOTAL
  508. $qry_total = $wpdb->get_row("
  509. SELECT count(date) as feeds
  510. FROM $table_name
  511. WHERE feed<>''
  512. AND spider=''
  513. ");
  514. print "<td>" . $qry_total->feeds . "</td>\n";
  515. //LAST MONTH
  516. $qry_lmonth = $wpdb->get_row("
  517. SELECT count(date) as feeds
  518. FROM $table_name
  519. WHERE feed<>''
  520. AND spider=''
  521. AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'
  522. ");
  523. print "<td>" . $qry_lmonth->feeds . "</td>\n";
  524. //THIS MONTH
  525. $qry_tmonth = $wpdb->get_row("
  526. SELECT count(date) as feeds
  527. FROM $table_name
  528. WHERE feed<>''
  529. AND spider=''
  530. AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'
  531. ");
  532. if ($qry_lmonth->feeds <> 0)
  533. {
  534. $pc = round(100 * ($qry_tmonth->feeds / $qry_lmonth->feeds) - 100, 1);
  535. if ($pc >= 0)
  536. $pc = "+" . $pc;
  537. $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
  538. }
  539. print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
  540. //TARGET
  541. $qry_tmonth->target = round($qry_tmonth->feeds / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t')));
  542. if ($qry_lmonth->feeds <> 0)
  543. {
  544. $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->feeds) - 100, 1);
  545. if ($pt >= 0)
  546. $pt = "+" . $pt;
  547. $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
  548. }
  549. print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
  550. $qry_y = $wpdb->get_row("
  551. SELECT count(date) as feeds
  552. FROM $table_name
  553. WHERE feed<>''
  554. AND spider=''
  555. AND date = '" . mysql_real_escape_string($yesterday) . "'
  556. ");
  557. print "<td>" . $qry_y->feeds . "</td>\n";
  558. $qry_t = $wpdb->get_row("
  559. SELECT count(date) as feeds
  560. FROM $table_name
  561. WHERE feed<>''
  562. AND spider=''
  563. AND date = '" . mysql_real_escape_string($today) . "'
  564. ");
  565. print "<td>" . $qry_t->feeds . "</td>\n";
  566. print "</tr></table><br />\n\n";
  567. //###############################################################################################
  568. //###############################################################################################
  569. // THE GRAPHS
  570. // last "N" days graph NEW
  571. $gdays = get_option('statpress_daysinoverviewgraph');
  572. if ($gdays == 0)
  573. {
  574. $gdays = 20;
  575. }
  576. // $start_of_week = get_settings('start_of_week');
  577. $start_of_week = get_option('start_of_week');
  578. print '<table width="100%" border="0"><tr>';
  579. $qry = $wpdb->get_row("
  580. SELECT count(date) as pageview, date
  581. FROM $table_name
  582. GROUP BY date HAVING date >= '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gdays) . "'
  583. ORDER BY pageview DESC
  584. LIMIT 1
  585. ");
  586. $maxxday = $qry->pageview;
  587. if ($maxxday == 0)
  588. {
  589. $maxxday = 1;
  590. }
  591. // Y
  592. $gd = (90 / $gdays) . '%';
  593. for ($gg = $gdays - 1; $gg >= 0; $gg--)
  594. {
  595. //TOTAL VISITORS
  596. $qry_visitors = $wpdb->get_row("
  597. SELECT count(DISTINCT ip) AS total
  598. FROM $table_name
  599. WHERE feed=''
  600. AND spider=''
  601. AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'
  602. ");
  603. $px_visitors = round($qry_visitors->total * 100 / $maxxday);
  604. //TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
  605. $qry_pageviews = $wpdb->get_row("
  606. SELECT count(date) as total
  607. FROM $table_name
  608. WHERE feed=''
  609. AND spider=''
  610. AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'
  611. ");
  612. $px_pageviews = round($qry_pageviews->total * 100 / $maxxday);
  613. //TOTAL SPIDERS
  614. $qry_spiders = $wpdb->get_row("
  615. SELECT count(ip) AS total
  616. FROM $table_name
  617. WHERE feed=''
  618. AND spider<>''
  619. AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'
  620. ");
  621. $px_spiders = round($qry_spiders->total * 100 / $maxxday);
  622. //TOTAL FEEDS
  623. $qry_feeds = $wpdb->get_row("
  624. SELECT count(ip) AS total
  625. FROM $table_name
  626. WHERE feed<>''
  627. AND spider=''
  628. AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'
  629. ");
  630. $px_feeds = round($qry_feeds->total * 100 / $maxxday);
  631. $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
  632. print '<td width="' . $gd . '" valign="bottom"';
  633. if ($start_of_week == gmdate('w', current_time('timestamp') - 86400 * $gg))
  634. {
  635. print ' style="border-left:2px dotted gray;"';
  636. }
  637. // week-cut
  638. 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;'>
  639. <div style='background:#ffffff;width:100%;height:" . $px_white . "px;'></div>
  640. <div style='background:$unique_color;width:100%;height:" . $px_visitors . "px;' title='" . $qry_visitors->total . " " . __('visitors', 'statpress')."'></div>
  641. <div style='background:$web_color;width:100%;height:" . $px_pageviews . "px;' title='" . $qry_pageviews->total . " " . __('pageviews', 'statpress')."'></div>
  642. <div style='background:$spider_color;width:100%;height:" . $px_spiders . "px;' title='" . $qry_spiders->total . " " . __('spiders', 'statpress')."'></div>
  643. <div style='background:$rss_color;width:100%;height:" . $px_feeds . "px;' title='" . $qry_feeds->total . " " . __('feeds', 'statpress')."'></div>
  644. <div style='background:gray;width:100%;height:1px;'></div>
  645. <br />" . gmdate('d', current_time('timestamp') - 86400 * $gg) . ' ' . gmdate('M', current_time('timestamp') - 86400 * $gg) . "</div></td>\n";
  646. }
  647. print '</tr></table>';
  648. print '</div>';
  649. // END OF OVERVIEW
  650. //###################################################################################################
  651. $querylimit = "LIMIT 20";
  652. // Tabella Last hits
  653. 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', 'statpress') . "</th><th scope='col'>" . __('Threat', 'statpress') . "</th><th scope='col'>" . __('Domain', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('OS', 'statpress') . "</th><th scope='col'>" . __('Browser', 'statpress') . "</th><th scope='col'>" . __('Feed', 'statpress') . "</th></tr></thead>";
  654. print "<tbody id='the-list'>";
  655. $fivesdrafts = $wpdb->get_results("SELECT * FROM $table_name WHERE (os<>'' OR feed<>'') order by id DESC $querylimit");
  656. foreach ($fivesdrafts as $fivesdraft)
  657. {
  658. print "<tr>";
  659. print "<td>" . irihdate($fivesdraft->date) . "</td>";
  660. print "<td>" . $fivesdraft->time . "</td>";
  661. print "<td>" . $fivesdraft->ip . "</td>";
  662. print "<td>" . $fivesdraft->threat_score;
  663. if ($fivesdraft->threat_score > 0)
  664. {
  665. print "/";
  666. if ($fivesdraft->threat_type == 0)
  667. print "Sp"; // Spider
  668. else
  669. {
  670. if (($fivesdraft->threat_type & 1) == 1)
  671. print "S"; // Suspicious
  672. if (($fivesdraft->threat_type & 2) == 2)
  673. print "H"; // Harvester
  674. if (($fivesdraft->threat_type & 4) == 4)
  675. print "C"; // Comment spammer
  676. }
  677. }
  678. print "<td>" . $fivesdraft->nation . "</td>";
  679. print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested), 30) . "</td>";
  680. print "<td>" . $fivesdraft->os . "</td>";
  681. print "<td>" . $fivesdraft->browser . "</td>";
  682. print "<td>" . $fivesdraft->feed . "</td>";
  683. print "</tr>";
  684. }
  685. print "</table></div>";
  686. // Last Search terms
  687. 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>";
  688. print "<tbody id='the-list'>";
  689. $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM $table_name WHERE search<>'' ORDER BY id DESC $querylimit");
  690. foreach ($qry as $rk)
  691. {
  692. print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . urldecode($rk->search) . "</a></td><td>" . $rk->searchengine . "</td><td><a href='" . irigetblogurl() . ((strpos($rk->urlrequested, 'index.php') === FALSE) ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
  693. }
  694. print "</table></div>";
  695. // Referrer
  696. 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>";
  697. print "<tbody id='the-list'>";
  698. $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");
  699. foreach ($qry as $rk)
  700. {
  701. 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='" . irigetblogurl() . ((strpos($rk->urlrequested, 'index.php') === FALSE) ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
  702. }
  703. print "</table></div>";
  704. // Last Agents
  705. print "<div class='wrap'><h2>" . __('Last agents', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Agent', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
  706. print "<tbody id='the-list'>";
  707. $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM $table_name WHERE (agent <>'') ORDER BY id DESC $querylimit");
  708. foreach ($qry as $rk)
  709. {
  710. print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . $rk->agent . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
  711. }
  712. print "</table></div>";
  713. // Last pages
  714. 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'>" . __('What', 'statpress') . "</th></tr></thead>";
  715. print "<tbody id='the-list'>";
  716. $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM $table_name WHERE (spider='' AND feed='') ORDER BY id DESC $querylimit");
  717. foreach ($qry as $rk)
  718. {
  719. print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 60) . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
  720. }
  721. print "</table></div>";
  722. // Last Spiders
  723. print "<div class='wrap'><h2>" . __('Last spiders', 'statpress') . "</h2>";
  724. print "<table class='widefat'><thead><tr>";
  725. print "<th scope='col'>" . __('Date', 'statpress') . "</th>";
  726. print "<th scope='col'>" . __('Time', 'statpress') . "</th>";
  727. print "<th scope='col'>" . __('Spider', 'statpress') . "</th>";
  728. print "<th scope='col'>" . __('Page', 'statpress') . "</th>";
  729. print "<th scope='col'>" . __('Agent', 'statpress') . "</th>";
  730. print "</tr></thead><tbody id='the-list'>";
  731. $qry = $wpdb->get_results("SELECT date,time,agent,spider,urlrequested,agent FROM $table_name WHERE (spider<>'') ORDER BY id DESC $querylimit");
  732. foreach ($qry as $rk)
  733. {
  734. print "<tr><td>" . irihdate($rk->date) . "</td>";
  735. print "<td>" . $rk->time . "</td>";
  736. print "<td>" . $rk->spider . "</td>";
  737. print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 30) . "</td>";
  738. print "<td> " . $rk->agent . "</td></tr>\n";
  739. }
  740. print "</table></div>";
  741. print "<br />";
  742. print "&nbsp;<i>" . __('StatPress table size', 'statpress') . ": <b>" . iritablesize($wpdb->prefix . "statpress") . "</b></i><br />";
  743. print "&nbsp;<i>" . __('StatPress current time', 'statpress') . ": <b>" . current_time('mysql') . "</b></i><br />";
  744. print "&nbsp;<i>" . __('RSS2 url', 'statpress') . ": <b>" . get_bloginfo('rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')) . ")</b></i><br />";
  745. print "&nbsp;<i>" . __('ATOM url', 'statpress') . ": <b>" . get_bloginfo('atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('atom_url')) . ")</b></i><br />";
  746. print "&nbsp;<i>" . __('RSS url', 'statpress') . ": <b>" . get_bloginfo('rss_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss_url')) . ")</b></i><br />";
  747. print "&nbsp;<i>" . __('COMMENT RSS2 url', 'statpress') . ": <b>" . get_bloginfo('comments_rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url')) . ")</b></i><br />";
  748. print "&nbsp;<i>" . __('COMMENT ATOM url', 'statpress') . ": <b>" . get_bloginfo('comments_atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url')) . ")</b></i><br />";
  749. }
  750. function iriStatPressDetails()
  751. {
  752. global $wpdb;
  753. $table_name = $wpdb->prefix . "statpress";
  754. $querylimit = "LIMIT 10";
  755. // Top days
  756. iriValueTable("date", __('Top days', 'statpress'), 5);
  757. // O.S.
  758. iriValueTable("os", __('O.S.', 'statpress'), 0, "", "", "AND feed='' AND spider='' AND os<>''");
  759. // Browser
  760. iriValueTable("browser", __('Browser', 'statpress'), 0, "", "", "AND feed='' AND spider='' AND browser<>''");
  761. // Feeds
  762. iriValueTable("feed", __('Feeds', 'statpress'), 5, "", "", "AND feed<>''");
  763. // SE
  764. iriValueTable("searchengine", __('Search engines', 'statpress'), 10, "", "", "AND searchengine<>''");
  765. // Search terms
  766. iriValueTable("search", __('Top search terms', 'statpress'), 20, "", "", "AND search<>''");
  767. // Top referrer
  768. iriValueTable("referrer", __('Top referrer', 'statpress'), 10, "", "", "AND referrer<>'' AND referrer NOT LIKE '%" . get_bloginfo('url') . "%'");
  769. // Countries
  770. iriValueTable("nation", __('Countries (domains)', 'statpress'), 10, "", "", "AND nation<>'' AND spider=''");
  771. // Spider
  772. iriValueTable("spider", __('Spiders', 'statpress'), 10, "", "", "AND spider<>''");
  773. // Top Pages
  774. iriValueTable("urlrequested", __('Top pages', 'statpress'), 5, "", "urlrequested", "AND feed='' and spider=''");
  775. // Top Days - Unique visitors
  776. iriValueTable("date", __('Top Days - Unique visitors', 'statpress'), 5, "distinct", "ip", "AND feed='' and spider=''");
  777. /* Maddler 04112007: required patching iriValueTable */
  778. // Top Days - Pageviews
  779. iriValueTable("date", __('Top Days - Pageviews', 'statpress'), 5, "", "urlrequested", "AND feed='' and spider=''");
  780. /* Maddler 04112007: required patching iriValueTable */
  781. // Top IPs - Pageviews
  782. iriValueTable("ip", __('Top IPs - Pageviews', 'statpress'), 5, "", "urlrequested", "AND feed='' and spider=''");
  783. /* Maddler 04112007: required patching iriValueTable */
  784. }
  785. function iriStatPressSpy()
  786. {
  787. global $wpdb;
  788. $table_name = $wpdb->prefix . "statpress";
  789. $LIMIT = 20;
  790. if(isset($_GET['pn']))
  791. {
  792. // Get Current page from URL
  793. $page = $_GET['pn'];
  794. if($page <= 0)
  795. {
  796. // Page is less than 0 then set it to 1
  797. $page = 1;
  798. }
  799. }
  800. else
  801. {
  802. // URL does not show the page set it to 1
  803. $page = 1;
  804. }
  805. // Create MySQL Query String
  806. $strqry = "SELECT id FROM $table_name WHERE (spider='' AND feed='') GROUP BY ip";
  807. $query = $wpdb->get_results($strqry);
  808. $TOTALROWS = $wpdb->num_rows;
  809. $NumOfPages = $TOTALROWS / $LIMIT;
  810. $LimitValue = ($page * $LIMIT) - $LIMIT;
  811. // Spy
  812. $today = gmdate('Ymd', current_time('timestamp'));
  813. $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
  814. print "<div class='wrap'><h2>" . __('Spy', 'statpress') . "</h2>";
  815. $sql = "SELECT ip,nation,os,browser,agent FROM $table_name WHERE (spider='' AND feed='') GROUP BY ip ORDER BY id DESC LIMIT $LimitValue, $LIMIT";
  816. $qry = $wpdb->get_results($sql);
  817. ?>
  818. <script>
  819. function ttogle(thediv){
  820. if (document.getElementById(thediv).style.display=="inline") {
  821. document.getElementById(thediv).style.display="none"
  822. } else {document.getElementById(thediv).style.display="inline"}
  823. }
  824. </script>
  825. <div align="center">
  826. <div id="paginating" align="center">Pages:
  827. <?php
  828. // Check to make sure we&#x2019;re not on page 1 or Total number of pages is not 1
  829. if($page == ceil($NumOfPages) && $page != 1) {
  830. for($i = 1; $i <= ceil($NumOfPages)-1; $i++) {
  831. // Loop through the number of total pages
  832. if($i > 0) {
  833. // if $i greater than 0 display it as a hyperlink
  834. echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?page=statpress-reloaded/statpress.php&statpress_action=spy&pn=' . $i . '">' . $i . '</a> ';
  835. }
  836. }
  837. }
  838. if($page == ceil($NumOfPages) ) {
  839. $startPage = $page;
  840. } else {
  841. $startPage = 1;
  842. }
  843. for ($i = $startPage; $i <= $page+6; $i++) {
  844. // Display first 7 pages
  845. if ($i <= ceil($NumOfPages)) {
  846. // $page is not the last page
  847. if($i == $page) {
  848. // $page is current page
  849. echo " [{$i}] ";
  850. } else {
  851. // Not the current page Hyperlink them
  852. echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?page=statpress-reloaded/statpress.php&statpress_action=spy&pn=' . $i . '">' . $i . '</a> ';
  853. }
  854. }
  855. }
  856. ?>
  857. </div>
  858. <table id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">
  859. <?php
  860. foreach ($qry as $rk)
  861. {
  862. print "<tr><td colspan='2' bgcolor='#dedede'><div align='left'>";
  863. print "<IMG SRC='http://api.hostip.info/flag.php?ip=" . $rk->ip . "' border=0 width=18 height=12>";
  864. print " <strong><span><font size='2' color='#7b7b7b'>" . $rk->ip . "</font></span></strong> ";
  865. print "<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;' onClick=ttogle('" . $rk->ip . "');>" . __('more info', 'statpress') . "</span></div>";
  866. print "<div id='" . $rk->ip . "' name='" . $rk->ip . "'>" . $rk->os . ", " . $rk->browser;
  867. // print "<br><iframe style='overflow:hide;border:0px;width:100%;height:15px;font-family:helvetica;paddng:0;' scrolling='no' marginwidth=0 marginheight=0 src=http://showip.fakap.net/txt/".$rk->ip."></iframe>";
  868. print "<br><iframe style='overflow:hide;border:0px;width:100%;height:40px;font-family:helvetica;paddng:0;' scrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=" . $rk->ip . "></iframe>";
  869. if ($rk->nation)
  870. {
  871. print "<br><small>" . gethostbyaddr($rk->ip) . "</small>";
  872. }
  873. print "<br><small>" . $rk->agent . "</small>";
  874. print "</div>";
  875. print "<script>document.getElementById('" . $rk->ip . "').style.display='none';</script>";
  876. print "</td></tr>";
  877. $qry2 = $wpdb->get_results("SELECT * FROM $table_name WHERE ip='" . $rk->ip . "' AND (date BETWEEN '$yesterday' AND '$today') order by id LIMIT 10");
  878. foreach ($qry2 as $details)
  879. {
  880. print "<tr>";
  881. print "<td valign='top' width='151'><div><font size='1' color='#3B3B3B'><strong>" . irihdate($details->date) . " " . $details->time . "</strong></font></div></td>";
  882. print "<td><div><a href='" . irigetblogurl() . ((strpos($details->urlrequested, 'index.php') === FALSE) ? $details->urlrequested : '') . "' target='_blank'>" . iri_StatPress_Decode($details->urlrequested) . "</a>";
  883. if ($details->searchengine != '')
  884. {
  885. print "<br><small>" . __('arrived from', 'statpress') . " <b>" . $details->searchengine . "</b> " . __('searching', 'statpress') . " <a href='" . $details->referrer . "' target=_blank>" . urldecode($details->search) . "</a></small>";
  886. }
  887. elseif ($details->referrer != '' && strpos($details->referrer, get_option('home')) === false)
  888. {
  889. print "<br><small>" . __('arrived from', 'statpress') . " <a href='" . $details->referrer . "' target=_blank>" . $details->referrer . "</a></small>";
  890. }
  891. print "</div></td>";
  892. print "</tr>\n";
  893. }
  894. }
  895. ?>
  896. </table>
  897. </div>
  898. <?php
  899. }
  900. function iriStatPressSearch($what = '')
  901. {
  902. global $wpdb;
  903. $table_name = $wpdb->prefix . "statpress";
  904. $f['urlrequested'] = __('URL Requested', 'statpress');
  905. $f['agent'] = __('Agent', 'statpress');
  906. $f['referrer'] = __('Referrer', 'statpress');
  907. $f['search'] = __('Search terms', 'statpress');
  908. $f['searchengine'] = __('Search engine', 'statpress');
  909. $f['os'] = __('Operative system', 'statpress');
  910. $f['browser'] = __('Browser', 'statpress');
  911. $f['spider'] = __('Spider', 'statpress');
  912. $f['ip'] = __('IP', 'statpress');
  913. ?>
  914. <div class='wrap'><h2><?php
  915. _e('Search', 'statpress');
  916. ?></h2>
  917. <form method=get><table>
  918. <?php
  919. for ($i = 1; $i <= 3; $i++)
  920. {
  921. print "<tr>";
  922. print "<td>" . __('Field', 'statpress') . " <select name=where$i><option value=''></option>";
  923. foreach (array_keys($f) as $k)
  924. {
  925. print "<option value='$k'";
  926. if ($_GET["where$i"] == $k)
  927. {
  928. print " SELECTED ";
  929. }
  930. print ">" . $f[$k] . "</option>";
  931. }
  932. print "</select></td>";
  933. print "<td><input type=checkbox name=groupby$i value='checked' " . $_GET["groupby$i"] . "> " . __('Group by', 'statpress') . "</td>";
  934. print "<td><input type=checkbox name=sortby$i value='checked' " . $_GET["sortby$i"] . "> " . __('Sort by', 'statpress') . "</td>";
  935. print "<td>, " . __('if contains', 'statpress') . " <input type=text name=what$i value='" . $_GET["what$i"] . "'></td>";
  936. print "</tr>";
  937. }
  938. ?>
  939. </table>
  940. <br>
  941. <table>
  942. <tr>
  943. <td>
  944. <table>
  945. <tr><td><input type=checkbox name=oderbycount value=checked <?php
  946. print $_GET['oderbycount']
  947. ?>> <?php
  948. _e('sort by count if grouped', 'statpress');
  949. ?></td></tr>
  950. <tr><td><input type=checkbox name=spider value=checked <?php
  951. print $_GET['spider']
  952. ?>> <?php
  953. _e('include spiders/crawlers/bot', 'statpress');
  954. ?></td></tr>
  955. <tr><td><input type=checkbox name=feed value=checked <?php
  956. print $_GET['feed']
  957. ?>> <?php
  958. _e('include feed', 'statpress');
  959. ?></td></tr>
  960. <tr><td><input type=checkbox name=distinct value=checked <?php
  961. print $_GET['distinct']
  962. ?>> <?php
  963. _e('SELECT DISTINCT', 'statpress');
  964. ?></td></tr>
  965. </table>
  966. </td>
  967. <td width=15> </td>
  968. <td>
  969. <table>
  970. <tr>
  971. <td><?php
  972. _e('Limit results to', 'statpress');
  973. ?>
  974. <select name=limitquery><?php
  975. if ($_GET['limitquery'] > 0)
  976. {
  977. print "<option>" . $_GET['limitquery'] . "</option>";
  978. }
  979. ?><option>1</option><option>5</option><option>10</option><option>20</option><option>50</option><option>100</option><option>250</option><option>500</option></select>
  980. </td>
  981. </tr>
  982. <tr><td>&nbsp;</td></tr>
  983. <tr>
  984. <td align=right><input type=submit value=<?php
  985. _e('Search', 'statpress');
  986. ?> name=searchsubmit></td>
  987. </tr>
  988. </table>
  989. </td>
  990. </tr>
  991. </table>
  992. <input type=hidden name=page value='statpress-reloaded/statpress.php'><input type=hidden name=statpress_action value=search>
  993. </form><br>
  994. <?php
  995. if (isset($_GET['searchsubmit']))
  996. {
  997. // query builder
  998. $qry = "";
  999. // FIELDS
  1000. $fields = "";
  1001. for ($i = 1; $i <= 3; $i++)
  1002. {
  1003. if ($_GET["where$i"] != '')
  1004. {
  1005. $fields .= $_GET["where$i"] . ",";
  1006. }
  1007. }
  1008. $fields = rtrim($fields, ",");
  1009. // WHERE
  1010. $where = "WHERE 1=1";
  1011. if ($_GET['spider'] != 'checked')
  1012. {
  1013. $where .= " AND spider=''";
  1014. }
  1015. if ($_GET['feed'] != 'checked')
  1016. {
  1017. $where .= " AND feed=''";
  1018. }
  1019. for ($i = 1; $i <= 3; $i++)
  1020. {
  1021. if (($_GET["what$i"] != '') && ($_GET["where$i"] != ''))
  1022. {
  1023. $where .= " AND " . $_GET["where$i"] . " LIKE '%" . mysql_real_escape_string($_GET["what$i"]) . "%'";
  1024. }
  1025. }
  1026. // ORDER BY
  1027. $orderby = "";
  1028. for ($i = 1; $i <= 3; $i++)
  1029. {
  1030. if (($_GET["sortby$i"] == 'checked') && ($_GET["where$i"] != ''))
  1031. {
  1032. $orderby .= $_GET["where$i"] . ',';
  1033. }
  1034. }
  1035. // GROUP BY
  1036. $groupby = "";
  1037. for ($i = 1; $i <= 3; $i++)
  1038. {
  1039. if (($_GET["groupby$i"] == 'checked') && ($_GET["where$i"] != ''))
  1040. {
  1041. $groupby .= $_GET["where$i"] . ',';
  1042. }
  1043. }
  1044. if ($groupby != '')
  1045. {
  1046. $groupby = "GROUP BY " . rtrim($groupby, ',');
  1047. $fields .= ",count(*) as totale";
  1048. if ($_GET['oderbycount'] == 'checked')
  1049. {
  1050. $orderby = "totale DESC," . $orderby;
  1051. }
  1052. }
  1053. if ($orderby != '')
  1054. {
  1055. $orderby = "ORDER BY " . rtrim($orderby, ',');
  1056. }
  1057. $limit = "LIMIT " . $_GET['limitquery'];
  1058. if ($_GET['distinct'] == 'checked')
  1059. {
  1060. $fields = " DISTINCT " . $fields;
  1061. }
  1062. // Results
  1063. print "<h2>" . __('Results', 'statpress') . "</h2>";
  1064. $sql = "SELECT $fields FROM $table_name $where $groupby $orderby $limit;";
  1065. // print "$sql<br>";
  1066. print "<table class='widefat'><thead><tr>";
  1067. for ($i = 1; $i <= 3; $i++)
  1068. {
  1069. if ($_GET["where$i"] != '')
  1070. {
  1071. print "<th scope='col'>" . ucfirst($_GET["where$i"]) . "</th>";
  1072. }
  1073. }
  1074. if ($groupby != '')
  1075. {
  1076. print "<th scope='col'>" . __('Count', 'statpress') . "</th>";
  1077. }
  1078. print "</tr></thead><tbody id='the-list'>";
  1079. $qry = $wpdb->get_results($sql, ARRAY_N);
  1080. foreach ($qry as $rk)
  1081. {
  1082. print "<tr>";
  1083. for ($i = 1; $i <= 3; $i++)
  1084. {
  1085. print "<td>";
  1086. if ($_GET["where$i"] == 'urlrequested')
  1087. {
  1088. print iri_StatPress_Decode($rk[$i - 1]);
  1089. }
  1090. else
  1091. {
  1092. print $rk[$i - 1];
  1093. }
  1094. print "</td>";
  1095. }
  1096. print "</tr>";
  1097. }
  1098. print "</table>";
  1099. print "<br /><br /><font size=1 color=gray>sql: $sql</font></div>";
  1100. }
  1101. }
  1102. function iri_StatPress_Abbrevia($s, $c)
  1103. {
  1104. $res = "";
  1105. if (strlen($s) > $c)
  1106. {
  1107. $res = "...";
  1108. }
  1109. return my_substr($s, 0, $c) . $res;
  1110. }
  1111. function iri_StatPress_Where($ip)
  1112. {
  1113. $url = "http://api.hostip.info/get_html.php?ip=$ip";
  1114. $res = file_get_contents($url);
  1115. if ($res === false)
  1116. {
  1117. return(array('', ''));
  1118. }
  1119. $res = str_replace("Country: ", "", $res);
  1120. $res = str_replace("\nCity: ", ", ", $res);
  1121. $nation = preg_split('/\(|\)/', $res);
  1122. print "( $ip $res )";
  1123. return(array($res, $nation[1]));
  1124. }
  1125. function iri_StatPress_Decode($out_url)
  1126. {
  1127. if(!permalinksEnabled())
  1128. {
  1129. if ($out_url == '')
  1130. {
  1131. $out_url = __('Page', 'statpress') . ": Home";
  1132. }
  1133. if (my_substr($out_url, 0, 4) == "cat=")
  1134. {
  1135. $out_url = __('Category', 'statpress') . ": " . get_cat_name(my_substr($out_url, 4));
  1136. }
  1137. if (my_substr($out_url, 0, 2) == "m=")
  1138. {
  1139. $out_url = __('Calendar', 'statpress') . ": " . my_substr($out_url, 6, 2) . "/" . my_substr($out_url, 2, 4);
  1140. }
  1141. if (my_substr($out_url, 0, 2) == "s=")
  1142. {
  1143. $out_url = __('Search', 'statpress') . ": " . my_substr($out_url, 2);
  1144. }
  1145. if (my_substr($out_url, 0, 2) == "p=")
  1146. {
  1147. $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A);
  1148. $out_url = $post_id_7['post_title'];
  1149. }
  1150. if (my_substr($out_url, 0, 8) == "page_id=")
  1151. {
  1152. $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A);
  1153. $out_url = __('Page', 'statpress') . ": " . $post_id_7['post_title'];
  1154. }
  1155. }
  1156. else
  1157. {
  1158. if ($out_url == '')
  1159. {
  1160. $out_url = __('Page', 'statpress') . ": Home";
  1161. }
  1162. else if (my_substr($out_url, 0, 9) == "category/")
  1163. {
  1164. $out_url = __('Category', 'statpress') . ": " . get_cat_name(my_substr($out_url, 9));
  1165. }
  1166. else if (my_substr($out_url, 0, 8) == "//") // not working yet
  1167. {
  1168. //$out_url = __('Calendar', 'statpress') . ": " . my_substr($out_url, 4, 0) . "/" . my_substr($out_url, 6, 7);
  1169. }
  1170. else if (my_substr($out_url, 0, 2) == "s=")
  1171. {
  1172. $out_url = __('Search', 'statpress') . ": " . my_substr($out_url, 2);
  1173. }
  1174. else if (my_substr($out_url, 0, 2) == "p=") // not working yet
  1175. {
  1176. $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A);
  1177. $out_url = $post_id_7['post_title'];
  1178. }
  1179. else if (my_substr($out_url, 0, 8) == "page_id=") // not working yet
  1180. {
  1181. $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A);
  1182. $out_url = __('Page', 'statpress') . ": " . $post_id_7['post_title'];
  1183. }
  1184. }
  1185. return $out_url;
  1186. }
  1187. function iri_StatPress_URL()
  1188. {
  1189. $urlRequested = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
  1190. if ($urlRequested == "")
  1191. {
  1192. // SEO problem!
  1193. $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '');
  1194. }
  1195. if (my_substr($urlRequested, 0, 2) == '/?')
  1196. {
  1197. $urlRequested = my_substr($urlRequested, 2);
  1198. }
  1199. if ($urlRequested == '/')
  1200. {
  1201. $urlRequested = '';
  1202. }
  1203. return $urlRequested;
  1204. }
  1205. function irigetblogurl()
  1206. {
  1207. $prsurl = parse_url(get_bloginfo('url'));
  1208. return $prsurl['scheme'] . '://' . $prsurl['host'] . ((!permalinksEnabled()) ? $prsurl['path'] . '/?' : '');
  1209. }
  1210. // Converte da data us to default format di Wordpress
  1211. function irihdate($dt = "00000000")
  1212. {
  1213. return mysql2date(get_option('date_format'), my_substr($dt, 0, 4) . "-" . my_substr($dt, 4, 2) . "-" . my_substr($dt, 6, 2));
  1214. }
  1215. function iritablesize($table)
  1216. {
  1217. global $wpdb;
  1218. $res = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table'");
  1219. foreach ($res as $fstatus)
  1220. {
  1221. $data_lenght = $fstatus->Data_length;
  1222. $data_rows = $fstatus->Rows;
  1223. }
  1224. return number_format(($data_lenght / 1024 / 1024), 2, ",", " ") . " MB ($data_rows records)";
  1225. }
  1226. function irirgbhex($red, $green, $blue)
  1227. {
  1228. $red = 0x10000 * max(0, min(255, $red + 0));
  1229. $green = 0x100 * max(0, min(255, $green + 0));
  1230. $blue = max(0, min(255, $blue + 0));
  1231. // convert the combined value to hex and zero-fill to 6 digits
  1232. return "#" . str_pad(strtoupper(dechex($red + $green + $blue)), 6, "0", STR_PAD_LEFT);
  1233. }
  1234. function iriValueTable($fld, $fldtitle, $limit = 0, $param = "", $queryfld = "", $exclude = "")
  1235. {
  1236. /* Maddler 04112007: param addedd */
  1237. global $wpdb;
  1238. $table_name = $wpdb->prefix . "statpress";
  1239. if ($queryfld == '')
  1240. {
  1241. $queryfld = $fld;
  1242. }
  1243. print "<div class='wrap'><h2>$fldtitle</h2><table style='width:100%;padding:0px;margin:0px;' cellpadding=0 cellspacing=0><thead><tr><th style='width:400px;background-color:white;'></th><th style='width:150px;background-color:white;'><u>" . __('Visits', 'statpress') . "</u></th><th style='background-color:white;'></th></tr></thead>";
  1244. print "<tbody id='the-list'>";
  1245. $rks = $wpdb->get_var("SELECT count($param $queryfld) as rks FROM $table_name WHERE 1=1 $exclude;");
  1246. if ($rks > 0)
  1247. {
  1248. $sql = "SELECT count($param $queryfld) as pageview, $fld FROM $table_name WHERE 1=1 $exclude GROUP BY $fld ORDER BY pageview DESC";
  1249. if ($limit > 0)
  1250. {
  1251. $sql = $sql . " LIMIT $limit";
  1252. }
  1253. $qry = $wpdb->get_results($sql);
  1254. $tdwidth = 450;
  1255. $red = 131;
  1256. $green = 180;
  1257. $blue = 216;
  1258. $deltacolor = round(250 / count($qry), 0);
  1259. // $chl="";
  1260. // $chd="t:";
  1261. foreach ($qry as $rk)
  1262. {
  1263. $pc = round(($rk->pageview * 100 / $rks), 1);
  1264. if ($fld == 'date')
  1265. {
  1266. $rk->$fld = irihdate($rk->$fld);
  1267. }
  1268. if ($fld == 'urlrequested')
  1269. {
  1270. $rk->$fld = iri_StatPress_Decode($rk->$fld);
  1271. }
  1272. if ($fld == 'search')
  1273. {
  1274. $rk->$fld = urldecode($rk->$fld);
  1275. }
  1276. // $chl.=urlencode(my_substr($rk->$fld,0,50))."|";
  1277. // $chd.=($tdwidth*$pc/100)."|";
  1278. print "<tr><td style='width:400px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>" . my_substr($rk->$fld, 0, 50);
  1279. if (strlen("$rk->fld") >= 50)
  1280. {
  1281. print "...";
  1282. }
  1283. // <td style='text-align:right'>$pc%</td>";
  1284. print "</td><td style='text-align:center;'>" . $rk->pageview . "</td>";
  1285. print "<td><div style='text-align:right;padding:2px;font-family:helvetica;font-size:7pt;font-weight:bold;height:16px;width:" . number_format(($tdwidth * $pc / 100), 1, '.', '') . "px;background:" . irirgbhex($red, $green, $blue) . ";border-top:1px solid " . irirgbhex($red + 20, $green + 20, $blue) . ";border-right:1px solid " . irirgbhex($red + 30, $green + 30, $blue) . ";border-bottom:1px solid " . irirgbhex($red - 20, $green - 20, $blue) . ";'>$pc%</div>";
  1286. print "</td></tr>\n";
  1287. $red = $red + $deltacolor;
  1288. $blue = $blue - ($deltacolor / 2);
  1289. }
  1290. }
  1291. print "</table>\n";
  1292. // $chl=my_substr($chl,0,strlen($chl)-1);
  1293. // $chd=my_substr($chd,0,strlen($chd)-1);
  1294. // print "<img src=http://chart.apis.google.com/chart?cht=p3&chd=".($chd)."&chs=400x200&chl=".($chl)."&chco=1B75DF,92BF23>\n";
  1295. print "</div>\n";
  1296. }
  1297. function iriDomain($ip)
  1298. {
  1299. $host = gethostbyaddr($ip);
  1300. if (ereg('^([0-9]{1,3}\.){3}[0-9]{1,3}$', $host))
  1301. {
  1302. return "";
  1303. }
  1304. else
  1305. {
  1306. return my_substr(strrchr($host, "."), 1);
  1307. }
  1308. }
  1309. function iriGetQueryPairs($url)
  1310. {
  1311. $parsed_url = parse_url($url);
  1312. $tab = parse_url($url);
  1313. $host = $tab['host'];
  1314. if (key_exists("query", $tab))
  1315. {
  1316. $query = $tab["query"];
  1317. $query = str_replace("&amp;", "&", $query);
  1318. $query = urldecode($query);
  1319. $query = str_replace("?", "&", $query);
  1320. return explode("&", $query);
  1321. }
  1322. else
  1323. {
  1324. return null;
  1325. }
  1326. }
  1327. function iriGetOS($arg)
  1328. {
  1329. $arg = str_replace(" ", "", $arg);
  1330. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/os.dat');
  1331. foreach ($lines as $line_num => $os)
  1332. {
  1333. list($nome_os, $id_os) = explode("|", $os);
  1334. if (strpos($arg, $id_os) === false)
  1335. continue;
  1336. // riconosciuto
  1337. return $nome_os;
  1338. }
  1339. return '';
  1340. }
  1341. function iriGetBrowser($arg)
  1342. {
  1343. $arg = str_replace(" ", "", $arg);
  1344. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/browser.dat');
  1345. foreach ($lines as $line_num => $browser)
  1346. {
  1347. list($nome, $id) = explode("|", $browser);
  1348. if (strpos($arg, $id) === false)
  1349. continue;
  1350. // riconosciuto
  1351. return $nome;
  1352. }
  1353. return '';
  1354. }
  1355. function iriCheckBanIP($arg)
  1356. {
  1357. if (file_exists(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/banips.dat'))
  1358. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/banips.dat');
  1359. else
  1360. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/banips.dat');
  1361. if ($lines !== false)
  1362. {
  1363. foreach ($lines as $banip)
  1364. {
  1365. if (@preg_match('/^' . rtrim($banip, "\r\n") . '$/', $arg)){
  1366. return true;
  1367. }
  1368. // riconosciuto, da scartare
  1369. }
  1370. }
  1371. return false;
  1372. }
  1373. function iriGetSE($referrer = null)
  1374. {
  1375. $key = null;
  1376. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/searchengines.dat');
  1377. foreach ($lines as $line_num => $se)
  1378. {
  1379. list($nome, $url, $key) = explode("|", $se);
  1380. if (strpos($referrer, $url) === false)
  1381. continue;
  1382. // trovato se
  1383. $variables = iriGetQueryPairs($referrer);
  1384. $i = count($variables);
  1385. while ($i--)
  1386. {
  1387. $tab = explode("=", $variables[$i]);
  1388. if ($tab[0] == $key)
  1389. {
  1390. return($nome . "|" . urlencode($tab[1]));
  1391. }
  1392. }
  1393. }
  1394. return null;
  1395. }
  1396. function iriGetSpider($agent = null)
  1397. {
  1398. $agent = str_replace(" ", "", $agent);
  1399. $key = null;
  1400. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/spider.dat');
  1401. if (file_exists(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'))
  1402. $lines = array_merge($lines, file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'));
  1403. foreach ($lines as $line_num => $spider)
  1404. {
  1405. list($nome, $key) = explode("|", $spider);
  1406. if (strpos($agent, $key) === false)
  1407. continue;
  1408. // trovato
  1409. return $nome;
  1410. }
  1411. return null;
  1412. }
  1413. function iri_StatPress_lastmonth()
  1414. {
  1415. $ta = getdate(current_time('timestamp'));
  1416. $year = $ta['year'];
  1417. $month = $ta['mon'];
  1418. // go back 1 month;
  1419. $month = $month - 1;
  1420. if ($month === 0)
  1421. {
  1422. // if this month is Jan
  1423. // go back a year
  1424. $year = $year - 1;
  1425. $month = 12;
  1426. }
  1427. // return in format 'YYYYMM'
  1428. return sprintf($year . '%02d', $month);
  1429. }
  1430. function iri_StatPress_CreateTable()
  1431. {
  1432. global $wpdb;
  1433. global $wp_db_version;
  1434. $table_name = $wpdb->prefix . "statpress";
  1435. $sql_createtable = "CREATE TABLE " . $table_name . " (
  1436. id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
  1437. date TINYTEXT,
  1438. time TINYTEXT,
  1439. ip TINYTEXT,
  1440. urlrequested TEXT,
  1441. agent TEXT,
  1442. referrer TEXT,
  1443. search TEXT,
  1444. nation TINYTEXT,
  1445. os TINYTEXT,
  1446. browser TINYTEXT,
  1447. searchengine TINYTEXT,
  1448. spider TINYTEXT,
  1449. feed TINYTEXT,
  1450. user TINYTEXT,
  1451. timestamp TINYTEXT,
  1452. threat_score SMALLINT,
  1453. threat_type SMALLINT,
  1454. UNIQUE KEY id (id)
  1455. );";
  1456. if ($wp_db_version >= 5540)
  1457. $page = 'wp-admin/includes/upgrade.php';
  1458. else
  1459. $page = 'wp-admin/upgrade-functions.php';
  1460. require_once(ABSPATH . $page);
  1461. dbDelta($sql_createtable);
  1462. }
  1463. function iri_StatPress_is_feed($url) {
  1464. if (stristr($url,get_bloginfo('comments_atom_url')) != FALSE) { return 'COMMENT ATOM'; }
  1465. elseif (stristr($url,get_bloginfo('comments_rss2_url')) != FALSE) { return 'COMMENT RSS'; }
  1466. elseif (stristr($url,get_bloginfo('rdf_url')) != FALSE) { return 'RDF'; }
  1467. elseif (stristr($url,get_bloginfo('atom_url')) != FALSE) { return 'ATOM'; }
  1468. elseif (stristr($url,get_bloginfo('rss_url')) != FALSE) { return 'RSS'; }
  1469. elseif (stristr($url,get_bloginfo('rss2_url')) != FALSE) { return 'RSS2'; }
  1470. elseif (stristr($url,'wp-feed.php') != FALSE) { return 'RSS2'; }
  1471. elseif (stristr($url,'/feed') != FALSE) { return 'RSS2'; }
  1472. return '';
  1473. }
  1474. function iriStatPressAgents()
  1475. {
  1476. global $wpdb;
  1477. $table_name = $wpdb->prefix . "statpress";
  1478. $query = "SELECT date, MAX(time), ip, COUNT(*) as count, agent";
  1479. $query .= " FROM " . $table_name;
  1480. $query .= " WHERE spider = '' AND browser = ''";
  1481. $query .= " GROUP BY date, ip, agent";
  1482. $query .= " ORDER BY date DESC";
  1483. $result = $wpdb->get_results($query);
  1484. print "<div class='wrap'><h2>" . __('Unknown User Agents', 'statpress') . "</h2>";
  1485. print "<table class='widefat'><thead><tr>";
  1486. print "<th scope='col'>" . __('Date', 'statpress') . "</th>";
  1487. print "<th scope='col'>" . __('Last Time', 'statpress') . "</th>";
  1488. print "<th scope='col'>" . __('IP', 'statpress') . "</th>";
  1489. print "<th scope='col'>" . __('Count', 'statpress') . "</th>";
  1490. print "<th scope='col'>" . __('User Agent', 'statpress') . "</th>";
  1491. print "</tr></thead><tbody id='the-list'>";
  1492. foreach ($result as $line)
  1493. {
  1494. $col = 0;
  1495. print '<tr>';
  1496. foreach ($line as $col_value)
  1497. {
  1498. $col++;
  1499. if ($col == 1)
  1500. print '<td>' . irihdate($col_value) . '</td>';
  1501. else if ($col == 3)
  1502. print "<td><a href='http://www.projecthoneypot.org/ip_" . $col_value . "' target='_blank'>" . $col_value . "</a></td>";
  1503. else
  1504. print '<td>' . $col_value . '</td>';
  1505. }
  1506. print '</tr>';
  1507. }
  1508. print '</table></div>';
  1509. }
  1510. function iri_StatPress_extractfeedreq($url)
  1511. {
  1512. if(!strpos($url, '?') === FALSE)
  1513. {
  1514. list($null, $q) = explode("?", $url);
  1515. list($res, $null) = explode("&", $q);
  1516. }
  1517. else
  1518. {
  1519. $prsurl = parse_url($url);
  1520. $res = $prsurl['path'] . $$prsurl['query'];
  1521. }
  1522. return $res;
  1523. }
  1524. function iriStatAppend()
  1525. {
  1526. global $wpdb;
  1527. $table_name = $wpdb->prefix . "statpress";
  1528. global $userdata;
  1529. global $_STATPRESS;
  1530. get_currentuserinfo();
  1531. $feed = '';
  1532. // Time
  1533. $timestamp = current_time('timestamp');
  1534. $vdate = gmdate("Ymd", $timestamp);
  1535. $vtime = gmdate("H:i:s", $timestamp);
  1536. // IP
  1537. $ipAddress = $_SERVER['REMOTE_ADDR'];
  1538. if (iriCheckBanIP($ipAddress) === true)
  1539. {
  1540. return '';
  1541. }
  1542. // Determine Threats if http:bl installed
  1543. $threat_score = 0;
  1544. $threat_type = 0;
  1545. $httpbl_key = get_option("httpbl_key");
  1546. if ($httpbl_key !== false)
  1547. {
  1548. $result = explode( ".", gethostbyname( $httpbl_key . "." .
  1549. implode ( ".", array_reverse( explode( ".",
  1550. $ipAddress ) ) ) .
  1551. ".dnsbl.httpbl.org" ) );
  1552. // If the response is positive
  1553. if ($result[0] == 127)
  1554. {
  1555. $threat_score = $result[2];
  1556. $threat_type = $result[3];
  1557. }
  1558. }
  1559. // URL (requested)
  1560. $urlRequested = iri_StatPress_URL();
  1561. if (eregi(".ico$", $urlRequested))
  1562. {
  1563. return '';
  1564. }
  1565. if (eregi("favicon.ico", $urlRequested))
  1566. {
  1567. return '';
  1568. }
  1569. if (eregi(".css$", $urlRequested))
  1570. {
  1571. return '';
  1572. }
  1573. if (eregi(".js$", $urlRequested))
  1574. {
  1575. return '';
  1576. }
  1577. if (stristr($urlRequested, "/wp-content/plugins") != false)
  1578. {
  1579. return '';
  1580. }
  1581. if (stristr($urlRequested, "/wp-content/themes") != false)
  1582. {
  1583. return '';
  1584. }
  1585. $referrer = (isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '');
  1586. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '');
  1587. $spider = iriGetSpider($userAgent);
  1588. if (($spider != '') and (get_option('statpress_donotcollectspider') == 'checked'))
  1589. {
  1590. return '';
  1591. }
  1592. if ($spider != '')
  1593. {
  1594. $os = '';
  1595. $browser = '';
  1596. }
  1597. else
  1598. {
  1599. // Trap feeds
  1600. $prsurl = parse_url(get_bloginfo('url'));
  1601. $feed = iri_StatPress_is_feed($prsurl['scheme'] . '://' . $prsurl['host'] . $_SERVER['REQUEST_URI']);
  1602. // Get OS and browser
  1603. $os = iriGetOS($userAgent);
  1604. $browser = iriGetBrowser($userAgent);
  1605. list($searchengine, $search_phrase) = explode("|", iriGetSE($referrer));
  1606. }
  1607. // Auto-delete visits if...
  1608. if (get_option('statpress_autodelete_spider') != '')
  1609. {
  1610. $t = gmdate("Ymd", strtotime('-' . get_option('statpress_autodelete_spider')));
  1611. $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "' AND spider <> ''");
  1612. }
  1613. if (get_option('statpress_autodelete') != '')
  1614. {
  1615. $t = gmdate("Ymd", strtotime('-' . get_option('statpress_autodelete')));
  1616. $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
  1617. }
  1618. if ((!is_user_logged_in()) or (get_option('statpress_collectloggeduser') == 'checked'))
  1619. {
  1620. if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
  1621. {
  1622. iri_StatPress_CreateTable();
  1623. }
  1624. $insert = "INSERT INTO " . $table_name . " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,threat_score,threat_type,timestamp) " . "VALUES ('$vdate','$vtime','$ipAddress','" . mysql_real_escape_string($urlRequested) . "','" . mysql_real_escape_string(strip_tags($userAgent)) . "','" . mysql_real_escape_string($referrer) . "','" . mysql_real_escape_string(strip_tags($search_phrase)) . "','" . iriDomain($ipAddress) . "','" . mysql_real_escape_string($os) . "','" . mysql_real_escape_string($browser) . "','$searchengine','$spider','$feed','$userdata->user_login',$threat_score,$threat_type,'$timestamp')";
  1625. $results = $wpdb->query($insert);
  1626. }
  1627. }
  1628. function iriStatPressUpdate()
  1629. {
  1630. global $wpdb;
  1631. $table_name = $wpdb->prefix . "statpress";
  1632. $wpdb->show_errors();
  1633. // update table
  1634. print "" . __('Updating table struct', 'statpress') . " $table_name... ";
  1635. iri_StatPress_CreateTable();
  1636. print "" . __('done', 'statpress') . "<br>";
  1637. // Update Feed
  1638. print "" . __('Updating Feeds', 'statpress') . "... ";
  1639. $wpdb->query("UPDATE $table_name SET feed='';");
  1640. // standard blog info urls
  1641. $s = iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url'));
  1642. if ($s != '')
  1643. {
  1644. $wpdb->query("UPDATE $table_name SET feed='COMMENT ATOM' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1645. }
  1646. $s = iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url'));
  1647. if ($s != '')
  1648. {
  1649. $wpdb->query("UPDATE $table_name SET feed='COMMENT RSS' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1650. }
  1651. $s = iri_StatPress_extractfeedreq(get_bloginfo('atom_url'));
  1652. if ($s != '')
  1653. {
  1654. $wpdb->query("UPDATE $table_name SET feed='ATOM' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1655. }
  1656. $s = iri_StatPress_extractfeedreq(get_bloginfo('rdf_url'));
  1657. if ($s != '')
  1658. {
  1659. $wpdb->query("UPDATE $table_name SET feed='RDF' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1660. }
  1661. $s = iri_StatPress_extractfeedreq(get_bloginfo('rss_url'));
  1662. if ($s != '')
  1663. {
  1664. $wpdb->query("UPDATE $table_name SET feed='RSS' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1665. }
  1666. $s = iri_StatPress_extractfeedreq(get_bloginfo('rss2_url'));
  1667. if ($s != '')
  1668. {
  1669. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
  1670. }
  1671. // not standard
  1672. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%/feed%' AND feed='';");
  1673. $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%wp-feed.php%' AND feed='';");
  1674. print "" . __('done', 'statpress') . "<br>";
  1675. // Update OS
  1676. print "" . __('Updating OS', 'statpress') . "... ";
  1677. $wpdb->query("UPDATE $table_name SET os = '';");
  1678. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/os.dat');
  1679. foreach ($lines as $line_num => $os)
  1680. {
  1681. list($nome_os, $id_os) = explode("|", $os);
  1682. $qry = "UPDATE $table_name SET os = '$nome_os' WHERE os='' AND replace(agent,' ','') LIKE '%" . $id_os . "%';";
  1683. $wpdb->query($qry);
  1684. }
  1685. print "" . __('done', 'statpress') . "<br>";
  1686. // Update Browser
  1687. print "". __('Updating Browsers', 'statpress') ."... ";
  1688. $wpdb->query("UPDATE $table_name SET browser = '';");
  1689. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/browser.dat');
  1690. foreach ($lines as $line_num => $browser)
  1691. {
  1692. list($nome, $id) = explode("|", $browser);
  1693. $qry = "UPDATE $table_name SET browser = '$nome' WHERE browser='' AND replace(agent,' ','') LIKE '%" . $id . "%';";
  1694. $wpdb->query($qry);
  1695. }
  1696. print "" . __('done', 'statpress') . "<br>";
  1697. print "" . __('Updating Spiders', 'statpress') . "... ";
  1698. $wpdb->query("UPDATE $table_name SET spider = '';");
  1699. $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/spider.dat');
  1700. if (file_exists(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'))
  1701. $lines = array_merge($lines, file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'));
  1702. foreach ($lines as $line_num => $spider)
  1703. {
  1704. list($nome, $id) = explode("|", $spider);
  1705. $qry = "UPDATE $table_name SET spider = '$nome',os='',browser='' WHERE spider='' AND replace(agent,' ','') LIKE '%" . $id . "%';";
  1706. $wpdb->query($qry);
  1707. }
  1708. print "" . __('done', 'statpress') . "<br>";
  1709. // Update feed to ''
  1710. print "" . __('Updating Feeds', 'statpress') . "... ";
  1711. $wpdb->query("UPDATE $table_name SET feed = '' WHERE isnull(feed);");
  1712. print "" . __('done', 'statpress') . "<br>";
  1713. // Update Search engine
  1714. print "" . __('Updating Search engines', 'statpress') . "... ";
  1715. print "<br>";
  1716. $wpdb->query("UPDATE $table_name SET searchengine = '', search='';");
  1717. print "..." . __('null-ed', 'statpress') . "!<br>";
  1718. $qry = $wpdb->get_results("SELECT id, referrer FROM $table_name WHERE referrer !=''");
  1719. print "..." . __('select-ed', 'statpress') . "!<br>";
  1720. foreach ($qry as $rk)
  1721. {
  1722. list($searchengine, $search_phrase) = explode("|", iriGetSE($rk->referrer));
  1723. if ($searchengine <> '')
  1724. {
  1725. $q = "UPDATE $table_name SET searchengine = '$searchengine', search='" . addslashes($search_phrase) . "' WHERE id=" . $rk->id;
  1726. $wpdb->query($q);
  1727. }
  1728. }
  1729. print "" . __('done', 'statpress') . "<br>";
  1730. $wpdb->hide_errors();
  1731. print "<br>&nbsp;<h1>" . __('Updated', 'statpress') . "!</h1>";
  1732. }
  1733. function StatPress_Widget($w = '')
  1734. {
  1735. }
  1736. function StatPress_Print($body = '')
  1737. {
  1738. print iri_StatPress_Vars($body);
  1739. }
  1740. function iri_StatPress_Vars($body)
  1741. {
  1742. global $wpdb;
  1743. $table_name = $wpdb->prefix . "statpress";
  1744. if (strpos(strtolower($body), "%visits%") !== false)
  1745. {
  1746. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE date = '" . gmdate("Ymd", current_time('timestamp')) . "' and spider='' and feed='';");
  1747. $body = str_replace("%visits%", $qry[0]->pageview, $body);
  1748. }
  1749. if (strpos(strtolower($body), "%totalvisits%") !== false)
  1750. {
  1751. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='';");
  1752. $body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
  1753. }
  1754. if (strpos(strtolower($body), "%thistotalvisits%") !== false)
  1755. {
  1756. $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='" . mysql_real_escape_string(iri_StatPress_URL()) . "';");
  1757. $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
  1758. }
  1759. if (strpos(strtolower($body), "%since%") !== false)
  1760. {
  1761. $qry = $wpdb->get_results("SELECT date FROM $table_name ORDER BY date LIMIT 1;");
  1762. $body = str_replace("%since%", irihdate($qry[0]->date), $body);
  1763. }
  1764. if (strpos(strtolower($body), "%os%") !== false)
  1765. {
  1766. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  1767. $os = iriGetOS($userAgent);
  1768. $body = str_replace("%os%", $os, $body);
  1769. }
  1770. if (strpos(strtolower($body), "%browser%") !== false)
  1771. {
  1772. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  1773. $browser = iriGetBrowser($userAgent);
  1774. $body = str_replace("%browser%", $browser, $body);
  1775. }
  1776. if (strpos(strtolower($body), "%ip%") !== false)
  1777. {
  1778. $ipAddress = $_SERVER['REMOTE_ADDR'];
  1779. $body = str_replace("%ip%", $ipAddress, $body);
  1780. }
  1781. if (strpos(strtolower($body), "%visitorsonline%") !== false)
  1782. {
  1783. $to_time = current_time('timestamp');
  1784. $from_time = strtotime('-4 minutes', $to_time);
  1785. $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;");
  1786. $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
  1787. }
  1788. if (strpos(strtolower($body), "%usersonline%") !== false)
  1789. {
  1790. $to_time = current_time('timestamp');
  1791. $from_time = strtotime('-4 minutes', $to_time);
  1792. $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;");
  1793. $body = str_replace("%usersonline%", $qry[0]->users, $body);
  1794. }
  1795. if (strpos(strtolower($body), "%toppost%") !== false)
  1796. {
  1797. $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;");
  1798. $body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body);
  1799. }
  1800. if (strpos(strtolower($body), "%topbrowser%") !== false)
  1801. {
  1802. $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;");
  1803. $body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body);
  1804. }
  1805. if (strpos(strtolower($body), "%topos%") !== false)
  1806. {
  1807. $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;");
  1808. $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body);
  1809. }
  1810. if(strpos(strtolower($body),"%pagestoday%") !== false)
  1811. {
  1812. $qry = $wpdb->get_results("SELECT count(ip) as pageview FROM $table_name WHERE date = '".gmdate("Ymd",current_time('timestamp'))."' and spider='' and feed='';");
  1813. $body = str_replace("%pagestoday%", $qry[0]->pageview, $body);
  1814. }
  1815. if(strpos(strtolower($body),"%thistotalpages%") !== FALSE)
  1816. {
  1817. $qry = $wpdb->get_results("SELECT count(ip) as pageview FROM $table_name WHERE spider='' and feed='';");
  1818. $body = str_replace("%thistotalpages%", $qry[0]->pageview, $body);
  1819. }
  1820. if (strpos(strtolower($body), "%latesthits%") !== false)
  1821. {
  1822. $qry = $wpdb->get_results("SELECT search FROM $table_name WHERE search <> '' ORDER BY id DESC LIMIT 10");
  1823. $body = str_replace("%latesthits%", urldecode($qry[0]->search), $body);
  1824. for ($counter = 0; $counter < 10; $counter += 1)
  1825. {
  1826. $body .= "<br>". urldecode($qry[$counter]->search);
  1827. }
  1828. }
  1829. if (strpos(strtolower($body), "%pagesyesterday%") !== false)
  1830. {
  1831. $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
  1832. $qry = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitsyesterday FROM $table_name WHERE feed='' AND spider='' AND date = '" . $yesterday . "'");
  1833. $body = str_replace("%pagesyesterday%", (is_array($qry) ? $qry[0]->visitsyesterday : 0), $body);
  1834. }
  1835. return $body;
  1836. }
  1837. function iri_StatPress_TopPosts($limit = 5, $showcounts = 'checked')
  1838. {
  1839. global $wpdb;
  1840. $res = "\n<ul>\n";
  1841. $table_name = $wpdb->prefix . "statpress";
  1842. $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY urlrequested ORDER BY totale DESC LIMIT $limit;");
  1843. foreach ($qry as $rk)
  1844. {
  1845. $res .= "<li><a href='" . irigetblogurl() . ((strpos($rk->urlrequested, 'index.php') === FALSE) ? $rk->urlrequested : '') . "'>" . iri_StatPress_Decode($rk->urlrequested) . "</a></li>\n";
  1846. if (strtolower($showcounts) == 'checked')
  1847. {
  1848. $res .= " (" . $rk->totale . ")";
  1849. }
  1850. }
  1851. return "$res</ul>\n";
  1852. }
  1853. function widget_statpress_init($args)
  1854. {
  1855. if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control'))
  1856. return;
  1857. // Multifunctional StatPress pluging
  1858. function widget_statpress_control()
  1859. {
  1860. $options = get_option('widget_statpress');
  1861. if (!is_array($options))
  1862. $options = array('title' => 'StatPress', 'body' => 'Visits today: %visits%');
  1863. if ($_POST['statpress-submit'])
  1864. {
  1865. $options['title'] = strip_tags(stripslashes($_POST['statpress-title']));
  1866. $options['body'] = stripslashes($_POST['statpress-body']);
  1867. update_option('widget_statpress', $options);
  1868. }
  1869. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1870. $body = htmlspecialchars($options['body'], ENT_QUOTES);
  1871. // the form
  1872. 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>';
  1873. 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>';
  1874. 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>';
  1875. }
  1876. function widget_statpress($args)
  1877. {
  1878. extract($args);
  1879. $options = get_option('widget_statpress');
  1880. $title = $options['title'];
  1881. $body = $options['body'];
  1882. echo $before_widget;
  1883. print($before_title . $title . $after_title);
  1884. print iri_StatPress_Vars($body);
  1885. echo $after_widget;
  1886. }
  1887. register_sidebar_widget('StatPress', 'widget_statpress');
  1888. register_widget_control(array('StatPress', 'widgets'), 'widget_statpress_control', 300, 210);
  1889. // Top posts
  1890. function widget_statpresstopposts_control()
  1891. {
  1892. $options = get_option('widget_statpresstopposts');
  1893. if (!is_array($options))
  1894. {
  1895. $options = array('title' => 'StatPress TopPosts', 'howmany' => '5', 'showcounts' => 'checked');
  1896. }
  1897. if ($_POST['statpresstopposts-submit'])
  1898. {
  1899. $options['title'] = strip_tags(stripslashes($_POST['statpresstopposts-title']));
  1900. $options['howmany'] = stripslashes($_POST['statpresstopposts-howmany']);
  1901. $options['showcounts'] = stripslashes($_POST['statpresstopposts-showcounts']);
  1902. if ($options['showcounts'] == "1")
  1903. {
  1904. $options['showcounts'] = 'checked';
  1905. }
  1906. update_option('widget_statpresstopposts', $options);
  1907. }
  1908. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1909. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  1910. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  1911. // the form
  1912. 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>';
  1913. 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>';
  1914. 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>';
  1915. echo '<input type="hidden" id="statpress-submitTopPosts" name="statpresstopposts-submit" value="1" />';
  1916. }
  1917. function widget_statpresstopposts($args)
  1918. {
  1919. extract($args);
  1920. $options = get_option('widget_statpresstopposts');
  1921. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  1922. $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES);
  1923. $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES);
  1924. echo $before_widget;
  1925. print($before_title . $title . $after_title);
  1926. print iri_StatPress_TopPosts($howmany, $showcounts);
  1927. echo $after_widget;
  1928. }
  1929. register_sidebar_widget('StatPress TopPosts', 'widget_statpresstopposts');
  1930. register_widget_control(array('StatPress TopPosts', 'widgets'), 'widget_statpresstopposts_control', 300, 110);
  1931. }
  1932. // a custom function for loading localization
  1933. function statpress_load_textdomain() {
  1934. //check whether necessary core function exists
  1935. if ( function_exists('load_plugin_textdomain') ) {
  1936. //load the plugin textdomain
  1937. load_plugin_textdomain('statpress', 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/locale');
  1938. }
  1939. }
  1940. // call the custom function on the init hook
  1941. add_action('init', 'statpress_load_textdomain');
  1942. add_action('admin_menu', 'iri_add_pages');
  1943. add_action('plugins_loaded', 'widget_statpress_init');
  1944. //add_action('wp_head', 'iriStatAppend');
  1945. add_action('send_headers', 'iriStatAppend');
  1946. register_activation_hook(__FILE__, 'iri_StatPress_CreateTable');
  1947. ?>