ozh

YOURLS plugin: Public Prefix-N-Shorten

ozh
Sep 19th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Public Prefix-N-Shorten
  4. Plugin URI: http://yourls.org/
  5. Description: Redirect "Prefix n' Shorten" bookmarklets to public interface
  6. Version: 1.0
  7. Author: Ozh
  8. Author URI: http://ozh.org/
  9. */
  10.  
  11. // URL of your public interface, with query parameter to which the long URL will be passed
  12. // This URL must contain a query string with "parameter equals %" (eg "url=%")
  13. define( 'OZH_PUBPNF_URL', 'http://shor.rt/public.php?url=%' );
  14.  
  15. yourls_add_action( 'load_template_redirect_admin', 'ozh_pubpnf' );
  16. function ozh_pubpnf( $args ) {
  17.     // Long URL requested?
  18.     $url = $args[0];
  19.    
  20.     // If logged in and don't want to change behavior for logged in users, do nothing
  21.     if( yourls_is_valid_user() )
  22.         return;
  23.    
  24.     // Otherwise, interrupt
  25.     $redirect = str_replace( '%', rawurlencode( $url ), OZH_PUBPNF_URL );
  26.     yourls_redirect( $redirect, 302 );
  27.     die();
  28. }
  29.  
  30.  
  31. /**
  32. Usage:
  33.  
  34. you must have a public interface up and running (for instance rename the provided sample public interface to public.php)
  35.  
  36. This public interface must accept a long URL as a query parameter (for instance 'url' as in
  37. the sample provided). Edit OZH_PUBPNF_URL to reflect the public interface location and the parameter name.
  38.  
  39. **/
Add Comment
Please, Sign In to add comment