[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 Plugin Name: YOURLS Toolbar 4 Plugin URI: http://yourls.org/ 5 Description: Add a toolbar to frame your short URLs. Fork this plugin if you want to make your own toolbar. 6 Version: 1.1 7 Author: Ozh 8 Author URI: http://ozh.org/ 9 Disclaimer: Toolbars ruin the user experience. Be warned. 10 */ 11 12 // No direct call 13 if( !defined( 'YOURLS_ABSPATH' ) ) die(); 14 15 global $ozh_toolbar; 16 $ozh_toolbar['do'] = false; 17 $ozh_toolbar['keyword'] = ''; 18 19 // When a redirection to a shorturl is about to happen, register variables 20 yourls_add_action( 'redirect_shorturl', 'ozh_toolbar_add' ); 21 function ozh_toolbar_add( $args ) { 22 global $ozh_toolbar; 23 $ozh_toolbar['do'] = true; 24 $ozh_toolbar['keyword'] = $args[1]; 25 } 26 27 // On redirection, check if this is a toolbar and draw it if needed 28 yourls_add_action( 'pre_redirect', 'ozh_toolbar_do' ); 29 function ozh_toolbar_do( $args ) { 30 global $ozh_toolbar; 31 32 // Does this redirection need a toolbar? 33 if( !$ozh_toolbar['do'] ) { 34 return; 35 } 36 37 // Do we have a cookie stating the user doesn't want a toolbar? 38 if( isset( $_COOKIE['yourls_no_toolbar'] ) && $_COOKIE['yourls_no_toolbar'] == 1 ) { 39 return; 40 } 41 42 // Get URL and page title 43 $url = $args[0]; 44 $pagetitle = yourls_get_keyword_title( $ozh_toolbar['keyword'] ); 45 46 // Update title if it hasn't been stored yet 47 if( $pagetitle == '' ) { 48 $pagetitle = yourls_get_remote_title( $url ); 49 yourls_edit_link_title( $ozh_toolbar['keyword'], $pagetitle ); 50 } 51 $_pagetitle = htmlentities( yourls_get_remote_title( $url ) ); 52 53 $www = YOURLS_SITE; 54 $ver = YOURLS_VERSION; 55 $favicon = yourls_get_yourls_favicon_url(false); 56 57 // When was the link created (in days) 58 $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) ); 59 $days = floor( $diff / (60*60*24) ); 60 if( $days == 0 ) { 61 $created = 'today'; 62 } else { 63 $created = $days . ' ' . yourls_n( 'day', 'days', $days ) . ' ago'; 64 } 65 66 // How many hits on the page 67 $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] ); 68 $hits = $hits . ' ' . yourls_n( 'view', 'views', $hits ); 69 70 // Plugin URL (no URL is hardcoded) 71 $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( __DIR__ ); 72 73 // All set. Draw the toolbar itself. 74 echo <<<PAGE 75 <html> 76 <head> 77 <title>$pagetitle — YOURLS</title> 78 <link rel="icon" type="image/gif" href="$favicon" /> 79 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 80 <meta name="generator" content="YOURLS v$ver" /> 81 <meta name="ROBOTS" content="NOINDEX, FOLLOW" /> 82 <link rel="stylesheet" href="$pluginurl/css/toolbar.css" type="text/css" media="all" /> 83 </head> 84 <body> 85 <div id="yourls-bar"> 86 <div id="yourls-about"> 87 Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits. 88 </div> 89 90 <div id="yourls-selfclose"> 91 <a id="yourls-once" href="$url" title="Close this toolbar">close</a> 92 <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a> 93 </div> 94 </div> 95 96 <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe> 97 <script type="text/javascript" src="$pluginurl/js/toolbar.js"></script> 98 </body> 99 </html> 100 PAGE; 101 102 // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL) 103 die(); 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Feb 22 05:10:06 2025 | Cross-referenced by PHPXref 0.7.1 |