dedecms拓展函数

有那么一个人出现在你的生命里,其他人都会变成风景,只有那个人是他心口的朱砂,放在心尖上的人,再也放不下。

这些函数是在一个视频站点中复制下来的,发布出来做一个备份,也许以后能用的上,至于函数的作用可以看一下具体代码,这里就不做解析了。

//解密js escape加密字符串
function unescape($str) {  
    $ret = '';  
    $len = strlen ( $str );  
    for($i = 0; $i < $len; $i ++) {  
        if ($str [$i] == '%' && $str [$i + 1] == 'u') {  
            $val = hexdec ( substr ( $str, $i + 2, 4 ) );  
            if ($val < 0x7f)  
                $ret .= chr ( $val );  
            else if ($val < 0x800)  
                $ret .= chr ( 0xc0 | ($val >> 6) ) . chr ( 0x80 | ($val & 0x3f) );  
            else  
                $ret .= chr ( 0xe0 | ($val >> 12) ) . chr ( 0x80 | (($val >> 6) & 0x3f) ) . chr ( 0x80 | ($val & 0x3f) );  
            $i += 5;  
        } else if ($str [$i] == '%') {  
            $ret .= urldecode ( substr ( $str, $i, 3 ) );  
            $i += 2;  
        } else  
            $ret .= $str [$i];  
    }  
    return $ret;  
}
//获取视频搜索结果列表
function get_videolist($str){
  global $cfg_cmsurl;
  $result="";
  foreach(explode('$@#$',$str) as $item){
     if(trim($item)=="") continue;
	 $arr=explode('$#',$item);
	 $link=$cfg_cmsurl."/play/".$arr[0];
	 $title=$arr[1];
	 $img=get_local_img($arr[2]);
	 $time=$arr[3];
	 $result.=' <li><a rel="nofollow noopener noreferrer" href="'.$link.'" class="img" title="'.$title.'" > <img src="'.$img.'" width="165" alt="'.$title.'" height="124" /> <label class="bg"></label> <label class="state">'.$time.'</label> </a> <h3>'.$title.'</h3></li> ';
  }
  return $result;
}
//获得视频详细信息html
function get_videodetail($str){
  global $cfg_cmsurl;
  $result="";
  foreach(explode('$@#$',$str) as $item){
     if(trim($item)=="") continue;
	 $arr=explode('$#',$item);
	 $link=$cfg_cmsurl."/play/".$arr[0];
	 $title=$arr[1];
	 $img=get_local_img($arr[2]);
	 $nianfen=$arr[3];
	 $pingfen=$arr[4];
     $star=get_star_html($pingfen);
	 $column=$arr[5];
	 $status=$arr[6];
	 $zhuyan=str_replace('/','',$arr[7]);
	 $diqu=$arr[8];
	 $leixing=str_replace('/','',$arr[9]);
	 $intro=$arr[10];
	 $result.='<div class="content"> <div class="detail"> <div class="picture"> <div class="pic"><img src="'.$img.'" width="128" height="182" alt="'.$title.'"></div> <span></span> </div> <div class="summary"> <h1><a rel="nofollow" rel="nofollow noopener noreferrer" href="'.$link.'">'.$title.'</a><span>('.$column.') '.$nianfen.'</span></h1> <p class="role"><span><strong>主演:</strong>'.$zhuyan.'</span>  </p> <p class="two"> <span><strong>更新:</strong><em>'.$status.'</em></span> <span><strong>类型:</strong>'.$leixing.'</span> <span><strong>地区:</strong>'.$diqu.'</span> </p> <p class="opera"><strong>剧情:</strong>'.$intro.'<span class="synopsis"><a rel="nofollow noopener noreferrer" href="'.$link.'" rel="nofollow">详细剧情</a></span></p> <p class="bf"><a title="快速观看" rel="nofollow" rel="nofollow noopener noreferrer" href="'.$link.'" class="playlink"></a> <a rel="nofollow noopener noreferrer" href="'.$cfg_cmsurl.'/plus/desktop.html?name='.$title.'" rel="nofollow" class="desktop"></a> </p> <div class="pingfen">'.$star.'&nbsp;<strong style="font-size:18px;color:red" id="MARK_B2">'.$pingfen.'</strong></div> </div> <div class="back"></div> </div> </div>';
  }
  return $result;
}
function get_star_html($pingfen){
     global $cfg_templets_skin;
	 $star0=(int)($pingfen/2);
	 $star1=(int)((10-$pingfen)/2);
	 $star2=5-$star0-$star1;
	 $html='';
	 for($i=0;$i<$star0;$i++){
	   $html.='<img src="'.$cfg_templets_skin.'/images/star0.gif">';
	 }
	 for($i=0;$i<$star2;$i++){
	   $html.='<img src="'.$cfg_templets_skin.'/images/star2.gif">';
	 }
	 for($i=0;$i<$star1;$i++){
	   $html.='<img src="'.$cfg_templets_skin.'/images/star1.gif">';
	 }
	 return $html;
}
function get_local_img($url){
   global $cfg_cmsurl;
   $result=$url;
   if(!strstr($url,'http://')&&!strstr($url,'/images/defaultpic.gif')){
    $result=$cfg_cmsurl.$url;
   }elseif(!strstr($url,'/images/defaultpic.gif')){
      //将远程地址替换为伪静态地址
	   $filename=basename($url);
	  $result=$cfg_cmsurl.'/static/'.$filename;
   }
   return $result;
}
function curl_get($url,$gzip=false){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  //抓取https网页
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //抓取https网页
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_REFERER,$url);
	curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; SeaPort/1.2; Windows NT 5.1; SV1; InfoPath.2)'); 
	curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
	curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
	if($gzip) curl_setopt($curl, CURLOPT_ENCODING, "gzip"); 
	$values = curl_exec($curl);
	curl_close($curl);
	return($values);
}
function curl_post($url,$post){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_REFERER,$url);
	curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; SeaPort/1.2; Windows NT 5.1; SV1; InfoPath.2)'); 
	curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
	curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
	curl_setopt($curl, CURLOPT_POST, 1);//post提交方式 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post); 	//指定post提交的参数
	$values = curl_exec($curl);
	curl_close($curl);
	return($values);
}
function get_baidu_keys($type){
   if($type=="all") $url="http://top.baidu.com/buzz?b=1";
   elseif($type=="week") $url="http://top.baidu.com/buzz?b=42";
   $html=curl_get($url);
   $html=iconv("GB2312","UTF-8//IGNORE",$html);
   preg_match_all('/<a class="list-title"(.*?)>(.*?)<\/a>/',$html,$arr);
   $data=$arr[2];
   return $data;
}
function get_rewrite_url($url){
  global $rewriteArr,$db;
  $re='';
  if(strstr($url,"list.php")){
    preg_match('/list.php\?tid=([\d]+)/',$url,$arr);
	$id=$arr[1];
	$sn=$rewriteArr[$id];
	$re=preg_replace('/plus\/list.php\?tid=([\d]+)/',$sn.'/',$url);
  }elseif(strstr($url,"view.php")){
    preg_match('/view.php\?aid=([\d]+)/',$url,$arr);
	$id=$arr[1];
	//查询出sn
	$row=$db->GetOne("select urlsn from dede_addonmovie where aid=$id");
	if(isset($row['urlsn'])) $sn=trim($row['urlsn']);
	$re=preg_replace('/plus\/view.php\?aid=([\d]+)/',$sn.'/',$url);
  }
  return $re;
}
function get_filter_title($typename){
  global $sn,$rewriteArr,$leixing;
  $sn=trim($sn);
  $re='';
  $arr=array_flip($rewriteArr);
  $tid=$arr[$sn];
  if(strstr($leixing,'剧')&&$tid==2) $re=$leixing;
  else  $re=$leixing.$typename;
  return $re;
} 

以上就是dedecms拓展函数。并肩走一段路的好,也是要被记住许多年甚至一辈子的。更多关于dedecms拓展函数请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
dedecms如何实现任意页面调用当前会员信息的方

DedeCMS织梦判断是否有二级栏目输出HTML代码

织梦dedecms dede:arclist输出取消换行符

dedecms文章添加字段填栏目id,内容页调用字段里的栏目文章

dedeCMS首页列表页文章页调用tag的方法