Google Doc Embedder - Version 1.8.2

Version Description

  • Fixed: Fatal PHP error if cURL library not active (WAMPServer, etc.)
Download this release

Release Info

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

Code changes from version 1.8.1 to 1.8.2

Files changed (3) hide show
  1. functions.php +20 -16
  2. gviewer.php +7 -2
  3. readme.txt +4 -1
functions.php CHANGED
@@ -51,24 +51,28 @@ function validType($link, $exts) {
51
  function validUrl($url) {
52
 
53
  // checks for existence and returns filesize
54
- $handle = curl_init($url);
55
- if (false === $handle) {
56
- return false;
57
- }
58
- curl_setopt($handle, CURLOPT_HEADER, true);
59
- curl_setopt($handle, CURLOPT_FAILONERROR, true);
60
- curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: 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)
61
- curl_setopt($handle, CURLOPT_NOBODY, true);
62
- curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); // only useful in case of redirects
63
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
64
- $data = curl_exec($handle);
65
- curl_close($handle);
 
66
 
67
- $contentLength = 0;
68
- if (preg_match('/Content-Length: (\d+)/i', $data, $matches)) {
69
- $contentLength = (int)$matches[1];
 
 
 
 
70
  }
71
- return $contentLength;
72
  }
73
 
74
  function splitFilename($filename) {
51
  function validUrl($url) {
52
 
53
  // checks for existence and returns filesize
54
+ if (function_exists('curl_init')) {
55
+ $handle = curl_init($url);
56
+ if (false === $handle) {
57
+ return false;
58
+ }
59
+ curl_setopt($handle, CURLOPT_HEADER, true);
60
+ curl_setopt($handle, CURLOPT_FAILONERROR, true);
61
+ curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: 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)
62
+ curl_setopt($handle, CURLOPT_NOBODY, true);
63
+ curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); // only useful in case of redirects
64
+ curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
65
+ $data = curl_exec($handle);
66
+ curl_close($handle);
67
 
68
+ $contentLength = 0;
69
+ if (preg_match('/Content-Length: (\d+)/i', $data, $matches)) {
70
+ $contentLength = (int)$matches[1];
71
+ }
72
+ return $contentLength;
73
+ } else {
74
+ return "nocurl";
75
  }
 
76
  }
77
 
78
  function splitFilename($filename) {
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.8.1
9
  */
10
 
11
  /**
@@ -80,13 +80,18 @@ function gviewer_func($atts) {
80
  } elseif ((!$fsize = validUrl($file)) && ($force !== "1")) {
81
  $code = "\n<!-- GDE EMBED ERROR: file not found -->\n";
82
  } else {
 
 
 
 
 
83
  $pUrl = getPluginUrl();
84
 
85
  $fn = basename($file);
86
  $fnp = splitFilename($fn);
87
  $fsize = formatBytes($fsize);
88
 
89
- $code=<<<HERE
90
  %A%
91
  <iframe src="%U%" width="%W%" height="%H%" frameborder="0" style="min-width:305px;" class="gde-frame"></iframe>\n
92
  %B%
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.8.2
9
  */
10
 
11
  /**
80
  } elseif ((!$fsize = validUrl($file)) && ($force !== "1")) {
81
  $code = "\n<!-- GDE EMBED ERROR: file not found -->\n";
82
  } else {
83
+ if ($fsize == "nocurl") {
84
+ $code = "\n<!-- GDE EMBED ERROR: cURL not installed, bypassing checks -->";
85
+ } else {
86
+ $code = "";
87
+ }
88
  $pUrl = getPluginUrl();
89
 
90
  $fn = basename($file);
91
  $fnp = splitFilename($fn);
92
  $fsize = formatBytes($fsize);
93
 
94
+ $code .=<<<HERE
95
  %A%
96
  <iframe src="%U%" width="%W%" height="%H%" frameborder="0" style="min-width:305px;" class="gde-frame"></iframe>\n
97
  %B%
readme.txt CHANGED
@@ -60,6 +60,9 @@ That's not a question ;) but if you have any particular ideas on further develop
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 1.8.1 =
64
  * Added: Temporary (I hope) workaround option to insert help statement for users of IE8 - <a href="http://davismetro.com/gde/ie8" target="_blank">more info</a>
65
 
@@ -75,7 +78,7 @@ That's not a question ;) but if you have any particular ideas on further develop
75
 
76
  = 1.7.1 =
77
  * Fixed: Misleading error message if file= attribute not used (thanks ersavla)
78
- * Fixed: Bug in curl header may cause false "not found" error
79
 
80
  = 1.7 =
81
  * Added: Ability to hide selected viewer toolbar buttons
60
 
61
  == Changelog ==
62
 
63
+ = 1.8.2 =
64
+ * Fixed: Fatal PHP error if cURL library not active (WAMPServer, etc.)
65
+
66
  = 1.8.1 =
67
  * Added: Temporary (I hope) workaround option to insert help statement for users of IE8 - <a href="http://davismetro.com/gde/ie8" target="_blank">more info</a>
68
 
78
 
79
  = 1.7.1 =
80
  * Fixed: Misleading error message if file= attribute not used (thanks ersavla)
81
+ * Fixed: Bug in cURL header may cause false "not found" error
82
 
83
  = 1.7 =
84
  * Added: Ability to hide selected viewer toolbar buttons