Google Doc Embedder - Version 1.9.6

Version Description

  • Changed: Removed min-width restriction of viewer (thanks Amanda)
  • Fixed: Enhanced Viewer failed in hardened PHP configs (thanks Waseem)
  • Fixed: Force Download option failed in hardened PHP configs
  • Fixed: Options page layout quirks in lower resolutions
  • Fixed: Options page PHP parse error on XAMPP (thanks John)
Download this release

Release Info

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

Code changes from version 1.9.5 to 1.9.6

Files changed (5) hide show
  1. gviewer.php +4 -4
  2. options.php +6 -21
  3. pdf.php +49 -37
  4. proxy.php +51 -9
  5. readme.txt +9 -2
gviewer.php CHANGED
@@ -5,10 +5,10 @@ Plugin Name: Google Doc Embedder
5
  Plugin URI: http://davismetro.com/gde/
6
  Description: Lets you embed Word Documents, PDF files, PowerPoint presentations, and TIFF images in a web page using the Google Docs Viewer (no Flash or PDF browser plug-ins required).
7
  Author: Kevin Davis
8
- Version: 1.9.5
9
  */
10
 
11
- $gde_ver = "1.9.5.98";
12
 
13
  /**
14
  * LICENSE
@@ -91,7 +91,7 @@ function gde_gviewer_func($atts) {
91
 
92
  $code .=<<<HERE
93
  %A%
94
- <iframe src="%U%" width="%W%" height="%H%" frameborder="0" style="min-width:305px;" class="gde-frame"></iframe>\n
95
  %B%
96
  HERE;
97
 
@@ -118,7 +118,7 @@ HERE;
118
  $dlFile = $pUrl;
119
  $fileParts = parse_url($file);
120
  $fileStr = str_replace($fileParts['scheme']."://","",$file);
121
- $dlFile .= "/pdf.php?file=".$fileStr."&dl=1&fn=".$fn;
122
  $target = "_self";
123
  } elseif ($dlMethod == "default") {
124
  $dlFile = $file;
5
  Plugin URI: http://davismetro.com/gde/
6
  Description: Lets you embed Word Documents, PDF files, PowerPoint presentations, and TIFF images in a web page using the Google Docs Viewer (no Flash or PDF browser plug-ins required).
7
  Author: Kevin Davis
8
+ Version: 1.9.6
9
  */
10
 
11
+ $gde_ver = "1.9.6.98";
12
 
13
  /**
14
  * LICENSE
91
 
92
  $code .=<<<HERE
93
  %A%
94
+ <iframe src="%U%" width="%W%" height="%H%" frameborder="0" class="gde-frame"></iframe>\n
95
  %B%
96
  HERE;
97
 
118
  $dlFile = $pUrl;
119
  $fileParts = parse_url($file);
120
  $fileStr = str_replace($fileParts['scheme']."://","",$file);
121
+ $dlFile .= "/pdf.php?file=".$fileStr."&fn=".$fn;
122
  $target = "_self";
123
  } elseif ($dlMethod == "default") {
124
  $dlFile = $file;
options.php CHANGED
@@ -86,26 +86,11 @@ echo "<h2>".__('Google Doc Embedder Settings')."</h2>";
86
  <form action="" method="post">
87
  <?php wp_nonce_field('update-options'); ?>
88
 
89
- <div id="poststuff" class="metabox-holder has-right-sidebar">
90
- <!--div class="inner-sidebar">
91
- <div id="side-sortables" class="meta-box-sortabless ui-sortable" style="position:relative;">
92
-
93
-
94
- <div id="sm_pnres" class="postbox">
95
- <h3 class="hndle"><span>About Plugin</span></h3>
96
-
97
- <div class="inside">
98
- Beta version
99
- </div>
100
- </div>
101
- </div>
102
- </div-->
103
- <div class="has-sidebar sm-padded" >
104
-
105
- <div id="post-body-content" class="has-sidebar-content">
106
-
107
- <div class="meta-box-sortabless">
108
- <div id="gde_vieweroptions" class="postbox">
109
 
110
  <h3 class="hndle"><span>Viewer Options</span></h3>
111
  <div class="inside">
@@ -196,7 +181,7 @@ if ($gdeoptions['disable_proxy'] == "no") {
196
  <?php gde_showCheckTb('gdet_n', gde_t('Open in New Window')); ?>
197
  </td>
198
  </tr>
199
- <? } ?>
200
  </table>
201
 
202
  </div>
86
  <form action="" method="post">
87
  <?php wp_nonce_field('update-options'); ?>
88
 
89
+ <div id="poststuff" class="metabox-holder">
90
+ <div class="sm-padded" >
91
+ <div id="post-body-content" class="has-sidebar-content">
92
+ <div class="meta-box-sortabless">
93
+ <div id="gde_vieweroptions" class="postbox">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  <h3 class="hndle"><span>Viewer Options</span></h3>
96
  <div class="inside">
181
  <?php gde_showCheckTb('gdet_n', gde_t('Open in New Window')); ?>
182
  </td>
183
  </tr>
184
+ <?php } ?>
185
  </table>
186
 
187
  </div>
pdf.php CHANGED
@@ -1,47 +1,59 @@
1
  <?php
2
 
3
- /* Calls remote PDF file locally (automates remote fetch)
4
-
5
- USAGE: pdf.php?
6
- file=file.pdf (the name of the remote file, required)
7
- download=1 (force save dialog rather than display in browser, optional)
8
- */
9
-
10
- $str = $_SERVER['QUERY_STRING'];
11
- parse_str($str);
12
-
13
- if (!$file) {
14
- echo "<html>No filename specified, action cancelled.</html>\n";
15
- exit;
16
- } elseif (!preg_match("/.pdf$/i",$file)) {
17
- # invalid filename or hack attempt
18
- echo "<html>Invalid filename, action cancelled.</html>\n";
19
- exit;
20
  }
