]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-toolbar/plugin.php
"Social Toolbar" improvements with delicious button and meta tags (charset, robots)
[Github/YOURLS.git] / user / plugins / sample-toolbar / plugin.php
1 <?php\r
2 /*\r
3 Plugin Name: YOURLS Toolbar\r
4 Plugin URI: http://yourls.org/\r
5 Description: Add a social toolbar to your redirected short URLs. Fork this plugin if you want to make your own toolbar.\r
6 Version: 1.0\r
7 Author: Ozh\r
8 Author URI: http://ozh.org/\r
9 Disclaimer: Toolbars ruin the user experience. Be warned.\r
10 */\r
11 \r
12 global $ozh_toolbar;\r
13 $ozh_toolbar['do'] = false;\r
14 $ozh_toolbar['keyword'] = '';\r
15 \r
16 // When a redirection to a shorturl is about to happen, register variables\r
17 yourls_add_action( 'redirect_shorturl', 'ozh_toolbar_add' );\r
18 function ozh_toolbar_add( $args ) {\r
19         global $ozh_toolbar;\r
20         $ozh_toolbar['do'] = true;\r
21         $ozh_toolbar['keyword'] = $args[1];\r
22 }\r
23 \r
24 // On redirection, check if this is a toolbar and draw it if needed\r
25 yourls_add_action( 'pre_redirect', 'ozh_toolbar_do' );\r
26 function ozh_toolbar_do( $args ) {\r
27         global $ozh_toolbar;\r
28         \r
29         // Does this redirection need a toolbar?\r
30         if( !$ozh_toolbar['do'] )\r
31                 return;\r
32 \r
33         // Do we have a cookie stating the user doesn't want a toolbar?\r
34         if( isset( $_COOKIE['yourls_no_toolbar'] ) && $_COOKIE['yourls_no_toolbar'] == 1 )\r
35                 return;\r
36         \r
37         // Get URL and page title\r
38         $url = $args[0];\r
39         $pagetitle = yourls_get_keyword_title( $ozh_toolbar['keyword'] );\r
40 \r
41         // Update title if it hasn't been stored yet\r
42         if( $pagetitle == '' ) {\r
43                 $pagetitle = yourls_get_remote_title( $url );\r
44                 yourls_edit_link_title( $ozh_toolbar['keyword'], $pagetitle );\r
45         }\r
46         \r
47         $www = YOURLS_SITE;\r
48         $ver = YOURLS_VERSION;\r
49         $md5 = md5( $url );\r
50 \r
51         // When was the link created (in days)\r
52         $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) );\r
53         $days = floor( $diff / (60*60*24) );\r
54         if( $days == 0 ) {\r
55                 $created = 'today';\r
56         } else {\r
57                 $created = $days.' '.yourls_plural( 'day', $days).' ago';\r
58         }\r
59         \r
60         // How many hits on the page\r
61         $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] );\r
62         $hits = $hits.' '.yourls_plural( 'view', $hits);\r
63         \r
64         // Plugin URL (no URL is hardcoded)\r
65         $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( dirname(__FILE__) );\r
66 \r
67         // All set. Draw the toolbar itself.\r
68         echo <<<PAGE\r
69 <html>\r
70 <head>\r
71         <title>$pagetitle &mdash; YOURLS</title>\r
72         <link rel="icon" type="image/gif" href="$www/images/favicon.gif" />\r
73         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
74         <meta http-equiv="X-UA-Compatible" content="chrome=1" />\r
75         <meta name="generator" content="YOURLS v$ver" />\r
76         <meta name="ROBOTS" content="NOINDEX, FOLLOW" />\r
77         <link rel="stylesheet" href="$pluginurl/css/toolbar.css" type="text/css" media="all" />\r
78 </head>\r
79 <body>\r
80 <div id="yourls-bar">\r
81         <div id="yourls-about">\r
82                 Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits.\r
83         </div>\r
84         \r
85         <div id="yourls-delicious">\r
86         <img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />\r
87         <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>\r
88         </div>\r
89 \r
90         <script type="text/javascript" id="topsy_global_settings">\r
91         var topsy_theme = "light-blue";\r
92         var topsy_nick = " ";\r
93         var topsy_style = "small";\r
94         var topsy_order = "count,retweet,badge";\r
95         </script>\r
96         <div id="yourls-topsy" class="topsy_widget_data">\r
97                 <!--{\r
98                         "url": "$www/{$ozh_toolbar['keyword']}",\r
99                         "title": "$pagetitle",\r
100                 }-->\r
101         </div>\r
102         \r
103         <div id="yourls-selfclose">\r
104                 <a id="yourls-once" href="$url" title="Close this toolbar">close</a>\r
105                 <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a>\r
106                 \r
107         </div>\r
108 </div>\r
109 \r
110 <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe>\r
111 <script type="text/javascript" src="$pluginurl/js/toolbar.js"></script>\r
112 <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>\r
113 <script type="text/javascript" src="http://feeds.delicious.com/v2/json/urlinfo/$md5?callback=yourls_get_books"></script>\r
114 </body>\r
115 </html>\r
116 PAGE;\r
117         \r
118         // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL)\r
119         die();\r
120 }