/** * 抓取资源 * @param [string] $html [抓取结果] * @param [array] $data [数据项] * @param [array] $rule [规则] * @param [array] $responses [已经抓取资源] * @return [array] [返回处理结果] */ public static function crawl($html, $data, $rule, $responses) { if (trim($data['rule']) === '') { return; } $name = $data['name']; if (spider::$dataTest) { print_r('<b>[' . $name . ']规则:</b>' . iS::escapeStr($data['rule'])); echo "<hr />"; } if (strpos($data['rule'], 'RULE@') !== false) { spider::$rid = str_replace('RULE@', '', $data['rule']); $_urls = trim($html); if (spider::$dataTest) { print_r('<b>使用[rid:' . spider::$rid . ']规则抓取</b>:' . $_urls); echo "<hr />"; } return spiderUrls::crawl('DATA@RULE', false, spider::$rid, $_urls); } /** * RAND@10,0 * 返回随机数 */ if (strpos($data['rule'], 'RAND@') !== false) { $random = str_replace('RAND@', '', $data['rule']); list($length, $numeric) = explode(',', $random); return random($length, empty($numeric) ? 0 : 1); } $contentArray = array(); $contentHash = array(); $_content = null; $_content = spiderContent::match($html, $data, $rule); $cmd5 = md5($_content); $contentArray[] = $_content; $contentHash[$cmd5] = true; if ($data['page']) { if (empty($rule['page_url'])) { $rule['page_url'] = $rule['list_url']; } if (empty(spider::$allHtml)) { $page_url_array = array(); $page_area_rule = trim($rule['page_area_rule']); if ($page_area_rule) { if (strpos($page_area_rule, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($html, 'UTF-8'); $pq_dom = str_replace('DOM::', '', $page_area_rule); $pq_array = phpQuery::pq($pq_dom); foreach ($pq_array as $pn => $pq_val) { $href = phpQuery::pq($pq_val)->attr('href'); if ($href) { if ($rule['page_url_rule']) { if (strpos($rule['page_url_rule'], '<%') !== false) { $page_url_rule = spiderTools::pregTag($rule['page_url_rule']); if (!preg_match('|' . $page_url_rule . '|is', $href)) { continue; } } else { $cleanhref = spiderTools::dataClean($rule['page_url_rule'], $href); if ($cleanhref) { $href = $cleanhref; unset($cleanhref); } else { continue; } } } $href = str_replace('<%url%>', $href, $rule['page_url']); $page_url_array[$pn] = spiderTools::url_complement($rule['__url__'], $href); } } phpQuery::unloadDocuments($doc->getDocumentID()); } else { $page_area_rule = spiderTools::pregTag($page_area_rule); if ($page_area_rule) { preg_match('|' . $page_area_rule . '|is', $html, $matches, $PREG_SET_ORDER); $page_area = $matches['content']; } else { $page_area = $html; } if ($rule['page_url_rule']) { $page_url_rule = spiderTools::pregTag($rule['page_url_rule']); preg_match_all('|' . $page_url_rule . '|is', $page_area, $page_url_matches, PREG_SET_ORDER); foreach ($page_url_matches as $pn => $row) { $href = str_replace('<%url%>', $row['url'], $rule['page_url']); $page_url_array[$pn] = spiderTools::url_complement($rule['__url__'], $href); gc_collect_cycles(); } } unset($page_area); } } else { // 逻辑方式 if ($rule['page_url_parse'] == '<%url%>') { $page_url = str_replace('<%url%>', $rule['__url__'], $rule['page_url']); } else { $page_url_rule = spiderTools::pregTag($rule['page_url_parse']); preg_match('|' . $page_url_rule . '|is', $rule['__url__'], $matches, $PREG_SET_ORDER); $page_url = str_replace('<%url%>', $matches['url'], $rule['page_url']); } if (stripos($page_url, '<%step%>') !== false) { for ($pn = $rule['page_no_start']; $pn <= $rule['page_no_end']; $pn = $pn + $rule['page_no_step']) { $page_url_array[$pn] = str_replace('<%step%>', $pn, $page_url); gc_collect_cycles(); } } } //URL去重清理 if ($page_url_array) { $page_url_array = array_filter($page_url_array); $page_url_array = array_unique($page_url_array); $puk = array_search($rule['__url__'], $page_url_array); if ($puk !== false) { unset($page_url_array[$puk]); } } if (spider::$dataTest) { echo "<b>内容页网址:</b>" . $rule['__url__'] . "<br />"; echo "<b>分页:</b>" . $rule['page_url'] . "<br />"; echo iS::escapeStr($page_url_rule); echo "<hr />"; } if (spider::$dataTest) { echo "<b>分页列表:</b><pre>"; print_r($page_url_array); echo "</pre><hr />"; } spider::$content_right_code = trim($rule['page_url_right']); spider::$content_error_code = trim($rule['page_url_error']); spider::$curl_proxy = $rule['proxy']; $pageurl = array(); foreach ($page_url_array as $pukey => $purl) { //usleep(100); $phtml = spiderTools::remote($purl); if (empty($phtml)) { break; } $md5 = md5($phtml); if ($pageurl[$md5]) { break; } $check_content = spiderTools::check_content_code($phtml); if ($check_content === false) { unset($check_content, $phtml); break; } $_content = spiderContent::match($phtml, $data, $rule); $cmd5 = md5($_content); if ($contentHash[$cmd5]) { break; } $contentArray[] = $_content; $contentHash[$cmd5] = true; $pageurl[$md5] = $purl; spider::$allHtml[$md5] = $phtml; } gc_collect_cycles(); unset($check_content, $phtml); if (spider::$dataTest) { echo "<b>最终分页列表:</b><pre>"; print_r($pageurl); echo "</pre><hr />"; } } else { foreach ((array) spider::$allHtml as $ahkey => $phtml) { $contentArray[] = spiderContent::match($phtml, $data, $rule); } } } $content = implode('#--iCMS.PageBreak--#', $contentArray); $html = null; unset($html, $contentArray, $contentHash, $_content); $content = stripslashes($content); if (spider::$dataTest) { print_r('<b>[' . $name . ']匹配结果:</b>' . htmlspecialchars($content)); echo "<hr />"; } if ($data['cleanbefor']) { $content = spiderTools::dataClean($data['cleanbefor'], $content); } /** * 在数据项里调用之前采集的数据[DATA@name][DATA@name.key] */ if (strpos($content, '[DATA@') !== false) { $content = spiderTools::getDATA($responses, $content); } if ($data['cleanhtml']) { $content = stripslashes($content); $content = preg_replace('/<[\\/\\!]*?[^<>]*?>/is', '', $content); } if ($data['format'] && $content) { $content = autoformat($content); } if ($data['img_absolute'] && $content) { // $content = stripslashes($content); preg_match_all("/<img.*?src\\s*=[\"|'](.*?)[\"|']/is", $content, $img_match); if ($img_match[1]) { $_img_array = array_unique($img_match[1]); $_img_urls = array(); foreach ((array) $_img_array as $_img_key => $_img_src) { $_img_urls[$_img_key] = spiderTools::url_complement($rule['__url__'], $_img_src); } $content = str_replace($_img_array, $_img_urls, $content); } unset($img_match, $_img_array, $_img_urls, $_img_src); } if ($data['trim']) { $content = trim($content); } if ($data['capture']) { // $content = stripslashes($content); $content = spiderTools::remote($content); } if ($data['download']) { // $content = stripslashes($content); $content = iFS::http($content); } if ($data['cleanafter']) { $content = spiderTools::dataClean($data['cleanafter'], $content); // $content = stripslashes($content); } if ($data['autobreakpage']) { $content = spiderTools::autoBreakPage($content); } if ($data['mergepage']) { $content = spiderTools::mergePage($content); } if ($data['empty'] && empty($content)) { $emptyMsg = '[' . $name . ']规则设置了不允许为空.当前抓取结果为空!请检查,规则是否正确!'; if (spider::$dataTest) { exit('<h1>' . $emptyMsg . '</h1>'); } if (spider::$work) { echo "\n{$emptyMsg}\n"; return false; } else { iPHP::alert($emptyMsg); } } if ($data['json_decode']) { $content = json_decode($content, true); } if ($data['array']) { return (array) $content; } if (spider::$callback['content'] && is_callable(spider::$callback['content'])) { $content = call_user_func_array(spider::$callback['content'], array($content)); } return $content; }
function dosave() { include_once iPATH . 'include/tag.class.php'; $id = $_POST['id']; $mid = $_POST['mid']; $FArray = model::field($mid); $model = model::data($mid); $content = array(); if ($_POST['content']) { foreach ($_POST['content'] as $field => $value) { if (model::isDefField($field)) { switch ($field) { case "userid": $value = intval($value); break; case "fid": $value = $fid = intval($value); empty($value) && javascript::alert('请选择所属栏目'); break; case "orderNum": $value = _int($value); break; case "top": $value = _int($value); break; case "title": $value = dhtmlspecialchars($value); empty($value) && javascript::alert('标题不能为空!'); break; case "editor": $value = dhtmlspecialchars($value); break; case "tags": $value = iTAG::split(dhtmlspecialchars($value), true); break; case "type": $value = intval($value); break; case "vlink": $value = implode(',', $value); break; case "postype": $value = empty($value) ? intval($value) : "1"; break; case "pubdate": $value = _strtotime($value); break; case "clink": $value = dhtmlspecialchars($value); if ($value) { $clinklen = strlen($value); for ($i = 0; $i < $clinklen; $i++) { !preg_match("/[a-zA-Z0-9_\\-~" . preg_quote($this->iCMS->config['CLsplit'], '/') . "]/", $value[$i]) && javascript::alert('自定链接只能由英文字母、数字或_-~组成(不支持中文)'); } } break; } } elseif ($F = $FArray[$field]) { switch ($F['type']) { case "number": $value = intval($value); break; case "calendar": $value = _strtotime($value); break; case in_array($F['type'], array('text', 'textarea', 'radio', 'select', 'email', 'url', 'image', 'upload')): $value = dhtmlspecialchars($value); break; case in_array($F['type'], array('checkbox', 'multiple')): $value = implode(',', $value); break; case 'editor': $this->iCMS->config['autoformat'] && ($value = autoformat($value)); break; default: $value = dhtmlspecialchars($value); } } WordFilter($value) && javascript::alert($field . '字段包含被系统屏蔽的字符,请返回重新填写。'); $content[$field] = $value; $PF[] = $field; } } if (empty($content['clink'])) { include iPATH . 'include/cn.class.php'; $content['clink'] = CN::pinyin($content['title'], $this->iCMS->config['CLsplit']); } $table = model::tbn($_POST['table']); $MF = explode(',', $model['field']); $diff = array_diff_values($PF, $MF); if ($diff['-']) { foreach ($diff['-'] as $field) { $content[$field] = ''; } } //缺少的字段 填认空值 $SELFURL = __SELF__ . (empty($_POST['REFERER']) ? '?mo=content&do=manage' : $_POST['REFERER']); $forum = new forum(); if (empty($id)) { empty($content['userid']) && ($content['userid'] = member::$uId); $content['hits'] = $content['good'] = $content['bad'] = $content['comments'] = 0; $content['status'] = "1"; $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `clink` ='" . $content['clink'] . "'"); if ($this->iCMS->config['repeatitle']) { iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `title` = '{$title}'") && alert('该标题内容已经存在!请检查是否重复'); $checkCL && javascript::alert('该自定链接已经存在!请另选一个'); } else { $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1)); } iCMS_DB::insert($table, $content); $id = iCMS_DB::$insert_id; model::upload($table, $id, $title); iTAG::add($content['tags'], $content['userid'], $id, $forum->rootid($fid), $mid); $vlink = empty($content['vlink']) ? $fid : $content['vlink'] . ',' . $fid; vlinkDiff($vlink, '', $id, $mid); if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $content['status']) { include iPATH . 'include/iHtml.class.php'; iHtml::content($id, $mid, $table); iHtml::forum($fid, 1, 0, 1); } iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); // $moreaction=array( // array("text"=>"编辑该内容","url"=>__SELF__."?do=content&operation=add&table=".$table."&mid=".$mid."&id=".$id), // array("text"=>"继续添加内容","url"=>__SELF__."?do=content&operation=add&table=".$table."&mid=".$mid."&cid=".$cid), // array("text"=>"查看该内容","url"=>$iCMS->iurl('content',array('mId'=>$mid,'id'=>$id,'link'=>$clink,'pubdate'=>$pubdate,'cid'=>$cid,'dir'=>$catalog->catalog[$cid]['dir'],'domain'=>$catalog->catalog[$cid]['domain'],'htmlext'=>$catalog->catalog[$cid]['htmlext']))->href,"o"=>'target="_blank"'), // array("text"=>"查看网站首页","url"=>"../index.php","o"=>'target="_blank"') // ); javascript::dialog("添加完成!", 'url:' . __SELF__ . "?mo=content&do=manage&table=" . $table . "&mid=" . $mid); } else { $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__{$table}` where `clink` ='{$clink}' AND `id` !='{$id}'"); if ($this->iCMS->config['repeatitle']) { $checkCL && alert('该自定链接已经存在!请另选一个'); } else { $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1)); } $art = iCMS_DB::getRow("SELECT `fid`,`tags`,`vlink` FROM `#iCMS@__{$table}` where `id` ='{$id}'"); iTAG::diff($content['tags'], member::$uId, $art->tags, $id, $forum->rootid($fid)); iCMS_DB::update($table, $content, array('id' => $id)); model::upload($table, $id, $title); $vlink = empty($content['vlink']) ? $fid : $content['vlink'] . ',' . $fid; vlinkDiff($vlink, $art->vlink, $id); if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) { include iPATH . 'include/iHtml.class.php'; iHtml::content($id, $mid, $table); iHtml::forum($fid, 1, 0, 1); } if ($art->fid != $fid) { iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count-1 WHERE `fid` ='{$art->fid}' LIMIT 1 "); iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); } javascript::dialog('编辑完成!<br />3秒后返回项目列表', 'url:' . $SELFURL); } }
function article_data($bodyArray, $aid = 0, $haspic = 0) { $id = (int) $_POST['adid']; $subtitle = iS::escapeStr($_POST['subtitle']); $body = implode('#--iCMS.PageBreak--#', $bodyArray); $body = preg_replace(array('/<script.+?<\\/script>/is', '/<form.+?<\\/form>/is'), '', $body); isset($_POST['dellink']) && ($body = preg_replace("/<a[^>].*?>(.*?)<\\/a>/si", "\\1", $body)); iCMS::$config['publish']['autoformat'] && ($body = autoformat($body)); articleTable::$ID = $aid; $fields = articleTable::data_fields($id); $data = compact($fields); if ($id) { articleTable::data_update($data, compact('id')); } else { $id = articleTable::data_insert($data); } if ($this->callback['data']) { $DCB = $this->callback['data']; $handler = $DCB[0]; $params = (array) $DCB[1]; if (is_callable($handler)) { call_user_func_array($handler, $params); } } $_POST['isredirect'] && (iFS::$redirect = true); $_POST['iswatermark'] && (iFS::$watermark = false); if (isset($_POST['remote'])) { $body = $this->remotepic($body, true, $aid); $body = $this->remotepic($body, true, $aid); $body = $this->remotepic($body, true, $aid); if ($body && $id) { articleTable::data_update(array('body' => $body), compact('id')); } } if (isset($_POST['autopic']) && empty($haspic)) { $picurl = $this->remotepic($body, 'autopic', $aid); $this->pic($picurl, $aid); } $this->pic_indexid($body, $aid); }
function doSave() { include_once iPATH . 'include/tag.class.php'; // print_r($_POST); // exit; set_time_limit(0); $aid = (int) $_POST['aid']; $fid = (int) $_POST['fid']; $title = dhtmlspecialchars($_POST['title']); $source = dhtmlspecialchars($_POST['source']); $author = dhtmlspecialchars($_POST['author']); $description = dhtmlspecialchars($_POST['description']); $keywords = dhtmlspecialchars($_POST['keywords']); $tags = dhtmlspecialchars($_POST['tags']); $pic = dhtmlspecialchars($_POST['pic']); $metadata = dhtmlspecialchars($_POST['metadata']); $metadata = $metadata ? addslashes(serialize($metadata)) : ''; $userid = member::$uId; $pubdate = _strtotime(); $type = 0; $orderNum = 0; $subtitle = ''; $stitle = ''; $editor = ''; $clink = ''; $url = ''; $tpl = ''; $top = 0; $vlink = ""; $related = ""; $postype = 0; $body = str_replace(array("\n", "\r", "\t"), "", $_POST['body']); empty($title) && javascript::alert('标题不能为空!'); empty($fid) && javascript::alert('请选择所属栏目'); empty($body) && javascript::alert('文章内容不能为空!'); WordFilter($title) && javascript::alert('标题包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($source) && javascript::alert('出处包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($author) && javascript::alert('作者包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($description) && javascript::alert('摘要包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($keywords) && javascript::alert('关键字包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($tags) && javascript::alert('标签包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($metadata) && javascript::alert('自定义内容包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($body) && javascript::alert('文章内容包含被系统屏蔽的字符,请返回重新填写。'); if ($this->iCMS->config['AutoPage']) { if ($this->iCMS->config['AutoPageLen'] && !preg_match('/<div\\s+style=\\\\"page-break-after:.*?<\\/div>/is', $body)) { $html = autoformat($body, false); AutoPageBreak::page($html, $this->iCMS->config['AutoPageLen']); $body = implode('<!--iCMS.PageBreak-->', AutoPageBreak::$Rs); AutoPageBreak::$Rs = ''; unset($html); $this->iCMS->config['autoformat'] = false; } } $body = preg_replace(array('/<script.+?<\\/script>/is', '/<form.+?<\\/form>/is', '/<div\\s+style=\\\\"page-break-after:.*?<\\/div>/is'), array('', '', '<!--iCMS.PageBreak-->'), $body); $this->iCMS->config['autoformat'] && ($body = autoformat($body)); if ($this->iCMS->config['autodesc'] == "1" && !empty($this->iCMS->config['descLen']) && empty($description)) { $_body = preg_replace(array('/<p[^>]*>/is', '/<[\\/\\!]*?[^<>]*?>/is', "/\n+/", "/ +/", "/^\n/"), array("\n\n", '', "\n", '', ''), $this->iCMS->config['autoformat'] ? $body : autoformat($body)); $description = csubstr($_body, $this->iCMS->config['descLen']); } $tags = iTAG::split($tags, true); include iPATH . 'include/cn.class.php'; $clink = CN::pinyin($title, $this->iCMS->config['CLsplit']); $isPic = empty($pic) ? 0 : 1; $SELFURL = __SELF__ . (empty($_POST['REFERER']) ? '?mo=article&do=manage' : $_POST['REFERER']); $forum = new forum(); $status = $forum->forum[$fid]['isexamine'] ? '0' : '1'; //审核投稿 if (empty($aid)) { $hits = $good = $bad = $comments = 0; iCMS_DB::insert('article', compact('fid', 'title', 'stitle', 'clink', 'orderNum', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'metadata', 'isPic', 'pic', 'pubdate', 'hits', 'good', 'bad', 'comments', 'type', 'vlink', 'top', 'status')); $aid = iCMS_DB::$insert_id; iCMS_DB::insert('article_data', compact('aid', 'subtitle', 'tpl', 'body')); if ($_FILES['picfile']) { require_once iPATH . 'include/upload.class.php'; $F = iUpload::FILES("picfile", $aid, $title); iCMS_DB::query("UPDATE `#iCMS@__article` SET `isPic`='1',`pic` = '" . $F["FilePath"] . "' WHERE `id` = '{$aid}'"); } //$this->insert_db_remote($body,$aid); iTAG::add($tags, $userid, $aid, $forum->rootid($fid)); vlinkDiff($fid, '', $aid); if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) { include iPATH . 'include/iHtml.class.php'; iHtml::Article($aid); iHtml::forum($fid, 1, 0, 1); } if ($status) { iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); $moreaction = array(array("text" => "查看该文章", "url" => $this->iCMS->iurl('show', array(array('id' => $aid, 'link' => $clink, 'url' => $url, 'fid' => $fid, 'pubdate' => $pubdate), $forum->forum[$fid]))->href, "o" => 'target="_blank"'), array("text" => "编辑该文章", "url" => __SELF__ . "?mo=article&do=add&id=" . $aid), array("text" => "继续添加文章", "url" => __SELF__ . "?mo=article&do=add&fid=" . $fid), array("text" => "返回文章列表", "url" => $SELFURL), array("text" => "查看网站首页", "url" => "../index.php", "o" => 'target="_blank"')); javascript::dialog('文章发布成功!<br />10秒后返回文章列表', 'url:' . $SELFURL, $moreaction, 10); } else { javascript::dialog('您的投稿文章发布成功!<br />该版块文章需要经过管理员审核才能显示!<br />请耐心等待,我们会尽快审核您的稿件!', 'url:' . $SELFURL, 'ok', 10); } } else { $art = iCMS_DB::getRow("SELECT `fid`,`tags`,`vlink` FROM `#iCMS@__article` where `id` ='{$aid}'"); iTAG::diff($tags, $art->tags, member::$uId, $aid, $forum->rootid($fid)); iCMS_DB::update('article', compact('fid', 'title', 'stitle', 'orderNum', 'clink', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'metadata', 'isPic', 'pic', 'pubdate', 'type', 'vlink', 'top', 'status'), array('id' => $aid)); vlinkDiff($fid, $art->vlink, $aid); iCMS_DB::update('article_data', compact('tpl', 'subtitle', 'body'), compact('aid')); if ($_FILES['picfile']) { require_once iPATH . 'include/upload.class.php'; $F = iUpload::FILES("picfile", $aid, $title); iCMS_DB::query("UPDATE `#iCMS@__article` SET `isPic`='1',`pic` = '" . $F["FilePath"] . "' WHERE `id` = '{$aid}'"); } //$this->insert_db_remote($body,$aid); if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) { include iPATH . 'include/iHtml.class.php'; iHtml::Article($aid); iHtml::forum($fid, 1, 0, 1); } if ($status) { if ($art->fid != $fid) { iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count-1 WHERE `fid` ='{$art->fid}' LIMIT 1 "); iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); } javascript::dialog('文章编辑完成!<br />3秒后返回文章列表', 'url:' . $SELFURL); } else { javascript::dialog('您的文章编辑完成!<br />该版块文章需要经过管理员审核才能显示!<br />请耐心等待,我们会尽快审核您的稿件!', 'url:' . $SELFURL, 'ok', 10); } } }
function content($html, $data, $rule) { if (trim($data['rule']) === '') { return; } $name = $data['name']; if ($data['page']) { if (empty($rule['page_url'])) { $rule['page_url'] = $rule['list_url']; } if (empty($this->allHtml)) { $page_url_array = array(); $page_area_rule = trim($rule['page_area_rule']); if ($page_area_rule) { if (strpos($page_area_rule, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($html, 'UTF-8'); $pq_dom = str_replace('DOM::', '', $page_area_rule); $pq_array = phpQuery::pq($pq_dom); foreach ($pq_array as $pn => $pq_val) { $href = phpQuery::pq($pq_val)->attr('href'); if ($href) { if ($rule['page_url_rule']) { $page_url_rule = $this->pregTag($rule['page_url_rule']); // var_dump('|' . $page_url_rule . '|is'); if (!preg_match('|' . $page_url_rule . '|is', $href)) { continue; } } $href = str_replace('<%url%>', $href, $rule['page_url']); $page_url_array[$pn] = $this->_url_complement($rule['__url__'], $href); } } if ($page_url_array) { $page_url_array = array_filter($page_url_array); $page_url_array = array_unique($page_url_array); $puk = array_search($rule['__url__'], $page_url_array); unset($page_url_array[$puk]); } //var_dump($page_url_array); // exit; } else { $page_area_rule = $this->pregTag($page_area_rule); if ($page_area_rule) { preg_match('|' . $page_area_rule . '|is', $html, $matches, $PREG_SET_ORDER); $page_area = $matches['content']; } else { $page_area = $html; } if ($rule['page_url_rule']) { $page_url_rule = $this->pregTag($rule['page_url_rule']); preg_match_all('|' . $page_url_rule . '|is', $page_area, $page_url_matches, PREG_SET_ORDER); foreach ($page_url_matches as $pn => $row) { $href = str_replace('<%url%>', $row['url'], $rule['page_url']); $page_url_array[$pn] = $this->_url_complement($rule['__url__'], $href); gc_collect_cycles(); } } if ($page_url_array) { $page_url_array = array_filter($page_url_array); $page_url_array = array_unique($page_url_array); $puk = array_search($rule['__url__'], $page_url_array); unset($page_url_array[$puk]); } unset($page_area); } } else { // 逻辑方式 if ($rule['page_url_parse'] == '<%url%>') { $page_url = str_replace('<%url%>', $rule['__url__'], $rule['page_url']); } else { $page_url_rule = $this->pregTag($rule['page_url_parse']); preg_match('|' . $page_url_rule . '|is', $rule['__url__'], $matches, $PREG_SET_ORDER); $page_url = str_replace('<%url%>', $matches['url'], $rule['page_url']); } if (stripos($page_url, '<%step%>') !== false) { for ($pn = $rule['page_no_start']; $pn <= $rule['page_no_end']; $pn = $pn + $rule['page_no_step']) { $page_url_array[$pn] = str_replace('<%step%>', $pn, $page_url); gc_collect_cycles(); } } } if ($this->contTest) { echo $rule['__url__'] . "<br />"; echo $rule['page_url'] . "<br />"; echo iS::escapeStr($page_url_rule); echo "<hr />"; } if ($this->contTest) { echo "<pre>"; print_r($page_url_array); echo "</pre><hr />"; } $this->content_right_code = trim($rule['page_url_right']); $this->content_error_code = trim($rule['page_url_error']); $this->curl_proxy = $rule['proxy']; $pcontent = ''; $pcon = ''; foreach ($page_url_array as $pukey => $purl) { //usleep(100); $phtml = $this->remote($purl); if (empty($phtml)) { break; } $phttp = $this->check_content_code($phtml); if ($phttp['match'] == false) { break; } $pageurl[] = $purl; $pcon .= $phttp['content']; } gc_collect_cycles(); $html .= $pcon; unset($pcon); $this->allHtml = $html; if ($this->contTest) { echo "<pre>"; print_r($pageurl); echo "</pre><hr />"; } } else { $html = $this->allHtml; } } if ($data['dom']) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $this->contTest && $_GET['pq_debug'] && (phpQuery::$debug = 1); $doc = phpQuery::newDocumentHTML($html, 'UTF-8'); //echo "\ndata:getDocumentID:".$doc->getDocumentID()."\n"; 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(); foreach ($doc[$content_dom] as $doc_key => $doc_value) { if ($content_attr) { $conArray[] = phpQuery::pq($doc_value)->{$content_fun}($content_attr); } else { $conArray[] = phpQuery::pq($doc_value)->{$content_fun}(); } } $content = implode('#--iCMS.PageBreak--#', $conArray); unset($conArray); } else { if ($content_attr) { $content = $doc[$content_dom]->{$content_fun}($content_attr); } else { $content = $doc[$content_dom]->{$content_fun}(); } } if ($this->contTest) { print_r(htmlspecialchars($content)); echo "<hr />"; } phpQuery::unloadDocuments($doc->getDocumentID()); unset($doc); } else { if (trim($data['rule']) == '<%content%>') { $content = $html; } else { $data_rule = $this->pregTag($data['rule']); if ($this->contTest) { print_r(iS::escapeStr($data_rule)); echo "<hr />"; } 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) { $conArray[] = $mat['content']; } $content = implode('#--iCMS.PageBreak--#', $conArray); if ($this->contTest) { print_r(htmlspecialchars($content)); echo "<hr />"; } } else { preg_match('|' . $data_rule . '|is', $html, $matches, $PREG_SET_ORDER); $content = $matches['content']; } } else { $content = $data_rule; } } } $html = null; unset($html); if ($data['cleanbefor']) { $content = $this->dataClean($data['cleanbefor'], $content); } if ($data['cleanhtml']) { $content = preg_replace('/<[\\/\\!]*?[^<>]*?>/is', '', $content); } if ($data['format'] && $content) { // $_content = iPHP::cleanHtml($content); // trim($_content) && $content = $_content; $content = autoformat($content); $content = stripslashes($content); // unset($_content); } if ($data['img_absolute'] && $content) { preg_match_all("/<img.*?src\\s*=[\"|'](.*?)[\"|']/is", $content, $img_match); if ($img_match[1]) { $_img_array = array_unique($img_match[1]); $_img_urls = array(); foreach ((array) $_img_array as $_img_key => $_img_src) { $_img_urls[$_img_key] = $this->_url_complement($rule['__url__'], $_img_src); } $content = str_replace($_img_array, $_img_urls, $content); } } $data['trim'] && ($content = trim($content)); if ($data['capture']) { $capture = str_replace('\\', '', $content); $content = $this->remote($capture); } if ($data['cleanafter']) { $content = $this->dataClean($data['cleanafter'], $content); } if ($data['mergepage']) { $_content = $content; preg_match_all("/<img.*?src\\s*=[\"|'|\\s]*(http:\\/\\/.*?\\.(gif|jpg|jpeg|bmp|png)).*?>/is", $_content, $picArray); $pA = array_unique($picArray[1]); $pA = array_filter($pA); $_pcount = count($pA); if ($_pcount < 4) { $content = str_replace('#--iCMS.PageBreak--#', "", $content); } else { $contentA = explode("#--iCMS.PageBreak--#", $_content); $newcontent = array(); $this->checkpage($newcontent, $contentA, 2); if (is_array($newcontent)) { $content = array_filter($newcontent); $content = implode('#--iCMS.PageBreak--#', $content); //$content = addslashes($content); } else { //$content = addslashes($newcontent); $content = $newcontent; } unset($newcontent, $contentA); } unset($_content); } if ($data['empty'] && empty($content)) { if ($this->work) { echo "\n[" . $name . "内容为空!请检查,规则是否正确!]\n"; return false; } else { $this->contTest && (iPHP::$dialog['alert'] = 'window'); iPHP::alert($name . '内容为空!请检查,规则是否正确!!'); } } if ($data['json_decode']) { $content = json_decode($content, true); // $content = preg_replace_callback('/&#\d{2,5};/u','utf8_num_decode',$content); // $content = preg_replace_callback(array( // '/&#x([a-fA-F0-7]{2,8});/u', // '/%u([a-fA-F0-7]{2,8})/u', // '/\\\u([a-fA-F0-7]{2,8})/u' // ),'utf8_entity_decode',$content); // $content = htmlspecialchars_decode($content); } if ($data['array']) { return (array) $content; } return $content; }
function body($body, $subtitle, $aid = 0, $id = 0, &$haspic = 0) { $body = preg_replace(array('/<script.+?<\\/script>/is', '/<form.+?<\\/form>/is'), '', $body); isset($_POST['dellink']) && ($body = preg_replace("/<a[^>].*?>(.*?)<\\/a>/si", "\\1", $body)); if (isset($_POST['markdown'])) { $body = '#--iCMS.Markdown--#' . $body; } else { iCMS::$config['publish']['autoformat'] && ($body = addslashes(autoformat($body))); } articleTable::$ID = $aid; $fields = articleTable::data_fields($id); $data = compact($fields); if ($id) { articleTable::data_update($data, compact('id')); } else { $id = articleTable::data_insert($data); } $_POST['isredirect'] && (iFS::$redirect = true); $_POST['iswatermark'] && (iFS::$watermark = false); if (isset($_POST['remote'])) { $body = $this->remotepic($body, true, $aid); $body = $this->remotepic($body, true, $aid); $body = $this->remotepic($body, true, $aid); if ($body && $id) { articleTable::data_update(array('body' => $body), compact('id')); } } if (isset($_POST['autopic']) && empty($haspic)) { if ($picurl = $this->remotepic($body, 'autopic', $aid)) { $this->pic($picurl, $aid); $haspic = true; } } $this->pic_indexid($body, $aid); }
function doSave() { include_once iPATH . 'include/tag.class.php'; // print_r($_POST); // exit; set_time_limit(0); $aid = (int) $_POST['aid']; $fid = (int) $_POST['fid']; $userid = (int) $_POST['userid']; $type = (int) $_POST['type']; $orderNum = (int) $_POST['orderNum']; $title = dhtmlspecialchars($_POST['title']); $subtitle = dhtmlspecialchars($_POST['subtitle']); $stitle = dhtmlspecialchars($_POST['stitle']); $pic = dhtmlspecialchars($_POST['pic']); $source = dhtmlspecialchars($_POST['source']); $author = dhtmlspecialchars($_POST['author']); $editor = dhtmlspecialchars($_POST['editor']); $description = dhtmlspecialchars($_POST['description']); $keywords = dhtmlspecialchars($_POST['keywords']); $tags = dhtmlspecialchars($_POST['tags']); $clink = dhtmlspecialchars($_POST['clink']); $url = dhtmlspecialchars($_POST['url']); $tpl = dhtmlspecialchars($_POST['template']); $metadata = dhtmlspecialchars($_POST['metadata']); $metadata = $metadata ? addslashes(serialize($metadata)) : ''; $top = _int($_POST['top']); $vlink = empty($_POST['vlink']) ? "" : implode(',', $_POST['vlink']); $related = empty($_POST['related']) ? "" : implode(',', $_POST['related']); $pubdate = _strtotime($_POST['pubdate']); $remote = isset($_POST['remote']) ? true : false; $dellink = isset($_POST['dellink']) ? true : false; $this->autopic = isset($_POST['autopic']) ? true : false; $status = isset($_POST['draft']) ? "0" : "1"; $postype = $_POST['postype'] == "0" ? "0" : "1"; if ($this->iCMS->config['AutoPage'] && empty($_POST['AutoPage'])) { if ($this->iCMS->config['AutoPageLen'] && count($_POST['body']) == 1 && !preg_match('/<div\\s+style=\\\\"page-break-after:.*?<\\/div>/is', $_POST['body'][0]) && stristr($_POST['body'][0], '<!--iCMS.PageBreak-->') === FALSE) { $html = autoformat($_POST['body'][0], false); AutoPageBreak::page($html, $this->iCMS->config['AutoPageLen']); $_POST['body'] = AutoPageBreak::$Rs; AutoPageBreak::$Rs = ''; unset($html); $this->iCMS->config['autoformat'] = false; } } $body = implode('<!--iCMS.PageBreak-->', $_POST['body']); $body = str_replace(array("\r", "\t"), "", $body); $body = preg_replace(array('/<script.+?<\\/script>/is', '/<form.+?<\\/form>/is', '/<div\\s+style=\\\\"page-break-after:.*?<\\/div>/is'), array('', '', '<!--iCMS.PageBreak-->'), $body); empty($title) && javascript::alert('标题不能为空!'); empty($fid) && javascript::alert('请选择所属栏目'); empty($body) && empty($url) && javascript::alert('文章内容不能为空!'); WordFilter($title) && javascript::alert('标题包含被系统屏蔽的字符,请返回重新填写。'); WordFilter($body) && javascript::alert('文章内容包含被系统屏蔽的字符,请返回重新填写。'); if ($clink) { $clinklen = strlen($clink); for ($i = 0; $i < $clinklen; $i++) { !preg_match("/[a-zA-Z0-9_\\-~" . preg_quote($this->iCMS->config['CLsplit'], '/') . "]/", $clink[$i]) && javascript::alert('自定链接只能由英文字母、数字或_-~组成(不支持中文)'); } } isset($_POST['keywordToTag']) && empty($tags) && ($tags = $keywords); $tags = iTAG::split($tags, true); if ($this->iCMS->config['autoformat'] && empty($_POST['autoformat'])) { $body = autoformat($body); } if ($this->iCMS->config['autodesc'] == "1" && !empty($this->iCMS->config['descLen']) && empty($description) && empty($url)) { $_body = preg_replace(array('/<p[^>]*>/is', '/<[\\/\\!]*?[^<>]*?>/is', "/\n+/", "/ +/", "/^\n/"), array("\n\n", '', "\n", '', ''), $this->iCMS->config['autoformat'] ? $body : autoformat($body)); $description = csubstr($_body, $this->iCMS->config['descLen']); } $remote && FS::remotepic($body, $title); !$remote && $this->autopic && FS::remotepic($body, $title, true); if (empty($clink)) { include iPATH . 'include/cn.class.php'; $clink = CN::pinyin($title, $this->iCMS->config['CLsplit']); } $isPic = empty($pic) ? 0 : 1; $dellink && ($body = preg_replace("/<a[^>].*?>(.*?)<\\/a>/si", "\\1", $body)); $SELFURL = __SELF__ . (empty($_POST['REFERER']) ? '?mo=article&do=manage' : $_POST['REFERER']); $forum = new forum(); if (empty($aid)) { empty($userid) && ($userid = member::$uId); $hits = $good = $bad = $comments = 0; $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `clink` ='{$clink}'"); if ($this->iCMS->config['repeatitle']) { iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `title` = '{$title}'") && javascript::alert('该标题的文章已经存在!请检查是否重复'); $checkCL && javascript::alert('该自定链接已经存在!请另选一个'); } else { $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1)); } iCMS_DB::insert('article', compact('fid', 'title', 'stitle', 'clink', 'orderNum', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'metadata', 'isPic', 'pic', 'pubdate', 'hits', 'good', 'bad', 'comments', 'type', 'vlink', 'top', 'status')); $aid = iCMS_DB::$insert_id; if (empty($url)) { // $body = addslashes($body); iCMS_DB::insert('article_data', compact('aid', 'subtitle', 'tpl', 'body')); $this->insert_db_remote($body, $aid); //$iCMS->setCache('system/search',$res,0); } iTAG::add($tags, $userid, $aid, $forum->rootid($fid)); $vlink = empty($vlink) ? $fid : $vlink . ',' . $fid; vlinkDiff($vlink, '', $aid); if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) { include iPATH . 'include/iHtml.class.php'; iHtml::Article($aid); iHtml::forum($fid, 1, 0, 1); } iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); $moreaction = array(array("text" => "查看该文章", "url" => $this->iCMS->iurl('show', array(array('id' => $aid, 'link' => $clink, 'url' => $url, 'fid' => $fid, 'pubdate' => $pubdate), $forum->forum[$fid]))->href, "o" => 'target="_blank"'), array("text" => "编辑该文章", "url" => __SELF__ . "?mo=article&do=add&id=" . $aid), array("text" => "继续添加文章", "url" => __SELF__ . "?mo=article&do=add&fid=" . $fid), array("text" => "返回文章列表", "url" => $SELFURL), array("text" => "查看网站首页", "url" => "../index.php", "o" => 'target="_blank"')); javascript::dialog('文章添加完成!<br />10秒后返回文章列表', 'url:' . $SELFURL, $moreaction, 10); } else { $checkCL = iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article` where `clink` ='{$clink}' AND `id` !='{$aid}'"); if ($this->iCMS->config['repeatitle']) { $checkCL && javascript::alert('该自定链接已经存在!请另选一个'); } else { $checkCL && ($clink .= $this->iCMS->config['CLsplit'] . random(6, 1)); } $art = iCMS_DB::getRow("SELECT `fid`,`tags`,`vlink` FROM `#iCMS@__article` where `id` ='{$aid}'"); iTAG::diff($tags, $art->tags, member::$uId, $aid, $forum->rootid($fid)); iCMS_DB::update('article', compact('fid', 'title', 'stitle', 'orderNum', 'clink', 'url', 'source', 'author', 'editor', 'userid', 'postype', 'keywords', 'tags', 'description', 'related', 'metadata', 'isPic', 'pic', 'pubdate', 'type', 'vlink', 'top', 'status'), array('id' => $aid)); $vlink = empty($vlink) ? $fid : $vlink . ',' . $fid; vlinkDiff($vlink, $art->vlink, $aid); if (empty($url)) { // $body = addslashes($body); if (iCMS_DB::getValue("SELECT `id` FROM `#iCMS@__article_data` where `aid` ='{$aid}'")) { iCMS_DB::update('article_data', compact('tpl', 'subtitle', 'body'), compact('aid')); } else { iCMS_DB::insert('article_data', compact('aid', 'subtitle', 'tpl', 'body')); } $this->insert_db_remote($body, $aid); } if (!strstr($forum->forum[$fid]['contentRule'], '{PHP}') && !$forum->forum[$fid]['url'] && $forum->forum[$fid]['mode'] == "1" && $status) { include iPATH . 'include/iHtml.class.php'; iHtml::Article($aid); iHtml::forum($fid, 1, 0, 1); } if ($art->fid != $fid) { iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count-1 WHERE `fid` ='{$art->fid}' LIMIT 1 "); iCMS_DB::query("UPDATE `#iCMS@__forum` SET `count` = count+1 WHERE `fid` ='{$fid}' LIMIT 1 "); } javascript::dialog('文章编辑完成!<br />3秒后返回文章列表', 'url:' . $SELFURL); } }