function get_array($cache = false) { $rs = iDB::all("SELECT * FROM `#iCMS@__menu` ORDER BY `ordernum` , `id` ASC"); $this->menu_array = array(); $this->root_array = array(); $this->parent = array(); $this->menu_uri = array(); $this->child_array = array(); foreach ((array) $rs as $M) { $this->menu_array[$M['id']] = $M; $this->root_array[$M['rootid']][$M['id']] = $M; $this->parent[$M['id']] = $M['rootid']; $M['app'] != 'separator' && ($this->child_array[$M['rootid']][$M['id']] = $M['id']); if (!$this->menu_uri[$M['app']][$M['href']]) { $this->menu_uri[$M['app']][$M['href']] = $M['id']; } $this->menu_uri[$M['app']]['#'] = $M['rootid']; } foreach ((array) $this->root_array as $rid => $array) { uasort($array, "order_num"); $this->root_array[$rid] = $array; } if ($cache) { iCache::set('iCMS/iMenu/menu_array', $this->menu_array, 0); iCache::set('iCMS/iMenu/root_array', $this->root_array, 0); iCache::set('iCMS/iMenu/child_array', $this->child_array, 0); iCache::set('iCMS/iMenu/parent', $this->parent, 0); iCache::set('iCMS/iMenu/menu_uri', $this->menu_uri, 0); } }
/** * @package iCMS * @copyright 2007-2010, iDreamSoft * @license http://www.idreamsoft.com iDreamSoft * @author coolmoo <*****@*****.**> */ function iCMS_link($vars) { $limit = isset($vars['row']) ? (int) $vars['row'] : "100"; $cache_time = isset($vars['time']) ? (int) $vars['time'] : -1; switch ($vars['type']) { case "text": $sql[] = " `logo`='' "; break; case "logo": $sql[] = " `logo`!='' "; break; } isset($vars['cid']) && ($sql[] = " cid='" . $vars['cid'] . "'"); $sql && ($where = 'WHERE ' . implode(' AND ', $sql)); $iscache = true; if ($vars['cache'] == false || isset($vars['page'])) { $iscache = false; $rs = ''; } else { $cacheName = 'links/' . md5($sql); $rs = iCache::get($cacheName); } if (empty($rs)) { $rs = iDB::all("SELECT * FROM `#iCMS@__links`{$where} ORDER BY ordernum ASC,id ASC LIMIT 0 , {$limit}"); $iscache && iCache::set($cacheName, $rs, $cache_time); } return $rs; }
public function cahce_one($C = null) { if (!is_array($C)) { $C = iDB::row("SELECT * FROM `#iCMS@__category` where `cid`='{$C}' LIMIT 1;", ARRAY_A); $C = $this->C($C); } iCache::delete('iCMS/category/' . $C['cid']); iCache::set('iCMS/category/' . $C['cid'], $C, 0); }
function cache() { $filter = $this->setting->get(0, 'word.filter'); $disable = $this->setting->get(0, 'word.disable'); foreach ((array) $filter as $k => $val) { $filterArray[$k] = implode("=", (array) $val); } iCache::set('iCMS/word.filter', $filter, 0); iCache::set('iCMS/word.disable', $filterArray, 0); }
/** * @package iCMS * @copyright 2007-2010, iDreamSoft * @license http://www.idreamsoft.com iDreamSoft * @author coolmoo <*****@*****.**> * @$Id: push.tpl.php 1392 2013-05-20 12:28:08Z coolmoo $ */ function push_list($vars) { $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 `userid`='{$vars['userid']}'"); 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['pid']) && ($where_sql .= " AND `type` ='{$vars['pid']}'"); isset($vars['pic']) && ($where_sql .= " AND `haspic`='1'"); isset($vars['nopic']) && ($where_sql .= " AND `haspic`='0'"); isset($vars['startdate']) && ($where_sql .= " AND `addtime`>='" . strtotime($vars['startdate']) . "'"); isset($vars['enddate']) && ($where_sql .= " AND `addtime`<='" . strtotime($vars['enddate']) . "'"); $by = $vars['by'] == "ASC" ? "ASC" : "DESC"; switch ($vars['orderby']) { case "id": $order_sql = " ORDER BY `id` {$by}"; break; case "addtime": $order_sql = " ORDER BY `addtime` {$by}"; break; case "disorder": $order_sql = " ORDER BY `ordernum` {$by}"; break; default: $order_sql = " ORDER BY `id` DESC"; } if ($vars['cache']) { $cache_name = iPHP_DEVICE . '/push/' . md5($where_sql); $resource = iCache::get($cache_name); } if (empty($resource)) { $resource = iDB::all("SELECT * FROM `#iCMS@__push` {$where_sql} {$order_sql} LIMIT {$maxperpage}"); iPHP_SQL_DEBUG && iDB::debug(1); if ($resource) { foreach ($resource as $key => $value) { $value['pic'] && ($value['pic'] = iFS::fp($value['pic'], '+http')); $value['pic2'] && ($value['pic2'] = iFS::fp($value['pic2'], '+http')); $value['pic2'] && ($value['pic2'] = iFS::fp($value['pic2'], '+http')); $value['metadata'] && ($value['metadata'] = unserialize($value['metadata'])); $resource[$key] = $value; } } $vars['cache'] && iCache::set($cache_name, $resource, $cache_time); } return $resource; }
public static function cache($value = 0, $field = 'id') { $rs = self::data($value, $field); $_count = count($rs); for ($i = 0; $i < $_count; $i++) { $C = iCache::get('iCMS/category/' . $rs[$i]['cid']); $TC = iCache::get('iCMS/category/' . $rs[$i]['tcid']); $rs[$i]['iurl'] = iURL::get('tag', array($rs[$i], $C, $TC)); $rs[$i]['url'] = $rs[$i]['iurl']->href; $tkey = self::tkey($rs[$i]['cid']); iCache::set($tkey, $rs[$i], 0); } }
public static function cache() { $rs = iDB::all("SELECT `id`,`name`,`title`,`table`,`field` FROM `#iCMS@__app`"); foreach ((array) $rs as $a) { $tb_array = json_decode($a['table']); $table = array('name' => '#iCMS@__' . $tb_array[0][0], 'primary' => $tb_array[0][1]); if ($tb_array[1]) { $table['join'] = '#iCMS@__' . $tb_array[1][0]; $table['on'] = $tb_array[1][1]; } $a['table'] = $table; $app_id_array[$a['id']] = $a; $app_name_array[$a['name']] = $a; iCache::delete('iCMS/app/' . $a['id']); iCache::set('iCMS/app/' . $a['id'], $a, 0); iCache::delete('iCMS/app/' . $a['name']); iCache::set('iCMS/app/' . $a['name'], $a, 0); } iCache::set('iCMS/app/cache_id', $app_id_array, 0); iCache::set('iCMS/app/cache_name', $app_name_array, 0); }
/** * @package iCMS * @copyright 2007-2010, iDreamSoft * @license http://www.idreamsoft.com iDreamSoft * @author coolmoo <*****@*****.**> * @$Id: search.tpl.php 1392 2013-05-20 12:28:08Z coolmoo $ */ function search_list($vars) { $maxperpage = isset($vars['row']) ? (int) $vars['row'] : "100"; $cache_time = isset($vars['time']) ? (int) $vars['time'] : "-1"; $where_sql = ''; $by = $vars['by'] == "ASC" ? "ASC" : "DESC"; switch ($vars['orderby']) { case "id": $order_sql = " ORDER BY `id` {$by}"; break; case "addtime": $order_sql = " ORDER BY `addtime` {$by}"; break; case "times": $order_sql = " ORDER BY `times` {$by}"; break; default: $order_sql = " ORDER BY `id` DESC"; } if ($vars['cache']) { $cache_name = iPHP_DEVICE . '/search/' . md5($where_sql . $order_sql); $resource = iCache::get($cache_name); } if (empty($resource)) { $resource = iDB::all("SELECT * FROM `#iCMS@__search_log` {$where_sql} {$order_sql} LIMIT {$maxperpage}"); iPHP_SQL_DEBUG && iDB::debug(1); if ($resource) { foreach ($resource as $key => $value) { $value['name'] = $value['search']; $value['url'] = search_url(array('query' => $value['name'], 'ret' => true)); $resource[$key] = $value; } } $vars['cache'] && iCache::set($cache_name, $resource, $cache_time); } return $resource; }
public static function timeline() { $_timeline = iCache::get('iCMS/timeline'); //list($_today,$_week,$_month) = $_timeline ; $time = $_SERVER['REQUEST_TIME']; $today = get_date($time, "Ymd"); $yday = get_date($time - 86400 + 1, "Ymd"); $week = get_date($time, "YW"); $month = get_date($time, "Ym"); $timeline = array($today, $week, $month); $_timeline[0] == $today or iCache::set('iCMS/timeline', $timeline, 0); //var_dump($_timeline,$timeline); return array('yday' => $today - $_timeline[0], 'today' => $_timeline[0] == $today, 'week' => $_timeline[1] == $week, 'month' => $_timeline[2] == $month); }
public static function total($tnkey, $sql, $type = null) { $tnkey == 'sql.md5' && ($tnkey = md5($sql)); $tnkey = substr($tnkey, 8, 16); $total = (int) $_GET['total_num']; if (empty($total) && $type === null && !isset($_GET['total_cahce'])) { $total = (int) iCache::get('total/' . $tnkey); } if (empty($total) || $type === 'nocache' || isset($_GET['total_cahce'])) { $total = iDB::value($sql); if ($type === null) { iCache::set('total/' . $tnkey, $total); } } return $total; }
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; }
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; }
function category_list($vars) { $appid = isset($vars['appid']) ? (int) $vars['appid'] : iCMS_APP_ARTICLE; $row = isset($vars['row']) ? (int) $vars['row'] : "100"; $cache_time = isset($vars['time']) ? (int) $vars['time'] : "-1"; $status = isset($vars['status']) ? (int) $vars['status'] : "1"; $where_sql = " WHERE `appid`='{$appid}' AND `status`='{$status}'"; $resource = array(); isset($vars['mode']) && ($where_sql .= " AND `mode` = '{$vars['mode']}'"); if (stripos($vars['cid'], ',') !== false) { $vars['cid'] = explode(',', $vars['cid']); } if (stripos($vars['cid!'], ',') !== false) { $vars['cid!'] = explode(',', $vars['cid!']); } isset($vars['cid']) && !isset($vars['stype']) && ($where_sql .= iPHP::where($vars['cid'], 'cid')); isset($vars['cid!']) && ($where_sql .= iPHP::where($vars['cid!'], 'cid', 'not')); switch ($vars['stype']) { case "top": $vars['cid'] && ($where_sql .= iPHP::where($vars['cid'], 'cid')); $where_sql .= " AND rootid='0'"; break; case "sub": $vars['cid'] && ($where_sql .= iPHP::where($vars['cid'], 'rootid')); break; // case "subtop": // $vars['cid'] && $where_sql.= iPHP::where($vars['cid'],'cid'); // break; // case "subtop": // $vars['cid'] && $where_sql.= iPHP::where($vars['cid'],'cid'); // break; case "suball": $where_sql .= iPHP::where(iCMS::get_category_ids($vars['cid'], false), 'cid'); break; case "self": $parent = iCache::get('iCMS/category/parent', $vars['cid']); $where_sql .= " AND `rootid`='{$parent}'"; break; } if (isset($vars['pids'])) { iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('prop', iCMS_APP_CATEGORY); $where_sql .= map::exists($vars['pids'], '`#iCMS@__category`.cid'); //主表小 map表大 // $map_where=map::where($vars['pids']); //主表大 map表大 // $map_ids = map::ids($vars['pid']); // $map_sql = map::sql($vars['pid']); //map 表小的用 in // $where_sql.=" AND `pid` = '{$vars['pid']}'"; //if(empty($map_ids)) return $resource; //$where_sql.=" AND `cid` IN ($map_ids)"; //$where_sql.=" AND `cid` IN ($map_sql)"; } if ($vars['cache']) { $cache_name = iPHP_DEVICE . '/category/' . md5($where_sql); $resource = iCache::get($cache_name); } if (empty($resource)) { $rootid_array = iCache::get('iCMS/category/rootid'); $resource = iDB::all("SELECT * FROM `#iCMS@__category` {$where_sql} ORDER BY `ordernum`,`cid` ASC LIMIT {$row}"); iPHP_SQL_DEBUG && iDB::debug(1); if ($resource) { foreach ($resource as $key => $value) { $value['child'] = $rootid_array[$value['cid']] ? true : false; $value['url'] = iURL::get('category', $value)->href; $value['link'] = "<a href='{$value['url']}'>{$value['name']}</a>"; if ($value['metadata']) { $mdArray = array(); $_metadata = unserialize($value['metadata']); foreach ((array) $_metadata as $mkey => $md) { $mdArray[$mkey] = $md; } $value['metadata'] = $mdArray; unset($_metadata); } unset($value['contentprop']); $resource[$key] = $value; } } $vars['cache'] && iCache::set($cache_name, $resource, $cache_time); } return $resource; }
public function value($article, $art_data = "", $vars = array(), $page = 1, $tpl = false) { $article['appid'] = iCMS_APP_ARTICLE; $categoryApp = iPHP::app("category"); $category = $categoryApp->category($article['cid'], false); if ($tpl) { $category or iPHP::throw404('运行出错!找不到该文章的栏目缓存<b>cid:' . $article['cid'] . '</b> 请更新栏目缓存或者确认栏目是否存在', 10002); } else { if (empty($category)) { return false; } } if ($category['status'] == 0) { return false; } if (iPHP::$iTPL_MODE == "html" && $tpl && (strstr($category['contentRule'], '{PHP}') || $category['outurl'] || $category['mode'] == "0")) { return false; } $_iurlArray = array($article, $category); $article['iurl'] = iURL::get('article', $_iurlArray, $page); $article['url'] = $article['iurl']->href; $article['link'] = "<a href='{$article['url']}'>{$article['title']}</a>"; $tpl && $category['mode'] == '1' && iCMS::gotohtml($article['iurl']->path, $article['iurl']->href); if ($vars['category_lite']) { $article['category'] = $categoryApp->get_lite($category); } else { $article['category'] = $category; } $this->taoke = false; if ($art_data) { $pageurl = $article['iurl']->pageurl; // if(strpos($art_data['body'], '#--iCMS.ArticleData--#')!==false){ // iPHP::app('article.table'); // $art_data['body'] = articleTable::get_text($article['id']); // } $art_data['body'] = $this->ubb($art_data['body']); preg_match_all("/<img.*?src\\s*=[\"|'|\\s]*(http:\\/\\/.*?\\.(gif|jpg|jpeg|bmp|png)).*?>/is", $art_data['body'], $pic_array); $p_array = array_unique($pic_array[1]); if ($p_array) { foreach ($p_array as $key => $_pic) { $article['pics'][$key] = trim($_pic); } } if (strpos($art_data['body'], '#--iCMS.Markdown--#') !== false) { $art_data['body'] = iPHP::Markdown($art_data['body']); } $body = explode('#--iCMS.PageBreak--#', $art_data['body']); $count = count($body); $total = $count + intval(iCMS::$config['article']['pageno_incr']); $article['body'] = $this->keywords($body[intval($page - 1)]); $article['body'] = $this->taoke($article['body']); $article['subtitle'] = $art_data['subtitle']; $article['taoke'] = $this->taoke; unset($art_data); if ($total > 1) { $flag = 0; $num_nav = ''; for ($i = $page - 3; $i <= $page - 1; $i++) { if ($i < 1) { continue; } $num_nav .= "<a href='" . iPHP::p2num($pageurl, $i) . "' target='_self'>{$i}</a>"; $flag++; } $num_nav .= '<span class="current">' . $page . '</span>'; for ($i = $page + 1; $i <= $total; $i++) { $num_nav .= "<a href='" . iPHP::p2num($pageurl, $i) . "' target='_self'>{$i}</a>"; $flag++; if ($flag == 6) { break; } } $index_nav = '<a href="' . $article['url'] . '" class="first" target="_self">' . iPHP::lang('iCMS:page:index') . '</a>'; $prev_url = iPHP::p2num($pageurl, $page - 1 > 1 ? $page - 1 : 1); $prev_nav = '<a href="' . $prev_url . '" class="prev" target="_self">' . iPHP::lang('iCMS:page:prev') . '</a>'; $next_url = iPHP::p2num($pageurl, $total - $page > 0 ? $page + 1 : $page); $next_nav = '<a href="' . $next_url . '" class="next" target="_self">' . iPHP::lang('iCMS:page:next') . '</a>'; $end_nav = '<a href="' . iPHP::p2num($pageurl, $total) . '" class="end" target="_self">共' . $total . '页</a>'; $text_nav = $index_nav . $prev_nav . '<span class="current">第' . $page . '页</span>' . $next_nav . $end_nav; $pagenav = $index_nav . $prev_nav . $num_nav . $next_nav . $end_nav; } $article['page'] = array('total' => $total, 'count' => $count, 'current' => $page, 'num' => $num_nav, 'text' => $text_nav, 'nav' => $pagenav, 'prev' => $prev_url, 'next' => $next_url, 'pageurl' => $pageurl, 'last' => $page == $count ? true : false, 'end' => $page == $total ? true : false); unset($index_nav, $prev_nav, $num_nav, $next_nav, $end_nav, $pagenav); //var_dump($page,$total,$count); if ($pic_array[0]) { $img_array = array_unique($pic_array[0]); foreach ($img_array as $key => $img) { $img = str_replace('<img', '<img title="' . $article['title'] . '" alt="' . $article['title'] . '"', $img); if (iCMS::$config['article']['pic_center']) { $img_replace[$key] = '<p align="center">' . $img . '</p>'; } else { $img_replace[$key] = $img; } if (iCMS::$config['article']['pic_next'] && $count > 1) { $clicknext = '<a href="' . $next_url . '"><b>' . iPHP::lang('iCMS:article:clicknext') . '</b></a>'; $clickimg = '<a href="' . $next_url . '" title="' . $article['title'] . '" class="img">' . $img . '</a>'; if (iCMS::$config['article']['pic_center']) { $img_replace[$key] = '<p align="center">' . $clicknext . '</p>'; $img_replace[$key] .= '<p align="center">' . $clickimg . '</p>'; } else { $img_replace[$key] = '<p>' . $clicknext . '</p>'; $img_replace[$key] .= '<p>' . $clickimg . '</p>'; } } } $article['body'] = str_replace($img_array, $img_replace, $article['body']); } } if ($vars['prev_next'] && iCMS::$config['article']['prev_next']) { //上一篇 $prev_cache = iPHP_DEVICE . '/article/' . $article['id'] . '/prev'; $prev_array = iCache::get($prev_cache); if (empty($prev_array)) { $prev_array = array('empty' => true, 'title' => iPHP::lang('iCMS:article:first'), 'pic' => array(), 'url' => 'javascript:;'); $prevrs = iDB::row("SELECT * FROM `#iCMS@__article` WHERE `id` < '{$article['id']}' AND `cid`='{$article['cid']}' AND `status`='1' order by id DESC LIMIT 1;"); if ($prevrs) { $prev_array = array('empty' => false, 'title' => $prevrs->title, 'pic' => get_pic($prevrs->pic), 'url' => iURL::get('article', array((array) $prevrs, $category))->href); } iCache::set($prev_cache, $prev_array); } $article['prev'] = $prev_array; //下一篇 $next_cache = iPHP_DEVICE . '/article/' . $article['id'] . '/next'; $next_array = iCache::get($next_cache); if (empty($next_array)) { $next_array = array('empty' => true, 'title' => iPHP::lang('iCMS:article:last'), 'pic' => array(), 'url' => 'javascript:;'); $nextrs = iDB::row("SELECT * FROM `#iCMS@__article` WHERE `id` > '{$article['id']}' and `cid`='{$article['cid']}' AND `status`='1' order by id ASC LIMIT 1;"); if ($nextrs) { $next_array = array('empty' => false, 'title' => $nextrs->title, 'pic' => get_pic($nextrs->pic), 'url' => iURL::get('article', array((array) $nextrs, $category))->href); } iCache::set($next_cache, $next_array); } $article['next'] = $next_array; } if ($vars['tags']) { $article['tags_fname'] = $category['name']; if ($article['tags']) { $tagApp = iPHP::app("tag"); $tagArray = $tagApp->get_array($article['tags']); $article['tag_array'] = array(); foreach ((array) $tagArray as $tk => $tag) { $article['tag_array'][$tk]['name'] = $tag['name']; $article['tag_array'][$tk]['url'] = $tag['url']; $article['tag_array'][$tk]['link'] = $tag['link']; $article['tags_link'] .= $tag['link']; $tag_name_array[] = $tag['name']; } $tag_name_array && ($article['tags_fname'] = $tag_name_array[0]); unset($tagApp, $tagArray, $tag_name_array); } } if ($vars['meta']) { if ($article['metadata']) { $article['meta'] = unserialize($article['metadata']); unset($article['metadata']); } } if ($vars['user']) { iPHP::app('user.class', 'static'); if ($article['postype']) { $article['user'] = user::empty_info($article['userid'], '#' . $article['editor']); } else { $article['user'] = user::info($article['userid'], $article['author']); } } if (strstr($article['source'], '||')) { list($s_name, $s_url) = explode('||', $article['source']); $article['source'] = '<a href="' . $s_url . '" target="_blank">' . $s_name . '</a>'; } if (strstr($article['author'], '||')) { list($a_name, $a_url) = explode('||', $article['author']); $article['author'] = '<a href="' . $a_url . '" target="_blank">' . $a_name . '</a>'; } $article['hits'] = array('script' => iCMS_API . '?app=article&do=hits&cid=' . $article['cid'] . '&id=' . $article['id'], 'count' => $article['hits'], 'today' => $article['hits_today'], 'yday' => $article['hits_yday'], 'week' => $article['hits_week'], 'month' => $article['hits_month']); $article['comment'] = array('url' => iCMS_API . "?app=article&do=comment&appid={$article['appid']}&iid={$article['id']}&cid={$article['cid']}", 'count' => $article['comments']); if ($article['picdata']) { $picdata = unserialize($article['picdata']); } unset($article['picdata']); $article['pic'] = get_pic($article['pic'], $picdata['b'], get_twh($vars['btw'], $vars['bth'])); $article['mpic'] = get_pic($article['mpic'], $picdata['m'], get_twh($vars['mtw'], $vars['mth'])); $article['spic'] = get_pic($article['spic'], $picdata['s'], get_twh($vars['stw'], $vars['sth'])); $article['param'] = array("appid" => $article['appid'], "iid" => $article['id'], "cid" => $article['cid'], "suid" => $article['userid'], "title" => $article['title'], "url" => $article['url']); return $article; }
function cache() { $rs = iDB::all("SELECT * FROM `#iCMS@__keywords` ORDER BY CHAR_LENGTH(`keyword`) DESC"); iCache::set('iCMS/keywords', $rs, 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; }
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; }
function cache() { $rs = iDB::all("SELECT * FROM `#iCMS@__prop`"); foreach ((array) $rs as $row) { $type_field_id[$row['type'] . '/' . $row['field']][$row['pid']] = $type_field_val[$row['type']][$row['field']][$row['val']] = $row; } // prop/article/author foreach ((array) $type_field_id as $key => $a) { iCache::set('iCMS/prop/' . $key, $a, 0); } // prop/article foreach ((array) $type_field_val as $k => $a) { iCache::set('iCMS/prop/' . $k, $a, 0); } }
function cache($id = null) { $id && ($sql = " AND `id`='{$id}'"); $rs = iDB::all("SELECT * FROM `#iCMS@__marker` WHERE `status`='1' {$sql} "); foreach ((array) $rs as $row) { iCache::set('marker/' . $row['key'], $row['data'], 0); } }
public function ACTION_login() { iCMS::$config['user']['login']['enable'] or iPHP::code(0, 'user:login:forbidden', 'uname', 'json'); $uname = iS::escapeStr($_POST['uname']); $pass = md5(trim($_POST['pass'])); $remember = (bool) $_POST['remember'] ? ture : false; $openid = iS::escapeStr($_POST['openid']); $platform = iS::escapeStr($_POST['platform']); if (iCMS::$config['user']['login']['seccode']) { $seccode = iS::escapeStr($_POST['seccode']); iPHP::seccode($seccode, true) or iPHP::code(0, 'iCMS:seccode:error', 'seccode', 'json'); } $remember && (user::$cookietime = 14 * 86400); $user = user::login($uname, $pass, strpos($uname, '@') === false ? 'nk' : 'un'); if ($user === true) { if ($openid) { iDB::query("\n INSERT INTO `#iCMS@__user_openid`\n (`uid`, `openid`, `platform`)\n VALUES ('" . user::$userid . "', '{$openid}', '{$platform}');\n "); } iPHP::code(1, 0, $this->forward, 'json'); } else { if (iCMS::$config['user']['login']['interval']) { $cache_name = "iCMS/error/login." . md5($uname); $login_error = iCache::get($cache_name); if ($login_error) { if ($login_error[1] >= 5) { $_field = strpos($uname, '@') === false ? 'nickname' : 'username'; iDB::update('user', array('status' => '3'), array($_field => $uname)); iPHP::code(0, 'user:login:interval', 'uname', 'json'); } else { $login_error[1]++; } } else { $login_error = array($uname, 1); } iCache::set($cache_name, $login_error, iCMS::$config['user']['login']['interval']); } // $lang = 'user:login:error'; // $user && $lang.='_status_'.$user; iPHP::code(0, 'user:login:error', 'uname', 'json'); } }
function do_save() { $appid = $this->appid; $cid = (int) $_POST['cid']; $rootid = (int) $_POST['rootid']; $status = (int) $_POST['status']; $isucshow = (int) $_POST['isucshow']; $issend = (int) $_POST['issend']; $isexamine = (int) $_POST['isexamine']; $ordernum = (int) $_POST['ordernum']; $mode = (int) $_POST['mode']; $pid = implode(',', (array) $_POST['pid']); $_pid = iS::escapeStr($_POST['_pid']); $_rootid_hash = iS::escapeStr($_POST['_rootid_hash']); $name = iS::escapeStr($_POST['name']); $subname = iS::escapeStr($_POST['subname']); $domain = iS::escapeStr($_POST['domain']); $htmlext = iS::escapeStr($_POST['htmlext']); $url = iS::escapeStr($_POST['url']); $password = iS::escapeStr($_POST['password']); $pic = iS::escapeStr($_POST['pic']); $mpic = iS::escapeStr($_POST['mpic']); $spic = iS::escapeStr($_POST['spic']); $dir = iS::escapeStr($_POST['dir']); $title = iS::escapeStr($_POST['title']); $keywords = iS::escapeStr($_POST['keywords']); $description = iS::escapeStr($_POST['description']); $categoryURI = iS::escapeStr($_POST['categoryURI']); $categoryRule = iS::escapeStr($_POST['categoryRule']); $contentRule = iS::escapeStr($_POST['contentRule']); $urlRule = iS::escapeStr($_POST['urlRule']); $indexTPL = iS::escapeStr($_POST['indexTPL']); $listTPL = iS::escapeStr($_POST['listTPL']); $contentTPL = iS::escapeStr($_POST['contentTPL']); $metadata = iS::escapeStr($_POST['metadata']); $contentprop = iS::escapeStr($_POST['contentprop']); $body = $_POST['body']; $hasbody = (int) $_POST['hasbody']; $hasbody or $hasbody = $body ? 1 : 0; if ($_rootid_hash) { $_rootid = authcode($_rootid_hash); if ($rootid != $_rootid) { iPHP::alert('非法数据提交!'); } else { iACP::CP($_rootid, 'a', 'alert'); exit; } } $cid && $cid == $rootid && iPHP::alert('不能以自身做为上级' . $this->category_name); empty($name) && iPHP::alert($this->category_name . '名称不能为空!'); if ($metadata) { $md = array(); foreach ($metadata['key'] as $_mk => $_mval) { !preg_match("/[a-zA-Z0-9_\\-]/", $_mval) && iPHP::alert($this->category_name . '附加属性名称只能由英文字母、数字或_-组成(不支持中文)'); $md[$_mval] = $metadata['value'][$_mk]; } $metadata = addslashes(serialize($md)); } if ($contentprop) { $ca = array(); foreach ($contentprop['key'] as $_cak => $_caval) { $_caval or $_caval = strtolower(pinyin($contentprop['name'][$_cak])); !preg_match("/[a-zA-Z0-9_\\-]/", $_caval) && iPHP::alert('内容附加属性字段只能由英文字母、数字或_-组成(不支持中文)'); $ca[$_caval] = $contentprop['name'][$_cak]; } $contentprop = addslashes(serialize($ca)); } if ($mode == "2") { if (strpos($categoryRule, '{CDIR}') === FALSE && strpos($categoryRule, '{CID}') === FALSE && strpos($categoryRule, '{0xCID}') === FALSE) { iPHP::alert('伪静态模式下版块URL规则<hr />必需要有<br />{CDIR}版块目录<br />或者<br />{CID},{0xCID}版块ID'); } if (strpos($contentRule, '{ID}') === FALSE && strpos($contentRule, '{0xID}') === FALSE && strpos($contentRule, '{LINK}') === FALSE) { iPHP::alert('伪静态模式下内容URL规则<hr />必需要有<br />{ID}' . $this->_app_name . 'ID <br />或者<br />{0xID}' . $this->_app_name . 'ID补零<br />或者<br />{LINK}' . $this->_app_name . '自定义链接'); } } iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('prop', iCMS_APP_CATEGORY); $fields = array('rootid', 'appid', 'ordernum', 'name', 'subname', 'password', 'title', 'keywords', 'description', 'dir', 'mode', 'domain', 'url', 'pic', 'mpic', 'spic', 'htmlext', 'categoryURI', 'categoryRule', 'contentRule', 'urlRule', 'indexTPL', 'listTPL', 'contentTPL', 'metadata', 'contentprop', 'hasbody', 'pid', 'isexamine', 'issend', 'isucshow', 'status'); $data = compact($fields); if (empty($cid)) { iACP::CP($rootid, 'a', 'alert'); $nameArray = explode("\n", $name); $_count = count($nameArray); foreach ($nameArray as $nkey => $_name) { $_name = trim($_name); if (empty($_name)) { continue; } if ($_count == "1") { if (empty($dir) && empty($url)) { $dir = strtolower(pinyin($_name)); } } else { empty($url) && ($dir = strtolower(pinyin($_name))); } $this->check_dir($dir, $appid, $url); $data['name'] = $_name; $data['dir'] = $dir; $data['userid'] = iMember::$userid; $data['creator'] = iMember::$nickname; $data['createtime'] = time(); $data['count'] = '0'; $data['comments'] = '0'; $cid = iDB::insert('category', $data); $pid && map::add($pid, $cid); $this->cache(false, $this->appid); $this->cahce_one($cid); } $msg = $this->category_name . "添加完成!"; } else { if (empty($dir) && empty($url)) { $dir = strtolower(pinyin($name)); } iACP::CP($cid, 'e', 'alert'); $this->check_dir($dir, $appid, $url, $cid); $data['dir'] = $dir; iDB::update('category', $data, array('cid' => $cid)); map::diff($pid, $_pid, $cid); $this->cahce_one($cid); $msg = $this->category_name . "编辑完成!"; } $hasbody && iCache::set('iCMS/category/' . $cid . '.body', $body, 0); iPHP::success($msg, 'url:' . $this->category_uri); }
function article_next($vars) { // if($vars['param']){ // $vars+= $vars['param']; // unset($vars['param']); // } empty($vars['order']) && ($vars['order'] = 'n'); $cache_time = isset($vars['time']) ? (int) $vars['time'] : -1; if (isset($vars['cid'])) { $sql = " AND `cid`='{$vars['cid']}' "; } if ($vars['order'] == 'p') { $sql .= " AND `id` < '{$vars['id']}' ORDER BY id DESC LIMIT 1"; } else { if ($vars['order'] == 'n') { $sql .= " AND `id` > '{$vars['id']}' ORDER BY id ASC LIMIT 1"; } } $hash = md5($sql); if ($vars['cache']) { $cache = iPHP_DEVICE . '/article/' . $hash; $array = iCache::get($cache); } if (empty($array)) { $rs = iDB::row("SELECT * FROM `#iCMS@__article` WHERE `status`='1' {$sql}"); if ($rs) { $category = iCache::get('iCMS/category/' . $rs->cid); $array = array('title' => $rs->title, 'pic' => get_pic($rs->pic), 'url' => iURL::get('article', array((array) $rs, $category))->href); } iCache::set($cache, $array, $cache_time); } return $array; }
function do_createCategory($cid = 0, $p = 1, $loop = 1) { $category = $this->PG['cid']; $rootid = $this->PG['rootid']; $k = (int) $this->PG['k']; if ($k > 0 || empty($category)) { $category = iCache::get('iCMS/create.category'); } if (empty($category)) { iPHP::alert('请选择需要生成静态的栏目!'); } $category[0] == 'all' && ($category = $this->get_category(iCMS_APP_ARTICLE)); $k === 0 && iCache::set('iCMS/create.category', $category, 0); $_GET['loop'] && ($loop = 0); $GLOBALS['page'] = $p + $this->page; $len = count($category) - 1; $cid = $category[$k]; $htm = iCMS::run('category', 'category', $cid, null); $htm or iPHP::alert("栏目[cid:{$cid}] URL规则设置问题! 此栏目不能生成静态"); $fpath = iPHP::p2num($htm[1]['iurl']['pagepath']); $total = $GLOBALS['iPage']['total']; iFS::check_ext($fpath) or iPHP::alert("文件类型不合法,禁止生成!<hr />请更改栏目->URL规则设置->栏目规则"); iFS::mkdir($htm[1]['iurl']['dir']); iFS::write($fpath, $htm[0]); $_total = $total ? $total : "1"; $name = $htm[1]['name']; $msg = "<span class='label label-success'>{$name}</span>栏目,共<span class='label label-info'>{$_total}</span>页 已生成<span class='label label-info'>" . $GLOBALS['page'] . "</span>页,"; // $surplus = ceil($total-$p); if ($loop < $this->CP && $GLOBALS['page'] < $total) { $loop++; $p++; $this->do_createCategory($cid, $p, $loop); } $looptimes = ($total - $GLOBALS['page']) / $this->CP; $use_time = iPHP::timer_stop(); $msg .= "用时<span class='label label-info'>{$use_time}</span>秒"; //$query["alltime"] = $query["alltime"] = $this->alltime + $use_time; $loopurl = $this->loopurl($total, $query); // print_r($loopurl); // exit; if ($loopurl) { $moreBtn = array(array("id" => "btn_stop", "text" => "停止", "url" => APP_URI . "&do=category"), array("id" => "btn_next", "text" => "继续", "src" => $loopurl, "next" => true)); $dtime = 1; $all_time = $looptimes * $use_time + $looptimes + 1; $msg .= "<hr /><span class='label label-success'>{$name}</span>栏目,预计全部生成还需要<span class='label label-info'>{$all_time}</span>秒"; } else { $moreBtn = array(array("id" => "btn_next", "text" => "完成", "url" => APP_URI . "&do=category")); $dtime = 3; $msg .= "<hr /><span class='label label-success'>{$name}</span>栏目,已全部生成完成.总共用时<span class='label label-info'>" . $query["alltime"] . "</span>秒"; if ($k < $len) { $query["k"] = $k + 1; $query["alltime"] = 0; $GLOBALS['page'] = 0; $loopurl = $this->loopurl(1, $query); $msg .= "<hr />准备开始生成下一个栏目"; $moreBtn = array(array("id" => "btn_stop", "text" => "停止", "url" => APP_URI . "&do=category"), array("id" => "btn_next", "text" => "继续", "src" => $loopurl, "next" => true)); $dtime = 1; } elseif ($k == $len) { $msg .= "<hr />所有栏目生成完成"; } $k > 0 && ($updateMsg = true); } if ($k == 0) { $updateMsg = $this->page ? true : false; } iPHP::dialog($msg, $loopurl ? "src:" . $loopurl : "", $dtime, $moreBtn, $updateMsg); }
/** * @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; }
/** * [set 更新配置] * @param [type] $v [description] * @param [type] $n [description] * @param [type] $appid [description] * @param boolean $cache [description] */ function set($value, $name, $appid, $cache = false) { $cache && iCache::set('iCMS/config/' . $name, $value, 0); is_array($value) && ($value = addslashes(serialize($value))); $check = iDB::value("SELECT `name` FROM `#iCMS@__config` WHERE `appid` ='{$appid}' AND `name` ='{$name}'"); $fields = array('appid', 'name', 'value'); $data = compact($fields); if ($check === null) { iDB::insert('config', $data); } else { iDB::update('config', $data, array('appid' => $appid, 'name' => $name)); } }
public static function set_cache($uid) { $user = iDB::row("SELECT * FROM `#iCMS@__user` where `uid`='{$uid}'", ARRAY_A); unset($user['password']); iCache::set('iCMS:user:'******'uid'], $user, 0); }