Browse Source

move shortlink existance check to avoid breaking 404

master
c? 2 years ago
parent
commit
66525df185
1 changed files with 28 additions and 29 deletions
  1. 28
    29
      plugin.php

+ 28
- 29
plugin.php View File

@@ -23,48 +23,47 @@ function drg_preview_loader_failed( $args ) {
if( preg_match( "@^([$pattern]+)".DRG_PREVIEW_CHAR."$@", $request, $matches ) ) {
$keyword = isset( $matches[1] ) ? $matches[1] : '';
$keyword = yourls_sanitize_keyword( $keyword );
drg_preview_show( $keyword );
die();
if( yourls_is_shorturl( $keyword ) ) {
drg_preview_show( $keyword );
die();
}
}
}

// Show the preview screen for a short URL
function drg_preview_show( $keyword ) {
if( yourls_is_shorturl( $keyword ) ) {

require_once( YOURLS_INC.'/functions-html.php' );
require_once( YOURLS_INC.'/functions-html.php' );


$title = yourls_get_keyword_title( $keyword );
$url = yourls_get_keyword_longurl( $keyword );
$base = YOURLS_SITE;
$char = DRG_PREVIEW_CHAR;
$title = yourls_get_keyword_title( $keyword );
$url = yourls_get_keyword_longurl( $keyword );
$base = YOURLS_SITE;
$char = DRG_PREVIEW_CHAR;

// Support for the Swap Short URL (http://github.com/ggwarpig/Yourls-Swap-Short-Url) plugin
if( YOURLS_SHORT_URL != "" ) {
$base = YOURLS_SHORT_URL;
}
// Support for the Swap Short URL (http://github.com/ggwarpig/Yourls-Swap-Short-Url) plugin
if( YOURLS_SHORT_URL != "" ) {
$base = YOURLS_SHORT_URL;
}

yourls_html_head( 'preview', 'Shortlink Info' );
yourls_html_logo();
yourls_html_head( 'preview', 'Shortlink Info' );
yourls_html_logo();

if( yourls_is_active_plugin( 'smartqr/plugin.php' ) ) {
$qrinfo = '<p><strong>QR code for this shortlink:</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$base.'/'.$keyword.'.qr" /></p>';
}
if( yourls_is_active_plugin( 'smartqr/plugin.php' ) ) {
$qrinfo = '<p><strong>QR code for this shortlink:</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$base.'/'.$keyword.'.qr" /></p>';
}

echo <<<HTML
<h2>Shortlink info for <strong><a href="$base/$keyword">$base/$keyword</a></strong></h2>
<p>This shortlink points to:</p>
<ul>
<li>Long URL: <strong><a href="$base/$keyword">$url</a></strong></li>
<li>Page title: <strong>$title</strong></li>
</ul>
echo <<<HTML
<h2>Shortlink info for <strong><a href="$base/$keyword">$base/$keyword</a></strong></h2>
<p>This shortlink points to:</p>
<ul>
<li>Long URL: <strong><a href="$base/$keyword">$url</a></strong></li>
<li>Page title: <strong>$title</strong></li>
</ul>

$qrinfo
$qrinfo

<p><strong><a href="$base/$keyword">Click here to continue to the target page</a></strong>.</p>
<p><strong><a href="$base/$keyword">Click here to continue to the target page</a></strong>.</p>
HTML;

yourls_html_footer();
}
yourls_html_footer();
}

Loading…
Cancel
Save