⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tag.php

📁 php 开发的内容管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		        }elseif(!$ts_id){
			        $sql = 	" INSERT INTO {$this->table_stats}".
			        		" 	(tag_id, tag_modid, tag_catid, tag_count)".
			        		" VALUES ".
			        		" 	({$tag_id}, {$modid}, {$catid}, {$count})"
			        		;
		        }
		        if( !empty($sql) && ($result = $this->db->queryF($sql)) == false){
			        xoops_error($this->db->error());
		        }
	        }
        }
        
        return true;
    }
    
    /**
     * Get tags with item count
     * 
     * @param	object	$criteria
     * @param	boolean	$fromStats	fetch from tag-stats table
     * @return 	array	associative array of tags (id, term, count)
     */
    function &getByLimit($criteria = null, $fromStats = true)
    {
	    $ret = array();
	    if($fromStats){
		    $sql  = "	SELECT DISTINCT(o.{$this->keyName}), o.tag_term, o.tag_status, SUM(l.tag_count) AS count, l.tag_modid";
		    $sql .= "	FROM {$this->table} AS o LEFT JOIN {$this->table_stats} AS l ON l.{$this->keyName} = o.{$this->keyName}";
	    }else{
		    $sql  = "	SELECT DISTINCT(o.{$this->keyName}), o.tag_term, o.tag_status, COUNT(l.tl_id) AS count, l.tag_modid";
		    $sql .= "	FROM {$this->table} AS o LEFT JOIN {$this->table_link} AS l ON l.{$this->keyName} = o.{$this->keyName}";
	    }
	    
	    $limit = null;
	    $start = null;
        $sort = "";
        $order = "";
        if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
            $sql .= "	".$criteria->renderWhere();
            $sort = $criteria->getSort();
            $order = $criteria->getOrder();
            $limit = $criteria->getLimit();
            $start = $criteria->getStart();
        }
		$sql  .= "	GROUP BY o.{$this->keyName}";
	    
	    $order = strtoupper($order);
	    $sort = strtolower($sort);
	    switch($sort) {
		    case "a":
		    case "alphabet":
		    	$order = ("DESC" != $order) ? "ASC" : "DESC";
			    $sql  .= "	ORDER BY o.tag_term {$order}";
	    		break;
		    case "id":
		    case "time":
		    	$order = ("ASC" != $order) ? "DESC" : "ASC";
			    $sql  .= "	ORDER BY o.{$this->keyName} {$order}";
	    		break;
		    case "c":
		    case "count":
		    default:
		    	$order = ("ASC" != $order) ? "DESC" : "ASC";
			    $sql  .= "	ORDER BY count {$order}";
	    		break;
    	}
    	
        if( ($result = $this->db->query($sql, $limit, $start)) == false){
	        xoops_error($this->db->error());
	        return null;
        }
        while($myrow = $this->db->fetchArray($result)){
        	$ret[$myrow[$this->keyName]] = array(
        				"id"	=> $myrow[$this->keyName],
        				"term"	=> htmlspecialchars($myrow["tag_term"]),
        				"status"=> $myrow["tag_status"],
        				"modid"	=> $myrow["tag_modid"],
        				"count"	=> intval($myrow["count"]),
        				);
        }
        
        return $ret;
    }
    
    /**
     * Get count of tags
     * 
     * @param	integer	$modid	id of corresponding module, optional: 0 for all; >1 for a specific module
     * @param	integer	$catid	id of corresponding category, optional
     * @return 	integer	count
     */
    function getCount($criteria = null)
    {
	    $ret = 0;
	    
	    /*
	    $catid	= intval($catid);
	    $modid	= intval($modid);
	    */
	    $sql = "	SELECT COUNT(DISTINCT o.{$this->keyName})";
	    $sql .= "	FROM {$this->table} AS o LEFT JOIN {$this->table_link} AS l ON l.{$this->keyName} = o.{$this->keyName}";
        if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
            $sql .= "	".$criteria->renderWhere();
        }
        /*
	    $sql_where	= "	WHERE 1 = 1";
	    if(!empty($modid)){
	    	$sql_where	.= " AND l.tag_modid = {$modid}";
	    }
	    if(empty($catid) || $catid > 0){
	    	$sql_where	.= " AND l.tag_catid = {$catid}";
	    }
    	
        $sql = 	$sql_select . " " . $sql_from . " " . $sql_where;
        */
        if( ($result = $this->db->query($sql)) == false){
	        xoops_error($this->db->error());
	        return $ret;
        }
        list($ret) = $this->db->fetchRow($result);
        
        return $ret;
    }
    
    /**
     * Get items linked with a tag
     * 
     * @param	object	criteria
     * @return 	array	associative array of items (id, modid, catid)
     */
    function &getItems($criteria = null)
    {
	    $ret = array();
	    $sql  = "	SELECT o.tl_id, o.tag_itemid, o.tag_modid, o.tag_catid, o.tag_time";
	    $sql .= "	FROM {$this->table_link} AS o LEFT JOIN {$this->table} AS l ON l.{$this->keyName} = o.{$this->keyName}";
	    
	    $limit = null;
	    $start = null;
        $sort = "";
        $order = "";
        if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
            $sql .= "	".$criteria->renderWhere();
            $sort = $criteria->getSort();
            $order = $criteria->getOrder();
            $limit = $criteria->getLimit();
            $start = $criteria->getStart();
        }
	    
	    $order = strtoupper($order);
	    $sort = strtolower($sort);
	    switch(strtolower($sort)) {
		    case "item":
		    	$order = ("DESC" != $order) ? "ASC" : "DESC";
			    $sql .= "	ORDER BY o.tag_itemid {$order}, o.tl_id DESC";
	    		break;
		    case "m":
		    case "module":
		    	$order = ("DESC" != $order) ? "ASC" : "DESC";
			    $sql .= "	ORDER BY o.tag_modid {$order}, o.tl_id DESC";
	    		break;
		    case "t":
		    case "time":
		    default:
		    	$order = ("ASC" != $order) ? "DESC" : "ASC";
			    $sql .= "	ORDER BY o.tl_id {$order}";
	    		break;
    	}
    	
        if( ($result = $this->db->query($sql, $limit, $start)) == false){
	        xoops_error($this->db->error());
		    return $ret;
        }
        while($myrow = $this->db->fetchArray($result)){
        	$ret[$myrow["tl_id"]] = array(
        				"itemid"=> $myrow["tag_itemid"],
        				"modid"	=> $myrow["tag_modid"],
        				"catid"	=> $myrow["tag_catid"],
        				"time"	=> $myrow["tag_time"],
        				);
        }
        
        return $ret;
    }
    
    /**
     * Get count of items linked with a tag
     * 
     * @param	integer	$tag_id
     * @param	integer	$modid	id of corresponding module, optional: 0 for all; >1 for a specific module
     * @param	integer	$catid	id of corresponding category, optional
     * @return 	integer	count
     */
    function getItemCount($tag_id, $modid = 0, $catid = 0)
    {
	    $ret = 0;
	    
	    if(!$tag_id	= intval($tag_id)){
		    return $ret;
	    }
	    $catid	= intval($catid);
	    $modid	= intval($modid);
	    
	    $sql_select	= "	SELECT COUNT(DISTINCT o.tl_id)";
	    $sql_from	= "	FROM {$this->table_link} AS o LEFT JOIN {$this->table} AS l ON l.{$this->keyName} = o.{$this->keyName}";
	    $sql_where	= "	WHERE o.tag_id = {$tag_id}";
	    if(!empty($modid)){
	    	$sql_where	.= "	AND o.tag_modid = {$modid}";
	    }
	    if(empty($catid) || $catid > 0){
	    	$sql_where	.= "	AND o.tag_catid = {$catid}";
	    }
    	
        $sql = 	$sql_select . " " . $sql_from . " " . $sql_where;
        if( ($result = $this->db->query($sql)) == false){
	        xoops_error($this->db->error());
	        return $ret;
        }
        list($ret) = $this->db->fetchRow($result);
        
        return $ret;
    }
    
    /**
     * delete an object as well as links relying on it
     * 
     * @param	object	$object		{@link NewbbTag}
     * @param 	bool 	$force 		flag to force the query execution despite security settings
     * @return 	bool
     */
    function delete(&$object, $force = true)
    {
	    if(!is_object($object) || !$object->getVar($this->keyName)) return false;
        $queryFunc = empty($force) ? "query":"queryF";
	    
	    /*
	     * Remove item-tag links
	     */
        $sql = "DELETE".
        		" FROM {$this->table_link}" . 
        		" WHERE  {$this->keyName} = " . $object->getVar($this->keyName);
        if( ($result = $this->db->{$queryFunc}($sql)) == false){
	       // xoops_error($this->db->error());
        }
        
	    /*
	     * Remove stats-tag links
	     */
        $sql = "DELETE".
        		" FROM {$this->table_stats}" . 
        		" WHERE  {$this->keyName} = " . $object->getVar($this->keyName);
        if( ($result = $this->db->{$queryFunc}($sql)) == false){
	       // xoops_error($this->db->error());
        }
	    
        return parent::delete($object, $force);
    }

    /**
     * clean orphan links from database
     * 
     * @return 	bool	true on success
     */
    function cleanOrphan()
    {
	    mod_loadFunctions("recon");
	    return tag_cleanOrphan();
        return true;
    }
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -