cvs: php-news-web / article.php common.inc
| From: | Wez Furlong | Date: | Mon, 19 May 2003 16:28:05 +0000 |
| Subject: | cvs: php-news-web / article.php common.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-17807@lists.php.net to get a copy of this message | ||
wez Mon May 19 12:28:05 2003 EDT
Modified files:
/php-news-web article.php common.inc
Log:
primitive spam protection of email addresses
Index: php-news-web/article.php
diff -u php-news-web/article.php:1.21 php-news-web/article.php:1.22
--- php-news-web/article.php:1.21 Wed Jan 15 23:24:54 2003
+++ php-news-web/article.php Mon May 19 12:28:05 2003
@@ -159,7 +159,7 @@
echo "<blockquote>\n";
echo '<table border="0" cellpadding="2" cellspacing="2"
width="100%">';
# from
- echo '<tr><td class="headerlabel">From:</td><td
class="headervalue">'.format_author($headers[from],
$charset)."</td>\n";
+ echo '<tr><td class="headerlabel">From:</td><td
class="headervalue">'.format_author($headers['from'],
$charset)."</td>\n";
# date
echo '<td class="headerlabel">Date:</td><td
class="headervalue">'.format_date($headers["date"])."</td></tr>\n";
# subject
Index: php-news-web/common.inc
diff -u php-news-web/common.inc:1.21 php-news-web/common.inc:1.22
--- php-news-web/common.inc:1.21 Fri Mar 7 13:56:51 2003
+++ php-news-web/common.inc Mon May 19 12:28:05 2003
@@ -90,16 +90,31 @@
return preg_replace("/=\\?(.+?)\\?([qb])\\?(.+?)\\?=/ie",
"decode_header('\\1','\\2','\\3')", $header);
}
+/* Email spam protection (taken from php-bugs-web) */
+function spam_protect($txt)
+{
+ $translate = array('@' => ' at ', '.' => ' dot ');
+
+ /* php.net addresses are not protected! */
+ if (preg_match('/^(.+)@php\.net/i', $txt)) {
+ return $txt;
+ } else {
+ return strtr($txt, $translate);
+ }
+}
+
+
# this turns some common forms of email addresses into mailto: links
function format_author($a, $charset) {
$a = recode_header($a, $charset);
if (preg_match("/^\s*(.+)\s+\\(\"?(.+?)\"?\\)\s*$/",$a,$ar)) {
- return "<a href=\"mailto:".htmlspecialchars(urlencode($ar[1]))."\">".str_replace("
", " ", htmlspecialchars($ar[2]))."</a>";
+ return "<a href=\"mailto:".htmlspecialchars(urlencode(spam_protect($ar[1])))."\">".str_replace("
", " ", htmlspecialchars($ar[2]))."</a>";
}
if (preg_match("/^\s*\"?(.+?)\"?\s*<(.+)>\s*$/",$a,$ar)) {
- return "<a href=\"mailto:".htmlspecialchars(urlencode($ar[2]))."\">".str_replace("
", " ", htmlspecialchars($ar[1]))."</a>";
+ return "<a href=\"mailto:".htmlspecialchars(urlencode(spam_protect($ar[2])))."\">".str_replace("
", " ", htmlspecialchars($ar[1]))."</a>";
}
if (ereg("@",$a)) {
+ $a = spam_protect($a);
return "<a href=\"mailto:".htmlspecialchars(urlencode($a))."\">".htmlspecialchars($a)."</a>";
}
return str_replace(" ", " ", htmlspecialchars($a));