Google Doc Embedder - Version 1.7

Version Description

  • Added: Ability to hide selected viewer toolbar buttons
  • Fixed: Mask URL option ignored on non-PDF file types
Download this release

Release Info

Developer k3davis
Plugin Icon wp plugin Google Doc Embedder
Version 1.7
Comparing to
See all releases

Code changes from version 1.6 to 1.7

Files changed (6) hide show
  1. altview.php +41 -0
  2. functions.php +6 -2
  3. gviewer.php +23 -6
  4. options.php +34 -2
  5. readme.txt +5 -1
  6. screenshot-2.png +0 -0
altview.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $str = $_SERVER['QUERY_STRING'];
4
+ parse_str($str);
5
+
6
+ if (!$src = curl_get_file_contents($loc)) {
7
+ echo "<html><body>\n\n<!-- GDE EMBED ERROR: alt viewer failed to load -->\n\n</body></html>";
8
+ exit;
9
+ }
10
+
11
+ $src = str_replace('<head>','<head><base href="http://docs.google.com/gview" />', $src);
12
+
13
+ if ($logo == "no") {
14
+ $src = str_replace('.goog-logo-small {','.goog-logo-small { display: none !important;', $src);
15
+ }
16
+ if ($full == "no") {
17
+ $src = str_replace('.controlbar-open-in-viewer-image {','.controlbar-open-in-viewer-image { display: none !important;', $src);
18
+ }
19
+ if ($pgup == "no") {
20
+ $src = str_replace('.controlbar-two-up-image {','.controlbar-two-up-image { display: none !important;', $src);
21
+ $src = str_replace('.controlbar-one-up-image {','.controlbar-one-up-image { display: none !important;', $src);
22
+ }
23
+ if ($zoom == "no") {
24
+ $src = str_replace('.controlbar-minus-image {','.controlbar-minus-image { display: none !important;', $src);
25
+ $src = str_replace('.controlbar-plus-image {','.controlbar-plus-image { display: none !important;', $src);
26
+ }
27
+
28
+ echo $src;
29
+
30
+ function curl_get_file_contents($URL)
31
+ {
32
+ $c = curl_init();
33
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
34
+ curl_setopt($c, CURLOPT_URL, $URL);
35
+ $contents = curl_exec($c);
36
+ curl_close($c);
37
+
38
+ if ($contents) return $contents;
39
+ else return FALSE;
40
+ }
41
+ ?>
functions.php CHANGED
@@ -8,7 +8,11 @@ function getDefaults() {
8
  "gde_show_dl" => 1,
9
  "gde_link_text" => "Download (%FT, %FS)",
10
  "gde_link_pos" => "below",
11
- "gde_link_func" => "default"
 
 
 
 
12
  );
13
 
14
  return $defaults;
@@ -44,7 +48,7 @@ function validUrl($url) {
44
  }
45
  curl_setopt($handle, CURLOPT_HEADER, true);
46
  curl_setopt($handle, CURLOPT_FAILONERROR, true);
47
- curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // needed for some sites (such as digg.com)
48
  curl_setopt($handle, CURLOPT_NOBODY, true);
49
  curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); // only useful in case of redirects
50
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
8
  "gde_show_dl" => 1,
9
  "gde_link_text" => "Download (%FT, %FS)",
10
  "gde_link_pos" => "below",
11
+ "gde_link_func" => "default",
12
+ "gde_xlogo" => 0,
13
+ "gde_xfull" => 0,
14
+ "gde_xpgup" => 0,
15
+ "gde_xzoom" => 0
16
  );
17
 
18
  return $defaults;
48
  }
49
  curl_setopt($handle, CURLOPT_HEADER, true);
50
  curl_setopt($handle, CURLOPT_FAILONERROR, true);
51
+ curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3") ); // needed for some sites (such as digg.com)
52
  curl_setopt($handle, CURLOPT_NOBODY, true);
53
  curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); // only useful in case of redirects
54
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
gviewer.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: Google Doc Embedder
5
  Plugin URI: http://davismetro.com/gde/
