Exemplo n.º 1
0
 function do_manage()
 {
     $sql = " where 1=1";
     $cid = (int) $_GET['cid'];
     $tcid = (int) $_GET['tcid'];
     $pid = (int) $_GET['pid'];
     $rootid = (int) $_GET['rootid'];
     $_GET['keywords'] && ($sql .= " AND CONCAT(name,seotitle,subtitle,keywords,description) REGEXP '{$_GET['keywords']}'");
     $sql .= $this->categoryApp->search_sql($cid);
     $sql .= $this->tagcategory->search_sql($tcid, 'tcid');
     $_GET['starttime'] && ($sql .= " AND `pubdate`>='" . iPHP::str2time($_GET['starttime'] . " 00:00:00") . "'");
     $_GET['endtime'] && ($sql .= " AND `pubdate`<='" . iPHP::str2time($_GET['endtime'] . " 23:59:59") . "'");
     $_GET['post_starttime'] && ($sql .= " AND `postime`>='" . iPHP::str2time($_GET['post_starttime'] . " 00:00:00") . "'");
     $_GET['post_endtime'] && ($sql .= " AND `postime`<='" . iPHP::str2time($_GET['post_endtime'] . " 23:59:59") . "'");
     isset($_GET['pic']) && ($sql .= " AND `haspic` ='" . ($_GET['pic'] ? 1 : 0) . "'");
     if (isset($_GET['pid']) && $pid != '-1') {
         $uri_array['pid'] = $pid;
         if ($_GET['pid'] == 0) {
             $sql .= " AND `pid`=''";
         } else {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('prop', $this->appid);
             $map_where = map::where($pid);
         }
     }
     if ($map_where) {
         $map_sql = iCMS::map_sql($map_where);
         $sql = ",({$map_sql}) map {$sql} AND `id` = map.`iid`";
     }
     $orderby = $_GET['orderby'] ? $_GET['orderby'] : "id DESC";
     $maxperpage = $_GET['perpage'] > 0 ? (int) $_GET['perpage'] : 20;
     $total = iPHP::total(false, "SELECT count(*) FROM `#iCMS@__tags` {$sql}", "G");
     iPHP::pagenav($total, $maxperpage, "个标签");
     $limit = 'LIMIT ' . iPHP::$offset . ',' . $maxperpage;
     if ($map_sql || iPHP::$offset) {
         $ids_array = iDB::all("\n                SELECT `id` FROM `#iCMS@__tags` {$sql}\n                ORDER BY {$orderby} {$limit}\n            ");
         //iDB::debug(1);
         $ids = iCMS::get_ids($ids_array);
         $ids = $ids ? $ids : '0';
         $sql = "WHERE `id` IN({$ids})";
         $limit = '';
     }
     $rs = iDB::all("SELECT * FROM `#iCMS@__tags` {$sql} ORDER BY {$orderby} {$limit}");
     $_count = count($rs);
     include iACP::view("tags.manage");
 }
Exemplo n.º 2
0
 function do_iCMS()
 {
     //iPHP::app('user.class','static');
     $sql = "WHERE 1=1";
     $pid = $_GET['pid'];
     if ($_GET['keywords']) {
         $sql .= " AND CONCAT(username,nickname) REGEXP '{$_GET['keywords']}'";
     }
     $_GET['gid'] && ($sql .= " AND `gid`='{$_GET['gid']}'");
     if (isset($_GET['status']) && $_GET['status'] !== '') {
         $sql .= " AND `status`='{$_GET['status']}'";
     }
     $_GET['regip'] && ($sql .= " AND `regip`='{$_GET['regip']}'");
     $_GET['loginip'] && ($sql .= " AND `lastloginip`='{$_GET['loginip']}'");
     if (isset($_GET['pid']) && $pid != '-1') {
         $uri_array['pid'] = $pid;
         if ($_GET['pid'] == 0) {
             $sql .= " AND `pid`=''";
         } else {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('prop', $this->appid);
             $map_where = map::where($pid);
         }
     }
     if ($map_where) {
         $map_sql = iCMS::map_sql($map_where);
         $sql = ",({$map_sql}) map {$sql} AND `uid` = map.`iid`";
     }
     $orderby = $_GET['orderby'] ? $_GET['orderby'] : "uid DESC";
     $maxperpage = $_GET['perpage'] > 0 ? (int) $_GET['perpage'] : 20;
     $total = iPHP::total(false, "SELECT count(*) FROM `#iCMS@__user` {$sql}", "G");
     iPHP::pagenav($total, $maxperpage, "个用户");
     $limit = 'LIMIT ' . iPHP::$offset . ',' . $maxperpage;
     if ($map_sql || iPHP::$offset) {
         $ids_array = iDB::all("\n                SELECT `uid` FROM `#iCMS@__user` {$sql}\n                ORDER BY {$orderby} {$limit}\n            ");
         //iDB::debug(1);
         $ids = iCMS::get_ids($ids_array, 'uid');
         $ids = $ids ? $ids : '0';
         $sql = "WHERE `uid` IN({$ids})";
         $limit = '';
     }
     $rs = iDB::all("SELECT * FROM `#iCMS@__user` {$sql} ORDER BY {$orderby} {$limit}");
     $_count = count($rs);
     include iACP::view("user.manage");
 }
