3 Plugin Name: YOURLS Toolbar
4 Plugin URI: http://yourls.org/
5 Description: Add a social toolbar to your redirected short URLs. Fork this plugin if you want to make your own toolbar.
8 Author URI: http://ozh.org/
9 Disclaimer: Toolbars ruin the user experience. Be warned.
13 if( !defined( 'YOURLS_ABSPATH' ) ) die();
16 $ozh_toolbar['do'] = false;
17 $ozh_toolbar['keyword'] = '';
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 ) {
23 $ozh_toolbar['do'] = true;
24 $ozh_toolbar['keyword'] = $args[1];
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 ) {
32 // Does this redirection need a toolbar?
33 if( !$ozh_toolbar['do'] )
36 // Do we have a cookie stating the user doesn't want a toolbar?
37 if( isset( $_COOKIE['yourls_no_toolbar'] ) && $_COOKIE['yourls_no_toolbar'] == 1 )
40 // Get URL and page title
42 $pagetitle = yourls_get_keyword_title( $ozh_toolbar['keyword'] );
44 // Update title if it hasn't been stored yet
45 if( $pagetitle == '' ) {
46 $pagetitle = yourls_get_remote_title( $url );
47 yourls_edit_link_title( $ozh_toolbar['keyword'], $pagetitle );
49 $_pagetitle = htmlentities( yourls_get_remote_title( $url ) );
52 $ver = YOURLS_VERSION;
54 $sql = yourls_get_num_queries();
56 // When was the link created (in days)
57 $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) );
58 $days = floor( $diff / (60*60*24) );
62 $created = $days . ' ' . yourls_n( 'day', 'days', $days ) . ' ago';
65 // How many hits on the page
66 $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] );
67 $hits = $hits . ' ' . yourls_n( 'view', 'views', $hits );
69 // Plugin URL (no URL is hardcoded)
70 $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( __DIR__ );
72 // All set. Draw the toolbar itself.
76 <title>$pagetitle — YOURLS</title>
77 <link rel="icon" type="image/gif" href="$www/images/favicon.gif" />
78 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
79 <meta http-equiv="X-UA-Compatible" content="IE-9"/>
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" />
86 <div id="yourls-about">
87 Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits.
91 <div id="yourls-delicious">
92 <img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
93 <a id="yourls-delicious-link" title="Bookmark on delicious" href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark on Delicious</a>
96 <script type="text/javascript" id="topsy_global_settings">
97 var topsy_theme = "light-blue";
99 var topsy_style = "small";
100 var topsy_order = "count,retweet,badge";
102 <div id="yourls-topsy" class="topsy_widget_data">
104 "url": "$www/{$ozh_toolbar['keyword']}",
105 "title": "$_pagetitle",
109 <div id="yourls-selfclose">
110 <a id="yourls-once" href="$url" title="Close this toolbar">close</a>
111 <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a>
116 <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe>
117 <script type="text/javascript" src="$pluginurl/js/toolbar.js"></script>
118 <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>
119 <script type="text/javascript" src="http://feeds.delicious.com/v2/json/urlinfo/$md5?callback=yourls_get_books"></script>
124 // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL)