📄 articlelib.php
字号:
<?php
//articlelib.php 在article子目录下
require "lib.php";
$db = db_connect();
//返回论坛中所有文章的数目
function readnum()
{
global $db;
$sql = "select id from article where id>0";
$result = mysql_query($sql, $db);
$total = mysql_num_rows($result);
return $total;
}
//返回论坛中所有parent字段值为0的记录(一级父)
function readborder_parent()
{
global $db;
$sql = "select id,title,importtime,content,writer,click,adda,fl from article where parent='0' order by id desc";
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
return $result;
}
else
{
return "";
}
}
//这里用到了两个数组,$infocontent_child, $infofamily_child
//$infocontent_child用来存储对应于一个一级父下的所有子文章
//infofamily_child用来存储这些文章之间的关系,如0表示一级父、1表示二级父、2表示三级父
//依次类推。以方便显示文章之间的关系
//返回对应于一级父下的所有子文章和这些文章的内在联系
$infocontent_child;
$infofamily_child;
function readborder_child($parent, $arragement)
{
global $db;
global $infocontent_child;
global $infofamily_child;
$sql = "select id,title,importtime,writer,content,click,adda,fl from article where parent='$parent' order by id desc";
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
$i = 0;
while ($resarticle=mysql_fetch_array($result))
{
$nums = count($infocontent_child);
$infocontent_child[$nums] = $resarticle;
$nums = count($infofamily_child);
$infofamily_child[$nums] = $arragement;
if ($resarticle["id"] > 0)
{
$i++;
$parent = $resarticle["id"];
readborder_child($parent, $arragement+$i);
//递归调用
}
}
}
}
//这里用到了两个数组:$info_content, $info_family
//$info_content用来存储论坛所有的文章信息
//$info_family用来存储文章之间的关系
//该函数返回论坛中所有的文章,以及这些文章之间的关系
$info_content;
$info_family;
function readborder_all()
{
global $infocontent_child;
global $infofamily_child;
global $info_content;
global $info_family;
global $begin;
if (empty($begin))
{
$begin = 0;
}
$result_parent = readborder_parent();
//读出所有的一级父
if (!empty($result_parent))
{
while ($resarticle_parent = mysql_fetch_array($result_parent))
{
if ($resarticle_parent["id"] > 0)
{
//找出每一个一级父,再找出其所有与之关联的实体
$info_content[] = $resarticle_parent;
//一级父的info_family为0
$info_family[] = 0;
readborder_child($resarticle_parent["id"], 1);
if (is_array($infocontent_child) && is_array($infofamily_child))
{
$nums = count($infocontent_child);
for ($i=$begin; $i<$nums; $i++)
{
$info_content[] = $infocontent_child[$i];
$info_family[] = $infofamily_child[$i];
}
$begin = $nums;
}
}
}
}
}
//该函数返回某篇文章的相关信息
function readfamily($id, $obj)
{
global $db;
if (!empty($id))
{
//根据$obj的不同,返回自己的详细信息($obj == "self_content")或简略信息
//($obj=="self")、其父文章($obj=="parent")以及其一级子文章($obj=="child")
if ($obj == "self_content")
{
$sql = "select title,content,importtime,click,writer,adda,fl from article where id='$id'";
}
if ($obj == "self")
{
$sql = "select title,importtime,click,writer,adda,fl from article where id='$id'";
}
elseif ($obj == "parent")
{
$sql = "select parent from article where id='$id'";
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
list($parent) = mysql_fetch_row($result);
if ($parent > 0)
{
$sql = "select id from article where id='$parent'";
}
}
}
elseif ($obj == "child")
{
$sql = "select id from article where parent='$id' order by id desc";
}
if (!empty($sql))
{
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
return $result;
}
}
}
}
//通过调用函数readfamily()、read_three()将返回某篇文章的所有相关主体以及
//它们之间的内在联系
function read_three($id, $need)
{
$res_parent = readfamily($id, "parent");
$level = 0;
if ($info_parent = mysql_fetch_array($res_parent))
{
if ($info_parent["id"]>0)
{
$id_three[] = $info_parent["id"];
$family_three[] = $level;
$level = 1;
if ($info_parent["id"] > 0)
{
$res_same = readfamily($info_parent["id"], "child");
while ($info_same = mysql_fetch_array($res_same))
{
if ($info_same["id"] != $id)
{
$id_three[] = $info_same["id"];
$family_three[] = $level;
}
}
}
}
}
$id_three[] = $id;
$family_three[] = $level;
$res_child = readfamily($id, "child");
while ($info_child=mysql_fetch_array($res_child))
{
$id_three[] = $info_child["id"];
$family_three[] = $level + 1;
}
if ($need == "id")
{
return $id_three;
}
elseif ($need == "family")
{
return $family_three;
}
}
//搜索文章可以按标题、内容、作者、时间等四种方式进行
//返回文章搜索的结果
function search_forum($style_search, $text_search)
{
global $db;
$sql = "select id,title,content,click,writer,importtime,adda,fl from article where ";
if ($text_search != "")
{
if ($style_search == "title")
{
$sql = $sql."title like '%$text_search%'";
}
if ($style_search == "content")
{
$sql = $sql."content like '%$text_search%'";
}
if ($style_search == "writer")
{
$sql = $sql."writer like '%$text_search%'";
}
if ($style_search == "fl")
{
$sql = $sql."fl like '%$text_search%'";
}
}
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
return $result;
}
}
//用于将发表(或回复)的文章写入数据库中
function write_card($title, $content, $writer, $parent, $adda,$fl)
{
global $db;
if ($title != "")
{
//String_dowith, text_dowith分别调用了以前的函数
$title = string_dowith($title);
$content = text_dowith($content);
$importtime = date("Y-m-d H:i:s");
$click = 1;
//将文章写入数据库表
$sql = "insert into article ";
$sql = $sql."(title,content,importtime,writer,click,parent,adda,fl)";
$sql = $sql." values('$title','$content','$importtime','$writer','$click','$parent','$adda','$fl')";
$result = mysql_query($sql, $db) or db_error();
}
}
//将论坛中在线用户已加密的用户名解密,方法是再online表中根据cryptname查找name值
//返回在线用户的用户名
function undo_crypt($cryptname)
{
global $db;
$name = "";
if ($cryptname != "")
{
$sql = "select name from online where cryptname='$cryptname'";
$result = mysql_query($sql, $db) or db_error();
list($name) = mysql_fetch_row($result);
}
return $name;
}
//在article表中更新文章单击的数目
function update_click($id)
{
global $db;
$sql = "update article set click=click+1 where id='$id'";
$result = mysql_query($sql, $db) or db_error();
}
//显示文章的某种格式,用户可以修改此函数,将在文章列表中显示不同的格式
function pri_readinfo($num, $id, $title, $writer, $num_click, $importtime, $space,
$cryptname, $nowpage, $theid)
{
echo "<TR bgColor='#CCCCFF'>";
echo "<TD width='5%'>";
echo "<FONT color='#000000'>$num</FONT>";
echo "</TD>";
echo "<TD width='50%'>";
for ($i=0; $i<$space; $i++)
{
echo " ";
}
if ($theid == $id)
{
echo "<FONT color='#FF6699'>$title</FONT>";
}
else
{
echo "<A href='read.php?id=$id&nowpage=$nowpage&cryptname=$cryptname'>";
echo "<FONT color='#000000'>$title</FONT>";
echo "</A>";
echo "</TD>";
}
echo "<TD width='15%'>";
echo "<FONT color='#000000'>";
echo "<A href='../user/infouser.php?name=$writer&cryptname=$cryptname'>$writer</A>";
echo "</FONT>";
echo "</TD>";
echo "<TD width='5%'>";
echo "<FONT color='#000000'>$num_click</FONT>";
echo "</TD>";
echo "<TD width='15%'>";
echo "<FONT color='#000000'>$importtime</FONT>";
echo "</TD>";
echo "</TR>";
}
//网页中的分页格式,用户可以对此进行修改,选择自己喜欢的格式
function pri_page($formname, $nowpage, $num_page)
{
echo "<TABLE>";
echo "<TBODY>";
echo "<TR>";
echo "<TD width='50%' height='15'> </TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage <= 1)
{
echo "首页";
}
else
{
echo "<A href='.'>首页</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage <= 1)
{
echo "|上一页";
}
else
{
echo "<A href='JavaScript:document.$formname.nowpage.value=$nowpage-1";
echo "$formname.submit();'>|上一页</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
echo "$nowpage/$num_page";
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage >= $num_page)
{
echo "|下一页";
}
else
{$nowpage++;
echo "<A href='index.php?nowpage=$nowpage'>|下一页</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage >= $num_page)
{
echo "结尾页";
}
else
{
echo "<A href='index.php?nowpage=$num_page'>|结尾页</A>";
}
echo "</DIV>";
echo "</TD>";
echo "</TR>";
echo "</TBODY>";
echo "</TABLE>";
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -