Update plugin.php

This commit is contained in:
Denny Dai 2016-04-02 09:37:15 +08:00
parent a80a7acc93
commit accd027915

View File

@ -11,25 +11,25 @@ Author URI: https://dennydai.github.io
// EDIT THIS // EDIT THIS
// Character to add to a short URL to trigger the preview interruption // Character to add to a short URL to trigger the preview interruption
define( 'OZH_PREVIEW_CHAR', '~' ); define( 'DD_PREVIEW_CHAR', '~' );
// DO NO EDIT FURTHER // DO NO EDIT FURTHER
// Handle failed loader request and check if there's a ~ // Handle failed loader request and check if there's a ~
yourls_add_action( 'loader_failed', 'ozh_preview_loader_failed' ); yourls_add_action( 'loader_failed', 'dd_preview_loader_failed' );
function ozh_preview_loader_failed( $args ) { function dd_preview_loader_failed( $args ) {
$request = $args[0]; $request = $args[0];
$pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() ); $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );
if( preg_match( "@^([$pattern]+)".OZH_PREVIEW_CHAR."$@", $request, $matches ) ) { if( preg_match( "@^([$pattern]+)".DD_PREVIEW_CHAR."$@", $request, $matches ) ) {
$keyword = isset( $matches[1] ) ? $matches[1] : ''; $keyword = isset( $matches[1] ) ? $matches[1] : '';
$keyword = yourls_sanitize_keyword( $keyword ); $keyword = yourls_sanitize_keyword( $keyword );
ozh_preview_show( $keyword ); dd_preview_show( $keyword );
die(); die();
} }
} }
// Show the preview screen for a short URL // Show the preview screen for a short URL
function ozh_preview_show( $keyword ) { function dd_preview_show( $keyword ) {
require_once( YOURLS_INC.'/functions-html.php' ); require_once( YOURLS_INC.'/functions-html.php' );
yourls_html_head( 'preview', 'Short URL preview' ); yourls_html_head( 'preview', 'Short URL preview' );
@ -38,7 +38,7 @@ function ozh_preview_show( $keyword ) {
$title = yourls_get_keyword_title( $keyword ); $title = yourls_get_keyword_title( $keyword );
$url = yourls_get_keyword_longurl( $keyword ); $url = yourls_get_keyword_longurl( $keyword );
$base = YOURLS_SITE; $base = YOURLS_SITE;
$char = OZH_PREVIEW_CHAR; $char = DD_PREVIEW_CHAR;
$qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents('http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=M&chl='.YOURLS_SITE.'/'.$keyword)); $qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents('http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=M&chl='.YOURLS_SITE.'/'.$keyword));
echo <<<HTML echo <<<HTML