Preview YOURLS shortlinks in style! https://git.drg.li/YOURLS/SmartPreview/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. Plugin Name: SmartPreview
  4. Plugin URI: https://github.com/DRGli/YOURLS-SmartPreview/
  5. Description: Preview URLs in style!
  6. Version: 1.1-drg-git
  7. Author: DRG
  8. Author URI: https://drg.one/
  9. */
  10. // EDIT THIS
  11. // Character to add to a short URL to trigger the preview interruption
  12. define( 'DRG_PREVIEW_CHAR', '~' );
  13. // DO NO EDIT FURTHER
  14. // Handle failed loader request and check if there's a ~
  15. yourls_add_action( 'loader_failed', 'drg_preview_loader_failed' );
  16. function drg_preview_loader_failed( $args ) {
  17. $request = $args[0];
  18. $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );
  19. if( preg_match( "@^([$pattern]+)".DRG_PREVIEW_CHAR."$@", $request, $matches ) ) {
  20. $keyword = isset( $matches[1] ) ? $matches[1] : '';
  21. $keyword = yourls_sanitize_keyword( $keyword );
  22. if( yourls_is_shorturl( $keyword ) ) {
  23. drg_preview_show( $keyword );
  24. die();
  25. }
  26. }
  27. }
  28. // Show the preview screen for a short URL
  29. function drg_preview_show( $keyword ) {
  30. require_once( YOURLS_INC.'/functions-html.php' );
  31. $title = yourls_get_keyword_title( $keyword );
  32. $url = yourls_get_keyword_longurl( $keyword );
  33. $base = YOURLS_SITE;
  34. $char = DRG_PREVIEW_CHAR;
  35. // Support for the Swap Short URL (http://github.com/ggwarpig/Yourls-Swap-Short-Url) plugin
  36. if( YOURLS_SHORT_URL != "" ) {
  37. $base = YOURLS_SHORT_URL;
  38. }
  39. yourls_html_head( 'preview', 'Shortlink Info' );
  40. yourls_html_logo();
  41. if( yourls_is_active_plugin( 'smartqr/plugin.php' ) ) {
  42. $qrinfo = '<p><strong>QR code for this shortlink:</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$base.'/'.$keyword.'.qr" /></p>';
  43. }
  44. echo <<<HTML
  45. <h2>Shortlink info for <strong><a href="$base/$keyword">$base/$keyword</a></strong></h2>
  46. <p>This shortlink points to:</p>
  47. <ul>
  48. <li>Long URL: <strong><a href="$base/$keyword">$url</a></strong></li>
  49. <li>Page title: <strong>$title</strong></li>
  50. </ul>
  51. $qrinfo
  52. <p><strong><a href="$base/$keyword">Click here to continue to the target page</a></strong>.</p>
  53. HTML;
  54. yourls_html_footer();
  55. }