📄 news.pl
字号:
#!/usr/bin/perl
$| = 1;
#######################################################################
# 免费新闻发布 Free News Ver 1.0
# Created by mqingyi mqingyi@126.com
# 作者网站: CGI 指南
# 网址: http://user.wzptt.gx.cn/cgi-guide/
# 作者网站: 楚之源
# 网址: http://chu-surce.yeah.net/
# Copyright (c) 1999 All Rights Reserved.
#
# 使用: http://host/路径/freenews.pl
#
# 式样:
#
# 欢迎下载使用,并请注明出处
#######################################################################
$newsdir = "news/";
$configfile = $newsdir."config.txt";
open (CONFIG, "$configfile") || &Error_File("配置文件");
@config = <CONFIG>;
close CONFIG;
foreach (@config) {
next if (/^\#/);
chop($_) if (/\n$/);
($name, $value) = split(/=/, $_);
$CONFIG{$name} = $value;
}
$CONFIG{Pages_Width} = 210 if ($CONFIG{Pages_Width} < 210);
$CONFIG{Pages_Width} = 760 if ($CONFIG{Pages_Width} > 760);
#======================================================================
# 以下不需修改,除非你非常熟悉 Perl
#======================================================================
$len = ($CONFIG{Pages_Width} <= 300) ? 17 : 40;
print "Content-type: text/html\n\n";
if ($ENV{'QUERY_STRING'} =~ /id=/i) {
($id, $para) = split(/=/,$ENV{'QUERY_STRING'});
($para, $pvalue) = split(/\+/,$para);
$pvalue = 1 unless ($pvalue); }
else {
($para, $typeid, $usernewsno) = split(/\+/, $ENV{'QUERY_STRING'}); }
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>//g if ($para ne "writems");
$INPUT{$name} = $value;
}
open (FILE, "$CONFIG{newstypefile}");
@newstype=<FILE>;
close(FILE);
# $para = $CONFIG{headnews} unless $para;
if ($para eq "newsform") { &News_Form; }
elsif ($para eq "refernews") {
if ($INPUT{B1} eq "发表新闻") { &Write_News; }
elsif ($INPUT{B1} eq "删除新闻") { &Delete_News; }
}
elsif ($para eq "writems") { &Write_Master_News; }
elsif ($para eq "manageform") { &Manage_Form; }
elsif ($para eq "referpw") { &Check_pw; }
elsif ($para eq "delnews") { &Delete_News; }
elsif ($para eq "searchnews") { &Search_News; }
elsif ($para eq "user") { &News_Form($para, $typeid, $usernewsno); }
# elsif ($id eq "id") { &Read_News($para); }
else { &Read_News($para); }
#======================================================================
sub Html_Header {
print <<EOF;
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>$CONFIG{newsname}</title>
<style><!--
A:link {text-decoration: none; color: 0000FF; font-family: XXX}
A:visited {text-decoration: none; color: 0000FF;font-family: XXX}
A:active {text-decoration: none; font-family: XXX}
A:hover {text-decoration: ; color: FF0000}-->
</style>
</head>
<body>
<table border="0" width=$CONFIG{Pages_Width} cellspacing="0" cellpadding="0">
EOF
if ($CONFIG{allowtitle} == 1) {
print "<tr>\n";
print " <td align=center valign=middle style=\"font-family: $CONFIG{titlefont}; color: $CONFIG{titlecolor}; background-color: $CONFIG{titlebgcolor}; font-size: $CONFIG{titlesize}\">\n";
if (($CONFIG{titlelogo} eq "http://") || (!$CONFIG{titlelogo})) {
print $CONFIG{newsname}; }
else { print "<img src=\"$CONFIG{titlelogo}\" alt=\"$CONFIG{newsname}\" border=0>\n";}
print " </td></tr>\n";
}
print " <tr><td height=20 valign=middle align=center style=\"color: $CONFIG{menuareacolor}; background-color: $CONFIG{menuareabgcolor}; font-size: 9pt\">\n";
print " | ";
print " <a href=\"$CONFIG{cgiurl}\">新闻首页</a> |\n" if ($para);
print " <a href=\"$CONFIG{cgiurl}?newsform\">发表新闻</a> |\n" unless ($para eq "newsform");
print " <a href=\"$CONFIG{cgiurl}?manageform\">新闻管理</a> | \n" unless ($para eq "manageform");
print " <a href=\"mailto:$CONFIG{masteremail}\">联系版主</a> |" unless ($pvalue);
print "\n</td>\n </tr>\n";
# 站长新闻
if ($CONFIG{allowmasternews} == 1) {
#if (-e "$CONFIG{masternews}" == 0) {
print " <tr>\n <td bgcolor=$CONFIG{masterareabgcolor} color: $CONFIG{masterareacolor}>\n";
open (FILE, "$CONFIG{masternews}");
@lines=<FILE>;
close(FILE);
foreach (@lines) { $str .= $_; }
print " $str <br></td>\n </tr>\n";
#}
}
# 搜索表单
if ($CONFIG{allowserach} == 1) {
print <<EOF;
<tr>\n <td align=center style="font-size: 9pt; background-color:$CONFIG{searchareabgcolor}; color: $CONFIG{searchareacolor}">
<form method="POST" action="$CONFIG{cgiurl}?searchnews">
<input type="text" name="newskeyword" size=$len style="font-size: 9pt">
<!-- <input type="radio" name="R1" value="&&" checked>and
<input type="radio" name="R1" value="||">or -->
<input type="submit" value="新闻搜索" name="B1" style="font-size: 9pt">
<!-- <br>支持多关键字搜索,关键字之间用逗号(,)隔开。-->
</form>
</td>\n </tr>
EOF
}
}
#======================================================================
sub Html_Footer {
if ($CONFIG{allowfooter} == 1) {
print <<EOF;
<tr>
<td align=center bgcolor=$CONFIG{footerareabgcolor} style="font-size: 9pt"><font color=$CONFIG{footerareacolor}>
[ <a href="http://mud.sz.jsinfo.net/per/mqingyi/" target="_top">CGI 指南</a> |
<a href="http://chu-source.yeah.net/" target="_top">楚之源</a> ] 提供<br>
<a href="mailto:mqingyi\@126.com">mqingyi</a> (C)Copyright 1999-2000. All rights reserved.</font></td>
</tr>
EOF
}
print <<EOF;
</table>
</body></html>
EOF
}
#======================================================================
sub Search_News {
unless ($INPUT{newskeyword}) { &error_msg ("您没有提供搜索关键字!","forward"); }
@keys = split(/,/, $INPUT{newskeyword});
$keysno = @keys;
$typeno = @newstype;
@tmp = ();
for ($i=0; $i<$typeno; $i++) {
($typename, $typeid, $newsno, $tmp) = split(/\+/, $newstype[$i]);
if (-e "$newsdir$typeid") {
open (FILE, "$newsdir$typeid");
@newslines = <FILE>;
close (FILE);
foreach (@newslines) {
for ($ii = 0; $ii < $keysno; $ii++) {
if (/$keys[$ii]/) {
push(@tmp, $_);
last;
}
}
}
}
}
&Html_Header;
@lines = @tmp;
$n = @lines;
print "<tr>\n <td style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";
&Print_Category_List;
print "搜索到符合条件的新闻共 <b>$n</b> 条<br>\n";
&msghead("msg");
print " </td>\n </tr>\n";
&Html_Footer;
}
#======================================================================
sub Delete_News {
if (!$INPUT{newsfile}) { &error_msg ("删除新闻,请通过 [ 站长管理 ] 进行!!!","forward"); }
open (FILE, "$newsdir$INPUT{newsfile}") || &Error_File("$newsdir$INPUT{newsfile}");
@lines=<FILE>;
close(FILE);
if ($INPUT{referid} eq "user") {
foreach (@lines){
($no,$username,$hpname,$hpurl,$email,$newstitle,$message,$gpw,$newstime) = split(/\+/,$_);
if (($INPUT{newsid} == $no) && ($INPUT{gpw} ne $gpw)) {
&error_msg ("新闻不能完成!<p>您输入的口令有错!"); }
else { last; }
}
}
open (FILE, ">$newsdir$INPUT{newsfile}") || &Error_File("$newsdir$INPUT{newsfile}");
$i=1;
$dn = 0;
foreach (@lines){
($no,$username,$hpname,$hpurl,$email,$newstitle,$message,$gpw,$newstime) = split(/\+/,$_);
if ($INPUT{referid} eq "user") {
unless (/^$INPUT{newsid}/) {
print FILE "$i+$username+$hpname+$hpurl+$email+$newstitle+$message+$gpw+$newstime";
$i++; }
else { $dn ++; }
}
else {
if (!$INPUT{$no}) {
print FILE "$i+$username+$hpname+$hpurl+$email+$newstitle+$message+$gpw+$newstime";
$i++; }
else { $dn ++; }
}
}
close (FILE);
foreach (@newstype) {
($typename, $typeid, $newsno, $tmp) = split(/\+/, $_);
if (/$INPUT{newsfile}/i) {
$newsno = $newsno - $dn;
$_ = "$typename+$typeid+$newsno+$tmp";
last;
}
}
open (FILE, ">$CONFIG{newstypefile}");
foreach (@newstype) {
print FILE $_;
}
close(FILE);
&error_msg ("新闻管理完成!");
}
#======================================================================
sub News_Form {
local ($t1, $t2, $t3) = @_ ;
if ($t1 eq "user") {
open (UFILE, "$t2");
@usernews = <UFILE>;
close(UFILE);
foreach (@usernews) {
($no,$username,$hpname,$hpurl,$email,$newstitle,$message,$gpw,$newstime) = split(/\+/,$_);
last if ($t3 == $no);
}
}
else {
$hpurl = "http://" unless ($hpurl);
}
&Html_Header;
print "<tr>\n <td style=\"font-size: 9pt; background-color:$CONFIG{newsareabgcolor}; color: $CONFIG{newsareacolor}\">\n";
print "<ul><form method=\"POST\" action=\"$CONFIG{cgiurl}?refernews\">\n";
if ($t1 eq "user") {
print "<input type=\"hidden\" name=\"referid\" value=\"$t1\">\n";
print "<input type=\"hidden\" name=\"newsfile\" value=\"$t2\">\n";
print "<input type=\"hidden\" name=\"newsid\" value=\"$t3\">\n";
}
print <<EOF;
<span style="font-size: 9pt"><br><br>
<u>发表新闻</u><p>
您的大名:<input type="text" name="username" size=$len style="font-size: 9pt" value="$username">*<br>
主页名称:<input type="text" name="hpname" size=$len style="font-size: 9pt" value="$hpname"><br>
主页地址:<input type="text" name="hpurl" size=$len style="font-size: 9pt" value="$hpurl"><br>
电子邮件:<input type="text" name="email" size=$len style="font-size: 9pt" value="$email"><br>
新闻标题:<input type="text" name="newstitle" size=$len style="font-size: 9pt" value="$newstitle">*<br>
新闻内容:<textarea rows="6" name="message" cols=$len style="font-size: 9pt">$message</textarea>*<br>
新闻类型:<select NAME="ListType" style="font-size: 9pt">
EOF
foreach (@newstype) {
($typename, $typeid, $newsno, $tmp) = split(/\+/, $_);
print "<OPTION value=\"$typeid\">$typename</option>\n";
}
print <<EOF;
</select>*\n<br>
管理口令:<input type="password" name="gpw" size=10 style="font-size: 9pt">(用于修改或删除新闻)<br>
</span><br>
<input type="submit" value="发表新闻" name="B1" style="font-size: 9pt">
EOF
print "<input type=\"submit\" value=\"删除新闻\" name=\"B1\" style=\"font-size: 9pt\">\n" if ($t1 eq "user");
print <<EOF;
</form>
</ul>
</td>\n </tr>
EOF
&Html_Footer;
}
#======================================================================
sub Check_pw {
open (FILE, "$CONFIG{masterpassword}");
$mpw = <FILE>;
close(FILE);
chop($mpw) if ($mpw =~ /\n$/);
if ($INPUT{password} eq $mpw) {
$mid = 1;
$para = $INPUT{ListType};
&Read_News($para); }
else {
&error_msg ("您试图管理新闻中心,但您提交的口令不对或根本没有提交!","forward"); }
}
#======================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -