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; }
/** * @package iCMS * @copyright 2007-2010, iDreamSoft * @license http://www.idreamsoft.com iDreamSoft * @author coolmoo <*****@*****.**> * @$Id: iCMS.push.php 148 2013-03-14 16:15:12Z coolmoo $ */ function iCMS_lang($vars) { if (empty($vars['key'])) { return; } echo iPHP::lang($vars['key']); }
public static function page($a) { iPHP::loadClass("Pages"); $lang = iPHP::lang(iPHP_APP . ':page'); $iPages = new iPages($a, $lang); if ($iPages->totalpage > 1) { $pagenav = $a['pagenav'] ? strtoupper($a['pagenav']) : 'NAV'; $pnstyle = $a['pnstyle'] ? $a['pnstyle'] : 0; iPHP::$iTPL->_iTPL_VARS['PAGE'] = array($pagenav => $iPages->show($pnstyle), 'COUNT' => $a['total'], 'TOTAL' => $iPages->totalpage, 'CURRENT' => $iPages->nowindex, 'PN' => $iPages->nowindex, 'NEXT' => $iPages->next_page()); iPHP::$iTPL->_iTPL_VARS['PAGES'] = $iPages; } return $iPages; }
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; }
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; }
/** * @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; }
public function ACTION_register() { iCMS::$config['user']['register']['enable'] or exit(iPHP::lang('user:register:forbidden')); $regip = iS::escapeStr(iPHP::getIp()); $regdate = time(); if (iCMS::$config['user']['register']['interval']) { $ip_regdate = iDB::value("\n SELECT `regdate`\n FROM `#iCMS@__user`\n WHERE `regip`='{$regip}'\n ORDER BY uid DESC"); $ip_regdate - $regdate > iCMS::$config['user']['register']['interval'] && iPHP::code(0, 'user:register:interval', 'username', 'json'); } $username = iS::escapeStr($_POST['username']); $nickname = iS::escapeStr($_POST['nickname']); $gender = $_POST['gender'] == 'girl' ? 0 : 1; $password = md5(trim($_POST['password'])); $rstpassword = md5(trim($_POST['rstpassword'])); $refer = iS::escapeStr($_POST['refer']); $openid = iS::escapeStr($_POST['openid']); $type = iS::escapeStr($_POST['platform']); $avatar = iS::escapeStr($_POST['avatar']); $province = iS::escapeStr($_POST['province']); $city = iS::escapeStr($_POST['city']); $agreement = $_POST['agreement']; $username or iPHP::code(0, 'user:register:username:empty', 'username', 'json'); preg_match("/^[\\w\\-\\.]+@[\\w\\-]+(\\.\\w+)+\$/i", $username) or iPHP::code(0, 'user:register:username:error', 'username', 'json'); user::check($username, 'username') && iPHP::code(0, 'user:register:username:exist', 'username', 'json'); $nickname or iPHP::code(0, 'user:register:nickname:empty', 'nickname', 'json'); (cstrlen($nickname) > 20 || cstrlen($nickname) < 4) && iPHP::code(0, 'user:register:nickname:error', 'nickname', 'json'); user::check($nickname, 'nickname') && iPHP::code(0, 'user:register:nickname:exist', 'nickname', 'json'); trim($_POST['password']) or iPHP::code(0, 'user:password:empty', 'password', 'json'); trim($_POST['rstpassword']) or iPHP::code(0, 'user:password:rst_empty', 'rstpassword', 'json'); $password == $rstpassword or iPHP::code(0, 'user:password:unequal', 'password', 'json'); if (iCMS::$config['user']['register']['seccode']) { $seccode = iS::escapeStr($_POST['seccode']); iPHP::seccode($seccode, true) or iPHP::code(0, 'iCMS:seccode:error', 'seccode', 'json'); } $gid = 0; $pid = 0; $fans = $follow = $article = $comments = $share = $credit = 0; $hits = $hits_today = $hits_yday = $hits_week = $hits_month = 0; $lastloginip = $lastlogintime = ''; $status = 1; $fields = array('gid', 'pid', 'username', 'nickname', 'password', 'gender', 'fans', 'follow', 'article', 'comments', 'share', 'credit', 'regip', 'regdate', 'lastloginip', 'lastlogintime', 'hits', 'hits_today', 'hits_yday', 'hits_week', 'hits_month', 'type', 'status'); $data = compact($fields); $uid = iDB::insert('user', $data); user::set_cookie($username, $password, array('uid' => $uid, 'username' => $username, 'nickname' => $nickname, 'status' => $status)); if ($openid) { $platform = $type; iDB::query("\n INSERT INTO `#iCMS@__user_openid`\n (`uid`, `openid`, `platform`)\n VALUES ('{$uid}', '{$openid}', '{$platform}');\n "); } if ($avatar) { $avatarData = iFS::remote($avatar); if ($avatarData) { $avatarpath = iFS::fp(get_user_pic($uid), '+iPATH'); iFS::mkdir(dirname($avatarpath)); iFS::write($avatarpath, $avatarData); iFS::yun_write($avatarpath); } } //user::set_cache($uid); iPHP::set_cookie('forward', '', -31536000); iPHP::json(array('code' => 1, 'forward' => $this->forward)); }
public function get_lite($C) { $C['iurl'] or $C['iurl'] = (array) iURL::get('category', $C); $category = array(); $category['name'] = $C['name']; $category['description'] = $C['description']; $category['subname'] = $C['subname']; $category['sname'] = $C['subname']; // $category['pic'] = $C['pic']; $category['navArray'] = $this->get_nav($C); $category['url'] = $C['iurl']['href']; $category['link'] = "<a href='{$C['url']}'>{$C['name']}</a>"; $category['pic'] = is_array($C['pic']) ? $C['pic'] : get_pic($C['pic']); $category['mpic'] = is_array($C['mpic']) ? $C['mpic'] : get_pic($C['mpic']); $category['spic'] = is_array($C['spic']) ? $C['spic'] : get_pic($C['spic']); if ($C['rootid']) { $_parent = iCache::get('iCMS/category/' . $C['rootid']); $category['parent'] = $this->get_lite($_parent); unset($_parent); } $category['nav'] = ''; krsort($category['navArray']); if ($category['navArray']) { foreach ($category['navArray'] as $key => $value) { $category['nav'] .= "<li><a href='{$value['href']}'>{$value['name']}</a><span class=\"divider\">" . iPHP::lang('iCMS:navTag') . "</span></li>"; } } return $category; }
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 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; }
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) { $pkey = intval($page - 1); $pageurl = $article['iurl']->pageurl; if ($article['chapter']) { $chapterArray = $art_data; $count = count($chapterArray); $adid = $chapterArray[$pkey]['id']; $art_data = iDB::row("SELECT body,subtitle FROM `#iCMS@__article_data` WHERE aid='" . (int) $article['id'] . "' AND id='" . (int) $adid . "' LIMIT 1;", ARRAY_A); } $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 (substr($art_data['body'], 0, 19) == '#--iCMS.Markdown--#') { // $art_data['body'] = iPHP::Markdown($art_data['body']); $art_data['body'] = substr($art_data['body'], 19); $article['markdown'] = ture; } if ($article['chapter']) { $article['body'] = $art_data['body']; } else { $body = explode('#--iCMS.PageBreak--#', $art_data['body']); $count = count($body); $article['body'] = $body[$pkey]; } $total = $count + intval(iCMS::$config['article']['pageno_incr']); $article['body'] = $this->keywords($article['body']); $article['body'] = $this->taoke($article['body']); $article['taoke'] = $this->taoke; $article['subtitle'] = $art_data['subtitle']; unset($body, $art_data); $pageArray = array(); if ($total > 1) { iPHP::loadClass("Pages"); $_GLOBALS_iPage = $GLOBALS['iPage']; $category['mode'] && iCMS::set_html_url($article['iurl']); $pageconf = array('page_name' => 'p', 'url' => $pageurl, 'total' => $total, 'perpage' => 1, 'nowindex' => (int) $_GET['p'], 'lang' => iPHP::lang(iPHP_APP . ':page')); if ($article['chapter']) { foreach ((array) $chapterArray as $key => $value) { $pageconf['titles'][$key + 1] = $value['subtitle']; } } $iPages = new iPages($pageconf); unset($GLOBALS['iPage']); $GLOBALS['iPage'] = $_GLOBALS_iPage; unset($_GLOBALS_iPage); $pageArray['list'] = $iPages->list_page(); $pageArray['index'] = $iPages->first_page('array'); $pageArray['prev'] = $iPages->prev_page('array'); $pageArray['next'] = $iPages->next_page('array'); $pageArray['endof'] = $iPages->last_page('array'); $pagenav = $iPages->show(0); $pagetext = $iPages->show(10); } $article['page'] = array('pn' => $page, 'total' => $total, 'count' => $count, 'current' => $page, 'nav' => $pagenav, 'pageurl' => $pageurl, 'text' => $pagetext, 'PAGES' => $iPages, 'args' => iS::escapeStr($_GET['pageargs']), 'first' => $page == "1" ? true : false, 'last' => $page == $count ? true : false, 'end' => $page == $total ? true : false) + $pageArray; $next_url = $pageArray['next']['url']; unset($pagenav, $pagetext, $iPages, $pageArray); 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['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] = $tag; $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; }
public static function pagenav($total, $displaypg = 20, $unit = "条记录", $url = '', $target = '') { iPHP::loadClass("Pages"); $pageconf = array('url' => $url, 'target' => $target, 'total' => $total, 'perpage' => $displaypg, 'total_type' => 'G', 'lang' => iPHP::lang(iPHP_APP . ':page')); $pageconf['lang']['format_left'] = '<li>'; $pageconf['lang']['format_right'] = '</li>'; $iPages = new iPages($pageconf); self::$offset = $iPages->offset; self::$pagenav = '<ul>' . (self::$pagenav .= $iPages->show(3)); self::$pagenav .= "<li> <span class=\"muted\">{$total}{$unit} {$displaypg}{$unit}/页 共{$iPages->totalpage}页</span></li>"; if ($iPages->totalpage > 200) { $url = $iPages->get_url(1); self::$pagenav .= "<li> <span class=\"muted\">跳到 <input type=\"text\" id=\"pageselect\" style=\"width:24px;height:12px;margin-bottom: 0px;line-height: 12px;\" /> 页 <input class=\"btn btn-small\" type=\"button\" onClick=\"window.location='{$url}&page='+\$('#pageselect').val();\" value=\"跳转\" style=\"height: 22px;line-height: 18px;\"/></span></li>"; } else { self::$pagenav .= "<li> <span class=\"muted\">跳到" . $iPages->select() . "页</span></li>"; } self::$pagenav .= '</ul>'; }