⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 news.pl

📁 一个可以自动进行首页新闻的程序
💻 PL
📖 第 1 页 / 共 2 页
字号:
sub Manage_Form {
	local ($newsfile) = @_;
	&Html_Header;
  print "<tr>\n    <td style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";
	print <<EOF;
<ul>
<form method="POST" action="$CONFIG{cgiurl}?referpw">
  管理口令:<input type="password" name="password" size=$len style="font-size: 9pt"><br>
  管理类型:<select NAME="ListType" style="font-size: 9pt"><br>
EOF
  foreach (@newstype) {
     ($typename, $typeid, $newsno, $tmp) = split(/\+/, $_);
     print "<OPTION value=\"$typeid\">$typename</option>\n";
       }
print <<EOF;
  </select>
  <input type="submit" value="提交管理口令" name="B1" style="font-size: 9pt">
</FORM>
</ul><hr><ul><form method="POST" action="$CONFIG{cgiurl}?writems">
  管理口令:<input type="password" name="password" size=$len style="font-size: 9pt"><br>
  站长新闻:<textarea rows="5" name="mastermsg" cols=$len style="font-size: 9pt">$str</textarea>*<br>
  <input type="submit" value="提交站长新闻" name="B1" style="font-size: 9pt">
</FORM></ul>
EOF
print "   </td>\n  </tr>\n";
	&Html_Footer;
}

#======================================================================
sub User_Form {
	local ($newsno) = @_;
	&Html_Header;
  print "<tr>\n    <td style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";
	print <<EOF;
<ul>
<form method="POST" action="$CONFIG{cgiurl}?referpw">
  管理口令:<input type="password" name="password" size=10 style="font-size: 9pt">
    <input type="radio" name="R1" value="delete" checked>删除
    <input type="radio" name="R1" value="amend">修改<br>

  <input type="submit" value="提交管理口令" name="B1" style="font-size: 9pt">
</FORM>
</ul>
EOF
print "   </td>\n  </tr>\n";
	&Html_Footer;
}

#======================================================================
sub Read_News {
	local ($newsfile) = @_;
	&Html_Header;
	print "<tr>\n    <td  align=left style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";

	if ($newsfile) {
		open (FILE, "$newsdir$newsfile") || &Error_File("$newsfile");
		@lines=<FILE>;
		close FILE;
	}

	&Print_Category_List ;

	if (($id ne "id") && (!$mid)){
		open (FILE, "$CONFIG{newstypefile}");
		@newstypes=<FILE>;
		close FILE;
		$types=@newstype;
		@lines = ();
		@typeslist = ();
		for ($i=0; $i<$types; $i++) {
			($typename, $typeid, $newsno, $tmp) = split(/\+/, $newstypes[$i]);
			open (FILE, "$newsdir$typeid");
			@tempnews=<FILE>;
			$tempno = @tempnews;
			close FILE;
			$j = 0;
			foreach (@tempnews) {
				push(@lines,"$_");
				push(@typeslist,"$typeid");
				last if ($j >= $CONFIG{newsnum});
				$j++;
			}
		}
		$currenttype = "新闻快报";
		$currentno = @lines;
	}

	print "当前栏目:<font color=red>$currenttype</font>(<b>$currentno</b>) \n";

	print "<form method=\"POST\" action=\"$CONFIG{cgiurl}?delnews\">\n" if ($mid == 1);
	print "<input type=\"hidden\" name=\"newsfile\" value=\"$newsfile\">\n" if ($mid == 1);
	
	if ($currentno == 0) {
		print "<center><br>";
		print "◆ <font color=red>$currenttype</font> ◆ 栏目目前还没有新闻<br><br></center>\n"; }
	else {	
		&msghead("title") if (($id ne "id") && (!$mid));
		&msghead("msg");
		print "<a href=\"$CONFIG{cgiurl}?newsform\">发表新闻或评论</a><br>\n"; }
	
	if ($mid == 1) {
		print "<input type=\"submit\" value=\"删除已选的新闻\" name=\"B1\" style=\"font-size: 9pt\">\n";
		print "</form>\n"; }

	print "   </td>\n  </tr>\n";

	&Html_Footer;
}

