大家好,我想在我的插件里面改个东西,能不能在标题前面插入我要的关键词?
set_time_limit(270);
error_reporting(E_ERROR|E_WARNING|E_PARSE);
define('TITLE_SEPAR','xxx**xxx');
define('TITLE_SEPAR2','262661');
$url='这里填写你的小发猫伪原创API地址';
$content_tag_name='内容';
$headdd='';
$taill='';
switch($LabelArray['PageType'])
{
case'List'://处理列表页,只能处理html
break;
case'Pages'://处理多页,只能处理html
break;
case'Content'://处理默认页,只能处理html
break;
case'Save'://只有保存时是可以处理标签值的
//保存原文
try{
/**********************************************************************/
//这一步用来获取伪原创文章
/**********************************************************************/
$title=$LabelArray['标题'];
$title='标题:'.$title;
$content=$LabelArray[$content_tag_name];
$article_src=compose_article($title,$content);
$article_src_b=$article_src;
$article_new=get_wyc_article($article_src);
$title_wyc=trim($article_new[0]);
$content_wyc=trim($article_new[1]);
$content_wyc=fix_newline($content_wyc);
$LabelArray[$content_tag_name]=$headdd.$content_wyc.$taill;
$title_wyc=str_replace(array('。',',','%'),array('','',''),$title_wyc);
$LabelArray['标题']=$title_wyc;
}
catch(Exception$e){
$LabelArray['标题'].=$e->getMessage();
$LabelArray[$content_tag_name].=$e->getMessage();
}
break;
default:
//$LabelArray[$content_tag_name]=curl_request($url,array('wenzhang'=>$LabelArray[$content_tag_name]));
}
echoserialize($LabelArray);
functioncompose_article($title,$content){
$separator=compose_separator();
return$title.$separator.$content;
}
functioncompose_separator(){
returnPHP_EOL.'('.TITLE_SEPAR2.')'.PHP_EOL;
}
functionfix_separator($article){
return$article;
}
functionget_wyc_article($str){
global$url;
$separator=compose_separator();
$separator=str_replace(PHP_EOL,'',$separator);
$wyc=curl_request($url,array('wenzhang'=>$str));
$wyc_f=$wyc;
$wyc=fix_separator($wyc);
$wyc=explode($separator,$wyc);
if(isset($wyc[0])){
$wyc[0]=trim($wyc[0]);
$wyc[0]=ltrim($wyc[0],'标题');
$wyc[0]=ltrim($wyc[0],'目:');
$wyc[0]=ltrim($wyc[0],':');
$wyc[0]=ltrim($wyc[0],':');
}
//if(isset($wyc[1]))$wyc[1]=trim($wyc[1]);
//$wyc[1]=$wyc_f.'jjjjjjjj'.$wyc[1];
return$wyc;
}
functionget_wyc_title($str){
$title=get_wyc_article($str.PHP_EOL.PHP_EOL.PHP_EOL.$str.PHP_EOL.PHP_EOL.PHP_EOL.$str);
$title=fix_newline($title);
$title=explode(PHP_EOL,$title);
return$title[0];
}
functionget_keywords($title,$contents){
$url_kw='xx';
$kws=curl_request($url_kw,array(
'title'=>$title,
'len'=>100,
'text'=>$contents));
return$kws;
}
functionremove_alt($contents){
$contents=preg_replace('/alt=\"(.*)\"/','',$contents);
return$contents;
}
functionfix_title($contents){
$punctuation_symbol=array('。','?',',',':',';','、','!',
'.','?',',',':',';','!');
$contents=str_replace($punctuation_symbol,'',$contents);
return$contents;
}
functionbr2newline($contents){
$contents=str_replace('
',PHP_EOL,$contents);
$contents=str_replace('
',PHP_EOL,$contents);
$contents=str_replace('
',PHP_EOL,$contents);
$contents=str_replace('
',PHP_EOL,$contents);
$contents=str_replace('
',PHP_EOL,$contents);
$contents=str_replace('
',PHP_EOL,$contents);
return$contents;
}
functionnewline2br($contnets){
$contnets=str_replace(PHP_EOL,"
",$contnets);
//$contnets=str_replace('>
$contnets=str_replace('
','
',$contnets);
return$contnets;
}
functiondelete_newline($contents){
$contents=fix_newline($contents);
//$contents=str_replace(PHP_EOL.PHP_EOL,PHP_EOL,$contents);
//$contents=str_replace('>'.PHP_EOL,'>',$contents);
return$contents;
}
functionreset_newline_win($contents){
//优化换行符
$contents=str_replace("\r\n","\n",$contents);
$contents=str_replace("\r","\n",$contents);
$contents=str_replace("\n",PHP_EOL,$contents);
return$contents;
}
functionfix_newline($data){
$data=str_replace("\r","\n",$data);
while(strpos($data,"\n\n")!==false){
$data=str_replace("\n\n","\n",$data);
}
$data=str_replace("\n",PHP_EOL,$data);
return$data;
}
functionclean_contents($contents){
//$str=preg_replace('#\s/]+)[^>]*>#','',$contents);
//return$str;
$sa=newcleanHtml;
$sa->allow=array('src');
$sa->exceptions=array(
'img'=>array('src','alt'),
//'a'=>array('href','title'),
'iframe'=>array('src','frameborder'),
);
$str=$sa->strip($contents);
return$str;
}
functionxfm_strong_str_replace_once($search,$replace,$subject){
$firstChar=strpos($subject,$search);
if($firstChar!==false){
$beforeStr=substr($subject,0,$firstChar);
$afterStr=substr($subject,$firstChar+strlen($search));
return$beforeStr.$replace.$afterStr;
}else{
return$subject;
}
}
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
functioncurl_request($url,$post='',$cookie='',$returnCookie=0){
if(!extension_loaded('curl')){
file_exists('./ext/php_curl.dll')&&dl('php_curl.dll');//加载扩展
}
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0(compatible;MSIE10.0;WindowsNT6.1;Trident/6.0)');
if(ini_get('open_basedir')==''&&strtolower(ini_get('safe_mode'))!='on'){
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
}
curl_setopt($curl,CURLOPT_AUTOREFERER,1);
curl_setopt($curl,CURLOPT_REFERER,"http://XXX");
if($post){
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post));
}
if($cookie){
curl_setopt($curl,CURLOPT_COOKIE,$cookie);
}
curl_setopt($curl,CURLOPT_HEADER,$returnCookie);
curl_setopt($curl,CURLOPT_TIMEOUT,150);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($curl);
if(curl_errno($curl)){
returncurl_error($curl);
}
curl_close($curl);
if($returnCookie){
list($header,$body)=explode("\r\n\r\n",$data,2);
preg_match_all("/Set\-Cookie:([^;]*);/",$header,$matches);
$info['cookie']=substr($matches[1][0],1);
$info['content']=$body;
return$info;
}else{
return$data;
}
}
//echo$tag;
//计算中文字符串长度
functionutf8_strlen($string=null){
//将字符串分解为单元
preg_match_all("/./us",$string,$match);
//返回单元个数
returncount($match[0]);
}
functionreg_escape($str)
{
$conversions=array("^"=>"\^","["=>"\[","."=>"\.","$"=>"\$","{"=>"\{","*"=>"\*","("=>"\(","\\"=>"\\\\","/"=>"\/","+"=>"\+",")"=>"\)","|"=>"\|","?"=>"\?",""\"=>"\>");
returnstrtr($str,$conversions);
}
/**
*StripattributeClass
*RemoveattributesfromXMLelements
*@authorDavid(semlabs.co.uk)
*@version0.2.1
*/
classcleanHtml{
public$str='';
public$allow=array();
public$exceptions=array();
public$ignore=array();
publicfunctionstrip($str)
{
$this->str=$str;
if(is_string($str)&&strlen($str)>0)
{
$res=$this->findElements();
if(is_string($res))
return$res;
$nodes=$this->findAttributes($res);
$this->removeAttributes($nodes);
}
return$this->str;
}
privatefunctionfindElements()
{
#Createanarrayofelementswithattributes
$nodes=array();
preg_match_all("/\n]+)([^>]*)>/i",$this->str,$elements);
foreach($elements[1]as$el_key=>$element)
{
if($elements[2][$el_key])
{
$literal=$elements[0][$el_key];
$element_name=$elements[1][$el_key];
$attributes=$elements[2][$el_key];
if(is_array($this->ignore)&&!in_array($element_name,$this->ignore))
$nodes[]=array('literal'=>$literal,'name'=>$element_name,'attributes'=>$attributes);
}
}
#ReturntheXMLiftherewerenoattributestoremove
if(!$nodes[0])
return$this->str;
else
return$nodes;
}
privatefunctionfindAttributes($nodes)
{
#Extractattributes
foreach($nodesas&$node)
{
preg_match_all("/([^=]+)\s*=\s*[\"|']{0,1}([^\"']*)[\"|']{0,1}/i",$node['attributes'],$attributes);
if($attributes[1])
{
foreach($attributes[1]as$att_key=>$att)
{
$literal=$attributes[0][$att_key];
$attribute_name=$attributes[1][$att_key];
$value=$attributes[2][$att_key];
$atts[]=array('literal'=>$literal,'name'=>$attribute_name,'value'=>$value);
}
}
else
$node['attributes']=null;
$node['attributes']=$atts;
unset($atts);
}
return$nodes;
}
privatefunctionremoveAttributes($nodes)
{
#Removeunwantedattributes
foreach($nodesas$node)
{
#Checkifnodehasanyattributestobekept
$node_name=$node['name'];
$new_attributes='';
if(is_array($node['attributes']))
{
foreach($node['attributes']as$attribute)
{
if((is_array($this->allow)&&in_array($attribute['name'],$this->allow))||$this->isException($node_name,$attribute['name'],$this->exceptions))
$new_attributes=$this->createAttributes($new_attributes,$attribute['name'],$attribute['value']);
}
}
$replacement=($new_attributes)?"":"";
$this->str=preg_replace('/'.reg_escape($node['literal']).'/',$replacement,$this->str);
}
}
privatefunctionisException($element_name,$attribute_name,$exceptions)
{
if(array_key_exists($element_name,$this->exceptions))
{
if(in_array($attribute_name,$this->exceptions[$element_name]))
returntrue;
}
returnfalse;
}
privatefunctioncreateAttributes($new_attributes,$name,$value)
{
if($new_attributes)
$new_attributes.="";
$new_attributes.="$name=\"$value\"";
return$new_attributes;
}
}
?>
php标题伪原创 火车头伪原创插件PHP版 如何在标题前面插入关键词?(悬赏1元) - 搜外SEO问答...