# $Workfile: misc_func.php3$ $Revision: 9$ $Date: 12/13/99 23:55:48$
/*
* W-AGORA
* -------
* File: Misc_func.php3
* Usage: Include file for common usage functions
* date: December 1999
* version: 3.0.1
* Author: Marc Druilhe
*/
if (isset($_POST['tkey']) && !empty($_POST['tkey']))
{
$tkey = $_POST['tkey'] + 0;
}
else if (isset($_GET['tkey']) && !empty($_GET['tkey']))
{
$tkey = $_GET['tkey'] + 0;
}
function msg ($number) {
global $site, $bn, $key, $note;
global $msg;
$mess=addSlashes(stripSlashes($msg[$number]));
eval ("\$m=stripSlashes(\"$mess\");");
return $m;
};
function dspMsg ($number) {
print msg($number);
};
function msgWarning ($message) {
$fontcolor="#FF2020";
print ("");
printf ("%s
", $fontcolor, $message);
};
function msgForm ($message, $url, $action="", $target="", $method="get") {
global $msg;
global $bn, $site;
global $frameset, $bn_frames, $bn_popup;
global $lynx, $form;
$fontcolor = "#000000";
if ($lynx==1) $bn_frames=0;
$base_url=strtok($url,"?");
$qs = strtok("?");
echo "
if ($frameset) {
?>
}
}
function displayUrl ($url, $target="", $text="", $status="") {
global $site, $bn, $lynx;
$url = preg_replace ("/[&?]+$/", "", $url);
if (!empty($site) && !preg_match ("/[&?]site=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "site=$site";
}
if (!empty($bn) && !preg_match ("/[&?]bn=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "bn=$bn";
}
if (!empty($lynx) && !preg_match ("/[&?]lynx=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "lynx=1";
}
$url = (preg_replace("/\s/", "+", $url));
$target = (empty($target) ) ? "" : " TARGET='$target'";
$text = empty($text) ? htmlSpecialChars($url) : $text;
$jsstatus = empty($status) ? "" : " onMouseover=\"window.status='" . addSlashes($status) . "';return true\" onMouseout=\"window.status='';return true\"";
printf ("%s", $url, $target, $jsstatus, $text);
}
function openWindow ($url, $text="", $status="", $width, $height) {
global $site, $bn, $lynx, $bn_popup;
$url = preg_replace ("/[&?]+$/", "", $url);
if (!empty($site) && !preg_match ("/[&?]site=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "site=$site";
}
if (!empty($bn) && !preg_match ("/[&?]bn=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "bn=$bn";
}
if (!empty($lynx) && !preg_match ("/[&?]lynx=/", $url) ) {
$url .= ( strpos($url, "?") != false ? "&" : "?" ). "lynx=1";
}
$url = (preg_replace("/\s/", "+", $url));
if ($bn_popup) {
$target = basename($bn). "_post";
} elseif ($bn_frames) {
$target = "main";
} else {
$target ="";
}
$text = empty($text) ? htmlSpecialChars($url) : $text;
$jsstatus = empty($status) ? "" : " onMouseover=\"window.status='" . addSlashes($status) . "';return true\" onMouseout=\"window.status='';return true\"";
printf ("%s", $url, (empty ($target)) ? "" : " TARGET='$target'", $jsstatus, $url, $target, $width, $height, $text);
}
// Copyrigth (c) Cooper Vert
function validate_email ($address) {
return (preg_match('/^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$/',
$address));
// For php5.2, just use this: return filter_var($address, FILTER_VALIDATE_EMAIL);
}
function checkURL($line) {
$addr_bad_chars = "()<>@,;\:[:space:][:cntrl:]";
$url_bad_chars = ")<>,;\"[:space:][:cntrl:]";
if ((eregi("href *=",$line)==0) && (eregi("img .*=",$line)==0) ) {
// if (eregi("href *=",$line)==0) {
if (eregi("(.*)(http:[^$url_bad_chars]+)(.*)", $line, $split)) {
$line=checkURL($split[1]) . "" . $split[2] . "" . checkURL($split[3]);
}
elseif (eregi("(.*)(www\.[^$url_bad_chars]+)(.*)", $line, $split)) {
$line=checkURL($split[1]) . "" . $split[2] . "" .checkURL( $split[3]);
}
elseif (eregi("(.*)(ftp:[^[:space:]]+)(.*)", $line, $split)) {
$line=checkURL($split[1]) . "" . $split[2] . "" .checkURL( $split[3]);
}
elseif (eregi("(.*)(ftp\.[^[:space:]]+)(.*)", $line, $split)) {
$line=checkURL($split[1]) . "" . $split[2] . "" .checkURL( $split[3]);
}
elseif (eregi("(.*)(mailto:[^[:space:]]+)(.*)", $line, $split)) {
$line=checkURL($split[1]) . "" . $split[2] . "" .checkURL( $split[3]);
}
elseif( eregi( "(.*)([[:space:](]+)([^$addr_bad_chars]*@[^$addr_bad_chars]*)([$addr_bad_chars]*)(.*)", $line, $split) ) {
$line = checkURL ( $split[1] ) . $split[2] . "" . $split[3] . "" . $split[4] . checkURL( $split[5] ) ;
}
}
return $line;
}
function jcheckUrl($line){
return preg_replace('/((?]+)/', '$1', $line);
}
function quote_text ($text) {
$text = my_br2nl ($text);
$lines = split ("\n", $text);
while ( list (,$line) = each($lines) ) {
$quoted_text .= "> $line\n";
}
return $quoted_text;
}
function my_br2nl ($text) {
$text=eregi_replace ("
\n", "\n", $text);
return eregi_replace ("
", "\n", $text);
}
function my_nl2br ($text) {
return str_replace (13, "", nl2br($text));
}
function emphasize ($text) {
if (preg_match ("/^>(.*)/", $text, $split) || preg_match ("/^>(.*)/i", $text, $split) )
$em_text = ">". $split[1] . "";
else
$em_text = $text;
return $em_text;
}
function format_text ($text) {
$text = my_nl2br($text);
$line = strtok ($text, "\n");
while ($line) {
$new_text .= jcheckUrl(emphasize($line)) . "\n";
$line = strtok ("\n");
}
return $new_text;
}
function jformat_text ($text) {
$text = preg_replace('/(?\s)$/m', '
', $text);
$line = strtok ($text, "\n");
while ($line) {
$new_text .= jcheckUrl(emphasize($line)) . "\n";
$line = strtok ("\n");
}
return $new_text;
}
function strip_banned_tags ($text) {
global $bn_banned_tags;
$banned_tags = split(" ", $bn_banned_tags);
// strip PHP tags
$text = preg_replace ("/<\\?/", "<?", $text);
$text = preg_replace ("/\\?>/", "?>", $text);
// kill javascript
$text = eregi_replace ("javascript:", "sorry_but_javascript_is_not_allowed:", $text);
// strip banned tags
if (is_array($banned_tags)) {
while ( list (,$badtag) = each($banned_tags) ) {
$text = eregi_replace("<(/*${badtag}[^>]*)>", "<\\1>", $text);
// $text = eregi_replace("<(/${badtag})>", "</\\1>", $text);
}
}
return $text;
}
function kill_html ($text) {
$text = str_replace ("<", "<", $text);
$text = str_replace (">", ">", $text);
return $text;
}
function kill_quotes ($text) {
$text = preg_replace ('/
/i', "\n", $text);
$text = str_replace ('"', """, $text);
$text = str_replace ("<", "<", $text);
$text = str_replace (">", ">", $text);
return $text;
}
function display_attachment ($key, $att_name, $att_type, $att_size) {
global $ext, $site, $bn, $bn_dir_notes;
switch (strtolower($att_type)) {
case "image/gif":
case "image/jpeg":
case "image/pjpeg":
echo "
\n";
break;
case "text/plain":
echo "";
$file = file ("$bn_dir_notes/$key/$att_name");
$size = count($file);
for ($i=0; $i < $size; $i++) {
echo (HtmlSpecialChars($file[$i]));
}
echo "
";
break;
case "text/html":
// ReadFile ("$bn_dir_notes/$key/$att_name");
$file = file ("$bn_dir_notes/$key/$att_name");
$size = count($file);
for ($i=0; $i < $size; $i++) {
echo (strip_banned_tags($file[$i]));
}
break;
default:
echo "\n";
DspMsg(57);
echo "$att_name (type : $att_type ) size: $att_size
\n";
break;
}
}
function table_header ($title, $width="95%") {
echo "";
echo "";
echo "$title \n\n";
}
function table_footer () {
echo "
\n";
}
# Form elements
# -------------
function beginForm ($action="", $method="post") {
global $site, $bn, $PHP_SELF;
$action = (empty ($action)) ? $PHP_SELF : $action;
printf ("";
}
function textField ($name, $value="", $size=0, $maxlength=0) {
printf ("\n",
$name,
($value == "") ? "" : " value=\"$value\"",
($size==0) ? "": " size=$size",
($maxlength==0) ? "": " maxlength=$maxlength"
);
}
function hiddenField ($name, $value) {
printf ("\n", $name, $value);
}
function passwordField ($name, $value="", $size=0, $maxlength=0) {
printf ("\n",
$name,
($value == "") ? "" : " value=\"$value\"",
($size==0) ? "": " size=$size",
($maxlength==0) ? "": " maxlength=$maxlength"
);
}
function textArea ($name, $value="", $rows=2, $cols=40, $wrap="logical") {
printf ("\n",
$name, $rows, $cols, $wrap, $value);
}
function listBox ($name, $values, $selected="", $multiple=0) {
printf ("\n";
}
function checkBox ($name, $value=1, $current, $text="") {
printf ("%s\n",
$name,
$value, ($current==$value)? " checked" : "",
(empty ($text)) ? "" : " $text" );
}
function radioButton ($name, $value=1, $current, $text="") {
printf ("%s\n",
$name,
$value, ($current==$value)? " checked" : "",
(empty ($text)) ? "" : " $text" );
}
function caption ($text, $tag="") {
$bt = empty($tag) ? "" : "<$tag>";
$et = empty($tag) ? "" : "$tag>";
printf ("%s%s%s \n", $bt, $text, $et);
}
function submitButton ($name="", $value="Save") {
printf ("\n", empty($name) ? "" : "name=\"$name\"", $value);
}
function backButton ($name="", $value=" << ") {
?>
}
function resetButton ($name="", $value="Reset") {
printf ("\n", empty($name) ? "" : "name=\"$name\"", $value);
}
function br () {
print "
\n";
}
function wa_version () {
return "w-agora version 3.0.1";
}
?>

%s |
\n", "\n", $text); return eregi_replace ("
", "\n", $text); } function my_nl2br ($text) { return str_replace (13, "", nl2br($text)); } function emphasize ($text) { if (preg_match ("/^>(.*)/", $text, $split) || preg_match ("/^>(.*)/i", $text, $split) ) $em_text = ">". $split[1] . ""; else $em_text = $text; return $em_text; } function format_text ($text) { $text = my_nl2br($text); $line = strtok ($text, "\n"); while ($line) { $new_text .= jcheckUrl(emphasize($line)) . "\n"; $line = strtok ("\n"); } return $new_text; } function jformat_text ($text) { $text = preg_replace('/(?\s)$/m', '
', $text); $line = strtok ($text, "\n"); while ($line) { $new_text .= jcheckUrl(emphasize($line)) . "\n"; $line = strtok ("\n"); } return $new_text; } function strip_banned_tags ($text) { global $bn_banned_tags; $banned_tags = split(" ", $bn_banned_tags); // strip PHP tags $text = preg_replace ("/<\\?/", "<?", $text); $text = preg_replace ("/\\?>/", "?>", $text); // kill javascript $text = eregi_replace ("javascript:", "sorry_but_javascript_is_not_allowed:", $text); // strip banned tags if (is_array($banned_tags)) { while ( list (,$badtag) = each($banned_tags) ) { $text = eregi_replace("<(/*${badtag}[^>]*)>", "<\\1>", $text); // $text = eregi_replace("<(/${badtag})>", "</\\1>", $text); } } return $text; } function kill_html ($text) { $text = str_replace ("<", "<", $text); $text = str_replace (">", ">", $text); return $text; } function kill_quotes ($text) { $text = preg_replace ('/
/i', "\n", $text); $text = str_replace ('"', """, $text); $text = str_replace ("<", "<", $text); $text = str_replace (">", ">", $text); return $text; } function display_attachment ($key, $att_name, $att_type, $att_size) { global $ext, $site, $bn, $bn_dir_notes; switch (strtolower($att_type)) { case "image/gif": case "image/jpeg": case "image/pjpeg": echo "
"; $file = file ("$bn_dir_notes/$key/$att_name"); $size = count($file); for ($i=0; $i < $size; $i++) { echo (HtmlSpecialChars($file[$i])); } echo ""; break; case "text/html": // ReadFile ("$bn_dir_notes/$key/$att_name"); $file = file ("$bn_dir_notes/$key/$att_name"); $size = count($file); for ($i=0; $i < $size; $i++) { echo (strip_banned_tags($file[$i])); } break; default: echo "
\n"; DspMsg(57); echo "$att_name | (type : $att_type ) |
size: $att_size |
";
echo "
|
\n"; } function wa_version () { return "w-agora version 3.0.1"; } ?>



