文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>丫丫留言板

丫丫留言板

时间:2007-03-15  来源:snowtty

 

<!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= '
 <br>
<table cellspacing="0" cellpadding="0" border="0" width="650" align="center">
<tr><td bgcolor="#000000">

<table border="0" cellspacing="1" cellpadding="4" width="100%">
        <tr class="header">
          <td align="center">丫丫留言板 欢迎你</td>
        </tr>
</table>
</td></tr></table>';
echo $head;
}
//form 显示

 $msge='
 <center><form name="form1" method="post" action="'.WENJIAN.'">
 <input type=hidden name=act value="liuyan">
 <input type=hidden name=pass value='.$pass.'>
   <table cellspacing="0" cellpadding="0" border="0" width="650" align="center">
<tr><td bgcolor="#000000">

    <table width="100%" border="0" cellpadding="4" cellspacing="1">
             <tr>
              <td colspan="2" class=header>发布新留言</td>
            </tr>
            <tr>
        <td bgcolor="DFDFDF" align="center">姓名</td>
        <td bgcolor="#F1F1F1"><input name="name" type="text" size="12"></td>
      </tr>
      <tr>
        <td bgcolor="DFDFDF" width="120" align="center">内容</td>
        <td bgcolor="#F1F1F1"> <textarea name="txt" cols="80" rows="7" ></textarea>
          <br>
          <input type="submit" name="Submit" value="发表留言">
          <input type="reset" name="Submit2" value="清空内容">
        </td>
      </tr>
    </table></td></tr></table>
</form>
</center>';
function bb2html($st,$woimg)
{
//global $woimg;

    $st = preg_replace("/\[b\](.*?)\[\/b\]/si", "<b>\\1</b>", $st);
    $st = preg_replace("/\[i\](.*?)\[\/i\]/si", "<i>\\1</i>", $st);
    $st = preg_replace("/\[u\](.*?)\[\/u\]/si", "<u>\\1</u>", $st);
    $st = preg_replace("/\[p\](.*?)\[\/p\]/si", "<p>\\1</p>", $st);
    $st = preg_replace("/\[color=(\S+?)\](.*?)\[\/color\]/si",
                           "<font color=\"\\1\">\\2</font>", $st);
    $st = preg_replace("/\[s([1-7])\](.*?)\[\/s([1-7])\]/si",
                           "<font size=\"\\1\">\\2</font>", $st);
    $st = preg_replace("/\[pre\](.*?)\[\/pre\]/si", "<pre>\\1</pre>", $st);
    $st = preg_replace("/\[quote\](.*?)\[\/quote\]/si", "<blockquote>\\1</blockquote>", $st);
    $st = preg_replace("/(^|[^=\]h])(ttp:)/si", "\\1http:", $st);
    $st = preg_replace("/(^|[^=\]])(http|https|ftp)(:\/\/[\!-;\=\?-\~]+)/si", "\\1<a href=\"\\2\\3\" target=_blank>\\2\\3</a>", $st);
    $st = preg_replace("/(^|[^=\]\/])(www\.[\!-;\=\?-\~]+)/si", "\\1<a href=\"http://\\2\" target=_blank>\\2</a>", $st);
    $st = preg_replace("/\[url\](http|https|ftp)(:\/\/\S+?)\[\/url\]/si",
                           "<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</A>", $st);
    $st = preg_replace("/\[url\](\S+?)\[\/url\]/si",
                           "<a href=\"http://\\1\" target=\"_blank\">\\1</A>", $st);
    $st = preg_replace("/\[url=(http|https|ftp)(:\/\/\S+?)\](.*?)\[\/url\]/si",
                           "<a href=\"\\1\\2\" target=\"_blank\">\\3</A>", $st);
    $st = preg_replace("/\[url=(\S+?)\](\S+?)\[\/url\]/si",
                           "<a href=\"http://\\1\" target=\"_blank\">\\2</A>", $st);
    $st = preg_replace("/\[email\](\S+?@\S+?\\.\S+?)\[\/email\]/si",
                           "<a href=\"mailto:\\1\">\\1</A>", $st);
    $st = preg_replace("/\[email=(\S+?@\S+?\\.\S+?)\](.*?)\[\/email\]/si",
                           "<a href=\"mailto:\\1\">\\2</A>", $st);
if($woimg){
    $st = preg_replace("/\[img\](mailto:)?(\S+?)(\.jpe?g|\.gif|\.png)\[\/img\]/si",
                           "<img src=\"\\2\\3\" border=0 alt=\"\\1\\2\\3\">", $st);
}
    $st = str_replace("&amp;heart;","<font color=red>&#9829;</font>",$st);
    return $st;
}
//写入信息


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

  
//完成提示

$wan='
 <table cellspacing="0" cellpadding="0" border="0" width="97%" align="center" style="table-layout: fixed">
  <tr>
    <td align="left" nowrap >&nbsp;<a href="'.WENJIAN.'">丫丫留言板</a>
      &raquo; 提示信息</td>
  </tr>
</table>
<br>
<table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr><td bgcolor="#000000">
<table border="0" cellspacing="1" cellpadding="4" width="100%">
<tr class="header">
          <td>丫丫留言板 提示信息</td>
        </tr>
<tr><td bgcolor="#F1F1F1" align="center">

<table border="0" width="90%" cellspacing="0" cellpadding="0">
<tr><td align="center" >
<br>
                  非常感谢,您的留言已经发布成功,现在将转入留言页。<br>
                  <br>
                  <br>
                  <br>
                  <a href="'.WENJIAN.'">如果您的浏览器没有自动跳转,请点击这里</a> <br>
                  <br>
