示例#1
0
 function setContent($isreturn = false)
 {
     global $jieqiTpl;
     global $jieqiConfigs;
     jieqi_getconfigs('article', 'configs');
     $article_static_url = empty($jieqiConfigs['article']['staticurl']) ? $GLOBALS['jieqiModules']['article']['url'] : $jieqiConfigs['article']['staticurl'];
     $article_dynamic_url = empty($jieqiConfigs['article']['dynamicurl']) ? $GLOBALS['jieqiModules']['article']['url'] : $jieqiConfigs['article']['dynamicurl'];
     $jieqiTpl->assign('article_static_url', $article_static_url);
     $jieqiTpl->assign('article_dynamic_url', $article_dynamic_url);
     jieqi_includedb();
     $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
     $criteria = new CriteriaCompo();
     $criteria->setFields("r.*,a.articlename");
     $criteria->setTables(jieqi_dbprefix('article_reviews') . " AS r LEFT JOIN " . jieqi_dbprefix('article_article') . " AS a ON r.ownerid=a.articleid");
     if ($this->exevars['istop'] == 1) {
         $criteria->add(new Criteria('r.istop', '1'));
     } elseif ($this->exevars['istop'] == 2) {
         $criteria->add(new Criteria('r.istop', '0'));
     }
     if ($this->exevars['isgood'] == 1) {
         $criteria->add(new Criteria('r.isgood', '1'));
     } elseif ($this->exevars['isgood'] == 2) {
         $criteria->add(new Criteria('r.isgood', '0'));
     }
     $criteria->setSort('r.topicid');
     $criteria->setOrder('DESC');
     $criteria->setLimit($this->exevars['listnum']);
     $criteria->setStart(0);
     $query->queryObjects($criteria);
     $reviewrows = array();
     $i = 0;
     while ($v = $query->getObject()) {
         $reviewrows[$i]['reviewtitle'] = jieqi_htmlstr(str_replace(array("\r", "\n"), array('', ' '), $v->getVar('title', 'n')));
         $reviewrows[$i]['ownerid'] = $v->getVar('ownerid');
         $reviewrows[$i]['articlename'] = $v->getVar('articlename');
         $reviewrows[$i]['topicid'] = $v->getVar('topicid');
         $reviewrows[$i]['url_review'] = $article_dynamic_url . '/reviews.php?aid=' . $v->getVar('ownerid');
         $reviewrows[$i]['poster'] = $v->getVar('poster');
         $reviewrows[$i]['posterid'] = $v->getVar('posterid');
         $reviewrows[$i]['postdate'] = date('m-d H:i', $v->getVar('posttime'));
         $reviewrows[$i]['posttime'] = $v->getVar('posttime');
         $reviewrows[$i]['replytime'] = $v->getVar('replytime');
         $reviewrows[$i]['views'] = $v->getVar('views');
         $reviewrows[$i]['replies'] = $v->getVar('replies');
         $reviewrows[$i]['islock'] = $v->getVar('islock');
         $reviewrows[$i]['istop'] = $v->getVar('istop');
         $reviewrows[$i]['isgood'] = $v->getVar('isgood');
         $reviewrows[$i]['topictype'] = $v->getVar('topictype');
         $reviewrows[$i]['url_articleinfo'] = jieqi_geturl('article', 'article', $v->getVar('ownerid'), 'info');
         $reviewrows[$i]['url_articleindex'] = jieqi_geturl('article', 'article', $v->getVar('ownerid'), 'index');
         $reviewrows[$i]['url_articleread'] = $reviewrows[$i]['url_articleindex'];
         $i++;
     }
     $jieqiTpl->assign_by_ref('reviewrows', $reviewrows);
     $jieqiTpl->assign('url_more', $article_dynamic_url . '/reviewslist.php');
 }