21
 
22
- $file = "http://".$file;
23
-
24
- if (!$handle = fopen("$file", "rb")) {
25
- # file doesn't exist
26
- echo "<html>Nonexistant filename, action cancelled.</html>\n";
27
- exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
- $contents = '';
31
- while (!feof($handle)) {
32
- $contents .= fread($handle, 8192);
 
 
 
 
 
 
 
33
  }
34
- fclose($handle);
35
-
36
-
37
- // We'll be outputting a PDF
38
- header('Content-type: application/pdf');
39
 
40
- // force save dialog with given name
41
- if ($dl) {
42
- header('Content-Disposition: attachment; filename="'.$fn.'"');
43
  }
44
-
45
- // spit it out
46
- echo $contents;
47
  ?>
1
  <?php
2
 
3
+ # This proxy code is a bypass of default browser handling of PDF files, used for the
4
+ # "Force Download" option of Google Doc Embedder plug-in for WordPress. If you do not
5
+ # wish to use this code, set the Link Behavior option to "Browser Default" in GDE Settings.
6
+
7
+ // test for allow_url_fopen in php config; try curl for function if disabled
8
+ if (ini_get('allow_url_fopen') !== "1") {
9
+ if (function_exists('curl_version')) {
10
+ $curl = 1;
11
+ } else {
12
+ $err = "This function is not supported on your web server. Please add ";
13
+ $err .= "<code>allow_url_fopen = 1</code> to your php.ini or enable cURL library. ";
14
+ $err .= "If you are unable to do this, please change the Link Behavior setting to ";
15
+ $err .= "Browser Default in GDE Options.";
16
+ showErr($err);
17
+ exit;
18
+ }
 
19
  }
20
 
21
+ if ((isset($_GET['fn'])) && (isset($_GET['file']))) {
22
+ // check for invalid file type
23
+ if (!preg_match("/.pdf$/i",$_GET['fn'])) {
24
+ showErr('Invalid file type; action cancelled.');
25
+ }
26
+
27
+ // get file
28
+ if ($curl) {
29
+ $code = curl_get_contents("http://". $_GET['file']);
30
+ } else {
31
+ $code = file_get_contents("http://". $_GET['file']);
32
+ }
33
+
34
+ // output file
35
+ header('Content-type: application/pdf');
36
+ header('Content-Disposition: attachment; filename="'.$_GET['fn'].'"');
37
+ echo $code;
38
+
39
+ } else {
40
+ showErr('No filename specified; action cancelled.');
41
  }
42
 
43
+ function curl_get_contents($url) {
44
+ $ch = curl_init();
45
+ $timeout = 5; // set to zero for no timeout
46
+ curl_setopt ($ch, CURLOPT_URL, $url);
47
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
48
+ curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
49
+ $file_contents = curl_exec($ch);
50
+ curl_close($ch);
51
+
52
+ return $file_contents;
53
  }
 
 
 
 
 
54
 
55
+ function showErr($msg) {
56
+ echo "<html>$msg</html>";
57
+ exit;
58
  }
 
 
 
59
  ?>
proxy.php CHANGED
@@ -1,18 +1,39 @@
1
  <?php
2
 
3
  # This proxy code is a bypass for an existing flaw in Google Docs Viewer that breaks the functionality
4
- # for IE users. If you do not wish to use this code, you can disable it in GDE Advanced Options. Note
5
- # that viewer toolbar customization options depend on this proxy workaround remaining enabled.
 
6
  #
7
  # The problem this code addresses is discussed at length on Google's Help Forum:
8
  # http://www.google.com/support/forum/p/Google+Docs/thread?tid=22d92671afd5b9b7&hl=en
9
  #
10
  # This code is based on the work of Peter Chen. For more information, see:
11
  # http://peterchenadded.herobo.com/gview/
 
 
12
 
13
- if (isset($_GET['embedded'])) {
14
- // get the src page, change relative to absolute and don't remove 'chan' param in get requests
15
- $code = file_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  $search = array("/gview/images", "gview/resources_gview/client/js");
18
  $replace = array("http://docs.google.com/gview/images", "?jsfile=gview/resources_gview/client/js");
@@ -52,8 +73,13 @@ if (isset($_GET['embedded'])) {
52
  echo $code;
53
 
54
  } else if (isset($_GET['a']) && $_GET['a'] == 'gt') {
55
- // get text coordinates file, can not redirect because of same origin policy
56
- $code = file_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
 
 
 
 
 
57
  header('Content-type: text/xml; charset=UTF-8');
58
  echo $code;
59
 
@@ -63,8 +89,12 @@ if (isset($_GET['embedded'])) {
63
  header('Content-type: image/png');
64
 
65
  } else if (isset($_GET['jsfile'])) {
66
- // proxy javascript files and replace navigator.cookieEnabled with false
67
- $code = file_get_contents("http://docs.google.com/" . $_GET['jsfile']);
 
 
 
 
68
 
69
  $search = array("navigator.cookieEnabled");
70
  $replace = array("false");
@@ -77,4 +107,16 @@ if (isset($_GET['embedded'])) {
77
  // everything else, of which there isn't!
78
  header("Location: http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
79
  }
 
 
 
 
 
 
 
 
 
 
 
 
80
  ?>
1
  <?php
2
 
3
  # This proxy code is a bypass for an existing flaw in Google Docs Viewer that breaks the functionality
4
+ # for IE users. If you do not wish to use this code, select Google Standard Viewer rather than
5
+ # Enhanced Viewer in GDE Settings. Note that viewer toolbar customization options depend on this
6
+ # proxy workaround remaining enabled.
7
  #
8
  # The problem this code addresses is discussed at length on Google's Help Forum:
9
  # http://www.google.com/support/forum/p/Google+Docs/thread?tid=22d92671afd5b9b7&hl=en
10
  #
11
  # This code is based on the work of Peter Chen. For more information, see:
12
  # http://peterchenadded.herobo.com/gview/
13
+ #
14
+ # Peter's code is modified below to allow for cURL fallback and viewer toolbar customization.
15
 
16
+ // test for allow_url_fopen in php config; try curl for function if disabled
17
+ if (ini_get('allow_url_fopen') !== "1") {
18
+ if (function_exists('curl_version')) {
19
+ $curl = 1;
20
+ } else {
21
+ $err = "This function is not supported on your web server. Please add ";
22
+ $err .= "<code>allow_url_fopen = 1</code> to your php.ini or enable cURL library. ";
23
+ $err .= "If you are unable to do this, please switch to Google Standard ";
24
+ $err .= "Viewer in GDE Options.";
25
+ echo $err;
26
+ exit;
27
+ }
28
+ }
29
+
30
+ if (isset($_GET['embedded'])) {
31
+ // get the src page, change relative path to absolute
32
+ if ($curl) {
33
+ $code = curl_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
34
+ } else {
35
+ $code = file_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
36
+ }
37
 
38
  $search = array("/gview/images", "gview/resources_gview/client/js");
39
  $replace = array("http://docs.google.com/gview/images", "?jsfile=gview/resources_gview/client/js");
73
  echo $code;
74
 
75
  } else if (isset($_GET['a']) && $_GET['a'] == 'gt') {
76
+ // get text coordinates file, can not redirect because of same origin policy
77
+ if ($curl) {
78
+ $code = curl_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
79
+ } else {
80
+ $code = file_get_contents("http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
81
+ }
82
+
83
  header('Content-type: text/xml; charset=UTF-8');
84
  echo $code;
85
 
89
  header('Content-type: image/png');
90
 
91
  } else if (isset($_GET['jsfile'])) {
92
+ // proxy javascript files and replace navigator.cookieEnabled with false
93
+ if ($curl) {
94
+ $code = curl_get_contents("http://docs.google.com/" . $_GET['jsfile']);
95
+ } else {
96
+ $code = file_get_contents("http://docs.google.com/" . $_GET['jsfile']);
97
+ }
98
 
99
  $search = array("navigator.cookieEnabled");
100
  $replace = array("false");
107
  // everything else, of which there isn't!
108
  header("Location: http://docs.google.com/gview?" . $_SERVER['QUERY_STRING']);
109
  }
110
+
111
+ function curl_get_contents($url) {
112
+ $ch = curl_init();
113
+ $timeout = 5; // set to zero for no timeout
114
+ curl_setopt ($ch, CURLOPT_URL, $url);
115
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
116
+ curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
117
+ $file_contents = curl_exec($ch);
118
+ curl_close($ch);
119
+
120
+ return $file_contents;
121
+ }
122
  ?>
readme.txt CHANGED
@@ -19,7 +19,7 @@ Google Doc Embedder lets you embed several types of files into your WordPress pa
19
 
20
  Similar to services like Scribd, Google Doc Embedder will allow you to embed these files directly into your page or post, not requiring the user to have Microsoft Word, Adobe Reader, PowerPoint, or other software installed to view the contents. Unlike Scribd, the files do not need to be uploaded to any service first - including Google Documents - but can exist anywhere publicly accessible on your site or the internet.
21
 
22
- Note: Uuse of this plug-in now implies your agreement with Google's published <a href="http://docs.google.com/viewer/TOS?hl=en" target="_blank">Terms of Service</a>.
23
 
24
  == Installation ==
25
 
@@ -27,7 +27,7 @@ Note: Uuse of this plug-in now implies your agreement with Google's published <a
27
  2. Activate the plugin through the 'Plugins' menu in WordPress.
28
  3. Done.
29
 
30
- For basic usage, please see the FAQ.
31
 
32
  Go to "GDE Settings" (under "Settings" in the admin panel) to change defaults, or override individually using the shortcode syntax in the FAQ.
33
 
@@ -67,6 +67,13 @@ That's not a question ;) but if you have any particular ideas on further develop
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
 
70
  = 1.9.5 =
71
  * Added: Support for Word documents (DOC, DOCX)
72
  * Added: Default language option for viewer
19
 
20
  Similar to services like Scribd, Google Doc Embedder will allow you to embed these files directly into your page or post, not requiring the user to have Microsoft Word, Adobe Reader, PowerPoint, or other software installed to view the contents. Unlike Scribd, the files do not need to be uploaded to any service first - including Google Documents - but can exist anywhere publicly accessible on your site or the internet.
21
 
22
+ Note: Use of this plug-in implies your agreement with Google's published <a href="http://docs.google.com/viewer/TOS?hl=en" target="_blank">Terms of Service</a>.
23
 
24
  == Installation ==
25
 
27
  2. Activate the plugin through the 'Plugins' menu in WordPress.
28
  3. Done.
29
 
30
+ For basic usage, please see the FAQ. For detailed usage, see the <a href="http://www.davismetro.com/gde/usage/">web site</a>.
31
 
32
  Go to "GDE Settings" (under "Settings" in the admin panel) to change defaults, or override individually using the shortcode syntax in the FAQ.
33
 
67
 
68
  == Changelog ==
69
 
70
+ = 1.9.6 =
71
+ * Changed: Removed min-width restriction of viewer (thanks Amanda)
72
+ * Fixed: Enhanced Viewer failed in hardened PHP configs (thanks Waseem)
73
+ * Fixed: Force Download option failed in hardened PHP configs
74
+ * Fixed: Options page layout quirks in lower resolutions
75
+ * Fixed: Options page PHP parse error on XAMPP (thanks John)
76
+
77
  = 1.9.5 =
78
  * Added: Support for Word documents (DOC, DOCX)
79
  * Added: Default language option for viewer