Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20419
Modified Files:
Tag: branch-smarty
serendipity_event_spamblock.php
Log Message:
MFH
Index: serendipity_event_spamblock.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php,v
retrieving revision 1.4.2.11
retrieving revision 1.4.2.12
diff -u -d -r1.4.2.11 -r1.4.2.12
--- serendipity_event_spamblock.php 23 Sep 2004 13:24:09 -0000 1.4.2.11
+++ serendipity_event_spamblock.php 24 Sep 2004 09:43:22 -0000 1.4.2.12
@@ -217,7 +217,7 @@
$use_gd = true;
} else {
$max_char = $min_char = 5;
- $use_gd = true;
+ $use_gd = false;
}
switch($event) {
@@ -326,6 +326,7 @@
} 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 '<div style="background-color: ' . $hexval . '">';
for ($i = 1; $i <= $max_char; $i++) {
printf('<img src="%s" title="%s" alt="CAPTCHA ' . $i . '" class="captcha" />',
@@ -336,7 +337,7 @@
echo '</div>';
}
echo '</label><br />';
- echo PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '<input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
+ echo PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '<br /><input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
} elseif (isset($serendipity['POST']['captcha'])) {
echo '<input type="hidden" name="serendipity[captcha]" value="' . htmlspecialchars($serendipity['POST']['captcha']) . '" />';
}
@@ -366,20 +367,17 @@
$bgcolors = explode(',', $this->get_config('captcha_color', '255,255,255'));
$fontfiles = array('Comic_Sans_MS.ttf', 'Impact.ttf', 'Verdana.ttf');
- $chars = array(2, 3, 4, 7, 9); // 1, 5, 6 and 8 may look like characters.
- $chars = array_merge($chars, array('A','B','C','D','E','F','H','J','K','L','M','N','P','Q','R','T','U','V','W','X','Y','Z')); // I, O, S may look like numbers
- if ($use_gd || $parts[1] == '1') {
- $strings = array_rand($chars, mt_rand($max_char, $min_char));
- $string = '';
- foreach($strings AS $idx => $charidx) {
- $string .= $chars[$charidx];
+ if ($use_gd) {
+ $strings = $this->random_string($max_char, $min_char);
+ $fontname = $fontfiles[array_rand($fontfiles)];
+ $font = $serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/' . $fontname;
+
+ if (!file_exists($font)) {
+ // Search in shared plugin directory
+ $font = S9Y_INCLUDE_PATH . 'plugins/serendipity_event_spamblock/' . $fontname;
}
- $_SESSION['spamblock'] = array('captcha' => $string);
- }
- if ($use_gd) {
- $font = $serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/' . $fontfiles[array_rand($fontfiles)];
if (!file_exists($font)) {
die(PLUGIN_EVENT_SPAMBLOCK_ERROR_NOTTF);
}
@@ -404,7 +402,7 @@
$pos_y,
$color,
$font,
- $chars[$charidx]
+ $this->chars[$charidx]
);
$pos_x = $pos_x + $size + 2;
@@ -429,6 +427,20 @@
}
}
+ function random_string($max_char, $min_char) {
+ $this->chars = array(2, 3, 4, 7, 9); // 1, 5, 6 and 8 may look like characters.
+ $this->chars = array_merge($this->chars, array('A','B','C','D','E','F','H','J','K','L','M','N','P','Q','R','T','U','V','W','X','Y','Z')); // I, O, S may look like numbers
+
+ $strings = array_rand($this->chars, mt_rand($max_char, $min_char));
+ $string = '';
+ foreach($strings AS $idx => $charidx) {
+ $string .= $this->chars[$charidx];
+ }
+ $_SESSION['spamblock'] = array('captcha' => $string);
+
+ return $strings;
+ }
+
function log($logfile, $id, $switch, $reason, $comment) {
global $serendipity;
|