示例#2
0
文件: package.php 项目: thu0ng91/jmc
 * @package    article
 * @copyright  Copyright (c) Hangzhou Jieqi Network Technology Co.,Ltd. (http://www.jieqi.com)
 * @author     $Author: juny $
 * @version    $Id: package.php 339 2009-06-23 03:03:24Z juny $
 */
//需要更新静态文章信息页面的打包类
include_once JIEQI_ROOT_PATH . '/lib/xml/xml.php';
jieqi_getconfigs('article', 'configs');
if (!isset($jieqiConfigs['article']['packdbattach'])) {
    $jieqiConfigs['article']['packdbattach'] = 0;
}
if (!$jieqiConfigs['article']['packdbattach'] && preg_match('/^(ftps?):\\/\\/([^:\\/]+):([^:\\/]*)@([0-9a-z\\-\\.]+)(:(\\d+))?([0-9a-z_\\-\\/\\.]*)/is', $jieqiConfigs['article']['attachdir'])) {
    $jieqiConfigs['article']['packdbattach'] = 1;
}
if ($jieqiConfigs['article']['packdbattach']) {
    jieqi_includedb();
    $package_query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
}
if (!empty($jieqiConfigs['article']['dynamicurl'])) {
    define('ARTICLE_DYNAMIC_URL', $jieqiConfigs['article']['dynamicurl']);
} else {
    define('ARTICLE_DYNAMIC_URL', $GLOBALS['jieqiModules']['article']['url']);
}
$article_dynamic_rooturl = ARTICLE_DYNAMIC_URL;
if (strpos($article_dynamic_rooturl, '/modules') > 0) {
    $article_dynamic_rooturl = substr($article_dynamic_rooturl, 0, strpos($article_dynamic_rooturl, '/modules'));
}
define('ARTICLE_DYNAMIC_ROOTURL', $article_dynamic_rooturl);
if (!empty($jieqiConfigs['article']['staticurl'])) {
    define('ARTICLE_STATIC_URL', $jieqiConfigs['article']['staticurl']);
} else {
示例#3
0
文件: funpost.php 项目: thu0ng91/jmc
/**
 * 帖子编辑后更新主题表
 * 
 * @param      array       $post_set 发帖信息设置
 * @param      string      $table 表名
 * @access     public
 * @return     bool
 */
function jieqi_topic_upedit(&$post_set, $table)
{
    global $query;
    if (!is_a($query, 'JieqiQueryHandler')) {
        jieqi_includedb();
        $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
    }
    $sql = "UPDATE " . $table . " SET title='" . jieqi_dbslashes($post_set['topictitle']) . "' WHERE topicid=" . intval($post_set['topicid']);
    return $query->execute($sql);
}
示例#4
0
function article_make_stoplist($sort, $fid = 1, $tid = 0, $static = true, $output = false)
{
    global $jieqiConfigs;
    global $query;
    if (!isset($jieqiConfigs['article'])) {
        jieqi_getconfigs('article', 'configs');
    }
    if (empty($tid) && JIEQI_MAX_PAGES > 0) {
        $tid = JIEQI_MAX_PAGES;
    }
    if (empty($tid)) {
        if (!is_a($query, 'JieqiQueryHandler')) {
            jieqi_includedb();
            $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
        }
        $sql = "SELECT count(*) AS cot FROM " . jieqi_dbprefix('article_article') . " WHERE display=0 AND size>0";
        $tmpvar = explode('-', date('Y-m-d', JIEQI_NOW_TIME));
        $daystart = mktime(0, 0, 0, (int) $tmpvar[1], (int) $tmpvar[2], (int) $tmpvar[0]);
        $monthstart = mktime(0, 0, 0, (int) $tmpvar[1], 1, (int) $tmpvar[0]);
        $tmpvar = date('w', JIEQI_NOW_TIME);
        if ($tmpvar == 0) {
            $tmpvar = 7;
        }
        //星期天是0,国人习惯作为作为一星期的最后一天
        $weekstart = $daystart;
        if ($tmpvar > 1) {
            $weekstart -= ($tmpvar - 1) * 86400;
        }
        switch ($sort) {
            case 'monthvisit':
            case 'mouthvisit':
                $sql .= " AND lastvisit >= " . $monthstart;
                break;
            case 'weekvisit':
                $sql .= " AND lastvisit >= " . $weekstart;
                break;
            case 'dayvisit':
                $sql .= " AND lastvisit >= " . $daystart;
                break;
            case 'allauthorvisit':
                $sql .= " AND authorid > 0";
                break;
            case 'monthauthorvisit':
            case 'mouthauthorvisit':
                $sql .= " AND authorid > 0 AND lastvisit >= " . $monthstart;
                break;
            case 'weekauthorvisit':
                $sql .= " AND authorid > 0 AND lastvisit >= " . $weekstart;
                break;
            case 'dayauthorvisit':
                $sql .= " AND authorid > 0 AND lastvisit >= " . $daystart;
                break;
            case 'monthvote':
            case 'mouthvote':
                $sql .= " AND lastvote >= " . $monthstart;
                break;
            case 'weekvote':
                $sql .= " AND lastvote >= " . $weekstart;
                break;
            case 'dayvote':
                $sql .= " AND lastvote >= " . $daystart;
                break;
            case 'authorupdate':
                $sql .= " AND authorid > 0";
                break;
            case 'masterupdate':
                $sql .= " AND authorid = 0";
                break;
        }
        $query->execute($sql);
        if ($row = $query->getRow()) {
            $cot = intval($row['cot']);
            $pnum = intval($jieqiConfigs['article']['toppagenum']);
            if (empty($pnum)) {
                $pnum = 10;
            }
            $tid = ceil($cot / $pnum);
        }
        if ($tid < 1) {
            $tid = 1;
        }
    }
    if ($fid > $tid) {
        return false;
    }
    for ($page = $fid; $page <= $tid; $page++) {
        article_make_ptoplist($sort, $page, $static, $output);
    }
}
示例#5
0
 function setContent($isreturn = false)
 {
     global $jieqiTpl;
     global $jieqiConfigs;
     jieqi_getconfigs('article', 'configs');
     jieqi_getconfigs('article', 'sort');
     $article_static_url = empty($jieqiConfigs['article']['staticurl']) ? $GLOBALS['jieqiModules']['article']['url'] : $jieqiConfigs['article']['staticurl'];
     $article_dynamic_url = empty($jieqiConfigs['article']['dynamicurl']) ? $GLOBALS['jieqiModules']['article']['url'] : $jieqiConfigs['article']['dynamicurl'];
     $jieqiTpl->assign('article_static_url', $article_static_url);
     $jieqiTpl->assign('article_dynamic_url', $article_dynamic_url);
     jieqi_includedb();
     $bookcase_query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
     $criteria = new CriteriaCompo();
     $criteria->add(new Criteria('c.userid', intval($this->blockvars['cacheid'])));
     if ($this->exevars['flag'] == 1) {
         $criteria->add(new Criteria('flag', 1));
     } elseif ($this->exevars['flag'] == 2) {
         $criteria->add(new Criteria('flag', 0));
     }
     $criteria->setTables(jieqi_dbprefix('article_bookcase') . ' c LEFT JOIN ' . jieqi_dbprefix('article_article') . ' a ON c.articleid=a.articleid');
     $criteria->setFields('c.*, a.articleid, a.lastupdate, a.articlename, a.authorid, a.author, a.sortid, a.typeid, a.lastchapterid, a.lastchapter');
     $tmpary = array('articleid' => 'a.articleid', 'lastupdate' => 'a.lastupdate', 'caseid' => 'c.caseid', 'joindate' => 'c.joindate', 'lastvisit' => 'c.lastvisit');
     $criteria->setSort($tmpary[$this->exevars['field']]);
     if ($this->exevars['asc'] == 1) {
         $criteria->setOrder('ASC');
     } else {
         $criteria->setOrder('DESC');
     }
     $criteria->setLimit($this->exevars['listnum']);
     $criteria->setStart(0);
     $bookcase_query->queryObjects($criteria);
     unset($criteria);
     $bookcaserows = array();
     $k = 0;
     while ($v = $bookcase_query->getObject()) {
         $bookcaserows[$k]['caseid'] = $v->getVar('caseid');
         $bookcaserows[$k]['articleid'] = $v->getVar('articleid');
         $bookcaserows[$k]['lastchapterid'] = $v->getVar('lastchapterid');
         $bookcaserows[$k]['chapterid'] = $v->getVar('chapterid');
         $bookcaserows[$k]['sortid'] = $v->getVar('sortid');
         $bookcaserows[$k]['typeid'] = $v->getVar('typeid');
         $bookcaserows[$k]['sort'] = $jieqiSort['article'][$v->getVar('sortid')]['shortname'];
         $bookcaserows[$k]['type'] = $bookcaserows[$k]['sort'];
         //$bookcaserows[$k]['type']=$jieqiSort['article'][$v->getVar('sortid')]['types'][$v->getVar('typeid')];
         $bookcaserows[$k]['authorid'] = $v->getVar('authorid');
         $bookcaserows[$k]['author'] = $v->getVar('author');
         $bookcaserows[$k]['checkbox'] = '<input type="checkbox" id="checkid[]" name="checkid[]" value="' . $v->getVar('caseid') . '">';
         $tmpvar = $v->getVar('articlename');
         if (!empty($tmpvar)) {
             $bookcaserows[$k]['url_articleinfo'] = $article_dynamic_url . '/readbookcase.php?aid=' . $v->getVar('articleid') . '&bid=' . $v->getVar('caseid');
             $bookcaserows[$k]['url_index'] = $bookcaserows[$k]['url_articleinfo'] . '&indexflag=1';
             $bookcaserows[$k]['articlename'] = $v->getVar('articlename');
         } else {
             $bookcaserows[$k]['url_articleinfo'] = '#';
             $bookcaserows[$k]['url_index'] = '#';
             $bookcaserows[$k]['articlename'] = $jieqiLang['article']['articlemark_has_deleted'];
         }
         if ($v->getVar('lastchapter') == '') {
             $bookcaserows[$k]['lastchapter'] = '';
             $bookcaserows[$k]['url_lastchapter'] = '#';
         } else {
             $bookcaserows[$k]['lastchapter'] = $v->getVar('lastchapter');
             $bookcaserows[$k]['url_lastchapter'] = $article_dynamic_url . '/readbookcase.php?aid=' . $v->getVar('articleid') . '&bid=' . $v->getVar('caseid') . '&cid=' . $v->getVar('lastchapterid');
         }
         if ($v->getVar('lastupdate') > $v->getVar('lastvisit')) {
             $bookcaserows[$k]['hasnew'] = 1;
         } else {
             $bookcaserows[$k]['hasnew'] = 0;
         }
         if ($v->getVar('chaptername') == '') {
             $bookcaserows[$k]['articlemark'] = '';
             $bookcaserows[$k]['url_articlemark'] = '#';
         } else {
             $bookcaserows[$k]['articlemark'] = $v->getVar('chaptername');
             $bookcaserows[$k]['url_articlemark'] = $article_dynamic_url . '/readbookcase.php?aid=' . $v->getVar('articleid') . '&bid=' . $v->getVar('caseid') . '&cid=' . $v->getVar('chapterid');
         }
         $bookcaserows[$k]['lastupdate'] = $v->getVar('lastupdate');
         $bookcaserows[$k]['url_delete'] = jieqi_addurlvars(array('delid' => $v->getVar('caseid')));
         $k++;
     }
     $jieqiTpl->assign_by_ref('bookcaserows', $bookcaserows);
     $jieqiTpl->assign('ownerid', $this->blockvars['cacheid']);
 }
示例#6
0
文件: funstat.php 项目: thu0ng91/jmc
/**
 * 通用的点击统计处理
 * 
 * 先判断是否重复的点击、然后检查是否缓存点击,然后更新点击数
 * 
 * @param      int         $id 点击对象ID
 * @param      string      $table 点击对象表名
 * @param      string      $fieldstat 点击数的字段名
 * @param      string      $fieldid ID的字段名
 * @param      object      $query 查询对象,不存在会自动创建
 * @param      int         $addnum 每次点击加几个点击数,默认1
 * @access     public
 * @return     bool
 */
function jieqi_visit_stat($id, $table, $fieldstat, $fieldid, $query = NULL, $addnum = 1)
{
    if (jieqi_visit_valid($id, $table . '_' . $fieldstat)) {
        if ($ids = jieqi_visit_ids($id, $table . '_' . $fieldstat)) {
            global $query;
            if (!is_a($query, 'JieqiQueryHandler')) {
                jieqi_includedb();
                $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
            }
            foreach ($ids as $k => $v) {
                $v['visitnum'] = intval($v['visitnum'] * $addnum);
                $sql = 'UPDATE ' . $table . ' SET ' . $fieldstat . '=' . $fieldstat . '+' . $v['visitnum'] . ' WHERE ' . $fieldid . '=' . intval($k);
                $query->execute($sql);
            }
        }
        return true;
    } else {
        return false;
    }
}
示例#7
0
/**
 * 本地用户注册,正式处理
 * 
 * @param      array       $params 参数数组
 * 必须参数: $params['username'] - 用户名,$params['password'] - 密码,$params['email'] - 邮箱
 * @access     public
 * @return     int    
 */
function jieqi_uregister_lprocess(&$params)
{
    global $jieqiConfigs;
    global $jieqiLang;
    global $query;
    global $users_handler;
    //载入参数设置
    if (!isset($jieqiConfigs['system'])) {
        jieqi_getconfigs('system', 'configs');
    }
    //载入语言包
    if (!isset($jieqiLang['system'])) {
        jieqi_loadlang('users', 'system');
    }
    //初始化查询类
    if (!is_a($query, 'JieqiQueryHandler')) {
        jieqi_includedb();
        $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
    }
    if (!is_a($users_handler, 'JieqiUsersHandler')) {
        include_once JIEQI_ROOT_PATH . '/class/users.php';
        $users_handler =& JieqiUsersHandler::getInstance('JieqiUsersHandler');
    }
    include_once JIEQI_ROOT_PATH . '/lib/text/textfunction.php';
    $newUser = $users_handler->create();
    $newUser->setVar('siteid', JIEQI_SITE_ID);
    $newUser->setVar('uname', $params['username']);
    $newUser->setVar('name', $params['nickname']);
    $newUser->setVar('pass', $users_handler->encryptPass($params['password']));
    $newUser->setVar('groupid', JIEQI_GROUP_USER);
    $newUser->setVar('regdate', JIEQI_NOW_TIME);
    $newUser->setVar('initial', jieqi_getinitial($params['username']));
    $newUser->setVar('sex', $params['sex']);
    $newUser->setVar('email', $params['email']);
    $newUser->setVar('url', $params['url']);
    $newUser->setVar('avatar', 0);
    $newUser->setVar('workid', 0);
    $newUser->setVar('qq', $params['qq']);
    $newUser->setVar('icq', '');
    $newUser->setVar('msn', $params['msn']);
    $newUser->setVar('mobile', '');
    $newUser->setVar('sign', '');
    $newUser->setVar('intro', '');
    $newUser->setVar('setting', '');
    $newUser->setVar('badges', '');
    $newUser->setVar('lastlogin', JIEQI_NOW_TIME);
    $newUser->setVar('showsign', 0);
    $newUser->setVar('viewemail', $params['viewemail']);
    $newUser->setVar('notifymode', 0);
    $newUser->setVar('adminemail', $params['adminemail']);
    $newUser->setVar('monthscore', 0);
    $newUser->setVar('experience', $jieqiConfigs['system']['scoreregister']);
    $newUser->setVar('score', $jieqiConfigs['system']['scoreregister']);
    $newUser->setVar('egold', 0);
    $newUser->setVar('esilver', 0);
    $newUser->setVar('credit', 0);
    $newUser->setVar('goodnum', 0);
    $newUser->setVar('badnum', 0);
    $newUser->setVar('isvip', 0);
    $newUser->setVar('overtime', 0);
    $newUser->setVar('state', 0);
    if (!$users_handler->insert($newUser)) {
        $params['uid'] = $newUser->getVar('uid', 'n');
        $params['error'] = $jieqiLang['system']['register_failure'];
        if ($params['return']) {
            return false;
        } else {
            jieqi_printfail($params['error']);
        }
    } else {
        //自动登录
        //记录注册时间IP
        if ($jieqiConfigs['system']['regtimelimit'] > 0) {
            $sql = "DELETE FROM " . jieqi_dbprefix('system_registerip') . " WHERE regtime<" . (JIEQI_NOW_TIME - ($jieqiConfigs['system']['regtimelimit'] > 72 ? $jieqiConfigs['system']['regtimelimit'] : 72) * 3600);
            $query->execute($sql);
            $sql = "INSERT INTO " . jieqi_dbprefix('system_registerip') . " (ip, regtime, count) VALUES ('" . jieqi_dbslashes($params['uip']) . "', '" . JIEQI_NOW_TIME . "', '0')";
            $query->execute($sql);
        }
        //更新在线用户表
        include_once JIEQI_ROOT_PATH . '/class/online.php';
        $online_handler =& JieqiOnlineHandler::getInstance('JieqiOnlineHandler');
        include_once JIEQI_ROOT_PATH . '/include/visitorinfo.php';
        $online = $online_handler->create();
        $online->setVar('uid', $newUser->getVar('uid', 'n'));
        $online->setVar('siteid', JIEQI_SITE_ID);
        $online->setVar('sid', session_id());
        $online->setVar('uname', $newUser->getVar('uname', 'n'));
        $tmpvar = strlen($newUser->getVar('name', 'n')) > 0 ? $newUser->getVar('name', 'n') : $newUser->getVar('uname', 'n');
        $online->setVar('name', $tmpvar);
        $online->setVar('pass', $newUser->getVar('pass', 'n'));
        $online->setVar('email', $newUser->getVar('email', 'n'));
        $online->setVar('groupid', $newUser->getVar('groupid', 'n'));
        $tmpvar = JIEQI_NOW_TIME;
        $online->setVar('logintime', $tmpvar);
        $online->setVar('updatetime', $tmpvar);
        $online->setVar('operate', '');
        $tmpvar = VisitorInfo::getIp();
        $online->setVar('ip', $tmpvar);
        $online->setVar('browser', VisitorInfo::getBrowser());
        $online->setVar('os', VisitorInfo::getOS());
        $location = VisitorInfo::getIpLocation($tmpvar);
        if (JIEQI_SYSTEM_CHARSET == 'big5') {
            include_once JIEQI_ROOT_PATH . '/include/changecode.php';
            $location = jieqi_gb2big5($location);
        }
        $online->setVar('location', $location);
        $online->setVar('state', '0');
        $online->setVar('flag', '0');
        $online_handler->insert($online);
        //设置SESSION
        jieqi_setusersession($newUser);
        //设置COOKIE
        $jieqi_user_info = array();
        $jieqi_user_info['jieqiUserId'] = $_SESSION['jieqiUserId'];
        $jieqi_user_info['jieqiUserName'] = $_SESSION['jieqiUserName'];
        $jieqi_user_info['jieqiUserGroup'] = $_SESSION['jieqiUserGroup'];
        include_once JIEQI_ROOT_PATH . '/include/changecode.php';
        if (JIEQI_SYSTEM_CHARSET == 'gbk') {
            $jieqi_user_info['jieqiUserName_un'] = jieqi_gb2unicode($_SESSION['jieqiUserName']);
        } else {
            $jieqi_user_info['jieqiUserName_un'] = jieqi_big52unicode($_SESSION['jieqiUserName']);
        }
        $jieqi_user_info['jieqiUserLogin'] = JIEQI_NOW_TIME;
        $cookietime = 0;
        @setcookie('jieqiUserInfo', jieqi_sarytostr($jieqi_user_info), $cookietime, '/', JIEQI_COOKIE_DOMAIN, 0);
        $jieqi_visit_info['jieqiUserLogin'] = $jieqi_user_info['jieqiUserLogin'];
        $jieqi_visit_info['jieqiUserId'] = $jieqi_user_info['jieqiUserId'];
        @setcookie('jieqiVisitInfo', jieqi_sarytostr($jieqi_visit_info), JIEQI_NOW_TIME + 99999999, '/', JIEQI_COOKIE_DOMAIN, 0);
        //推广积分
        if (JIEQI_PROMOTION_REGISTER > 0 && !empty($_COOKIE['jieqiPromotion'])) {
            $users_handler->changeCredit(intval($_COOKIE['jieqiPromotion']), intval(JIEQI_PROMOTION_REGISTER), true);
            setcookie('jieqiPromotion', '', 0, '/', JIEQI_COOKIE_DOMAIN, 0);
        }
    }
    //$params['jumpurl']=JIEQI_URL.'/';
    if (empty($params['jumpurl'])) {
        $params['jumpurl'] = JIEQI_URL . '/';
    }
    return true;
}
示例#8
0
文件: funtag.php 项目: thu0ng91/jmc
/**
 * 删除标签关联信息
 * 
 * @param      array      $tags 标签数组
 * @param      int        $articleid 关联ID
 * @param      array      $tables 标签相关数据表 array('tag'=>'', 'taglink'=>'', 'tagcache'=>'')
 * @access     public
 * @return     bool
 */
function jieqi_tag_delete($tags, $articleid, $tables)
{
    global $query;
    if (!is_a($query, 'JieqiQueryHandler')) {
        jieqi_includedb();
        $query = JieqiQueryHandler::getInstance('JieqiQueryHandler');
    }
    $articleid = intval($articleid);
    foreach ($tags as $tag) {
        $sql = "SELECT * FROM " . $tables['tag'] . " WHERE tagname = '" . jieqi_dbslashes($tag) . "' LIMIT 0,1";
        $query->execute($sql);
        if ($row = $query->getRow()) {
            $tagid = intval($row['tagid']);
            $sql = "DELETE FROM " . $tables['taglink'] . " WHERE tagid = " . $tagid . " AND articleid = " . $articleid;
            $query->execute($sql);
            if ($query->db->getAffectedRows() > 0) {
                $uptag = true;
                //最后一条关联记录
                if ($row['linknum'] <= 1) {
                    $sql = "SELECT count(*) as cot FROM " . $tables['taglink'] . " WHERE tagid = " . $tagid;
                    $query->execute($sql);
                    if ($row1 = $query->getRow()) {
                        if ($row1['cot'] == 0) {
                            $uptag = false;
                            $sql = "DELETE FROM " . $tables['tag'] . " WHERE tagid = " . $tagid;
                            $query->execute($sql);
                            $sql = "DELETE FROM " . $tables['tagcache'] . " WHERE tagid = " . $tagid;
                            $query->execute($sql);
                        }
                    }
                }
                if (!$uptag) {
                    $sql = "UPDATE " . $tables['tag'] . " SET linknum = linknum - 1 WHERE tagid = " . $tagid;
                    $query->execute($sql);
                    $sql = "SELECT * FROM " . $tables['tagcache'] . " WHERE tagid = " . $tagid . " LIMIT 0,1";
                    $query->execute($sql);
                    if ($row2 = $query->getRow()) {
                        $lids = explode(',', $row2['linkids']);
                        if (!in_array($articleid, $lids)) {
                            $lids[] = $articleid;
                            $sql = "UPDATE " . $tables['tagcache'] . " SET linkids = '" . jieqi_dbslashes(implode(',', $lids)) . "' WHERE tagid = " . $tagid;
                            $query->execute($sql);
                        }
                    }
                }
            }
        }
    }
    return true;
}