formula21 / yourls-qr-thumbnail-plugin-with-preview-redirect
YOURLS 插件,集成 QR 插件、缩略图插件,并将两者结合以制作预览页面,可以在重定向前或通过预览字符强制查看。
Requires
- guzzlehttp/guzzle: ^7.0
README
描述
当你使用短链接如 https://sho.rt/mylink
并重定向到 https://www.example.com/redirect-with-shortlink/long-link/my-link
时,用户永远不会知道这个重定向。为了在您的用户之上添加一层信任,我向您介绍 预览和重定向插件(带有二维码、缩略图生成、预预览和强制预览[互补])。
特性(很多!)
- 支持通过在短链接中添加
.i
生成缩略图。 - 支持通过在短链接末尾添加
.qr
生成二维码。 - 支持预览和重定向
- 这可以通过在短链接末尾添加
~
字符来完成。(这是默认引起的行为) - 您可以选择在重定向前自动预览预设默认秒数。
- 这可以通过在短链接末尾添加
启用和禁用
- 如果您想启用
QR (.qr)
生成,则需要修改users/config.php
,添加以下内容
# Defining the constant to disable QR feature define('F21_QR_PLUGIN', true); // true -> enabled, false -> disabled (default).
默认:插件已禁用。
- 如果您想启用
缩略图 (.i) 生成插件
,则需要修改users/config.php
,添加以下内容
# Defining the constant to disable thumbnail feature. define('F21_THUMB_PLUGIN', true); // true -> enabled, false -> disabled (default).
默认:插件已禁用。
-
如果您选择自定义重定向前的预览,以下应予以注意
- 默认情况下,重定向前的自动预览是 禁用 的。要启用,请使用以下代码在
users/config.php
中。
# Defining the constant to enable preview before redirect define('F21_PREVIEW_REDIRECT', true); // false -> disabled (default), true -> enabled.
- 您还可以更改显示预览页面前的等待时间,然后自动重定向。
# Modifying the wait time (0) means disabled, i.e. the user needs to click to redirect same as adding ~ define('F21_PREVIEW_TIME', 12); // Value is an integer in seconds, 0 -> disabled. By default it is 0 seconds, so disabled.
常量
F21_PREVIEW_TIME
仅在F21_PREVIEW_REDIRECT
为true
时有效。默认:时间的常量值是
0
,这意味着无限等待时间。如果我们找不到有效的整数,那么我们默认将其视为0
。范围:时间的有效范围是 [0, 60],包括两者。
计量单位:这里的时间以秒为单位。
- 默认情况下,重定向前的自动预览是 禁用 的。要启用,请使用以下代码在
其他特性
如果您喜欢同时查看预览页面进行重定向,同时保持预览前重定向插件活动,无论时间(由 F21_PREVIEW_TIME 定义或未定义
),我们可以使用 ?utm_redirect=auto&utm_preview=1
,自动重定向而不显示预览页面。
预期增强
- 能够打开或关闭此功能。
- 定义自己的键值对。
管理员区域附加组件
安装
步骤
- 通过
git clone
或下载为ZIP
来下载代码。 - 解压并将其放置在
user/plugins
文件夹中。 - 转到管理页面 -> 管理插件。点击以激活插件。
Google PageSpeed Insights
我们使用Google PageSpeed Insights API为您提供您请求的页面的缩略图。此API无需API_KEY
。但是,如果您流量过多,可能会超过配额。这将给出429 Quota exceeded for quota metric 'Queries' and limit 'Queries per minute'
错误。为了避免这种情况,我们请求您获取一个API密钥。在这样做之前,您可能想查看https://developers.google.com/speed/docs/insights/v5/get-started上的文档。您也可以从文档中创建API密钥。如果您愿意使用现有的API密钥,您也可以这样做。请务必启用PageSpeed Insights API。出于安全考虑,Google(以及我自己)建议您将API密钥的使用限制在子集网站上。
注意:如果您只限制某些引用者使用您的密钥,请务必不要忘记将确切的域名(以及路径,如果有)添加到由users/config.php
中定义的常量YOURLS_SITE
定义的异常列表中。
如果您愿意使用API密钥,请使用以下代码来正确关联它
# Defining the API Key. define('F21_API_KEY', 'xxxxxxxxxxxxxxxxxxxxx'); # Do we add the referrer header # By default NO (by false) define('F21_API_REF', true);
注意:请勿向任何人泄露您的API_KEY。如果您看到任何不希望看到的流量,请考虑重新生成您的密钥。
Composer相关内容
如果您愿意,可以始终运行composer命令。
composer require formula21/yourls-qr-thumbnail-plugin-with-preview-redirect
或者,
php composer.phar require formula21/yourls-qr-thumbnail-plugin-with-preview-redirect
有关composer的更多信息,请访问Composer文档。
有关如何安装composer.phar
的说明,请参阅安装指南。
警告!!
介绍
我在localhost
以及https://stp.rf.gd
上进行了测试。我本人使用著名的插件名称:Sean的QR码短网址插件与404 If Not Found ☑️。然而,不知何故,当我访问URL https://sho.rt/link.qr
时,它立即显示一个HTTP 404 - Not Found Error
。我明白,在以下操作之一之后,会触发操作loader_failed
- redirect_keyword_not_found
- infos_keyword_not_found
- redirect_no_keyword
- infos_no_keyword
调查与错误代码
在调查中,我在https://yourls.org/hooklist.php发现了这些行为。从那里,我搜索了每个被调用的行为。如果你注意到,在yourls_loader.php
页面同时触发了redirect_keyword_not_found
和loader_failed
。在检查过程中我发现
/* Code Before */ // Past this point this is a request the loader could not understand : not a valid shorturl, not a bookmarklet --> yourls_do_action( 'redirect_keyword_not_found', $keyword ); --> yourls_do_action( 'loader_failed', $request ); /* Code After */
请注意–>
不是代码的一部分。在这里它表示错误的代码片段。
如果你仔细观察,redirect_keyword_not_found
是在loader_failed
之前触发的。因此,link.qr
被redirect_keyword_not_found
行为标记(因为它不在数据库中),因此产生了404 Not Found
。
如何解决问题?
实际上有两种方法。
- 简单的方法是将错误的代码片段交换位置,即
/** @ yourls_loader.php nearly end of file **/ yourls_do_action('loader_failed', $request); yourls_do_action('redirect_keyword_not_found', $keyword);
但是不鼓励这样做,因为如果你更改了代码,你需要在每次更新时都进行相同的操作,并且直接修改核心是不被推荐的。
- 查找并注释掉使用
redirect_keyword_not_found
动作的每个插件,例如ozh的404插件。
// yourls_add_action('redirect_keyword_not_found', 'callback_function');
注意:callback_function
可以是 动作或过滤器 在这里的钩子列表中。
翻译
此插件已翻译成英语和俄语,只需使用YOURLS使用的任何语言即可,如此处所述。
如果您想将此插件翻译成您自己的语言,YOURLS的这篇博客文章描述了如何进行。您可以在插件目录的languages
文件夹中找到最新的.pot文件。请按照以下贡献指南添加您的翻译。
演示
- 对于二维码预览:https://stp.rf.gd/f21.qr
- 对于缩略图预览:https://stp.rf.gd/f21.i
- 对于预览:https://stp.rf.gd/f21~
- 对于预重定向预览:https://stp.rf.gd/f21
测试
此插件已在YOURLS 1.5至1.8.1
上进行了测试,包括在localhost
和位于https://stp.rf.gd
的实时服务器上。
许可证
代码根据MIT许可证授权。应将许可证副本包含在插件每个导出中。但是,如果尚未导出,则条款如下。
MIT License
Copyright (c) 2021 Anweshan Roy Chowdhury
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.