Typehco 自定义UBB短代码函数
1年前
这只是实现UBB短代码中的一种方法,其中样式问题请自行修改。
//自定义ubb代码函数演示
function ubb($nr){
if (strpos($nr, '{wy') !== false) {
$nr = preg_replace('/{wy id="(.+?)"}/',"<audio id=\"media\" src=\"http://music.163.com/song/media/outer/url?id=\\1.mp3\" controls=\"controls\" style=\"width:98%\"><这里是一段音乐,由于您的浏览器原因不能显示播放器></audio>", $nr);
}
if (strpos($nr, '{bl') !== false) {
$nr = preg_replace('/{bl av="(.+?)"}/',"<iframe class='iframe_video' src=\"//player.bilibili.com/player.html?aid=\\1&page=1\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\"> </iframe>", $nr);
$nr = preg_replace('/{bl bv="(.+?)"}/',"<iframe class='iframe_video' src=\"//player.bilibili.com/player.html?bvid=\\1&page=1\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\"> </iframe>", $nr);
}
if (strpos($nr, '{wl') !== false) {
$nr = preg_replace('/{wl url="(.+?)"}(.+?){\/wl title="(.+?)"}/',"<div class='xm_cloud'><div class='xm_cloud__logo _lz'></div><div class='xm_cloud__describe'><div class='xm_cloud__describe-title'><a href='\\1' target='_blank' rel='noopener noreferrer nofollow'>\\3</a></div><div class='xm_cloud__describe-type'>来源:\\2</div></div><a class='xm_cloud__btn' href='\\1' target='_blank' rel='noopener noreferrer nofollow'>下</a></div>", $nr);
}
if (strpos($nr, '{url') !== false) {
$nr = preg_replace('/{url url="(.+?)"}(.+?){\/url title="(.+?)"}/',"<a target='_blank' href='\\1' class='LinkCard'><span class='LinkCard-content'><span class='LinkCard-text'><span class='LinkCard-title'>\\2</span><span class='LinkCard-excerpt ell'>\\3</span><span class='LinkCard-meta'><span style='display:inline-flex;margin-top: 2px;margin-right: 5px;'><svg fill='currentColor' viewBox='0 0 24 24' width='17' height='17'><path d='M6.77 17.23c-.905-.904-.94-2.333-.08-3.193l3.059-3.06-1.192-1.19-3.059 3.058c-1.489 1.489-1.427 3.954.138 5.519s4.03 1.627 5.519.138l3.059-3.059-1.192-1.192-3.059 3.06c-.86.86-2.289.824-3.193-.08zm3.016-8.673l1.192 1.192 3.059-3.06c.86-.86 2.289-.824 3.193.08.905.905.94 2.334.08 3.194l-3.059 3.06 1.192 1.19 3.059-3.058c1.489-1.489 1.427-3.954-.138-5.519s-4.03-1.627-5.519-.138L9.786 8.557zm-1.023 6.68c.33.33.863.343 1.177.029l5.34-5.34c.314-.314.3-.846-.03-1.176-.33-.33-.862-.344-1.176-.03l-5.34 5.34c-.314.314-.3.846.03 1.177z' fill-rule='evenodd'></path></svg></span><span>\\1</span></span></span><span class='LinkCard-imageCell'><span class='LinkCard-image LinkCard-image-default'><svg fill='currentColor' viewBox='0 0 24 24' width='32' height='32'><path d='M11.991 3C7.023 3 3 7.032 3 12s4.023 9 8.991 9C16.968 21 21 16.968 21 12s-4.032-9-9.009-9zm6.237 5.4h-2.655a14.084 14.084 0 0 0-1.242-3.204A7.227 7.227 0 0 1 18.228 8.4zM12 4.836A12.678 12.678 0 0 1 13.719 8.4h-3.438A12.678 12.678 0 0 1 12 4.836zM5.034 13.8A7.418 7.418 0 0 1 4.8 12c0-.621.09-1.224.234-1.8h3.042A14.864 14.864 0 0 0 7.95 12c0 .612.054 1.206.126 1.8H5.034zm.738 1.8h2.655a14.084 14.084 0 0 0 1.242 3.204A7.188 7.188 0 0 1 5.772 15.6zm2.655-7.2H5.772a7.188 7.188 0 0 1 3.897-3.204c-.54.999-.954 2.079-1.242 3.204zM12 19.164a12.678 12.678 0 0 1-1.719-3.564h3.438A12.678 12.678 0 0 1 12 19.164zm2.106-5.364H9.894A13.242 13.242 0 0 1 9.75 12c0-.612.063-1.215.144-1.8h4.212c.081.585.144 1.188.144 1.8 0 .612-.063 1.206-.144 1.8zm.225 5.004c.54-.999.954-2.079 1.242-3.204h2.655a7.227 7.227 0 0 1-3.897 3.204zm1.593-5.004c.072-.594.126-1.188.126-1.8 0-.612-.054-1.206-.126-1.8h3.042c.144.576.234 1.179.234 1.8s-.09 1.224-.234 1.8h-3.042z'></path></svg></span></span></span></a>", $nr);
}
if (strpos($nr, '{tab') !== false) {
/*tab自定义配套ubb*/
$nr = preg_replace('/{tab}(.+?){\/tab}/s',"<div class='tpt-bar'>\\1</div>", $nr);
$nr = preg_replace('/{taba id="(.+?)"}(.+?){\/taba title="(.+?)"}/s',"<input type='radio' name='bar' id='tab-\\1'><label for='tab-\\1'>\\3</label><div class='tpt-bar-con'>\\2</div>
", $nr);
$nr = preg_replace('/{tabb id="(.+?)"}(.+?){\/tabb title="(.+?)"}/s',"<input type='radio' name='bar' id='tab-\\1' checked=''><label for='tab-\\1'>\\3</label><div class='tpt-bar-con'>\\2</div>
", $nr);
}
return $nr;
}
添加下面这段代码,不然文章列表显示的时候会暴露UBB代码中的内容。
//隐藏相关自定义ubb代码内容
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('myyodux','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('myyodux','one');
class myyodux {
public static function one($con,$obj,$text){
$text = empty($text)?$con:$text;
if(!$obj->is('single')){
$text = preg_replace('/{tab}(.+?){\/tab}/sm','',$text);
$text = preg_replace('/{taba id="(.+?)"}(.+?){\/taba title="(.+?)"}/sm','',$text);
$text = preg_replace('/{tabb id="(.+?)"}(.+?){\/tabb title="(.+?)"}/sm','',$text);
$text = preg_replace('/{url url="(.+?)"}(.+?){\/url title="(.+?)"}/sm','',$text);
$text = preg_replace('/{wl url="(.+?)"}(.+?){\/wl title="(.+?)"}/sm','',$text);
$text = preg_replace('/{bl bv="(.+?)"}/sm','',$text);
$text = preg_replace('/{bl av="(.+?)"}/sm','',$text);
$text = preg_replace('/{wy id="(.+?)"}/sm','',$text);
}
return $text;
}
}