Exemplo n.º 3
0
function article_list($vars)
{
    if ($vars['loop'] === "rel" && empty($vars['id'])) {
        return false;
    }
    $resource = array();
    $map_where = array();
    $status = '1';
    isset($vars['status']) && ($status = (int) $vars['status']);
    $where_sql = "WHERE `status`='{$status}'";
    $vars['call'] == 'user' && ($where_sql .= " AND `postype`='0'");
    $vars['call'] == 'admin' && ($where_sql .= " AND `postype`='1'");
    $hidden = iCache::get('iCMS/category/hidden');
    $hidden && ($where_sql .= iPHP::where($hidden, 'cid', 'not'));
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : 10;
    $cache_time = isset($vars['time']) ? (int) $vars['time'] : -1;
    isset($vars['userid']) && ($where_sql .= " AND `userid`='{$vars['userid']}'");
    isset($vars['weight']) && ($where_sql .= " AND `weight`='" . _int($vars['weight']) . "'");
    if (isset($vars['ucid']) && $vars['ucid'] != '') {
        $where_sql .= " AND `ucid`='{$vars['ucid']}'";
    }
    if (isset($vars['cid!'])) {
        $ncids = explode(',', $vars['cid!']);
        $vars['sub'] && ($ncids += iCMS::get_category_ids($ncids, true));
        $where_sql .= iPHP::where($ncids, 'cid', 'not');
    }
    if ($vars['cid'] && !isset($vars['cids'])) {
        $cid = explode(',', $vars['cid']);
        $vars['sub'] && ($cid += iCMS::get_category_ids($cid, true));
        $where_sql .= iPHP::where($cid, 'cid');
    }
    if (isset($vars['cids']) && !$vars['cid']) {
        $cids = explode(',', $vars['cids']);
        $vars['sub'] && ($cids += iCMS::get_category_ids($vars['cids'], true));
        if ($cids) {
            iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
            map::init('category', iCMS_APP_ARTICLE);
            $map_where += map::where($cids);
        }
    }
    if (isset($vars['pid']) && !isset($vars['pids'])) {
        $where_sql .= iPHP::where($vars['pid'], 'pid');
    }
    if (isset($vars['pids']) && !isset($vars['pid'])) {
        iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
        map::init('prop', iCMS_APP_ARTICLE);
        $map_where += map::where($vars['pids']);
    }
    if (isset($vars['tids'])) {
        iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
        map::init('tags', iCMS_APP_ARTICLE);
        $map_where += map::where($vars['tids']);
    }
    if (isset($vars['keywords'])) {
        //最好使用 iCMS:article:search
        if (empty($vars['keywords'])) {
            return;
        }
        if (strpos($vars['keywords'], ',') === false) {
            $vars['keywords'] = str_replace(array('%', '_'), array('\\%', '\\_'), $vars['keywords']);
            $where_sql .= " AND CONCAT(title,keywords,description) like '%" . addslashes($vars['keywords']) . "%'";
        } else {
            $kws = explode(',', $vars['keywords']);
            foreach ($kws as $kwv) {
                $keywords .= addslashes($kwv) . "|";
            }
            $keywords = substr($keywords, 0, -1);
            $where_sql .= " AND CONCAT(title,keywords,description) REGEXP '{$keywords}' ";
        }
    }
    $vars['id'] && ($where_sql .= iPHP::where($vars['id'], 'id'));
    $vars['id!'] && ($where_sql .= iPHP::where($vars['id!'], 'id', 'not'));
    $by = $vars['by'] == "ASC" ? "ASC" : "DESC";
    isset($vars['pic']) && ($where_sql .= " AND `haspic`='1'");
    isset($vars['nopic']) && ($where_sql .= " AND `haspic`='0'");
    switch ($vars['orderby']) {
        case "id":
            $order_sql = " ORDER BY `id` {$by}";
            break;
        case "hot":
            $order_sql = " ORDER BY `hits` {$by}";
            break;
        case "week":
            $order_sql = " ORDER BY `hits_week` {$by}";
            break;
        case "month":
            $order_sql = " ORDER BY `hits_month` {$by}";
            break;
        case "comment":
            $order_sql = " ORDER BY `comments` {$by}";
            break;
        case "pubdate":
            $order_sql = " ORDER BY `pubdate` {$by}";
            break;
        case "disorder":
            $order_sql = " ORDER BY `ordernum` {$by}";
            break;
        case "rand":
            $order_sql = " ORDER BY rand() {$by}";
            break;
        case "weight":
            $order_sql = " ORDER BY `weight`,`ordernum` ASC";
            break;
        default:
            $order_sql = " ORDER BY `id` {$by}";
    }
    isset($vars['startdate']) && ($where_sql .= " AND `pubdate`>='" . strtotime($vars['startdate']) . "'");
    isset($vars['enddate']) && ($where_sql .= " AND `pubdate`<='" . strtotime($vars['enddate']) . "'");
    isset($vars['where']) && ($where_sql .= $vars['where']);
    if ($map_where) {
        $map_sql = iCMS::map_sql($map_where, 'join');
        //join
        //empty($vars['cid']) && $map_order_sql = " ORDER BY map.`iid` $by";
        $map_table = 'map';
        $vars['map_order_table'] && ($map_table = $vars['map_order_table']);
        $map_order_sql = " ORDER BY {$map_table}.`iid` {$by}";
        //$map_order_sql = " ORDER BY `icms_article`.`id` $by";
        //
        $where_sql .= ' AND ' . $map_sql['where'];
        $where_sql = ",{$map_sql['from']} {$where_sql} AND `#iCMS@__article`.`id` = {$map_table}.`iid`";
        //derived
        // $where_sql = ",({$map_sql}) map {$where_sql} AND `id` = map.`iid`";
    }
    $offset = 0;
    $limit = "LIMIT {$maxperpage}";
    if ($vars['page']) {
        $total_type = $vars['total_cache'] ? $vars['total_cache'] : null;
        $total = iPHP::total('sql.md5', "SELECT count(*) FROM `#iCMS@__article` {$where_sql}", $total_type);
        $pagenav = isset($vars['pagenav']) ? $vars['pagenav'] : "pagenav";
        $pnstyle = isset($vars['pnstyle']) ? $vars['pnstyle'] : 0;
        $multi = iCMS::page(array('total_type' => $total_type, 'total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:list'), 'nowindex' => $GLOBALS['page']));
        $offset = $multi->offset;
        $limit = "LIMIT {$offset},{$maxperpage}";
        iPHP::assign("article_list_total", $total);
    }
    $hash = md5($where_sql . $order_sql . $limit);
    if ($offset) {
        if ($vars['cache']) {
            $map_cache_name = iPHP_DEVICE . '/article_page/' . $hash;
            $ids_array = iCache::get($map_cache_name);
        }
        if (empty($ids_array)) {
            $ids_order_sql = $map_order_sql ? $map_order_sql : $order_sql;
            $ids_array = iDB::all("SELECT `#iCMS@__article`.`id` FROM `#iCMS@__article` {$where_sql} {$ids_order_sql} {$limit}");
            iPHP_SQL_DEBUG && iDB::debug(1);
            $vars['cache'] && iCache::set($map_cache_name, $ids_array, $cache_time);
        }
        $ids = iCMS::get_ids($ids_array);
        $ids = $ids ? $ids : '0';
        $where_sql = "WHERE `id` IN({$ids})";
        $limit = '';
    } else {
        if ($map_order_sql) {
            $order_sql = $map_order_sql;
        }
    }
    if ($vars['cache']) {
        $cache_name = iPHP_DEVICE . '/article/' . $hash;
        $resource = iCache::get($cache_name);
    }
    // $func = '__article_array';
    // if($vars['func']=="user_home"){ //暂时只有一个选项
    //     $func = '__article_user_home_array';
    // }
    if (empty($resource)) {
        $resource = iDB::all("SELECT `#iCMS@__article`.* FROM `#iCMS@__article` {$where_sql} {$order_sql} {$limit}");
        iPHP_SQL_DEBUG && iDB::debug(1);
        $resource = __article_array($vars, $resource);
        $vars['cache'] && iCache::set($cache_name, $resource, $cache_time);
    }
    //print_r($resource);
    return $resource;
}
Exemplo n.º 4
0
function user_list($vars = null)
{
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : "100";
    $cache_time = isset($vars['time']) ? (int) $vars['time'] : "-1";
    $where_sql = "WHERE `status`='1'";
    isset($vars['userid']) && ($where_sql .= " AND `uid`='{$vars['userid']}'");
    isset($vars['gid']) && ($where_sql .= " AND `gid` ='{$vars['gid']}'");
    isset($vars['type']) && ($where_sql .= " AND `type` ='{$vars['type']}'");
    if (isset($vars['pid']) && !isset($vars['pids'])) {
        $where_sql .= iPHP::where($vars['pid'], 'pid');
    }
    if (isset($vars['pids']) && !isset($vars['pid'])) {
        iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
        map::init('prop', iCMS_APP_USER);
        //$where_sql.= map::exists($vars['pid'],'`#iCMS@__user`.uid'); //map 表大的用exists
        $map_where = map::where($vars['pids']);
    }
    $by = $vars['by'] == "ASC" ? "ASC" : "DESC";
    switch ($vars['orderby']) {
        case "id":
            $order_sql = " ORDER BY `uid` {$by}";
            break;
        case "article":
            $order_sql = " ORDER BY `article` {$by}";
            break;
        case "comments":
            $order_sql = " ORDER BY `comments` {$by}";
            break;
        case "follow":
            $order_sql = " ORDER BY `follow` {$by}";
            break;
        case "fans":
            $order_sql = " ORDER BY `fans` {$by}";
            break;
        case "hits":
            $order_sql = " ORDER BY `hits` {$by}";
            break;
        default:
            $order_sql = " ORDER BY `uid` {$by}";
    }
    if ($map_where) {
        $map_sql = iCMS::map_sql($map_where);
        $where_sql = ",({$map_sql}) map {$where_sql} AND `uid` = map.`iid`";
    }
    $offset = 0;
    $limit = "LIMIT {$maxperpage}";
    if ($vars['page']) {
        $total = iPHP::total('sql.md5', "SELECT count(*) FROM `#iCMS@__user` {$where_sql} ");
        $multi = iCMS::page(array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:sql'), 'nowindex' => $GLOBALS['page']));
        $offset = $multi->offset;
        $limit = "LIMIT {$offset},{$maxperpage}";
        iPHP::assign("user_list_total", $total);
    }
    $hash = md5($where_sql . $order_sql . $limit);
    if ($map_sql || $offset) {
        if ($vars['cache']) {
            $map_cache_name = iPHP_DEVICE . '/user_map/' . $hash;
            $ids_array = iCache::get($map_cache_name);
        }
        if (empty($ids_array)) {
            $ids_array = iDB::all("SELECT `id` FROM `#iCMS@__user` {$where_sql} {$order_sql} {$limit}");
            iPHP_SQL_DEBUG && iDB::debug(1);
            $vars['cache'] && iCache::set($map_cache_name, $ids_array, $cache_time);
        }
        //iDB::debug(1);
        $ids = iCMS::get_ids($ids_array, 'uid');
        $ids = $ids ? $ids : '0';
        $where_sql = "WHERE `uid` IN({$ids})";
    }
    if ($vars['cache']) {
        $cache_name = iPHP_DEVICE . '/user_list/' . $hash;
        $resource = iCache::get($cache_name);
    }
    if (empty($resource)) {
        $resource = iDB::all("SELECT * FROM `#iCMS@__user` {$where_sql} {$order_sql} {$limit}");
        iPHP_SQL_DEBUG && iDB::debug(1);
        if ($resource) {
            foreach ($resource as $key => $value) {
                $value['url'] = user::router($value['uid'], "url");
                $value['urls'] = user::router($value['uid'], "urls");
                $value['avatar'] = user::router($value['uid'], "avatar", $vars['size'] ? $vars['size'] : 0);
                $value['at'] = '<a href="' . $value['url'] . '" class="iCMS_user_link" target="_blank" data-tip="iCMS:ucard:' . $value['uid'] . '">@' . $value['nickname'] . '</a>';
                $value['link'] = '<a href="' . $value['url'] . '" class="iCMS_user_link" target="_blank" data-tip="iCMS:ucard:' . $value['uid'] . '">' . $value['nickname'] . '</a>';
                $value['gender'] = $value['gender'] ? 'male' : 'female';
                isset($vars['data']) && ($value['data'] = (array) user::data($value['uid']));
                $resource[$key] = $value;
            }
        }
        $vars['cache'] && iCache::set($cache_name, $resource, $cache_time);
    }
    return $resource;
}
Exemplo n.º 5
0
/**
 * @package iCMS
 * @copyright 2007-2016, iDreamSoft
 * @license http://www.idreamsoft.com iDreamSoft
 * @author coolmoo <*****@*****.**>
 * @$Id: tag.tpl.php 159 2013-03-23 04:11:53Z coolmoo $
 */
function tag_list($vars)
{
    $where_sql = "WHERE status='1' ";
    $map_where = array();
    if (isset($vars['rootid'])) {
        $where_sql .= " AND `rootid`='" . (int) $vars['rootid'] . "'";
    }
    if (!isset($vars['tcids']) && isset($vars['tcid'])) {
        $where_sql .= iPHP::where($vars['tcid'], 'tcid');
    }
    if (isset($vars['tcids']) && !isset($vars['tcid'])) {
        iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
        map::init('category', iCMS_APP_TAG);
        //$where_sql.= map::exists($vars['tcid'],'`#iCMS@__tags`.id'); //map 表大的用exists
        $map_where += map::where($vars['tcid']);
    }
    if (isset($vars['tcid!'])) {
        $where_sql .= iPHP::where($vars['tcid!'], 'tcid', 'not');
    }
    if (!isset($vars['pids']) && isset($vars['pid'])) {
        $where_sql .= iPHP::where($vars['pid'], 'pid');
    }
    if (isset($vars['pids']) && !isset($vars['pid'])) {
        iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
        map::init('prop', iCMS_APP_TAG);
        //$where_sql.= map::exists($vars['pids'],'`#iCMS@__tags`.id'); //map 表大的用exists
        $map_where += map::where($vars['pids']);
    }
    if (isset($vars['pid!'])) {
        $where_sql .= iPHP::where($vars['pid!'], 'pid', 'not');
    }
    if (!isset($vars['cids']) && isset($vars['cid'])) {
        $cid = explode(',', $vars['cid']);
        $vars['sub'] && ($cid += iCMS::get_category_ids($cid, true));
        $where_sql .= iPHP::where($cid, 'cid');
    }
    if (isset($vars['cids']) && !isset($vars['cid'])) {
        $cids = explode(',', $vars['cids']);
        $vars['sub'] && ($cids += iCMS::get_category_ids($vars['cids'], true));
        if ($cids) {
            iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
            map::init('category', iCMS_APP_TAG);
            $map_where += map::where($cids);
        }
    }
    if (isset($vars['cid!'])) {
        $ncids = explode(',', $vars['cid!']);
        $vars['sub'] && ($ncids += iCMS::get_category_ids($ncids, true));
        $where_sql .= iPHP::where($ncids, 'cid', 'not');
    }
    if (isset($vars['keywords'])) {
        //最好使用 iCMS:tag:search
        if (empty($vars['keywords'])) {
            return;
        }
        if (strpos($vars['keywords'], ',') === false) {
            $vars['keywords'] = str_replace(array('%', '_'), array('\\%', '\\_'), $vars['keywords']);
            $where_sql .= " AND CONCAT(tkey,name,seotitle,keywords) like '%" . addslashes($vars['keywords']) . "%'";
        } else {
            $kws = explode(',', $vars['keywords']);
            foreach ($kws as $kwv) {
                $keywords .= addslashes($kwv) . "|";
            }
            $keywords = substr($keywords, 0, -1);
            $where_sql .= " AND CONCAT(tkey,name,seotitle,keywords) REGEXP '{$keywords}' ";
        }
    }
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : "10";
    $cache_time = isset($vars['time']) ? (int) $vars['time'] : -1;
    $by = $vars['by'] == 'ASC' ? "ASC" : "DESC";
    switch ($vars['orderby']) {
        case "hot":
            $order_sql = " ORDER BY `count` {$by}";
            break;
        case "new":
            $order_sql = " ORDER BY `id` {$by}";
            break;
        case "order":
            $order_sql = " ORDER BY `ordernum` {$by}";
            break;
            //		case "rand":	$order_sql=" ORDER BY rand() $by";		break;
        //		case "rand":	$order_sql=" ORDER BY rand() $by";		break;
        default:
            $order_sql = " ORDER BY `id` {$by}";
    }
    if ($map_where) {
        $map_sql = iCMS::map_sql($map_where);
        $where_sql = ",({$map_sql}) map {$where_sql} AND `id` = map.`iid`";
    }
    $offset = 0;
    $limit = "LIMIT {$maxperpage}";
    if ($vars['page']) {
        $total = iPHP::total('sql.md5', "SELECT count(*) FROM `#iCMS@__tags` {$where_sql} ");
        iPHP::assign("tags_total", $total);
        $multi = iCMS::page(array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:list'), 'nowindex' => $GLOBALS['page']));
        $offset = $multi->offset;
        $limit = "LIMIT {$offset},{$maxperpage}";
        iPHP::assign("tags_list_total", $total);
    }
    if ($vars['orderby'] == 'rand') {
        $ids_array = iCMS::get_rand_ids('#iCMS@__tags', $where_sql, $maxperpage, 'id');
    }
    $hash = md5($where_sql . $order_sql . $limit);
    if ($vars['cache']) {
        $cache_name = iPHP_DEVICE . '/tags/' . $md5 . "/" . (int) $GLOBALS['page'];
        $resource = iCache::get($cache_name);
    }
    if ($map_sql || $offset) {
        if ($vars['cache']) {
            $map_cache_name = iPHP_DEVICE . '/tags_map/' . $hash;
            $ids_array = iCache::get($map_cache_name);
        }
        if (empty($ids_array)) {
            $ids_array = iDB::all("SELECT `id` FROM `#iCMS@__tags` {$where_sql} {$order_sql} {$limit}");
            iPHP_SQL_DEBUG && iDB::debug(1);
            $vars['cache'] && iCache::set($map_cache_name, $ids_array, $cache_time);
        }
        //iDB::debug(1);
    }
    if ($ids_array) {
        $ids = iCMS::get_ids($ids_array);
        $ids = $ids ? $ids : '0';
        $where_sql = "WHERE `#iCMS@__tags`.`id` IN({$ids})";
        $limit = '';
    }
    if ($vars['cache']) {
        $cache_name = iPHP_DEVICE . '/tags/' . $hash;
        $resource = iCache::get($cache_name);
    }
    if (empty($resource)) {
        $resource = iDB::all("SELECT * FROM `#iCMS@__tags` {$where_sql} {$order_sql} {$limit}");
        iPHP_SQL_DEBUG && iDB::debug(1);
        $resource = __tag_array($vars, $resource);
        $vars['cache'] && iCache::set($cache_name, $resource, $cache_time);
    }
    return $resource;
}
Exemplo n.º 6
0
 function do_manage($stype = 'normal')
 {
     $cid = (int) $_GET['cid'];
     $pid = $_GET['pid'];
     //$stype OR $stype = iACP::$app_do;
     $stype_map = array('inbox' => '0', 'normal' => '1', 'trash' => '2', 'examine' => '3', 'off' => '4');
     $map_where = array();
     //status:[0:草稿][1:正常][2:回收][3:待审核][4:不合格]
     //postype: [0:用户][1:管理员]
     $stype && ($this->_status = $stype_map[$stype]);
     if (isset($_GET['pt']) && $_GET['pt'] != '') {
         $this->_postype = (int) $_GET['pt'];
     }
     $sql = "WHERE `status`='{$this->_status}'";
     $this->_postype === 'all' or $sql .= " AND `postype`='{$this->_postype}'";
     if (iACP::MP("ARTICLE.VIEW")) {
         $_GET['userid'] && ($sql .= iPHP::where($_GET['userid'], 'userid'));
     } else {
         $sql .= iPHP::where(iMember::$userid, 'userid');
     }
     if (isset($_GET['pid']) && $pid != '-1') {
         $uri_array['pid'] = $pid;
         if (empty($_GET['pid'])) {
             $sql .= " AND `pid`=''";
         } else {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('prop', $this->appid);
             $map_where += map::where($pid);
         }
     }
     $cp_cids = iACP::CP('__CID__', 'cs');
     //取得所有有权限的栏目ID
     if ($cp_cids) {
         if (is_array($cp_cids)) {
             if ($cid) {
                 array_search($cid, $cp_cids) === false && iACP::permission_msg('栏目[cid:' . $cid . ']', $ret);
             } else {
                 $cids = $cp_cids;
             }
         } else {
             $cids = $cid;
         }
         if ($_GET['sub'] && $cid) {
             $cids = $this->categoryApp->get_ids($cid, true);
             array_push($cids, $cid);
         }
         if ($_GET['scid'] && $cid) {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('category', $this->appid);
             $map_where += map::where($cids);
         } else {
             $sql .= iPHP::where($cids, 'cid');
         }
     } else {
         $sql .= iPHP::where('-1', 'cid');
     }
     if ($_GET['keywords']) {
         $kws = $_GET['keywords'];
         switch ($_GET['st']) {
             case "title":
                 $sql .= " AND `title` REGEXP '{$kws}'";
                 break;
             case "tag":
                 $sql .= " AND `tags` REGEXP '{$kws}'";
                 break;
             case "source":
                 $sql .= " AND `source` REGEXP '{$kws}'";
                 break;
             case "weight":
                 $sql .= " AND `weight`='{$kws}'";
                 break;
             case "id":
                 $sql .= " AND `id` REGEXP '{$kws}'";
                 break;
             case "tkd":
                 $sql .= " AND CONCAT(title,keywords,description) REGEXP '{$kws}'";
                 break;
         }
     }
     $_GET['title'] && ($sql .= " AND `title` like '%{$_GET['title']}%'");
     $_GET['tag'] && ($sql .= " AND `tags` REGEXP '[[:<:]]" . preg_quote(rawurldecode($_GET['tag']), '/') . "[[:>:]]'");
     $_GET['starttime'] && ($sql .= " AND `pubdate`>='" . iPHP::str2time($_GET['starttime'] . " 00:00:00") . "'");
     $_GET['endtime'] && ($sql .= " AND `pubdate`<='" . iPHP::str2time($_GET['endtime'] . " 23:59:59") . "'");
     isset($_GET['pic']) && ($sql .= " AND `haspic` ='" . ($_GET['pic'] ? 1 : 0) . "'");
     isset($_GET['userid']) && ($uri_array['userid'] = (int) $_GET['userid']);
     isset($_GET['keyword']) && ($uri_array['keyword'] = $_GET['keyword']);
     isset($_GET['tag']) && ($uri_array['tag'] = $_GET['tag']);
     isset($_GET['pt']) && ($uri_array['pt'] = $_GET['pt']);
     isset($_GET['cid']) && ($uri_array['cid'] = $_GET['cid']);
     $uri_array && ($uri = http_build_query($uri_array));
     $orderby = $_GET['orderby'] ? $_GET['orderby'] : "id DESC";
     $maxperpage = $_GET['perpage'] > 0 ? (int) $_GET['perpage'] : 20;
     if ($map_where) {
         $map_sql = iCMS::map_sql($map_where);
         $sql = ",({$map_sql}) map {$sql} AND `id` = map.`iid`";
     }
     $total = iPHP::total(false, articleTable::count_sql($sql), "G");
     iPHP::pagenav($total, $maxperpage, "篇文章");
     $limit = 'LIMIT ' . iPHP::$offset . ',' . $maxperpage;
     if ($map_sql || iPHP::$offset) {
         // if($map_sql){
         $ids_array = iDB::all("\n                    SELECT `id` FROM `#iCMS@__article` {$sql}\n                    ORDER BY {$orderby} {$limit}\n                ");
         //iDB::debug(1);
         $ids = iCMS::get_ids($ids_array);
         $ids = $ids ? $ids : '0';
         $sql = "WHERE `id` IN({$ids})";
         // }else{
         // $sql = ",(
         // SELECT `id` AS aid FROM `#iCMS@__article` {$sql}
         // ORDER BY {$orderby} {$limit}
         // ) AS art WHERE `id` = art.aid ";
         // }
         $limit = '';
     }
     $rs = iDB::all("SELECT * FROM `#iCMS@__article` {$sql} ORDER BY {$orderby} {$limit}");
     //iDB::debug(1);
     $_count = count($rs);
     include iACP::view("article.manage");
 }