Advertisement
ozh

Inline QR Code

ozh
Nov 6th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Inline QRCodes
  4. Version: 1.0
  5. Author: Ozh
  6. Author URI: http://ozh.org/
  7. */
  8.  
  9.  
  10. yourls_add_filter( 'share_box_data', 'inline_qr_data' );
  11. function inline_qr_data( $data ) {
  12.     // Generate a real QR code for $data['shorturl']
  13.     $data['shortlink_title'] = '<div id="qrcode">QR for '.$data['shorturl'].'</div>' . $data['shortlink_title'] ;
  14.     return $data;
  15. }
  16.  
  17. yourls_add_filter( 'add_new_link', 'inline_qr_add_url' );
  18. function inline_qr_add_url( $data ) {
  19.     $shorturl = $data['shorturl'];
  20.     $data['html'] .= "<script>inline_qr_code( '$shorturl' );</script>";
  21.     return $data;
  22. }
  23.  
  24. yourls_add_action( 'html_head', 'inline_qr_js' );
  25. function inline_qr_js() {
  26.     echo <<<JS
  27.     <style>
  28.     #copybox { width: 300px; }
  29.     #qrcode { float:right;width:50px;height:50px;margin-top:30px;background:red; font-size:8px; }
  30.     </style>
  31.     <script>
  32.     function inline_qr_code( url ) {
  33.         url = ( url == null ? $( '#origlink' ).attr('href') : url );
  34.         // This function would fetch an actual QR code :
  35.         $('#qrcode').html('QR Code for '+url);
  36.     }
  37.     $(document).ready(function(){
  38.         // Share button behavior
  39.         $('.button_share').click(function(){
  40.             inline_qr_code();
  41.         });
  42.        
  43.         // Tab behavior on stats page
  44.         $('a[href=#stat_tab_share]').click(function(){
  45.             inline_qr_code();
  46.         });
  47.        
  48.         inline_qr_code();
  49.     });
  50.     </script>
  51. JS;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement