]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/tools.php
Adding Social Bookmarklets
[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         
13         <h2><?php yourls_e( 'Bookmarklets' ); ?></h2>
14         
15                 <p><?php yourls_e( 'YOURLS comes with <span>four</span> handy <span>bookmarklets</span> for easier link shortening.' ); ?></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( "With the Standard Bookmarklets you will also get a <span>Quick Share</span> tool box to make posting to Twitter, Facebook or Friendfeed a snap." );
31                 echo "\n";
32                 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" );
33                 ?></p>
34                 
35                 <h3><?php yourls_e( 'The Bookmarklets' ); ?></h3>
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                                 <td><a href="javascript:(function()%7Bvar%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:enc(s)),f='<?php echo yourls_admin_url('index.php'); ?>',l=d.location,p='?u='+enc(l.href)+'&t='+enc(d.title)+'&s='+s2,u=f+p;try%7Bthrow('ozhismygod');%7Dcatch(z)%7Ba=function()%7Bif(!w.open(u))l.href=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();%7Dvoid(0);%7D)()" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'Shorten' ); ?></a></td>
51                                 <td><a href="javascript:(function()%7Bvar%20d=document,s=d.createElement('script');window.yourls_callback=function(r)%7Bif(r.short_url)%7Bprompt(r.message,r.short_url);%7Delse%7Balert('An%20error%20occured:%20'+r.message);%7D%7D;s.src='<?php echo yourls_admin_url('index.php'); ?>?u='+encodeURIComponent(d.location.href)+'&jsonp=yourls';void(d.body.appendChild(s));%7D)();" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'Instant Shorten' ); ?></a></td>
52                         </tr>
53                         <tr>
54                                 <th class="header"><?php yourls_e( 'Custom Keyword' ); ?></th>
55                                 <td><a href="javascript:(function()%7Bvar%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:enc(s)),f='<?php echo yourls_admin_url('index.php'); ?>',l=d.location,k=prompt(%22Custom%20URL%22),k2=(k?'&k='+k:%22%22),p='?u='+enc(l.href)+'&t='+enc(d.title)+'&s='+s2+k2,u=f+p;if(k!=null)%7Btry%7Bthrow('ozhismygod');%7Dcatch(z)%7Ba=function()%7Bif(!w.open(u))l.href=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();%7Dvoid(0)%7D%7D)()" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'Custom shorten' ); ?></a></td>
56                                 <td><a href="javascript:(function()%7Bvar%20d=document,k=prompt('Custom%20URL'),s=d.createElement('script');if(k!=null){window.yourls_callback=function(r)%7Bif(r.short_url)%7Bprompt(r.message,r.short_url);%7Delse%7Balert('An%20error%20occured:%20'+r.message);%7D%7D;s.src='<?php echo yourls_admin_url('index.php'); ?>?u='+encodeURIComponent(d.location.href)+'&k='+k+'&jsonp=yourls';void(d.body.appendChild(s));%7D%7D)();" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'Instant Custom Shorten' ); ?></a></td>
57                         </tr>
58                         <tr>
59                                 <th class="header"><?php yourls_e( 'Social' ); ?></th>
60                                 <td><a href="javascript:(function(){var e=document;window.open( '<?php echo yourls_admin_url('index.php'); ?>?u='+encodeURIComponent(e.location.href)+'&type=fb&share=' + encodeURIComponent('http://www.facebook.com/share.php?u='),'Share','width=500,height=340,left=100','_blank');})();" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'FB Share' ); ?></a></td>
61                                 <td><a href="javascript:(function(){var e=document;window.open( '<?php echo yourls_admin_url('index.php'); ?>?u='+encodeURIComponent(e.location.href)+'&title='+encodeURIComponent(e.title)+'&type=tw&share=' + encodeURIComponent('http://twitter.com/share?&url=&text='),'Share','width=780,height=265,left=100','_blank');})();" class="bookmarklet" onclick="alert('<?php echo yourls_esc_attr__( 'Drag to your toolbar!' ); ?>');return false;"><?php yourls_e( 'Tweet this' ); ?></a></td>
62                         </tr>
63                         </tbody>
64                 </table>
65                 
66         <h2><?php yourls_e( 'Prefix-n-Shorten' ); ?></h2>
67                 
68                 <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>
69                 
70                 <p><?php
71                 yourls_e( 'Note: this will probably not work if your web server is running on Windows' );
72                 if( yourls_is_windows() )
73                         yourls_e( ' (which seems to be the case here)' );
74                 ?>.</p>
75
76
77         <?php if( yourls_is_private() ) { ?>
78
79         <h2><?php yourls_e( 'Secure passwordless API call' ); ?></h2>
80         
81                 <p><?php
82                 yourls_e( 'YOURLS allows API calls the old fashioned way, using <tt>username</tt> and <tt>password</tt> parameters.' );
83                 echo "\n";
84                 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." );
85                 ?></p>
86
87                 <p><?php
88                 yourls_se( 'Your secret signature token: <strong><code>%s</code></strong>', yourls_auth_signature() );
89                 yourls_e( "(It's a secret. Keep it secret) ");
90                 ?></p>
91
92                 <p><?php yourls_e( 'This signature token can only be used with the API, not with the admin interface.' ); ?></p>
93                 
94                 <ul>
95                         <li><h3><?php yourls_e( 'Usage of the signature token' ); ?></h3>
96                         <p><?php yourls_e( 'Simply use parameter <tt>signature</tt> in your API requests. Example:' ); ?></p>
97                         <p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?signature=<?php echo yourls_auth_signature(); ?>&action=...</code></p>
98                         </li>
99                 
100                         <li><h3><?php yourls_e( 'Usage of a time limited signature token' ); ?></h3>
101 <pre><code>&lt;?php
102 $timestamp = time();
103 <tt>// <?php yourls_e( 'actual value:' ); ?> $time = <?php $time = time(); echo $time; ?></tt>
104 $signature = md5( $timestamp . '<?php echo yourls_auth_signature(); ?>' ); 
105 <tt>// <?php yourls_e( 'actual value:' ); ?> $signature = "<?php $sign = md5( $time. yourls_auth_signature() ); echo $sign; ?>"</tt>
106 ?> 
107 </code></pre>
108                 <p><?php yourls_e( 'Now use parameters <tt>signature</tt> and <tt>timestamp</tt> in your API requests. Example:' ); ?></p>
109                 <p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<strong>$timestamp</strong>&signature=<strong>$signature</strong>&action=...</code></p>
110                 <p><?php yourls_e( 'Actual values:' ); ?><br/>
111                 <tt><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<?php echo $time; ?>&signature=<?php echo $sign; ?>&action=...</tt></p>
112                 <p><?php yourls_se( 'This URL would be valid for only %s seconds', YOURLS_NONCE_LIFE ); ?></p>
113                 </li>
114         </ul>
115         
116         <p><?php yourls_se( 'See the <a href="%s">API documentation</a> for more', YOURLS_SITE . '/readme.html#API' ); ?></p>
117
118         </div>
119
120         <?php } // end is private ?>
121
122 <?php yourls_html_footer(); ?>