yourls-preview-url-with-qrcode/plugin.php

61 lines
2.2 KiB
PHP
Raw Normal View History

2016-03-31 20:46:57 -07:00
<?php
/*
Plugin Name: Preview URL with QR Code
2022-05-12 02:35:14 -07:00
Plugin URI: https://github.com/SophiaAtkinson/yourls-preview-url-with-qrcode
2016-03-31 20:46:57 -07:00
Description: Preview URLs before you're redirected there
2022-05-12 02:35:14 -07:00
Version: 1.1
Author: Sophia Atkinson
Author URI: https:/sophia.wtf
Plugin Based Off Of DennyDai's Preview URL with QR Code
2016-03-31 20:46:57 -07:00
*/
// EDIT THIS
// Character to add to a short URL to trigger the preview interruption
2016-04-01 18:37:15 -07:00
define( 'DD_PREVIEW_CHAR', '~' );
2016-03-31 20:46:57 -07:00
// DO NO EDIT FURTHER
// Handle failed loader request and check if there's a ~
2016-04-01 18:37:15 -07:00
yourls_add_action( 'loader_failed', 'dd_preview_loader_failed' );
function dd_preview_loader_failed( $args ) {
2016-03-31 20:46:57 -07:00
$request = $args[0];
$pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );
2016-04-01 18:37:15 -07:00
if( preg_match( "@^([$pattern]+)".DD_PREVIEW_CHAR."$@", $request, $matches ) ) {
2016-03-31 20:46:57 -07:00
$keyword = isset( $matches[1] ) ? $matches[1] : '';
$keyword = yourls_sanitize_keyword( $keyword );
2016-04-01 18:37:15 -07:00
dd_preview_show( $keyword );
2016-03-31 20:46:57 -07:00
die();
}
}
// Show the preview screen for a short URL
2016-04-01 18:37:15 -07:00
function dd_preview_show( $keyword ) {
2016-03-31 20:46:57 -07:00
require_once( YOURLS_INC.'/functions-html.php' );
yourls_html_head( 'preview', 'Short URL preview' );
yourls_html_logo();
$title = yourls_get_keyword_title( $keyword );
$url = yourls_get_keyword_longurl( $keyword );
$base = YOURLS_SITE;
2016-04-01 18:37:15 -07:00
$char = DD_PREVIEW_CHAR;
2022-05-12 02:35:14 -07:00
$qrcode = 'https://chart.apis.google.com/chart?chs=256x256&cht=qr&chld=M&chl='.YOURLS_SITE.'/'.$keyword;
2016-03-31 20:46:57 -07:00
echo <<<HTML
<h2>Link Preview</h2>
<p>You requested the short URL <strong><a href="$base/$keyword">$base/$keyword</a></strong></p>
<p>This short URL points to:</p>
<ul>
<li>Long URL: <strong><a href="$base/$keyword">$url</a></strong></li>
<li>Page title: <strong>$title</strong></li>
<li>QR Code: <br><img src="$qrcode"></li>
</ul>
<p>If you still want to visit this link, please <strong><a href="$base/$keyword">click here</a></strong>.</p>
<p>Thank you for using our shortening service.</p>
HTML;
yourls_html_footer();
2016-04-01 18:37:15 -07:00
}