Chinaunix首页 | 论坛 | 博客
  • 博客访问: 630730
  • 博文数量: 184
  • 博客积分: 10057
  • 博客等级: 上将
  • 技术积分: 2505
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-31 16:34
文章分类

全部博文(184)

文章存档

2010年(5)

2009年(104)

2008年(75)

我的朋友

分类:

2008-09-21 21:05:53

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>丫丫留言板-YaYa MessageBoard</title>
<style type="text/css">
<?
 if(phpversion()>="4.1.0"){
  extract($_REQUEST);
  extract($_COOKIE);
  }
  /*欢迎使用"丫丫留言板(YaYa MessageBoard )"*/
    define(WENJIAN,"index.php");
//留言板主文件名

    define(PASS, '123');
 define(LOGFILE, 'liuyan.txt');
//留言存放文件

 define(YE, '10');
//每页显示留言数目

 $jzusername=array("whl","whl204","丫丫");
//开头

 function head($head)
{
$head=
'
 





        
          
        
丫丫留言板 欢迎你

'
;
echo $head;
}
//form 显示

 $msge=
'
 
.WENJIAN.'">
 
 
   


    
             
              
            
            
        
        
      
      
        
        
      
    
发布新留言
姓名
内容
          

          
          
        


'
;
function bb2html($st,$woimg)
{
//global $woimg;

    $st = preg_replace("/\[b\](.*?)\[\/b\]/si", "\\1", $st);
    $st = preg_replace("/\[i\](.*?)\[\/i\]/si", "\\1", $st);
    $st = preg_replace("/\[u\](.*?)\[\/u\]/si", "\\1", $st);
    $st = preg_replace("/\[p\](.*?)\[\/p\]/si", "

\\1

"
, $st);
    $st = preg_replace("/\[color=(\S+?)\](.*?)\[\/color\]/si",
                           "\\2", $st);
    $st = preg_replace("/\[s([1-7])\](.*?)\[\/s([1-7])\]/si",
                           "\\2", $st);
    $st = preg_replace("/\[pre\](.*?)\[\/pre\]/si", "
\\1
"
, $st);
    $st = preg_replace("/\[quote\](.*?)\[\/quote\]/si", "
\\1
"
, $st);
    $st = preg_replace("/(^|[^=\]h])(ttp:)/si", "\\1http:", $st);
    $st = preg_replace("/(^|[^=\]])(http|https|ftp)(:\/\/[\!-;\=\?-\~]+)/si", "\\1\\2\\3", $st);
    $st = preg_replace("/(^|[^=\]\/])(www\.[\!-;\=\?-\~]+)/si", "\\1\\2", $st);
    $st = preg_replace("/\[url\](http|https|ftp)(:\/\/\S+?)\[\/url\]/si",
                           "\\1\\2", $st);
    $st = preg_replace("/\[url\](\S+?)\[\/url\]/si",
                           "\\1", $st);
    $st = preg_replace("/\[url=(http|https|ftp)(:\/\/\S+?)\](.*?)\[\/url\]/si",
                           "\\3", $st);
    $st = preg_replace("/\[url=(\S+?)\](\S+?)\[\/url\]/si",
                           "\\2", $st);
    $st = preg_replace("/\[email\](\S+?@\S+?\\.\S+?)\[\/email\]/si",
                           "\\1", $st);
    $st = preg_replace("/\[email=(\S+?@\S+?\\.\S+?)\](.*?)\[\/email\]/si",
                           "\\2", $st);
if($woimg){
    $st = preg_replace("/\[img\](mailto:)?(\S+?)(\.jpe?g|\.gif|\.png)\[\/img\]/si",
                           "\"\\1\\2\\3\"", $st);
}
    $st = str_replace("&heart;","",$st);
    return $st;
}
//写入信息


function xie($name,$txt,$pass)
 
  {
   global $jzusername;
   
//,$panduan, $woimg;

  
//完成提示

$wan=
'
 
  
    
  
 .WENJIAN.'">丫丫留言板
      » 提示信息







          
        
丫丫留言板 提示信息






                  非常感谢,您的留言已经发布成功,现在将转入留言页。

                  

                  

                  

                  .WENJIAN.'">如果您的浏览器没有自动跳转,请点击这里

                  



'
;
   $shicha = 0;
//时差

     $time=strftime("%Y-%m-%d %H:%M:%S",time()+$shicha*3600);
  global $REQUEST_METHOD;
  if(empty($name)) error("姓名不能为空");
  if(empty($txt)) error("内容不能为空");
  if(strlen($name) > 14) error("姓名不能超过7个汉字");
  if(strlen($name) > 1000) error("内容不能超过500汉字");
  
  $line = file(LOGFILE);
  list($lastno,$ltime,$lname,$ltxt) = explode(",", $line[0]);
  $no=$lastno+1;
  $name=CleanStr($name);
  $txt=CleanStr($txt);
  if(ereg("[ \r]",$name)) error("用户名中间不能用空格");
  
 if(!$pass==PASS)
 {
  for($m=0;$m<count($jzusername);$m++)
        {
        if($jzusername[$m]==$name) error("留言板保留用户名");
        }
    }
    if($pass==PASS)
    {
        $name="".$name."";
        $woimg=1;
     }
       
  $txt = str_replace( "\r\n", "\n", $txt);
        $txt = str_replace( "\r", "\n", $txt);
  $txt = ereg_replace("\n(( | )*\n){3,}","\n",$txt);
        $txt = nl2br($txt);
        $txt = str_replace("\n", "", $txt);
        $txt = bb2html($txt,$woimg);
  $newline = "$no,$time,$name,$txt\n";
  $fp = fopen(LOGFILE, "w");
        flock($fp, 2);
        fputs($fp, $newline);
        fputs($fp, implode('', $line));
        fclose($fp);
echo $wan;
echo ".WENJIAN." \">";
 }
 
 
