article.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,497 行 · 第 1/4 页
PHP
1,497 行
// Register
case 0:
$value = time().", 0, 0";
break;
// Publish
default:
case 1:
$value = time().",".time().", 0";
break;
}
$cat_str[]="(".$art_id.", ".intval($id).", ".$value.", ".intval($cat["uid"]).")";
}
$values = implode(",",$cat_str);
$sql = "INSERT INTO ".art_DB_prefix("artcat")." (art_id, cat_id, ac_register, ac_publish, ac_feature, uid) VALUES ". $values;
if (!$result = $this->db->queryF($sql)) {
xoops_error("Insert article-category error:" . $sql);
return false;
}
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
if (!empty($GLOBALS["xoopsModuleConfig"]["notification_enabled"])) {
$notification_handler =& xoops_gethandler("notification");
if(!is_object($article)) $article_obj =& $this->get($article);
else $article_obj =& $article;
$tags = array();
$tags["ARTICLE_TITLE"] = $article_obj->getVar("art_title");
}
if(count($cats_pub)>0) {
$category_handler->setLastArticleIds($cats_pub);
if (!empty($GLOBALS["xoopsModuleConfig"]["notification_enabled"])) {
$cats = $cats_pub;
foreach($cats as $id){
$tags["ARTICLE_URL"] = XOOPS_URL . "/modules/" . $GLOBALS["artdirname"] . "/view.article.php".URL_DELIMITER."" .$article_obj->getVar("art_id")."/c".$id;
$category_obj =& $category_handler->get($id);
$tags["CATEGORY_TITLE"] = $category_obj->getVar("cat_title");
$notification_handler->triggerEvent("global", 0, "article_new", $tags);
$notification_handler->triggerEvent("global", 0, "article_monitor", $tags);
$notification_handler->triggerEvent("category", $id, "article_new", $tags);
$notification_handler->triggerEvent("article", $article_obj->getVar("art_id"), "article_approve", $tags);
unset($category_obj);
}
}
}
$cats_reg = array_diff(array_keys($cats), $cats_pub);
if(count($cats_reg)>0) {
if (!empty($GLOBALS["xoopsModuleConfig"]["notification_enabled"])) {
$cats = $cats_reg;
foreach($cats as $id){
$tags["ARTICLE_URL"] = XOOPS_URL . "/modules/" . $GLOBALS["artdirname"] . "/edit.article.php?article=" .$article_obj->getVar("art_id")."&category=".$id;
$category_obj =& $category_handler->get($id);
$tags["CATEGORY_TITLE"] = $category_obj->getVar("cat_title");
$notification_handler->triggerEvent("global", 0, "article_submit", $tags);
$notification_handler->triggerEvent("category", $id, "article_submit", $tags);
unset($category_obj);
}
}
}
return true;
}
/**
* terminate an article from categories
*
* {@link Xcategory}
*
* @param mixed $article array or {@link Article} reference to Article
* @param mixed $cat_id array of category IDs
* @return bool true on success
*/
function terminateCategory(&$article, $cat_id = null, $check_basic = true)
{
if( empty($cat_id) ) return false;
if(!is_array($cat_id)) $cat_id = array($cat_id);
if(is_object($article)){
$art_obj =& $article;
$art_id = $article->getVar("art_id");
}else{
$art_id = intval($article);
$art_obj =& $this->get($art_id);
if(!is_object($art_obj) || !$art_id = $art_obj->getVar("art_id")){
return false;
}
}
if(empty($art_id)) {
xoops_error("empty art_id");
return false;
}
$cat_id = array_map("intval",$cat_id);
$remove_all = false;
if($check_basic):
// The basic category is to remove
if(in_array($art_obj->getVar("cat_id"),$cat_id)){
$remove_all = true;
}else{
$cats = $art_obj->getCategories();
// Or all categories are to remove
if(array_intersect($cat_id, $cats) == $cats){
$remove_all = true;
}
}
endif;
$where = " WHERE art_id = ". $art_id;
if(empty($remove_all)){
$where .= " AND cat_id IN (".implode(",",$cat_id).")";
}
// remove article-category links
$sql = "DELETE FROM ".art_DB_prefix("artcat").$where;
if (!$result = $this->db->queryF($sql)) {
xoops_error("terminate article-category error:" . $sql);
return false;
}
// update last-articles for relevant categories
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
$category_handler->setLastArticleIds($cat_id);
if(!empty($remove_all)){
$this->delete($art_obj, true);
}
return true;
}
/**
* move an article=
*
* {@link Xcategory}
*
* @param object $article {@link Article} reference to Article
* @param int $cat_to destination category
* @param int $cat_from source category
* @return bool true on success
*/
function moveCategory(&$article, $cat_to, $cat_from)
{
if(in_array($cat_to, $article->getCategories())){
return true;
}
$sql = "UPDATE ".art_DB_prefix("artcat")." SET cat_id = ".intval($cat_to)." WHERE art_id= ". $article->getVar("art_id")." AND cat_id=".intval($cat_from);
if (!$result = $this->db->queryF($sql)) {
xoops_error("moveCategory error:" . $sql);
return false;
}
return true;
}
/**
* register an article to topics
*
* @param object $article {@link Article} reference to Article
* @param mixed $top_id array of topic IDs
* @return bool true on success
*/
function registerTopic(&$article, $top_id)
{
if(is_array($top_id)){
if(count($top_id)>0){
$top_str=array();
$top_id = array_map("intval",$top_id);
foreach($top_id as $top) {
$top_str[]="(".$article->getVar("art_id").", ".$article->getVar("uid").", $top,".time().")";
}
$values = implode(",",$top_str);
$top_id_value = " top_id IN (".implode(",",$top_id).")";
}else{
return false;
}
}else{
$values = "(".$article->getVar("art_id").", ".$article->getVar("uid").", ".intval($top_id).",".time().")";
$top_id_value = " top_id =".intval($top_id);
}
$sql = "INSERT INTO ".art_DB_prefix("arttop")." (art_id, uid, top_id, at_time) VALUES ". $values;
if (!$result = $this->db->queryF($sql)) {
xoops_error("Insert article-topic error:" . $sql);
return false;
}
$sql = "UPDATE ".art_DB_prefix("topic")." SET top_time=".time()." WHERE ". $top_id_value;
if (!$result = $this->db->queryF($sql)) {
xoops_error("Update topic time error:" . $sql);
return false;
}
return true;
}
/**
* terminate an article from topics
*
* @param mixed $article array or {@link Article} reference to Article
* @param mixed $top_id array of topic IDs
* @return bool true on success
*/
function terminateTopic(&$article, $top_id=null)
{
if(is_object($article)){
$art_id = $article->getVar("art_id");
}else{
$art_id =intval($article);
}
if(empty($art_id)) return false;
$where = " WHERE art_id =".$art_id;
if(!is_array($top_id) && !empty($top_id)){
$top_id = array($top_id);
}
if(count($top_id)>0){
$top_id = array_map("intval",$top_id);
$where .= " AND top_id IN (".implode(",",$top_id).")";
}
$sql = "DELETE FROM ".art_DB_prefix("arttop").$where;
if (!$result = $this->db->queryF($sql)) {
xoops_error("terminate article-topic error:" . $sql);
return false;
}
return true;
}
/**
* retrieve global article stats of the module
*
* @return array array of authors, article view count, article rates
*/
function &getStats()
{
$sql = "SELECT COUNT(DISTINCT uid) AS authors, SUM(art_counter) AS views, SUM(art_rates) AS rates FROM ".art_DB_prefix("article");
$result = $this->db->query($sql);
$myrow = $this->db->fetchArray($result);
return $myrow;
}
/**
* insert a trackback item of the article into database
*
* @param object $article {@link Article} reference to Article
* @param array $trackback associative array of time, url
* @return bool true on success
*/
function addTracked(&$article, $trackback)
{
$sql = "INSERT INTO ".art_DB_prefix("tracked")." (art_id, td_time, td_url) VALUES (". $article->getVar("art_id").", ".$trackback["time"].", ".$this->db->quoteString($trackback["url"]).")";
if (!$result = $this->db->queryF($sql)) {
xoops_error("Add tracked error:" . $sql);
return false;
}
return true;
}
/**
* update tracked trackbacks of the article
*
* @param object $article {@link Article} reference to Article
* @param mixed $td_id trackback id
* @return bool true on success
*/
function updateTracked(&$article, $td_id)
{
if(is_array($tb_id) && count($tb_id)>0) $id = "td_id IN (".implode(",",$td_id).")";
else $id = "td_id =".$td_id;
$sql = "UPDATE " . art_DB_prefix("tracked") . " SET td_time=". time() ." WHERE art_id=" . $article->getVar("art_id")." AND ".$id;
if (!$result = $this->db->queryF($sql)) {
xoops_error("update tracked error:" . $sql);
return false;
}
return true;
}
/**
* retrieve trackbacks of the article from database
*
* @param object $article {@link Article} reference to Article
* @param string $type type of trackbacks
* @return array associative array of trackback ID and values
*/
function getTracked(&$article, $type="all")
{
$sql = "SELECT * FROM " . art_DB_prefix("tracked") . " WHERE art_id =". $article->getVar("art_id");
if($type=="tracked") $sql .= "AND td_time>0";
if($type=="untracked") $sql .= "AND td_time=0";
$result = $this->db->query($sql);
$res = array();
while ($myrow = $this->db->fetchArray($result)) {
$res[$myrow["td_id"]] = $myrow;
}
return $res;
}
/**
* clean expired articles from database
*
* @param int $expire time limit for expiration
* @return bool true on success
*/
function cleanExpires($expire)
{
$sql = "DELETE FROM ".$this->table.
" WHERE art_time_create < ". (time()-intval($expire)).
" AND art_time_submit =0";
if (!$result = $this->db->queryF($sql)) {
xoops_error("cleanExpires error:". $sql);
return false;
}
return true;
}
/**
* clean orphan articles from database
*
* @return bool true on success
*/
function cleanOrphan()
{
/* for MySQL 4.1+ */
if($this->mysql_major_version() >= 4):
$sql = "DELETE FROM ".$this->table.
" WHERE ".
" (".$this->table.".cat_id >0 AND cat_id NOT IN ( SELECT DISTINCT cat_id FROM ".art_DB_prefix("category").") )";
else:
$sql = "DELETE ".$this->table." FROM ".$this->table.
" LEFT JOIN ".art_DB_prefix("category")." AS aa ON ".$this->table.".cat_id = aa.cat_id ".
" WHERE ".
" (".$this->table.".cat_id>0 AND aa.cat_id IS NULL)";
endif;
if (!$result = $this->db->queryF($sql)) {
//xoops_error("cleanOrphan error: ". $sql);
}
/* for MySQL 4.1+ */
if($this->mysql_major_version() >= 4):
$sql = "DELETE FROM ".art_DB_prefix("artcat").
" WHERE ".
" (".art_DB_prefix("artcat").".art_id = 0 OR art_id NOT IN ( SELECT DISTINCT art_id FROM ".$this->table.") )";
else:
$sql = "DELETE ".art_DB_prefix("artcat")." FROM ".art_DB_prefix("artcat").
" LEFT JOIN ".$this->table." AS aa ON ".art_DB_prefix("artcat").".art_id = aa.art_id ".
" WHERE ".
" (".art_DB_prefix("artcat").".art_id = 0 OR aa.art_id IS NULL)";
endif;
if (!$result = $this->db->queryF($sql)) {
//xoops_error("cleanOrphan error: ". $sql);
}
/* for MySQL 4.1+ */
if($this->mysql_major_version() >= 4):
$sql = "DELETE FROM ".art_DB_prefix("arttop").
" WHERE ".
" (".art_DB_prefix("arttop").".art_id = 0 OR art_id NOT IN ( SELECT DISTINCT art_id FROM ".$this->table.") )";
else:
$sql = "DELETE ".art_DB_prefix("arttop")." FROM ".art_DB_prefix("arttop").
" LEFT JOIN ".$this->table." AS aa ON ".art_DB_prefix("arttop").".art_id = aa.art_id ".
" WHERE ".
" (".art_DB_prefix("arttop").".art_id = 0 OR aa.art_id IS NULL)";
endif;
if (!$result = $this->db->queryF($sql)) {
//xoops_error("cleanOrphan error:". $sql);
}
return true;
}
}
'
);
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?