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