2012-11-30 15:11:41 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Archive - 统一文档类,实现各类文档的读取和IO操作,包括新闻、帮助、想法等。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class Archive
|
|
|
|
|
{
|
|
|
|
|
private $db; //传入PDO对象
|
|
|
|
|
public $ptype; //文档分类
|
|
|
|
|
public $tbl_archives; //文档表
|
|
|
|
|
public $tbl_categorys; //栏目表
|
|
|
|
|
public $tbl_catalog; //文档栏目关联表
|
|
|
|
|
public $tbl_tag; //关键字表
|
2012-12-04 09:31:14 +00:00
|
|
|
|
private $DefaultFetchMode; //默认检索模式,防止出现sdtClass错误
|
2012-11-30 15:11:41 +00:00
|
|
|
|
|
|
|
|
|
function __construct($db)
|
|
|
|
|
{
|
2012-12-03 04:00:47 +00:00
|
|
|
|
$this->db = $db;
|
2012-11-30 15:11:41 +00:00
|
|
|
|
//文档的大分类
|
|
|
|
|
//在数组中设置文档分类
|
|
|
|
|
//"中文名称" => "数据库中标识"
|
|
|
|
|
$this->ptype = array(
|
|
|
|
|
"新闻" => "news",
|
|
|
|
|
"想法" => "idea",
|
|
|
|
|
"帮助" => "help",
|
|
|
|
|
"关于" => "about"
|
2012-12-03 04:00:47 +00:00
|
|
|
|
);
|
2012-11-30 15:11:41 +00:00
|
|
|
|
$this->tbl_archives = "archive";
|
|
|
|
|
$this->tbl_categorys = "ar_category";
|
|
|
|
|
$this->tbl_catalog = "ar_catalog";
|
|
|
|
|
$this->tbl_tag = "ar_tag";
|
2012-12-04 09:31:14 +00:00
|
|
|
|
|
|
|
|
|
$this->DefaultFetchMode = "PDO::FETCH_BOTH";
|
2012-11-30 15:11:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
写入关系表
|
2012-12-03 04:00:47 +00:00
|
|
|
|
不能外部调用
|
2012-11-30 15:11:41 +00:00
|
|
|
|
*/
|
2012-12-03 04:00:47 +00:00
|
|
|
|
private function ToCatalog($aid,$cid,$uuid='',$status=0){
|
2012-11-30 15:11:41 +00:00
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2012-12-03 04:00:47 +00:00
|
|
|
|
//写入关系表,外部只能调用此接口
|
|
|
|
|
public function AddToCatalog($aid,$cid,$uuid='',$status=0)
|
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($aid))
|
2012-11-30 15:11:41 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 04:00:47 +00:00
|
|
|
|
if(!is_array($cid) && !is_numeric($cid))
|
2012-11-30 15:11:41 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 04:00:47 +00:00
|
|
|
|
if(is_array($cid) && count($cid)<1)
|
2012-11-30 15:11:41 +00:00
|
|
|
|
{
|
2012-12-03 04:00:47 +00:00
|
|
|
|
return false;
|
2012-11-30 15:11:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 07:49:37 +00:00
|
|
|
|
//多个cid
|
2012-12-03 04:00:47 +00:00
|
|
|
|
if(is_array($cid))
|
2012-11-30 15:11:41 +00:00
|
|
|
|
{
|
2012-12-07 07:49:37 +00:00
|
|
|
|
|
2012-12-03 04:00:47 +00:00
|
|
|
|
foreach($cid as $v)
|
|
|
|
|
{
|
2012-12-07 07:49:37 +00:00
|
|
|
|
//多个UUID
|
|
|
|
|
if(is_array($uuid))
|
|
|
|
|
{
|
|
|
|
|
foreach ($uuid as $vv)
|
|
|
|
|
{
|
|
|
|
|
$this->ToCatalog($aid,$v,$vv,$status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//单个UUID
|
|
|
|
|
else{
|
|
|
|
|
$this->ToCatalog($aid,$v,$uuid,$status);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}
|
2012-11-30 15:11:41 +00:00
|
|
|
|
return true;
|
2012-12-07 07:49:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//单个cid
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
//多个UUID
|
|
|
|
|
if(is_array($uuid))
|
|
|
|
|
{
|
|
|
|
|
foreach($uuid as $v)
|
|
|
|
|
{
|
|
|
|
|
$this->ToCatalog($aid,$cid,$v,$status);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//单个cid和uuid
|
|
|
|
|
else{
|
|
|
|
|
return $this->ToCatalog($aid,$cid,$uuid,$status);
|
|
|
|
|
}
|
2012-11-30 15:11:41 +00:00
|
|
|
|
}
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}//AddToCatalog
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除一个关系
|
|
|
|
|
function DeleteCatalog($id)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_catalog." WHERE id=$id";
|
|
|
|
|
@$this->db->exec($sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 更改栏目 ChangeCatalog()
|
|
|
|
|
*/
|
|
|
|
|
function ChangeCatalog($aid,$typeid,$uuid='',$status=0){
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$sql = "SELECT * FROM ar_catalog WHERE aid=$aid";
|
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
|
|
|
|
|
|
$types = array();
|
|
|
|
|
|
|
|
|
|
foreach($rows as $k=>$v)
|
|
|
|
|
{
|
|
|
|
|
$types[] = $v['cid'];
|
2012-12-05 07:12:38 +00:00
|
|
|
|
if(is_array($typeid))
|
2012-12-03 04:00:47 +00:00
|
|
|
|
{
|
2012-12-05 07:12:38 +00:00
|
|
|
|
if(!in_array($v['cid'],$typeid))
|
|
|
|
|
{
|
|
|
|
|
//删除一个栏目
|
|
|
|
|
$this->DeleteCatalog($v['id']);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2012-12-03 04:00:47 +00:00
|
|
|
|
$this->DeleteCatalog($v['id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-05 07:12:38 +00:00
|
|
|
|
if(is_array($typeid))
|
2012-12-03 04:00:47 +00:00
|
|
|
|
{
|
2012-12-05 07:12:38 +00:00
|
|
|
|
foreach($typeid as $v)
|
2012-12-03 04:00:47 +00:00
|
|
|
|
{
|
2012-12-05 07:12:38 +00:00
|
|
|
|
if(!in_array($v,$types))
|
|
|
|
|
{
|
|
|
|
|
//添加一个栏目
|
|
|
|
|
$this->ToCatalog($aid,$v,$uuid,$status);
|
|
|
|
|
}
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}
|
2012-12-05 07:12:38 +00:00
|
|
|
|
}else{
|
|
|
|
|
$this->ToCatalog($aid,$typeid,$uuid,$status);
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}catch(Exception $e){
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 15:11:41 +00:00
|
|
|
|
}//ChangeCatalog
|
|
|
|
|
|
2012-12-07 07:49:37 +00:00
|
|
|
|
//ChangeCatalogByUUID 根据UUID更改记录
|
|
|
|
|
function ChangeCatalogByUUID($aid,$typeid,$uuid,$status=0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$sql = "SELECT * FROM ar_catalog WHERE aid=$aid";
|
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
|
|
|
|
|
|
$types = array();
|
|
|
|
|
|
|
|
|
|
foreach($rows as $k=>$v)
|
|
|
|
|
{
|
|
|
|
|
$types[] = $v['uuid'];
|
|
|
|
|
if(is_array($uuid))
|
|
|
|
|
{
|
|
|
|
|
if(!in_array($v['uuid'],$uuid))
|
|
|
|
|
{
|
|
|
|
|
//删除一个栏目
|
|
|
|
|
$this->DeleteCatalog($v['id']);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$this->DeleteCatalog($v['id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(is_array($uuid))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach($uuid as $v)
|
|
|
|
|
{
|
|
|
|
|
if(!in_array($v,$types))
|
|
|
|
|
{
|
|
|
|
|
//添加一个记录
|
|
|
|
|
$this->ToCatalog($aid,$typeid,$v,$status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$this->ToCatalog($aid,$typeid,$uuid,$status);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}catch(Exception $e){
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}//ChangeCatalogByUUID
|
|
|
|
|
|
2012-11-30 15:11:41 +00:00
|
|
|
|
//修改文档状态
|
|
|
|
|
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{
|
2012-12-05 07:12:38 +00:00
|
|
|
|
if($this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$keywords)))
|
2012-11-30 15:11:41 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}//DeleteTags
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* addArchive() 添加档案
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
*
|
|
|
|
|
* @return int;
|
|
|
|
|
*/
|
2012-12-05 07:12:38 +00:00
|
|
|
|
function addArchive($data,$typeid,$keyword='',$uuid='')
|
2012-12-03 04:00:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$data = $this->scanField($data);
|
|
|
|
|
if($data == false)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//执行SQL语句后返回插入文章表的ID
|
2014-05-09 02:36:30 +00:00
|
|
|
|
$sql = "INSERT INTO ".$this->tbl_archives." (userid,title,description,image,source,ts_published,is_pub,body,language)
|
2012-12-03 04:00:47 +00:00
|
|
|
|
VALUES (
|
|
|
|
|
".$data['userid'].",
|
|
|
|
|
".$data['title'].",
|
|
|
|
|
".$data['description'].",
|
|
|
|
|
".$data['image'].",
|
|
|
|
|
".$data['source'].",
|
|
|
|
|
".$data['ts_published'].",
|
|
|
|
|
".$data['is_pub'].",
|
2014-05-09 02:36:30 +00:00
|
|
|
|
".$data['body'].",
|
|
|
|
|
".$data['language']."
|
2012-12-03 04:00:47 +00:00
|
|
|
|
)
|
|
|
|
|
RETURNING id";
|
|
|
|
|
try{
|
|
|
|
|
$sth = $this->db->prepare($sql);
|
|
|
|
|
if($sth->execute())
|
|
|
|
|
{
|
|
|
|
|
$temp = $sth->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
$newAid = $temp['id'];
|
2012-12-05 07:12:38 +00:00
|
|
|
|
$this->AddToCatalog($newAid,$typeid,$uuid);
|
2012-12-03 04:00:47 +00:00
|
|
|
|
if(!empty($keyword))
|
|
|
|
|
{
|
2012-12-03 10:08:25 +00:00
|
|
|
|
$this->MakeTags($newAid,$keyword);
|
2012-12-03 04:00:47 +00:00
|
|
|
|
}
|
|
|
|
|
return $newAid;
|
|
|
|
|
}else{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception $e)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}//addArchive()
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* updateArchive() 更改文档
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2012-12-05 07:12:38 +00:00
|
|
|
|
function updateArchive($aid,$data,$typeid,$keyword='',$uuid='')
|
2012-12-03 04:00:47 +00:00
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($aid))
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $this->scanField($data);
|
|
|
|
|
if($data == false)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE ".$this->tbl_archives." SET
|
|
|
|
|
userid=".$data['userid'].",
|
|
|
|
|
title=".$data['title'].",
|
|
|
|
|
description=".$data['description'].",
|
|
|
|
|
image=".$data['image'].",
|
|
|
|
|
source=".$data['source'].",
|
|
|
|
|
ts_published=".$data['ts_published'].",
|
|
|
|
|
is_pub=".$data['is_pub'].",
|
2014-05-09 02:36:30 +00:00
|
|
|
|
body=".$data['body'].",
|
|
|
|
|
language=".$data['language']."
|
2012-12-03 04:00:47 +00:00
|
|
|
|
WHERE id=$aid";
|
|
|
|
|
try{
|
|
|
|
|
if($this->db->exec($sql))
|
|
|
|
|
{
|
|
|
|
|
if(!empty($keyword))
|
|
|
|
|
{
|
|
|
|
|
$this->DeleteTags($aid);
|
|
|
|
|
$this->MakeTags($aid,$keyword);
|
|
|
|
|
}
|
2012-12-07 07:49:37 +00:00
|
|
|
|
if(!is_array($uuid))
|
|
|
|
|
{
|
|
|
|
|
$this->ChangeCatalog($aid,$typeid,$uuid);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$this->ChangeCatalogByUUID($aid,$typeid,$uuid);
|
|
|
|
|
}
|
2012-12-03 04:00:47 +00:00
|
|
|
|
return $aid;
|
|
|
|
|
}else{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception $e)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//扫描字段
|
|
|
|
|
function scanField($data){
|
|
|
|
|
|
|
|
|
|
if(!is_array($data))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
2012-12-01 12:25:12 +00:00
|
|
|
|
}
|
2012-12-03 04:00:47 +00:00
|
|
|
|
|
|
|
|
|
//对特殊字段进行特别处理
|
|
|
|
|
$data['title'] = $this->replaceHtml($data['title']);
|
|
|
|
|
$data['description'] = $this->replaceHtml($data['description']);
|
|
|
|
|
|
|
|
|
|
//将参数过滤一遍,如果是字符型字段
|
|
|
|
|
//就执行db->quote()
|
|
|
|
|
foreach($data as $k=>$v)
|
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($v) || !is_bool($v))
|
|
|
|
|
{
|
|
|
|
|
$data[$k] = $this->db->quote($v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}//scanField
|
|
|
|
|
|
|
|
|
|
//过滤UTF-8字符的html代码
|
|
|
|
|
function replaceHtml($html)
|
|
|
|
|
{
|
|
|
|
|
$newString = htmlentities($html, ENT_QUOTES, "UTF-8");
|
|
|
|
|
return $newString;
|
|
|
|
|
}
|
2012-12-03 10:08:25 +00:00
|
|
|
|
|
|
|
|
|
/************* 读取 ****************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* makeArchiveUrl()
|
|
|
|
|
* 创建一个文档的链接
|
|
|
|
|
* 连接地址需要和路由规则对应
|
|
|
|
|
*
|
|
|
|
|
* @param array $parts
|
|
|
|
|
*
|
|
|
|
|
* @return string;
|
|
|
|
|
*/
|
|
|
|
|
public function makeArchiveUrl($parts)
|
|
|
|
|
{
|
|
|
|
|
$http_host = "http://".$_SERVER ['HTTP_HOST'];
|
|
|
|
|
$controller = "archives";
|
2012-12-04 04:34:47 +00:00
|
|
|
|
$url = $http_host."/".$controller."/".$parts['ptype']."/".$parts['type_code']."/archive-".$parts['archive_id'].".html";
|
|
|
|
|
//$url = $http_host."/".$controller."/".$parts['type_code']."/".$parts['archive_id'];
|
2012-12-03 10:08:25 +00:00
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function makeCategoryUrl($parts)
|
|
|
|
|
{
|
|
|
|
|
$http_host = "http://".$_SERVER ['HTTP_HOST'];
|
|
|
|
|
$controller = "archives";
|
|
|
|
|
$url = $http_host."/".$controller."/".$parts['ptype']."/".$parts['type_code']."";
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* getArchiveUrl()
|
|
|
|
|
* 通过文档ID和栏目ID获得某个文档的url
|
|
|
|
|
* 仅适用于单个栏目的文档且已经得知其栏目ID
|
|
|
|
|
* 如果是多个栏目的文档,则获取第一个栏目的文档连接
|
|
|
|
|
*
|
|
|
|
|
* @param int $aid
|
|
|
|
|
*
|
|
|
|
|
* @return string;
|
|
|
|
|
*/
|
|
|
|
|
function getArchiveUrlByCid($aid,$cid=0)
|
|
|
|
|
{
|
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ecField = array($aid);
|
|
|
|
|
$wheresql = "";
|
|
|
|
|
|
|
|
|
|
if(!empty($cid) && is_numeric($cid))
|
|
|
|
|
{
|
|
|
|
|
$wheresql = " AND c.id=? ";
|
|
|
|
|
$ecField[] = $cid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT arc.id,c.id as cid,c.title,c.code,c.ptype FROM ".$this->tbl_archives." arc
|
|
|
|
|
LEFT JOIN ".$this->tbl_catalog." ct ON arc.id=ct.aid
|
|
|
|
|
LEFT JOIN ".$this->tbl_categorys." c ON ct.cid = c.id
|
|
|
|
|
WHERE arc.id=? $wheresql
|
|
|
|
|
LIMIT 1";
|
|
|
|
|
$sth = $this->db->prepare($sql);
|
|
|
|
|
$sth->execute($ecField);
|
2012-12-04 09:31:14 +00:00
|
|
|
|
$row = $sth->fetch(PDO::FETCH_BOTH);
|
2012-12-03 10:08:25 +00:00
|
|
|
|
|
|
|
|
|
$url_parts = array(
|
|
|
|
|
"ptype"=>$row['ptype'],
|
|
|
|
|
"type_code"=>$row['code'],
|
|
|
|
|
"archive_id"=>$row['id']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
'archive_url'=>$this->makeArchiveUrl($url_parts),
|
|
|
|
|
'type_title'=>$row['title'],
|
|
|
|
|
'type_id'=>$row['cid'],
|
|
|
|
|
'type_url'=>$this->makeCategoryUrl($url_parts),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}//getArchiveUrlByCid()
|
|
|
|
|
|
|
|
|
|
function getArchive($code='')
|
|
|
|
|
{
|
|
|
|
|
$sql = "select a.* from ".$this->tbl_archives." a
|
|
|
|
|
left join ".$this->tbl_catalog." ac on a.id=ac.aid
|
|
|
|
|
left join ".$this->tbl_categorys." c on ac.cid=c.id ";
|
|
|
|
|
if (!empty($code)) $sql.=" where c.code='".$code."'";
|
|
|
|
|
$rs=$this->db->query($sql);
|
|
|
|
|
$rows=$rs->fetchAll();
|
|
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-13 04:04:42 +00:00
|
|
|
|
//getOneArchive 获取单个文档
|
2012-12-03 10:08:25 +00:00
|
|
|
|
function getOneArchive($title,$ptype='news')
|
|
|
|
|
{
|
|
|
|
|
$sql="update ".$this->tbl_archives." set click=click+1";
|
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
$sql = "select a.* from ".$this->tbl_archives." a
|
|
|
|
|
left join ".$this->tbl_catalog." ac on a.id=ac.aid
|
|
|
|
|
left join ".$this->tbl_categorys." c on ac.cid=c.id ";
|
|
|
|
|
$sql.=" where a.title=? and c.ptype=?";
|
|
|
|
|
$sth=$this->db->prepare($sql);
|
|
|
|
|
$sth->execute(array($title,$ptype));
|
|
|
|
|
$rows=$sth->fetch();
|
|
|
|
|
return $rows;
|
2012-12-13 04:04:42 +00:00
|
|
|
|
}//getOneArchive
|
2012-12-05 07:12:38 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* getArchiveField() 读取某个文档的某个字段
|
|
|
|
|
*
|
|
|
|
|
* @param int $aid
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getArchiveField($aid,$field)
|
|
|
|
|
{
|
|
|
|
|
if(!is_numeric($aid))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT $field as output_string FROM ".$this->tbl_archives." WHERE id=$aid";
|
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
|
$row = $sth->fetch();
|
|
|
|
|
|
|
|
|
|
return $row['output_string'];
|
2012-12-13 04:04:42 +00:00
|
|
|
|
}//getArchiveField
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* getArchiveByUUID() 通过UUID获得数据新闻
|
|
|
|
|
*
|
|
|
|
|
* @param uuid $uuid
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function getArchiveByUUID($uuid){
|
|
|
|
|
|
|
|
|
|
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT arc.* FROM archive arc
|
|
|
|
|
LEFT JOIN ar_catalog ct ON arc.id = ct.aid
|
|
|
|
|
WHERE ct.uuid='$uuid'";
|
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
|
$rows = $sth->fetchAll(PDO::FETCH_BOTH);
|
|
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
|
|
|
|
|
|
}//getArchiveByUUID()
|
2012-11-30 15:11:41 +00:00
|
|
|
|
}
|