]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-toolbar/plugin.php
Fix empty pagetitle notice
[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         $_pagetitle = htmlentities( yourls_get_remote_title( $url ) );\r
47         \r
48         $www = YOURLS_SITE;\r
49         $ver = YOURLS_VERSION;\r
50         $md5 = md5( $url );\r
51         $sql = yourls_get_num_queries();\r
52 \r
53         // When was the link created (in days)\r
54         $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) );\r
55         $days = floor( $diff / (60*60*24) );\r
56         if( $days == 0 ) {\r
57                 $created = 'today';\r
58         } else {\r
59                 $created = $days.' '.yourls_plural( 'day', $days).' ago';\r
60         }\r
61         \r
62         // How many hits on the page\r
63         $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] );\r
64         $hits = $hits.' '.yourls_plural( 'view', $hits);\r
65         \r
66         // Plugin URL (no URL is hardcoded)\r
67         $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( dirname(__FILE__) );\r
68 \r
69         // All set. Draw the toolbar itself.\r
70         echo <<<PAGE\r
71 <html>\r
72 <head>\r
73         <title>$pagetitle &mdash; YOURLS</title>\r
74         <link rel="icon" type="image/gif" href="$www/images/favicon.gif" />\r
75         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
76         <meta http-equiv="X-UA-Compatible" content="chrome=1" />\r
77         <meta name="generator" content="YOURLS v$ver" />\r
78         <meta name="ROBOTS" content="NOINDEX, FOLLOW" />\r
79         <link rel="stylesheet" href="$pluginurl/css/toolbar.css" type="text/css" media="all" />\r
80 </head>\r
81 <body>\r
82 <div id="yourls-bar">\r
83         <div id="yourls-about">\r
84                 Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits.\r
85                 <!-- $sql queries -->\r
86         </div>\r
87         \r
88         <div id="yourls-delicious">\r
89         <img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />\r
90         <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
91         </div>\r
92 \r
93         <script type="text/javascript" id="topsy_global_settings">\r
94         var topsy_theme = "light-blue";\r
95         var topsy_nick = " ";\r
96         var topsy_style = "small";\r
97         var topsy_order = "count,retweet,badge";\r
98         </script>\r
99         <div id="yourls-topsy" class="topsy_widget_data">\r
100                 <!--{\r
101                         "url": "$www/{$ozh_toolbar['keyword']}",\r
102                         "title": "$_pagetitle",\r
103                 }-->\r
104         </div>\r
105         \r
106         <div id="yourls-selfclose">\r
107                 <a id="yourls-once" href="$url" title="Close this toolbar">close</a>\r
108                 <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a>\r
109                 \r
110         </div>\r
111 </div>\r
112 \r
113 <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe>\r
114 <script type="text/javascript" src="$pluginurl/js/toolbar.js"></script>\r
115 <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>\r
116 <script type="text/javascript" src="http://feeds.delicious.com/v2/json/urlinfo/$md5?callback=yourls_get_books"></script>\r
117 </body>\r
118 </html>\r
119 PAGE;\r
120         \r
121         // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL)\r
122         die();\r
123 }