]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-toolbar/plugin.php
Sample toolbar plugin - draft
[Github/YOURLS.git] / user / plugins / sample-toolbar / plugin.php
1 <?php\r
2 /*\r
3 Plugin Name: Sample Toolbar\r
4 Plugin URI: http://yourls.org/\r
5 Description: Add a "toolbar" wrapping redirected short URLs.\r
6 Version: 0.1\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 yourls_add_action( 'redirect_shorturl', 'ozh_toolbar_add' );\r
17 function ozh_toolbar_add( $args ) {\r
18         global $ozh_toolbar;\r
19         $ozh_toolbar['do'] = true;\r
20         $ozh_toolbar['keyword'] = $args[1];\r
21 }\r
22 \r
23 yourls_add_action( 'pre_redirect', 'ozh_toolbar_do' );\r
24 function ozh_toolbar_do( $args ) {\r
25         global $ozh_toolbar;\r
26         \r
27         if( !$ozh_toolbar['do'] )\r
28                 return;\r
29                 \r
30         $url = $args[0];\r
31         \r
32         $pagetitle = yourls_get_keyword_title( $ozh_toolbar['keyword'] );\r
33         \r
34         echo <<<PAGE\r
35 <html>\r
36 <head>\r
37         <title>$pagetitle (YOURLS toolbar)</title>\r
38         <style>\r
39         body {\r
40                 margin:0;\r
41                 padding:0;\r
42                 overflow:hidden;\r
43         }\r
44         #yourlsFrame {\r
45                 position: absolute;\r
46                 background: transparent;\r
47                 width: 100%;\r
48                 height:100%;\r
49                 top: 0;\r
50                 padding: 32px 0;\r
51                 z-index: 1;\r
52         }\r
53         #yourlsBar {\r
54                 font-family: Verdana, Arial;\r
55                 font-size: 12px;\r
56                 position:absolute;\r
57                 top:0;\r
58                 height:32px;\r
59                 width:100%;\r
60                 background:#e3f3ff;\r
61                 color:#888;\r
62                 -moz-box-shadow: 0 1px 5px rgba(0,0,0,0.5);\r
63                 -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.5);\r
64                 z-index: 900000;\r
65         }\r
66         #yourlsBar p {\r
67                 padding:5px 10px;\r
68                 margin:2px;\r
69         }\r
70         #selfclose {\r
71                 display:block;\r
72                 float:right;\r
73                 zmargin-right:70px;\r
74         }\r
75         div.topsy_widget_data { display:inline; float:left; }\r
76         </style>\r
77         <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>\r
78 </head>\r
79 <body>\r
80 <div id="yourlsBar">\r
81         <p>\r
82                 Toolbar by <a href="http://yourls.org/">YOURLS</a>\r
83                 <div class="topsy_widget_data"><!--\r
84                     {\r
85                         "url": "http://labs.topsy.com/widgets/retweet-button/",\r
86                         "title": "Topsy Retweet Button for Web Sites"\r
87                     }\r
88                 --></div>\r
89                 <span id="selfclose">(<a href="$url">close</a>)</span>\r
90         </p>\r
91 </div>\r
92 <iframe id="yourlsFrame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe>\r
93 </body>\r
94 </html>\r
95 PAGE;\r
96         \r
97         die();\r
98 }