6
  Description: Lets you embed PDF files, PowerPoint presentations, and TIFF images in a web page using the Google Docs Viewer.
7
  Author: Kevin Davis
8
- Version: 1.6
9
  */
10
 
11
  /* Copyright 2009 Kevin Davis. E-mail: kev@tnw.org
@@ -35,6 +35,10 @@ function gviewer_func($atts) {
35
  $wd = get_option('gde_default_width');
36
  $ht = get_option('gde_default_height');
37
  $txt = get_option('gde_link_text');
 
 
 
 
38
  extract(shortcode_atts(array(
39
  'file' => '',
40
  'save' => $dl,
@@ -53,20 +57,31 @@ function gviewer_func($atts) {
53
  } elseif (!$fsize = validUrl($file)) {
54
  $code = "\n<!-- GDE EMBED ERROR: file not found -->\n";
55
  } else {
 
 
56
  $fn = basename($file);
57
  $fnp = splitFilename($fn);
58
  $fsize = formatBytes($fsize);
59
 
60
  $code=<<<HERE
61
- <iframe src="http://docs.google.com/viewer?url=%U%&embedded=true" style="width:%W%px; height:%H%px;" frameborder="0" class="gde-frame"></iframe>\n
62
  HERE;
63
 
 
 
 
 
 
 
 
 
 
64
  if ($save == "1") {
65
 
66
  $dlMethod = get_option('gde_link_func');
67
  if ($fnp[1] == "PDF") {
68
  if ($dlMethod == "force" or $dlMethod == "force-mask") {
69
- $dlFile = getPluginUrl();
70
  $fileParts = parse_url($file);
71
  $fileStr = str_replace($fileParts['scheme']."://","",$file);
72
  $dlFile .= "/pdf.php?file=".$fileStr."&dl=1&fn=".$fn;
@@ -79,9 +94,12 @@ HERE;
79
  $dlFile = shortUrl($dlFile);
80
  }
81
 
 
 
 
82
  } else {
83
  $dlFile = $file;
84
- $target = "_blank";
85
  }
86
  $linkcode = "<p class=\"gde-text\"><a href=\"$dlFile\" target=\"$target\" class=\"gde-link\">$txt</a></p>";
87
 
@@ -92,7 +110,7 @@ HERE;
92
  }
93
  }
94
 
95
- $code = str_replace("%U%", $file, $code);
96
  $code = str_replace("%W%", $width, $code);
97
  $code = str_replace("%H%", $height, $code);
98
  $code = str_replace("%FN", $fn, $code);
@@ -131,7 +149,6 @@ function gde_options() {
131
  // add additional settings link, for convenience
132
  $plugin = plugin_basename(__FILE__);
133
  function my_plugin_actlinks( $links ) {
134
- // Add a link to this plugin's settings page
135
  $settings_link = '<a href="options-general.php?page=gviewer.php">Settings</a>';
136
  array_unshift( $links, $settings_link );
137
  return $links;
5
  Plugin URI: http://davismetro.com/gde/
6
  Description: Lets you embed PDF files, PowerPoint presentations, and TIFF images in a web page using the Google Docs Viewer.
7
  Author: Kevin Davis
8
+ Version: 1.7
9
  */
10
 
