Auto Post Thumbnail - Version 1.1

Version Description

  • Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
Download this release

Release Info

Developer adityamooley
Plugin Icon 128x128 Auto Post Thumbnail
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. auto-post-thumbnail.php +32 -3
  2. readme.txt +5 -2
auto-post-thumbnail.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Auto Post Thumbnail
5
  Plugin URI: http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-automatic-post-thumbnail/
6
  Description: Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
7
- Version: 1.0
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
@@ -112,8 +112,18 @@ function apt_generate_post_thumb($matches, $key)
112
 
113
  // Move the file to the uploads dir
114
  $new_file = $uploads['path'] . "/$filename";
115
-
116
- file_put_contents($new_file, @file_get_contents($imageUrl));
 
 
 
 
 
 
 
 
 
 
117
 
118
  // Set correct file permissions
119
  $stat = stat( dirname( $new_file ));
@@ -150,4 +160,23 @@ function apt_generate_post_thumb($matches, $key)
150
  }
151
 
152
  return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
4
  Plugin Name: Auto Post Thumbnail
5
  Plugin URI: http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-automatic-post-thumbnail/
6
  Description: Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
7
+ Version: 1.1
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
112
 
113
  // Move the file to the uploads dir
114
  $new_file = $uploads['path'] . "/$filename";
115
+
116
+ if (!ini_get('allow_url_fopen')) {
117
+ $file_data = curl_get_file_contents($imageUrl);
118
+ } else {
119
+ $file_data = @file_get_contents($imageUrl);
120
+ }
121
+
122
+ if (!$file_data) {
123
+ return null;
124
+ }
125
+
126
+ file_put_contents($new_file, $file_data);
127
 
128
  // Set correct file permissions
129
  $stat = stat( dirname( $new_file ));
160
  }
161
 
162
  return null;
163
+ }
164
+
165
+ /**
166
+ * Function to fetch the contents of URL using curl in absense of allow_url_fopen.
167
+ *
168
+ * Copied from user comment on php.net (http://in.php.net/manual/en/function.file-get-contents.php#82255)
169
+ */
170
+ function curl_get_file_contents($URL) {
171
+ $c = curl_init();
172
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
173
+ curl_setopt($c, CURLOPT_URL, $URL);
174
+ $contents = curl_exec($c);
175
+ curl_close($c);
176
+
177
+ if ($contents) {
178
+ return $contents;
179
+ }
180
+
181
+ return FALSE;
182
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: adityamooley
3
  Tags: post thumbnail
4
  Requires at least: 2.9.1
5
- Tested up to: 2.9.2
6
- Stable tag: 1.0
7
 
8
  Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
9
 
@@ -22,5 +22,8 @@ If you don't want a post thumbnail for some post with images, just add a custom
22
 
23
  == Changelog ==
24
 
 
 
 
25
  = 1.0 =
26
  * First release
2
  Contributors: adityamooley
3
  Tags: post thumbnail
4
  Requires at least: 2.9.1
5
+ Tested up to: 3.0-RC3
6
+ Stable tag: 1.1
7
 
8
  Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
9
 
22
 
23
  == Changelog ==
24
 
25
+ = 1.1 =
26
+ * Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
27
+
28
  = 1.0 =
29
  * First release