在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>
编程语言

Linux 国内源一键安装docker及docker-compose Debian11

2022-5-20 8:33:16

编程语言

VSCODE Dendron 笔记个人知识管理工具插件快速使用指南

2022-12-7 8:59:00

3 条回复 A文章作者 M管理员
  1. I do trust all the ideas youve presented in your post They are really convincing and will definitely work Nonetheless the posts are too short for newbies May just you please lengthen them a bit from next time Thank you for the post

  2. function copyShortUrl() { //复制短链接
    var obj = document.getElementById("short-url");
    obj.select();
    document.execCommand("Copy");
    document.getElementById("copy-url-btn").innerText = "已复制";
    }

    这部分代码错误

    前面多了个空格 后面少了个t

    • script

有新私信 私信列表
搜索