function luc_referrer() { global $wpdb, $StatPressV_Option; $table_name = STATPRESS_V_TABLE_NAME; $action = "referrer"; $referrer_color = "#419E0C"; $graphdays = $StatPressV_Option['StatPressV_Graph_Days']; if ($graphdays == 0) { $graphdays = 7; } // $pa = pa and $pp = pp in the slug $pa = luc_page_posts(); $pp = luc_page_periode(); $today = gmdate('Ymd', current_time('timestamp')); $limitdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * $pp + 86400); $currentdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * ($pp - 1)); $permalink = luc_permalink(); $NP = luc_count_periode("date", "FROM {$table_name}", "", "referrer<>'' AND referrer NOT LIKE '%" . get_bloginfo('url') . "%' AND searchengine=''", "date", $graphdays); $start_of_week = get_option('start_of_week'); $strqry = "SELECT count(distinct referrer)\r\n\t\t\t\t\tFROM {$table_name}\r\n\t\t\t\t\tWHERE referrer<>''\r\n\t\t\t\t\t\tAND referrer NOT LIKE '%" . get_bloginfo('url') . "%'\r\n\t\t\t\t\t\tAND searchengine=''\r\n\t\t\t\t\t\tAND date BETWEEN {$limitdate} AND {$currentdate};\r\n\t\t\t\t"; $NumberPosts = $wpdb->get_var($strqry); $NumberDisplayPost = $StatPressV_Option['StatPressV_Graph_Per_Page']; if ($NumberDisplayPost == 0) { $NumberDisplayPost = 20; } $NA = ceil($NumberPosts / $NumberDisplayPost); $LimitValueArticles = $pa * $NumberDisplayPost - $NumberDisplayPost; // sort post or page by most unique visitors $strqry = "SELECT count(*) as total, referrer, urlrequested\r\n\t\t\t\t\tFROM {$table_name}\r\n\t\t\t\t\tWHERE referrer<>''\r\n\t\t\t\t\t\tAND referrer NOT LIKE '" . get_bloginfo('url') . "%'\r\n\t\t\t\t\t\tAND searchengine=''\r\n\t\t\t\t\t\tAND date BETWEEN {$limitdate} AND {$currentdate}\r\n\t\t\t\t\tGROUP BY referrer\r\n\t\t\t\t\tORDER by total DESC LIMIT {$LimitValueArticles}, {$NumberDisplayPost};\r\n\t\t\t\t"; $query = $wpdb->get_results($strqry); echo "<div class='wrap'><h2>Most referrer these " . $graphdays . " days </h2>"; luc_print_pp_pa_link($NP, $pp, $action, $NA, $pa); foreach ($query as $url) { for ($i = 0; $i < $graphdays; $i++) { $Date = gmdate('Ymd', current_time('timestamp') - 86400 * ($graphdays * $pp - $i - 1)); $total->visitors[$Date] = 0; } $total->totalvisitors = 0; //TOTAL VISITORS if ($url->post_name == 'page_accueil') { //url == home $qry_visitors = luc_query_graph("DISTINCT ip", "urlrequested ='' AND spider='' AND feed=''", $limitdate, $currentdate); } else { $qry_visitors = luc_query_graph("*", "referrer = '" . $url->referrer . "'", $limitdate, $currentdate); } foreach ($qry_visitors as $row) { $total->visitors[$row->date] = $row->total; $total->totalvisitors += $row->total; } $maxxday = luc_maxxday($total, $graphdays, $pp); $px = luc_pixel($total, $graphdays, $maxxday, $pp, $action); // Overhead of the graph, display the name of the post/page and the average by day of the feeds echo "<div class='wrap'>\r\n\t\t\t\t<table class='widefat'>\r\n\t\t\t\t\t<thead>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th scope='col' width='15%'>\r\n\t\t\t\t\t\t\t\t<div style='background:{$referrer_color};width:10px;height:10px;float:left;margin-top:2px;margin-right:5px;'></div>" . $total->totalvisitors . " visits\r\n\t\t\t\t\t\t\t</th>\r\n\t\t\t\t\t\t\t<th scope='col' width='15%'>\r\n\t\t\t\t\t\t\t\t<div style='background:{$referrer_color};width:10px;height:10px;float:left;margin-top:2px;margin-right:5px;'></div>Average " . round($total->totalvisitors / $graphdays, 1) . " by day\r\n\t\t\t\t\t\t\t</th>\r\n\t\t\t\t\t\t\t<th scope='col' width='70%'>\r\n\t\t\t\t\t\t\t\t<font font-size='1'>" . $url->referrer . "</font>\r\n\t\t\t\t\t\t\t</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</thead>\r\n\t\t\t\t</table>\r\n\t\t\t\t<table class='graph'>\r\n\t\t\t\t\t<tbody>\r\n\t\t\t\t\t\t<tr>"; luc_graph($px, $total, $graphdays, $pp, $action); echo "\t\t\t</tr>\r\n\t\t\t\t\t</tbody>\r\n\t\t\t\t</table>\r\n\t\t\t</div>"; } luc_print_pp_pa_link($NP, $pp, $action, $NA, $pa); echo "</div>"; luc_StatPressV_load_time(); }
function luc_visitors() { global $wpdb, $StatPressV_Option; $table_name = STATPRESS_V_TABLE_NAME; $visitors_color = "#114477"; $action = "visitors"; $graphdays = $StatPressV_Option['StatPressV_Graph_Days']; if ($graphdays == 0) { $graphdays = 7; } // $pa = pa and $pp = pp in the slug $pa = luc_page_posts(); $pp = luc_page_periode(); $today = gmdate('Ymd', current_time('timestamp')); $limitdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * $pp + 86400); $currentdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * ($pp - 1)); $permalink = luc_permalink(); $NP = luc_count_periode("date", "FROM {$table_name} as t", "JOIN {$wpdb->posts} as p ON t.urlrequested LIKE CONCAT('%', p.post_name, '_' ) OR t.urlrequested =''", "(ip IS NOT NULL) AND p.post_status = 'publish' AND (post_type = 'page' OR post_type = 'post')", "date", $graphdays); $start_of_week = get_option('start_of_week'); $strqry = "SELECT count(distinct post_name)\n\t\t\t\t\tFROM {$wpdb->posts} as p\n\t\t\t\t\tJOIN {$table_name} as t\n\t\t\t\t\tON t.urlrequested LIKE CONCAT('" . $permalink . "', p.post_name, '_' )\n\t\t\t\t\tWHERE p.post_status = 'publish'\n\t\t\t\t\t\tAND t.feed=''\n\t\t\t\t\t\tAND (p.post_type = 'page' OR p.post_type = 'post')\n\t\t\t\t\t\tAND t.date BETWEEN {$limitdate} AND {$currentdate} ;\n\t\t\t\t"; $NumberPosts = $wpdb->get_var($strqry); $NumberDisplayPost = $StatPressV_Option['StatPressV_Graph_Per_Page']; if ($NumberDisplayPost == 0) { $NumberDisplayPost = 20; } $NA = ceil($NumberPosts / $NumberDisplayPost); $LimitValueArticles = $pa * $NumberDisplayPost - $NumberDisplayPost; // sort post or page by most unique visitors $strqry = "SELECT post_name, total, urlrequested\n\t\t\t\t\tFROM (\n\t\t\t\t\t(SELECT 'page_accueil' as post_name, count(DISTINCT ip) as total, urlrequested\n\t\t\t\t\t\tFROM {$wpdb->posts} as p\n\t\t\t\t\t\tJOIN {$table_name} as t ON urlrequested =''\n\t\t\t\t\t\tWHERE p.post_status = 'publish'\n\t\t\t\t\t\t\tAND (p.post_type = 'page' OR p.post_type = 'post')\n\t\t\t\t\t\t\tAND t.spider=''\n\t\t\t\t\t\t\tAND t.feed=''\n\t\t\t\t\t\t\tAND (t.date BETWEEN {$limitdate} AND {$currentdate})\n\t\t\t\t\t\tGROUP BY post_name)\n\t\t\t\t\tUNION ALL\n\t\t\t\t\t(SELECT post_name, count(DISTINCT ip) as total, urlrequested\n\t\t\t\t\t\tFROM {$wpdb->posts} as p\n\t\t\t\t\t\tJOIN {$table_name} as t\n\t\t\t\t\t\tON t.urlrequested LIKE CONCAT('%', p.post_name, '_' )\n\t\t\t\t\t\tWHERE p.post_status = 'publish'\n\t\t\t\t\t\t\tAND (p.post_type = 'page' OR p.post_type = 'post')\n\t\t\t\t\t\t\tAND t.spider=''\n\t\t\t\t\t\t\tAND t.feed=''\n\t\t\t\t\t\t\tAND t.date BETWEEN {$limitdate} AND {$currentdate}\n\t\t\t\t\t\tGROUP BY post_name)\n\t\t\t\t\t) visitors\n\t\t\t\t\tGROUP BY post_name\n\t\t\t\t\tORDER BY total DESC LIMIT {$LimitValueArticles}, {$NumberDisplayPost} ;\n\t\t\t\t"; $query = $wpdb->get_results($strqry); $spider = $StatPressV_Option['StatPressV_Dont_Collect_Spider']; echo "<div class='wrap'><h2>Most visitors these " . $graphdays . " days </h2>"; luc_print_pp_pa_link($NP, $pp, $action, $NA, $pa); foreach ($query as $url) { $where1 = " (urlrequested LIKE '" . $permalink . "feed%' OR urlrequested LIKE '" . $permalink . "comment%') "; $where2 = " urlrequested LIKE '%" . $url->post_name . "%' AND spider='' "; if ($url->post_name == 'page_accueil') { //url == home $total = luc_count_graph(luc_init_count_graph($graphdays, $pp), $graphdays, $pp, " urlrequested ='' ", $where1, "feed=''", "feed<>''", $limitdate, $currentdate); } else { //url<> home $total = luc_count_graph(luc_init_count_graph($graphdays, $pp), $graphdays, $pp, $where2, $where2, "feed=''", "feed<>''", $limitdate, $currentdate); } $maxxday = luc_maxxday($total, $graphdays, $pp); $px = luc_pixel($total, $graphdays, $maxxday, $pp, $action); if ($url->urlrequested == '') { $out_url = "[Page]: Home"; } else { $out_url = luc_post_title_Decode($permalink . $url->post_name); } // Overhead of the graph, display the name of the post/page and the average by day of the visitors echo "<div class='wrap' >\n\t\t\t\t<table class='widefat' >\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th scope='col' width='15%'>\n\t\t\t\t\t\t\t\t<div style='background:{$visitors_color};width:10px;height:10px;float:left;margin-top:2px;margin-right:5px;'></div>" . $total->totalvisitors . " visitors\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th scope='col' width='15%'>\n\t\t\t\t\t\t\t\t<div style='background:{$visitors_color};width:10px;height:10px;float:left;margin-top:2px;margin-right:5px;'></div>Average " . round($total->totalvisitors / $graphdays, 1) . " by day\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th scope='col' width='70%'>\n\t\t\t\t\t\t\t\t<font font-size='1'>" . $out_url . "</font>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t</table>\n\t\t\t\t<table class='graph'>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t<tr>"; luc_graph($px, $total, $graphdays, $pp, $action); echo "\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>"; } luc_print_pp_pa_link($NP, $pp, $action, $NA, $pa); echo "</div>"; luc_StatPressV_load_time(); }
function luc_spyvisitors() { global $wpdb; global $StatPressV_Option; $action = "spyvisitors"; $table_name = STATPRESS_V_TABLE_NAME; // number of IP or bot by page $LIMIT = $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] ? $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] : 20; $LIMIT_PROOF = $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] ? $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] : 20; $pp = luc_page_periode(); // Number of distinct ip (unique visitors) $NumIP = $wpdb->get_var("SELECT count(distinct ip)\n\t\t\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\t\t\tWHERE spider='' ;"); $NP = ceil($NumIP / $LIMIT); $LimitValue = $pp * $LIMIT - $LIMIT; $sql = "SELECT *\n\t\t\t\t\tFROM {$table_name} as T1\n\t\t\t\t\tJOIN\n\t\t\t\t\t\t(SELECT max(id) as MaxId,ip\n\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\tWHERE spider=''\n\t\t\t\t\t\t\tGROUP BY ip\n\t\t\t\t\t\t\tORDER BY MaxId DESC LIMIT {$LimitValue}, {$LIMIT}\n\t\t\t\t\t\t) as T2\n\t\t\t\t\tON T1.ip = T2.ip\n\t\t\t\t\tORDER BY MaxId DESC, id DESC;\n\t\t\t\t"; $qry = $wpdb->get_results($sql); if ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked' & function_exists('geoip_open')) { // Open the database to read and save info if (file_exists(luc_GeoIP_dbname('city'))) { $gic = geoip_open(luc_GeoIP_dbname('city'), GEOIP_STANDARD); $geoip_isok = true; } } echo "<div class='wrap'><h2>" . __('Visitor Spy', 'statpress') . "</h2>"; ?> <script> function ttogle(thediv){ if (document.getElementById(thediv).style.display=="inline") { document.getElementById(thediv).style.display="none" } else {document.getElementById(thediv).style.display="inline"} } </script> <?php $MaxId = 0; $num_row = 0; // Add pagination luc_insert_pagination_options("spyvisitors", $NumIP, $LIMIT); luc_print_pp_link($NP, $pp, $action); echo '<table class="widefat" id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">'; foreach ($qry as $rk) { // Visitor Spy if ($MaxId != $rk->MaxId) { if ($geoip_isok === true) { $gir = GeoIP_record_by_addr($gic, $rk->ip); } echo "<thead><tr><th scope='colgroup' colspan='2'>"; if ($rk->country != '') { echo "HTTP country " . luc_HTML_IMG($rk->country, 'country', false); } else { echo "Hostip country <IMG SRC='http://api.hostip.info/flag.php?ip=" . $rk->ip . "' border=0 width=18 height=12> "; } if ($geoip_isok === true) { $lookupsvc = "GeoIP details"; } else { $lookupsvc = "Hostip details"; } echo "\t<strong><span><font size='2' color='#7b7b7b'> " . $rk->ip . " </font></span></strong>\n\t\t\t\t\t<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;'\n\t\t\t\t\t\tonClick=ttogle('" . $rk->ip . "');>" . $lookupsvc . "</span></div>\n\t\t\t\t\t<div id='" . $rk->ip . "' name='" . $rk->ip . "'>"; if ($geoip_isok === true) { echo "\t<small><br>\n\t\t\t\t\t\t\tCountry: " . utf8_encode($gir->country_name) . " (" . $gir->country_code . ")<br>\n\t\t\t\t\t\t\tCity: " . utf8_encode($gir->city) . "<br>\n\t\t\t\t\t\t\tLatitude/Longitude: <a href='http://maps.google.com/maps?q=" . $gir->latitude . "+" . $gir->longitude . "' target='_blank' title='Lookup latitude/longitude location on Google Maps...'>" . $gir->latitude . " " . $gir->longitude . "</a>\n\t\t\t\t\t\t</small>"; } else { echo "\t<iframe style='overflow:hide;border:0px;width:100%;height:35px;font-family:helvetica;paddng:0;'\n\t\t\t\t\t\t\tscrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=" . $rk->ip . ">\n\t\t\t\t\t\t</iframe>"; } echo "\t<small>\n\t\t\t\t\t\t<br>" . $rk->os . "\n\t\t\t\t\t\t<br>" . $rk->browser . "\n\t\t\t\t\t\t<br>" . gethostbyaddr($rk->ip) . "\n\t\t\t\t\t\t<br>" . $rk->agent . "\n\t\t\t\t\t</small></div></th></tr></thead><tbody>\n\t\t\t\t\t<script> document.getElementById('" . $rk->ip . "').style.display='none';</script>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . ""; if ($rk->searchengine != '') { echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>"; } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) { echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>"; } echo "</div></td></tr>\n"; $MaxId = $rk->MaxId; $num_row = 1; } elseif ($num_row < $LIMIT_PROOF) { echo "<tr><td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . ""; if ($rk->searchengine != '') { echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>"; } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) { echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>"; } $num_row += 1; echo "</td></tr></tbody>"; } } echo "</div></td></tr>\n</table>"; luc_print_pp_link($NP, $pp, $action); echo "</div>"; luc_StatPressV_load_time(); }