11
  /* Copyright 2009 Kevin Davis. E-mail: kev@tnw.org
35
  $wd = get_option('gde_default_width');
36
  $ht = get_option('gde_default_height');
37
  $txt = get_option('gde_link_text');
38
+ $xlogo = get_option('gde_xlogo');
39
+ $xfull = get_option('gde_xfull');
40
+ $xpgup = get_option('gde_xpgup');
41
+ $xzoom = get_option('gde_xzoom');
42
  extract(shortcode_atts(array(
43
  'file' => '',
44
  'save' => $dl,
57
  } elseif (!$fsize = validUrl($file)) {
58
  $code = "\n<!-- GDE EMBED ERROR: file not found -->\n";
59
  } else {
60
+ $pUrl = getPluginUrl();
61
+
62
  $fn = basename($file);
63
  $fnp = splitFilename($fn);
64
  $fsize = formatBytes($fsize);
65
 
66
  $code=<<<HERE
67
+ <iframe src="%U%" style="width:%W%px; height:%H%px;" frameborder="0" class="gde-frame"></iframe>\n
68
  HERE;
69
 
70
+ $lnk = "http://docs.google.com/viewer?url=".urlencode($file)."&embedded=true";
71
+ if ($xlogo || $xfull || $xpgup || $xzoom) {
72
+ $lnk = $pUrl."/altview.php?loc=".urlencode($lnk);
73
+ if ($xlogo == "1") { $lnk .= "&logo=no"; }
74
+ if ($xfull == "1") { $lnk .= "&full=no"; }
75
+ if ($xpgup == "1") { $lnk .= "&pgup=no"; }
76
+ if ($xzoom == "1") { $lnk .= "&zoom=no"; }
77
+ }
78
+
79
  if ($save == "1") {
80
 
81
  $dlMethod = get_option('gde_link_func');
82
  if ($fnp[1] == "PDF") {
83
  if ($dlMethod == "force" or $dlMethod == "force-mask") {
84
+ $dlFile = $pUrl;
85
  $fileParts = parse_url($file);
86
  $fileStr = str_replace($fileParts['scheme']."://","",$file);
87
  $dlFile .= "/pdf.php?file=".$fileStr."&dl=1&fn=".$fn;
94
  $dlFile = shortUrl($dlFile);
95
  }
96
 
97
+ } elseif ($dlMethod == "force-mask") {
98
+ $dlFile = shortUrl($file);
99
+ $target = "_self";
100
  } else {
101
  $dlFile = $file;
102
+ $target = "_self";
103
  }
104
  $linkcode = "<p class=\"gde-text\"><a href=\"$dlFile\" target=\"$target\" class=\"gde-link\">$txt</a></p>";
105
 
110
  }
111
  }
112
 
113
+ $code = str_replace("%U%", $lnk, $code);
114
  $code = str_replace("%W%", $width, $code);
115
  $code = str_replace("%H%", $height, $code);
116
  $code = str_replace("%FN", $fn, $code);
149
  // add additional settings link, for convenience
150
  $plugin = plugin_basename(__FILE__);
151
  function my_plugin_actlinks( $links ) {
 
152
  $settings_link = '<a href="options-general.php?page=gviewer.php">Settings</a>';
153
  array_unshift( $links, $settings_link );
154
  return $links;
options.php CHANGED
@@ -12,6 +12,10 @@ if(isset($_REQUEST['defaults'])) {
12
  update_option('gde_link_text', $set['gde_link_text']);
13
  update_option('gde_link_pos', $set['gde_link_pos']);
14
  update_option('gde_link_func', $set['gde_link_func']);
 
 
 
 
15
 
16
  showMessage("Options reset to defaults");
17
  } elseif(isset($_REQUEST['submit'])) {
@@ -22,6 +26,26 @@ if(isset($_REQUEST['defaults'])) {
22
  } else {
23
  update_option('gde_show_dl', 0);
24
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  if(isset($_POST['gde_default_width'])) {
26
  $neww = $_POST['gde_default_width'];
27
  if (strlen($neww) > 0) update_option('gde_default_width', sanitizeOpt($neww));
@@ -52,8 +76,8 @@ if(isset($_REQUEST['defaults'])) {
52
 
53
  <table class="form-table">
54
  <tr valign="top">
55
- <td colspan="2"><strong>Global Viewer Size</strong><br/>
56
- To override on individual posts, manually set <code>height=</code> and <code>width=</code> (number in px) in the post shortcode.</td>
57
  </tr>
58
  <tr valign="top">
59
  <th scope="row">Default Width</th>
@@ -64,6 +88,14 @@ To override on individual posts, manually set <code>height=</code> and <code>wid
64
  <td><input type="text" size="5" name="gde_default_height" value="<?php echo get_option('gde_default_height'); ?>" /> px</td>
65
  </tr>
66
  <tr valign="top">
 
 
 
 
 
 
 
 
67
  <td colspan="2"><strong>Download Link Options</strong><br/>
68
  To override display setting on an individual post, use <code>save="1"</code> (show) or <code>save="0"</code> (hide) in the post shortcode.</em></td>
69
  </tr>
12
  update_option('gde_link_text', $set['gde_link_text']);
13
  update_option('gde_link_pos', $set['gde_link_pos']);
14
  update_option('gde_link_func', $set['gde_link_func']);
15
+ update_option('gde_xlogo', $set['gde_xlogo']);
16
+ update_option('gde_xfull', $set['gde_xfull']);
17
+ update_option('gde_xpgup', $set['gde_xpgup']);
18
+ update_option('gde_xzoom', $set['gde_xzoom']);
19
 
20
  showMessage("Options reset to defaults");
21
  } elseif(isset($_REQUEST['submit'])) {
26
  } else {
27
  update_option('gde_show_dl', 0);
28
  }
29
+ if(isset($_POST['gde_xlogo'])) {
30
+ update_option('gde_xlogo', 1);
31
+ } else {
32
+ update_option('gde_xlogo', 0);
33
+ }
34
+ if(isset($_POST['gde_xfull'])) {
35
+ update_option('gde_xfull', 1);
36
+ } else {
37
+ update_option('gde_xfull', 0);
38
+ }
39
+ if(isset($_POST['gde_xpgup'])) {
40
+ update_option('gde_xpgup', 1);
41
+ } else {
42
+ update_option('gde_xpgup', 0);
43
+ }
44
+ if(isset($_POST['gde_xzoom'])) {
45
+ update_option('gde_xzoom', 1);
46
+ } else {
47
+ update_option('gde_xzoom', 0);
48
+ }
49
  if(isset($_POST['gde_default_width'])) {
50
  $neww = $_POST['gde_default_width'];
51
  if (strlen($neww) > 0) update_option('gde_default_width', sanitizeOpt($neww));
76
 
77
  <table class="form-table">
78
  <tr valign="top">
79
+ <td colspan="2"><strong>Global Viewer Options</strong><br/>
80
+ To override size on individual posts, manually set <code>height=</code> and <code>width=</code> (number in px) in the post shortcode.</td>
81
  </tr>
82
  <tr valign="top">
83
  <th scope="row">Default Width</th>
88
  <td><input type="text" size="5" name="gde_default_height" value="<?php echo get_option('gde_default_height'); ?>" /> px</td>
89
  </tr>
90
  <tr valign="top">
91
+ <th scope="row">Hide From Toolbar:</th>
92
+ <td><?php showCheck('gde_xlogo', t('Google Logo')); ?>
93
+ <?php showCheck('gde_xpgup', t('Single/Double Page View')); ?>
94
+ <?php showCheck('gde_xzoom', t('Zoom In/Out')); ?>
95
+ <?php showCheck('gde_xfull', t('Open in New Window')); ?>
96
+ </td>
97
+ </tr>
98
+ <tr valign="top">
99
  <td colspan="2"><strong>Download Link Options</strong><br/>
100
  To override display setting on an individual post, use <code>save="1"</code> (show) or <code>save="0"</code> (hide) in the post shortcode.</em></td>
101
  </tr>
readme.txt CHANGED
@@ -51,11 +51,15 @@ That's not a question ;) but if you have any particular ideas on further develop
51
 
52
  == Screenshots ==
53
 
54
- 1. Appearance of embedded viewer (blank file)
55
  2. Settings page
56
 
57
  == Changelog ==
58
 
 
 
 
 
59
  = 1.6 =
60
  * Added: Additional class names for optional stylesheet use
61
  * Added: Support to embed TIFF images
51
 
52
  == Screenshots ==
53
 
54
+ 1. Default appearance of embedded viewer
55
  2. Settings page
56
 
57
  == Changelog ==
58
 
59
+ = 1.7 =
60
+ * Added: Ability to hide selected viewer toolbar buttons
61
+ * Fixed: Mask URL option ignored on non-PDF file types
62
+
63
  = 1.6 =
64
  * Added: Additional class names for optional stylesheet use
65
  * Added: Support to embed TIFF images
screenshot-2.png CHANGED
Binary file