public function API_goto() { $appid = (int) $_GET['appid']; $iid = (int) $_GET['iid']; $_GET = iS::escapeStr($_GET); iPHP::import(iPHP_APP_CORE . '/iAPP.class.php'); $url = app::get_url($appid, $iid); iPHP::gotourl($url); }
function do_del($id = null, $dialog = true) { $id === null && ($id = $this->id); $id or iPHP::alert('请选择要删除的评论!'); $comment = iDB::row("SELECT * FROM `#iCMS@__comment` WHERE `id`='{$id}' LIMIT 1"); iPHP::import(iPHP_APP_CORE . '/iAPP.class.php'); $table = app::get_table($comment->appid); iDB::query("UPDATE {$table['name']} SET comments = comments-1 WHERE `comments`>0 AND `{$table['primary']}`='{$comment->iid}' LIMIT 1;"); iDB::query("UPDATE `#iCMS@__user` SET comments = comments-1 WHERE `comments`>0 AND `uid`='{$comment->userid}' LIMIT 1;"); iDB::query("DELETE FROM `#iCMS@__comment` WHERE `id` = '{$id}';"); $dialog && iPHP::success('评论删除完成', 'js:parent.$("#id-' . $id . '").remove();'); }
public static function yun($vendor = null) { if ($vendor === null) { return false; } $conf = self::$config['sdk'][$vendor]; if ($conf['AccessKey'] && $conf['SecretKey']) { iPHP::import(iPHP_LIB . '/' . $vendor . '.php'); return new $vendor($conf['AccessKey'], $conf['SecretKey'], $conf['AppId']); } else { return false; } }
public static function match($html, $data, $rule) { $match_hash = array(); if ($data['dom']) { iPHP::import(iPHP_LIB . '/phpQuery.php'); spider::$dataTest && $_GET['pq_debug'] && (phpQuery::$debug = 1); $doc = phpQuery::newDocumentHTML($html, 'UTF-8'); if (strpos($data['rule'], '@') !== false) { list($content_dom, $content_attr) = explode("@", $data['rule']); $content_fun = 'attr'; } else { list($content_dom, $content_fun, $content_attr) = explode("\n", $data['rule']); } $content_dom = trim($content_dom); $content_fun = trim($content_fun); $content_attr = trim($content_attr); $content_fun or $content_fun = 'html'; if ($data['multi']) { $conArray = array(); $_content = null; foreach ($doc[$content_dom] as $doc_key => $doc_value) { if ($content_attr) { $_content = phpQuery::pq($doc_value)->{$content_fun}($content_attr); } else { $_content = phpQuery::pq($doc_value)->{$content_fun}(); } $cmd5 = md5($_content); if ($match_hash[$cmd5]) { break; } $conArray[$doc_key] = $_content; $match_hash[$cmd5] = true; } if (spider::$dataTest) { echo "<b>多条匹配结果:</b><pre>"; print_r($match_hash); echo "</pre><hr />"; } $content = implode('#--iCMS.PageBreak--#', $conArray); unset($conArray, $_content, $match_hash); } else { if ($content_attr) { $content = $doc[$content_dom]->{$content_fun}($content_attr); } else { $content = $doc[$content_dom]->{$content_fun}(); } } phpQuery::unloadDocuments($doc->getDocumentID()); unset($doc); } else { if (trim($data['rule']) == '<%content%>') { $content = $html; } else { $data_rule = spiderTools::pregTag($data['rule']); if (preg_match('/(<\\w+>|\\.\\*|\\.\\+|\\\\d|\\\\w)/i', $data_rule)) { if ($data['multi']) { preg_match_all('|' . $data_rule . '|is', $html, $matches, PREG_SET_ORDER); $conArray = array(); foreach ((array) $matches as $mkey => $mat) { $cmd5 = md5($mat['content']); if ($match_hash[$cmd5]) { break; } $conArray[$mkey] = $mat['content']; $match_hash[$cmd5] = true; } if (spider::$dataTest) { echo "<b>多条匹配结果:</b><pre>"; print_r($match_hash); echo "</pre><hr />"; } $content = implode('#--iCMS.PageBreak--#', $conArray); unset($conArray, $match_hash); } else { preg_match('|' . $data_rule . '|is', $html, $matches, $PREG_SET_ORDER); $content = $matches['content']; } } else { $content = $data_rule; } } } return $content; }
public static function TBAPI() { iPHP::import(iPHP_APP_CORE . '/tbapi.class.php'); if (isset($GLOBALS['TBAPI'])) { return $GLOBALS['TBAPI']; } $GLOBALS['TBAPI'] = new TBAPI(); return $GLOBALS['TBAPI']; }
/** * @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; }
private function __action_manage_comment() { $act = iS::escapeStr($_POST['act']); if ($act == "del") { $id = (int) $_POST['id']; $id or iPHP::code(0, 'iCMS:error', 0, 'json'); $comment = iDB::row("SELECT `appid`,`iid` FROM `#iCMS@__comment` WHERE `userid` = '" . user::$userid . "' AND `id`='{$id}' LIMIT 1;"); iPHP::import(iPHP_APP_CORE . '/iAPP.class.php'); $table = app::get_table($comment->appid); iDB::query("\n UPDATE {$table['name']}\n SET comments = comments-1\n WHERE `comments`>0\n AND `{$table['primary']}`='{$comment->iid}'\n LIMIT 1;\n "); iDB::query("\n DELETE FROM `#iCMS@__comment`\n WHERE `userid` = '" . user::$userid . "'\n AND `id`='{$id}' LIMIT 1;\n "); user::update_count(user::$userid, 1, 'comments', '-'); iPHP::code(1, 0, 0, 'json'); } }
function do_save($callback = false) { $aid = (int) $_POST['aid']; $cid = (int) $_POST['cid']; $userid = (int) $_POST['userid']; $scid = implode(',', (array) $_POST['scid']); $pid = implode(',', (array) $_POST['pid']); $status = (int) $_POST['status']; $chapter = (int) $_POST['chapter']; $ordernum = _int($_POST['ordernum']); $_cid = iS::escapeStr($_POST['_cid']); $_pid = iS::escapeStr($_POST['_pid']); $_scid = iS::escapeStr($_POST['_scid']); $_tags = iS::escapeStr($_POST['_tags']); $title = iS::escapeStr($_POST['title']); $stitle = iS::escapeStr($_POST['stitle']); $pic = iS::escapeStr($_POST['pic']); $mpic = iS::escapeStr($_POST['mpic']); $spic = iS::escapeStr($_POST['spic']); $source = iS::escapeStr($_POST['source']); $author = iS::escapeStr($_POST['author']); $editor = iS::escapeStr($_POST['editor']); $description = iS::escapeStr($_POST['description']); $keywords = iS::escapeStr($_POST['keywords']); $tags = str_replace(',', ',', iS::escapeStr($_POST['tags'])); $clink = iS::escapeStr($_POST['clink']); $url = iS::escapeStr($_POST['url']); $tpl = iS::escapeStr($_POST['tpl']); $metadata = iS::escapeStr($_POST['metadata']); $metadata = $metadata ? addslashes(serialize($metadata)) : ''; $body = (array) $_POST['body']; $creative = (int) $_POST['creative']; iACP::CP($cid, $aid ? 'ce' : 'ca', 'alert'); empty($_POST['pubdate']) && ($_POST['pubdate'] = get_date(0, 'Y-m-d H:i:s')); $pubdate = iPHP::str2time($_POST['pubdate']); $weight = _int($_POST['weight']); $postype = $_POST['postype'] ? $_POST['postype'] : 0; $ischapter = isset($_POST['ischapter']) ? 1 : 0; isset($_POST['inbox']) && ($status = "0"); $tags && ($tags = preg_replace('/<[\\/\\!]*?[^<>]*?>/is', '', $tags)); empty($title) && iPHP::alert('标题不能为空!'); empty($cid) && iPHP::alert('请选择所属栏目'); empty($body) && empty($url) && iPHP::alert('文章内容不能为空!'); $userid or $userid = iMember::$userid; iFS::$userid = $userid; if (empty($aid) && iCMS::$config['publish']['repeatitle']) { articleTable::check_title($title) && iPHP::alert('该标题的文章已经存在!请检查是否重复'); } if (strstr($this->category[$cid]['contentRule'], '{LINK}') !== false) { empty($clink) && ($clink = strtolower(pinyin($title))); if (empty($aid) && $clink) { articleTable::check_clink($clink) && iPHP::alert('该文章自定义链接已经存在!请检查是否重复'); } } if (empty($description) && empty($url)) { $description = $this->autodesc($body); } stripos($pic, 'http://') === false or $pic = iFS::http($pic); stripos($mpic, 'http://') === false or $mpic = iFS::http($mpic); stripos($spic, 'http://') === false or $spic = iFS::http($spic); $haspic = empty($pic) ? 0 : 1; $SELFURL = __SELF__ . $_POST['REFERER']; if (empty($_POST['REFERER']) || strstr($_POST['REFERER'], '=save')) { $SELFURL = __SELF__ . '?app=article&do=manage'; } $editor or $editor = empty(iMember::$data->nickname) ? iMember::$data->username : iMember::$data->nickname; // if($aid && $ischapter){ // $this->article_data($body,$aid); // iDB::query("UPDATE `#iCMS@__article` SET `chapter`=chapter+1 WHERE `id` = '$aid'"); // iPHP::success('章节添加完成!','url:'.$SELFURL); // } iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); $picdata = ''; $ucid = 0; $fields = articleTable::fields($aid); if (empty($aid)) { $postime = $pubdate; $hits = 0; $good = $bad = $comments = 0; $ischapter && ($chapter = 1); $mobile = 0; $aid = articleTable::insert(compact($fields)); if ($this->callback['primary']) { $PCB = $this->callback['primary']; $handler = $PCB[0]; $params = (array) $PCB[1] + array('indexid' => $aid); if (is_callable($handler)) { call_user_func_array($handler, $params); } } if ($tags) { iPHP::app('tag.class', 'static'); tag::add($tags, $userid, $aid, $cid); //articleTable::update(compact('tags'),array('id'=>$aid)); } map::init('prop', $this->appid); $pid && map::add($pid, $aid); map::init('category', $this->appid); map::add($cid, $aid); $scid && map::add($scid, $aid); $tagArray && tag::map_iid($tagArray, $aid); $url or $this->article_data($body, $aid, $haspic); $this->categoryApp->update_count_one($cid); $article_url = iURL::get('article', array(array('id' => $aid, 'url' => $url, 'cid' => $cid, 'pubdate' => $pubdate), $this->category[$cid]))->href; if ($status && iCMS::$config['api']['baidu']['sitemap']['sync']) { baidu_ping($article_url); } if ($callback) { return array("code" => $callback, 'indexid' => $aid); } $moreBtn = array(array("text" => "查看该文章", "target" => '_blank', "url" => $article_url, "o" => 'target="_blank"'), array("text" => "编辑该文章", "url" => APP_URI . "&do=add&id=" . $aid), array("text" => "继续添加文章", "url" => APP_URI . "&do=add&cid=" . $cid), array("text" => "返回文章列表", "url" => $SELFURL), array("text" => "查看网站首页", "url" => iCMS_URL, "target" => '_blank')); iPHP::$dialog['lock'] = true; iPHP::dialog('success:#:check:#:文章添加完成!<br />10秒后返回文章列表', 'url:' . $SELFURL, 10, $moreBtn); } else { if ($tags) { iPHP::app('tag.class', 'static'); tag::diff($tags, $_tags, iMember::$userid, $aid, $cid); } $picdata = $this->picdata($pic, $mpic, $spic); articleTable::update(compact($fields), array('id' => $aid)); if ($this->callback['primary']) { $PCB = $this->callback['primary']; $handler = $PCB[0]; $params = (array) $PCB[1] + array('indexid' => $aid); if (is_callable($handler)) { call_user_func_array($handler, $params); } } map::init('prop', $this->appid); map::diff($pid, $_pid, $aid); map::init('category', $this->appid); map::diff($cid, $_cid, $aid); map::diff($scid, $_scid, $aid); $url or $this->article_data($body, $aid, $haspic); //$ischapter && $this->chapter_count($aid); if ($_cid != $cid) { $this->categoryApp->update_count_one($_cid, '-'); $this->categoryApp->update_count_one($cid); } if ($callback) { return array("code" => $callback, 'indexid' => $aid); } // if(!strstr($this->category[$cid]['contentRule'],'{PHP}')&&!$this->category[$cid]['url']&&$this->category[$cid]['mode']=="1" && $status) { // $htmlApp = iACP::app('html'); // $htmlApp->Article($aid); // } iPHP::success('文章编辑完成!<br />3秒后返回文章列表', 'url:' . $SELFURL); } }
<?php /** * iCMS - i Content Management System * Copyright (c) 2007-2012 idreamsoft.com iiimon Inc. All rights reserved. * * @author coolmoo <*****@*****.**> * @site http://www.idreamsoft.com * @licence http://www.idreamsoft.com/license.php * @version 6.0.0 * @$Id: spider.app.php 634 2013-04-03 06:02:53Z coolmoo $ */ defined('iPHP') or exit('What are you doing?'); iPHP::import(iPHP_APP_CORE . '/iSpider.class.php'); iPHP::import(iPHP_APP_CORE . '/iSpider.Tools.php'); iPHP::import(iPHP_APP_CORE . '/iSpider.Content.php'); iPHP::import(iPHP_APP_CORE . '/iSpider.Urls.php'); iPHP::import(iPHP_APP_CORE . '/iSpider.Data.php');
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; }
<?php /** * iCMS - i Content Management System * Copyright (c) 2007-2012 idreamsoft.com iiimon Inc. All rights reserved. * * @author coolmoo <*****@*****.**> * @site http://www.idreamsoft.com * @licence http://www.idreamsoft.com/license.php * @version 6.0.0 * @$Id: spider.app.php 156 2013-03-22 13:40:07Z coolmoo $ */ defined('iPHP') or exit('What are you doing?'); iPHP::import(iPHP_APP_CORE . '/iSpider.Autoload.php'); class spiderApp { function __construct() { spider::$cid = $this->cid = (int) $_GET['cid']; spider::$rid = $this->rid = (int) $_GET['rid']; spider::$pid = $this->pid = (int) $_GET['pid']; spider::$sid = $this->sid = (int) $_GET['sid']; spider::$title = $this->title = $_GET['title']; spider::$url = $this->url = $_GET['url']; spider::$work = $this->work = false; $this->poid = (int) $_GET['poid']; } function do_update() { if ($this->sid) { $data = iACP::fields($_GET['iDT']);
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; }
public static function check_content_code($content) { if (spider::$content_right_code) { if (strpos(spider::$content_right_code, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($content, 'UTF-8'); $pq_dom = str_replace('DOM::', '', spider::$content_right_code); $matches = (bool) (string) phpQuery::pq($pq_dom); phpQuery::unloadDocuments($doc->getDocumentID()); unset($doc, $content); } else { $matches = strpos($content, spider::$content_right_code); unset($content); } if ($matches === false) { return false; } } if (spider::$content_error_code) { if (strpos(spider::$content_error_code, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($content, 'UTF-8'); $pq_dom = str_replace('DOM::', '', spider::$content_error_code); $_matches = (bool) (string) phpQuery::pq($pq_dom); phpQuery::unloadDocuments($doc->getDocumentID()); unset($doc, $content); } else { $_matches = strpos($content, spider::$content_error_code); unset($content); } if ($_matches !== false) { return false; } } return true; }
function check_content_code($content) { if ($this->content_right_code) { if (strpos($this->content_right_code, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($content, 'UTF-8'); $pq_dom = str_replace('DOM::', '', $this->content_right_code); $matches = (bool) (string) phpQuery::pq($pq_dom); } else { $matches = strpos($content, $this->content_right_code); } if ($matches === false) { $match = false; return false; } } if ($this->content_error_code) { if (strpos($this->content_right_code, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($content, 'UTF-8'); $pq_dom = str_replace('DOM::', '', $this->content_right_code); $_matches = (bool) (string) phpQuery::pq($pq_dom); } else { $_matches = strpos($content, $this->content_error_code); } if ($_matches !== false) { $match = false; return false; } } $match = true; return compact('content', 'match'); }
public static function crawl($work = NULL, $pid = NULL, $_rid = NULL, $_urls = null, $callback = null) { $pid === NULL && ($pid = spider::$pid); if ($pid) { $project = spider::project($pid); $cid = $project['cid']; $rid = $project['rid']; $prule_list_url = $project['list_url']; $lastupdate = $project['lastupdate']; } else { $cid = spider::$cid; $rid = spider::$rid; } if (empty($rid) && $_rid !== NULL) { $rid = $_rid; } if ($work == 'shell') { $lastupdate = $project['lastupdate']; if ($project['psleep']) { if (time() - $lastupdate < $project['psleep']) { echo '采集方案[' . $pid . "]:" . format_date($lastupdate) . "刚采集过了,请" . $project['psleep'] / 3600 . "小时后在继续采集\n"; return; } } echo "[32m开始采集方案[" . $pid . "] 采集规则[" . $rid . "][0m\n"; } $ruleA = spider::rule($rid); $rule = $ruleA['rule']; $urls = $rule['list_urls']; $project['urls'] && ($urls = $project['urls']); spiderUrls::$urls && ($urls = spiderUrls::$urls); $_urls && ($urls = $_urls); $urlsArray = explode("\n", $urls); $urlsArray = array_filter($urlsArray); $_urlsArray = $urlsArray; $urlsList = array(); if ($work == 'shell') { // echo "$urls\n"; print_r($urlsArray); } foreach ($_urlsArray as $_key => $_url) { $_url = htmlspecialchars_decode($_url); $_urlsList = array(); /** * RULE@rid@url * url使用[rid]规则采集并返回列表结果 */ if (strpos($_url, 'RULE@') !== false) { list($___s, $_rid, $_urls) = explode('@', $_url); if (spider::$ruleTest) { print_r('<b>使用[rid:' . $_rid . ']规则抓取列表</b>:' . $_urls); echo "<hr />"; } $_urlsList = spiderUrls::crawl($work, false, $_rid, $_urls, 'CALLBACK@URL'); $urlsList = array_merge($urlsList, $_urlsList); unset($urlsArray[$_key]); } else { preg_match('|.*<(.*)>.*|is', $_url, $_matches); if ($_matches) { list($format, $begin, $num, $step, $zeroize, $reverse) = explode(',', $_matches[1]); $url = str_replace($_matches[1], '*', trim($_matches[0])); $_urlsList = spiderTools::mkurls($url, $format, $begin, $num, $step, $zeroize, $reverse); unset($urlsArray[$_key]); $urlsList = array_merge($urlsList, $_urlsList); } } } $urlsList && ($urlsArray = array_merge($urlsArray, $urlsList)); unset($_urlsArray, $_key, $_url, $_matches, $_urlsList, $urlsList); $urlsArray = array_unique($urlsArray); // spider::$useragent = $rule['user_agent']; // spider::$encoding = $rule['curl']['encoding']; // spider::$referer = $rule['curl']['referer']; // spider::$charset = $rule['charset']; if (empty($urlsArray)) { if ($work == 'shell') { echo "采集列表为空!请填写!\n"; return false; } iPHP::alert('采集列表为空!请填写!', 'js:parent.window.iCMS_MODAL.destroy();'); } // if(spider::$ruleTest){ // echo "<pre>"; // print_r(iS::escapeStr($project)); // print_r(iS::escapeStr($rule)); // echo "</pre>"; // echo "<hr />"; // } if ($rule['mode'] == "2") { iPHP::import(iPHP_LIB . '/phpQuery.php'); spider::$ruleTest && $_GET['pq_debug'] && (phpQuery::$debug = 1); } $pubArray = array(); $pubCount = array(); $pubAllCount = array(); spider::$curl_proxy = $rule['proxy']; spider::$urlslast = null; foreach ($urlsArray as $key => $url) { $url = trim($url); spider::$urlslast = $url; if ($work == 'shell') { echo '开始采集列表:' . $url . "\n"; } if (spider::$ruleTest) { echo '<b>抓取列表:</b>' . $url . "<br />"; } $html = spiderTools::remote($url); if (empty($html)) { continue; } if ($rule['mode'] == "2") { $doc = phpQuery::newDocumentHTML($html, 'UTF-8'); $list_area = $doc[trim($rule['list_area_rule'])]; // if(strpos($rule['list_area_format'], 'DOM::')!==false){ // $list_area = spiderTools::dataClean($rule['list_area_format'], $list_area); // } if ($rule['list_area_format']) { $list_area_format = trim($rule['list_area_format']); if (strpos($list_area_format, 'ARRAY::') !== false) { $list_area_format = str_replace('ARRAY::', '', $list_area_format); $lists = array(); foreach ($list_area as $la_key => $la) { $lists[] = phpQuery::pq($list_area_format, $la); } } else { $lists = phpQuery::pq($list_area_format, $list_area); } } else { $lists = $list_area; } // $lists = $list_area; //echo 'list:getDocumentID:'.$lists->getDocumentID()."\n"; } else { $list_area_rule = spiderTools::pregTag($rule['list_area_rule']); if ($list_area_rule) { preg_match('|' . $list_area_rule . '|is', $html, $matches, $PREG_SET_ORDER); $list_area = $matches['content']; } else { $list_area = $html; } $html = null; unset($html); if (spider::$ruleTest) { echo iS::escapeStr($rule['list_area_rule']); // echo iS::escapeStr($list_area); echo "<hr />"; } if ($rule['list_area_format']) { $list_area = spiderTools::dataClean($rule['list_area_format'], $list_area); } preg_match_all('|' . spiderTools::pregTag($rule['list_url_rule']) . '|is', $list_area, $lists, PREG_SET_ORDER); $list_area = null; unset($list_area); if ($rule['sort'] == "1") { //arsort($lists); } elseif ($rule['sort'] == "2") { asort($lists); } elseif ($rule['sort'] == "3") { shuffle($lists); } } if (spider::$ruleTest) { echo '<b>列表区域规则:</b>' . iS::escapeStr($rule['list_area_rule']); echo "<hr />"; echo '<b>列表区域抓取结果:</b>' . iS::escapeStr($list_area); echo "<hr />"; echo '<b>列表链接规则:</b>' . iS::escapeStr($rule['list_url_rule']); echo "<hr />"; echo '<b>网址合成规则:</b>' . iS::escapeStr($rule['list_url']); echo "<hr />"; } if ($prule_list_url) { $rule['list_url'] = $prule_list_url; } //PID@xx 返回URL列表 if ($callback == 'CALLBACK@URL') { $cbListUrl = array(); foreach ($lists as $lkey => $row) { list(spider::$title, spider::$url) = spiderTools::title_url($row, $rule, $url); if (spider::$url === false) { continue; } // if(spider::checker($work)===true){ $cbListUrl[] = spider::$url; // } } return $cbListUrl; } if ($work == "shell") { $pubCount[$url]['count'] = count($lists); $pubAllCount['count'] += $pubCount[$url]['count']; echo "开始采集:" . $url . " 列表 " . $pubCount[$url]['count'] . "条记录\n"; foreach ($lists as $lkey => $row) { list(spider::$title, spider::$url) = spiderTools::title_url($row, $rule, $url); if (spider::$url === false) { continue; } $hash = md5(spider::$url); echo "title:" . spider::$title . "\n"; echo "url:" . spider::$url . "\n"; spider::$rid = $rid; $checker = spider::checker($work); if ($checker === true) { echo "开始采集...."; $callback = spider::publish("shell"); if ($callback['code'] == "1001") { $pubCount[$url]['success']++; $pubAllCount['success']++; echo "....√\n"; if ($project['sleep']) { echo "sleep:" . $project['sleep'] . "s\n"; if ($rule['mode'] != "2") { unset($lists[$lkey]); } gc_collect_cycles(); sleep($project['sleep']); } else { //sleep(1); } } else { $pubCount[$url]['error']++; $pubAllCount['error']++; echo "error\n\n"; continue; } } $pubCount[$url]['published']++; $pubAllCount['published']++; } if ($rule['mode'] == "2") { phpQuery::unloadDocuments($doc->getDocumentID()); } else { unset($lists); } } if ($work == "WEB@MANUAL") { $listsArray[$url] = $lists; } if ($work == "WEB@AUTO" || $work == 'DATA@RULE') { foreach ($lists as $lkey => $row) { list(spider::$title, spider::$url) = spiderTools::title_url($row, $rule, $url); if (spider::$url === false) { continue; } $hash = md5(spider::$url); if (spider::$ruleTest) { echo '<b>列表抓取结果:</b>' . $lkey . '<br />'; echo spider::$title . ' (<a href="' . APP_URI . '&do=testdata' . '&url=' . urlencode(spider::$url) . '&rid=' . $rid . '&pid=' . $pid . '&title=' . urlencode(spider::$title) . '" target="_blank">测试内容规则</a>) <br />'; echo spider::$url . "<br />"; echo $hash . "<br /><hr />"; } else { if (spider::checker($work) === true || spider::$dataTest) { $suData = array('sid' => 0, 'url' => spider::$url, 'title' => spider::$title, 'cid' => $cid, 'rid' => $rid, 'pid' => $pid, 'hash' => $hash); switch ($work) { case 'DATA@RULE': $contentArray[$lkey] = spiderData::crawl(); // $contentArray[$lkey] = spiderUrls::crawl($work,$_pid); unset($suData['sid']); $suData['title'] = addslashes($suData['title']); $suData += array('addtime' => time(), 'status' => '2', 'publish' => '2', 'indexid' => '0', 'pubdate' => '0'); spider::$dataTest or $suid = iDB::insert('spider_url', $suData); $contentArray[$lkey]['spider_url'] = $suid; break; case 'WEB@AUTO': $pubArray[] = $suData; break; } } } } } } $lists = null; unset($lists); gc_collect_cycles(); switch ($work) { case 'WEB@AUTO': return $pubArray; break; case 'DATA@RULE': return $contentArray; break; case 'WEB@MANUAL': return array('cid' => $cid, 'rid' => $rid, 'pid' => $pid, 'sid' => $sid, 'work' => $work, 'rule' => $rule, 'listsArray' => $listsArray); break; case "shell": echo "采集数据统结果:\n"; print_r($pubCount); print_r($pubAllCount); echo "全部采集完成....\n"; iDB::update('spider_project', array('lastupdate' => time()), array('id' => $pid)); break; } }
function do_app($dialog = true) { iPHP::import(iPHP_APP_CORE . '/iAPP.class.php'); app::cache(); }
function do_batch() { $idA = (array) $_POST['id']; $idA or iPHP::alert("请选择要操作的用户"); $ids = implode(',', (array) $_POST['id']); $batch = $_POST['batch']; switch ($batch) { case 'prop': iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('prop', iCMS_APP_USER); $pid = implode(',', (array) $_POST['pid']); foreach ((array) $_POST['id'] as $id) { $_pid = iDB::value("SELECT `pid` FROM `#iCMS@__user` where `uid`='{$id}' LIMIT 1"); iDB::update('user', compact('pid'), array('uid' => $id)); map::diff($pid, $_pid, $id); } iPHP::success('用户属性设置完成!', 'js:1'); break; case 'dels': iPHP::$break = false; foreach ($idA as $id) { $this->do_del($id, false); } iPHP::$break = true; iPHP::success('用户全部删除完成!', 'js:1'); break; } }
public static function app($app = NULL, $arg = NULL) { iPHP::import(ACP_PATH . '/' . $app . '.app.php'); if ($arg === 'import' || $arg === 'static') { return; } $appName = $app . 'App'; if ($arg !== NULL) { return new $appName($arg); } return new $appName(); }
public static function yun($frp, $provider = 'QiNiu') { iPHP::import(iPHP_LIB . '/QiniuClient.php'); $client = new QiniuClient(self::$config['yun'][$provider]['AccessKey'], self::$config['yun'][$provider]['SecretKey']); $fp = ltrim(self::fp($frp, '-iPATH'), '/'); $res = $client->uploadFile($frp, self::$config['yun'][$provider]['Bucket'], $fp); $res = json_decode($res, true); if ($res['error']) { return self::_error(array('code' => 0, 'state' => 'Error')); } return true; }
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); }
<?php /** * iCMS - i Content Management System * Copyright (c) 2007-2012 idreamsoft.com iiimon Inc. All rights reserved. * * @author coolmoo <*****@*****.**> * @site http://www.idreamsoft.com * @licence http://www.idreamsoft.com/license.php * @version 6.0.0 * @$Id: patch.app.php 1665 2013-06-21 05:57:53Z coolmoo $ */ defined('iPHP') or exit('What are you doing?'); iPHP::import(iPHP_APP_CORE . '/iPatch.class.php'); class patchApp { function __construct() { $this->msg = ""; $this->patch = iPatch::init(isset($_GET['force']) ? true : false); } function do_check() { if (empty($this->patch)) { if ($_GET['ajax']) { iPHP::json(array('code' => 0)); } else { iPHP::success("您使用的 iCMS 版本,目前是最新版本<hr />当前版本:iCMS " . iCMS_VER . " [" . iCMS_RELEASE . "]", 0, "5"); } } else { switch (iCMS::$config['system']['patch']) {
function do_batch() { $idArray = (array) $_POST['id']; $idArray or iPHP::alert("请选择要操作的标签"); $ids = implode(',', $idArray); $batch = $_POST['batch']; switch ($batch) { case 'dels': iPHP::$break = false; foreach ($idArray as $id) { $this->do_del($id, false); } iPHP::$break = true; iPHP::success('标签全部删除完成!', 'js:1'); break; case 'move': $_POST['cid'] or iPHP::alert("请选择目标栏目!"); iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('category', $this->appid); $cid = (int) $_POST['cid']; foreach ($idArray as $id) { $_cid = iDB::value("SELECT `cid` FROM `#iCMS@__tags` where `id` ='{$id}'"); iDB::update("tags", compact('cid'), compact('id')); if ($_cid != $cid) { map::diff($cid, $_cid, $id); $this->categoryApp->update_count_one($_cid, '-'); $this->categoryApp->update_count_one($cid); } } iPHP::success('成功移动到目标栏目!', 'js:1'); break; case 'mvtcid': $_POST['tcid'] or iPHP::alert("请选择目标分类!"); iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('category', $this->appid); $tcid = (int) $_POST['tcid']; foreach ($idArray as $id) { $_tcid = iDB::value("SELECT `tcid` FROM `#iCMS@__tags` where `id` ='{$id}'"); iDB::update("tags", compact('tcid'), compact('id')); if ($_tcid != $tcid) { map::diff($tcid, $_tcid, $id); $this->categoryApp->update_count_one($_tcid, '-'); $this->categoryApp->update_count_one($tcid); } } iPHP::success('成功移动到目标分类!', 'js:1'); break; case 'prop': iPHP::import(iPHP_APP_CORE . '/iMAP.class.php'); map::init('prop', $this->appid); $pid = implode(',', (array) $_POST['pid']); foreach ((array) $_POST['id'] as $id) { $_pid = iDB::value("SELECT pid FROM `#iCMS@__tags` WHERE `id`='{$id}'"); iDB::update("tags", compact('pid'), compact('id')); map::diff($pid, $_pid, $id); } iPHP::success('属性设置完成!', 'js:1'); break; case 'weight': $weight = _int($_POST['mweight']); $sql = "`weight` = '{$weight}'"; break; case 'tpl': $tpl = iS::escapeStr($_POST['mtpl']); $sql = "`tpl` = '{$tpl}'"; break; case 'keyword': if ($_POST['pattern'] == 'replace') { $sql = "`keywords` = '" . iS::escapeStr($_POST['mkeyword']) . "'"; } elseif ($_POST['pattern'] == 'addto') { foreach ($idArray as $id) { $keywords = iDB::value("SELECT keywords FROM `#iCMS@__tags` WHERE `id`='{$id}'"); $sql = "`keywords` = '" . ($keywords ? $keywords . ',' . iS::escapeStr($_POST['mkeyword']) : iS::escapeStr($_POST['mkeyword'])) . "'"; iDB::query("UPDATE `#iCMS@__tags` SET {$sql} WHERE `id`='{$id}'"); } iPHP::success('关键字更改完成!', 'js:1'); } break; case 'tag': if ($_POST['pattern'] == 'replace') { $sql = "`related` = '" . iS::escapeStr($_POST['mtag']) . "'"; } elseif ($_POST['pattern'] == 'addto') { foreach ($idArray as $id) { $keywords = iDB::value("SELECT related FROM `#iCMS@__tags` WHERE `id`='{$id}'"); $sql = "`related` = '" . ($keywords ? $keywords . ',' . iS::escapeStr($_POST['mtag']) : iS::escapeStr($_POST['mtag'])) . "'"; iDB::query("UPDATE `#iCMS@__tags` SET {$sql} WHERE `id`='{$id}'"); } iPHP::success('相关标签更改完成!', 'js:1'); } break; default: if (strpos($batch, ':')) { $data = iACP::fields($batch); foreach ($idArray as $id) { $data && iDB::update("tags", $data, array('id' => $id)); } iPHP::success('操作成功!', 'js:1'); } else { iPHP::alert('请选择要操作项!', 'js:1'); } } $sql && iDB::query("UPDATE `#iCMS@__tags` SET {$sql} WHERE `id` IN ({$ids})"); iPHP::success('操作成功!', 'js:1'); }
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; }