Skip to content

Commit

Permalink
Adding Social Bookmarklets
Browse files Browse the repository at this point in the history
Adding Facebook & Twitter bookmarklets in tools page, which use the
yourls shorten url
  • Loading branch information
Hultra committed Apr 25, 2013
1 parent aefbe16 commit abbf30f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@

$text = ( isset( $_GET['s'] ) ? stripslashes( $_GET['s'] ) : '' );

// Sharing with social bookmarklets
if ( !empty($_GET['share']) ) {
if ( !empty($_GET['type']) && $_GET['type'] == 'tw' )
header( 'Location:' . urldecode($_GET['share']) . urlencode($_GET['title'] . ' - ' . $return['shorturl']) );
else
header( 'Location:' . urldecode($_GET['share']) . urlencode($return['shorturl']) );
}

// This is not a bookmarklet
} else {
Expand Down
5 changes: 5 additions & 0 deletions admin/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<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>
<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>
</tr>
<tr>
<th class="header"><?php yourls_e( 'Social' ); ?></th>
<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>
<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>
</tr>
</tbody>
</table>

Expand Down

0 comments on commit abbf30f

Please sign in to comment.