<?php
header("Content-Type:text/html;charset=gbk");
require ("inc/function.php");
require("lib_splitword_full.php");
date_default_timezone_set('PRC');




function get_keywords($html)
{
$keywords = str_replace("-",",",cut($html,"\"keywords\" content=\"", "\"" ));
if ($keywords == "") $keywords = "NO";
$keywords=replace_word(textcut($keywords,150));
$keywords=str_replace("，",",",$keywords);
$keywords=str_replace(",,",",",$keywords);
$keywords=str_replace(" ",",",$keywords);
$keywords=str_replace("|",",",$keywords);
$keywords=str_replace("｜",",",$keywords);
$keywords=str_replace("、",",",$keywords);
return $keywords;
}

function get_ds($html)
{
$keywords = str_replace("-",",",cut($html,"\"description\" content=\"", "\"" ));
if ($keywords == "") $keywords = "NO";
$keywords=replace_word(textcut($keywords,150));
$keywords=str_replace("，",",",$keywords);
$keywords=str_replace(",,",",",$keywords);
$keywords=str_replace(" ",",",$keywords);
$keywords=str_replace("|",",",$keywords);
$keywords=str_replace("｜",",",$keywords);
$keywords=str_replace("、",",",$keywords);
return $keywords;
}

function cut($string,$start,$end)
{
	$message = explode($start,$string);
	$message = explode($end,$message[1]); 
	return $message[0];
}


function replace_word($string){
global $delkey;
    $delkeys = explode("|",$delkey);
    foreach ($delkeys as $del_word) 
    {    
        if (@stristr(trim($string),$del_word))
        {
            $length = strlen($del_word);
        $stars = "*";
        $string = eregi_replace($del_word,$stars,trim($string));
        }
    }
    return $string;
}


function textcut($string, $length, $dot = '') {
	global $charset;

	if(strlen($string) <= $length) {
		return $string;
	}

	$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);

	$strcut = '';
	if(strtolower($charset) == 'utf-8') {

		$n = $tn = $noc = 0;
		while($n < strlen($string)) {

			$t = ord($string[$n]);
			if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
				$tn = 1; $n++; $noc++;
			} elseif(194 <= $t && $t <= 223) {
				$tn = 2; $n += 2; $noc += 2;
			} elseif(224 <= $t && $t < 239) {
				$tn = 3; $n += 3; $noc += 2;
			} elseif(240 <= $t && $t <= 247) {
				$tn = 4; $n += 4; $noc += 2;
			} elseif(248 <= $t && $t <= 251) {
				$tn = 5; $n += 5; $noc += 2;
			} elseif($t == 252 || $t == 253) {
				$tn = 6; $n += 6; $noc += 2;
			} else {
				$n++;
			}

			if($noc >= $length) {
				break;
			}

		}
		if($noc > $length) {
			$n -= $tn;
		}

		$strcut = substr($string, 0, $n);

	} else {
		for($i = 0; $i < $length; $i++) {
			$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
		}
	}

	$strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);

	return $strcut.$dot;
}



?>
<?php
if ($_GET["action"]=="update")
{
$id=$_GET["id"];
axing_connect();
$sql="select * from base where id='$id'";
$result=mysql_query($sql);
$myrow=mysql_fetch_assoc($result);
$url=$myrow["url"];
mysql_close();

$content = get_encoding(get_url_content($url),"GBK");
//获取网页标题
eregi("<title>(.*)</title>",$content, $title);


$keywords=get_keywords($content);
$ds=get_ds($content);


//中文分词分析标题
$sp = new SplitWord();
$tag=$sp->SplitRMM($title[1]);
$sp->Clear();

$tag_tag=explode(" ",$tag);
for ($i=0;$i<(count($tag_tag)-1);$i++)
{
if (strlen($tag_tag[$i])>2 and strlen($tag_tag[$i])<10)
{
axing_connect();
$sql="select * from tag where tag='$tag_tag[$i]'";
$result=mysql_query($sql);
if (!mysql_num_rows($result))
{
$sql="insert into tag(tag) values('$tag_tag[$i]')";
$result=mysql_query($sql);
mysql_close();
}
}
}
//去除HTML标签等
$str = FSubstr(get_enhtml($content),0,120);
axing_connect();
$now=date("Y-m-d H:i:s");
$sql="update base set title='$title[1]',content='$str',updatetime='$now',keywords='$keywords',description='$ds' where id='$id'";
$result=mysql_query($sql) or die(mysql_error());
if (mysql_affected_rows()>0)
{
echo "更新成功！";
}
else
{
echo "更新成功！";
}
mysql_close();
}
?>