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