#======================================================================
sub Print_Category_List {
print <<EOF;
    <select name="D1" size="1" onChange=location.href=this.options[this.selectedIndex].value style="font-size: 9pt">
    <option selected>看其他类新闻</option>
    <option value=$CONFIG{cgiurl}>新闻快报(首页)</option>
EOF
	foreach (@newstype) {
		($typename, $typeid, $newsno, $tmp) = split(/\+/, $_);
		print "	<option value=$CONFIG{cgiurl}?id=$typeid>$typename($newsno)</option>\n";
		$currenttype = $typename if ($para eq $typeid);
		$currentno = $newsno if ($para eq $typeid);
	}
	print "</select>\n";
}

#======================================================================
sub msghead {
	local ($temp) = @_;
	local ($i);
	$i = 0;
	$size = @lines;
	
	# 计算页数

	if (($CONFIG{perpage} > 0) && ($size > $CONFIG{perpage}) && ($mid != 1) && ($id eq "id")) {
		$p = ($size % $CONFIG{perpage} >0)? $size / $CONFIG{perpage} + 1 : $size / $CONFIG{perpage};
		$pvalue = $p if ($pvalue > $p);
		$begin = $CONFIG{perpage}*$pvalue-$CONFIG{perpage};
		$end = $CONFIG{perpage}*$pvalue;  }
	else{	$p = 0;
		$begin = 0;
		$end = $size;  }

	# 开始打印新闻条
	&Pages_Links if (($p > 1) && ($mid != 1) && ($id eq "id"));

	print "<hr>";
	for ($i = $begin; $i < $end; $i++) {
		($no,$username,$hpname,$hpurl,$email,$newstitle,$message,$gpw,$newstime) = split(/\+/,$lines[$i]);
		chop($newstime) if ($newstime =~ /\n$/);
		
		print "<input type=\"checkbox\" name=\"$no\" value=1>\n"  if ($mid == 1);
		
		if ($temp eq "title") { 
			print "<li>";
			print "<a href=#$no>$newstitle</a> - ";  }
		else {	if ($id ne "id") {print "<a href=\"$CONFIG{cgiurl}?user+$typeslist[$i]+$no\">";  }
			else {	print "<a href=\"$CONFIG{cgiurl}?user+$para+$no\">"; }
			
			if (-e "$CONFIG{linkimg}") {
				print "<img src=\"$CONFIG{linkimg}\" alt=\"点击:修改或删除您自己发布的新闻\" border=0></a>\n"; }
			else {	print "$CONFIG{linkchr}\n"; }
			
			print "<a name=#$no>$newstitle</a> - ";  }
		
		if ($email) {	print "<a href=mailto:$email>$username</a> \@&nbsp;&nbsp;";   }
		else {		print "$username   "; }

		print "<a href=$hpurl target=\"_blank\">$hpname</a>&nbsp;&nbsp;" if ($hpurl);
		print "$newstime<br>\n";
		print "&nbsp;&nbsp;&nbsp;&nbsp;$message\n" if ($temp eq "msg");
		if (($temp eq "msg") && ($CONFIG{allowhr} == 1)) {
			print "<hr>\n" ; }
		elsif (($temp eq "msg") && ($CONFIG{allowhr} == 0)) {	print "<br><br>";  }
	
		last if ($i == $size-1);
	}
	
	# 打印分页链接
	&Pages_Links if (($p > 1) && ($mid != 1) && ($id eq "id"));
}

#======================================================================
sub Pages_Links {
	print <<EOF;
    其他页:
    <select name="D1" size="1" onChange=location.href=this.options[this.selectedIndex].value style="font-size: 9pt">
EOF
		
		for ($i=1; $i<=$p; $i++) {
			print "	<option value=$CONFIG{cgiurl}?id=$para+$i ";
			print "selected" if ($i == $pvalue);
			print ">第 $i 页</option>\n";
		}
		print "</select><br><br>\n";
}