//字符串过滤

 function CleanStr($str)

{
  $str = trim($str);
  if (get_magic_quotes_gpc())
     {
    $str = stripslashes($str);
  }
  $str = htmlspecialchars($str);
  $str = str_replace("&", "&", $str);
  return str_replace(",", ",", $str);
          }
          
//上一页下一页显示

 
function pagexianshi($gongjl,$gongye,$diye,$shangye,$xiaye)
  {
 global $no,$nextint,$j;
if(isset($no))
{
 if ($no==1&&$nextint==0){}
 else
       {
 if($no>$nextint or $no <=0 ) error("没有该页");
          }
}
  else {$no=1;}
$gongjl = "共$j\0条留言  ";
$gongye = "共$nextint\0页  ";
$diye = "第$no\0页  ";

if($no==1&&$nextint==1)
{
}
else{
 if($no==1&&$nextint>$no)
      {
 $no1=$no+1;
    $xiaye=".WENJIAN."?no=$no1\">下一页";
       }
     else {
 if($no==$nextint)
            {
 $no1=$no-1;
    $shangye=".WENJIAN."?no=$no1\">上一页";
                }
                   else {
   $no1=$no-1;
   $shangye=".WENJIAN."?no=$no1\">上一页  ";
 
         $no1=$no1+2;
         $xiaye=".WENJIAN."\">下一页";
                               }
            }
      }
  
     $dat1.='
.WENJIAN.'">';
     $dat1.="$gongjl $gongye $diye $shangye $xiaye                页    ";
     $dat1.='.WENJIAN.'?act=admin">管理
'
;
     echo $dat1;
     }
//错误跳出

function error($err){
 
  echo
"





        
$err

        


"
;
  die(" ");
}
//显示留言

$line = file(LOGFILE);
if (!is_array($line)) error(" 没有建立留言存放文件");
$j=count($line);
$l=$j/YE;
$nextint=ceil($l);
 
function main($dat,$no)
{
//global $LOGFILE,$YE;

$line = file(LOGFILE);

$j=count($line);

$l=$j/YE;
$nextint=ceil($l);
if(!isset($no)) {$no=1;
                $nextint=1;}
$no=$no*YE-YE+1;

for($i = $no-1; $i <$no+YE-1; $i++)
  {$w=$j-$i;
    if($line[$i]=="") break;
    $backclor="DFDFDF";
    if(!(($i+2)%2-1)) {$backclor="#F1F1F1";}
    list($no,$time,$name,$txt) = explode(",", $line[$i]);
    
    $dat.='';
    
    $dat.='
';
    $dat.='';
    $dat.='';
   $dat.="";
    $dat.="";
    $dat.='';
    $dat.='';
   $dat.="";
    $dat.="';
    $dat.='';
    $dat.='
留言者:$time
$name$txt";
    $dat.='
'
;
    }
   $no=($no-1)/YE+1;
   echo $dat;
}
 function foot($dat3)
{
 $dat3=
'
   

  

 


  

联系我们-丫丫留言板 >


  

Copyright © 2003 Whl,All
    Rights Reserved


'
;
 echo $dat3;
}
function valid($pass){
  if($pass && $pass != PASS) error("密码错误");
 
  echo '[.WENJIAN.'">丫丫留言板]';
    echo '

.WENJIAN.'" method=POST>';
    if(!$pass){
    echo "
留言删除 ";
    echo "管理人留言

";
    echo "\n";
    echo "";
    echo "

\n"
;
    die("");
  }
}
 function del($delno,$pass)
    {
      
$line = file(LOGFILE);
$j=count($line);
 for($i = 0; $i < count($line); $i++)
        {
           list($no,$time,$name,$txt) = explode(",",$line[$i]);
           $find = FALSE;
           
           for($w=0;$w<$j;$w++)
          { if($delno[$w]==$no)
           {
               $find = TRUE;
               $line[$i]="";
           }
            if($find){
      $fp = fopen(LOGFILE, "w");
      flock($fp, 2);
      fputs($fp, implode('', $line));
      fclose($fp);

      }
           
          }
         }
      
echo '
.WENJIAN.'" method=POST>';
echo "\n";
echo "\n";
echo "\n";
echo '';
    echo'
';
    echo "";
    echo"";
 $line=file(LOGFILE);
            
for($k= 0;$k<$j;$k++)
  {
    if($line[$k]=="")break;
    list($no,$time,$name,$txt)=explode(",",$line[$k]);
    list($time,$dmy)=split(" ",$time);
    
    
    echo"";
    echo"";
    echo"";
    echo"";
    echo"";
    echo"";
    echo"";
    }
    echo"
留言管理
$no $time $name $txt
";
    if(count($line)==0) error("留言已经被清空");
    echo "
"
;
  }
  
 
//main

   switch($act)
   {
 case "liuyan":
  
   xie($name,$txt,$pass);
   break;
   case "admin":
       valid($pass);
   if($admin=="del") del($delno,$pass);
   if($admin=="post") echo $msge;
   break;
   default:
       if($j==0){}
    else {head($head);
    main($dat,$no);}
    if($act=="liuyan") { }
    else{
pagexianshi($gongjl,$gongye,$diye,$shangye,$xiaye);
  echo $msge;
  foot($dat3);
         }
   }
  ?>
</body>
</html>

阅读(791) | 评论(0) | 转发(0) |
0

上一篇:文件上传(php)

下一篇:perl 函数(ZT)

给主人留下些什么吧!~~