You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
4.5 KiB
235 lines
4.5 KiB
<?
|
|
//
|
|
// "$Id: common.php,v 1.1 2004/05/17 03:23:06 mike Exp $"
|
|
//
|
|
// Common utility functions for PHP pages...
|
|
//
|
|
// Contents:
|
|
//
|
|
// quote_text() - Quote a string...
|
|
// sanitize_email() - Convert an email address to something a SPAMbot
|
|
// can't read...
|
|
// sanitize_text() - Sanitize text.
|
|
//
|
|
|
|
//
|
|
// 'quote_text()' - Quote a string...
|
|
//
|
|
|
|
function // O - Quoted string
|
|
quote_text($text, // I - Original string
|
|
$quote = 0) // I - Add ">" to front of message
|
|
{
|
|
$len = strlen($text);
|
|
$col = 0;
|
|
|
|
if ($quote)
|
|
$qtext = "> ";
|
|
else
|
|
$qtext = "";
|
|
|
|
for ($i = 0; $i < $len; $i ++)
|
|
{
|
|
switch ($text[$i])
|
|
{
|
|
case '<' :
|
|
$col ++;
|
|
$qtext .= "<";
|
|
break;
|
|
|
|
case '>' :
|
|
$col ++;
|
|
$qtext .= ">";
|
|
break;
|
|
|
|
case '&' :
|
|
$col ++;
|
|
$qtext .= "&";
|
|
break;
|
|
|
|
case "\n" :
|
|
if ($quote)
|
|
$qtext .= "\n> ";
|
|
else
|
|
$qtext .= "<br />";
|
|
|
|
$col = 0;
|
|
break;
|
|
|
|
case "\r" :
|
|
break;
|
|
|
|
case "\t" :
|
|
if ($col == 0)
|
|
$qtext .= " ";
|
|
else
|
|
$qtext .= " ";
|
|
break;
|
|
|
|
case " " :
|
|
if ($col == 0 || $text[$i + 1] == " ")
|
|
$qtext .= " ";
|
|
else if ($col > 65 && $quote)
|
|
{
|
|
$qtext .= "\n> ";
|
|
$col = 0;
|
|
}
|
|
else
|
|
$qtext .= " ";
|
|
|
|
if ($col > 0)
|
|
$col ++;
|
|
break;
|
|
|
|
case 'f' :
|
|
case 'h' :
|
|
if (substr($text, $i, 7) == "http://" ||
|
|
substr($text, $i, 8) == "https://" ||
|
|
substr($text, $i, 6) == "ftp://")
|
|
{
|
|
// Extract the URL and make this a link...
|
|
for ($j = $i; $j < $len; $j ++)
|
|
if ($text[$j] == " " || $text[$j] == "\n" || $text[$j] == "\r" ||
|
|
$text[$j] == "\t" || $text[$j] == "\'" || $text[$j] == "'")
|
|
break;
|
|
|
|
$count = $j - $i;
|
|
$url = substr($text, $i, $count);
|
|
$qtext .= "<a href='$url'>$url</a>";
|
|
$col += $count;
|
|
$i = $j - 1;
|
|
break;
|
|
}
|
|
|
|
default :
|
|
$col ++;
|
|
$qtext .= $text[$i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $qtext;
|
|
}
|
|
|
|
|
|
//
|
|
// 'sanitize_email()' - Convert an email address to something a SPAMbot
|
|
// can't read...
|
|
//
|
|
|
|
function // O - Sanitized email
|
|
sanitize_email($email, // I - Email address
|
|
$html = 1) // I - HTML format?
|
|
{
|
|
$nemail = "";
|
|
$len = strlen($email);
|
|
|
|
for ($i = 0; $i < $len; $i ++)
|
|
{
|
|
switch ($email[$i])
|
|
{
|
|
case '@' :
|
|
if ($i > 0)
|
|
$i = $len;
|
|
else if ($html)
|
|
$nemail .= " <I>at</I> ";
|
|
else
|
|
$nemail .= " at ";
|
|
break;
|
|
|
|
case '<' :
|
|
if ($i > 0)
|
|
$i = $len;
|
|
break;
|
|
|
|
case '>' :
|
|
break;
|
|
|
|
case '&' ;
|
|
$nemail .= "&";
|
|
break;
|
|
|
|
default :
|
|
$nemail .= $email[$i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
return trim($nemail);
|
|
}
|
|
|
|
|
|
//
|
|
// 'sanitize_text()' - Sanitize text.
|
|
//
|
|
|
|
function // O - Sanitized text
|
|
sanitize_text($text) // I - Original text
|
|
{
|
|
$len = strlen($text);
|
|
$word = "";
|
|
$qtext = "";
|
|
|
|
for ($i = 0; $i < $len; $i ++)
|
|
{
|
|
switch ($text[$i])
|
|
{
|
|
case "\n" :
|
|
if (!strncmp($word, "http://", 7) ||
|
|
!strncmp($word, "https://", 8) ||
|
|
!strncmp($word, "ftp://", 6))
|
|
$qtext .= "<a href='$word'>$word</a>";
|
|
else if (strchr($word, '@'))
|
|
$qtext .= sanitize_email($word);
|
|
else
|
|
$qtext .= quote_text($word);
|
|
|
|
$qtext .= "<br />";
|
|
$word = "";
|
|
break;
|
|
|
|
case "\r" :
|
|
break;
|
|
|
|
case "\t" :
|
|
case " " :
|
|
if (!strncmp($word, "http://", 7) ||
|
|
!strncmp($word, "https://", 8) ||
|
|
!strncmp($word, "ftp://", 6))
|
|
$qtext .= "<a href='$word'>$word</a>";
|
|
else if (strchr($word, '@'))
|
|
$qtext .= sanitize_email($word);
|
|
else
|
|
$qtext .= quote_text($word);
|
|
|
|
if ($word)
|
|
$qtext .= " ";
|
|
else
|
|
$qtext .= " ";
|
|
|
|
$word = "";
|
|
break;
|
|
|
|
default :
|
|
$word .= $text[$i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!strncmp($word, "http://", 7) ||
|
|
!strncmp($word, "https://", 8) ||
|
|
!strncmp($word, "ftp://", 6))
|
|
$qtext .= "<a href='$word'>$word</a>";
|
|
else if (strchr($word, '@'))
|
|
$qtext .= sanitize_email($word);
|
|
else
|
|
$qtext .= quote_text($word);
|
|
|
|
return $qtext;
|
|
}
|
|
|
|
|
|
//
|
|
// End of "$Id: common.php,v 1.1 2004/05/17 03:23:06 mike Exp $".
|
|
//
|
|
?>
|
|
|