]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-toolbar/plugin.php
A toolbar. For those who like them. Yuck. Fixes issue 228.
[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 \r
49         // When was the link created (in days)\r
50         $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) );\r
51         $days = floor( $diff / (60*60*24) );\r
52         if( $days == 0 ) {\r
53                 $created = 'today';\r
54         } else {\r
55                 $created = $days.' '.yourls_plural( 'day', $days).' ago';\r
56         }\r
57         \r
58         // How many hits on the page\r
59         $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] );\r
60         $hits = $hits.' '.yourls_plural( 'view', $hits);\r
61         \r
62         // Plugin URL (no URL is hardcoded)\r
63         $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( dirname(__FILE__) );\r
64 \r
65         // All set. Draw the toolbar itself.\r
66         echo <<<PAGE\r
67 <html>\r
68 <head>\r
69         <title>$pagetitle &mdash; YOURLS</title>\r
70         <link rel="stylesheet" href="$pluginurl/css/toolbar.css" type="text/css" media="all" />\r
71 </head>\r
72 <body>\r
73 <div id="yourls-bar">\r
74         <div id="yourls-about">\r
75                 Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits.\r
76         </div>\r
77         \r
78         <script type="text/javascript" id="topsy_global_settings">\r
79         var topsy_theme = "light-blue";\r
80         var topsy_nick = " ";\r
81         var topsy_style = "small";\r
82         var topsy_order = "count,retweet,badge";\r
83         </script>\r
84         <div id="yourls-topsy" class="topsy_widget_data">\r
85                 <!--{\r
86                         "url": "$www/{$ozh_toolbar['keyword']}",\r
87                         "title": "$pagetitle",\r
88                 }-->\r
89         </div>\r
90 \r
91         <div id="yourls-selfclose">\r
92                 <a id="yourls-once" href="$url" title="Close this toolbar">close</a>\r
93                 <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a>\r
94                 \r
95         </div>\r
96 </div>\r
97 \r
98 <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe>\r
99 <script type="text/javascript" src="$pluginurl/js/toolbar.js"></script>\r
100 <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>\r
101 </body>\r
102 </html>\r
103 PAGE;\r
104         \r
105         // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL)\r
106         die();\r
107 }