From c07e07fc9cf144719722959d66c38c08e34993a1 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Mon, 26 Mar 2007 09:37:41 +0000 Subject: [PATCH] Show current captcha look in the plugin configuration menu --- docs/NEWS | 3 + .../lang_en.inc.php | 2 + .../serendipity_event_spamblock.php | 69 ++++++++++++------- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index f42d116..2987584 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 1.2 () ------------------------------------------------------------------------ + * Show current captcha look in the plugin configuration menu + (garvinhicking) + * Add new category property to hide blog postings made into sub- categories from the frontend view, per category. Thanks to netmorix from the forums! (garvinhicking) diff --git a/plugins/serendipity_event_spamblock/lang_en.inc.php b/plugins/serendipity_event_spamblock/lang_en.inc.php index 4c86ff6..9622436 100644 --- a/plugins/serendipity_event_spamblock/lang_en.inc.php +++ b/plugins/serendipity_event_spamblock/lang_en.inc.php @@ -121,3 +121,5 @@ @define('PLUGIN_EVENT_SPAMBLOCK_HTACCESS', 'Block bad IPs via HTaccess?'); @define('PLUGIN_EVENT_SPAMBLOCK_HTACCESS_DESC', 'Enabling this will add IPs that have sent spam to your blog to your .htaccess file. The .htaccess file will be regenerated regularly with the forbidden IPs of the last month.'); + +@define('PLUGIN_EVENT_SPAMBLOCK_LOOK', 'This is how your captcha images currently look like. If you changed and saved settings above and want to refresh the look of your captcha, simply click on it to reload.'); \ No newline at end of file diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index c47d757..225697a 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -39,7 +39,7 @@ var $filter_defaults; 'smarty' => '2.6.7', 'php' => '4.1.0' )); - $propbag->add('version', '1.65'); + $propbag->add('version', '1.66'); $propbag->add('event_hooks', array( 'frontend_saveComment' => true, 'external_plugin' => true, @@ -389,12 +389,12 @@ var $filter_defaults; $q = "SELECT ip FROM {$serendipity['dbPrefix']}spamblock_htaccess WHERE timestamp > " . (time() - 86400*2) . " GROUP BY ip"; $rows = serendipity_db_query($q, false, 'assoc'); - + $deny = array(); foreach($rows AS $row) { $deny[] = $row['ip']; } - + $hta = $serendipity['serendipityPath'] . '.htaccess'; if (file_exists($hta) && is_writable($hta)) { $htaccess = file_get_contents($hta); @@ -415,7 +415,7 @@ var $filter_defaults; } } } - + function &getBlacklist($where, $api_key = '', &$eventData, &$addData) { global $serendipity; @@ -598,7 +598,7 @@ var $filter_defaults; // Their IPs will be constantly blocked. function IsHardcoreSpammer() { global $serendipity; - + if (serendipity_db_bool($this->get_config('automagic_htaccess'))) { $this->htaccess_update($_SERVER['REMOTE_ADDR']); } @@ -630,6 +630,44 @@ var $filter_defaults; return false; } + function example() { + echo '
' . PLUGIN_EVENT_SPAMBLOCK_LOOK . '
'; + $this->show_captcha(); + echo '
'; + } + + function show_captcha($use_gd = false) { + global $serendipity; + + if ($use_gd || (function_exists('imagettftext') && function_exists('imagejpeg'))) { + $max_char = 5; + $min_char = 3; + $use_gd = true; + } else { + $max_char = $min_char = 5; + $use_gd = false; + } + + if ($use_gd) { + printf('CAPTCHA', + $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()), + htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2) + ); + } else { + $bgcolors = explode(',', $this->get_config('captcha_color', '255,0,255')); + $hexval = '#' . dechex(trim($bgcolors[0])) . dechex(trim($bgcolors[1])) . dechex(trim($bgcolors[2])); + $this->random_string($max_char, $min_char); + echo '
'; + for ($i = 1; $i <= $max_char; $i++) { + printf('CAPTCHA ' . $i . '', + $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . $i . '_' . md5(time()), + htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2) + ); + } + echo '
'; + } + } + function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; @@ -704,7 +742,7 @@ var $filter_defaults; } } } - + /* if ($addData['type'] != 'NORMAL' && empty($addData['name'])) { $eventData = array('allow_coments' => false); @@ -1048,24 +1086,7 @@ var $filter_defaults; echo '
'; if (!isset($serendipity['POST']['preview']) || strtolower($serendipity['POST']['captcha'] != strtolower($_SESSION['spamblock']['captcha']))) { echo '
' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '
'; - if ($use_gd) { - printf('CAPTCHA', - $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()), - htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2) - ); - } else { - $bgcolors = explode(',', $this->get_config('captcha_color', '255,0,255')); - $hexval = '#' . dechex(trim($bgcolors[0])) . dechex(trim($bgcolors[1])) . dechex(trim($bgcolors[2])); - $this->random_string($max_char, $min_char); - echo '
'; - for ($i = 1; $i <= $max_char; $i++) { - printf('CAPTCHA ' . $i . '', - $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . $i . '_' . md5(time()), - htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2) - ); - } - echo '
'; - } + $this->show_captcha($use_gd); echo '
'; echo '
'; } elseif (isset($serendipity['POST']['captcha'])) { -- 2.39.5