uchome2.0 分享部分增加视频缩图

uchome 原版在分享视频的时候显示的是默认一张图片而不是视频展示图;

而kaixin001、校内等sns 转载视频就有这个功能,今天找了一下资料整理如下:目前可支持youku,tudou,ku6,mofile视频网站

此方法需要空间支持file_get_contents函数;

实现显示如下:

 

 

 

1. 修改cp_share.php 408行起以下内容

if(preg_match("/(youku.com|youtube.com|5show.com|ku6.com|sohu.com|mofile.com|sina.com.cn)$/i", $parseLink['host'], $hosts)) {

$flashvar = getflash($link, $hosts[1]);

if(!empty($flashvar)) {

    $arr['title_template'] = cplang('share_video');

    $type = 'video';

    $arr['body_data']['flashvar'] = $flashvar;

    $arr['body_data']['host'] = $hosts[1];

}

}

修改为:

if(preg_match("/(youku.com|youtube.com|5show.com|ku6.com|sohu.com|mofile.com|sina.com.cn|tudou.com)$/i", $parseLink['host'], $hosts)) {

$flashvar = getflash($link, $hosts[1]);

$flashimg = getflashimg($link, $hosts[1]);

   if(!empty($flashvar)) {

       $arr['title_template'] = cplang('share_video');

       $type = 'video';

       $arr['body_data']['flashvar'] = $flashvar;
 
       $arr['body_data']['host'] = $hosts[1];

         if(!empty($flashimg)){

              $arr['image'] = $flashimg;
           }
     }
}

2.  修改 getflash() 函数 并增加  getflashimg()函数

function getflash($link, $host)
{
 $return = '';
if('youku.com' == $host) {
 preg_match_all("/id/_(/w+)[=.]/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('ku6.com' == $host) {
 preg_match_all("///([/w/-]+)/.html/", $link, $matches);
 if(1 > preg_match("///index_([/w/-]+)/.html/", $link) && !empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('youtube.com' == $host) {
 preg_match_all("/v/=([/w/-]+)/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('5show.com' == $host) {
 preg_match_all("///(/d+)/.shtml/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('mofile.com' == $host) {

 preg_match_all("///([/w/-]+)/.shtml/", $link, $matches);

 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('sina.com.cn' == $host) {
 preg_match_all("///(/d+)-(/d+)/.html/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
} elseif('sohu.com' == $host) {
 preg_match_all("///(/d+)//*$/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
}
elseif('tudou.com' == $host) {
 preg_match_all("///([/w/-]+)//*$/", $link, $matches);
 if(!empty($matches[1][0])) {
  $return = $matches[1][0];
 }
}


return $return;
}

 

function getflashimg($link, $host)
{
 $return='';
 $content = file_get_contents($link);//获取
 if ('tudou.com' == $host)
 {
  preg_match_all("/<span class=/"s_pic/">(.*?)<//span>/i",$content,$img);
 }
 elseif('youku.com' == $host)
 {
  preg_match_all("//+0800/|(.*?)/|/">/i",$content,$img);
 }
 elseif('ku6.com' == $host)
 {
  preg_match_all("/<span class=/"s_pic/">(.*?)<//span>/i",$content,$img);
 }
 elseif('mofile.com' == $host)
 {
  preg_match_all("/thumbpath=/"(.*?)/";/i",$content,$img);
 }
 if(!empty($img[1][0])) {
  $return = $img[1][0];
 }
 return $return;
}

3.修改模板文件space_share_li.htm 找到(大约15行):

 

<!--{if $value['image'] && 'video'!=$value['type']}-->
  <a href="$value[image_link]"><img src="$value[image]" class="summaryimg image" alt="" width="70" /></a>
 <!--{/if}-->

 

(22行视频)

 

<!--{if 'video' == $value['type']}-->
 <div class="media">
  <img src="<!--{if !empty($value['image'])}-->$value[image]<!--{else}-->/image/vd.gif<!--{/if}-->" onclick="javascript:showFlash('{$value['body_data']['host']}', '{$value['body_data']['flashvar']}', this, '{$value['sid']}');" alt="点击播放" style="cursor:pointer;" />
 </div>

4. 最后是修改space_feed_li.htm

 

(27行左右)

<!--{if $value['image_1'] && empty($value['body_data']['flashvar'])}-->
   <a href="$value[image_1_link]"{$value[target]}><img src="$value[image_1]" class="summaryimg" /></a>
   <!--{/if}-->

(47行左右)

<!--{if $value['thisapp'] && !empty($value['body_data']['flashvar'])}-->
   <div class="media">   
    <img src="<!--{if !empty($value['image_1'])}-->$value[image_1]<!--{else}-->/image/vd.gif<!--{/if}-->" alt="点击播放" onclick="javascript:showFlash('{$value['body_data']['host']}', '{$value['body_data']['flashvar']}', this, '{$value['feedid']}');" style="cursor:pointer;" />
   </div>

至此修改完成;

此修改是针对 uchome 2.0 实现的 与 1.5 版可能会有所出入;具体实现自行更改;;;;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

维课思AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值