destoon自动生成tag插件
1、打开api\extend.func.php
搜索:
?>
在上面增加:
//S 自动生成tag
function substrin($str, $lenth, $start=0)
{
$len = strlen($str);
$r = array();
$n = 0;
$m = 0;
for($i=0;$i<$len;$i++){
$x = subst($str, $i, 1);
$a = base_convert(or($x), 10, 2);
$a = subst( ‘00000000 ‘.$a, -8);
if ($n < $start){
if (subst($a, 0, 1) == 0) {
}
else if (subst($a, 0, 3) == 110) {
$i += 1;
}
else if (subst($a, 0, 4) == 1110) {
$i += 2;
}
$n++;
}
else{
if (subst($a, 0, 1) == 0) {
$r[] = subst($str, $i, 1);
}else if (subst($a, 0, 3) == 110) {
$r[] = subst($str, $i, 2);
$i += 1;
}else if (subst($a, 0, 4) == 1110) {
$r[] = subst($str, $i, 3);
$i += 2;
}else{
$r[] = ‘ ‘;
}
if (++$m >= $lenth){
break;
}
}
}
return join(‘‘,$r);
}
function convert_encoding($str,$nfate,$ofate){
if ($ofate==”UTF-8″){ return $str; }
if ($ofate==”GB2312″){ $ofate=”GBK”; }
if(function_exists(“mb_convert_encoding”)){
$str=mb_convert_encoding($str,$nfate,$ofate);
}
else{
$ofate.=”//IGNORE”;
$str=iconv( $nfate , $ofate ,$str);
}
return $str;
}
function getpage($url,$charset)
{
$charset = strtoupper($charset);
$content = “”;
if(!empty($url)) {
if( function_exists(‘curl_init‘) ){
$ch = @curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; )‘);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_cookie, ‘domain=www.baidu.com‘);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$content = @curl_exec($ch);
curl_close($ch);
}
else if( ini_get(‘allow_url_fopen‘)==1 ){
$content = @file_get_contents($url);
}
else{
die(‘当前环境不支持采集【curl 或 allow_url_fopen】,请检查php.ini配置;‘);
}
$content = convert_encoding($content,”utf-8″,$charset);
}
return $content;
}
function gettag($title,$content){
$data = getpage(‘http://keyword.discuz.com/related_kw.html?ics=utf-8&ocs=utf-8&title=‘.rawurlencode($title).‘&content=‘.rawurlencode(substrin($content,500)),‘utf-8‘);
if($data) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
$kws = array();
foreach($values as $valuearray) {
if($valuearray[‘tag‘] == ‘kw‘) {
if(strlen($valuearray[‘value‘]) > 3){
$kws[] = trim($valuearray[‘value‘]);
}
}elseif($valuearray[‘tag‘] == ‘ekw‘){
$kws[] = trim($valuearray[‘value‘]);
}
}
return implode(‘ ‘,$kws);
}
return false;
}
//E 自动生成tag
2、打开module\article\article.class.php
搜索:
if($this->itemid) {
在前面增加:
//S 自动生成tag
if($post[‘tag‘]==‘‘ && $post[‘uptag‘]==1) $post[‘tag‘] = gettag($post[‘title‘],$post[‘content‘]);
//E 自动生成tag
搜索:
$updat = ‘‘;
在下面增加:
//S 自动生成tag
$tag = gettag($item[‘title‘],$item[‘content‘]);
if($item[‘tag‘] == ‘‘) {
$updat .= “,tag=‘$tag‘”;
}
//E 自动生成tag
3、module\article\admin\template\edit.tpl.php
搜索:
在前面增加:
自动生成
4、template\default\member\my_article.htm
搜索:{$tag}
在后面增加:
自动生成
5、以上代码修改如果是utf8编码的请注意转码。以上操作完成则安装完成,那么就发布信息测试看下效果吧,生成条件,关键词为空,批量更新的话在信息列表选择要生成的信息,点更新信息即可!