<?php
/*##################
UPDATE Nov 2016 v.2.1.4
##################*/
include("./config.php");
include("./lang.php");
// array_to_string and string_to_array functions
// originally by daenders AT yahoo DOT com on php.net
function array_to_string($array)
{
$retval = '';
foreach ($array as $index => $value)
{
$retval .= urlencode(base64_encode($index)) . '|' . urlencode(base64_encode($value)) . '||';
}
return urlencode(substr($retval, 0, -2));
}
function string_to_array($string)
{
$retval = array();
$string = urldecode($string);
$tmp_array = explode('||', $string);
foreach ($tmp_array as $tmp_val)
{
list($index, $value) = explode('|', $tmp_val);
$retval[base64_decode(urldecode($index))] = base64_decode(urldecode($value));
}
return $retval;
}
function check_words($string,$banwordz)
{
for($i=0;$i<sizeof($banwordz);$i++)
{
$string=preg_replace("/$banwordz[$i]/", "****", $string);
}
return $string;
}
function check_ip($baedipz)
{
$isokay = true;
foreach($baedipz as $banip)
{
if ($_SERVER['REMOTE_ADDR'] == $banip)
{
$isokay = false;
}
}
$banlist = file("./bans.txt");
foreach($banlist as $banip)
{
if($_SERVER['REMOTE_ADDR'] == str_replace(array("n","r"),"",$banip))
{
$isokay = false;
}
}
return $isokay;
}
function getTagName($text,$cnt)
{
while(($cnt < strlen($text))&&(preg_match("/[^a-z0-9]/i",substr($text,$cnt,1))))$cnt++;
$tagNameStart=$cnt;
while(($cnt < strlen($text))&&(!preg_match("/[^a-z0-9]/i",substr($text,$cnt,1))))$cnt++;
return substr($text,$tagNameStart,$cnt-$tagNameStart);
}
function getTagEnd($text,$cnt)
{
return strpos($text,">",$cnt);
}
function closeUnclosedTags($text)
{
$openedTags=array();
$cnt=0;
while(($cnt < strlen($text))&&(true))
{
if(substr($text,$cnt,2)=="</")
{
$tagEnd=getTagEnd($text,$cnt);
$tagName=getTagName($text,$cnt);
$lastOpenedTag=array_pop($openedTags);
if($lastOpenedTag==NULL)
{
//error: no tag was opened - delete the close tag
$text=substr($text,0,$cnt).substr($text,$tagEnd+1);
}
elseif($lastOpenedTag!=$tagName)
{
//error: closing unopened tag (possible cross-nesting) - return the original opened tag and delete the close tag
array_push($openedTags,$lastOpenedTag);
$text=substr($text,0,$cnt).substr($text,$tagEnd+1);
}
else
{
$cnt=$tagEnd+1;
}
}
elseif(substr($text,$cnt,1)=="<")
{
$tagEnd=getTagEnd($text,$cnt);
$tagName=getTagName($text,$cnt);
if(substr($text,$tagEnd-1,1)!="/")
array_push($openedTags,$tagName);
$cnt=$tagEnd+1;
}
else
{
$cnt++;
}
}
while(count($openedTags)>0)$text.="</".array_pop($openedTags).">";
return $text;
}
function parse_smileys($string)
{
$smileylist = array();
$i = 0;
if ($handle = opendir('./smileys/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file != "Thumbs.db")
{
$smileylist[$i] = str_replace(".gif", "", $file);
$i++;
}
}
closedir($handle);
}
foreach ($smileylist as $smileycheck)
{
$string = str_replace(":".$smileycheck.":", "<img src="smileys/".$smileycheck.".gif" alt="smiley">", $string);
}
return $string;
}
function is_url($url){
// http, https. ftp
$regex = "`^(https?://|ftp://)(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?" . //user@
"(([0-9]{1,3}.){3}[0-9]{1,3}" . // IP
"|" . // allows either IP or domain
"([0-9a-z_!~*'()-]+.)*" . // tertiary domain(s)
"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]." . // second level domain
"[a-z]{2,6})" . // first level domain
"(:[0-9]{1,4})?" . // port number
"((/?)|" . // a slash isn't required if there is no file name
"(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$`"; //filename
// www.
$regex2 = "`^(www.)(" . //www.
"([0-9a-z_!~*'()-]+.)*" . // tertiary domain(s)
"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]." . // second level domain
"[a-z]{2,6})" . // first level domain
"(:[0-9]{1,4})?" . // port number
"((/?)|" . // a slash isn't required if there is no file name
"(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$`"; //filename
return (preg_match($regex, $url) || preg_match($regex2, $url));
}
function is_email($email){
$regex = "`^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$`";
return preg_match($regex, $email);
}
function parse_links($msg)
{
$words = explode(" ", $msg);
$new = array();
foreach($words as $word)
{
if(is_url($word))
if(substr($word,0,4)=="www.")
$word = "<a href="http://".$word."" target="_blank"><b>[link]</b></a>";
else
$word = "<a href="".$word."" target="_blank"><b>[link]</b></a>";
if(is_email($word))
$word = "<a href="contact".$word."" target="_blank"><b>[mail]</b></a>";
$new[] = $word;
}
return implode(" ", $new);
}
//############################################################
// begin actual script
//############################################################
if(isset($_COOKIE['remembername']))
{
$cookiename=$_COOKIE['remembername'];
}
else
{
$cookiename=$lang["name"];
}
if(isset($_COOKIE['rememberurl']))
{
$cookieurl=$_COOKIE['rememberurl'];
}
else
{
$cookieurl="http://";
}
if(isset($_GET['act']))
{
$act = $_GET['act'];
}
else
{
$act = "null";
}
switch($act)
{
case "tag":
//############################################################
if (!check_ip($baedips))
{
die("<span style="background-color:#888"><strong>".$lang["error"]." ".$lang["baed"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
$tagname = $_POST['tagname'];
$tagmsg = $_POST['tagmsg'];
$tagurl = "http://";
if (!isset($_POST['tagname']) || !$_POST['tagmsg'] || $tagname == "Naam" || $tagname == "" || $tagmsg == "" )
{
die("<span style="background-color:#555"><strong>".$lang["error"]." ".$lang["fillin"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
$tagname = strip_tags(check_words($tagname,$banwords));
if (strlen($tagname) > $maxname)
{
die("<span style="background-color:#444"><strong>".$lang["error"]." ".str_replace("%1",$maxname,$lang["longname"])."</strong><br><a href="index2.php">".$lang
["back"]."</a></span>");
}
$tagmsg = strip_tags(check_words($tagmsg,$banwords),$allowedhtml);
$tagmsg = str_replace("style=", "alt=", $tagmsg);
$tagmsg = closeUnclosedTags($tagmsg);
if (strlen($tagmsg) > $maxsize)
{
die("<span style="background-color:#333"><strong>".$lang["error"]." ".str_replace("%1",$maxsize,$lang["longmsg"])."</strong><br><a href="index2.php">".$lang
["back"]."</a></span>");
}
$tagurl = "http://";
if (!empty($tagurl) && (substr($tagurl, 0, 7) != "http://"))
{
die("<span style="background-color:#222"><strong>".$lang["error"]." ".$lang["badurl"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
if (!empty($_COOKIE['floodprotect']))
{
$cookietime = time() - $_COOKIE['floodprotect'];
if ($cookietime <= $floodtimer)
{
die("<span style="background-color:#444"><strong>".$lang["error"]." ".$lang["flood"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
}
if ($doublepostblock)
{
$lines = file("./db.txt");
$numlines = count($lines);
$lastpost = string_to_array($lines[$numlines-1]);
if($lastpost[3] == $_SERVER['REMOTE_ADDR'])
{
die("<span style="background-color:#fff"><strong>".$lang["error"]." ".$lang["flood"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
}
//####################
$langupper= strtoupper($lang["admiame"]);
$langlower= strtolower($lang["admiame"]);
if($tagname == $langupper || $tagname == $langlower){
//session_start();
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==md5(md5($adminpass)))
{
}else{
die("<span style="background-color:#fff"><strong>".$lang["error"]." ".$lang["notadmin"]."</strong><br><a href="index2.php">".$lang["back"]."</a></span>");
}
}
//#######################
setcookie("floodprotect", time(), time()+100);
setcookie("remembername", $tagname, time()+10000000);
setcookie("rememberurl", $tagurl, time()+10000000);
$postit = array();
$postit[] = 0;
$postit[] = $tagname;
$postit[] = $tagurl;
$postit[] = $_SERVER['REMOTE_ADDR'];
$postit[] = $tagmsg;
$postit[] = time();
$tagdb = fopen("./db.txt", "a+");
if (!fwrite($tagdb, array_to_string($postit)."n"))
{
die("CHMOD db.txt to 666");
}
fclose($tagdb);
echo "<script>window.location='index2.php';</script>";
break; case "info":
//########################################################
include("./header.php");
echo "n<div class="taga"><strong>".$lang["smileys"]."</strong></div>n";
echo "<table style="width:100%;border:0" class="tagb" cellspacing="5" cellpadding="0>n";
$smileylist = array();
$i = 0;
if ($handle = opendir('./smileys/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$smileylist[$i] = str_replace(".gif", "", $file);
$i++;
}
}
closedir($handle);
}
foreach ($smileylist as $smileyshow)
{
echo "<tr><td align="right">:".$smileyshow.":</td><td align="left"><img src="smileys/".$smileyshow.".gif" alt="smiley"></td></tr>n";
}
echo "</table>n";
echo "<div class="taga"><strong>".$lang["html"]."</strong></div>n";
echo "<div class="tagb">";
echo str_replace(",","<br>",str_replace(">",">",str_replace("<","<",$allowedhtml)));
echo "</div>n";
echo "<div class="formarea">Powered by <strong><a href="http://www.marcelhofman.com/scripts/tagbox" target="_blank">tagBox ".$versie."</a></strong></div>n";
echo "</body>n";
echo "</html>";
break; case "history":
//########################################################
include("./header.php");
$lines = file("./db.txt");
$numlines = count($lines);
if($reverse_posts)
{
$lines = array_reverse($lines);
}
$numlines = count($lines);
echo "n<div style="text-align:center"><strong>".$lang["history"]."</strong><br>".str_replace("%1",$numlines,$lang["numtags"])."</div>n";
$i = 0;
$ab = 0;
while( $i < $numlines )
{
$thistag = string_to_array($lines[$i]);
$thistag[4] = parse_smileys($thistag[4]);
if(!$thistag[2] || ($thistag[2]=="http://"))
{
$thistag[2] = "<a href="#">";
}
else
{
$thistag[2] = "<a href="".$thistag[2]."" target="_blank">";
}
if($timestamps_enabled&&$thistag[5])
{
$timestamp = date($timestamp_format,$thistag[5])." »";
}
else
{
$timestamp="";
}
if($linkparsing)
{
$message = parse_links(stripslashes($thistag[4]));
}
else
{
$message = stripslashes($thistag[4]);
}
if(!$ab)
{
echo "<div class="taga">".$timestamp."<strong>".$thistag[2].stripslashes($thistag[1])."</a> »</strong> ".$message."</div>n";
$ab = 1;
}
else
{
echo "<div class="tagb">".$timestamp."<strong>".$thistag[2].stripslashes($thistag[1])."</a> »</strong> ".$message."</div>n";
$ab = 0;
}
$i++;
}
echo "</body>n";
echo "</html>";
break; default:
//########################################################
include("./header.php");
if($clickable_smileys)
{
echo "<div class="formarea">";
$smileylist = array();
$i = 0;
if ($handle = opendir('./smileys/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file != "Thumbs.db")
{
$smileylist[$i] = str_replace(".gif", "", $file);
$i++;
}
}
closedir($handle);
}
foreach ($smileylist as $smileyshow)
{
echo "<img src="smileys/".$smileyshow.".gif" onclick="addSmiley('".$smileyshow."');" alt="smiley"> ";
}
echo "</div>";
}
include("./footer.php");
break;
}
?>
برچسب:
نویسنده: آیلین رضوانی