搞机社 编程语言 在dokuwiki & bootstrap3模板中添加复制短链接功能
一、修改 index.php
//在 dokuwiki/indexphp 中添加以下代码
$shortId = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if(preg_match('/\/[a-z0-5]{6}/', $shortId)) {
header("Location: /x.php?id=" . $shortId);
exit;
}
二、修改 bootstrap 模板
//在 dokuwiki/lib/tpl/bootstrap3/tpl/page-icons.php 中添加以下代码
<?php
$shorturl =& plugin_load('helper', 'shorturl');//复制短链接
if ($shorturl) {
$shortID = $shorturl->autoGenerateShortUrl($ID);
$schema = $_SERVER['HTTPS'] ? 'https://' : 'http://';
$shortUrl = $schema . $_SERVER['HTTP_HOST'] . '/' . $shortID;
//echo $shortUrl;
echo "<li>";
echo "<input type=\"text\" id=\"short-url\" value=\"{$shortUrl}\" style=\"position: absolute; top: 0; left: 0; opacity: 0; z-index: -10;\"/>";
echo "<button id=\"copy-url-btn\" onclick=\"copyShortUrl()\" src=\"{$shortUrl}\">复制短链</button>";
echo "</li>";
}
?>
//JS 代码
<scrip t>
function copyShortUrl() { //复制短链接
var obj = document.getElementById("short-url");
obj.select();
document.execCommand("Copy");
document.getElementById("copy-url-btn").innerText = "已复制";
}
</scrip>
幸运之星正在降临...
点击领取今天的签到奖励!
恭喜!您今天获得了{{mission.data.mission.credit}}积分
-
限制以下商品使用:
限制以下商品分类使用:
不限制使用:
所有商品和商品类型均可使用