今天接到个SEO一个任务,让后台的文章列表显示百度是否收录。捣腾了一会。结果,FTP没上传php的权限,先存这里吧。下面代码加到include/extend.func.php结尾:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<?php function litimgurls($imgid=0) { global $lit_imglist,$dsql; //获取附加表 $row = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c ON a.channel=c.id where a.id='$imgid'"); $addtable = trim($row['addtable']); //获取图片附加表imgurls字段内容进行处理 $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'"); //调用inc_channel_unit.php中ChannelUnit类 $ChannelUnit = new ChannelUnit(2,$imgid); //调用ChannelUnit类中GetlitImgLinks方法处理缩略图 $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']); //返回结果 return $lit_imglist; } function GetOneDocUrl($aid) { global $dsql; include_once(DEDEINC."/channelunit.func.php"); $aid = trim(ereg_replace('[^0-9]','',$aid)); $chRow = $dsql->GetOne("Select arc.*,ch.maintable,ch.addtable,ch.issystem From `#@__arctiny` arc left join `#@__channeltype` ch on ch.id=arc.channel where arc.id='$aid' "); if(!is_array($chRow)) { return $reArr; } else { if(empty($chRow['maintable'])) $chRow['maintable'] = '#@__archives'; } if($chRow['issystem']!=-1) { $nquery = " Select arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath From `{$chRow['maintable']}` arc left join `#@__arctype` tp on tp.id=arc.typeid where arc.id='$aid' "; } else { $nquery = " Select arc.*,1 as ismake,0 as money,'' as filename,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath From `{$chRow['addtable']}` arc left join `#@__arctype` tp on tp.id=arc.typeid where arc.aid='$aid' "; } $arcRow = $dsql->GetOne($nquery); $url = GetFileUrl($aid,$arcRow['typeid'],$arcRow['senddate'],$reArr['title'],$arcRow['ismake'],$arcRow['arcrank'],$arcRow['namerule'],$arcRow['typedir'],$arcRow['money'],$arcRow['filename'],$arcRow['moresite'],$arcRow['siteurl'],$arcRow['sitepath']); $url='http://www.baidu.com/s?wd='.$arcRow['siteurl'].$url; $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); $rs=curl_exec($curl); curl_close($curl); $arr=parse_url($url); if(strpos($arr['query'],'http://')){ $arr['query']=str_replace('http://','',str_replace('wd=','',$arr['query'])); }else{ $arr['query']=str_replace('wd=','',$arr['query']); } if(strpos($arr['query'],'?')){ $str=strstr($arr['query'],'?'); $arr['query']=str_replace($str,'',$arr['query']); } if(strpos($arr['query'],'/')){ $narr=explode('/',$arr['query']); $arr['query']=$narr[0]; } if(strpos($rs,'<b>'.$arr['query'].'</b>')){ return "已收录"; }else{ return "<font color='#FF0000'>未收录</font>"; } } |
然后是后台模版代码:
1 |
{dede:field.id function='GetOneDocUrl(@me)'/} |
加到content_list.htm相应位置,OK大功告成。