bainternet

Google Docs Embed

Aug 1st, 2011
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Google Docs Embed
  4. Plugin URI: http://en.bainternet.info
  5. Description: Simple plugin that provides a shortcode to embed PDF ,Word document or PowerPoint presentation.
  6. Version: 1.0
  7. Author: Bainternet
  8. Author URI: http://en.bainternet.info
  9. */
  10. /*
  11.         *   Copyright (C) 2011  Ohad Raz
  12.         *   http://en.bainternet.info
  13.         *   admin@bainternet.info
  14.  
  15.         This program is free software; you can redistribute it and/or modify
  16.         it under the terms of the GNU General Public License as published by
  17.         the Free Software Foundation; either version 2 of the License, or
  18.         (at your option) any later version.
  19.  
  20.         This program is distributed in the hope that it will be useful,
  21.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.         GNU General Public License for more details.
  24.  
  25.         You should have received a copy of the GNU General Public License
  26.         along with this program; if not, write to the Free Software
  27.         Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  28. */
  29.  
  30. /* Disallow direct access to the plugin file */
  31. if (basename($_SERVER['PHP_SELF']) == basename (__FILE__)) {
  32.     //die('Sorry, but you cannot access this page directly.');
  33. }
  34.  
  35. add_shortcode('GDOCS', 'Gdocs_embed');
  36. function Gdocs_embed( $atts, $content = null ) {
  37.     extract( shortcode_atts( array(
  38.         'height' => 300,
  39.         'width' => 400,
  40.         'style' => '',
  41.         'title' => '',
  42.         'class' => 'pdf',
  43.         'id' => '',
  44.         'url' => ''
  45.         ), $atts ) );
  46.    
  47.    
  48.    
  49.     if (!strstr($url,'http://')) {
  50.         return '';
  51.     }
  52.        
  53.         $embed = '<iframe src="http://docs.google.com/viewer?url='.urlencode($url).'&amp;embedded=true" style="height:'.$height.'px;width:'.$width.'px;" class="'.$class.'"';
  54.     if ($id != '') {
  55.         $embed .= ' id="'.$id.'"';
  56.     }
  57.     if ($style != '') {
  58.         $embed .= ' style="'.$style.'"';
  59.     }
  60.     if ($title != '') {
  61.         $embed .= ' title="'.$title.'"';
  62.     }
  63.     $embed .= '></iframe>';
  64.  
  65.     return apply_filters( 'GDOCS', $embed  );
  66. }
  67.  
  68. /*
  69. Usage:
  70.  
  71. [GDOCS url="http://link.to/PDF"]
  72. */
Add Comment
Please, Sign In to add comment