266 lines
4.7 KiB
PHP
266 lines
4.7 KiB
PHP
<?php
|
|
class news
|
|
{
|
|
private $db; //传入PDO对象
|
|
public $ptype; //文档分类
|
|
public $tbl_archives; //文档表
|
|
public $tbl_categorys; //栏目表
|
|
public $tbl_catalog; //文档栏目关联表
|
|
public $tbl_tag; //关键字表
|
|
|
|
function __construct($db)
|
|
{
|
|
$this->db = $db;
|
|
$this->ptype();
|
|
$this->tbl_archives = "archive";
|
|
$this->tbl_categorys = "ar_category";
|
|
$this->tbl_catalog = "ar_catalog";
|
|
$this->tbl_tag = "ar_tag";
|
|
}
|
|
|
|
//文档分类
|
|
//在数组中设置档案分类
|
|
// "中文名称" => "数据库中标识"
|
|
function ptype (){
|
|
$this->ptype = array(
|
|
"新闻" => "news",
|
|
"数据新闻" => "datanews",
|
|
"说明文档" => "help",
|
|
"FAQ" => "faq"
|
|
);
|
|
}//ptype()
|
|
|
|
/*
|
|
递归获得所有栏目
|
|
*/
|
|
function getAllCategory($hide = true){
|
|
|
|
if($hide == -1)
|
|
{
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
ORDER BY displayorder asc";
|
|
}else{
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
WHERE is_pub = $hide
|
|
ORDER BY displayorder asc";
|
|
}
|
|
|
|
$re = $this->db->query($sql);
|
|
$categorys = $re->fetchAll();
|
|
|
|
return $categorys;
|
|
}
|
|
|
|
//取得最顶级的栏目
|
|
function getTopType(){
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
WHERE is_pub = true AND fid=0
|
|
ORDER BY displayorder asc";
|
|
$re = $this->db->query($sql);
|
|
$categorys = $re->fetchAll();
|
|
return $categorys;
|
|
}
|
|
|
|
//获得栏目
|
|
function getCategory($id)
|
|
{
|
|
$sql = "SELECT * FROM ".$this->tbl_categorys." WHERE id=?";
|
|
$sth = $this->db->prepare($sql);
|
|
$sth->execute(array($id));
|
|
$rows = $sth->fetch();
|
|
return $rows;
|
|
}
|
|
|
|
/*
|
|
写入关系表
|
|
*/
|
|
function ToCatalog($aid,$cid,$uuid='',$status=0){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(empty($cid) && empty($uuid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data = array(
|
|
"aid" => $aid,
|
|
"cid" => $cid,
|
|
"status" => $status
|
|
);
|
|
|
|
if(!empty($uuid))
|
|
{
|
|
$data['uuid'] = $uuid;
|
|
}
|
|
|
|
if($this->db->insert($this->tbl_catalog,$data))
|
|
{
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
|
|
}//ToCatalog()
|
|
|
|
/*
|
|
* 更改栏目 ChangeCatalog()
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
function ChangeCatalog($aid,$cid,$uuid='',$status=0){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(empty($cid) && empty($uuid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data = array(
|
|
"cid" => $cid,
|
|
"status" => $status
|
|
);
|
|
|
|
if(!empty($uuid))
|
|
{
|
|
$data['uuid'] = $uuid;
|
|
}
|
|
|
|
if($this->db->update($this->tbl_catalog,$data,"id=$aid"))
|
|
{
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
|
|
}//ChangeCatalog
|
|
|
|
//修改文档状态
|
|
function ChangeStatus($aid,$pub){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(!is_bool($pub))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data = array(
|
|
"is_pub" => $pub
|
|
);
|
|
|
|
if($this->db->update($this->tbl_archives,$data,"id=$aid"))
|
|
{
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}//修改文档状态
|
|
|
|
//删除文档
|
|
function DeleteArchives($aid){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$this->DeleteTags($aid);
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_archives." WHERE id=$aid";
|
|
@$this->db->exec($sql);
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_catalog." WHERE aid=$aid";
|
|
@$this->db->exec($sql);
|
|
|
|
return true;
|
|
}//DeleteArchives
|
|
|
|
//写入标签关系
|
|
function MakeTags($aid,$keywords){
|
|
|
|
$keywords = trim($keywords);
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(preg_match("/,/",$keywords))
|
|
{
|
|
$tag = explode(",",$keywords);
|
|
}else{
|
|
if($this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$tag)))
|
|
{
|
|
return true;
|
|
}else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if(is_array($tag))
|
|
{
|
|
foreach($tag as $v)
|
|
{
|
|
$v = trim($v);
|
|
if($v!='')
|
|
{
|
|
$this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$v));
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
}//MakeTags
|
|
|
|
//读取标签
|
|
function GetTags($aid,$limit=0){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_tag." WHERE id=$aid";
|
|
|
|
if(!empty($limit))
|
|
{
|
|
$sql .= " LIMIT $limit";
|
|
}
|
|
|
|
$sth = $this->db->query($sql);
|
|
$rows = $sth->fetchAll();
|
|
|
|
$keywords = array();
|
|
foreach($rows as $k=>$v)
|
|
{
|
|
$keywords[] = $v['tag'];
|
|
}
|
|
|
|
return $keywords;
|
|
}//GetTags
|
|
|
|
//删除标签
|
|
function DeleteTags($aid){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_tag." WHERE id=$aid";
|
|
@$this->db->exec($sql);
|
|
return true;
|
|
}
|
|
} |