function defensio_counter($defensio_conf) { $last_updated = $defensio_conf['defensio_stats_updated_at']; $two_hours = 60 * 60 * 2; if ($last_updated == null or mktime() - $last_updated > $two_hours) { $v = defensio_get_stats($defensio_conf); } else { $v = unserialize($defensio_conf['defensio_stats']); } if ($v['status'] = 'success') { switch ($defensio_conf['defensio_widget_align']) { case 'left': $counter_image_style = "float: left;"; break; case 'right': $counter_image_style = "float: right;"; break; case 'center': $counter_image_style = "margin: 0 auto;"; break; } if ($defensio_conf['defensio_widget_image'] == 'dark') { $counter_text_style = "color: #fff;"; } else { $counter_text_style = "color:#211d1e;"; } $spam = isset($v['spam']) ? $v['spam'] : ''; $counter_html = ' <div id="defensio_counter" style="width: 100%; margin: 10px 0 10px 0; text-align: ' . $defensio_conf['defensio_widget_align'] . '"> <a id="defensio_counter_link" style ="text-decoration: none;" href="http://defensio.com"> <div id="defensio_counter_image" style="background:url(\'addons/_defensio/images/defensio-counter-' . $defensio_conf['defensio_widget_image'] . '.gif\') no-repeat top left; border:none; font: 10px \'Trebuchet MS\', \'Myriad Pro\', sans-serif; overflow: hidden; text-align: left; height: 50px; width: 120px;' . $counter_image_style . '"> <div style="display:block; width: 100px; padding: 9px 9px 25px 12px; line-height: 1em; color: #211d1e;' . $counter_text_style . '" "><div style="font-size: 12px; font-weight: bold;">' . $spam . '</div> spam comments blocked</div> </div> <div style="clear:both;" class="defensio_clear"> </div> </a> </div>'; } else { $counter_html = 'Error in retrieving stats.'; } if ($defensio_conf['defensio_widget_image'] != 'none') { return $counter_html; } else { return null; } }
function DEFENSIO() { global $blogid, $pluginMenuURL, $pluginURL, $pluginSelfParam, $blog, $user, $blogURL, $defaultURL, $hostURL, $service, $skinSetting, $configVal; requireComponent('Textcube.Function.misc'); $comment_TYPE = !empty($_GET['t']) ? $_GET['t'] : ''; $page = !empty($_GET['page']) ? $_GET['page'] : 1; $perPage = getBlogSetting('rowsPerPage', 10); if ($comment_TYPE != "T") { $comment_TYPE = "C"; } $data = misc::fetchConfigVal($configVal); $blogHome = preg_replace("'^http://'", "", $hostURL); print '<div><h2 class="caption"><span class="main-text">Defensio Anti Spam Filter</span></h2></div>'; if (!isset($data['apikey']) || $data['apikey'] == '') { print <<<ENDL \t\t<div> \t\t\t<p><a href="http://www.defensio.com">Defensio</a>'s blog spam web service aggressively and intelligently prevents comment and trackback spam from hitting your blog. You should quickly notice a dramatic reduction in the amount of spam you have to worry about.</p><br /> \t\t\t<p>When the filter does rarely make a mistake (say, the odd spam message gets through or a rare good comment is marked as spam) we've made it a joy to sort through your comments and set things straight. Not only will the filter learn and improve over time, but it will do so in a personalized way!</p><br /> \t\t\t<p>In order to use our service, you will need a free Defensio API key. Get yours now at <a href="http://www.defensio.com/signup">Defensio.com</a>.</p> \t\t</div> ENDL; return; } print "<div>"; // TODO: Cache? // get stats $stats = defensio_get_stats(); if ($stats !== false) { $accuracy = number_format($stats['accuracy'] * 100, 2, '.', ''); $spam = $stats['spam']; $ham = $stats['ham']; $fn = $stats['false-negatives']; $fp = $stats['false-positives']; $apikey = $data['apikey']; print <<<ENDL \t\t<div class="defensio_stats" style="margin:10px;padding:5px;"> \t\t<div style="float:right;"><a href="http://defensio.com/manage/stats/{$apikey}">Detail Stats</a></div> \t\t<ul> \t\t\t<li><strong>Recent accuracy: {$accuracy}%</strong><hr></li> \t\t\t<li><strong>{$spam}</strong> spams, <strong>{$ham}</strong> legitimate comments</li> \t\t\t<li><strong>{$fn}</strong> false negatives (undetected spam)</li> \t\t\t<li><strong>{$fp}</strong> false positives (legitimate comments identified as spam)</li> \t\t</ul> \t\t</div> ENDL; } // get quarntines list list($comments, $paging) = defensio_get_data($comment_TYPE, $page, $perPage); include 'template/' . ($comment_TYPE == 'C' ? 'comment' : 'trackback') . '.php'; print "</div>"; }
/** * defensio_show_stats() * * @param mixed $defensio_conf * @return */ function defensio_show_stats($defensio_conf) { global $defensio; $last_updated = $defensio_conf['defensio_stats_updated_at']; $two_hours = 60 * 60 * 2; if ($last_updated == null or mktime() - $last_updated > $two_hours) { $stats_result = defensio_get_stats($defensio, $defensio_conf); } else { $stats_result = sxml_unserialize($defensio_conf['defensio_stats']); } if ($stats_result[1]->status == 'success') { $percentage = number_format((double) $stats_result[1]->accuracy * 100, 2, '.', ''); $stats = "<h2>Statistics</h2>\n \t<div style=\"float:right;width:32%;background:url('../addons/_defensio2.0/images/chart.gif') 0 15px no-repeat;padding-left:45px;\">\n\t\t\t<h3 style=\"font-size:10pt;margin-bottom: 4px;margin-top:-10px;\">There's more!</h3>\n \t<p style=\"margin:0px;\">For more detailed statistics (and gorgeous charts), please visit your Defensio <a href=\"http://defensio.com/manage/stats/" . $defensio_conf['key'] . "\" target=\"_blank\">Account Management</a> panel.</p>\n \t</div>"; if ($stats_result[1]->learning == 1) { $stats .= "<span style=\"clear:both;color:red;font-weight:bold;\">UNDEFINED LEARNING STATUS<br /><br /></span>"; } else { $stats .= "<span style=\"clear:both;\"> </span>"; } $unwanted = $stats_result[1]->unwanted; $stats .= "<ul id='defensio_stats'>\n \t\t<li class='defensio_statsline'><strong>Recent accuracy: " . $percentage . "%</strong></li>\n \t\t<li class='defensio_statsline'>" . (int) $unwanted->malicious . " malicious</li>\n <li class='defensio_statsline'>" . (int) $unwanted->spam . " spam</li>\n \t\t<li class='defensio_statsline'>" . (int) $stats_result[1]->legitimate->total . " legitimate comments</li>\n \t\t<li class='defensio_statsline'>" . (int) $stats_result[1]->{'false-negatives'} . " false negatives (undetected spam)</li>\n \t\t<li class='defensio_statsline'>" . (int) $stats_result[1]->{'false-positives'} . " false positives (legitimate comments identified as spam)</li>\n \t\t \t</ul>"; } else { $stats = "<p>Statistics could not be retrieved, please check back later.</p>"; } return $stats; }