示例#1
0
function favorite_data($vars = null)
{
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : "10";
    $where_sql = "WHERE 1=1 ";
    isset($vars['userid']) && ($where_sql .= " AND `uid`='" . (int) $vars['userid'] . "' ");
    $vars['fid'] && ($where_sql .= " AND `fid`='" . (int) $vars['fid'] . "' ");
    isset($vars['appid']) && ($where_sql .= " AND `appid`='" . (int) $vars['appid'] . "' ");
    $cache_time = isset($vars['time']) ? (int) $vars['time'] : -1;
    $by = $vars['by'] == "ASC" ? "ASC" : "DESC";
    switch ($vars['orderby']) {
        default:
            $order_sql = " ORDER BY `id` {$by}";
    }
    $md5 = md5($where_sql . $order_sql);
    $offset = 0;
    if ($vars['page']) {
        $total = iPHP::total($md5, "SELECT count(*) FROM `#iCMS@__favorite_data` {$where_sql} ");
        iPHP::assign("fav_data_total", $total);
        $multi = iCMS::page(array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:list'), 'nowindex' => $GLOBALS['page']));
        $offset = $multi->offset;
    }
    if ($vars['cache']) {
        $cache_name = 'favorite_data/' . $md5 . "/" . (int) $GLOBALS['page'];
        $resource = iCache::get($cache_name);
    }
    if (empty($resource)) {
        $resource = iDB::all("SELECT * FROM `#iCMS@__favorite_data` {$where_sql} {$order_sql} LIMIT {$offset},{$maxperpage}");
        iPHP_SQL_DEBUG && iDB::debug(1);
        // $resource = array();
        // if($rs)foreach ($rs as $key => $value) {
        // }
        $vars['cache'] && iCache::set($cache_name, $resource, $cache_time);
    }
    return $resource;
}
示例#2
0
function article_search($vars)
{
    if (empty(iCMS::$config['sphinx']['host'])) {
        return array();
    }
    $resource = array();
    $hidden = iCache::get('iCMS/category/hidden');
    $hidden && ($where_sql .= iPHP::where($hidden, 'cid', 'not'));
    $SPH = iCMS::sphinx();
    $SPH->init();
    $SPH->SetArrayResult(true);
    if (isset($vars['weights'])) {
        //weights='title:100,tags:80,keywords:60,name:50'
        $wa = explode(',', $vars['weights']);
        foreach ($wa as $wk => $wv) {
            $waa = explode(':', $wv);
            $FieldWeights[$waa[0]] = $waa[1];
        }
        $FieldWeights or $FieldWeights = array("title" => 100, "tags" => 80, "name" => 60, "keywords" => 40);
        $SPH->SetFieldWeights($FieldWeights);
    }
    $page = (int) $_GET['page'];
    $maxperpage = isset($vars['row']) ? (int) $vars['row'] : 10;
    $start = $page && isset($vars['page']) ? ($page - 1) * $maxperpage : 0;
    $SPH->SetMatchMode(SPH_MATCH_EXTENDED);
    if ($vars['mode']) {
        $vars['mode'] == "SPH_MATCH_BOOLEAN" && $SPH->SetMatchMode(SPH_MATCH_BOOLEAN);
        $vars['mode'] == "SPH_MATCH_ANY" && $SPH->SetMatchMode(SPH_MATCH_ANY);
        $vars['mode'] == "SPH_MATCH_PHRASE" && $SPH->SetMatchMode(SPH_MATCH_PHRASE);
        $vars['mode'] == "SPH_MATCH_ALL" && $SPH->SetMatchMode(SPH_MATCH_ALL);
        $vars['mode'] == "SPH_MATCH_EXTENDED" && $SPH->SetMatchMode(SPH_MATCH_EXTENDED);
    }
    isset($vars['userid']) && $SPH->SetFilter('userid', array($vars['userid']));
    isset($vars['postype']) && $SPH->SetFilter('postype', array($vars['postype']));
    if (isset($vars['cid'])) {
        $cids = $vars['sub'] ? iCMS::get_category_ids($vars['cid'], true) : (array) $vars['cid'];
        $cids or $cids = (array) $vars['cid'];
        $cids = array_map("intval", $cids);
        $SPH->SetFilter('cid', $cids);
    }
    if (isset($vars['startdate'])) {
        $startime = strtotime($vars['startdate']);
        $enddate = empty($vars['enddate']) ? time() : strtotime($vars['enddate']);
        $SPH->SetFilterRange('pubdate', $startime, $enddate);
    }
    $SPH->SetLimits($start, $maxperpage, 10000);
    $orderby = '@id DESC, @weight DESC';
    $order_sql = ' order by id DESC';
    $vars['orderby'] && ($orderby = $vars['orderby']);
    $vars['ordersql'] && ($order_sql = ' order by ' . $vars['ordersql']);
    $vars['pic'] && $SPH->SetFilter('haspic', array(1));
    $vars['id!'] && $SPH->SetFilter('@id', array($vars['id!']), true);
    $SPH->setSortMode(SPH_SORT_EXTENDED, $orderby);
    $query = str_replace(',', '|', $vars['q']);
    $vars['acc'] && ($query = '"' . $vars['q'] . '"');
    $vars['@'] && ($query = '@(' . $vars['@'] . ') ' . $query);
    $res = $SPH->Query($query, iCMS::$config['sphinx']['index']);
    if (is_array($res["matches"])) {
        foreach ($res["matches"] as $docinfo) {
            $aid[] = $docinfo['id'];
        }
        $aids = implode(',', (array) $aid);
    }
    if (empty($aids)) {
        return;
    }
    $where_sql = " `id` in({$aids})";
    $offset = 0;
    if ($vars['page']) {
        $total = $res['total'];
        iPHP::assign("article_search_total", $total);
        $pagenav = isset($vars['pagenav']) ? $vars['pagenav'] : "pagenav";
        $pnstyle = isset($vars['pnstyle']) ? $vars['pnstyle'] : 0;
        $multi = iCMS::page(array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:list'), 'nowindex' => $GLOBALS['page']));
        $offset = $multi->offset;
    }
    $resource = iDB::all("SELECT * FROM `#iCMS@__article` WHERE {$where_sql} {$order_sql} LIMIT {$maxperpage}");
    iPHP_SQL_DEBUG && iDB::debug(1);
    $resource = __article_array($vars, $resource);
    return $resource;
}
示例#3
0
function user_inbox($vars = null)
{
    $maxperpage = 30;
    $where_sql = "WHERE `status` ='1'";
    if ($_GET['user']) {
        if ($_GET['user'] == "10000") {
            $where_sql .= " AND `userid`='10000' AND `friend` IN ('" . user::$userid . "','0')";
        } else {
            $friend = (int) $_GET['user'];
            $where_sql .= " AND `userid`='" . user::$userid . "' AND `friend`='" . $friend . "'";
        }
        $group_sql = '';
        $p_fields = 'COUNT(*)';
        $s_fields = '*';
        iPHP::assign("msg_count", false);
    } else {
        //	 	$where_sql.= " AND (`userid`='".user::$userid."' OR (`userid`='10000' AND `friend`='0'))";
        $where_sql .= " AND `userid`='" . user::$userid . "'";
        $group_sql = ' GROUP BY `friend` DESC';
        $p_fields = 'COUNT(DISTINCT id)';
        $s_fields = 'max(id) AS id ,COUNT(id) AS msg_count,`userid`, `friend`, `send_uid`, `send_name`, `receiv_uid`, `receiv_name`, `content`, `type`, `sendtime`, `readtime`';
        iPHP::assign("msg_count", true);
    }
    $offset = 0;
    $total = iPHP::total($md5, "SELECT {$p_fields} FROM `#iCMS@__message` {$where_sql} {$group_sql}", 'nocache');
    iPHP::assign("msgs_total", $total);
    $multi = iCMS::page(array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:list'), 'nowindex' => $GLOBALS['page']));
    $offset = $multi->offset;
    $resource = iDB::all("SELECT {$s_fields} FROM `#iCMS@__message` {$where_sql} {$group_sql} ORDER BY `id` DESC LIMIT {$offset},{$maxperpage}");
    iPHP_SQL_DEBUG && iDB::debug(1);
    $msg_type_map = array('0' => '系统信息', '1' => '私信', '2' => '提醒', '3' => '留言');
    if ($resource) {
        foreach ($resource as $key => $value) {
            $value['sender'] = user::info($value['send_uid'], $value['send_name']);
            $value['receiver'] = user::info($value['receiv_uid'], $value['receiv_name']);
            $value['label'] = $msg_type_map[$value['type']];
            if ($value['userid'] == $value['send_uid']) {
                $value['is_sender'] = true;
                $value['user'] = $value['receiver'];
            }
            if ($value['userid'] == $value['receiv_uid']) {
                $value['is_sender'] = false;
                $value['user'] = $value['sender'];
            }
            $value['url'] = iPHP::router(array('/user/inbox/{uid}', $value['user']['uid']), iPHP_ROUTER_REWRITE);
            $resource[$key] = $value;
        }
    }
    return $resource;
}
示例#4
0
文件: tag.func.php 项目: Junred/iCMS
/**
 * @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;
}
示例#5
0
function comment_list($vars)
{
    if ($vars['display'] && empty($vars['loop'])) {
        if (empty($vars['_display'])) {
            $_vars = iCMS::app_ref(true);
            $vars = array_merge($vars, $_vars);
        }
        return comment_list_display($vars);
    }
    $where_sql = " `status`='1'";
    if (isset($vars['appid'])) {
        $appid = (int) $vars['appid'];
        $where_sql .= " AND `appid`='{$appid}'";
    }
    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['cid'])) {
        $cid = explode(',', $vars['cid']);
        $vars['sub'] && ($cid += iCMS::get_category_ids($cid, true));
        $where_sql .= iPHP::where($cid, 'cid');
    }
    isset($vars['userid']) && ($where_sql .= " AND `userid`='{$vars['userid']}'");
    $vars['pid'] && ($where_sql .= " AND `pid`='" . (int) $vars['pid'] . "'");
    $vars['iid'] && ($where_sql .= " AND `iid`='" . (int) $vars['iid'] . "'");
    $vars['id'] && ($where_sql .= " AND `id`='" . (int) $vars['id'] . "'");
    $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']) {
        default:
            $order_sql = " ORDER BY `id` {$by}";
    }
    $md5 = md5($where_sql . $order_sql);
    $offset = 0;
    $limit = "LIMIT {$maxperpage}";
    if ($vars['page']) {
        isset($vars['total_cache']) && ($_GET['total_cahce'] = true);
        $total = iPHP::total($md5, "SELECT count(*) FROM `#iCMS@__comment` WHERE {$where_sql} limit 1");
        $pgconf = array('total' => $total, 'perpage' => $maxperpage, 'unit' => iPHP::lang('iCMS:page:comment'), 'ajax' => $vars['page_ajax'] ? 'iCMS.comment.page' : FALSE, 'nowindex' => $GLOBALS['page']);
        if ($vars['display'] == 'iframe' || $vars['page_ajax']) {
            iS::gp('pn', 'GP', 2);
            $pgconf['page_name'] = 'pn';
            $pgconf['nowindex'] = $GLOBALS['pn'];
        }
        isset($vars['total_cache']) && ($pgconf['total_type'] = $vars['total_cache']);
        $multi = iCMS::page($pgconf);
        $offset = $multi->offset;
        $limit = "LIMIT {$offset},{$maxperpage}";
        // if($offset>1000){
        //$where_sql.=" AND `id` >= (SELECT `id` FROM `#iCMS@__comment` WHERE {$where_sql} {$order_sql} LIMIT {$offset},1)";
        //$limit  = "LIMIT {$maxperpage}";
        // }
        iPHP::assign("comment_total", $total);
    }
    if ($vars['cache']) {
        $cache_name = iPHP_DEVICE . '/comment/' . $md5 . "/" . (int) $offset;
        $resource = iCache::get($cache_name);
    }
    if (empty($resource)) {
        $resource = iDB::all("SELECT * FROM `#iCMS@__comment` WHERE {$where_sql} {$order_sql} {$limit}");
        //iDB::debug(1);
        $ln = $GLOBALS['page'] - 1 < 0 ? 0 : $GLOBALS['page'] - 1;
        if ($resource) {
            foreach ($resource as $key => $value) {
                if ($vars['date_format']) {
                    $value['addtime'] = get_date($value['addtime'], $vars['date_format']);
                }
                $value['url'] = iCMS_API . '?app=comment&do=goto&iid=' . $value['iid'] . '&appid=' . $value['appid'] . '&cid=' . $value['cid'];
                $value['lou'] = $total - ($i + $ln * $maxperpage);
                $value['content'] = nl2br($value['content']);
                $value['user'] = user::info($value['userid'], $value['username'], $vars['facesize']);
                $value['reply_uid'] && ($value['reply'] = user::info($value['reply_uid'], $value['reply_name'], $vars['facesize']));
                $value['total'] = $total;
                if ($vars['page']) {
                    $value['page'] = array('total' => $multi->totalpage, 'perpage' => $multi->perpage);
                }
                $value['param'] = array("appid" => iCMS_APP_COMMENT, "id" => $value['id'], "userid" => $value['userid'], "name" => $value['username']);
                $resource[$key] = $value;
            }
        }
        $vars['cache'] && iCache::set($cache_name, $resource, $cache_time);
    }
    return $resource;
}