|
Reisebrev
/////////////// SignMe 1.1 ///////////////
// Written in July 2004 //
// by Lukas Stalder //
// contact: support@planetluc.com //
// read INSTALL.txt for installation //
// instructions. //
// Visit www.planetluc.com! //
// enjoy it! //
//////////////////////////////////////////////
// ************************** CONFIG **************************
// ************************************************************
$ppp = 10; // posts to display per page
$adminname = "vitre";
$adminpwd = "erkule";
$adminexpire = 5*60; // time in seconds until admin has to relogin
$pathtoscript = ""; // eg if you call the script from within a file in a top level folder you have to put "folder_to_signme/". Otherwise leave it blank "".
$wrap = 100; // max. length of a word (to avoid bad entries like "hhhheeeeeeeeelllllllllllloooooooooo" that destroy your design)
// language setttings
$txtsign = "Skriv ny"; // menu item text
$txtview = "Vis alle"; // menu item text
$txtadmin = "Rediger/slett"; // menu item text
$txtbadname = "Du skreiv ikke inn noe navn";
$txtbademail = "Du skreiv inn ei ugyldig e-postadresse";
$txtbadmsg = "Du skreiv ikke inn noen melding";
$txtclickback = "Klikk tilbake i browseren din!";
$txterrors = "Aiaiai, den går ikke:";
$txtedit = "rediger";
$txtdelete = "slett";
$txtoptional = "optimalt";
// list badwords here seperated by comma
$badwords = "knull";
// ************************** STYLE DEFs **********************
// ************************************************************
?>
// ************************** misc other variables - do not change **********************
// ************************************ below here! *************************************
// ************************* unless you know what you're doing **************************
$dat=$pathtoscript."data.dat";
$template=$pathtoscript."template.inc.php";
$log=$pathtoscript."log.dat.php";
$badwords=explode(",", $badwords);
$me= $_SERVER['PHP_SELF'];
$empty=false;
$now=time();
$version="v1.1";
if (!isset($_GET['hash']) || $_GET['hash']=="") {
srand($now);
for ($i=0; $i<16 ; $i++) $secret.=chr(rand(60, 127));
$secret=md5($secret);
$hash=md5($_SERVER['HTTP_USER_AGENT'].$now.$secret);
}else $hash= $_GET['hash'];
$getvars="?hash=$hash";
if (isset($_REQUEST['do'])) $do=$_REQUEST['do'];
if (isset($_REQUEST['id'])) $id=$_REQUEST['id'];
if (isset($_REQUEST['action'])) $action=$_REQUEST['action'];
if (isset($_REQUEST['name'])) $name=$_REQUEST['name'];
if (isset($_REQUEST['pwd'])) $pwd=$_REQUEST['pwd'];
if (isset($_REQUEST['email'])) $email=$_REQUEST['email'];
if (isset($_REQUEST['www'])) $www=$_REQUEST['www'];
if (isset($_REQUEST['msg'])) $msg=$_REQUEST['msg'];
if (isset($_REQUEST['time'])) $time=$_REQUEST['time'];
if (isset($_REQUEST['from'])) $from=$_REQUEST['from']; else $from=1;
// ************************** functions ***********************
// ************************************************************
class mdasort {
var $data;
var $sortkeys;
function _sortcmp($a, $b, $i=0) {
$r = strnatcmp($a[$this->sortkeys[$i][0]],$b[$this->sortkeys[$i][0]]);
if ($this->sortkeys[$i][1] == "DESC") $r = $r * -1;
if($r==0) {
$i++;
if ($this->sortkeys[$i]) $r = $this->_sortcmp($a, $b, $i);
}
return $r;
}
function msort() {
if(count($this->sortkeys)) {
usort($this->data,array($this,"_sortcmp"));
}
}
}
function getkey($index, $stuff){
foreach ($stuff->data as $key => $item){
if ($item['id']==$index){
$ret=$key;
break;
}
}
return $ret;
}
function validemail($addr){
return eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$", $addr);
}
function clearoldadmins() {
global $log, $now, $adminexpire;
include($log);
if (count($admins)>0){
$i=0;
$fp=fopen($log, "w");
fputs($fp, "\n");
foreach ($admins as $line){
if ($now-$line['time']<$adminexpire)
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
fputs($fp, "?>");
fclose($fp);
}
}
function saveposts($stuff){
global $dat;
$fp=fopen($dat, "w");
foreach ($stuff->data as $post){
$line=$post['id']."|".$post['time']."|".$post['name']."|".$post['email']."|".$post['www']."|".$post['post']."\n";
fputs($fp, $line);
}
fclose($fp);
}
function isloggedin() {
global $log, $now, $adminexpire;
include($log);
$logged=false;
if (count($admins)>0){
foreach ($admins as $line){
if ($line['hash']==md5($_GET['hash'])) $logged=true;
}
}
return $logged;
}
function showmenu() {
global $txtsign, $txtview, $txtadmin, $me, $getvars;
echo "";
}
function emailencoder ($str){
for ($i=0; $i< strlen($str); $i++){
$n=rand(0,10);
if ($n>5) $foo.="".ord($str[$i]).";";
else $foo.="".sprintf("%X", ord($str[$i])).";";
}
return $foo;
}
if (!function_exists('str_ireplace'))
{
function str_ireplace ($search, $replace, $subject, $count = null)
{
if (is_string($search) && is_array($replace)) {
trigger_error('Array to string conversion', E_USER_NOTICE);
$replace = (string) $replace;
}
// If search isn't an array, make it one
if (!is_array($search)) {
$search = array ($search);
}
// If replace isn't an array, make it one, and pad it to the length of search
if (!is_array($replace))
{
$replace_string = $replace;
$replace = array ();
for ($i = 0, $c = count($search); $i < $c; $i++)
{
$replace[$i] = $replace_string;
}
}
// Check the replace array is padded to the correct length
$length_replace = count($replace);
$length_search = count($search);
if ($length_replace < $length_search)
{
for ($i = $length_replace; $i < $length_search; $i++)
{
$replace[$i] = '';
}
}
// If subject is not an array, make it one
$was_array = false;
if (!is_array($subject)) {
$was_array = true;
$subject = array ($subject);
}
// Loop through each subject
$count = 0;
foreach ($subject as $subject_key => $subject_value)
{
// Loop through each search
foreach ($search as $search_key => $search_value)
{
// Split the array into segments, in between each part is our search
$segments = explode(strtolower($search_value), strtolower($subject_value));
// The number of replacements done is the number of segments minus the first
$count += count($segments) - 1;
$pos = 0;
// Loop through each segment
foreach ($segments as $segment_key => $segment_value)
{
// Replace the lowercase segments with the upper case versions
$segments[$segment_key] = substr($subject_value, $pos, strlen($segment_value));
// Increase the position relative to the initial string
$pos += strlen($segment_value) + strlen($search_value);
}
// Put our original string back together
$subject_value = implode($replace[$search_key], $segments);
}
$result[$subject_key] = $subject_value;
}
// Check if subject was initially a string and return it as a string
if ($was_array === true) {
return $result[0];
}
// Otherwise, just return the array
return $result;
}
}
// ************************** MAIN ****************************
// ************************************************************
// init
$foo=file($dat);
$stuff= new mdasort;
$stuff->sortkeys = array(array('time','DESC'));
if (count($foo)==0){
$empty=true;
$nextindex=1;
}else{
$i=0;
foreach ($foo as $line){
$line=explode("|", rtrim($line));
$stuff->data[$i] = array("id" => $line[0], "time" => $line[1], "name" => $line[2], "email" => $line[3], "www" => $line[4], "post" => $line[5]);
$i++;
}
$stuff->sortkeys = array(array('id','DESC'));
$stuff->msort();
$foo=current($stuff->data);
$nextindex=$foo['id']+1;
$stuff->sortkeys = array(array('time','DESC'));
$stuff->msort();
$numposts=count($stuff->data);
}
echo "\n\n\n\n";
echo "";
clearoldadmins();
showmenu();
// admin stuff
if ($do=="admin") {
if ($action=="login"){
if ($name==$adminname && $pwd==$adminpwd){
include($log);
$fp=fopen($log, "w");
fputs($fp, "\n");
$i=0;
if (count($admins)>0){
foreach ($admins as $line){
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
}
fputs($fp, "\$admins[$i]['time']=".$now."; \$admins[$i]['hash']='".md5($hash)."';\n?>");
fclose($fp);
echo "";
}
}
if ($action=="delete" && isloggedin()){
$todel=getkey($id, $stuff);
unset($stuff->data[$todel]);
$stuff->msort();
saveposts($stuff);
$do="view";
}else{
?>
}
}
// sign post
if ($do=="sign"){
if ($action=="save"){
$error=false;
$saveit=false;
if ($name=="") $error.=" » $txtbadname";
if ($email!=""){ if (!validemail($email)) $error.=" » $txtbademail"; }
if ($msg=="") $error.=" » $txtbadmsg";
if ($error===false){
if ($id=="new"){
$index=$numposts;
$id=$nextindex;
$time=$now;
$saveit=true;
}else if (isloggedin() && is_numeric($id)){
$index=getkey($id, $stuff);
$saveit=true;
}
if ($saveit){
$stuff->data[$index]['id']=$id;
$stuff->data[$index]['time']=$time;
$stuff->data[$index]['name']=htmlentities(strip_tags($name), ENT_QUOTES);
$stuff->data[$index]['email']=strip_tags($email);
if ($www!="http://") $stuff->data[$index]['www']=strip_tags($www);
else $stuff->data[$index]['www']="";
$stuff->data[$index]['post']=str_replace(array("\r", "\n"), array("", " "), htmlentities(strip_tags($msg), ENT_QUOTES));
saveposts($stuff);
$stuff->msort();
$empty=false;
}
$do="view";
}else echo "$txterrors$error
$txtclickback ";
}else{
if ($action=="edit" && isloggedin()){
$post=$stuff->data[getkey($id, $stuff)];
$name= html_entity_decode($post['name'], ENT_QUOTES);
$email=$post['email'];
$www=$post['www'];
$msg=stripslashes(str_replace(" ", "\n", html_entity_decode($post['post'], ENT_QUOTES)));
$time=$post['time'];
}else{
$name="";
$email="";
$www="";
$msg="";
$time="notset";
$id="new";
}
?>
}
}
// display posts
if ($do=="view" || !isset($do)){
if (!$empty){
$tpl=implode("", file($template));
$i=1;
foreach($stuff->data as $post){
if ($post['id']!=0 && $i>=$from && $i< ($from+$ppp) ){
$post['post']=str_ireplace($badwords, "******", $post['post']);
if ($wrap!==false) $post['post']=wordwrap($post['post'], $wrap, " ", 1);
$match=array("{name}", "{time}", "{website}", "{post}", "{edit}", "{delete}");
if (isloggedin())
$replace=array( ($post['email']!="") ? "".$post['name']."" : $post['name'], date("d. M Y", $post['time']), ($post['www']!="") ? "Webside" : "", stripslashes($post['post']), "$txtedit", "$txtdelete" );
else
$replace=array( ($post['email']!="") ? "".$post['name']."" : $post['name'], date("d. M Y", $post['time']), ($post['www']!="") ? "Webside" : "", stripslashes($post['post']), "", "" );
$html.=str_replace($match, $replace, $tpl);
}
$i++;
}
echo $html;
$numpages=(fmod($numposts,$ppp)>0) ? floor($numposts/$ppp)+1 : ($numposts/$ppp);
echo "";
echo (($from>1) ? " ««« " : "").(!(($from+$ppp>$numposts)) ? " »»»" : "");
echo " ";
}
}
// closing table tags
// Please don't remove the 'powered by...' link
echo " | ";
echo "\n\n\n\n";
?>
|
|
|