2021-01-29 15:38:41 +00:00
|
|
|
<?php
|
|
|
|
|
2021-02-06 10:33:20 +00:00
|
|
|
function _parseContent($post, $login)
|
2021-01-29 15:38:41 +00:00
|
|
|
{
|
2021-02-06 10:33:20 +00:00
|
|
|
/* 优先判断文章内是否有回复可见的内容 */
|
|
|
|
$content = $post->content;
|
2021-02-18 13:28:07 +00:00
|
|
|
|
|
|
|
/* 过滤表情 */
|
|
|
|
$content = _parseReply($content);
|
|
|
|
|
2021-02-21 09:45:35 +00:00
|
|
|
/* 过滤默认卡片 */
|
|
|
|
if (strpos($content, '{/card-default}') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{card-default\s*width="(.*)"\s*label="(.*)"\s*\}(.*)\{\/card-default\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<span class="joe_detail__article-card block" style="width: ' . $matches[1] . '">
|
|
|
|
<span class="title block">' . $matches[2] . '</span>
|
|
|
|
<span class="content block">' . $matches[3] . '</span>
|
|
|
|
</span>
|
|
|
|
';
|
|
|
|
},
|
2021-01-29 15:38:41 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤消息提示 */
|
|
|
|
if (strpos($content, '{/message}') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{message\s*type="(success|info|warning|error)"\s*\}(.*)\{\/message\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<span class="joe_detail__article-message block ' . $matches[1] . '">
|
|
|
|
<span class="icon"></span>
|
|
|
|
<span class="content">' . $matches[2] . '</span>
|
|
|
|
</span>
|
|
|
|
';
|
|
|
|
},
|
2021-02-01 13:24:49 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤note button */
|
|
|
|
if (strpos($content, '{/anote}') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{anote\s*icon="(.*)"\s*href="(.*)"\s*type="(secondary|success|warning|error|info)"\s*}(.*)\{\/anote\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<a class="joe_detail__article-anote ' . $matches[3] . '" href="' . $matches[2] . '" target="_blank" rel="noopener noreferrer nofollow">
|
|
|
|
<span class="icon"><i class="fa ' . $matches[1] . '"></i></span><span class="content">' . $matches[4] . '</span>
|
|
|
|
</a>
|
|
|
|
';
|
|
|
|
},
|
2021-02-01 13:24:49 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤普通button */
|
|
|
|
if (strpos($content, '{/abtn}') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{abtn\s*icon="(.*)"\s*color="(.*)"\s*href="(.*)"\s*radius="(.*)"\s*\}(.*)\{\/abtn\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<a class="joe_detail__article-abtn" style="background: ' . $matches[2] . '; border-radius: ' . $matches[4] . '" href="' . $matches[3] . '" target="_blank" rel="noopener noreferrer nofollow">
|
|
|
|
<span class="icon"><i class="' . $matches[1] . ' fa"></i></span><span class="content">' . $matches[5] . '</span>
|
|
|
|
</a>
|
|
|
|
';
|
|
|
|
},
|
2021-02-05 02:29:26 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤回复可见 */
|
|
|
|
if (strpos($content, '{/hide}') !== false) {
|
|
|
|
$db = Typecho_Db::get();
|
|
|
|
$hasComment = $db->fetchAll($db->select()->from('table.comments')->where('cid = ?', $post->cid)->where('mail = ?', $post->remember('mail', true))->limit(1));
|
|
|
|
if ($hasComment || $login) {
|
|
|
|
$content = strtr($content, array("{hide}" => "", "{/hide}" => ""));
|
|
|
|
} else {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{hide\}.*\{\/hide\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function () {
|
|
|
|
return '<span class="joe_detail__article-hide block">此处内容作者设置了 <i>回复</i> 可见</span>';
|
|
|
|
},
|
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-05 02:29:26 +00:00
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤网易云音乐 */
|
|
|
|
if (strpos($content, '{music') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{music-list\s*id="(\w*)"\s*\/\}/SU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
2021-02-22 04:57:50 +00:00
|
|
|
return '<iframe class="lazyload" data-src="//music.163.com/outchain/player?type=0&id=' . $matches[1] . '&auto=0&height=430" width="330" height="450"></iframe>';
|
2021-02-21 09:45:35 +00:00
|
|
|
},
|
2021-02-05 10:27:44 +00:00
|
|
|
$content
|
|
|
|
);
|
2021-02-21 09:45:35 +00:00
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{music\s*id="(\w*)"\s*\/\}/SU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
2021-02-22 04:57:50 +00:00
|
|
|
return '<iframe class="lazyload" data-src="//music.163.com/outchain/player?type=2&id=' . $matches[1] . '&auto=0&height=66" width="330" height="86"></iframe>';
|
2021-02-21 09:45:35 +00:00
|
|
|
},
|
2021-02-05 10:27:44 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤dplayer播放器 */
|
|
|
|
if (strpos($content, '{dplayer') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{dplayer\s*src="(.*)"\s*\/\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
$player = Helper::options()->JCustomPlayer ? Helper::options()->JCustomPlayer : '/usr/themes/Joe/library/player.php?url=';
|
|
|
|
return '<iframe class="joe_detail__article-player block lazyload" allowfullscreen="true" data-src="' . $player . $matches[1] . '"></iframe>';
|
|
|
|
},
|
2021-02-05 12:12:22 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤bilibili播放器 */
|
|
|
|
if (strpos($content, '{bilibili') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{bilibili\s*bvid="(\w*)"\s*\/\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<iframe class="joe_detail__article-player block lazyload" allowfullscreen="true" data-src="//player.bilibili.com/player.html?bvid=' . $matches[1] . '"></iframe>';
|
|
|
|
},
|
2021-02-06 10:33:20 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤完成任务勾选 */
|
|
|
|
if (strpos($content, '{x}') !== false || strpos($content, '{ }') !== false) {
|
|
|
|
$content = strtr($content, array(
|
|
|
|
"{x}" => '<input type="checkbox" class="joe_detail__article-checkbox" checked disabled></input>',
|
|
|
|
"{ }" => '<input type="checkbox" class="joe_detail__article-checkbox" disabled></input>'
|
|
|
|
));
|
2021-02-06 12:30:38 +00:00
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
2021-02-07 09:32:06 +00:00
|
|
|
/* 过滤复制粘贴功能 */
|
2021-02-21 09:45:35 +00:00
|
|
|
if (strpos($content, '{/copy}') !== false) {
|
|
|
|
$content = preg_replace_callback(
|
2021-02-21 13:26:30 +00:00
|
|
|
'/\{copy\s*text="(.*)"\s*\}(.*)\{\/copy\}/sSU',
|
2021-02-21 09:45:35 +00:00
|
|
|
function ($matches) {
|
|
|
|
return '<span data-clipboard-text="' . $matches[1] . '" class="joe_detail__article-copy">' . $matches[2] . '</span>';
|
|
|
|
},
|
2021-02-07 09:32:06 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
2021-02-21 09:45:35 +00:00
|
|
|
|
|
|
|
/* 过滤居中标题 */
|
|
|
|
if (strpos($content, '{/mtitle}') !== false) {
|
|
|
|
$content = strtr($content, array(
|
|
|
|
"{mtitle}" => '<span class="joe_detail__article-mtitle"><span class="text">',
|
|
|
|
"{/mtitle}" => '</span></span>'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2021-02-06 10:33:20 +00:00
|
|
|
echo $content;
|
2021-01-29 15:38:41 +00:00
|
|
|
}
|