# ===================================================================
sub Write_Master_News {
	
  open (FILE, "$CONFIG{masterpassword}");
  $mpw = <FILE>;
  close(FILE);
  chop($mpw) if ($mpw =~ /\n$/);
  if ($INPUT{password} eq $mpw) {
	&error_msg ("您并没有提交站长新闻!","forward") unless ($INPUT{mastermsg});
	open (FILE, ">$CONFIG{masternews}");
  	print FILE $INPUT{mastermsg};
  	close FILE;
  	&error_msg ("站长新闻管理完成!");
  	}
  else {
	  &error_msg ("您试图管理新闻中心,但您提交的口令不对或根本没有提交!","forward");   }
}
#======================================================================
sub Write_News {
  # Give Error Messages
  &error_msg ("您没有提交您的大名, 请重新登记","forward") unless $INPUT{"username"};
#  &error_msg ("您没有提交 Email, 请重新登记","forward")   unless $INPUT{"email"};
  if ($INPUT{'email'}) {
    $INPUT{'email'} =~ s/\s//g;
    if ($INPUT{'email'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/
     || $INPUT{'email'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)  {
	&error_msg ("您提交 Email 可能有错, 请重新登记","forward");
    }
  }
  &error_msg ("您没有提交新闻标题, 请重新登记","forward") unless $INPUT{"newstitle"};
  &error_msg ("您没有提交新闻内容, 请重新登记","forward") unless $INPUT{"message"};
  $INPUT{"message"} =~ s/\cM\n//g;

  if ($INPUT{referid} eq "user") {
  	$fid = $INPUT{newsfile}; }
  else {$fid = $INPUT{ListType}; }
  
  open (FILE, "$newsdir$fid");
  @lines=<FILE>;
  $size = @lines;
  close(FILE);

  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  $mon ++;
  $s = ($INPUT{referid} eq "user")?$INPUT{newsid}:$size+1;

  $newsstr ="$s+$INPUT{username}+$INPUT{hpname}+$INPUT{hpurl}+$INPUT{email}+$INPUT{newstitle}+$INPUT{message}+$INPUT{gpw}+$year.$mon.$mday $hour:$min:$sec\n";

  foreach (@lines) {
 	&error_msg ("您的新闻不能重复提交!","forward") if (/$INPUT{message}/);
  }
  foreach (@lines) {
	&error_msg ("您试图修改新闻,但管理口令错误或没有提交口令!","forward") if ((/^$INPUT{newsid}/) && (/$INPUT{gpw}/));
  }

  open (FILE,">$newsdir$fid");
  if ($INPUT{referid} eq "user") {
	foreach (@lines)  {
		$_ = $newsstr if (/^$INPUT{newsid}/);
		print FILE $_;	}
  }
  else {
	print FILE "$newsstr";
	foreach (@lines)  {    print FILE $_;  }
  }

  close (FILE);

&Html_Header;

foreach (@newstype) {
	($typename, $typeid, $newsno, $tmp) = split(/\+/, $_);

	if (/$fid/i) {
		$newsno ++;
		$_ = "$typename+$typeid+$newsno+$tmp";
		last;
	}
}

unless ($INPUT{referid}) {
  open (FILE, ">$CONFIG{newstypefile}");
  foreach (@newstype) {
  	print FILE $_;
  }
  close(FILE);
}
  print <<EOF;

<tr>\n    <td style="font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}">
您的新闻已经提交.<hr>
<b>$typename</b> 类 
(<a href='mailto:$INPUT{email}'><b>$INPUT{username}</b></a>)<br>
<a href='$INPUT{"hpurl"}'><b>$INPUT{"hpname"}</b></a><br>
<b>新闻内容:</b> $INPUT{"message"}<br><hr>

<center>返回 [ <a href=\"$CONFIG{cgiurl}\">新闻首页</a> | <a href=\"$CONFIG{cgiurl}?id=$fid\"> $typename 类新闻</a> ]<br><br>
<b>如果没有看到您的新闻,请按 Reload. </b><br><BR></center>
</td>
  </tr>
EOF
&Html_Footer;
exit;
}

# ===================================================================
# Error Pages

sub error_msg {
	local($inp, $id) = @_;
	&Html_Header;
	print "<tr>\n    <td  align=center style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";
	print "<br>$inp.<br><br>\n";
	print "返回<a href=javascript:(history.go(-1))>上一页</a><br><br>" if ($id eq forward);

	print "   </td>\n  </tr>\n";
	&Html_Footer;
	exit;
}

sub Error_File {
	print <<EOF;
<tr><td style="font-size: 9pt">
<P ALIGN=CENTER><br><font class="title3">文件操作错误!</font></P><hr>
<UL><P><font class="title1">服务器度在访问<STRONG>$_[0]</STRONG>遇到了麻烦! <br>
也可能是目录不存在,也可能是需要的文件不存在,或者脚本的权限设置得不够。</font></UL>

EOF
	print "   </td>\n  </tr>\n";
	&Html_Footer;
	exit;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -