PageRenderTime 69ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wassup/wassup.php

https://github.com/alx/alexgirard.com-blog
PHP | 2990 lines | 2137 code | 177 blank | 676 comment | 628 complexity | 5fff4a73495c4af5560905cd16522219 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. Plugin Name: WassUp
  4. Plugin URI: http://www.wpwp.org
  5. Description: Wordpress plugin to analyze your visitors traffic with real time stats, chart and a lot of chronological informations. It has sidebar Widget support to show current online visitors and other statistics.
  6. Version: 1.6.2
  7. Author: Michele Marcucci, Helene D.
  8. Author URI: http://www.michelem.org/
  9. Copyright (c) 2007 Michele Marcucci
  10. Released under the GNU General Public License (GPL)
  11. http://www.gnu.org/licenses/gpl.txt
  12. */
  13. //# Stop any attempt to call wassup.php directly. -Helene D. 1/27/08.
  14. if (preg_match('#'.basename(__FILE__) .'#', $_SERVER['PHP_SELF'])) {
  15. die('Permission Denied! You are not allowed to call this page directly.');
  16. }
  17. $version = "1.6.2";
  18. define('WASSUPFOLDER', dirname(plugin_basename(__FILE__)), TRUE);
  19. require_once(dirname(__FILE__).'/lib/wassup.class.php');
  20. require_once(dirname(__FILE__).'/lib/main.php');
  21. $wpurl = get_bloginfo('wpurl'); //global
  22. if (isset($_GET['export'])) {
  23. export_wassup();
  24. }
  25. global $wp_version;
  26. //#This works only in WP2.2 or higher
  27. if (version_compare($wp_version, '2.2', '<')) {
  28. wp_die( '<strong style="color:#c00;background-color:#dff;padding:5px;">'.__("Sorry, Wassup requires WordPress 2.2 or higher to work","wassup").'.</strong>');
  29. } elseif (function_exists('wp_cache_flush')) {
  30. //clear the WP cache
  31. wp_cache_flush(); //to prevent "cannot redeclare" errors???
  32. }
  33. //#add initial options and create table when Wassup activated
  34. // -Helene D. 2/26/08.
  35. function wassup_install() {
  36. global $wpdb;
  37. $table_name = $wpdb->prefix . "wassup";
  38. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  39. //### Add/update wassup settings in Wordpress options table
  40. $wassup_options = new wassupOptions; //#settings initialized here
  41. //# set hash
  42. $whash = $wassup_options->get_wp_hash();
  43. if (!empty($whash)) {
  44. $wassup_options->whash = $whash;
  45. }
  46. //# Add timestamp to optimize table once a day
  47. $wassup_options->wassup_optimize = wassup_get_time();
  48. //# set wmark and wip to null
  49. $wassup_options->wmark = 0; //#no preservation of delete/mark
  50. $wassup_options->wip = null;
  51. //### For upgrade of Wassup, manually initialize new settings
  52. //# initialize settings for 'spamcheck', 'refspam', and 'spam'
  53. if (!isset($wassup_options->wassup_spamcheck)) {
  54. $wassup_options->wassup_spamcheck = "0";
  55. //#set wassup_spamcheck=0 if wassup_refspam=0 and wassup_spam=0
  56. if (!isset($wassup_options->wassup_spam) && !isset($wassup_options->wassup_refspam)) {
  57. $wassup_options->wassup_spam = "1";
  58. $wassup_options->wassup_refspam = "1";
  59. } elseif ( $wassup_options->wassup_spam == "0" && $wassup_options->wassup_refspam == "0" ) {
  60. $wassup_options->wassup_spamcheck = "0";
  61. }
  62. }
  63. //# update wassup settings for 'savepath' (default is null)
  64. //$wassup_options->wassup_savepath = "/fakedirectory"; //#debug
  65. if (!isset($wassup_options->wassup_savepath)) {
  66. $wassup_options->wassup_savepath = null;
  67. }
  68. //# display google chart by default for upgrades from 1.4.4
  69. if (!isset($wassup_options->wassup_chart)) {
  70. $wassup_options->wassup_chart = 1;
  71. }
  72. //# assign top ten items for upgrades from 1.4.9 or less
  73. if (empty($wassup_options->wassup_top10)) {
  74. $wassup_options->wassup_top10 = serialize(array("topsearch"=>"1",
  75. "topreferrer"=>"1",
  76. "toprequest"=>"1",
  77. "topbrowser"=>"1",
  78. "topos"=>"1",
  79. "toplocale"=>"0",
  80. "topfeed"=>"0",
  81. "topcrawler"=>"0",
  82. "topvisitor"=>"0",
  83. "topreferrer_exclude"=>""));
  84. }
  85. //#upgrade from 1.6: new options wassup_time_format and wassup_hack
  86. if (!isset($wassup_options->wassup_time_format)) {
  87. $wassup_options->wassup_time_format = 24;
  88. }
  89. if (!isset($wassup_options->wassup_hack)) {
  90. $wassup_options->wassup_hack = 1;
  91. }
  92. $wassup_options->saveSettings();
  93. //### Detect problems with WassUp install and show warning
  94. //#
  95. //#Check for problems with 'session_savepath' and disable
  96. //# recording, if found. -Helene D. 2/24/08
  97. /*
  98. $sessionpath = $wassup_options->wassup_savepath;
  99. if (empty($sessionpath)) { $sessionpath = getSessionpath(); }
  100. //default to "/tmp" if no sessionpath value
  101. if (empty($sessionpath)) {
  102. $sessionpath = "/tmp";
  103. $wassup_options->wassup_savepath = $sessionpath;
  104. }
  105. if ($wassup_options->isWritableFolder($sessionpath) == false) {
  106. if ($wassup_options->wassup_active == "1") {
  107. $wassup_options->wassup_active = "0";
  108. $wassup_options->wassup_alert_message = __('WassUp has detected a problem with "session.save_path" setting in your Wordpress/PHP configuration. Statistics logging has been disabled as a result. To fix, go to admin menu, "Wassup-->Options-->Manage Files & Database" and modify "Temporary files location folder".','wassup');
  109. } else {
  110. $wassup_options->wassup_alert_message = __('WassUp has detected a problem with "session.save_path" setting in your Wordpress/PHP configuration. Please fix by modifying "Temporary files location folder" in admin menu, "Wassup-->Options-->Manage Files & Database".','wassup');
  111. }
  112. }
  113. $wassup_options->saveSettings();
  114. unset($sessionpath); //because "install" works in global scope
  115. */
  116. //# TODO:
  117. //###Detect known incompatible plugins like "wp_cache" and disable
  118. //# recordings and show warning message...
  119. //### Create/upgrade wassup MAIN table
  120. if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
  121. CreateTable($table_name);
  122. CreateTable($table_tmp_name);
  123. } else {
  124. UpdateTable(); //<== wassup_tmp is added here, if missing
  125. }
  126. } //#end function wassup_install
  127. //set global variables that are dependent on Wassup's wp_options values
  128. $wassup_settings = get_option('wassup_settings'); //temp only..
  129. $wassup_options = new wassupOptions;
  130. //$wassup_options->loadSettings(); //done automatically
  131. $whash = $wassup_options->whash; //global...
  132. //#Completely remove all wassup tables and options from Wordpress when
  133. //# the 'wassup_uninstall' option is set and plugin is deactivated.
  134. //# -Helene D. 2/26/08
  135. function wassup_uninstall() {
  136. global $wassup_options, $wpdb;
  137. if ($wassup_options->wassup_uninstall == "1") {
  138. $table_name = $wpdb->prefix . "wassup";
  139. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  140. //$wpdb->query("DROP TABLE IF EXISTS $table_name"); //incorrectly causes an activation error in Wordpress
  141. //$wpdb->query("DROP TABLE IF EXISTS $table_tmp_name"); //incorrectly causes an activation error in Wordpress
  142. mysql_query("DROP TABLE IF EXISTS $table_tmp_name");
  143. mysql_query("DROP TABLE IF EXISTS $table_name");
  144. $wassup_options->deleteSettings();
  145. }
  146. } //#end function wassup_uninstall
  147. function add_wassup_meta_info() {
  148. global $version;
  149. print '<meta name="wassup-version" content="'.$version.'" />';
  150. }
  151. //# Wassup init hook actions performed before headers are sent:
  152. //# -Load jquery AJAX library and dependent javascripts for admin menus
  153. //# -Load language/localization files for admin menus and widget
  154. //# -Set 'wassup' cookie for new visitor hits
  155. function wassup_init() {
  156. global $wpurl;
  157. //### Add wassup scripts to Wassup Admin pages...
  158. if (stristr($_GET['page'],'wassup') !== FALSE) {
  159. if ( function_exists('wp_deregister_script')) {
  160. //removes old jquery vers.
  161. wp_deregister_script('jquery');
  162. }
  163. // the safe way to load jquery into WP
  164. wp_register_script('jquery', $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/js/jquery.js',FALSE,'1.2.6');
  165. if ($_GET['page'] == "wassup-spy") {
  166. //the safe way to load a jquery dependent script
  167. wp_enqueue_script('spy', $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/js/spy.js', array('jquery'), '1.4');
  168. } elseif($_GET['page'] == "wassup-options") {
  169. wp_enqueue_script('ui.base', $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/js/ui.base.js', array('jquery'), '3');
  170. wp_enqueue_script('ui.tabs', $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/js/ui.tabs.js', array('jquery'), '3');
  171. } else {
  172. //the safe way to load a jquery dependent script
  173. wp_enqueue_script('thickbox', $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/thickbox/thickbox.js', array('jquery'), '3');
  174. }
  175. }
  176. //Loading language file...
  177. //Doesn't work if the plugin file has its own directory.
  178. //Let's make it our way... load_plugin_textdomain() searches only in the wp-content/plugins dir.
  179. $currentLocale = get_locale();
  180. if(!empty($currentLocale)) {
  181. $moFile = dirname(__FILE__) . "/language/" . $currentLocale . ".mo";
  182. if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('wassup', $moFile);
  183. }
  184. //Set Wassup cookie for visitor hits before headers are sent
  185. //add_action('init', 'wassupPrepend');
  186. if (!is_admin()) { //exclude wordpress admin page visits
  187. wassupPrepend();
  188. }
  189. } // end function wassup_init
  190. //Add the wassup stylesheet and other javascripts...
  191. function add_wassup_css() {
  192. global $wpurl, $wassup_options, $whash;
  193. //assign a value to whash, if none
  194. if ($whash == "") {
  195. $whash = $wassup_options->get_wp_hash();
  196. $wassup_options->whash = $whash; //save new hash
  197. $wassup_options->saveSettings();
  198. }
  199. $plugin_page = attribute_escape($_GET['page']);
  200. if (stristr($plugin_page,'wassup') !== FALSE) { $plugin_page="wassup"; }
  201. //Add css and javascript to wassup menu pages only...
  202. if ($plugin_page == "wassup") {
  203. //$wassup_settings = get_option('wassup_settings');
  204. echo "\n".'<script type="text/javascript">var tb_pathToImage = "'.$wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/thickbox/loadingAnimation.gif";</script>';
  205. echo "\n".'<link rel="stylesheet" href="'.$wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/thickbox/thickbox.css'.'" type="text/css" />';
  206. echo "\n".'<link rel="stylesheet" href="'.$wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/ui.tabs.css'.'" type="text/css" />';
  207. echo "\n".'<link rel="stylesheet" href="'.$wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/wassup.css'.'" type="text/css" />'."\n";
  208. if ($_GET['page'] != "wassup-options" AND $_GET['page'] != "wassup-spy") { ?>
  209. <script type='text/javascript'>
  210. //<![CDATA[
  211. function selfRefresh(){
  212. location.href='?<?php print $_SERVER['QUERY_STRING']; ?>';
  213. }
  214. setTimeout('selfRefresh()', <?php print ($wassup_options->wassup_refresh * 60000); ?>);
  215. //]]>
  216. </script>
  217. <script type='text/javascript'>
  218. //<![CDATA[
  219. var _countDowncontainer="0";
  220. var _currentSeconds="0";
  221. function ActivateCountDown(strContainerID, initialValue) {
  222. _countDowncontainer = document.getElementById(strContainerID);
  223. SetCountdownText(initialValue);
  224. window.setTimeout("CountDownTick()", 1000);
  225. }
  226. function CountDownTick() {
  227. SetCountdownText(_currentSeconds-1);
  228. window.setTimeout("CountDownTick()", 1000);
  229. }
  230. function SetCountdownText(seconds) {
  231. //store:
  232. _currentSeconds = seconds;
  233. //build text:
  234. var strText = AddZero(seconds);
  235. //apply:
  236. if (_countDowncontainer) { //prevents error in "Options" submenu
  237. _countDowncontainer.innerHTML = strText;
  238. }
  239. }
  240. function AddZero(num) {
  241. return ((num >= "0")&&(num < 10))?"0"+num:num+"";
  242. }
  243. //]]>
  244. </script>
  245. <script type="text/javascript">
  246. //<![CDATA[
  247. window.onload=WindowLoad;
  248. function WindowLoad(event) {
  249. ActivateCountDown("CountDownPanel", <?php print ($wassup_options->wassup_refresh * 60); ?>);
  250. }
  251. //]]>
  252. </script>
  253. <script type="text/javascript">
  254. //<![CDATA[
  255. jQuery(document).ready(function($){
  256. $("a.showhide").click(function(){
  257. var id = $(this).attr('id');
  258. $("div.navi" + id).toggle("slow");
  259. return false;
  260. });
  261. $("a.toggleagent").click(function(){
  262. var id = $(this).attr('id');
  263. $("div.naviagent" + id).slideToggle("slow");
  264. return false;
  265. });
  266. $("a.deleteID").click(function(){
  267. var id = $(this).attr('id');
  268. $.ajax({
  269. url: "<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/lib/action.php?action=delete&whash='.$whash; ?>&id=" + id,
  270. async: false
  271. })
  272. $("div.delID" + id).fadeOut("slow");
  273. return false;
  274. });
  275. $("a.show-search").toggle(function(){
  276. $("div.search-ip").slideDown("slow");
  277. $("a.show-search").html("<a href='#' class='show-search'><?php _e("Hide Search", "wassup") ?></a>");
  278. },function() {
  279. $("div.search-ip").slideUp("slow");
  280. $("a.show-search").html("<a href='#' class='show-search'><?php _e("Search", "wassup") ?></a>");
  281. return false;
  282. });
  283. $("a.show-topten").toggle(function(){
  284. $("div.topten").slideDown("slow");
  285. $("a.show-topten").html("<a href='#' class='show-topten'><?php _e("Hide TopTen", "wassup") ?></a>");
  286. },function() {
  287. $("div.topten").slideUp("slow");
  288. $("a.show-topten").html("<a href='#' class='show-topten'><?php _e("Show TopTen", "wassup") ?></a>");
  289. return false;
  290. });
  291. $("a.toggle-all").toggle(function() {
  292. $("div.togglenavi").slideDown("slow");
  293. $("a.toggle-all").html("<a href='#' class='toggle-all'><?php _e("Collapse All", "wassup") ?></a>");
  294. },function() {
  295. $("div.togglenavi").slideUp("slow");
  296. $("a.toggle-all").html("<a href='#' class='toggle-all'><?php _e("Expand All", "wassup") ?></a>");
  297. return false;
  298. });
  299. $("a.toggle-allcrono").toggle(function() {
  300. $("div.togglecrono").slideUp("slow");
  301. $("a.toggle-allcrono").html("<a href='#' class='toggle-allcrono'><?php _e("Expand Cronology", "wassup") ?></a>");
  302. },function() {
  303. $("div.togglecrono").slideDown("slow");
  304. $("a.toggle-allcrono").html("<a href='#' class='toggle-allcrono'><?php _e("Collapse Cronology", "wassup") ?></a>");
  305. return false;
  306. });
  307. }); //end jQuery(document).ready
  308. //]]>
  309. </script>
  310. <?php } //end if page != wassup-options ?>
  311. <script type='text/javascript'>
  312. //<![CDATA[
  313. function go()
  314. {
  315. box = document.forms["0"].navi;
  316. destination = box.options[box.selectedindex].value;
  317. if (destination) location.href = destination;
  318. }
  319. function go2()
  320. {
  321. box2 = document.forms["0"].type;
  322. destination2 = box2.options[box2.selectedindex].value;
  323. if (destination2) location.href = destination2;
  324. }
  325. //]]>
  326. </script>
  327. <?php
  328. if ($_GET['page'] == "wassup-options") {
  329. //#Current active tabs are indentified after page reload with
  330. //# either $_GET['tab']=N or $_POST['submit-optionsN'] where
  331. //# N=tab number. The tab is then activated directly in
  332. //# "settings.php" with <li class="ui-tabs-selected">
  333. ?>
  334. <script type="text/javascript">
  335. //<![CDATA[
  336. jQuery(document).ready(function($) {
  337. $('#tabcontainer > ul').tabs({ fx: { opacity: 'toggle' } });
  338. });
  339. //]]>
  340. </script>
  341. <?php
  342. } elseif ($_GET['page'] == "wassup-spy") {
  343. //## Filter detail lists by visitor type...
  344. if (isset($_GET['spytype'])) {
  345. $spytype = htmlentities(attribute_escape($_GET['spytype']));
  346. $wassup_options->wassup_default_spy_type = $spytype;
  347. } elseif ($wassup_options->wassup_default_spy_type != '') {
  348. $spytype = $wassup_options->wassup_default_spy_type;
  349. }
  350. $wassup_options->saveSettings();
  351. ?>
  352. <script type="text/javascript">
  353. //<![CDATA[
  354. jQuery(document).ready(function($){
  355. $('#spyContainer > div:gt(4)').fadeEachDown(); // initial fade
  356. $('#spyContainer').spy({
  357. limit: 10,
  358. fadeLast: 5,
  359. ajax: '<?php echo $wpurl."/wp-content/plugins/".WASSUPFOLDER."/lib/action.php?action=spy&whash=$whash&spytype=$spytype"; ?>',
  360. timeout: 2000,
  361. 'timestamp': myTimestamp,
  362. fadeInSpeed: 1100 });
  363. });
  364. function myTimestamp() {
  365. var d = new Date();
  366. var timestamp = d.getFullYear() + '-' + pad(d.getMonth()) + '-' + pad(d.getDate());
  367. timestamp += ' ';
  368. timestamp += pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
  369. return timestamp;
  370. }
  371. // pad ensures the date looks like 2006-09-13 rather than 2006-9-13
  372. function pad(n) {
  373. n = n.toString();
  374. return (n.length == 1 ? '0' + n : n);
  375. }
  376. //]]>
  377. </script>
  378. <?php } //end if page == "wassup-spy"
  379. } //end if plugin_page == "wassup"
  380. } //end function add_wassup_css()
  381. //put WassUp in the top-level admin menu and add submenus....
  382. function wassup_add_pages() {
  383. global $wassup_options;
  384. $userlevel = $wassup_options->wassup_userlevel;
  385. if (empty($userlevel)) { $userlevel = 8; }
  386. // add the default submenu first (important!)...
  387. add_submenu_page(WASSUPFOLDER, __('Visitor Details', 'wassup'), __('Visitor Details', 'wassup'), $userlevel, WASSUPFOLDER, 'WassUp'); //<-- WASSUPFOLDER needed here for directory names that include a version number...
  388. // then add top menu and other submenus...
  389. add_menu_page('Wassup', 'WassUp', $userlevel, WASSUPFOLDER, 'Wassup');
  390. add_submenu_page(WASSUPFOLDER, __('Spy Visitors', 'wassup'), __('SPY Visitors', 'wassup'), $userlevel, 'wassup-spy', 'WassUp');
  391. add_submenu_page(WASSUPFOLDER, __('Current Visitors Online', 'wassup'), __('Current Visitors Online', 'wassup'), $userlevel, 'wassup-online', 'WassUp');
  392. add_submenu_page(WASSUPFOLDER, __('Options', 'wassup'), __('Options', 'wassup'), $userlevel, 'wassup-options', 'WassUp');
  393. }
  394. function WassUp() {
  395. global $wpdb, $wp_version, $version, $wpurl, $wassup_options, $whash;
  396. // Start getting time of execution to debug SQL query
  397. $mtime = microtime();
  398. $mtime = explode(" ",$mtime);
  399. $mtime = $mtime[1] + $mtime[0];
  400. $starttime = $mtime;
  401. // This could be commented out
  402. //#debug...
  403. //error_reporting(E_ALL | E_STRICT); //debug, E_STRICT=php5 only
  404. //ini_set('display_errors','On'); //debug
  405. //$wpdb->show_errors(); //debug
  406. $table_name = $wpdb->prefix . "wassup";
  407. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  408. $wassup_options->loadSettings(); //needed in case "update_option is run elsewhere in wassup (widget)
  409. // RUN THE SAVE/RESET OPTIONS
  410. $admin_message="";
  411. if (isset($_POST['submit-options']) ||
  412. isset($_POST['submit-options2']) ||
  413. isset($_POST['submit-options3'])) {
  414. if ($_POST['wassup_remind_flag'] == 1 AND $_POST['wassup_remind_mb'] == "") {
  415. $wassup_options->wassup_remind_flag = $_POST['wassup_remind_flag'];
  416. $wassup_options->wassup_remind_mb = 10;
  417. } else {
  418. $wassup_options->wassup_remind_flag = $_POST['wassup_remind_flag'];
  419. $wassup_options->wassup_remind_mb = $_POST['wassup_remind_mb'];
  420. }
  421. $wassup_options->wassup_active = $_POST['wassup_active'];
  422. $wassup_options->wassup_chart_type = $_POST['wassup_chart_type'];
  423. $wassup_options->wassup_loggedin = $_POST['wassup_loggedin'];
  424. $wassup_options->wassup_spider = $_POST['wassup_spider'];
  425. $wassup_options->wassup_attack = $_POST['wassup_attack'];
  426. $wassup_options->wassup_hack = $_POST['wassup_hack'];
  427. $wassup_options->wassup_spamcheck = $_POST['wassup_spamcheck'];
  428. $wassup_options->wassup_spam = $_POST['wassup_spam'];
  429. $wassup_options->wassup_refspam = $_POST['wassup_refspam'];
  430. $wassup_options->wassup_exclude = $_POST['wassup_exclude'];
  431. $wassup_options->wassup_exclude_url = $_POST['wassup_exclude_url'];
  432. $wassup_options->delete_auto = $_POST['delete_auto'];
  433. $wassup_options->delete_auto_size = $_POST['delete_auto_size'];
  434. $wassup_options->wassup_screen_res = $_POST['wassup_screen_res'];
  435. $wassup_options->wassup_refresh = $_POST['wassup_refresh'];
  436. $wassup_options->wassup_userlevel = $_POST['wassup_userlevel'];
  437. $wassup_options->wassup_dashboard_chart = $_POST['wassup_dashboard_chart'];
  438. $wassup_options->wassup_geoip_map = $_POST['wassup_geoip_map'];
  439. $wassup_options->wassup_googlemaps_key = $_POST['wassup_googlemaps_key'];
  440. $wassup_options->wassup_time_format = $_POST['wassup_time_format'];
  441. $wassup_options->wassup_default_type = $_POST['wassup_default_type'];
  442. $wassup_options->wassup_default_limit = $_POST['wassup_default_limit'];
  443. $top_ten = array("topsearch" => $_POST['topsearch'],
  444. "topreferrer" => $_POST['topreferrer'],
  445. "toprequest" => $_POST['toprequest'],
  446. "topbrowser" => $_POST['topbrowser'],
  447. "topos" => $_POST['topos'],
  448. "toplocale" => $_POST['toplocale'],
  449. "topvisitor" => $_POST['topvisitor'],
  450. "topfeed" => "0",
  451. "topcrawler" => "0",
  452. "topreferrer_exclude" => $_POST['topreferrer_exclude']);
  453. $wassup_options->wassup_top10 = serialize($top_ten);
  454. /* if ( $_POST['wassup_savepath'] != $wassup_options->wassup_savepath ) {
  455. if (empty($_POST['wassup_savepath']) || rtrim($_POST['wassup_savepath'],"/") == getSessionpath()) {
  456. $wassup_options->wassup_savepath = NULL;
  457. } else {
  458. $wassup_options->setSavepath($_POST['wassup_savepath']);
  459. }
  460. } */
  461. if ($wassup_options->saveSettings()) {
  462. $admin_message = __("Wassup options updated successfully","wassup")."." ;
  463. }
  464. } elseif (isset($_POST['submit-options4'])) { //uninstall checkbox
  465. $wassup_options->wassup_uninstall = $_POST['wassup_uninstall'];
  466. if ($wassup_options->saveSettings()) {
  467. $admin_message = __("Wassup uninstall option updated successfully","wassup")."." ;
  468. }
  469. } elseif (isset($_POST['submit-spam'])) {
  470. $wassup_options->wassup_spamcheck = $_POST['wassup_spamcheck'];
  471. $wassup_options->wassup_spam = $_POST['wassup_spam'];
  472. $wassup_options->wassup_refspam = $_POST['wassup_refspam'];
  473. if ($wassup_options->saveSettings()) {
  474. $admin_message = __("Wassup spam options updated successfully","wassup")."." ;
  475. }
  476. } elseif (isset($_POST['reset-to-default'])) {
  477. $wassup_options->loadDefaults();
  478. if ($wassup_options->saveSettings()) {
  479. $admin_message = __("Wassup options updated successfully","wassup")."." ;
  480. }
  481. }
  482. //#sets current tab style for Wassup admin submenu?
  483. if ($_GET['page'] == "wassup-spy") {
  484. $class_spy="class='current'";
  485. } elseif ($_GET['page'] == "wassup-options") {
  486. $class_opt="class='current'";
  487. } elseif ($_GET['page'] == "wassup-online") {
  488. $class_ol="class='current'";
  489. } else {
  490. $class_sub="class='current'";
  491. }
  492. //for stringShortener calculated values and max-width...-Helene D. 11/27/07, 12/6/07
  493. if (!empty($wassup_options->wassup_screen_res)) {
  494. $screen_res_size = (int) $wassup_options->wassup_screen_res;
  495. } else {
  496. $screen_res_size = 670;
  497. }
  498. $max_char_len = ($screen_res_size)/10;
  499. $screen_res_size = $screen_res_size+20; //for wrap margins...
  500. //for generating page link urls....
  501. //$wpurl = get_bloginfo('wpurl'); //global
  502. $siteurl = get_bloginfo('siteurl');
  503. //#display an admin message or an alert. This must be above "wrap"
  504. //# div. -Helene D. 2/26/08.
  505. if (!empty($admin_message)) {
  506. $wassup_options->showMessage($admin_message);
  507. } elseif (!empty($wassup_options->wassup_alert_message)) {
  508. $wassup_options->showMessage();
  509. //#show alert message only once, so remove it here...
  510. $wassup_options->wassup_alert_message = "";
  511. $wassup_options->saveSettings();
  512. }
  513. //#debug - display MySQL errors/warnings
  514. //$mysqlerror = $wpdb->print_error(); //debug
  515. //if (!empty($mysqlerror)) { $wassup_options->showMessage($mysqlerror); } //debug
  516. //moved max-width to single "wrap" div and removed it from
  517. // the individual spans and divs in style.php... ?>
  518. <div class="wrap" style="max-width:<?php echo $screen_res_size; ?>px;" >
  519. <?php // HERE IS THE VISITORS ONLINE VIEW
  520. if ($_GET['page'] == "wassup-online") { ?>
  521. <h2><?php _e("Current Visitors Online", "wassup"); ?></h2>
  522. <p class="legend"><?php echo __("Legend", "wassup").': <span class="box-log">&nbsp;&nbsp;</span> '.__("Logged-in Users", "wassup").' <span class="box-aut">&nbsp;&nbsp;</span> '.__("Comments Authors", "wassup").' <span class="box-spider">&nbsp;&nbsp;</span> '.__("Spiders/bots", "wassup"); ?></p><br />
  523. <p class="legend"><a href="#" class="toggle-all"><?php _e("Expand All","wassup"); ?></a></p>
  524. <?php
  525. $to_date = wassup_get_time();
  526. $from_date = strtotime('-3 minutes', $to_date);
  527. $currenttot = $wpdb->get_var("SELECT COUNT(DISTINCT wassup_id) as currenttot FROM $table_tmp_name WHERE `timestamp` BETWEEN $from_date AND $to_date");
  528. $currenttot = $currenttot+0; //set to integer
  529. print "<p class='legend'>".__("Visitors online", "wassup").": <strong>".$currenttot."</strong></p><br />";
  530. if ($currenttot > 0) {
  531. $qryC = $wpdb->get_results("SELECT id, wassup_id, max(timestamp) as max_timestamp, ip, hostname, searchengine, urlrequested, agent, referrer, spider, username, comment_author FROM $table_tmp_name WHERE `timestamp` BETWEEN $from_date AND $to_date GROUP BY ip ORDER BY max_timestamp DESC");
  532. foreach ($qryC as $cv) {
  533. if ($wassup_options->wassup_time_format == 24) {
  534. $timed = gmdate("H:i:s", $cv->max_timestamp);
  535. } else {
  536. $timed = gmdate("h:i:s a", $cv->max_timestamp);
  537. }
  538. $ip_proxy = strpos($cv->ip,",");
  539. //if proxy, get 2nd ip...
  540. if ($ip_proxy !== false) {
  541. $ip = substr($cv->ip,(int)$ip_proxy+1);
  542. } else {
  543. $ip = $cv->ip;
  544. }
  545. if ($cv->referrer != '') {
  546. if (!eregi($wpurl, $cv->referrer) OR $cv->searchengine != "") {
  547. if (!eregi($wpurl, $cv->referrer) AND $cv->searchengine == "") {
  548. $referrer = '<a href="'.$cv->referrer.'" target=_"BLANK"><span style="font-weight: bold;">'.stringShortener($cv->referrer, round($max_char_len*.8,0)).'</span></a>';
  549. } else {
  550. $referrer = '<a href="'.$cv->referrer.'" target=_"BLANK">'.stringShortener($cv->referrer, round($max_char_len*.9,0)).'</a>';
  551. }
  552. } else {
  553. $referrer = __("From your blog", "wassup");
  554. }
  555. } else {
  556. $referrer = __("Direct hit", "wassup");
  557. }
  558. $numurl = $wpdb->get_var("SELECT COUNT(DISTINCT id) as numurl FROM $table_tmp_name WHERE wassup_id='".$cv->wassup_id."'");
  559. ?>
  560. <div class="sum">
  561. <span class="sum-box"><?php if ($numurl >= 2) { ?><a href="#" class="showhide" id="<?php echo $cv->id ?>"><?php print $ip; ?></a><?php } else { ?><?php print $ip; ?><?php } ?></span>
  562. <div class="sum-det"><span class="det1">
  563. <?php
  564. //# html_entity_decode() links that were already
  565. //# "htmlentities-encoded" in database to prevent wacky links
  566. //# like "/imagegallery/?album=3&amp;amp;amp;gallery=13"
  567. print '<a href="'.wAddSiteurl(htmlspecialchars(html_entity_decode($cv->urlrequested))).'" target="_BLANK">';
  568. print stringShortener(urlencode(html_entity_decode($cv->urlrequested)), round($max_char_len*.9,0)); ?></a></span><br />
  569. <span class="det2"><strong><?php print $timed; ?> - </strong><?php print $referrer ?></span></div>
  570. </div>
  571. <?php // User is logged in or is a comment's author
  572. if ($cv->username != "" OR $cv->comment_author != "") {
  573. if ($cv->username != "") {
  574. $Ousername = '<li class="users"><span class="indent-li-agent">'.__("LOGGED IN USER", "wassup").': <strong>'.$cv->username.'</strong></span></li>';
  575. $Ocomment_author = '<li class="users"><span class="indent-li-agent">'.__("COMMENT AUTHOR", "wassup").': <strong>'.$cv->comment_author.'</strong></span></li>';
  576. $unclass = "userslogged";
  577. } elseif ($cv->comment_author != "") {
  578. $Ocomment_author = '<li class="users"><span class="indent-li-agent">'.__("COMMENT AUTHOR", "wassup").': <strong>'.$cv->comment_author.'</strong></span></li>';
  579. $unclass = "users";
  580. }
  581. ?>
  582. <ul class="<?php print $unclass; ?>">
  583. <?php print $Ousername; ?>
  584. <?php print $Ocomment_author; ?>
  585. </ul>
  586. <?php } ?>
  587. <div style="display: none;" class="togglenavi navi<?php echo $cv->id ?>">
  588. <ul class="url">
  589. <?php
  590. $qryCD = $wpdb->get_results("SELECT `timestamp`, urlrequested FROM $table_tmp_name WHERE wassup_id='".$cv->wassup_id."' ORDER BY `timestamp` ASC");
  591. $i=0;
  592. foreach ($qryCD as $cd) {
  593. $time2 = gmdate("H:i:s", $cd->timestamp);
  594. $num = ($i&1);
  595. $char_len = round($max_char_len*.9,0);
  596. if ($num == 0) $classodd = "urlodd"; else $classodd = "url";
  597. if ($i >= 1) {
  598. ?>
  599. <li class="<?php print $classodd; ?> navi<?php echo $cv->id ?>"><span class="indent-li"><?php print $time2; ?> -
  600. <?php
  601. print '<a href="'.wAddSiteurl(htmlspecialchars(html_entity_decode($cd->urlrequested))).'" target="_BLANK">';
  602. print stringShortener(urlencode(html_entity_decode($cd->urlrequested)), $char_len).'</a></span></li>'."\n";
  603. }
  604. $i++;
  605. } //end foreach qryCD
  606. print '</ul>';
  607. print '</div>';
  608. print '<p class="sum-footer"></p>';
  609. } //end foreach qryC
  610. } //end if currenttot ?>
  611. <br /><p class="legend"><a href="#" class="toggle-all"><?php _e("Expand All", "wassup"); ?></a></p>
  612. <?php // HERE IS THE SPY MODE VIEW
  613. } elseif ($_GET['page'] == "wassup-spy") {
  614. ?>
  615. <h2><?php _e("SPY Visitors", "wassup"); ?></h2>
  616. <p class="legend"><?php echo __("Legend", "wassup").': <span class="box-log">&nbsp;&nbsp;</span> '.__("Logged-in Users", "wassup").' <span class="box-aut">&nbsp;&nbsp;</span> '.__("Comments Authors", "wassup").' <span class="box-spider">&nbsp;&nbsp;</span> '.__("Spiders/bots", "wassup"); ?></p><br />
  617. <div>
  618. <a href="#?" onclick="return pauseSpy();"><span id="spy-pause"><?php _e("Pause", "wassup"); ?></span></a>
  619. <a href="#?" onclick="return playSpy();"><span id="spy-play"><?php _e("Play", "wassup"); ?></span></a>
  620. - <span style="font-size: 11px;"><?php _e('Spy items by','wassup'); ?>: <select name="navi" style="font-size: 11px;" onChange="window.location.href=this.options[this.selectedIndex].value;">
  621. <?php
  622. //## selectable filter by type of record (wassup_default_spy_type)
  623. if (isset($_GET['spytype'])) {
  624. $spytype = htmlentities(attribute_escape($_GET['spytype']));
  625. } elseif ($wassup_options->wassup_default_spy_type != '') {
  626. $spytype = $wassup_options->wassup_default_spy_type;
  627. }
  628. $selected=$spytype;
  629. $optionargs="?page=wassup-spy&spytype=";
  630. $wassup_options->showFormOptions("wassup_default_spy_type","$selected","$optionargs");
  631. ?>
  632. </select>
  633. </span>
  634. <br />&nbsp;<br /></div>
  635. <?php // GEO IP Map
  636. if ($wassup_options->wassup_geoip_map == 1 AND $wassup_options->wassup_googlemaps_key != "") { ?>
  637. <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $wassup_options->wassup_googlemaps_key; ?>" type="text/javascript"></script>
  638. <div id="map" style="width: <?php echo ($screen_res_size*95/100); ?>px; height: 220px;border:2px solid #999;"></div>
  639. <script type="text/javascript">
  640. //<![CDATA[
  641. if (GBrowserIsCompatible()) {
  642. // Display the map, with some controls and set the initial location
  643. var map = new GMap2(document.getElementById("map"));
  644. map.addControl(new GSmallMapControl());
  645. map.addControl(new GMapTypeControl());
  646. //map.enableScrollWheelZoom();
  647. map.setCenter(new GLatLng(0,0),3);
  648. }
  649. // display a warning if the browser was not compatible
  650. else {
  651. alert("Sorry, the Google Maps API is not compatible with this browser");
  652. }
  653. //]]>
  654. </script>
  655. <p>&nbsp;</p>
  656. <? } //end if geoip_map
  657. ?>
  658. <div id="spyContainer">
  659. <?php
  660. //display the last few hits here. The rest will be added by spy.js
  661. $to_date = (wassup_get_time()-2);
  662. $from_date = ($to_date - 12*(60*60)); //display last 10 visits in 12 hours...
  663. spyview($from_date,$to_date,10,$spytype); ?>
  664. </div><br />
  665. <?php // HERE IS THE OPTIONS VIEW
  666. } elseif($_GET['page'] == "wassup-options") {
  667. //#moved content to external include file, "settings.php"
  668. //# to make "wassup" code easier to read and modify
  669. //# -Helene D. 1/15/08.
  670. include(dirname(__FILE__).'/lib/settings.php'); ?>
  671. <?php // HERE IS THE MAIN/DETAILS VIEW
  672. } else { ?>
  673. <h2><?php _e("Latest hits", "wassup"); ?></h2>
  674. <?php if ($wassup_options->wassup_active != 1) { ?>
  675. <p style="color:red; font-weight:bold;"><?php _e("WassUp recording is disabled", "wassup"); ?></p>
  676. <?php }
  677. $res = (int) $wassup_options->wassup_screen_res;
  678. if (empty($res)) $res=620;
  679. elseif ($res < 800) $res=620;
  680. elseif ($res < 1024) $res=740;
  681. elseif ($res < 1200) $res=1000;
  682. else $res=1000;
  683. //## GET parameters that change options settings
  684. if (isset($_GET['wchart']) || isset($_GET['wmark'])) {
  685. if (isset($_GET['wchart'])) {
  686. if ($_GET['wchart'] == 0) {
  687. $wassup_options->wassup_chart = 0;
  688. } else {
  689. $wassup_options->wassup_chart = 1;
  690. }
  691. }
  692. if (isset($_GET['wmark'])) {
  693. if ($_GET['wmark'] == 0) {
  694. $wassup_options->wmark = "0";
  695. $wassup_options->wip = "";
  696. } else {
  697. $wassup_options->wmark = "1";
  698. $wassup_options->wip = attribute_escape($_GET['wip']);
  699. }
  700. }
  701. $wassup_options->saveSettings();
  702. }
  703. //## GET params that filter detail display
  704. //
  705. //## Filter detail list by date range...
  706. $to_date = wassup_get_time();
  707. if (isset($_GET['last']) && $_GET['last'] != "") {
  708. $last = htmlentities(attribute_escape($_GET['last']));
  709. } else {
  710. $last = 1;
  711. }
  712. $from_date = strtotime('-'.$last.' day', $to_date);
  713. //## Filter detail lists by visitor type...
  714. if (isset($_GET['type'])) {
  715. $type = htmlentities(attribute_escape($_GET['type']));
  716. } elseif ($wassup_options->wassup_default_type != '') {
  717. $type = $wassup_options->wassup_default_type;
  718. }
  719. $whereis="";
  720. if ($type == 'spider') {
  721. $whereis = " AND spider!=''";
  722. } elseif ($type == 'nospider') {
  723. $whereis = " AND spider=''";
  724. } elseif ($type == 'spam') {
  725. $whereis = " AND spam>0";
  726. } elseif ($type == 'nospam') {
  727. $whereis = " AND spam=0";
  728. } elseif ($type == 'nospamspider') {
  729. $whereis = " AND spam=0 AND spider=''";
  730. } elseif ($type == 'searchengine') {
  731. $whereis = " AND searchengine!='' AND search!=''";
  732. } elseif ($type == 'referrer') {
  733. $whereis = " AND referrer!='' AND referrer NOT LIKE '%$wpurl%' AND searchengine='' AND search=''";
  734. } elseif ($type == 'comauthor') {
  735. $whereis = " AND comment_author!=''";
  736. } elseif ($type == 'loggedin') {
  737. $whereis = " AND username!=''";
  738. }
  739. //## Filter detail lists by a specific page and number
  740. //# of items per page...
  741. $items = 10; //default
  742. if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
  743. //$items = htmlentities(attribute_escape($_GET['limit']));
  744. $items = $_GET['limit'];
  745. } elseif ($wassup_options->wassup_default_limit != '') {
  746. $items = $wassup_options->wassup_default_limit;
  747. }
  748. if ((int)$items < 1 ) { $items = 10; }
  749. //# current page selections
  750. if (isset($_GET['pages']) && is_numeric($_GET['pages'])) {
  751. $pages = (int)$_GET['pages'];
  752. } else {
  753. $pages = 1;
  754. }
  755. if ( $pages > 1 ) {
  756. $limit = " LIMIT ".(($pages-1)*$items).",$items";
  757. } else {
  758. $limit = " LIMIT $items";
  759. }
  760. //## Filter detail lists by a searched item
  761. if (!empty($_GET['search'])) {
  762. $search = attribute_escape($_GET['search']);
  763. } else {
  764. $search = "";
  765. }
  766. // DELETE EVERY RECORD MARKED BY IP
  767. //# Delete limited to selected date range only. -Helene D. 3/4/08.
  768. if (!empty($_GET['deleteMARKED']) && $wassup_options->wmark == "1" ) {
  769. $rec_deleted = $wpdb->get_var("SELECT COUNT(ip) as deleted FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND `timestamp` BETWEEN $from_date AND $to_date");
  770. if (method_exists($wpdb,'prepare')) {
  771. $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE ip='%s' AND `timestamp` BETWEEN %s AND %s", urlencode(attribute_escape($_GET['dip'])), $from_date, $to_date));
  772. } else {
  773. $wpdb->query("DELETE FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND `timestamp` BETWEEN $from_date AND $to_date");
  774. }
  775. echo '<p><strong>'.$rec_deleted.' '.__('records deleted','wassup').'</strong></p>';
  776. //reset wmark/deleteMarked after delete and
  777. // clean up $_SERVER['QUERY_STRING'] as it is
  778. // used in filter selections below...
  779. $remove_query= array("&dip=".$_GET['dip'],"&deleteMARKED=".$_GET['deleteMARKED'],"&wmark=1","&wip=".$_GET['wip']);
  780. $new_query = str_replace($remove_query,"",$_SERVER['QUERY_STRING']);
  781. $_SERVER['QUERY_STRING']=$new_query;
  782. $wassup_options->wmark = "0";
  783. $wassup_options->wip = null;
  784. $wassup_options->saveSettings();
  785. }
  786. // Instantiate class to count items
  787. $Tot = New MainItems;
  788. $Tot->tableName = $table_name;
  789. $Tot->from_date = $from_date;
  790. $Tot->to_date = $to_date;
  791. $Tot->whereis = $whereis;
  792. $Tot->Limit = $limit;
  793. $Tot->WpUrl = $wpurl;
  794. $itemstot = $Tot->calc_tot("count", $search, null, "DISTINCT");
  795. $pagestot = $Tot->calc_tot("count", $search, null, null);
  796. $spamtot = $Tot->calc_tot("count", $search, "AND spam>0");
  797. // Check if some records was marked
  798. if ($wassup_options->wmark == "1") {
  799. $markedtot = $Tot->calc_tot("count", $search, "AND ip LIKE '%".$wassup_options->wip."%'", "DISTINCT");
  800. }
  801. // Check if some records was searched
  802. if (!empty($search)) {
  803. $searchtot = $Tot->calc_tot("count", $search, null, "DISTINCT");
  804. } ?>
  805. <form><table width="100%">
  806. <tr>
  807. <td>
  808. <p class="legend">
  809. <?php if ($wassup_options->wassup_chart == "1") { ?>
  810. <a href="<?php echo '?page='.WASSUPFOLDER.'&wchart=0&last='.$last.'&limit='.$items.'&type='.$_GET['type'].'&search='.$search.'&pages='.$pages; ?>" style="text-decoration:none;">
  811. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/chart_delete.png" style="padding:0px 6px 0 0;" alt="'.__('hide chart','wassup').'" title="'.__('Hide the chart and site usage','wassup'); ?>" /></a>
  812. <?php } else { ?>
  813. <a href="<?php echo '?page='.WASSUPFOLDER.'&wchart=1&last='.$last.'&limit='.$items.'&type='.$_GET['type'].'&search='.$search.'&pages='.$pages; ?>" style="text-decoration:none;">
  814. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/chart_add.png" style="padding:0px 6px 0 0;" alt="'.__('show chart','wassup').'" title="'.__('Show the chart and site usage','wassup'); ?>" /></a>
  815. <?php }
  816. //## Show selectable detail filters...
  817. if (isset($_GET['limit'])) {
  818. $new_limit = eregi_replace("\&limit=".$_GET['limit']."", "", $_SERVER['QUERY_STRING']);
  819. } else {
  820. $new_limit = $_SERVER['QUERY_STRING'];
  821. }
  822. if (isset($_GET['last'])) {
  823. $new_last = eregi_replace("\&last=".$_GET['last']."", "", $_SERVER['QUERY_STRING']);
  824. } else {
  825. $new_last = $_SERVER['QUERY_STRING'];
  826. }
  827. _e('Summary for the last','wassup'); ?>
  828. <select style="font-size: 11px;" name="last" onChange="window.location.href=this.options[this.selectedIndex].value;">
  829. <?php
  830. //## selectable filter by date range
  831. echo "
  832. <option value='?$new_last&last=1'".($_GET['last'] == 1 ? " SELECTED" : "").">".__('24 hours','wassup')."</option>
  833. <option value='?$new_last&last=7'".($_GET['last'] == 7 ? " SELECTED" : "").">".__('7 days','wassup')."</option>
  834. <option value='?$new_last&last=30'".($_GET['last'] == 30 ? " SELECTED" : "").">".__('1 month','wassup')."</option>
  835. <option value='?$new_last&last=365'".($_GET['last'] == 365 ? " SELECTED" : "").">".__('1 year','wassup')."</option>"; ?>
  836. </select></p>
  837. </td>
  838. <td align="right"><p style="font-size: 11px;"><?php _e('Items per page','wassup'); ?>: <select name="navi" style="font-size: 11px;" onChange="window.location.href=this.options[this.selectedIndex].value;">
  839. <?php
  840. //## selectable filter by number of items on page (default_limit)
  841. $selected=$items;
  842. $optionargs="?$new_limit&limit=";
  843. $wassup_options->showFormOptions("wassup_default_limit","$selected","$optionargs");
  844. ?>
  845. </select> - <?php _e('Show items by','wassup'); ?>: <select style="font-size: 11px;" name="type" onChange="window.location.href=this.options[this.selectedIndex].value;">
  846. <?php
  847. //## selectable filter by type of record (wassup_default_type)
  848. $selected=$type;
  849. $optionargs="?page=".WASSUPFOLDER."&type=";
  850. $wassup_options->showFormOptions("wassup_default_type","$selected","$optionargs");
  851. ?>
  852. </select>
  853. </p>
  854. </td>
  855. </tr>
  856. </table>
  857. </form>
  858. <?php // Print Site Usage
  859. if ($wassup_options->wassup_chart == 1) { ?>
  860. <div class='main-tabs'>
  861. <div id='usage'>
  862. <ul>
  863. <li><span style="border-bottom:2px solid #0077CC;"><?php echo $itemstot; ?></span> <small><?php _e('Visits','wassup'); ?></small></li>
  864. <li><span style="border-bottom:2px dashed #FF6D06;"><?php echo $pagestot; ?></span> <small><?php _e('Pageviews','wassup'); ?></small></li>
  865. <li><span><?php echo @number_format(($pagestot/$itemstot), 2); ?></span> <small><?php _e('Pages/Visits','wassup'); ?></small></li>
  866. <?php // Print spam usage only if enabled
  867. if ($wassup_options->wassup_spamcheck == 1) { ?>
  868. <li><span><a href="#TB_inline?height=180&width=300&inlineId=hiddenspam" class="thickbox"><?php echo $spamtot; ?></a></span> <span>(<?php echo @number_format(($spamtot*100/$pagestot), 2); ?>%)</span> <small><?php _e('Spams','wassup'); ?></small></li>
  869. <?php } ?>
  870. </ul>
  871. <?php
  872. // Print the Google chart!
  873. if ($pagestot > 20) {
  874. echo $Tot->TheChart($last, $res, "125", $search, $wassup_options->wassup_chart_type, "bg,s,ffffff")."";
  875. } else {
  876. echo '<div id="placeholder" align="center"><p style="padding-top:50px;">'.__('Too few records to print chart','wassup').'...</p></div>';
  877. } ?>
  878. </div>
  879. </div>
  880. <?php } //end if wassup_chart == 1
  881. if (!isset($_GET['limit']) OR $_GET['limit'] == 10 OR $_GET['limit'] == 20) {
  882. $expcol = '
  883. <table width="100%"><tr>
  884. <td align="left" class="legend"><a href="#" class="toggle-all">'.__('Expand All','wassup').'</a></td>
  885. <td align="right" class="legend"><a href="#" class="toggle-allcrono">'.__('Collapse Chronology','wassup').'</a></td>
  886. </tr></table><br />';
  887. }
  888. // MAIN QUERY
  889. $main = $Tot->calc_tot("main", $search);
  890. if ($itemstot > 0) {
  891. $p=new pagination();
  892. $p->items($itemstot);
  893. $p->limit($items);
  894. $p->currentPage($pages);
  895. $p->target("admin.php?page=".WASSUPFOLDER."&limit=$items&type=$type&last=$last&search=$search");
  896. $p->calculate();
  897. $p->adjacents(5);
  898. }
  899. // hidden spam options
  900. ?>
  901. <div id="hiddenspam" style="display:none;">
  902. <h2><?php _e('Spam Options','wassup'); ?></h2>
  903. <form action="" method="post">
  904. <p><input type="checkbox" name="wassup_spamcheck" value="1" <?php if($wassup_options->wassup_spamcheck == 1 ) print "CHECKED"; ?> /> <strong><?php _e('Enable/Disable Spam Check on Records','wassup'); ?></strong></p>
  905. <p style="padding-left:30px;"><input type="checkbox" name="wassup_spam" value="1" <?php if($wassup_options->wassup_spam == 1) print "CHECKED"; ?> /> <?php _e('Record Akismet comment spam attempts','wassup'); ?></p>
  906. <p style="padding-left:30px;"><input type="checkbox" name="wassup_refspam" value="1" <?php if($wassup_options->wassup_refspam == 1) print "CHECKED"; ?> /> <?php _e('Record referrer spam attempts','wassup'); ?></p>
  907. <p style="padding-left:0;"><input type="submit" name="submit-spam" value="<?php _e('Save Settings','wassup'); ?>" /></p>
  908. </form>
  909. </div>
  910. <table width="100%">
  911. <tr>
  912. <td align="left" class="legend">
  913. <?php
  914. // Marked items - Refresh
  915. if ($wassup_options->wmark == 1) echo '<a href="?'.$_SERVER['QUERY_STRING'].'&search='.$wassup_options->wip.'" title="'.__('Filter by marked IP','wassup').'"><strong>'.$markedtot.'</strong> '.__('show marked items','wassup').'</a> - ';
  916. if (!empty($search)) print "<strong>$searchtot</strong> ".__('Searched for','wassup').": <strong>$search</strong> - ";
  917. echo __('Auto refresh in','wassup').' <span id="CountDownPanel"></span> '.__('seconds','wassup'); ?>
  918. </td>
  919. <td align="right" class="legend"><a href="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/lib/action.php?action=topten&whash='.$whash.'&from_date='.$from_date.'&to_date='.$to_date.'&width='.$res.'&height=400'; ?>" class="thickbox" title="Wassup <?php _e('Top Ten','wassup'); ?>"><?php _e('Show Top Ten','wassup'); ?></a> - <a href="#" class='show-search'><?php _e('Search','wassup'); ?></a></td>
  920. </tr>
  921. </table>
  922. <div class="search-ip" style="display: none;">
  923. <table border=0 width="100%">
  924. <tr valign="top">
  925. <td align="right">
  926. <form action="" method="get">
  927. <input type="hidden" name="page" value="<?php echo WASSUPFOLDER; ?>" />
  928. <input type="text" size="25" name="search" value="<?php if ($search != "") print $search; ?>" /><input type="submit" name="submit-search" value="search" />
  929. </form>
  930. </td>
  931. </tr>
  932. </table>
  933. </div>
  934. <?php
  935. //# Detailed List of Wassup Records...
  936. print $expcol;
  937. //# Show Page numbers/Links...
  938. if ($itemstot >= 10) {
  939. print "\n".'<div id="pag" align="center">'.$p->show().'</div><br />'."\n";
  940. }
  941. if ($itemstot > 0) {
  942. foreach ($main as $rk) {
  943. $timestampF = $rk->max_timestamp;
  944. $dateF = gmdate("d M Y", $timestampF);
  945. if ($wassup_options->wassup_time_format == 24) {
  946. $datetimeF = gmdate('Y-m-d H:i:s', $timestampF);
  947. $timeF = gmdate("H:i:s", $timestampF);
  948. } else {
  949. $datetimeF = gmdate('Y-m-d h:i:s a', $timestampF);
  950. $timeF = gmdate("h:i:s a", $timestampF);
  951. }
  952. //$ip = @explode(",", $rk->ip);
  953. $ip_proxy = strpos($rk->ip,",");
  954. //if proxy, get 2nd ip...
  955. if ($ip_proxy !== false) {
  956. $ip = substr($rk->ip,(int)$ip_proxy+1);
  957. } else {
  958. $ip = $rk->ip;
  959. }
  960. // Visitor Record - raw data (hidden)
  961. $raw_div="raw-".substr($rk->wassup_id,0,25).rand(0,99);
  962. echo "\n"; ?>
  963. <div id="<?php echo $raw_div; ?>" style="display:none; padding-top:7px;" >
  964. <h2><?php _e("Raw data","wassup"); ?>:</h2>
  965. <style type="text/css">.raw { color: #542; padding-left:5px; }</style>
  966. <ul style="list-style-type:none;padding:20px 0 0 30px;">
  967. <li><?php echo __("Visit type","wassup").': <span class="raw">';
  968. if ($rk->username != "") {
  969. echo __("Logged-in user","wassup").' - '.$rk->username;
  970. } elseif ($rk->spam == "1" || $rk->spam == "2" ) {
  971. _e("Spammer","wassup");
  972. } elseif ($rk->comment_author != "") {
  973. echo __("Comment author","wassup").' - '.$rk->comment_author;
  974. } elseif ($rk->feed != "") {
  975. echo __("Feed","wassup").' - '.$rk->feed;
  976. } elseif ($rk->spider != "") {
  977. echo __("Spider","wassup").' - '.$rk->spider;
  978. } else {
  979. _e("Regular visitor","wassup");
  980. }
  981. echo '</span>'; ?></li>
  982. <li><?php echo __("IP","wassup").': <span class="raw">'.$rk->ip.'</span>'; ?></li>
  983. <li><?php echo __("Hostname","wassup").': <span class="raw">'.$rk->hostname.'</span>'; ?></li>
  984. <li><?php echo __("Url Requested","wassup").': <span class="raw">'.htmlspecialchars(html_entity_decode(clean_url($rk->urlrequested))).'</span>'; ?></li>
  985. <li><?php echo __("User Agent","wassup").': <span class="raw">'.$rk->agent.'</span>'; ?></li>
  986. <li><?php echo __("Referrer","wassup").': <span class="raw">'.urldecode($rk->referrer).'</span>'; ?></li>
  987. <?php if ($rk->search != "") { ?>
  988. <li><?php echo __("Search Engine","wassup").': <span class="raw">'.$rk->searchengine.'</span> &nbsp; &nbsp; ';
  989. echo __("Search","wassup").': <span class="raw">'.$rk->search.'</span>'; ?></li>
  990. <?php }
  991. if ($rk->os != "") { ?>
  992. <li><?php echo __("OS","wassup").': <span class="raw">'.$rk->os.'</span>'; ?></li>
  993. <?php }
  994. if ($rk->browser != "") { ?>
  995. <li><?php echo __("Browser","wassup").': <span class="raw">'.$rk->browser.'</span>'; ?></li>
  996. <?php }
  997. if ($rk->language != "") { ?>
  998. <li><?php echo __("Locale/Language","wassup").': <span class="raw">'.$rk->language.'</span>'; ?></li>
  999. <?php } ?>
  1000. <li><?php echo 'Wassup ID'.': <span class="raw">'.$rk->wassup_id.'</span>'; ?></li>
  1001. <li><?php echo __("End timestamp","wassup").': <span class="raw">'.$datetimeF.' ( '.$rk->max_timestamp.' )</span>'; ?></li>
  1002. </ul>
  1003. </div> <!-- raw-wassup_id -->
  1004. <?php //Visitor Record - detail listing
  1005. if ($rk->referrer != '') {
  1006. if (!eregi($wpurl, $rk->referrer) OR $rk->searchengine != "") {
  1007. if (!eregi($wpurl, $rk->referrer) AND $rk->searchengine == "") {
  1008. $referrer = '<a href="'.$rk->referrer.'" target="_BLANK"><span style="font-weight: bold;">'.stringShortener($rk->referrer, round($max_char_len*.8,0)).'</span></a>';
  1009. } else {
  1010. $referrer = '<a href="'.$rk->referrer.'" target="_BLANK">'.stringShortener($rk->referrer, round($max_char_len*.9,0)).'</a>';
  1011. }
  1012. } else {
  1013. $referrer = __('From your blog','wassup');
  1014. }
  1015. } else {
  1016. $referrer = __('Direct hit','wassup');
  1017. }
  1018. $numurl = $wpdb->get_var("SELECT COUNT(DISTINCT id) as numurl FROM $table_name WHERE wassup_id='".$rk->wassup_id."'");
  1019. if ($rk->hostname != "") $hostname = $rk->hostname; else $hostname = "unknown";
  1020. ?>
  1021. <div class="delID<?php echo $rk->wassup_id ?>">
  1022. <div class="<?php if ($wassup_options->wmark == 1 AND $wassup_options->wip == $ip) echo "sum-nav-mark"; else echo "sum-nav"; ?>">
  1023. <p class="delbut">
  1024. <?php // Mark/Unmark IP
  1025. if ($wassup_options->wmark == 1 AND $wassup_options->wip == $ip) { ?>
  1026. <a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&deleteMARKED=1&dip=<?php print $ip; ?>" style="text-decoration:none;">
  1027. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/cross.png" alt="'.__('delete','wassup').'" title="'.__('Delete ALL marked records with this IP','wassup'); ?>" /></a>
  1028. <a href="?page=<?php echo WASSUPFOLDER; ?>&wmark=0" style="text-decoration:none;">
  1029. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/error_delete.png" alt="'.__('unmark','wassup').'" title="'.__('UnMark IP','wassup'); ?>" /></a>
  1030. <?php } else { ?>
  1031. <a href="#" class="deleteID" id="<?php echo $rk->wassup_id ?>" style="text-decoration:none;">
  1032. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/cross.png" alt="'.__('delete','wassup').'" title="'.__('Delete this record','wassup'); ?>" /></a>
  1033. <a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&wmark=1&wip=<?php print $ip; ?>" style="text-decoration:none;">
  1034. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/error_add.png" alt="'.__('mark','wassup').'" title="'.__('Mark IP','wassup'); ?>" /></a>
  1035. <?php } ?>
  1036. <a href="#TB_inline?height=400&width=<?php echo $res.'&inlineId='.$raw_div; ?>" class="thickbox">
  1037. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/database_table.png" alt="'.__('show raw table','wassup').'" title="'.__('Show the items as raw table','wassup'); ?>" /></a>
  1038. </p>
  1039. <span class="sum-box"><?php if ($numurl >= 2) { ?><a href="#" class="showhide" id="<?php echo $rk->id ?>"><?php print $ip; ?></a><?php } else { ?><?php print $ip; ?><?php } ?></span>
  1040. <span class="sum-date"><?php print $datetimeF; ?></span>
  1041. <div class="sum-det"><span class="det1">
  1042. <?php
  1043. print '<a href="'.wAddSiteurl(htmlspecialchars(html_entity_decode(clean_url($rk->urlrequested)))).'" target="_BLANK">';
  1044. print stringShortener(urlencode(html_entity_decode(clean_url($rk->urlrequested))), round($max_char_len*.8,0)); ?></a>
  1045. </span><br />
  1046. <span class="det2"><strong><?php _e('Referrer','wassup'); ?>: </strong><?php print $referrer; ?><br /><strong><?php _e('Hostname','wassup'); ?>:</strong> <a href="#" class="toggleagent" id="<?php echo $rk->id ?>"><?php print $hostname; ?></a></span></div>
  1047. </div>
  1048. <div style="margin-left: auto; margin-right: auto;">
  1049. <div style="display: none;" class="togglenavi naviagent<?php echo $rk->id ?>">
  1050. <ul class="useragent">
  1051. <li class="useragent"><span class="indent-li-agent"><?php _e('User Agent','wassup'); ?>: <strong><?php print $rk->agent; ?></strong></span></li>
  1052. </ul>
  1053. </div>
  1054. <?php // Referer is search engine
  1055. if ($rk->searchengine != "") {
  1056. if (eregi("images", $rk->searchengine)) {
  1057. $bg = 'style="background: #e5e3ec;"';
  1058. $page = (number_format(($rk->searchpage / 19), 0) * 18);
  1059. $Apagenum = explode(".", number_format(($rk->searchpage / 19), 1));
  1060. $pagenum = ($Apagenum[0] + 1);
  1061. $url = parse_url($rk->referrer);
  1062. $ref = $url['scheme']."://".$url['host']."/images?q=".eregi_replace(" ", "+", $rk->search)."&start=".$page;
  1063. } else {
  1064. $bg = 'style="background: #e4ecf4;"';
  1065. $pagenum = $rk->searchpage;
  1066. $ref = $rk->referrer;
  1067. }
  1068. ?>
  1069. <ul class="searcheng" <?php print $bg; ?>>
  1070. <li class="searcheng"><span class="indent-li-agent"><?php _e('SEARCH ENGINE','wassup'); ?>: <strong><?php print $rk->searchengine." (".__("page","wassup").": $pagenum)"; ?></strong></span></li>
  1071. <li class="searcheng"><?php _e("KEYWORDS","wassup"); ?>: <strong><a href="<?php print $ref; ?>" target="_BLANK"><?php print stringShortener($rk->search, round($max_char_len*.52,0)); ?></a></strong></li>
  1072. </ul>
  1073. <?php
  1074. } ?>
  1075. <?php
  1076. // User is logged in or is a comment's author
  1077. if ($rk->username != "" OR $rk->comment_author != "") {
  1078. if ($rk->username != "") {
  1079. $Ocomment_author = '<li class="users"><span class="indent-li-agent">'.__("LOGGED IN USER","wassup").': <strong>'.$rk->username.'</strong></span></li>
  1080. <li class="users"><span class="indent-li-agent">'.__("COMMENT AUTHOR","wassup").': <strong>'.$rk->comment_author.'</strong></span></li>';
  1081. $unclass = "userslogged";
  1082. } elseif ($rk->comment_author != "") {
  1083. $Ocomment_author = '<li class="users"><span class="indent-li-agent">'.__("COMMENT AUTHOR","wassup").': <strong>'.utf8_decode($rk->comment_author).'</strong></span></li>';
  1084. $unclass = "users";
  1085. }
  1086. ?>
  1087. <ul class="<?php print $unclass; ?>">
  1088. <?php print $Ocomment_author; ?>
  1089. </ul>
  1090. <?php } ?>
  1091. <?php // Referer is a Spider or Bot
  1092. if ($rk->spider != "") {
  1093. if ($rk->feed != "") { ?>
  1094. <ul style="background:#fdeec8;" class="spider">
  1095. <li class="feed"><span class="indent-li-agent"><?php _e('FEEDREADER','wassup'); ?>: <strong><?php print $rk->spider; ?></strong></span></li>
  1096. <?php if (is_numeric($rk->feed)) { ?>
  1097. <li class="feed"><span class="indent-li-agent"><?php _e('SUBSCRIBER(S)','wassup'); ?>: <strong><?php print (int)$rk->feed; ?></strong></span></li>
  1098. <?php } ?>
  1099. </ul>
  1100. <?php } else { ?>
  1101. <ul class="spider">
  1102. <li class="spider"><span class="indent-li-agent"><?php _e('SPIDER','wassup'); ?>: <strong><?php print $rk->spider; ?></strong></span></li>
  1103. </ul>
  1104. <?php }
  1105. } ?>
  1106. <?php // Referer is a SPAM
  1107. if ($rk->spam > 0 && $rk->spam < 3) { ?>
  1108. <ul class="spam">
  1109. <li class="spam"><span class="indent-li-agent">
  1110. <?php _e("Probably SPAM!","wassup");
  1111. if ($rk->spam==2) { echo '('.__("Referer Spam","wassup").')'; }
  1112. else { echo '(Akismet '.__("Spam","wassup").')'; } ?>
  1113. </span></li>
  1114. </ul>
  1115. <?php } elseif ($rk->spam == 3) { ?>
  1116. <ul class="spam">
  1117. <li class="spam"><span class="indent-li-agent">
  1118. <?php _e("Probably hack attempt!","wassup"); ?>
  1119. </li></ul>
  1120. <?php } ?>
  1121. <?php // User os/browser/language
  1122. if ($rk->spider == "" AND ($rk->os != "" OR $rk->browser != "")) {
  1123. ?>
  1124. <ul class="agent">
  1125. <li class="agent"><span class="indent-li-agent">
  1126. <?php if ($rk->language != "") { ?>
  1127. <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/flags/'.strtolower($rk->language).'.png'.'" alt="'.strtolower($rk->language).'" title="'.__("Language","wassup").': '.strtolower($rk->language); ?>" />
  1128. <?php }
  1129. _e("OS","wassup"); ?>: <strong><?php print $rk->os; ?></strong></span></li>
  1130. <li class="agent"><?php _e("BROWSER","wassup"); ?>: <strong><?php print $rk->browser; ?></strong></li>
  1131. <?php if ($rk->screen_res != "") { ?>
  1132. <li class="agent"><?php _e("RESOLUTION","wassup"); ?>: <strong><?php print $rk->screen_res; ?></strong></li>
  1133. <?php } ?>
  1134. </ul>
  1135. <?php } ?>
  1136. <div style="display: visible;" class="togglecrono navi<?php echo $rk->id ?>">
  1137. <ul class="url">
  1138. <?php
  1139. $qryCD = $wpdb->get_results("SELECT `timestamp`, urlrequested FROM $table_name WHERE wassup_id='".$rk->wassup_id."' ORDER BY `timestamp` ASC");
  1140. $i=0;
  1141. foreach ($qryCD as $cd) {
  1142. //$timestamp2 = $cd->timestamp; //redundant
  1143. $time2 = gmdate("H:i:s", $cd->timestamp);
  1144. $char_len = round($max_char_len*.92,0);
  1145. $num = ($i&1);
  1146. if ($num == 0) $classodd = "urlodd"; else $classodd = "url";
  1147. if ($i >= 1) {
  1148. print '<li class="'.$classodd.' navi'.$rk->id.'"><span class="indent-li-nav">'.$time2.' ->';
  1149. print '<a href="'.wAddSiteurl(htmlspecialchars(html_entity_decode($cd->urlrequested))).'" target="_BLANK">';
  1150. print stringShortener(urlencode(html_entity_decode($cd->urlrequested)), $char_len).'</a></span></li>'."\n";
  1151. }
  1152. $i++;
  1153. } //end foreach qryCD
  1154. print "</ul>";
  1155. ?>
  1156. </div>
  1157. <p class="sum-footer"></p>
  1158. </div>
  1159. </div>
  1160. <?php } //end foreach qry
  1161. } //end if itemstot > 0
  1162. print '<br />';
  1163. if ($itemstot >= 10) $p->show();
  1164. print '<br />';
  1165. if (!isset($_GET['limit']) OR $_GET['limit'] == 10 OR $_GET['limit'] == 20) {
  1166. print $expcol;
  1167. }
  1168. if($con) mysql_close($con);
  1169. } //end MAIN/DETAILS VIEW
  1170. // End calculating execution time of script
  1171. $mtime = microtime();
  1172. $mtime = explode(" ",$mtime);
  1173. $mtime = $mtime[1] + $mtime[0];
  1174. $endtime = $mtime;
  1175. $totaltime = ($endtime - $starttime);
  1176. ?>
  1177. <p><small>WassUp ver: <?php echo $version.' - '.__("Check the official","wassup").' <a href="http://www.wpwp.org" target="_BLANK">WassUp</a> '.__("page for updates, bug reports and your hints to improve it","wassup").' - <a href="http://trac.wpwp.org/wiki/Documentation" title="Wassup '.__("User Guide documentation","wassup").'">Wassup '.__("User Guide documentation","wassup").'</a>'; ?> - Exec time: <?php echo $totaltime ?></small></p>
  1178. </div> <!-- end wrap -->
  1179. <?php
  1180. } //end function Wassup
  1181. function CreateTable($table_name="",$withcharset=true) {
  1182. global $wpdb;
  1183. $charset_collate = '';
  1184. //#don't do character set/collation if < MySQL 4.1
  1185. if (version_compare(mysql_get_server_info(), '4.1.0', '<')) {
  1186. $withcharset=false;
  1187. } elseif (!defined('DB_CHARSET')) { //DB_CHARSET must be defined in wp-config.php
  1188. $withcharset=false;
  1189. }
  1190. if ($withcharset && $wpdb->supports_collation() && !empty($wpdb->charset)) {
  1191. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  1192. //use collate only when charset is specified
  1193. if (!empty($wpdb->collate)) {
  1194. $charset_collate .= " COLLATE $wpdb->collate";
  1195. }
  1196. }
  1197. if ($table_name == "") {
  1198. $table_name = $wpdb->prefix . "wassup";
  1199. }
  1200. $sql_createtable = "CREATE TABLE " . $table_name . " (
  1201. id mediumint(9) NOT NULL auto_increment,
  1202. wassup_id varchar(80) NOT NULL,
  1203. timestamp varchar(20) NOT NULL,
  1204. ip varchar(35) default NULL,
  1205. hostname varchar(150) default NULL,
  1206. urlrequested text,
  1207. agent varchar(255) default NULL,
  1208. referrer text default NULL,
  1209. search varchar(255) default NULL,
  1210. searchpage int(11) default 0,
  1211. os varchar(15) default NULL,
  1212. browser varchar(50) default NULL,
  1213. language varchar(5) default NULL,
  1214. screen_res varchar(15) default NULL,
  1215. searchengine varchar(25) default NULL,
  1216. spider varchar(50) default NULL,
  1217. feed varchar(50) default NULL,
  1218. username VARCHAR(50) default NULL,
  1219. comment_author VARCHAR(50) default NULL,
  1220. spam VARCHAR(5) default 0,
  1221. UNIQUE KEY id (id),
  1222. KEY idx_wassup (wassup_id(32),timestamp),
  1223. INDEX (os),
  1224. INDEX (browser),
  1225. INDEX (timestamp)
  1226. ) $charset_collate;";
  1227. require_once( ABSPATH.'wp-admin/upgrade-functions.php');
  1228. dbDelta($sql_createtable);
  1229. //#TODO: check for errors or warnings during table creation
  1230. } //end function createTable
  1231. function UpdateTable() {
  1232. global $wpdb, $wassup_options;
  1233. $table_name = $wpdb->prefix . "wassup";
  1234. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  1235. $idx_timestamp = false; //used for upgrade from <= 1.4.9
  1236. $idx_wassup = false; //used for upgrade from <= 1.6
  1237. // Upgrade from version < 1.3.9 - add 'spam' column to wassup table
  1238. if ($wpdb->get_var("SHOW COLUMNS FROM $table_name LIKE 'spam'") == "") {
  1239. $sql_add_spam = "ALTER TABLE {$table_name} ADD COLUMN spam VARCHAR(5) DEFAULT '0'";
  1240. $wpdb->query( $sql_add_spam );
  1241. }
  1242. // Upgrade from version <= 1.4.9 - create an index on 'timestamp'
  1243. //#$idx_cols = $wpdb->get_col("SHOW INDEX FROM $table_name","Column_name"); //doesn't work
  1244. //# look for an index on 'timestamp' and make one if doesn't exist
  1245. $result = mysql_query("SHOW INDEX FROM $table_name");
  1246. if ($result) {
  1247. $row_count = mysql_num_rows($result);
  1248. //# look for an index on 'timestamp'
  1249. if ($row_count > 0) {
  1250. while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
  1251. if ($row["Column_name"] == "timestamp") {
  1252. $idx_timestamp = true;
  1253. } elseif ( $row["Key_name"] == "idx_wassup") {
  1254. $idx_wassup = true;
  1255. }
  1256. }
  1257. //# create an index on 'timestamp'
  1258. if (!$idx_timestamp) {
  1259. $wpdb->query("ALTER TABLE {$table_name} ADD INDEX idx_timestamp (timestamp)");
  1260. }
  1261. } //end if row_count
  1262. mysql_free_result($result);
  1263. } //end if result
  1264. // Upgrade from version <= 1.5.1 - increase size of wassup_id
  1265. $wassup_col = $wpdb->get_results("SHOW COLUMNS FROM $table_name LIKE 'wassup_id'");
  1266. foreach ($wassup_col as $wID) {
  1267. if ($wID->Type != "varchar(80)") {
  1268. $wpdb->query("ALTER TABLE {$table_name} CHANGE wassup_id wassup_id varchar(80) NULL");
  1269. }
  1270. }
  1271. // Upgrade from version <= 1.6
  1272. // - change wassup_id index to combination (wassup_id,timestamp)
  1273. if (!$idx_wassup) {
  1274. $wpdb->query("ALTER TABLE {$table_name} DROP KEY wassup_id");
  1275. $wpdb->query("ALTER TABLE {$table_name} ADD KEY idx_wassup (wassup_id(32),timestamp)");
  1276. }
  1277. // For all upgrades
  1278. // - drop and recreate table "wp_wassup_tmp" and optimize "wp_wassup"
  1279. //$wpdb->query("DROP TABLE IF EXISTS $table_tmp_name"); //incorrectly causes an activation error in Wordpress
  1280. mysql_query("DROP TABLE IF EXISTS $table_tmp_name");
  1281. CreateTable($table_tmp_name);
  1282. $wpdb->query("OPTIMIZE TABLE {$table_name}");
  1283. } //end function UpdateTable
  1284. //Set Wassup_id and cookie (before headers sent)
  1285. function wassupPrepend() {
  1286. $wassup_id = "";
  1287. $session_timeout = 1;
  1288. //### Check if this is an ongoing visit or a new hit...
  1289. //#visitor tracking with "cookie"...
  1290. if (isset($_COOKIE['wassup'])) {
  1291. $wassup_cookie = explode('::',$_COOKIE['wassup']);
  1292. $wassup_id = $wassup_cookie[0];
  1293. if (!empty($wassup_cookie[1])) {
  1294. $wassup_timer = $wassup_cookie[1];
  1295. $session_timeout = ((int)$wassup_timer - (int)time());
  1296. }
  1297. }
  1298. if (empty($wassup_id) || $session_timeout < 1) {
  1299. $ipAddress = "";
  1300. $hostname = "";
  1301. //#### Get the visitor's details from http header...
  1302. if (isset($_SERVER["REMOTE_ADDR"])) {
  1303. if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
  1304. //in case of multiple forwarding
  1305. list($IP) = explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]);
  1306. $proxy = $_SERVER["REMOTE_ADDR"];
  1307. $hostname = @gethostbyaddr($IP);
  1308. if (empty($hostname) || $hostname == "unknown") {
  1309. $hostname = @gethostbyaddr($proxy);
  1310. }
  1311. if (empty($IP) || $IP == "unknown") {
  1312. $IP = $proxy;
  1313. $ipAddress = $_SERVER["REMOTE_ADDR"];
  1314. } else {
  1315. $ipAddress = $proxy.",".$IP;
  1316. }
  1317. }else{
  1318. list($IP) = explode(",",$_SERVER["REMOTE_ADDR"]);
  1319. $hostname = @gethostbyaddr($IP);
  1320. $ipAddress = $_SERVER["REMOTE_ADDR"];
  1321. }
  1322. }
  1323. if (empty($IP)) { $IP = $ipAddress; }
  1324. if (empty($hostname)) { $hostname = "unknown"; }
  1325. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  1326. $current_user = wp_get_current_user();
  1327. $logged_user = $current_user->user_login;
  1328. //# Create a new wassup id for this visit from a
  1329. //# combination of date/hour/min/ip/hostname/useragent/.
  1330. //# It is not unique so that multiple visits from the
  1331. //# same ip/userAgent within a 30 minute-period, can be
  1332. //# tracked, even when session/cookies is disabled.
  1333. $temp_id = sprintf("%-060.60s", date('YmdH').str_replace(array(' ','http://','www.','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','!','@',')','(',), '', intval(date('i')/30).$IP.strrev($logged_user).strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').$hostname.rand());
  1334. //$temp_id = sprintf("%-060.60s", date('YmdH').str_replace(array(' ','http://','www.','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','!','@',')','(',), '', intval(date('i')/30).$IP.strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').$hostname.rand());
  1335. //Work-around for cookie rejection:
  1336. //#assign new wassup id from "temp_id"
  1337. //$wassup_id = $temp_id; //debug
  1338. $wassup_id = md5($temp_id);
  1339. $wassup_timer=((int)time() + 2700); //use 45 minutes timer
  1340. //put the cookie in the oven and set the timer...
  1341. //#this must be done before headers sent
  1342. $cookieurl = parse_url(get_option('home'));
  1343. $cookiedomain = preg_replace('/^www\./','',$cookieurl['host']);
  1344. $cookiepath = $cookieurl['path'];
  1345. $expire = time()+3000; //expire based on unix time, not on Wordpress time
  1346. $cookievalue = implode('::',array("$wassup_id", "$wassup_timer"));
  1347. setcookie("wassup", "$cookievalue", $expire, $cookiepath, $cookiedomain);
  1348. }
  1349. } //end function wassupPrepend
  1350. //Track visitors and save record in wassup table, after page is displayed
  1351. function wassupAppend() {
  1352. global $wpdb, $wpurl, $wassup_options; //removed unused globals
  1353. $siteurl = get_bloginfo('siteurl');
  1354. $table_name = $wpdb->prefix . "wassup";
  1355. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  1356. $wassup_settings = get_option('wassup_settings');
  1357. $current_user = wp_get_current_user();
  1358. $logged_user = $current_user->user_login;
  1359. $urlRequested = clean_url($_SERVER['REQUEST_URI']);
  1360. if (empty($logged_user) && $wassup_setting->wassup_hack == "1") {
  1361. $hackercheck = true;
  1362. } else {
  1363. $hackercheck = false;
  1364. }
  1365. if ((!is_admin() && stristr($urlRequested,"/wp-admin/") === FALSE) || $hackercheck) { //exclude valid wordpress admin page visits
  1366. //#### Get the visitor's details from http header...
  1367. if (isset($_SERVER["REMOTE_ADDR"])) {
  1368. if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
  1369. //in case of multiple forwarding
  1370. list($IP) = explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]);
  1371. $proxy = $_SERVER["REMOTE_ADDR"];
  1372. $hostname = @gethostbyaddr($IP);
  1373. if (empty($hostname) || $hostname == "unknown") {
  1374. $hostname = @gethostbyaddr($proxy);
  1375. }
  1376. if (empty($IP) || $IP == "unknown") {
  1377. $IP = $proxy;
  1378. $ipAddress = $_SERVER["REMOTE_ADDR"];
  1379. } else {
  1380. $ipAddress = $proxy.",".$IP;
  1381. }
  1382. }else{
  1383. list($IP) = explode(",",$_SERVER["REMOTE_ADDR"]);
  1384. $hostname = @gethostbyaddr($IP);
  1385. $ipAddress = $_SERVER["REMOTE_ADDR"];
  1386. }
  1387. }
  1388. if (empty($IP)) { $IP = $ipAddress; }
  1389. if (empty($hostname)) { $hostname = "unknown"; }
  1390. // Get the visitor's resolution, TODO
  1391. /*
  1392. if(isset($HTTP_COOKIE_VARS["users_resolution"])) {
  1393. $screen_res = $HTTP_COOKIE_VARS["users_resolution"];
  1394. } else { //means cookie is not found set it using Javascript
  1395. ?>
  1396. <script language="javascript">
  1397. <!--
  1398. writeCookie();
  1399. function writeCookie()
  1400. {
  1401. var today = new Date();
  1402. var the_date = new Date("December 31, 2023");
  1403. var the_cookie_date = the_date.toGMTString();
  1404. var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
  1405. var the_cookie = the_cookie + ";expires=" + the_cookie_date;
  1406. document.cookie=the_cookie
  1407. location = '<?php echo $_SERVER['REQUEST_URI']; ?>';
  1408. }
  1409. //-->
  1410. </script>
  1411. <?php
  1412. $screen_res = $HTTP_COOKIE_VARS["users_resolution"];
  1413. }
  1414. */
  1415. $referrer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
  1416. $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
  1417. $language = (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? attribute_escape($_SERVER['HTTP_ACCEPT_LANGUAGE']) : '');
  1418. //$current_user = wp_get_current_user(); //moved up
  1419. //$logged_user = $current_user->user_login; //moved up
  1420. $comment_user = (isset($_COOKIE['comment_author_'.COOKIEHASH]) ? utf8_encode($_COOKIE['comment_author_'.COOKIEHASH]) : '');
  1421. $timestamp = wassup_get_time(); //Add a timestamp to visit...
  1422. $flag_exclude_url = 0;
  1423. //#####Start recording visit....
  1424. //## wassup is activated and IP not on exclusion list...
  1425. if ($wassup_options->wassup_active == 1) { //(moved)
  1426. if (empty($wassup_options->wassup_exclude) ||
  1427. strstr($wassup_options->wassup_exclude,$ipAddress) == FALSE) {
  1428. //## check if url requested is not on exclusion list...
  1429. if (!empty($wassup_options->wassup_exclude_url)) {
  1430. $exclude_url_list = explode(",", $wassup_options->wassup_exclude_url);
  1431. foreach ($exclude_url_list as $exclude_url) {
  1432. if (stristr($urlRequested, trim($exclude_url)) !== FALSE) {
  1433. $flag_exclude_url = 1;
  1434. }
  1435. }
  1436. }
  1437. if ($flag_exclude_url != 1) {
  1438. //### Exclude requests for themes, plugins, and favicon from recordings
  1439. if (stristr($urlRequested,"favicon.ico") === FALSE) { //moved
  1440. if (stristr($urlRequested,"/wp-content/plugins") === FALSE || stristr($urlRequested,"forum") !== FALSE || $hackercheck) { //moved and modified to allow forum requests
  1441. if (stristr($urlRequested,"/wp-content/themes") === FALSE || stristr($urlRequested,"comment") !== FALSE) { //moved and modified to allow comment requests
  1442. //# More recording exclusion controls
  1443. if ($wassup_options->wassup_loggedin == 1 || !is_user_logged_in()) {
  1444. if ($wassup_options->wassup_attack == 1 || stristr($userAgent,"libwww-perl") === FALSE ) {
  1445. if (!is_404() || $hackercheck) { //don't record 404 pages...
  1446. //##### Extract useful visit information from http header..
  1447. $browser = "";
  1448. $os = "";
  1449. list($browser,$os) = wGetBrowser($userAgent);
  1450. //#===================================================
  1451. //###Start visitor tracking...
  1452. //Work-around for cookie rejection:
  1453. //# Create a temporary id for this visit from a combination of
  1454. //# date/hour/min/ip/hostname/useragent/os/browser.
  1455. //# It is not unique so that multiple visits from the same
  1456. //# ip/userAgent within a 30 minute-period, can be tracked as
  1457. //# such, even when session/cookies is disabled.
  1458. //# An md5 encoded version of temp_id is saved as "wassup_id".
  1459. $temp_id = sprintf("%-060.60s", date('YmdH').str_replace(array(' ','http://','www.','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','!','@',')','(',), '', intval(date('i')/30).$IP.strrev($logged_user).strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').$hostname.rand());
  1460. $wassup_id = "";
  1461. //Read the cookie for wassup_id
  1462. if (isset($_COOKIE['wassup'])) {
  1463. $wassup_cookie = explode('::',$_COOKIE['wassup']);
  1464. $wassup_id = $wassup_cookie[0];
  1465. }
  1466. /*
  1467. $session_timeout = 1;
  1468. //### Check if this is an ongoing visit or a new hit...
  1469. //#visitor tracking with "session"...
  1470. //# Set savepath directory before session_start()
  1471. $sessionpath = $wassup_options->wassup_savepath;
  1472. if (empty($sessionpath)) { $sessionpath = getSessionpath(); }
  1473. if ($sessionpath != "" && $wassup_options->isWritableFolder($sessionpath)) {
  1474. session_save_path($sessionpath);
  1475. }
  1476. session_start(); //required to use/update $_SESSION
  1477. //#confirm that session is started...
  1478. if (isset($_SESSION)) {
  1479. // Prevent Session Fixation attack (http://shiflett.org/articles/session-fixation)
  1480. if (!isset($_SESSION['initiated'])) {
  1481. session_regenerate_id();
  1482. $_SESSION['initiated'] = true;
  1483. }
  1484. //Get session variables...
  1485. if (isset($_SESSION['wassup_id'])) {
  1486. $wassup_id = $_SESSION['wassup_id'];
  1487. $session_timeout = ((int)$_SESSION['wassup_timer'] - (int)time());
  1488. if (isset($_SESSION['spamresult'])) {
  1489. $spamresult = $_SESSION['spamresult'];
  1490. }
  1491. if ( $_SESSION['urlrequest'] == $urlRequested && (($timestamp - (int)$_SESSION['visittime']) < 5)) {
  1492. $dup_urlrequest=1;
  1493. }
  1494. }
  1495. //#reset wassup_id for new visitors or when timer is 0...
  1496. if (empty($wassup_id) or $session_timeout < 1) {
  1497. //# don't "destroy" old session in case it is
  1498. //# in use elsewhere in wordpress ??..
  1499. //if (!empty($wassup_id)) {
  1500. // session_destroy();
  1501. // session_start();
  1502. //}
  1503. $_SESSION['wassup_id'] = md5($temp_id);
  1504. //$_SESSION['wassup_id'] = md5(uniqid(rand(), true));
  1505. //#timeout session after 24 minutes
  1506. $_SESSION['wassup_timer'] = ((int)time() + 1440);
  1507. $dup_urlrequest=0;
  1508. }
  1509. $wassup_id = $_SESSION['wassup_id'];
  1510. if ($dup_urlrequest == 0) { //for dup checks
  1511. $_SESSION['visittime'] = $timestamp; //for dup checks
  1512. $_SESSION['urlrequest'] = $urlRequested;
  1513. }
  1514. //#SID is empty when session uses cookies...
  1515. //if (defined('SID') && !empty(SID)) {
  1516. // //#manually add SID to url_rewriter when trans-sid
  1517. // //# is disabled (how to test for this???)...
  1518. // output_add_rewrite_var(session_name(), htmlspecialchars(session_id()));
  1519. //}
  1520. @session_write_close();
  1521. } */
  1522. //### Check if this is an ongoing visit or a new hit...
  1523. /* //#visitor tracking with "cookie"...
  1524. if (isset($_COOKIE['wassup'])) {
  1525. $wassup_cookie = unserialize($_COOKIE['wassup']);
  1526. //$wassup_id = $wassup_cookie['wassup_id'];
  1527. $wassup_timer = $wassup_cookie['timer'];
  1528. if (isset($wassup_cookie['spamresult'])) {
  1529. $spamresult = $wassup_cookie['spamresult'];
  1530. }
  1531. $session_timeout = ((int)$wassup_timer - (int)time());
  1532. if ( $session_timeout < 1) {
  1533. //#reset cookie values when timer is 0
  1534. unset($wassup_cookie);
  1535. $wassup_id = ""; //a new id will be assigned
  1536. }
  1537. } */
  1538. //Work-around for cookie rejection:
  1539. //#assign new wassup id from "temp_id" and include it in dup check
  1540. if (empty($wassup_id)) {
  1541. $wassup_id = md5($temp_id);
  1542. //$wassup_id = $temp_id; //debug
  1543. }
  1544. //### Check for duplicates.
  1545. $dup_urlrequest=0;
  1546. // Dup: Hit recorded, ==wassup_id, last visit, <90 secs old, ==URL
  1547. $dups = $wpdb->get_results("SELECT wassup_id, urlrequested, spam, `timestamp` AS hit_timestamp FROM ".$table_tmp_name." WHERE wassup_id='".$wassup_id."' AND `timestamp` >".($timestamp-90)." GROUP BY wassup_id ORDER BY hit_timestamp DESC");
  1548. if (!empty($dups)) {
  1549. $i=0;
  1550. foreach ($dups as $dup) { //check first record only
  1551. if ($i == 0) {
  1552. if ($dup->urlrequested == $urlRequested) {
  1553. $dup_urlrequest=1;
  1554. }
  1555. //retrieve spam check results
  1556. $spamresult = $dup->spam;
  1557. }
  1558. $i=$i+1;
  1559. }
  1560. }
  1561. //
  1562. //#End visitor tracking with cookie/session
  1563. //#===================================================
  1564. //### Exclude duplicates...
  1565. if ($dup_urlrequest == 0) {
  1566. //##### Extract useful visit information from http header..
  1567. if (empty($browser) || strstr($browser,"N/A") || is_feed()) {
  1568. list($spider,$feed) = wGetSpider($userAgent,$hostname,$browser);
  1569. }
  1570. //#I prefer to see os/browser info. for spiders/bots.
  1571. //spider exclusion control
  1572. //# Spider exclusion control moved to avoid unneeded tests
  1573. if ($wassup_options->wassup_spider == 1 || $spider == '') {
  1574. //
  1575. //#get language/locale info from hostname or referrer data
  1576. $language = wGetLocale($language,$hostname,$referrer);
  1577. //# get search string details from referrer data
  1578. list($searchengine,$search_phrase)=explode("|",wGetSE($referrer));
  1579. $se=seReferer($referrer);
  1580. if ($search_phrase != '') {
  1581. if (stristr($searchengine,"images")) {
  1582. // ATTENTION Position retrieved by referer in Google Images is
  1583. // the Position number of image NOT the number of items in the page like web search
  1584. $searchpage=$se['Pos'];
  1585. $searchcountry = explode(".", $se['Se']);
  1586. } else {
  1587. $searchpage=($se['Pos']/10+1);
  1588. $searchcountry = explode(".", $se['Se']);
  1589. }
  1590. if ($searchcountry[3] != '' ) {
  1591. $searchengine .= " ".strtoupper($searchcountry[3]);
  1592. } elseif ($searchcountry[2] != '') {
  1593. $searchengine .= " ".strtoupper($searchcountry[2]);
  1594. }
  1595. }
  1596. if ($searchpage == "") {
  1597. $searchpage = 0;
  1598. }
  1599. //### Check for spam...
  1600. $spam = 0; //a spam default of 0 is required to add record...
  1601. if ( $wassup_options->wassup_spamcheck == 1 ) {
  1602. if ( $wassup_options->wassup_refspam == 1 && !empty($referrer) ) {
  1603. //#first check for referrer spam (faster, if positive)
  1604. //#...but skip when referrer is own blog ($siteurl/$wpurl)
  1605. if (stristr($referrer,$wpurl) === FALSE && stristr($referrer,$siteurl) === FALSE) {
  1606. // Do a control if it is Referrer Spam
  1607. if (wGetSpamRef($referrer) == 1) {
  1608. $spam = 2;
  1609. $spamresult = $spam;
  1610. }
  1611. }
  1612. }
  1613. if ( $wassup_options->wassup_spam == 1 && $spam == 0 ) {
  1614. //# some valid spiders to exclude from spam checking
  1615. $goodbot = false;
  1616. if ($hostname!="" && !empty($spider)) {
  1617. if (preg_match('/^(googlebot|msnbot|yahoo\!\ slurp|technorati)/i',$spider)>0 && preg_match('/\.(googlebot|live|msn|yahoo|technorati)\.(com|net)$/i',$hostname)>0){
  1618. $goodbot = true;
  1619. }
  1620. }
  1621. //# No duplicate spam testing in same session unless there
  1622. //# is a forum page request or comment...
  1623. if (isset($spamresult) && stristr($urlRequested,"comment") === FALSE && stristr($urlRequested,"forum") === FALSE && empty($comment_user) && empty($_POST['comment'])) {
  1624. $spam = $spamresult;
  1625. //# No spam check on known bots (google, yahoo,...) unless
  1626. //# there is a comment or forum page request...
  1627. } elseif (empty($spider) || !$goodbot || stristr($urlRequested,"comment") !== FALSE || stristr($urlRequested,"forum") !== FALSE || !empty($comment_user) ) {
  1628. // Try to search for previous spammer detected by akismet with same IP
  1629. if (!empty($ipAddress)) {
  1630. $checkauthor = New CheckComment;
  1631. $checkauthor->tablePrefix = $wpdb->prefix;
  1632. $spammerIP = $checkauthor->isSpammer($ipAddress);
  1633. if ( $spammerIP > 0) {
  1634. $spam = 1;
  1635. $spamresult = $spam;
  1636. }
  1637. }
  1638. // search for spammer in badhosts file...
  1639. if ( $spam == 0) {
  1640. if (!empty($hostname) && $hostname != "unknown") {
  1641. if (wGetSpamRef($hostname) == 1) {
  1642. $spam = 1;
  1643. $spamresult = $spam;
  1644. }
  1645. }
  1646. }
  1647. //#lastly check for comment spammers using Akismet API
  1648. //# Note: this causes "header already sent" errors in some Wordpress configurations
  1649. if ($spam == 0) {
  1650. $akismet_key = get_option('wordpress_api_key');
  1651. $akismet_class = dirname(__FILE__).'/lib/akismet.class.php';
  1652. if (file_exists($akismet_class) && !empty($akismet_key)) {
  1653. $comment_user_email = utf8_encode($_COOKIE['comment_author_email_'.COOKIEHASH]);
  1654. $comment_user_url = utf8_encode($_COOKIE['comment_author_url_'.COOKIEHASH]);
  1655. include($akismet_class);
  1656. // load array with comment data
  1657. $Acomment = array(
  1658. 'author' => $comment_user,
  1659. 'email' => $comment_user_email,
  1660. 'website' => $comment_user_url,
  1661. 'body' => $_POST["comment"],
  1662. 'permalink' => $urlRequested,
  1663. 'user_ip' => $ipAddress,
  1664. 'user_agent' => $userAgent
  1665. );
  1666. // instantiate an instance of the class
  1667. $akismet = new Akismet($wpurl, $akismet_key, $Acomment);
  1668. // Check if it's spam
  1669. if ( $akismet->isSpam() ) {
  1670. $spam = 1;
  1671. $spamresult = $spam;
  1672. }
  1673. // test for errors
  1674. if($akismet->errorsExist()) {
  1675. //#error means don't save result in cookie
  1676. unset($spamresult);
  1677. }
  1678. } //end if file_exists(akismet_class)
  1679. } //end if $spam == 0
  1680. } //end else $spamresult
  1681. } //end if wassup_spam == 1
  1682. } //end if wassup_spamcheck == 1
  1683. //identify hacker/bad activity attempts and assign spam=3
  1684. if ($spam == 0 && $hackercheck) {
  1685. if (is_admin() || stristr($urlRequested,"/wp-content/plugins")!==FALSE || stristr($urlRequested,"/wp-admin/")!== FALSE) {
  1686. $spam=3;
  1687. }
  1688. }
  1689. // Personally used to debug
  1690. if ($current_user->user_email == "michele@befree.it") {
  1691. }
  1692. //## Final exclusion control is spam...
  1693. if ($spam == 0 OR ($wassup_options->wassup_spam == 1 AND $spam == 1) OR ($wassup_options->wassup_refspam == 1 AND $spam == 2)) {
  1694. /* // #save spam results in session...
  1695. if (isset($spamresult)) {
  1696. @session_start(); //required to access $_SESSION
  1697. $_SESSION['spamresult'] = $spamresult;
  1698. @session_write_close();
  1699. }
  1700. */
  1701. // #Record visit in wassup tables...
  1702. // Insert the record into the db
  1703. insert_into_wp($table_name, $wassup_id, $timestamp, $ipAddress, $hostname, $urlRequested, $userAgent, $referrer, $search_phrase, $searchpage, $os, $browser, $language, $screen_res, $searchengine, $spider, $feed, $logged_user, $comment_user, $spam);
  1704. // Insert the record into the wassup_tmp table too
  1705. insert_into_wp($table_tmp_name, $wassup_id, $timestamp, $ipAddress, $hostname, $urlRequested, $userAgent, $referrer, $search_phrase, $searchpage, $os, $browser, $language, $screen_res, $searchengine, $spider, $feed, $logged_user, $comment_user, $spam);
  1706. // Delete records older then 3 minutes
  1707. $wpdb->query("DELETE FROM $table_tmp_name WHERE `timestamp`<'".strtotime("-3 minutes", $timestamp)."'");
  1708. } //end if $spam == 0
  1709. } //end if wassup_spider
  1710. } //end if dup_urlrequest == 0
  1711. } //end if !is_404
  1712. } //end if wassup_attack
  1713. } //end if wassup_loggedin
  1714. } //end if !themes
  1715. } //end if !plugins
  1716. } //end if !favicon
  1717. //### Purge old records from wassup table
  1718. //automatic database cleanup of old records...
  1719. if ($wassup_options->delete_auto != "") {
  1720. // do purge every few visits to keep wassup fast...
  1721. if ( ((int)$timestamp)%7 == 0 ) {
  1722. //use visit timestamp instead of current time for
  1723. // delete parameter
  1724. //$to_date = wassup_get_time();
  1725. $from_date = strtotime($wassup_options->delete_auto, $timestamp);
  1726. //#check before doing delete as it could lock the table...
  1727. if ((int)$wpdb->get_var("SELECT COUNT(id) FROM $table_name WHERE `timestamp`<'$from_date'") > 0) {
  1728. $wpdb->query("DELETE FROM $table_name WHERE `timestamp`<'$from_date'");
  1729. }
  1730. // Optimize table once a day
  1731. if ($timestamp > strtotime("24 hours", $wassup_options->wassup_optimize)) {
  1732. $wpdb->query("OPTIMIZE TABLE $table_name");
  1733. $wassup_options->wassup_optimize = wassup_get_time();
  1734. $wassup_options->saveSettings();
  1735. }
  1736. }
  1737. } //end if delete_auto
  1738. } //end if wassup_exclude
  1739. } //end if wassup_exclude_url
  1740. } //end if wassup_active
  1741. } //end if !is_admin
  1742. //### Notify admin if alert is set and wassup table > alert
  1743. if ($wassup_options->wassup_remind_flag == 1) {
  1744. // check database size every few visits to keep wassup fast...
  1745. if ( (time())%7 == 0 ) {
  1746. $table_status = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table_name'");
  1747. foreach ($table_status as $fstatus) {
  1748. $data_lenght = $fstatus->Data_length;
  1749. }
  1750. $tusage = ($data_lenght/1024/1024);
  1751. if ($tusage > $wassup_options->wassup_remind_mb) {
  1752. $recipient = get_bloginfo('admin_email');
  1753. $sender = get_bloginfo('name').' <wassup_noreply@'.parse_url(get_bloginfo('siteurl'),PHP_URL_HOST).'>';
  1754. $subject = "[ALERT]".__('WassUp Plugin table has reached maximum size!','wassup');
  1755. $message = __('Hi','wassup').",\n".__('you have received this email because your WassUp Database table at your Wordpress blog','wassup')." (".get_bloginfo('url').") ".__('has reached the maximum value you set in the options menu','wassup')." (".$wassup_options->wassup_remind_mb." Mb).\n\n";
  1756. $message .= __('This is only a reminder, please take the actions you want in the WassUp options menu','wassup')." (".get_bloginfo('url')."/wp-admin/admin.php?page=wassup-options).\n\n".__('This alert now will be removed and you will be able to set a new one','wassup').".\n\n";
  1757. $message .= __('Thank you for using WassUp plugin. Check if there is a new version available here:','wassup')." http://wordpress.org/extend/plugins/wassup/\n\n".__('Have a nice day!','wassup')."\n";
  1758. mail($recipient, $subject, $message, "From: $sender");
  1759. $wassup_options->wassup_remind_flag = 2;
  1760. $wassup_options->saveSettings();
  1761. }
  1762. }
  1763. } //if wassup_remind_flag
  1764. //} //if SECRET_KEY
  1765. } //end function wassupAppend()
  1766. // Function to insert the item into the db
  1767. function insert_into_wp($table_name, $wassup_id, $timestamp, $ipAddress, $hostname, $urlRequested, $userAgent, $referrer, $search_phrase, $searchpage, $os, $browser, $language, $screen_res, $searchengine, $spider, $feed, $logged_user, $comment_user, $spam) {
  1768. global $wpdb;
  1769. if (!empty($table_name) && !empty($wassup_id) && !empty($timestamp)) {
  1770. //double-check that table exists before doing insert to avoid errors showing up on page
  1771. if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
  1772. if (method_exists($wpdb,'prepare')) {
  1773. $insert = $wpdb->query( $wpdb->prepare("INSERT INTO $table_name (wassup_id, `timestamp`, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam)
  1774. VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )",
  1775. attribute_escape($wassup_id),
  1776. attribute_escape($timestamp),
  1777. attribute_escape($ipAddress),
  1778. attribute_escape($hostname),
  1779. attribute_escape($urlRequested),
  1780. attribute_escape($userAgent),
  1781. attribute_escape($referrer),
  1782. attribute_escape($search_phrase),
  1783. attribute_escape($searchpage),
  1784. attribute_escape($os),
  1785. attribute_escape($browser),
  1786. attribute_escape($language),
  1787. attribute_escape($screen_res),
  1788. attribute_escape($searchengine),
  1789. attribute_escape($spider),
  1790. attribute_escape($feed),
  1791. attribute_escape($logged_user),
  1792. attribute_escape($comment_user),
  1793. attribute_escape($spam)
  1794. ));
  1795. } else {
  1796. $insert = $wpdb->query("INSERT INTO " . $table_name .
  1797. " (wassup_id, `timestamp`, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam) " .
  1798. "VALUES (
  1799. '".attribute_escape($wassup_id)."',
  1800. '".attribute_escape($timestamp)."',
  1801. '".attribute_escape($ipAddress)."',
  1802. '".attribute_escape($hostname)."',
  1803. '".attribute_escape($urlRequested)."',
  1804. '".attribute_escape($userAgent)."',
  1805. '".attribute_escape($referrer)."',
  1806. '".attribute_escape($search_phrase)."',
  1807. '".attribute_escape($searchpage)."',
  1808. '".attribute_escape($os)."',
  1809. '".attribute_escape($browser)."',
  1810. '".attribute_escape($language)."',
  1811. '".attribute_escape($screen_res)."',
  1812. '".attribute_escape($searchengine)."',
  1813. '".attribute_escape($spider)."',
  1814. '".attribute_escape($feed)."',
  1815. '".attribute_escape($logged_user)."',
  1816. '".attribute_escape($comment_user)."',
  1817. '".attribute_escape($spam)."'
  1818. )");
  1819. } //end else method_exists(prepare)
  1820. } //end if table exists
  1821. } //end if !empty($table_name)
  1822. } //end function insert_into_wp
  1823. // This is the function to print out a chart's preview in the dashboard
  1824. function wassupDashChart() {
  1825. global $wpdb, $wassup_options;
  1826. if ($wassup_options->wassup_dashboard_chart == 1) {
  1827. $table_name = $wpdb->prefix . "wassup";
  1828. $to_date = wassup_get_time();
  1829. $Chart = New MainItems;
  1830. $Chart->tableName = $table_name;
  1831. $Chart->to_date = $to_date;
  1832. echo '<h3>WassUp Stats <cite><a href="admin.php?page=wassup">More &raquo;</a></cite></h3>';
  1833. echo $Chart->TheChart(1, "400", "125", "", $wassup_options->wassup_chart_type, "bg,s,00000000", "dashboard", "left");
  1834. }
  1835. } //end function wassupDashChart
  1836. //#Return current PHP session.save_path value (pathname portion)
  1837. function getSessionpath() {
  1838. $sessionpath = session_save_path();
  1839. if (strpos($sessionpath, ";") !== FALSE) {
  1840. $sessionpath = substr($sessionpath, strpos($sessionpath, ";")+1);
  1841. }
  1842. $sessionpath = rtrim($sessionpath,"/");
  1843. return $sessionpath;
  1844. }
  1845. function wGetQueryPairs($url){
  1846. $parsed_url = parse_url($url);
  1847. $tab=parse_url($url);
  1848. $host = $tab['host'];
  1849. if(key_exists("query",$tab)){
  1850. $query=$tab["query"];
  1851. return explode("&",$query);
  1852. } else {
  1853. return null;
  1854. }
  1855. }
  1856. function array_search_extended($file,$str_search) {
  1857. foreach($file as $key => $line) {
  1858. if (strpos($line, $str_search)!== FALSE) {
  1859. return $key;
  1860. }
  1861. }
  1862. return false;
  1863. }
  1864. function seReferer($ref = false){
  1865. $SeReferer = (is_string($ref) ? $ref : mb_convert_encoding(strip_tags($_SERVER['HTTP_REFERER']), "HTML-ENTITIES", "auto"));
  1866. if( //Check against Google, Yahoo, MSN, Ask and others
  1867. preg_match(
  1868. "/[&\?](prev|q|p|w|searchfor|as_q|as_epq|s|query)=([^&]+)/i",
  1869. $SeReferer,$pcs)
  1870. ){
  1871. if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
  1872. $SeDomain = trim(strtolower($SeDomain[1]));
  1873. $SeQuery = $pcs[2];
  1874. if(preg_match("/[&\?](start|b|first|stq)=([0-9]*)/i",$SeReferer,$pcs)){
  1875. $SePos = (int)trim($pcs[2]);
  1876. }
  1877. }
  1878. }
  1879. if(!isset($SeQuery)){
  1880. if( //Check against DogPile
  1881. preg_match(
  1882. "/\/search\/web\/([^\/]+)\//i",
  1883. $SeReferer,$pcs)
  1884. ){
  1885. if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
  1886. $SeDomain = trim(strtolower($SeDomain[1]));
  1887. $SeQuery = $pcs[1];
  1888. }
  1889. }
  1890. }
  1891. // We Do Not have a query
  1892. if(!isset($SeQuery)){ return false; }
  1893. $OldQ=$SeQuery;
  1894. $SeQuery=urldecode($SeQuery);
  1895. // The Multiple URLDecode Trick to fix DogPile %XXXX Encodes
  1896. while($SeQuery != $OldQ){
  1897. $OldQ=$SeQuery; $SeQuery=urldecode($SeQuery);
  1898. }
  1899. //-- We have a query
  1900. return array(
  1901. "Se"=>$SeDomain,
  1902. "Query"=>$SeQuery,
  1903. "Pos"=>(int)$SePos,
  1904. "Referer"=>$SeReferer
  1905. );
  1906. }
  1907. function wGetSE($referrer = null){
  1908. $key = null;
  1909. $lines = array("Alice|search.alice.it|qs|", "Google|www.google.|as_q|", "Google|www.google.|q|", "Google Groups|groups.google.|q|",
  1910. "Google Images|images.google.|prev|", "Yahoo|search.yahoo.com|p|", "Google Blog|blogsearch.google.|as_q|", "Google Blog|blogsearch.google.|q|",
  1911. "Virgilio|search.virgilio.it|qs|","Arianna|arianna.libero.it|query|","Altavista|.altavista.com|q|","Kataweb|kataweb.it|q|",
  1912. "Il Trovatore|categorie.iltrovatore.it|query|","Il Trovatore|search.iltrovatore.it|q|","2020Search|2020search.c|us|st|pn|1|",
  1913. "abcsearch.com|abcsearch.com|terms|","100Links|100links.supereva.it|q|","Alexa|alexa.com|q|","Alltheweb|alltheweb.com|q|",
  1914. "Aol|.aol.|query|","Aol|aolrecherches.aol.fr|query|","Ask|ask.com|ask|","Ask|ask.com|q|","DMOZ|search.dmoz.org|search|",
  1915. "Dogpile|dogpile.com|q|","Excite|excite.|q|","Godago|.godago.com|keywords|","HotBot|hotbot.*|query|","ixquick|ixquick.com|query|",
  1916. "Lycos|cerca.lycos.it|query|","Lycos|lycos.|q|","Windows Live|search.live.com|q|mkt|","My Search|mysearch.com|searchfor|",
  1917. "My Way|mysearch.myway.com|searchfor|","Metacrawler|metacrawler.|q|","Netscape Search|search.netscape.com|query|","MSN|msn.|q|",
  1918. "Overture|overture.com|Keywords|","Supereva|supereva.it|q|","Teoma|teoma.com|q|","Tiscali|search-dyn.tiscali.|key|","Voil|voila.fr|kw|",
  1919. "Web|web.de|su|","Clarence|search.clarence.com|q|","Gazzetta|search.gazzetta.it|q|","PagineGialle|paginegialle.it|qs|",
  1920. "Jumpy|servizi.mediaset.it|searchWord|","ItaliaPuntoNet|italiapuntonet.net|search|","StartNow|search.startnow.|q|","Search|search.it|srctxt|",
  1921. "Search|search.com|q|", "Good Search|goodsearch.com|Keywords|", "ABC Sok|verden.abcsok.no|q|", "Kvasir|kvasir.no|searchExpr|",
  1922. "Start.no|start.no|q|", "bluewin.ch|bluewin.ch|query|", "Google Translate|translate.google.|u|");
  1923. foreach($lines as $line_num => $se) {
  1924. list($nome,$url,$key,$lang)=explode("|",$se);
  1925. if(@strpos($referrer,$url)===FALSE) continue;
  1926. // found it!
  1927. // The SE is Google Images
  1928. if ($nome == "Google Images") {
  1929. $variables = wGetQueryPairs($referrer);
  1930. $rightkey = array_search_extended($variables, "images");
  1931. $variables = eregi_replace("prev=/images\?q=", "", urldecode($variables[$rightkey]));
  1932. $variables = explode("&",$variables);
  1933. return ($nome."|".urldecode($variables[0]));
  1934. } else {
  1935. $variables = wGetQueryPairs($referrer);
  1936. $i = count($variables);
  1937. while($i--){
  1938. $tab=explode("=",$variables[$i]);
  1939. if($tab[0] == $key){return ($nome."|".urldecode($tab[1]));}
  1940. }
  1941. }
  1942. }
  1943. return null;
  1944. }
  1945. //extract browser and platform info from a user agent string and
  1946. // return the values in an array: 0->browser 1->os. -Helene D. 6/7/08.
  1947. function wGetBrowser($agent="") {
  1948. if (empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; }
  1949. $browsercap = array();
  1950. $browscapbrowser = "";
  1951. $browser = "";
  1952. $os = "";
  1953. //check PHP browscap data for browser and platform, when available
  1954. if (ini_get("browscap") != "" ) {
  1955. $browsercap = get_browser($agent,true);
  1956. if (!empty($browsercap['platform'])) {
  1957. if (stristr($browsercap['platform'],"unknown") === false) {
  1958. $os = $browsercap['platform'];
  1959. if (!empty($browsercap['browser'])) {
  1960. $browser = $browsercap['browser'];
  1961. } else {
  1962. $browser = $browsercap['parent'];
  1963. }
  1964. if (!empty($browsercap['version'])) {
  1965. $browser = $browser." ".$browsercap['version'];
  1966. }
  1967. } }
  1968. //reject generic browscap browsers (ex: mozilla, default)
  1969. if (preg_match('/^(mozilla|default|unknown)/i',$browser) > 0) {
  1970. $browscapbrowser = "$browser"; //save just in case
  1971. $browser = "";
  1972. }
  1973. }
  1974. $os = trim($os);
  1975. $browser = trim($browser);
  1976. //use Detector class when browscap is missing or browser is unknown
  1977. if ( $os == "" || $browser == "") {
  1978. $dip = &new Detector("", $agent);
  1979. $browser = trim($dip->browser." ".$dip->browser_version);
  1980. $os = trim($dip->os." ".$dip->os_version);
  1981. //use saved browscap data, if Detector had no results
  1982. if (!empty($browscapbrowser) && ($browser == "" || $browser == "N/A")) {
  1983. if ($os != "" && $os != "N/A") {
  1984. $browser = $browscapbrowser;
  1985. }
  1986. }
  1987. }
  1988. return array($browser,$os);
  1989. } //end function wGetBrowser
  1990. //extract spider and feed info from a user agent string and
  1991. // return the values in an array: 0->spider 1->feed
  1992. function wGetSpider($agent="",$hostname="", $browser=""){
  1993. if (empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; }
  1994. $ua = $agent;
  1995. $crawler = "";
  1996. $feed = "";
  1997. $os = "";
  1998. //check browscap data for crawler info., when available
  1999. if (ini_get("browscap") != "" ) {
  2000. $browsercap = get_browser($agent,true);
  2001. //if no platform(os), assume crawler...
  2002. if (!empty($browsercap['platform'])) {
  2003. if ( $browsercap['platform'] != "unknown") {
  2004. $os = $browsercap['platform'];
  2005. }
  2006. }
  2007. if (!empty($browsercap['crawler']) || !empty($browsercap['stripper']) || $os == "") {
  2008. if (!empty($browsercap['browser'])) {
  2009. $crawler = $browsercap['browser'];
  2010. } else {
  2011. $crawler = $browsercap['parent'];
  2012. }
  2013. if (!empty($browsercap['version'])) {
  2014. $crawler = $crawler." ".$browsercap['version'];
  2015. }
  2016. }
  2017. //reject unknown browscap crawlers (ex: default)
  2018. if (preg_match('/^(default|unknown)/i',$crawler) > 0) {
  2019. $crawler = "";
  2020. }
  2021. }
  2022. //get crawler info. from a known list
  2023. $crawler = trim($crawler);
  2024. $agent=str_replace(" ","",$agent);
  2025. if (empty($crawler)) {
  2026. $key = null;
  2027. //# query list to identify some feedreaders and bots that don't show their name first in UA string
  2028. //# format: "Bot Name"|"UserAgent keyword" (no spaces)|(F=feedreader or R=robot)
  2029. $lines = array( "AboutUsBot|AboutUsBot/|R|",
  2030. "Aggrevator|Aggrevator/0.|F|",
  2031. "AlestiFeedBot|AlestiFeedBot||",
  2032. "Alexa|ia_archiver|R|", "AltaVista|Scooter-|R|",
  2033. "AltaVista|Scooter/|R|", "AltaVista|Scooter_|R|",
  2034. "AMZNKAssocBot|AMZNKAssocBot/|R|",
  2035. "AppleSyndication|AppleSyndication/|F|",
  2036. "Apple-PubSub|Apple-PubSub/|F|",
  2037. "Ask.com/Teoma|AskJeeves/Teoma)|R|",
  2038. "Ask Jeeves/Teoma|ask.com|R|",
  2039. "AskJeeves|AskJeeves|R|",
  2040. "BlogBot|BlogBot/|F|", "Bloglines|Bloglines/|F|",
  2041. "Blogslive|Blogslive|F|",
  2042. "BlogsNowBot|BlogsNowBot|F|",
  2043. "BlogPulseLive|BlogPulseLive|F|",
  2044. "IceRocket BlogSearch|BlogSearch/|F|",
  2045. "Charlotte|Charlotte/|R|",
  2046. "Xyleme|cosmos/0.|R|", "cURL|curl/|R|",
  2047. "Die|die-kraehe.de|R|",
  2048. "Diggit! Robot|Digger/|R|",
  2049. "disco/Nutch|disco/Nutch|R|",
  2050. "Emacs-w3|Emacs-w3/v[0-9\.]+|",
  2051. "ananzi|EMC|",
  2052. "EnaBot|EnaBot|",
  2053. "esculapio|esculapio/1.1|", "Esther|esther|",
  2054. "everyfeed-spider|everyfeed-spider|F|",
  2055. "Evliya|Evliya|", "nzexplorer|explorersearch|",
  2056. "eZ publish Validator|eZpublishLinkValidator|",
  2057. "FastCrawler|FastCrawler|R|",
  2058. "FDSE|(compatible;FDSErobot)|R|",
  2059. "Feed::Find|Feed::Find|",
  2060. "FeedBurner|FeedBurner|F|",
  2061. "FeedDemon|FeedDemon/|F|",
  2062. "FeedHub FeedFetcher|FeedHub|F|",
  2063. "Feedreader|Feedreader|F|",
  2064. "Feedshow|Feedshow|F|",
  2065. "Feedster|Feedster|F|",
  2066. "FeedTools|feedtools|F|",
  2067. "Feedfetcher-Google|Feedfetcher-google|F|",
  2068. "Felix|FelixIDE/1.0|", "Wild|Hazel's|", "FetchRover|ESIRover|",
  2069. "fido|fido/0.9|",
  2070. "Fish|Fish-Search-Robot|", "Fouineur|Fouineur|",
  2071. "Freecrawl|Freecrawl|R|", "FunnelWeb|FunnelWeb-1.0|",
  2072. "gammaSpider|gammaSpider|", "gazz|gazz/1.0|", "GCreep|gcreep/1.0|",
  2073. "GetRight|GetRight|R|",
  2074. "GetterroboPlus|straight|",
  2075. "GetURL|GetURL.rexx|", "Golem|Golem/1.1|",
  2076. "Googlebot|Googlebot/|R|",
  2077. "Google|googlebot/|R|","Google Images|Googlebot-Image|R|",
  2078. "Google AdSense|Mediapartners-Google|R|",
  2079. "Google Desktop|GoogleDesktop|F|",
  2080. "GreatNews|GreatNews|F|",
  2081. "Gregarius|Gregarius/|F|",
  2082. "Gromit|Gromit/1.0|",
  2083. "gsinfobot|gsinfobot|",
  2084. "Northern|Gulliver/1.1|", "Gulper|Gulper|",
  2085. "GurujiBot|GurujiBot|",
  2086. "Harvest|yes|", "havIndex|havIndex/X.xx[bxx]|",
  2087. "heritrix|heritrix/|",
  2088. "HI|AITCSRobot/1.1|",
  2089. "HKU|HKU|",
  2090. "Hometown|Hometown|",
  2091. "ht://Dig|htdig/3|R|", "HTMLgobble|HTMLgobble|", "Hyper-Decontextualizer|Hyper|",
  2092. "iajaBot|iajaBot/0.1|", "IBM_Planetwide|IBM_Planetwide,|",
  2093. "ichiro|ichiro|",
  2094. "Popular|gestaltIconoclast/1.0|",
  2095. "Ingrid|INGRID/0.1|", "Imagelock|Imagelock|", "IncyWincy|IncyWincy/1.0b1|", "Informant|Informant|",
  2096. "InfoSeek|InfoSeek|",
  2097. "InfoSpiders|InfoSpiders/0.1|", "Inspector|inspectorwww/1.0|", "IntelliAgent|'IAGENT/1.0'|",
  2098. "ISC Systems iRc Search|ISCSystemsiRcSearch|",
  2099. "Israeli-search|IsraeliSearch/1.0|",
  2100. "IRLIRLbot/|IRLIRLbot|",
  2101. "Italian Blog Rankings|blogbabel|F|",
  2102. "Jakarta|Jakarta|",
  2103. "Java|Java/|",
  2104. "JBot|JBot|",
  2105. "JCrawler|JCrawler/0.2|",
  2106. "JoBo|JoBo|", "Jobot|Jobot/0.1alpha|", "JoeBot|JoeBot/x.x,|", "The|JubiiRobot/version#|", "JumpStation|jumpstation|",
  2107. "image.kapsi.net|image.kapsi.net/1.0|R|",
  2108. "Internet|User-Agent:|",
  2109. "kalooga/kalooga|kalooga/kalooga|",
  2110. "Katipo|Katipo/1.0|", "KDD-Explorer|KDD-Explorer/0.1|",
  2111. "KIT-Fireball|KIT-Fireball/2.0|",
  2112. "KindOpener|KindOpener|",
  2113. "kinjabot|kinjabot|",
  2114. "KO_Yappo_Robot|KO_Yappo_Robot/1.0.4(http://yappo.com/info/robot.html)|",
  2115. "Krugle|Krugle|",
  2116. "LabelGrabber|LabelGrab/1.1|",
  2117. "Larbin|larbin_|", "legs|legs|",
  2118. "libwww-perl|libwww-perl|",
  2119. "lilina|Lilina|",
  2120. "Link|Linkidator/0.93|", "LinkWalker|LinkWalker|",
  2121. "LiteFinder|LiteFinder|",
  2122. "logo.gif|logo.gif|",
  2123. "LookSmart|grub-client|",
  2124. "Lsearch/sondeur|Lsearch/sondeur|",
  2125. "Lycos|Lycos/x.x|",
  2126. "Magpie|Magpie/1.0|",
  2127. "MagpieRSS|MagpieRSS|",
  2128. "Mail.ru|Mail.ru|",
  2129. "marvin/infoseek|marvin/infoseek|",
  2130. "Mattie|M/3.8|",
  2131. "MediaFox|MediaFox/x.y|",
  2132. "Megite2.0|Megite.com|",
  2133. "NEC-MeshExplorer|NEC-MeshExplorer|",
  2134. "MindCrawler|MindCrawler|",
  2135. "Missigua Locator|Missigua Locator|",
  2136. "MJ12bot|MJ12bot|",
  2137. "mnoGoSearch|UdmSearch|",
  2138. "MOMspider|MOMspider/1.00|",
  2139. "Monster|Monster/vX.X.X|",
  2140. "Moreover|Moreoverbot|",
  2141. "Motor|Motor/0.2|",
  2142. "MSNBot|MSNBOT/0.1|R|",
  2143. "MSN|msnbot|R|",
  2144. "MSRBOT|MSRBOT|R|",
  2145. "Muninn|Muninn/0.1|",
  2146. "Muscat|MuscatFerret/<version>|",
  2147. "Mwd.Search|MwdSearch/0.1|",
  2148. "Naver|NaverBot|","Naver|Cowbot|",
  2149. "NDSpider|NDSpider/1.5|",
  2150. "Nederland.zoek|Nederland.zoek|",
  2151. "NetCarta|NetCarta|", "NetMechanic|NetMechanic|",
  2152. "NetScoop|NetScoop/1.0|",
  2153. "NetNewsWire|NetNewsWire|",
  2154. "NewsAlloy|NewsAlloy|",
  2155. "newscan-online|newscan-online/1.1|",
  2156. "NewsGatorOnline|NewsGatorOnline|",
  2157. "NG/2.0|NG/2.0|",
  2158. "NHSE|NHSEWalker/3.0|", "Nomad|Nomad-V2.x|",
  2159. "Nutch/Nutch|Nutch/Nutch|",
  2160. "ObjectsSearch|ObjectsSearch/0.01|",
  2161. "Occam|Occam/1.0|",
  2162. "Openfind|Openfind|",
  2163. "OpiDig|OpiDig|",
  2164. "Orb|Orbsearch/1.0|",
  2165. "OSSE Scanner|OSSE Scanner|",
  2166. "OWPBot|OWPBot|",
  2167. "Pack|PackRat/1.0|", "ParaSite|ParaSite/0.21|",
  2168. "Patric|Patric/0.01a|",
  2169. "PECL::HTTP|PECL::HTTP|",
  2170. "PerlCrawler|PerlCrawler/1.0|",
  2171. "Phantom|Duppies|", "PhpDig|phpdig/x.x.x|",
  2172. "PiltdownMan|PiltdownMan/1.0|",
  2173. "Pimptrain.com's|Pimptrain|", "Pioneer|Pioneer|",
  2174. "Portal|PortalJuice.com/4.0|", "PGP|PGP-KA/1.2|",
  2175. "PlumtreeWebAccessor|PlumtreeWebAccessor/0.9|",
  2176. "Poppi|Poppi/1.0|", "PortalB|PortalBSpider/1.0|",
  2177. "psbot|psbot/|",
  2178. "R6_CommentReade|R6_CommentReade|",
  2179. "R6_FeedFetcher|R6_FeedFetcher|",
  2180. "radianrss|RadianRSS|",
  2181. "Raven|Raven-v2|",
  2182. "relevantNOISE|www.relevantnoise.com|",
  2183. "Resume|Resume|", "RoadHouse|RHCS/1.0a|",
  2184. "RixBot|RixBot|", "Road|Road|",
  2185. "Robbie|Robbie/0.1|", "RoboCrawl|RoboCrawl|",
  2186. "RoboFox|Robofox|", "Robot|Robot|",
  2187. "Robozilla|Robozilla/1.0|",
  2188. "Rojo|rojo|F|",
  2189. "Roverbot|Roverbot|",
  2190. "RssBandit|RssBandit|",
  2191. "RSSMicro|RSSMicro.com|F|",
  2192. "Ruby|Rfeedfinder|",
  2193. "RuLeS|RuLeS/1.0|",
  2194. "Runnk RSS aggregator|Runnk|",
  2195. "SafetyNet|SafetyNet|",
  2196. "Sage|(Sage)|F|",
  2197. "SBIder|Site|",
  2198. "Scooter|Scooter/2.0|",
  2199. "ScoutJet|ScoutJet|",
  2200. "Search.Aus-AU.COM|not|",
  2201. "SearchProcess|searchprocess/0.9|",
  2202. "Seekbot|HTTPFetcher|",
  2203. "wp-autoblogSimplePie|SimplePie|",
  2204. "Sitemap Generator|SitemapGenerator|",
  2205. "Senrigan|Senrigan/xxxxxx|",
  2206. "SG-Scout|SG-Scout|", "Shai'Hulud|Shai'Hulud|",
  2207. "Simmany|SimBot/1.0|",
  2208. "SiteTech-Rover|SiteTech-Rover|",
  2209. "shelob|shelob|",
  2210. "Skymob.com|aWapClient|",
  2211. "Sleek|Sleek|",
  2212. "Inktomi|Slurp/2.0|",
  2213. "Snapbot|Snap|",
  2214. "Smart|ESISmartSpider/2.0|",
  2215. "Snooper|Snooper/b97_01|", "Solbot|Solbot/1.0|",
  2216. "Sphere Scout|SphereScout|",
  2217. "Spider|Spider|", "spider_monkey|mouse.house/7.1|", "SpiderBot|SpiderBot/1.0|", "Spiderline|spiderline/3.1.3|", "SpiderView(tm)|SpiderView|", "Site|ssearcher100|",
  2218. "StackRambler|StackRambler|",
  2219. "Strategic Board Bot|StrategicBoardBot|",
  2220. "Suke|suke/*.*|",
  2221. "SummizeFeedReader|SummizeFeedReader|",
  2222. "suntek|suntek/1.0|",
  2223. "SurveyBot|SurveyBot|",
  2224. "Sygol|http://www.sygol.com|",
  2225. "Syndic8|Syndic8|F|",
  2226. "TACH|TACH|", "Tarantula|Tarantula/1.0|",
  2227. "tarspider|tarspider|", "Tcl|dlw3robot/x.y|",
  2228. "TechBOT|TechBOT|",
  2229. "Technorati|Technoratibot|",
  2230. "Teemer|Teemer|",
  2231. "Templeton|Templeton/{version}|",
  2232. "TitIn|TitIn/0.2|", "TITAN|TITAN/0.1|",
  2233. "Twiceler|cuill.com/twiceler/|R|",
  2234. "UCSD|UCSD-Crawler|", "UdmSearch|UdmSearch/2.1.1|",
  2235. "UniversalFeedParser|UniversalFeedParser|",
  2236. "UptimeBot|uptimebot|",
  2237. "URL|urlck/1.2.3|", "URL|URL|",
  2238. "VadixBot|VadixBot|",
  2239. "Valkyrie|Valkyrie/1.0|", "Verticrawl|Verticrawlbot|", "Victoria|Victoria/1.0|", "vision-search|vision-search/3.0'|",
  2240. "void-bot|void-bot/0.1|",
  2241. "Voila|VoilaBot|",
  2242. "Voyager|Voyager/0.0|", "VWbot|VWbot_K/4.2|",
  2243. "W3C_Validator|W3C_Validator|",
  2244. "The|w3index|", "W3M2|W3M2/x.xxx|",
  2245. "w3mir|w3mir|",
  2246. "w@pSpider|w@pSpider/xxx|",
  2247. "WallPaper|CrawlPaper/n.n.n|", "the|WWWWanderer|",
  2248. "Web|root/0.1|",
  2249. "WebCatcher|WebCatcher/1.0|",
  2250. "webcollage|webcollage|",
  2251. "WebCopier|WebCopier|",
  2252. "WebCopy|WebCopy/(version)|",
  2253. "webfetcher|WebFetcher/0.8,|",
  2254. "WebGenBot|WebGenBot|",
  2255. "Webinator|weblayers|",
  2256. "weblayers/0.0|WebLinker|",
  2257. "WebLinker/0.0|WebMirror|",
  2258. "webLyzard|webLyzard|",
  2259. "Weblog|wlm-1.1|",
  2260. "Digimarc|WebReaper|", "WebReaper|webs|", "webs@recruit.co.jp|Websnarf|", "WebVac|webvac/1.0|", "webwalk|webwalk|",
  2261. "WebWalker|WebWalker/1.10|", "WebWatch|WebWatch|",
  2262. "WebStolperer|WOLP/1.0|",
  2263. "WebZinger|none|",
  2264. "Wells Search II|WellsSearchII|",
  2265. "Wget|Wget/1.4.0|",
  2266. "Wget|Wget/1.|",
  2267. "whatUseek|whatUseek_winona/3.0|",
  2268. "whiteiexpres/Nutch|whiteiexpres/Nutch|",
  2269. "wikioblogs|wikioblogs|",
  2270. "WikioFeedBot|WikioFeedBot|",
  2271. "WikioPxyFeedBo|WikioPxyFeedBo|",
  2272. "Wired|wired-digital-newsbot/1.5|",
  2273. "Wordpress Pingback/Trackback|Wordpress|",
  2274. "WWWC|WWWC/0.25|",
  2275. "XGET|XGET/0.7|",
  2276. "yacybot|yacybot|",
  2277. "MyBlogLog|Yahoo!MyBlogLogAPIClient|F|",
  2278. "Yahoo!|slurp@inktomi|","Yahoo!|Yahoo!Slurp|","Yahoo!|MMCrawler|",
  2279. "Yahoo FeedSeeker|YahooFeedSeeker|",
  2280. "Tailrank|Spinn3r|F|",
  2281. "Yandex|Yandex|");
  2282. foreach($lines as $line_num => $spider) {
  2283. list($nome,$key,$typebot)=explode("|",$spider);
  2284. if ($key != "") {
  2285. if(strstr($agent,$key)===FALSE) {
  2286. continue;
  2287. } else {
  2288. $crawler = trim($nome);
  2289. if (!empty($typebot) && $typebot == "F") {
  2290. $feed = $crawler;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. } // end if crawler
  2296. //#If crawler not in list, use first word in user agent for crawler name
  2297. if (empty($crawler)) {
  2298. if (preg_match("/^(\w+)[\/\ \-\:_\.]/",$ua,$matches) > 0) {
  2299. if (strlen($matches[1]) > 1 && $matches[1] != "Mozilla") {
  2300. $crawler = $matches[1];
  2301. }
  2302. }
  2303. if (empty($crawler) && !empty($browser)) {
  2304. $crawler = $browser;
  2305. }
  2306. }
  2307. //#do a feed check and get feed subcribers, if available
  2308. if (preg_match("/([0-9]{1,10})(subscriber)/i",$agent,$subscriber) > 0) {
  2309. // It's a feedreader with some subscribers
  2310. $feed = $subscriber[1];
  2311. if (empty($crawler)) {
  2312. $crawler = "Feed Reader";
  2313. }
  2314. } elseif (is_feed() || (empty($feed) && preg_match("/(feed|rss)/i",$agent)>0)) {
  2315. if (!empty($crawler)) {
  2316. $feed = $crawler;
  2317. } else {
  2318. $crawler = "Feed Reader";
  2319. $feed = "feed reader";
  2320. }
  2321. } //end else preg_match subscriber
  2322. //check for spoofers of Google/Yahoo crawlers...
  2323. if ($hostname!="") {
  2324. if (preg_match('/^(googlebot|yahoo\!\ slurp)/i',$crawler)>0 && preg_match('/\.(googlebot|yahoo)\./i',$hostname)==0){
  2325. $crawler = "Spoofer bot";
  2326. }
  2327. } //end if hostname
  2328. return array($crawler,trim($feed));
  2329. } //end function wGetSpider
  2330. //#get the visitor locale/language
  2331. function wGetLocale($language="",$hostname="",$referrer="") {
  2332. //#use country code for language, if it exists in hostname
  2333. if (!empty($hostname) && preg_match("/\.[a-zA-Z]{2}$/", $hostname) > 0) {
  2334. $country = strtolower(substr($hostname,-2));
  2335. if ($country == "uk") { $country = "gb"; } //change UK to GB for consistent language codes
  2336. $language = $country;
  2337. } elseif (strlen($language) >2) {
  2338. $langarray = @explode("-", $language);
  2339. $langarray = @explode(",", $langarray[1]);
  2340. list($language) = @explode(";", strtolower($langarray[0]));
  2341. }
  2342. //#check referrer search string for language/locale code, if any
  2343. if ((empty($language) || $language=="us" || $language=="en") && !empty($referrer)) {
  2344. $country = $language;
  2345. // google referrer syntax: google.com[.country],hl=language
  2346. if (preg_match('/\.google(\.com)?\.(com|([a-z]{2}))?\/.*[&?]hl\=(\w{2})\-?(\w{2})?/',$referrer,$matches)>0) {
  2347. if (!empty($matches[5])) {
  2348. $country = strtolower($matches[5]);
  2349. } elseif (!empty($matches[3])) {
  2350. $country = strtolower($matches[3]);
  2351. } elseif (!empty($matches[4])) {
  2352. $country = strtolower($matches[4]);
  2353. }
  2354. }
  2355. $language = $country;
  2356. }
  2357. //default to "US" if language==en (english)
  2358. if ($language == "en") {
  2359. $language = "us";
  2360. }
  2361. return $language;
  2362. } //end function wGetLocale
  2363. //# Check input, $referrer against a list of known spammers and
  2364. //# return "1" if match found.
  2365. //# All comparisons are case-insensistive and uses the faster string
  2366. //# functions (stristr) instead of "regular expression" functions.
  2367. function wGetSpamRef($referrer) {
  2368. $referrer=htmlentities(strip_tags(str_replace(" ","",html_entity_decode($referrer))));
  2369. $badhostfile= dirname(__FILE__).'/badhosts.txt';
  2370. $key = null;
  2371. if (empty($referrer)) { return null; } //nothing to check...
  2372. //#Assume any referrer name similar to "viagra/zanax/.."
  2373. //# is spam and mark as such...
  2374. $lines = array("cialis","viagra","zanax","phentermine");
  2375. foreach ($lines as $badreferrer) {
  2376. if (stristr($referrer, $badreferrer) !== FALSE) {
  2377. return 1;
  2378. }
  2379. }
  2380. $lines = array("1clickholdem.com", "1ps.biz", "24h.to", "4all-credit.com", "4all-prescription.com", "4u-money.com", "6q.org", "88.to", "always-casino.com",
  2381. "always-credit.com", "andipink.com", "antiquemarketplace.net", "artmedia.com.ru", "asstraffic.com", "at.cx", "available-casino.com", "available-credit.com",
  2382. "available-prescription.com", "base-poker.com", "bayfronthomes.net", "bitlocker.net", "black-poker.com", "blest-money.com", "budgethawaii.net", "bwdow.com",
  2383. "cafexml.com", "cameralover.net", "capillarychromatogr.org", "cash-2u.com", "casino-500.com", "casino-bu.com", "casinos4spain.com", "cheat-elite.com", "clan.ws",
  2384. "computerxchange.com", "conjuratia.com", "credit-4me.com", "credit-dreams.com", "cups.cs.cmu.edu", "de.tc", "dietfacts.com", "doctor-here.com", "doctor-test.com",
  2385. "eu.cx", "fidelityfunding.net", "finance-4all.com", "finestrealty.net", "fortexasholdem.com", "freewarechannel.de", "gb.com", "golfshoot.com", "great-finance.com",
  2386. "great-money.com", "health-livening.com", "here.ws", "hu.tc", "iepills.com", "ihomebroker.com", "including-poker.com", "internettexashold.com", "isdrin.de",
  2387. "iwebtool.com", "jaja-jak-globusy.com", "jobruler.com", "jpe.com", "js4.de", "just-pharmacy.com", "learnhowtoplay.com", "mine-betting.com", "new-doctor.com",
  2388. "nonews.ru", "now-cash.com", "online-pills.us", "online.cx", "only-casino.com", "ourtexasholdem.com", "p.cx", "partyshopcentral.com", "petsellers.net",
  2389. "pharmacy-here.com", "pills-only.com", "plenty-cash.com", "poker-check.com", "poker-spanish.com", "pressemitteilung.ws", "quality-poker.com", "reale-amateure.com",
  2390. "realtorx2.com", "rulen.de", "shop.tc", "sp.st", "spanish-casino-4u.com", "standard-poker.com", "start.bg", "take-mortgage.com", "texasholdfun.com",
  2391. "the-discount-store.com", "unique-pills.com", "unixlover.com", "us.tc", "useful-pills.com", "vadoptions.com", "vcats.com", "vinsider.com", "vjackpot.com",
  2392. "vmousetrap.com", "vplaymate.com", "vselling.com", "vsymphony.com", "vthought.com", "walnuttownfireco.org", "white-pills.com", "wkelleylucas.com", "yourpsychic.net",
  2393. "mature-lessons.com", "wrongsideoftown.com", "wildpass.com", "collegefuckfest.com", "brutalblowjobs.com", "livemarket.com.ua", "allinternal.com", "asstraffic.com",
  2394. "progressiveupdate.net","dating-s.net","ua-princeton.com","royalfreehost.com", "www.texas-va-loan.com", "jmhic.com", "whvc.net", "vegas-hair.com", "owned.com",
  2395. "sml338.org", "kredite-kredit", "buy-2005.com", "vrajitor.com", "ro7kalbe.com", "ca-america.com", "udcorp.com", "walnuttownfireco.org", "yx-colorweaving.com",
  2396. "terashells.com", "chat-nett.com", "exitq.com", "cxa.de", "sysrem03.com", "pharmacy.info", "guide.info", "drugstore.info","vpshs.com", "vp888.net", "coresat.com",
  2397. "psxtreme.com", "freakycheats.com", "cool-extreme.com", "pervertedtaboo.com", "crescentarian.net", "texas-holdem", "yelucie.com", "poker-online.com",
  2398. "findwebhostingnow.com", "smsportali.net", "6q.org", "flowersdeliveredquick.com", "trackerom.com", "andrewsaluk.com", "4u.net", "4u.com", "doobu.com", "isacommie.com",
  2399. "musicbox1.com", "roody.com", "zoomgirls.net", "cialis-gl-pills.com", "fickenfetzt.com");
  2400. foreach($lines as $line_num => $spammer) {
  2401. if(stristr($referrer,$spammer) !== FALSE) {
  2402. // find it!
  2403. return 1;
  2404. }
  2405. }
  2406. //#check for a customized spammer list...
  2407. if (file_exists($badhostfile)) {
  2408. $lines = file($badhostfile,FILE_IGNORE_NEW_LINES);
  2409. foreach($lines as $line_num => $spammer) {
  2410. if(stristr($referrer,trim($spammer)) !== FALSE) {
  2411. // find it!
  2412. return 1;
  2413. }
  2414. }
  2415. }
  2416. return null;
  2417. } //end function wGetSpamRef()
  2418. function export_wassup() {
  2419. global $wpdb, $table_name;
  2420. $table_name = $wpdb->prefix . "wassup";
  2421. $filename = 'wassup.' . gmdate('Y-m-d') . '.sql';
  2422. //# check for records before exporting...
  2423. $numrecords = $wpdb->get_var("SELECT COUNT(wassup_id) FROM $table_name");
  2424. if ( $numrecords > 0 ) {
  2425. //TODO: use compressed file transfer when zlib available...
  2426. do_action('export_wassup');
  2427. header('Content-Description: File Transfer');
  2428. header("Content-Disposition: attachment; filename=$filename");
  2429. header('Content-Type: text/plain charset=' . get_option('blog_charset'), true);
  2430. // Function is below
  2431. backup_table($table_name);
  2432. die(); //sends output and flushes buffer
  2433. } //end if numrecords > 0
  2434. } //end function export_wassup()
  2435. /**
  2436. * Taken partially from wp-db-backup plugin
  2437. * Alain Wolf, Zurich - Switzerland
  2438. * Website: http://www.ilfilosofo.com/blog/wp-db-backup/
  2439. * @param string $table
  2440. * @param string $segment
  2441. * @return void
  2442. */
  2443. function backup_table($table, $segment = 'none') {
  2444. global $wpdb;
  2445. define('ROWS_PER_SEGMENT', 100);
  2446. $table_structure = $wpdb->get_results("DESCRIBE $table");
  2447. if (! $table_structure) {
  2448. $this->error(__('Error getting table details','wassup') . ": $table");
  2449. return FALSE;
  2450. }
  2451. if(($segment == 'none') || ($segment == 0)) {
  2452. // Add SQL statement to drop existing table
  2453. $sql .= "\n\n";
  2454. $sql .= "#\n";
  2455. $sql .= "# " . sprintf(__('Delete any existing table %s','wassup'),$table) . "\n";
  2456. $sql .= "#\n";
  2457. $sql .= "\n";
  2458. $sql .= "#\n";
  2459. $sql .= "# Uncomment if you need\n";
  2460. $sql .= "#DROP TABLE IF EXISTS " . $table . ";\n";
  2461. // Table structure
  2462. // Comment in SQL-file
  2463. $sql .= "\n\n";
  2464. $sql .= "#\n";
  2465. $sql .= "# " . sprintf(__('Table structure of table %s','wassup'),$table) . "\n";
  2466. $sql .= "#\n";
  2467. $sql .= "\n";
  2468. $sql .= "#\n";
  2469. $sql .= "# Uncomment if you need\n";
  2470. $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
  2471. if (FALSE === $create_table) {
  2472. $err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wassup'), $table);
  2473. print $err_msg;
  2474. $sql .= "#\n# $err_msg\n#\n";
  2475. }
  2476. $sql .= $create_table[0][1] . ' ;';
  2477. if (FALSE === $table_structure) {
  2478. $err_msg = sprintf(__('Error getting table structure of %s','wassup'), $table);
  2479. print $err_msg;
  2480. $sql .= "#\n# $err_msg\n#\n";
  2481. }
  2482. // Comment in SQL-file
  2483. $sql .= "\n\n";
  2484. $sql .= "#\n";
  2485. $sql .= '# ' . sprintf(__('Data contents of table %s','wassup'),$table) . "\n";
  2486. $sql .= "#\n";
  2487. }
  2488. if(($segment == 'none') || ($segment >= 0)) {
  2489. $defs = array();
  2490. $ints = array();
  2491. foreach ($table_structure as $struct) {
  2492. if ( (0 === strpos($struct->Type, 'tinyint')) ||
  2493. (0 === strpos(strtolower($struct->Type), 'smallint')) ||
  2494. (0 === strpos(strtolower($struct->Type), 'mediumint')) ||
  2495. (0 === strpos(strtolower($struct->Type), 'int')) ||
  2496. (0 === strpos(strtolower($struct->Type), 'bigint')) ||
  2497. (0 === strpos(strtolower($struct->Type), 'timestamp')) ) {
  2498. $defs[strtolower($struct->Field)] = $struct->Default;
  2499. $ints[strtolower($struct->Field)] = "1";
  2500. }
  2501. }
  2502. // Batch by $row_inc
  2503. if($segment == 'none') {
  2504. $row_start = 0;
  2505. $row_inc = ROWS_PER_SEGMENT;
  2506. } else {
  2507. $row_start = $segment * ROWS_PER_SEGMENT;
  2508. $row_inc = ROWS_PER_SEGMENT;
  2509. }
  2510. do {
  2511. if ( !ini_get('safe_mode')) @set_time_limit(15*60);
  2512. $table_data = $wpdb->get_results("SELECT * FROM $table LIMIT {$row_start}, {$row_inc}", ARRAY_A);
  2513. $entries = 'INSERT INTO ' . $table . ' VALUES (';
  2514. // \x08\\x09, not required
  2515. $search = array("\x00", "\x0a", "\x0d", "\x1a");
  2516. $replace = array('\0', '\n', '\r', '\Z');
  2517. if($table_data) {
  2518. foreach ($table_data as $row) {
  2519. $values = array();
  2520. foreach ($row as $key => $value) {
  2521. if ($ints[strtolower($key)]) {
  2522. // make sure there are no blank spots in the insert syntax,
  2523. // yet try to avoid quotation marks around integers
  2524. $value = ( '' === $value) ? $defs[strtolower($key)] : $value;
  2525. $values[] = ( '' === $value ) ? "''" : $value;
  2526. } else {
  2527. $values[] = "'" . str_replace($search, $replace, addslashes($value)) . "'";
  2528. }
  2529. }
  2530. $sql .= " \n" . $entries . implode(', ', $values) . ') ;';
  2531. }
  2532. $row_start += $row_inc;
  2533. }
  2534. } while((count($table_data) > 0) and ($segment=='none'));
  2535. }
  2536. if(($segment == 'none') || ($segment < 0)) {
  2537. // Create footer/closing comment in SQL-file
  2538. $sql .= "\n";
  2539. $sql .= "#\n";
  2540. $sql .= "# " . sprintf(__('End of data contents of table %s','wp-db-backup'),$table) . "\n";
  2541. $sql .= "# --------------------------------------------------------\n";
  2542. $sql .= "\n";
  2543. }
  2544. print $sql;
  2545. } // end backup_table()
  2546. // START initializing Widget
  2547. function wassup_widget_init() {
  2548. if ( !function_exists('register_sidebar_widget') )
  2549. return;
  2550. function wassup_widget($wargs) {
  2551. global $wpdb;
  2552. extract($wargs);
  2553. $wassup_settings = get_option('wassup_settings');
  2554. $wpurl = get_bloginfo('wpurl');
  2555. $siteurl = get_bloginfo('siteurl');
  2556. if ($wassup_settings['wassup_widget_title'] != "") $title = $wassup_settings['wassup_widget_title']; else $title = "Visitors Online";
  2557. if ($wassup_settings['wassup_widget_ulclass'] != "") $ulclass = $wassup_settings['wassup_widget_ulclass']; else $ulclass = "links";
  2558. if ($wassup_settings['wassup_widget_chars'] != "") $chars = $wassup_settings['wassup_widget_chars']; else $chars = "18";
  2559. if ($wassup_settings['wassup_widget_searchlimit'] != "") $searchlimit = $wassup_settings['wassup_widget_searchlimit']; else $searchlimit = "5";
  2560. if ($wassup_settings['wassup_widget_reflimit'] != "") $reflimit = $wassup_settings['wassup_widget_reflimit']; else $reflimit = "5";
  2561. if ($wassup_settings['wassup_widget_topbrlimit'] != "") $topbrlimit = $wassup_settings['wassup_widget_topbrlimit']; else $topbrlimit = "5";
  2562. if ($wassup_settings['wassup_widget_toposlimit'] != "") $toposlimit = $wassup_settings['wassup_widget_toposlimit']; else $toposlimit = "5";
  2563. $table_name = $wpdb->prefix . "wassup";
  2564. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  2565. $to_date = wassup_get_time();
  2566. $from_date = strtotime('-3 minutes', $to_date);
  2567. print $before_widget;
  2568. // Widget Latest Searches
  2569. if ($wassup_settings['wassup_widget_search'] == 1) {
  2570. $query_det = $wpdb->get_results("SELECT search, referrer FROM $table_tmp_name WHERE search!='' GROUP BY search ORDER BY `timestamp` DESC LIMIT ".attribute_escape($searchlimit)."");
  2571. if (count($query_det) > 0) {
  2572. print "$before_title ".__('Last searched terms','wassup')." $after_title";
  2573. print "<ul class='$ulclass'>";
  2574. foreach ($query_det as $sref) {
  2575. print "<li>- <a href='".attribute_escape($sref->referrer)."' target='_blank' rel='nofollow'>".stringShortener(attribute_escape($sref->search), $chars)."</a></li>";
  2576. }
  2577. print "</ul>";
  2578. }
  2579. }
  2580. // Widget Latest Referers
  2581. if ($wassup_settings['wassup_widget_ref'] == 1) {
  2582. $query_ref = $wpdb->get_results("SELECT referrer FROM $table_tmp_name WHERE searchengine='' AND referrer!='' AND referrer NOT LIKE '$wpurl%' GROUP BY referrer ORDER BY `timestamp` DESC LIMIT ".attribute_escape($reflimit)."");
  2583. if (count($query_ref) > 0) {
  2584. print "$before_title ".__('Last referers','wassup')." $after_title";
  2585. print "<ul class='$ulclass'>";
  2586. foreach ($query_ref as $eref) {
  2587. print "<li>- <a href='".attribute_escape($eref->referrer)."' target='_blank' rel='nofollow'>".stringShortener(eregi_replace("#https?://#", "", attribute_escape($eref->referrer)), $chars)."</a></li>";
  2588. }
  2589. print "</ul>";
  2590. }
  2591. }
  2592. // Widget TOP Browsers
  2593. if ($wassup_settings['wassup_widget_topbr'] == 1) {
  2594. $query_topbr = $wpdb->get_results("SELECT count(browser) as top_browser, browser FROM $table_name WHERE browser!='' AND browser NOT LIKE 'N/A%' GROUP BY browser ORDER BY top_browser DESC LIMIT ".attribute_escape($topbrlimit)."");
  2595. if (count($query_topbr) > 0) {
  2596. print "$before_title ".__('Top Browsers','wassup')." $after_title";
  2597. print "<ul class='$ulclass'>";
  2598. foreach ($query_topbr as $etopbr) {
  2599. print "<li>- ".stringShortener($etopbr->browser, $chars)."</li>";
  2600. }
  2601. print "</ul>";
  2602. }
  2603. }
  2604. // Widget TOP Oses
  2605. if ($wassup_settings['wassup_widget_topos'] == 1) {
  2606. $query_topos = $wpdb->get_results("SELECT count(os) as top_os, os FROM $table_name WHERE os!='' AND os NOT LIKE 'N/A%' GROUP BY os ORDER BY top_os DESC LIMIT ".attribute_escape($toposlimit)."");
  2607. if (count($query_topos) > 0) {
  2608. print "$before_title ".__('Top OS','wassup')." $after_title";
  2609. print "<ul class='$ulclass'>";
  2610. foreach ($query_topos as $etopos) {
  2611. print "<li>- ".stringShortener($etopos->os, $chars)."</li>";
  2612. }
  2613. print "</ul>";
  2614. }
  2615. }
  2616. // Widget Visitors Online
  2617. $TotWid = New MainItems;
  2618. $TotWid->tableName = $table_tmp_name;
  2619. $TotWid->from_date = $from_date;
  2620. $TotWid->to_date = $to_date;
  2621. $currenttot = $TotWid->calc_tot("count", null, null, "DISTINCT");
  2622. $currentlogged = $TotWid->calc_tot("count", null, "AND username!=''", "DISTINCT");
  2623. $currentauth = $TotWid->calc_tot("count", null, "AND comment_author!='' AND username=''", "DISTINCT");
  2624. print $before_title . $title . $after_title;
  2625. print "<ul class='$ulclass'>";
  2626. if ((int)$currenttot < 10) $currenttot = "0".$currenttot;
  2627. print "<li><strong style='padding:0 4px 0 4px;background:#ddd;color:#777'>".$currenttot."</strong> ".__('visitor(s) online','wassup')."</li>";
  2628. if ((int)$currentlogged > 0 AND $wassup_settings['wassup_widget_loggedin'] == 1) {
  2629. if ((int)$currentlogged < 10) $currentlogged = "0".$currentlogged;
  2630. print "<li><strong style='padding:0 4px 0 4px;background:#e7f1c8;color:#777'>".$currentlogged."</strong> ".__('logged-in user(s)','wassup')."</li>";
  2631. }
  2632. if ((int)$currentauth > 0 AND $wassup_settings['wassup_widget_comauth'] == 1) {
  2633. if ((int)$currentauth < 10) $currentauth = "0".$currentauth;
  2634. print "<li><strong style='padding:0 4px 0 4px;background:#fbf9d3;color:#777'>".$currentauth."</strong> ".__('comment author(s)','wassup')."</li>";
  2635. }
  2636. print "<li style='font-size:6pt; color:#bbb;'>".__("powered by", "wassup")." <a style='color:#777;' href='http://www.wpwp.org' title='WassUp - Real Time Visitors Tracking'>WassUp</a></li>";
  2637. print "</ul>";
  2638. print $after_widget;
  2639. } //end function wassup_widget
  2640. function wassup_widget_control() {
  2641. //global $_POST;
  2642. $wassup_settings = get_option('wassup_settings');
  2643. if (isset($_POST['wassup-submit'])) {
  2644. $wassup_settings['wassup_widget_title'] = $_POST['wassup_widget_title'];
  2645. $wassup_settings['wassup_widget_ulclass'] = $_POST['wassup_widget_ulclass'];
  2646. $wassup_settings['wassup_widget_chars'] = $_POST['wassup_widget_chars'];
  2647. $wassup_settings['wassup_widget_loggedin'] = $_POST['wassup_widget_loggedin'];
  2648. $wassup_settings['wassup_widget_comauth'] = $_POST['wassup_widget_comauth'];
  2649. $wassup_settings['wassup_widget_search'] = $_POST['wassup_widget_search'];
  2650. $wassup_settings['wassup_widget_searchlimit'] = $_POST['wassup_widget_searchlimit'];
  2651. $wassup_settings['wassup_widget_ref'] = $_POST['wassup_widget_ref'];
  2652. $wassup_settings['wassup_widget_reflimit'] = $_POST['wassup_widget_reflimit'];
  2653. $wassup_settings['wassup_widget_topbr'] = $_POST['wassup_widget_topbr'];
  2654. $wassup_settings['wassup_widget_topbrlimit'] = $_POST['wassup_widget_topbrlimit'];
  2655. $wassup_settings['wassup_widget_topos'] = $_POST['wassup_widget_topos'];
  2656. $wassup_settings['wassup_widget_toposlimit'] = $_POST['wassup_widget_toposlimit'];
  2657. update_option('wassup_settings', $wassup_settings);
  2658. $wassup_settings = get_option('wassup_settings');
  2659. }
  2660. ?>
  2661. <div class="wrap" style="text-align:left">
  2662. <h3>Wassup Widget</h3>
  2663. <p style="text-align:left"><input type="text" name="wassup_widget_title" size="20" value="<?php echo $wassup_settings['wassup_widget_title'] ?>" /> <?php _e("What title for the widget (default \"Visitors Online\")", "wassup") ?></p>
  2664. <p style="text-align:left"><input type="text" name="wassup_widget_ulclass" size="3" value="<?php echo $wassup_settings['wassup_widget_ulclass'] ?>" /> <?php _e("What style sheet class for &lt;ul&gt; attribute (default \"links\")", "wassup") ?></p>
  2665. <p style="text-align:left"><input type="text" name="wassup_widget_chars" size="3" value="<?php echo $wassup_settings['wassup_widget_chars'] ?>" /> <?php _e("How many characters left? (For template compatibility - default 18)", "wassup") ?></p>
  2666. <p style="text-align:left"><input type="checkbox" name="wassup_widget_loggedin" value="1"<?php if ($wassup_settings['wassup_widget_loggedin'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show logged-in online users (default Yes)", "wassup") ?></p>
  2667. <p style="text-align:left"><input type="checkbox" name="wassup_widget_comauth" value="1" <?php if ($wassup_settings['wassup_widget_comauth'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show comment-author online users (default Yes)", "wassup") ?></p>
  2668. <p style="text-align:left"><input type="checkbox" name="wassup_widget_search" value="1" <?php if ($wassup_settings['wassup_widget_search'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show some last search referers (default Yes)", "wassup") ?></p>
  2669. <p style="text-align:left"><input type="text" name="wassup_widget_searchlimit" size="3" value="<?php echo $wassup_settings['wassup_widget_searchlimit'] ?>" /> <?php _e("How many search referers want to show (default 5)", "wassup") ?></p>
  2670. <p style="text-align:left"><input type="checkbox" name="wassup_widget_ref" value="1" <?php if ($wassup_settings['wassup_widget_ref'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show some last external referers (default Yes)", "wassup") ?></p>
  2671. <p style="text-align:left"><input type="text" name="wassup_widget_reflimit" size="3" value="<?php echo $wassup_settings['wassup_widget_reflimit'] ?>" /> <?php _e("How many external referers want to show (default 5)", "wassup") ?></p>
  2672. <p style="text-align:left"><input type="checkbox" name="wassup_widget_topbr" value="1" <?php if ($wassup_settings['wassup_widget_topbr'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show top browsers (default No - enabling it could slow down blog)", "wassup") ?></p>
  2673. <p style="text-align:left"><input type="text" name="wassup_widget_topbrlimit" size="3" value="<?php echo $wassup_settings['wassup_widget_topbrlimit'] ?>" /> <?php _e("How many top browsers want to show (default 5)", "wassup") ?></p>
  2674. <p style="text-align:left"><input type="checkbox" name="wassup_widget_topos" value="1" <?php if ($wassup_settings['wassup_widget_topos'] == 1) echo "CHECKED"; ?> /> <?php _e("Check if you want to show top operating systems (default No - enabling it could slow down blog)", "wassup") ?></p>
  2675. <p style="text-align:left"><input type="text" name="wassup_widget_toposlimit" size="3" value="<?php echo $wassup_settings['wassup_widget_toposlimit'] ?>" /> <?php _e("How many top operating systems want to show (default 5)", "wassup") ?></p>
  2676. <p style="text-align:left"><input type="hidden" name="wassup-submit" id="wassup-submit" value="1" /></p>
  2677. </div>
  2678. <?php
  2679. } //end function wassup_widget_control
  2680. $wassup_settings = get_option('wassup_settings');
  2681. if ($wassup_settings['wassup_userlevel'] == "") {
  2682. if ($wassup_settings['wassup_userlevel'] == "") {
  2683. $wassup_settings['wassup_userlevel'] = 8;
  2684. update_option('wassup_settings', $wassup_settings);
  2685. }
  2686. if ($wassup_settings['wassup_refresh'] == "") {
  2687. $wassup_settings['wassup_refresh'] = 3;
  2688. update_option('wassup_settings', $wassup_settings);
  2689. }
  2690. }
  2691. if(function_exists('register_sidebar_widget')) {
  2692. register_sidebar_widget(__('Wassup Widget'), 'wassup_widget');
  2693. register_widget_control(array('Wassup Widget', 'widgets'), 'wassup_widget_control', 600, 540);
  2694. }
  2695. } //end function wassup_widgit_init
  2696. function wassup_sidebar($before_widget='', $after_widget='', $before_title='', $after_title='', $wtitle='', $wulclass='', $wchars='', $wsearch='', $wsearchlimit='', $wref='', $wreflimit='', $wtopbr='', $wtopbrlimit='', $wtopos='', $wtoposlimit='') {
  2697. global $wpdb;
  2698. $wpurl = get_bloginfo('wpurl');
  2699. $siteurl = get_bloginfo('siteurl');
  2700. if ($wtitle != "") $title = $wtitle; else $title = "Visitors Online";
  2701. if ($wulclass != "") $ulclass = $wulclass; else $ulclass = "links";
  2702. if ($wchars != "") $chars = $wchars; else $chars = "18";
  2703. if ($wsearchlimit != "") $searchlimit = $wsearchlimit; else $searchlimit = "5";
  2704. if ($wreflimit != "") $reflimit = $wreflimit; else $reflimit = "5";
  2705. if ($wtopbrlimit != "") $topbrlimit = $wtopbrlimit; else $topbrlimit = "5";
  2706. if ($wtoposlimit != "") $toposlimit = $wtoposlimit; else $toposlimit = "5";
  2707. $table_name = $wpdb->prefix . "wassup";
  2708. $table_tmp_name = $wpdb->prefix . "wassup_tmp";
  2709. $to_date = wassup_get_time();
  2710. $from_date = strtotime('-3 minutes', $to_date);
  2711. print $before_widget;
  2712. if ($wsearch == 1) {
  2713. $query_det = $wpdb->get_results("SELECT search, referrer FROM $table_tmp_name WHERE search!='' GROUP BY search ORDER BY `timestamp` DESC LIMIT $searchlimit");
  2714. if (count($query_det) > 0) {
  2715. print "$before_title Last searched terms $after_title";
  2716. print "<ul class='$ulclass'>";
  2717. foreach ($query_det as $sref) {
  2718. print "<li>- <a href='".attribute_escape($sref->referrer)."' target='_blank' rel='nofollow'>".stringShortener(attribute_escape($sref->search), $chars)."</a></li>";
  2719. }
  2720. print "</ul>";
  2721. }
  2722. }
  2723. if ($wref == 1) {
  2724. $query_ref = $wpdb->get_results("SELECT referrer FROM $table_tmp_name WHERE searchengine='' AND referrer!='' AND referrer NOT LIKE '$wpurl%' GROUP BY referrer ORDER BY `timestamp` DESC LIMIT $reflimit");
  2725. if (count($query_ref) > 0) {
  2726. print "$before_title Last referers $after_title";
  2727. print "<ul class='$ulclass'>";
  2728. foreach ($query_ref as $eref) {
  2729. print "<li>- <a href='".attribute_escape($eref->referrer)."' target='_blank' rel='nofollow'>".stringShortener(preg_replace("#https?://#", "", attribute_escape($eref->referrer)), $chars)."</a></li>";
  2730. }
  2731. print "</ul>";
  2732. }
  2733. }
  2734. if ($wtopbr == 1) {
  2735. $query_topbr = $wpdb->get_results("SELECT count(browser) as top_browser, browser FROM $table_name WHERE browser!='' AND browser NOT LIKE 'N/A%' GROUP BY browser ORDER BY top_browser DESC LIMIT $topbrlimit");
  2736. if (count($query_topbr) > 0) {
  2737. print "$before_title Top Browsers $after_title";
  2738. print "<ul class='$ulclass'>";
  2739. foreach ($query_topbr as $etopbr) {
  2740. print "<li>- ".stringShortener(attribute_escape($etopbr->browser), $chars)."</li>";
  2741. }
  2742. print "</ul>";
  2743. }
  2744. }
  2745. if ($wtopos == 1) {
  2746. $query_topos = $wpdb->get_results("SELECT count(os) as top_os, os FROM $table_name WHERE os!='' AND os NOT LIKE 'N/A%' GROUP BY os ORDER BY top_os DESC LIMIT $toposlimit");
  2747. if (count($query_topos) > 0) {
  2748. print "$before_title Top OS $after_title";
  2749. print "<ul class='$ulclass'>";
  2750. foreach ($query_topos as $etopos) {
  2751. print "<li>- ".stringShortener(attribute_escape($etopos->os), $chars)."</li>";
  2752. }
  2753. print "</ul>";
  2754. }
  2755. }
  2756. $TotWid = New MainItems;
  2757. $TotWid->tableName = $table_tmp_name;
  2758. $TotWid->from_date = $from_date;
  2759. $TotWid->to_date = $to_date;
  2760. $currenttot = $TotWid->calc_tot("count", null, null, "DISTINCT");
  2761. $currentlogged = $TotWid->calc_tot("count", null, "AND username!=''", "DISTINCT");
  2762. $currentauth = $TotWid->calc_tot("count", null, "AND comment_author!=''' AND username=''", "DISTINCT");
  2763. print $before_title . $title . $after_title;
  2764. print "<ul class='$ulclass'>";
  2765. if ((int)$currenttot < 10) $currenttot = "0".$currenttot;
  2766. print "<li><strong style='padding:0 4px 0 4px;background:#ddd;color:#777'>".$currenttot."</strong> visitor(s) online</li>";
  2767. if ((int)$currentlogged > 0 AND $wassup_settings['wassup_widget_loggedin'] == 1) {
  2768. if ((int)$currentlogged < 10) $currentlogged = "0".$currentlogged;
  2769. print "<li><strong style='padding:0 4px 0 4px;background:#e7f1c8;color:#777'>".$currentlogged."</strong> logged-in user(s)</li>";
  2770. }
  2771. if ((int)$currentauth > 0 AND $wassup_settings['wassup_widget_comauth'] == 1) {
  2772. if ((int)$currentauth < 10) $currentauth = "0".$currentauth;
  2773. print "<li><strong style='padding:0 4px 0 4px;background:#fbf9d3;color:#777'>".$currentauth."</strong> comment author(s)</li>";
  2774. }
  2775. print "<li style='font-size:6pt; color:#bbb;'>".__("powered by", "wassup")." <a style='color:#777;' href='http://www.wpwp.org/' title='WassUp - Real Time Visitors Tracking'>WassUp</a></li>";
  2776. print "</ul>";
  2777. print $after_widget;
  2778. } //end function wassup_sidebar
  2779. //### Add hooks after functions have been defined
  2780. //## General hooks
  2781. add_action('init', 'wassup_init');
  2782. add_action("widgets_init", "wassup_widget_init");
  2783. //## Wassup Admin filters
  2784. register_activation_hook(__FILE__, 'wassup_install');
  2785. register_deactivation_hook(__FILE__, 'wassup_uninstall');
  2786. //add hooks for wassup admin header functions
  2787. add_action('admin_head', 'add_wassup_css');
  2788. add_action('admin_menu', 'wassup_add_pages');
  2789. add_action('activity_box_end', 'wassupDashChart');
  2790. //## Wassup visitor tracking hooks
  2791. //record visit after page is displayed to keep page load fast
  2792. add_action('shutdown', 'wassupAppend');
  2793. //add_action('send_headers', 'wassupAppend'); //slows down page load
  2794. add_action('wp_head', 'add_wassup_meta_info');
  2795. ?>