The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Sample-public-front-page
By iankt on 26th September 2025 07:35:31 AM | Syntax: TEXT | Views: 3




New paste | Download | Show/Hide line no. | Copy text to clipboard
  1.  
  2. /*
  3.  * This is an example file for a public interface and a bookmarklet. It
  4.  * is provided so you can build from it and customize to suit your needs.
  5.  * It's not really part of the project. Don't submit feature requests
  6.  * about this file. It's _your_ job to make it what you need it to be :)
  7.  *
  8.  * Rename to .php
  9.  *
  10.  */
  11.  
  12. // Start YOURLS engine
  13. require_once( dirname(__FILE__).'/includes/load-yourls.php' );
  14.  
  15. // Change this to match the URL of your public interface. Something like: http://your-own-domain-here.com/index.php
  16. $page = YOURLS_SITE . '/sample-public-front-page.php' ;
  17.  
  18. // Part to be executed if FORM has been submitted
  19. if ( isset( $_REQUEST['url'] ) && $_REQUEST['url'] != 'http://' ) {
  20.  
  21.         // Get parameters -- they will all be sanitized in yourls_add_new_link()
  22.         $url     = $_REQUEST['url'];
  23.         $keyword = isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ;
  24.         $title   = isset( $_REQUEST['title'] ) ?  $_REQUEST['title'] : '' ;
  25.         $text    = isset( $_REQUEST['text'] ) ?  $_REQUEST['text'] : '' ;
  26.  
  27.         // Create short URL, receive array $return with various information
  28.         $return  = yourls_add_new_link( $url, $keyword, $title );
  29.  
  30.         $shorturl = isset( $return['shorturl'] ) ? $return['shorturl'] : '';
  31.         $message  = isset( $return['message'] ) ? $return['message'] : '';
  32.         $title    = isset( $return['title'] ) ? $return['title'] : '';
  33.         $status   = isset( $return['status'] ) ? $return['status'] : '';
  34.  
  35.         // Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets)
  36.         if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
  37.                 $short = $return['shorturl'] ? $return['shorturl'] : '';
  38.                 $message = "Short URL (Ctrl+C to copy)";
  39.                 header('Content-type: application/json');
  40.                 echo yourls_apply_filter( 'bookmarklet_jsonp', "yourls_callback({'short_url':'$short','message':'$message'});" );
  41.  
  42.                 die();
  43.         }
  44. }
  45.  
  46. // Insert markup and all CSS & JS files
  47. yourls_html_head();
  48.  
  49. // Display title
  50. echo "

    YOURLS - Your Own URL Shortener

    \n";
  51.  
  52. // Display left hand menu
  53. yourls_html_menu() ;
  54.  
  55. // Part to be executed if FORM has been submitted
  56. if ( isset( $_REQUEST['url'] ) && $_REQUEST['url'] != 'http://' ) {
  57.  
  58.         // Display result message of short link creation
  59.         if( isset( $message ) ) {
  60.                 echo "

    $message

    ";
  61.         }
  62.  
  63.         if( $status == 'success' ) {
  64.                 // Include the Copy box and the Quick Share box
  65.                 yourls_share_box( $url, $shorturl, $title, $text );
  66.  
  67.                 // Initialize clipboard -- requires js/share.js and js/clipboard.min.js to be properly loaded in the
  68.                 echo "\n";
  69.         }
  70.  
  71. // Part to be executed when no form has been submitted
  72. } else {
  73.  
  74.                 $site = YOURLS_SITE;
  75.  
  76.                 // Display the form
  77.                 echo <<
  78.                

    Enter a new URL to shorten

  79.                
  80.                

  81.                

  82.                

  83.                

  84.                
  85. HTML;
  86.  
  87. }
  88.  
  89. ?>
  90.  
  91. Bookmarklets

  92.  
  93. Bookmark these links:

  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. Please note

  102.  
  103. Be aware that a public interface will attract spammers. You are strongly advised to install anti spam plugins and any appropriate counter measure to deal with this issue.

  104.  
  105.  
  106. // Display page footer
  107. yourls_html_footer();