discuz論壇,如果帖子里面含有flash視頻,當手機瀏覽器或微信里面瀏覽就是…
當前位置:網(wǎng)站首頁 > 幫助中心 > 正文
使用discuz論壇,如果帖子里面含有flash視頻,當在手機上瀏覽的時候,并不能顯示視頻出來,而是直接顯示視頻的原URL地址。下面,我們就來解決這個問題。
注意:我升級了discuz論壇程序,當前版本是3.3,別改錯了!
打開source/function/function_discuzcode.php,大概在205行
if(strpos($msglower, '[/flash]') !== FALSE) { $message = preg_replace("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", "[media]\\4[/media]", $message); }
通過這段可以發(fā)現(xiàn),論壇代碼只是把[flash]標簽中的內(nèi)容直接顯示出來了,我們只要進行相應的修改即可:
if(strpos($msglower, '[/flash]') !== FALSE) { $message = preg_replace_callback( "/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", 'discuzcode_callback_parseflash_h5', $message); }
在當前頁面最后,新增加函數(shù):discuzcode_callback_parseflash_h5
function discuzcode_callback_parseflash_h5($matches) { return '< iframe style="width:100%;height:280px;" src="'.getH5Url($matches[4]).'" data-ke-src="'.getH5Url($matches[4]).'" scrolling="no" frameborder="0" allowfullscreen>no iframe'; }
再通過解析出來的視頻地址,添加轉(zhuǎn)換函數(shù):getH5Url
function getH5Url($url) { if (stripos($url, 'youku') !== false) { $pattern = "/id_(.*?)\.html|sid\/(.*?)\/v/"; preg_match($pattern, $url, $result); if($result){ $url = 'http://player.youku.com/embed/' . ($result[1] ?: $result[2]); } } elseif (stripos($url, 'qq.com') !== false) { $pattern = "/vid=(.*?)\&/"; preg_match($pattern, $url, $result); if($result){ $url = 'https://v.qq.com/iframe/player.html?vid='.($result[1] ?: $result[2]).'&tiny=0&auto=0'; } } return $url; }
上面的代碼里,我只使用了優(yōu)酷和QQ視頻,其他網(wǎng)站的大家只要找到轉(zhuǎn)換規(guī)律自己添加上即可。
最后后,要想discuz論壇的微社區(qū)中也能正常播放視頻的話,還需要修改source/plugin/mobile/discuzcode.func.php文件中的129行,找到如下代碼并注釋掉。
if(strpos($msglower, '[/flash]') !== FALSE) { $message = preg_replace_callback("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", 'mobile_discuzcode_callback_bbcodeurl_4', $message); }
記住,修改前記得備份文件!!!
至此,discuz論壇帖子里面的視頻可以在手機瀏覽器或微信中訪問了!