]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/tools.php
Use __DIR__ instead of dirname(__FILE__)
[Github/YOURLS.git] / admin / tools.php
1 <?php
2 define( 'YOURLS_ADMIN', true );
3 require_once( dirname( __DIR__ ).'/includes/load-yourls.php' );
4 yourls_maybe_require_auth();
5
6 yourls_html_head( 'tools', yourls__( 'Cool YOURLS Tools' ) );
7 yourls_html_logo();
8 yourls_html_menu();
9 ?>
10
11         <main role="main" class="sub_wrap">
12
13         <h2><?php yourls_e( 'Bookmarklets' ); ?></h2>
14         
15                 <p><?php yourls_e( 'YOURLS comes with handy <span>bookmarklets</span> for easier link shortening and sharing.' ); ?></p>
16
17                 <h3><?php yourls_e( 'Standard or Instant, Simple or Custom' ); ?></h3>
18                 
19                 <ul>
20                         <li><?php yourls_e( 'The <span>Standard Bookmarklets</span> will take you to a page where you can easily edit or delete your brand new short URL.' ); ?></li>
21                         
22                         <li><?php yourls_e( 'The <span>Instant Bookmarklets</span> will pop the short URL without leaving the page you are viewing.' ); ?></li>
23                         
24                         <li><?php yourls_e( 'The <span>Simple Bookmarklets</span> will generate a short URL with a random or sequential keyword.' ); ?></li>
25                         
26                         <li><?php yourls_e( 'The <span>Custom Keyword Bookmarklets</span> will prompt you for a custom keyword first.' ); ?></li>
27                 </ul>
28                 
29                 <p><?php
30                 yourls_e( "If you want to share a description along with the link you're shortening, simply <span>select text</span> on the page you're viewing before clicking on your bookmarklet link" );
31                 ?></p>
32                 
33                 <h3><?php yourls_e( 'The Bookmarklets' ); ?></h3>
34         
35         <?php $base_bookmarklet = yourls_admin_url( 'index.php' ); ?>
36                 
37                 <p><?php yourls_e( 'Click and drag links to your toolbar (or right-click and bookmark it)' ); ?></p>
38         
39         <table class="tblSorter" cellpadding="0" cellspacing="1">
40                         <thead>
41                         <tr>
42                                 <td>&nbsp;</td>
43                                 <th><?php yourls_e( 'Standard (new page)' ); ?></th>
44                                 <th><?php yourls_e( 'Instant (popup)' ); ?></th>
45                         </tr>
46                         </thead>
47                         <tbody>
48                         <tr>
49                                 <th class="header"><?php yourls_e( 'Simple' ); ?></th>
50
51                                 <td>
52                 <?php $js_code = <<<STANDARD_SIMPLE
53                 // Simple Standard Bookmarklet (new page, no keyword asked)
54                 var d   = document,
55                     w   = window,
56                     enc = encodeURIComponent,
57                     e   = w.getSelection,
58                     k   = d.getSelection,
59                     x   = d.selection,
60                     s   = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
61                     s2  = ((s.toString() == '') ? s : enc(s)),
62                     f   = '$base_bookmarklet',
63                     l   = d.location.href,
64                     ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
65                     ur  = l.split(new RegExp(ups))[1],
66                     ups = ups.split(/\:/),
67                     p   = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title)+'&s='+s2,
68                     u   = f + p;
69                 try {
70                     throw ('ozhismygod');
71                 } catch (z) {
72                     a = function () {
73                         if (!w.open(u)) l.href = u;
74                     };
75                     if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
76                     else a();
77                 }
78                 void(0);
79 STANDARD_SIMPLE;
80                 yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Shorten' ) );
81                 ?>
82                 </td>
83
84                                 <td>
85                 <?php $js_code = <<<POPUP_SIMPLE
86                 // Simple Popup (in-page popup dialog, no keyword asked)
87                 var d   = document,
88                     sc  = d.createElement('script'),
89                     l   = d.location.href,
90                     enc = encodeURIComponent,
91                     ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
92                     ur  = l.split(new RegExp(ups))[1],
93                     ups = ups.split(/\:/),
94                     p   = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title);
95                 window.yourls_callback = function (r) {
96                     if (r.short_url) {
97                         prompt(r.message, r.short_url);
98                     } else {
99                         alert('An error occured: ' + r.message);
100                     }
101                 };
102                 sc.src = '$base_bookmarklet' + p + '&jsonp=yourls';
103                 void(d.body.appendChild(sc));
104 POPUP_SIMPLE;
105                 yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Instant Shorten' ) );
106                 ?>
107                 </td>
108
109             </tr>
110                         <tr>
111                                 <th class="header"><?php yourls_e( 'Custom Keyword' ); ?></th>
112
113                                 <td>
114                 <?php $js_code = <<<CUSTOM_STANDARD
115                 // Custom Standard (new page, prompt for a keyword)
116                 var d   = document,
117                     enc = encodeURIComponent,
118                     w   = window,
119                     e   = w.getSelection,
120                     k   = d.getSelection,
121                     x   = d.selection,
122                     s   = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
123                     s2  = ((s.toString() == '') ? s : enc(s)),
124                     f   = '$base_bookmarklet',
125                     l   = d.location.href,
126                     ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
127                     ur  = l.split(new RegExp(ups))[1],
128                     ups = ups.split(/\:/),
129                     k   = prompt("Custom URL"),
130                     k2  = (k ? '&k=' + k : ""),
131                     p   = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title)+'&s='+s2 + k2,
132                     u   = f + p;
133                 if (k != null) {
134                     try {
135                         throw ('ozhismygod');
136                     } catch (z) {
137                         a = function () {
138                             if (!w.open(u)) l = u;
139                         };
140                         if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
141                         else a();
142                     }
143                     void(0)
144                 }
145 CUSTOM_STANDARD;
146                 yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Custom shorten' ) );
147                 ?>
148                 </td>
149                                 
150                 <td>
151                 <?php $js_code = <<<CUSTOM_POPUP
152                 // Custom Popup (prompt for a keyword + on-page popup)
153                 var d   = document,
154                     l   = d.location.href,
155                     k   = prompt('Custom URL'),
156                     enc = encodeURIComponent,
157                     ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
158                     ur  = l.split(new RegExp(ups))[1],
159                     ups = ups.split(/\:/),
160                     p   = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title);
161                     sc  = d.createElement('script');
162                 if (k != null) {
163                     window.yourls_callback = function (r) {
164                         if (r.short_url) {
165                             prompt(r.message, r.short_url);
166                         } else {
167                             alert('An error occured: ' + r.message);
168                         }
169                     };
170                     sc.src = '$base_bookmarklet' + p + '&k=' + k + '&jsonp=yourls';
171                     void(d.body.appendChild(sc));
172                 }
173 CUSTOM_POPUP;
174                 yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Instant Custom Shorten' ) );
175                 ?>
176                 </td>
177                 
178                         </tr>
179                         </tbody>
180                 </table>
181         
182
183                 <h3><?php yourls_e( 'Social Bookmarklets' ); ?></h3>
184                 
185                 <p><?php yourls_e( 'Create a short URL and share it on social networks, all in one click!' ); ?>        
186                 <?php yourls_e( 'Click and drag links to your toolbar (or right-click and bookmark it)' ); ?></p>
187
188                 <p><?php yourls_e( 'Shorten and share:' ); ?></p>
189         
190         <p>
191         <?php $js_code = <<<FACEBOOK
192         // Share on Facebook 
193         var d   = document,
194             enc = encodeURIComponent,
195             f   = '$base_bookmarklet',
196             l   = d.location.href,
197             ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
198             ur  = l.split(new RegExp(ups))[1],
199             ups = ups.split(/\:/),
200             p   = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur=' + enc(ur) + '&t=' + enc(d.title) + '&share=facebook',
201             u   = f + p;
202         try {
203             throw ('ozhismygod');
204         } catch (z) {
205             a = function () {
206                 if (!window.open(u,'Share','width=500,height=340,left=100','_blank')) l.href = u;
207             };
208             if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
209             else a();
210         }
211         void(0);
212 FACEBOOK;
213         yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Facebook' ) );
214         ?>
215         
216         <?php $js_code = <<<TWITTER
217         // Share on Twitter
218         var d = document,
219             w = window,
220             enc = encodeURIComponent,
221             e = w.getSelection,
222             k = d.getSelection,
223             x = d.selection,
224             s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
225             s2 = ((s.toString() == '') ? s : '%20%22' + enc(s) + '%22'),
226             f = '$base_bookmarklet',
227             l = d.location.href,
228             ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
229             ur = l.split(new RegExp(ups))[1],
230             ups = ups.split(/\:/),
231             p = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur='+enc(ur) + '&t=' + enc(d.title) + s2 + '&share=twitter',
232             u = f + p;
233         try {
234             throw ('ozhismygod');
235         } catch (z) {
236             a = function () {
237                 if (!w.open(u,'Share','width=780,height=265,left=100','_blank')) l = u;
238             };
239             if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
240             else a();
241         }
242         void(0);
243 TWITTER;
244         yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Twitter' ) );
245         ?>
246                 
247         <?php $js_code = <<<TUMBLR
248         // Share on Tumlr
249         var d = document,
250             w = window,
251             enc = encodeURIComponent,
252             share = 'tumblr',
253             e = w.getSelection,
254             k = d.getSelection,
255             x = d.selection,
256             s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
257             s2 = ((s.toString() == '') ? s : '%20%22' + enc(s) + '%22'),
258             f = '$base_bookmarklet',
259             l = d.location.href,
260             ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
261             ur = l.split(new RegExp(ups))[1],
262             ups = ups.split(/\:/),
263             p = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur='+enc(ur) + '&t=' + enc(d.title) + '&s=' + s2 + '&share=tumblr',
264             u = f + p;
265         try {
266             throw ('ozhismygod');
267         } catch (z) {
268             a = function () {
269                 if (!w.open(u,'Share','width=450,height=450,left=430','_blank')) l = u;
270             };
271             if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
272             else a();
273         }
274         void(0);
275 TUMBLR;
276         yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Tumblr' ) );
277         ?>
278         
279                 <?php yourls_do_action( 'social_bookmarklet_buttons_after' ); ?>
280                 
281                 </p>
282
283         <h2><?php yourls_e( 'Prefix-n-Shorten' ); ?></h2>
284                 
285                 <p><?php yourls_se( "When viewing a page, you can also prefix its full URL: just head to your browser's address bar, add \"<span>%s</span>\" to the beginning of the current URL (right before its 'http://' part) and hit enter.", preg_replace('@https?://@', '', YOURLS_SITE) . '/' ); ?></p>
286                 
287                 <p><?php
288                 yourls_e( 'Note: this will probably not work if your web server is running on Windows' );
289                 if( yourls_is_windows() )
290                         yourls_e( ' (which seems to be the case here)' );
291                 ?>.</p>
292
293
294         <?php if( yourls_is_private() ) { ?>
295
296         <h2><?php yourls_e( 'Secure passwordless API call' ); ?></h2>
297         
298                 <p><?php
299                 yourls_e( 'YOURLS allows API calls the old fashioned way, using <tt>username</tt> and <tt>password</tt> parameters.' );
300                 echo "\n";
301                 yourls_e( "If you're worried about sending your credentials into the wild, you can also make API calls without using your login or your password, using a secret signature token." );
302                 ?></p>
303
304                 <p><?php yourls_se( 'Your secret signature token: <strong><code>%s</code></strong>', yourls_auth_signature() ); ?>
305         <?php yourls_e( "(It's a secret. Keep it secret) "); ?></p>
306
307                 <p><?php yourls_e( 'This signature token can only be used with the API, not with the admin interface.' ); ?></p>
308                 
309                 <ul>
310                         <li><h3><?php yourls_e( 'Usage of the signature token' ); ?></h3>
311                         <p><?php yourls_e( 'Simply use parameter <tt>signature</tt> in your API requests. Example:' ); ?></p>
312                         <p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?signature=<?php echo yourls_auth_signature(); ?>&action=...</code></p>
313                         </li>
314                 
315                         <li><h3><?php yourls_e( 'Usage of a time limited signature token' ); ?></h3>
316 <pre><code>&lt;?php
317 $timestamp = time();
318 <tt>// <?php yourls_e( 'actual value:' ); ?> $time = <?php $time = time(); echo $time; ?></tt>
319 $signature = md5( $timestamp . '<?php echo yourls_auth_signature(); ?>' ); 
320 <tt>// <?php yourls_e( 'actual value:' ); ?> $signature = "<?php $sign = md5( $time. yourls_auth_signature() ); echo $sign; ?>"</tt>
321 ?> 
322 </code></pre>
323                 <p><?php yourls_e( 'Now use parameters <tt>signature</tt> and <tt>timestamp</tt> in your API requests. Example:' ); ?></p>
324                 <p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<strong>$timestamp</strong>&signature=<strong>$signature</strong>&action=...</code></p>
325                 <p><?php yourls_e( 'Actual values:' ); ?><br/>
326                 <tt><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<?php echo $time; ?>&signature=<?php echo $sign; ?>&action=...</tt></p>
327                 <p><?php yourls_se( 'This URL would be valid for only %s seconds', YOURLS_NONCE_LIFE ); ?></p>
328                 </li>
329         </ul>
330         
331         <p><?php yourls_se( 'See the <a href="%s">API documentation</a> for more', YOURLS_SITE . '/readme.html#API' ); ?></p>
332
333         </main>
334
335         <?php } // end is private ?>
336
337 <?php yourls_html_footer(); ?>