</td></tr></table>
</td></tr></table>
</td></tr></table>';
   $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="<font color=\"#FF9900\">".$name."</font>";
        $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 "<META HTTP-EQUIV=\"refresh\" content=\"6;URL= ".WENJIAN." \">";
 }
 
 //字符串过滤

 function CleanStr($str)

{
  $str = trim($str);
  if (get_magic_quotes_gpc())
     {
    $str = stripslashes($str);
  }
  $str = htmlspecialchars($str);
  $str = str_replace("&amp;", "&", $str);
  return str_replace(",", "&#44;", $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条留言&nbsp;&nbsp;";
$gongye = "共$nextint\0页&nbsp;&nbsp;";
$diye = "第$no\0页&nbsp;&nbsp";

if($no==1&&$nextint==1)
{
}
else{
 if($no==1&&$nextint>$no)
      {
 $no1=$no+1;
    $xiaye="<a href=\"".WENJIAN."?no=$no1\">下一页</a>";
       }
     else {
 if($no==$nextint)
            {
 $no1=$no-1;
    $shangye="<a href=\"".WENJIAN."?no=$no1\">上一页</a>";
                }
                   else {
   $no1=$no-1;
   $shangye="<a href=\"".WENJIAN."?no=$no1\">上一页</a>&nbsp;&nbsp";
 
         $no1=$no1+2;
         $xiaye="<a href=\"".WENJIAN."\">下一页</a>";
                               }
            }
      }
  
     $dat1.='<center><form name="form2" method="post" action="'.WENJIAN.'">';
     $dat1.="$gongjl $gongye $diye $shangye $xiaye &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"submit\" name=\"Submit\" value=\"查看\">第<input name=\"no\" type=\"text\" size=\"2\">页&nbsp;&nbsp;&nbsp;&nbsp;";
     $dat1.='<a href="'.WENJIAN.'?act=admin">管理</a></center></form>';
     echo $dat1;
     }
//错误跳出

function error($err){
 
  echo "<br><br><hr size=1><br><br>
        <center><font color=red size=5><b>$err</b></font></center>
        <br><br><hr size=1>";
  die("</body></html>");
}
//显示留言

$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.='<table cellspacing="0" cellpadding="0" border="0" width="650" align="center">';
    
    $dat.='<tr><td bgcolor="#000000">';
    $dat.='<table width="100%" border="0" cellpadding="4" cellspacing="1">';
    $dat.='<tr>';
   $dat.="<td bgcolor=$backclor align=\"left\">留言者:</td>";
    $dat.="<td bgcolor=$backclor>$time</td>";
    $dat.='</tr>';
    $dat.='<tr>';
   $dat.="<td bgcolor=$backclor width=\"120\" align=\"center\">$name</td>";
    $dat.="<td bgcolor=$backclor>$txt";
    $dat.='</td>';
    $dat.='</tr>';
    $dat.='</table></td></tr></table>';
    }
   $no=($no-1)/YE+1;
   echo $dat;
}
 function foot($dat3)
{
 $dat3='
   <center>
  <p>&nbsp;</p>
  <p>&lt;&nbsp;<a href="mailto:[email protected]">联系我们</a>-<a href="">丫丫留言板</a>&nbsp;&gt;</p>
  <p>Copyright &copy; 2003 <a href="http://yayamb.yeah.net" target="_blank">Whl</a>,All
    Rights Reserved </p>
</center>';
 echo $dat3;
}
function valid($pass){
  if($pass && $pass != PASS) error("密码错误");
 
  echo '[<a href="'.WENJIAN.'">丫丫留言板</a>]';
    echo '<p><form action="'.WENJIAN.'" method=POST>';
    if(!$pass){
    echo "<center><input type=radio name=admin value=del checked>留言删除 ";
    echo "<input type=radio name=admin value=post>管理人留言<p>";
    echo "<input type=hidden name=act value=admin>\n";
    echo "<input type=password name=pass size=8>";
    echo "<input type=submit value=\" 确 定 \"></form></center>\n";
    die("</body></html>");
  }
}
 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 '<form action="'.WENJIAN.'" method=POST>';
echo "<input type=hidden name=act value=admin>\n";
echo "<input type=hidden name=admin value=del>\n";
echo "<input type=hidden name=pass value=\"$pass\">\n";
echo '<table cellspacing="0" cellpadding="0" border="0" width="650" align="center">';
    echo '<tr><td bgcolor="#000000">';
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">";
    echo "<tr><td colspan=\"5\" bgcolor=\"#F1F1F1\" class=header><center>留言管理</center></td></tr>";
 $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 "<tr>";
    echo "<td width=\"20\" bgcolor=\"#F1F1F1\"><input type=\"checkbox\" name=delno[$k] value=\"$no\"></td>";
    echo "<td width=\"30\" bgcolor=\"#F1F1F1\">$no</td>";
    echo "<td width=\"100\" bgcolor=\"#F1F1F1\">$time</td>";
    echo "<td width=\"100\" bgcolor=\"#F1F1F1\">$name</td>";
    echo "<td width=\"400\" bgcolor=\"#F1F1F1\">$txt</td>";
    echo "</tr>";
    }
    echo "</table></td></tr></table><center>";
    if(count($line)==0) error("留言已经被清空");
    echo "</br><input type=submit value=\"确认删除\"></center></form>";
  }
  
 //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>

相关阅读 更多 +
排行榜 更多 +
兵人放置战争

兵人放置战争

音乐节奏 下载
新豪足球

新豪足球

浏览阅读 下载
会玩

会玩

游戏工具 下载