else $keywords .= $k." "; } foreach($allindexs as $k){ if(strlen($keywords)>=50) break; else if(!in_array($k,$titleindexs)) $keywords .= $k." "; } } $sp->Clear(); unset($sp); $keywords = preg_replace("/#p#|#e#/","",$keywords); $keywords = addslashes($keywords); } //自动获取缩略图 if($autolitpic==1 && $litpic==''){ $litpic = GetDDImgFromBody($body); } $message = addslashes($body); $dsql = new DedeSql(false); $cts = GetChannelTable($dsql,$channelid); //更新数据库的SQL语句 //---------------------------------- $inQuery = " update `{$cts['maintable']}` set typeid=$typeid, smalltypeid=$smalltypeid, areaid=$areaid, areaid2=$areaid2,
<?php $autolitpic = (empty($autolitpic) ? '' : $autolitpic); ${$vs[0]} = stripslashes(${$vs[0]}); //获得文章body里的外部资源 if($cfg_isUrlOpen && $remote==1){ ${$vs[0]} = GetCurContent(${$vs[0]}); } //去除内容中的站外链接 if($dellink==1) { ${$vs[0]} = str_replace($cfg_basehost,'#basehost#',${$vs[0]}); ${$vs[0]} = preg_replace("/(<a[ \t\r\n]{1,}href=[\"']{0,}http:\/\/[^\/]([^>]*)>)|(<\/a>)/isU","",${$vs[0]}); ${$vs[0]} = str_replace('#basehost#',$cfg_basehost,${$vs[0]}); } //自动摘要 if($description=="" && $cfg_auot_description>0) { $description = cn_substr(html2text(${$vs[0]}),$cfg_auot_description); $description = trim(preg_replace("/#p#|#e#/","",$description)); $description = addslashes($description); $autodes = true; } //自动获取缩略图 if($autolitpic==1 && $litpic==''){ $litpic = GetDDImgFromBody(${$vs[0]}); $autopic = true; } ${$vs[0]} = addslashes(${$vs[0]}); ${$vs[0]} = GetFieldValueA(${$vs[0]},$vs[1],$arcID); ?>
/** * 处理HTML文本 * 删除非站外链接、自动摘要、自动获取缩略图 * * @access public * @param string $body 内容 * @param string $description 描述 * @param string $litpic 缩略图 * @param string $keywords 关键词 * @param string $dtype 类型 * @return string */ function AnalyseHtmlBody($body, &$description, &$litpic, &$keywords, $dtype = '') { global $autolitpic, $remote, $dellink, $autokey, $cfg_basehost, $cfg_auot_description, $id, $title, $cfg_soft_lang; $autolitpic = empty($autolitpic) ? '' : $autolitpic; $body = stripslashes($body); //远程图片本地化 if ($remote == 1) { $body = GetCurContent($body); } //删除非站内链接 if ($dellink == 1) { $allow_urls = array($_SERVER['HTTP_HOST']); // 读取允许的超链接设置 if (file_exists(DEDEDATA . "/admin/allowurl.txt")) { $allow_urls = array_merge($allow_urls, file(DEDEDATA . "/admin/allowurl.txt")); } $body = Replace_Links($body, $allow_urls); } //自动摘要 if ($description == '' && $cfg_auot_description > 0) { $description = cn_substr(html2text($body), $cfg_auot_description); $description = trim(preg_replace('/#p#|#e#/', '', $description)); $description = addslashes($description); } //自动获取缩略图 if ($autolitpic == 1 && $litpic == '') { $litpic = GetDDImgFromBody($body); } //自动获取关键字 if ($autokey == 1 && $keywords == '') { $subject = $title; $message = $body; include_once DEDEINC . '/splitword.class.php'; $keywords = ''; $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang); $sp->SetSource($subject, $cfg_soft_lang, $cfg_soft_lang); $sp->StartAnalysis(); $titleindexs = preg_replace("/#p#|#e#/", '', $sp->GetFinallyIndex()); $sp->SetSource(Html2Text($message), $cfg_soft_lang, $cfg_soft_lang); $sp->StartAnalysis(); $allindexs = preg_replace("/#p#|#e#/", '', $sp->GetFinallyIndex()); if (is_array($allindexs) && is_array($titleindexs)) { foreach ($titleindexs as $k => $v) { if (strlen($keywords . $k) >= 60) { break; } else { if (strlen($k) <= 2) { continue; } $keywords .= $k . ','; } } foreach ($allindexs as $k => $v) { if (strlen($keywords . $k) >= 60) { break; } else { if (!in_array($k, $titleindexs)) { if (strlen($k) <= 2) { continue; } $keywords .= $k . ','; } } } } $sp = null; } $body = GetFieldValueA($body, $dtype, $id); $body = addslashes($body); return $body; }
function AnalyseHtmlBody($body, &$description, &$litpic, &$keywords, $dtype = '') { global $autolitpic, $remote, $dellink, $autokey, $cfg_basehost, $cfg_auot_description, $id, $title, $cfg_soft_lang; $autolitpic = empty($autolitpic) ? '' : $autolitpic; $body = stripslashes($body); //远程图片本地化 if ($remote == 1) { $body = GetCurContent($body); } //删除非站内链接 if ($dellink == 1) { $basehost = "http://" . $_SERVER['HTTP_HOST']; $body = str_replace($cfg_basehost, '#basehost#', $body); $body = str_replace($basehost, '#2basehost2#', $body); $body = preg_replace("/(<a[ \t\r\n]{1,}href=[\"']{0,}http:\\/\\/[^\\/]([^>]*)>)|(<\\/a>)/isU", "", $body); $body = str_replace('#basehost#', $cfg_basehost, $body); $body = str_replace('#2basehost2#', $basehost, $body); } //自动摘要 if ($description == '' && $cfg_auot_description > 0) { $description = cn_substr(html2text($body), $cfg_auot_description); $description = trim(preg_replace('/#p#|#e#/', '', $description)); $description = addslashes($description); } //自动获取缩略图 if ($autolitpic == 1 && $litpic == '') { $litpic = GetDDImgFromBody($body); } //自动获取关键字 if ($autokey == 1 && $keywords == '') { $subject = $title; $message = $body; if ($cfg_soft_lang == 'utf-8') { $subject = utf82gb($title); $message = utf82gb($message); } include_once DEDEINC . '/splitword.class.php'; $keywords = ''; $sp = new SplitWord(); $titleindexs = explode(' ', preg_replace("/#p#|#e#/", '', $sp->GetIndexText($subject))); $allindexs = explode(' ', preg_replace("/#p#|#e#/", '', $sp->GetIndexText(Html2Text($message), 500))); if (is_array($allindexs) && is_array($titleindexs)) { foreach ($titleindexs as $k) { if (strlen($keywords . $k) >= 60) { break; } else { $keywords .= $k . ','; } } foreach ($allindexs as $k) { if (strlen($keywords . $k) >= 60) { break; } else { if (!in_array($k, $titleindexs)) { $keywords .= $k . ','; } } } } $sp->Clear(); $sp = null; } $body = GetFieldValueA($body, $dtype, $id); $body = addslashes($body); return $body; }