Changeset 685232
- Timestamp:
- 03/21/2013 02:40:23 PM (13 years ago)
- Location:
- add-linked-images-to-gallery-v01/trunk
- Files:
-
- 2 edited
-
attach-linked-images.php (modified) (2 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
add-linked-images-to-gallery-v01/trunk/attach-linked-images.php
r352529 r685232 17 17 function externimg_find_imgs ($post_id) { 18 18 19 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;20 21 if (wp_is_post_revision($post_id)) return;22 23 if ($c=get_option('externimg_catlist')) {24 $catfound = false;25 $catlist = get_the_category($post_id);26 foreach ($catlist as $category) {27 if (in_array($category->cat_ID, explode(',', $c)))28 $catfound = true;29 }30 if (!$catfound) return;31 }32 $post = get_post($post_id);33 $a = get_option('externimg_authlist');34 if($a && !in_array($post->post_author, explode(',', $a))) return;35 36 $l = get_option('externimg_replacesrc');37 $k = get_option('externimg_custtagname');38 $processed = get_post_custom_values($k, $post_id);39 $replaced = false;40 $content = $post->post_content;41 $imgs = externimg_get_img_tags($post_id);42 global $externimg_count;43 44 for($i=0; $i<count($imgs); $i++) {45 if (!$processed || !in_array($imgs[$i], $processed)) {46 47 $parseurl = parse_url($imgs[$i]);48 $pathname = $parseurl['path'];49 $filename = substr(strrchr($pathname, '/'), 1);50 if (preg_match ('/(\.php|\.aspx?)$/', $filename) ) $filename .= '.jpg';51 $imgid = externimg_sideload($imgs[$i], $filename, $post_id);52 $imgpath = wp_get_attachment_url($imgid);53 if (!is_wp_error($imgpath)) {54 if ($l=='custtag') {55 add_post_meta($post_id, $k, $imgs[$i], false);56 } else {57 $trans = preg_quote($imgs[$i], "/");58 $content = preg_replace('/(<img[^>]* src=[\'"]?)('.$trans.')/', '$1'.$imgpath, $content);59 $replaced = true;60 }61 $processed[] = $imgs[i];62 $externimg_count++;63 }64 }65 }66 if ($replaced) {67 $upd = array();68 $upd['ID'] = $post_id;69 $upd['post_content'] = $content;70 wp_update_post($upd);71 }19 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; 20 21 if (wp_is_post_revision($post_id)) return; 22 23 if ($c=get_option('externimg_catlist')) { 24 $catfound = false; 25 $catlist = get_the_category($post_id); 26 foreach ($catlist as $category) { 27 if (in_array($category->cat_ID, explode(',', $c))) 28 $catfound = true; 29 } 30 if (!$catfound) return; 31 } 32 $post = get_post($post_id); 33 $a = get_option('externimg_authlist'); 34 if($a && !in_array($post->post_author, explode(',', $a))) return; 35 36 $l = get_option('externimg_replacesrc'); 37 $k = get_option('externimg_custtagname'); 38 $processed = get_post_custom_values($k, $post_id); 39 $replaced = false; 40 $content = $post->post_content; 41 $imgs = externimg_get_img_tags($post_id); 42 global $externimg_count; 43 44 for($i=0; $i<count($imgs); $i++) { 45 if (!$processed || !in_array($imgs[$i], $processed)) { 46 47 $parseurl = parse_url($imgs[$i]); 48 $pathname = $parseurl['path']; 49 $filename = substr(strrchr($pathname, '/'), 1); 50 if (preg_match ('/(\.php|\.aspx?)$/', $filename) ) $filename .= '.jpg'; 51 $imgid = externimg_sideload($imgs[$i], $filename, $post_id); 52 $imgpath = wp_get_attachment_url($imgid); 53 if (!is_wp_error($imgpath)) { 54 if ($l=='custtag') { 55 add_post_meta($post_id, $k, $imgs[$i], false); 56 } else { 57 $trans = preg_quote($imgs[$i], "/"); 58 $content = preg_replace('/(<img[^>]* src=[\'"]?)('.$trans.')/', '$1'.$imgpath, $content); 59 $replaced = true; 60 } 61 $processed[] = $imgs[i]; 62 $externimg_count++; 63 } 64 } 65 } 66 if ($replaced) { 67 $upd = array(); 68 $upd['ID'] = $post_id; 69 $upd['post_content'] = $content; 70 wp_update_post($upd); 71 } 72 72 } 73 73 74 74 function externimg_getext ($file) { 75 if (function_exists('mime_content_type'))76 $mime = mime_content_type($file);77 else return '';78 switch($mime) {79 case 'image/jpg':80 case 'image/jpeg':81 return '.jpg';82 break;83 case 'image/gif':84 return '.gif';85 break;86 case 'image/png':87 return '.png';88 break;89 }90 return '';75 if (function_exists('mime_content_type')) 76 $mime = mime_content_type($file); 77 else return ''; 78 switch($mime) { 79 case 'image/jpg': 80 case 'image/jpeg': 81 return '.jpg'; 82 break; 83 case 'image/gif': 84 return '.gif'; 85 break; 86 case 'image/png': 87 return '.png'; 88 break; 89 } 90 return ''; 91 91 } 92 92 93 93 function externimg_sideload ($file, $url, $post_id) { 94 if(!empty($file)){95 $file_array['tmp_name'] = download_url($file);96 if(is_wp_error($file_array['tmp_name'])) return;97 $file_array['name'] = basename($file);98 //$desc = @$desc;99 $desc = externimg_getext($file);100 101 $pathparts = pathinfo($file_array['tmp_name']);102 if (''==$pathparts['extension']) {103 $ext = externimg_getext($file_array['tmp_name']);104 rename($file_array['tmp_name'], $file_array['tmp_name'] . $ext);105 $file_array['name'] = basename($file_array['tmp_name']) . $ext;106 $file_array['tmp_name'] .= $ext;107 }108 109 $id = media_handle_sideload($file_array, $post_id, $desc);110 $src = $id;111 112 if(is_wp_error($id)) {113 @unlink($file_array['tmp_name']);114 return $id;115 }116 }117 if (!empty($src)) return $src;118 else return false;94 if(!empty($file)){ 95 $file_array['tmp_name'] = download_url($file); 96 if(is_wp_error($file_array['tmp_name'])) return; 97 $file_array['name'] = basename($file); 98 //$desc = @$desc; 99 $desc = externimg_getext($file); 100 101 $pathparts = pathinfo($file_array['tmp_name']); 102 if (''==$pathparts['extension']) { 103 $ext = externimg_getext($file_array['tmp_name']); 104 rename($file_array['tmp_name'], $file_array['tmp_name'] . $ext); 105 $file_array['name'] = basename($file_array['tmp_name']) . $ext; 106 $file_array['tmp_name'] .= $ext; 107 } 108 109 $id = media_handle_sideload($file_array, $post_id, $desc); 110 $src = $id; 111 112 if(is_wp_error($id)) { 113 @unlink($file_array['tmp_name']); 114 return $id; 115 } 116 } 117 if (!empty($src)) return $src; 118 else return false; 119 119 } 120 120 121 121 function externimg_get_img_tags ($post_id) { 122 $post = get_post($post_id);123 $w = get_option('externimg_whichimgs');124 $s = get_option('siteurl');125 126 $result = array();127 //preg_match_all('/<img[^>]+src=\\\\?[\'"]?([^>\\\"\' ]+)/', $content, $matches);128 preg_match_all('/<img[^>]* src=[\'"]?([^>\'" ]+)/', $post->post_content, $matches);129 for ($i=0; $i<count($matches[0]); $i++) {130 $uri = $matches[1][$i];131 132 //only check FQDNs133 if (preg_match('/^http:\/\//', $uri)) {134 //make sure it's not external135 if ($s != substr($uri, 0, strlen($s)) ) {136 //only match Flickr images?137 if($w == 'All' || 138 ($w == 'Flickr' && preg_match('/^http:\/\/[a-z0-9]+\.static\.flickr\.com\//', $uri)) ) {139 $result[] = $matches[1][$i];140 }141 }142 }143 }144 return $result;122 $post = get_post($post_id); 123 $w = get_option('externimg_whichimgs'); 124 $s = get_option('siteurl'); 125 126 $result = array(); 127 //preg_match_all('/<img[^>]+src=\\\\?[\'"]?([^>\\\"\' ]+)/', $content, $matches); 128 preg_match_all('/<img[^>]* src=[\'"]?([^>\'" ]+)/', $post->post_content, $matches); 129 for ($i=0; $i<count($matches[0]); $i++) { 130 $uri = $matches[1][$i]; 131 132 //only check FQDNs 133 if (preg_match('/^http:\/\//', $uri)) { 134 //make sure it's not external 135 if ($s != substr($uri, 0, strlen($s)) ) { 136 //only match Flickr images? 137 if($w == 'All' || 138 ($w == 'Flickr' && preg_match('/^http:\/\/[a-z0-9]+\.static\.flickr\.com\//', $uri)) ) { 139 $result[] = $matches[1][$i]; 140 } 141 } 142 } 143 } 144 return $result; 145 145 } 146 146 147 147 function externimg_savefile ($file, $url, $post_id) { 148 $time = null;149 150 $uploads = wp_upload_dir($time);151 $filename = wp_unique_filename( $uploads['path'], $url, $unique_filename_callback );152 $savepath = $uploads['path'] . "/$filename";153 154 if($fp = fopen($savepath, 'w')) {155 fwrite($fp, $file);156 fclose($fp);157 }158 159 $wp_filetype = wp_check_filetype( $savepath, $mimes );160 $type = $wp_filetype['type'];161 $title = $filename;162 $content = '';163 164 // Construct the attachment array165 $attachment = array(166 'post_mime_type' => $type,167 'guid' => $uploads['url'] . "/$filename",168 'post_parent' => $post_id,169 'post_title' => $title,170 'post_content' => $content171 );172 173 // Save the data174 $id = wp_insert_attachment($attachment, $savepath, $post_id);175 if ( !is_wp_error($id) ) {176 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );177 } else return '';178 return $uploads['url'] . "/$filename";148 $time = null; 149 150 $uploads = wp_upload_dir($time); 151 $filename = wp_unique_filename( $uploads['path'], $url, $unique_filename_callback ); 152 $savepath = $uploads['path'] . "/$filename"; 153 154 if($fp = fopen($savepath, 'w')) { 155 fwrite($fp, $file); 156 fclose($fp); 157 } 158 159 $wp_filetype = wp_check_filetype( $savepath, $mimes ); 160 $type = $wp_filetype['type']; 161 $title = $filename; 162 $content = ''; 163 164 // Construct the attachment array 165 $attachment = array( 166 'post_mime_type' => $type, 167 'guid' => $uploads['url'] . "/$filename", 168 'post_parent' => $post_id, 169 'post_title' => $title, 170 'post_content' => $content 171 ); 172 173 // Save the data 174 $id = wp_insert_attachment($attachment, $savepath, $post_id); 175 if ( !is_wp_error($id) ) { 176 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 177 } else return ''; 178 return $uploads['url'] . "/$filename"; 179 179 } 180 180 … … 182 182 //modified from code found at http://www.bin-co.com/php/scripts/load/ 183 183 function externimg_loadimage ($url) { 184 185 $url_parts = parse_url($url);186 $ch = false;187 $info = array(//Currently only supported by curl.188 'http_code' => 200189 );190 $response = '';191 192 $send_header = array(193 'Accept' => 'text/*',194 'User-Agent' => 'Attach-Linked-Images WordPress Plugin (http://www.bbqiguana.com/)'195 );196 197 198 199 ///////////////////////////// Curl /////////////////////////////////////200 //If curl is available, use curl to get the data.201 if(function_exists("curl_init")) { //$options['use'] == 'fsocketopen'))) { //Don't use curl if it is specifically stated to use fsocketopen in the options202 203 $page = $url;204 205 $ch = curl_init($url_parts['host']);206 207 curl_setopt($ch, CURLOPT_URL, $page) or die("Invalid cURL Handle Resouce");208 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Just return the data - not print the whole thing.209 curl_setopt($ch, CURLOPT_HEADER, true); //We need the headers210 curl_setopt($ch, CURLOPT_NOBODY, false); //Yes, get the body.211 212 //Set the headers our spiders sends213 curl_setopt($ch, CURLOPT_USERAGENT, $send_header['User-Agent']); //The Name of the UserAgent we will be using ;)214 $custom_headers = array("Accept: " . $send_header['Accept'] );215 curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);216 217 @curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/binget-cookie.txt"); //If ever needed...218 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);219 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);220 @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);221 222 if(isset($url_parts['user']) and isset($url_parts['pass'])) {223 $custom_headers = array("Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass']));224 curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);225 }226 227 $response = curl_exec($ch);228 $info = curl_getinfo($ch); //Some information on the fetch229 if('http://l.yimg.com/g/images/photo_unavailable.gif'==$info['url']) $body = '';230 curl_close($ch); //If the session option is not set, close the session.231 232 //////////////////////////////////////////// FSockOpen //////////////////////////////233 } else { //If there is no curl, use fsocketopen - but keep in mind that most advanced features will be lost with this approch.234 if(isset($url_parts['query'])) {235 $page = $url_parts['path'] . '?' . $url_parts['query'];236 } else {237 $page = $url_parts['path'];238 }239 240 if(!isset($url_parts['port'])) $url_parts['port'] = 80;241 $fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, 30);242 if ($fp) {243 $out = "GET $page HTTP/1.0\r\n"; //HTTP/1.0 is much easier to handle than HTTP/1.1244 $out .= "Host: $url_parts[host]\r\n";245 $out .= "Accept: $send_header[Accept]\r\n";246 $out .= "User-Agent: {$send_header['User-Agent']}\r\n";247 $out .= "Connection: Close\r\n";248 249 //HTTP Basic Authorization support250 if(isset($url_parts['user']) and isset($url_parts['pass'])) {251 $out .= "Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass']) . "\r\n";252 }253 $out .= "\r\n";254 255 fwrite($fp, $out);256 while (!feof($fp)) {257 $response .= fgets($fp, 128);258 }259 fclose($fp);260 }261 }262 263 //Get the headers in an associative array264 $headers = array();265 266 if($info['http_code'] == 404 || $info['http_code'] == 400) {267 $body = '';268 $headers['Status'] = 404;269 } else {270 //Seperate header and content271 $header_text = substr($response, 0, $info['header_size']);272 $body = substr($response, $info['header_size']);273 274 foreach(explode("\n",$header_text) as $line) {275 $parts = explode(": ",$line);276 if(count($parts) == 2) $headers[$parts[0]] = chop($parts[1]);277 }278 }279 280 //if($options['return_info']) return array('body' => $body, 'info' => $info, 'curl_handle'=>$ch);281 return $body;184 185 $url_parts = parse_url($url); 186 $ch = false; 187 $info = array(//Currently only supported by curl. 188 'http_code' => 200 189 ); 190 $response = ''; 191 192 $send_header = array( 193 'Accept' => 'text/*', 194 'User-Agent' => 'Attach-Linked-Images WordPress Plugin (http://www.bbqiguana.com/)' 195 ); 196 197 198 199 ///////////////////////////// Curl ///////////////////////////////////// 200 //If curl is available, use curl to get the data. 201 if(function_exists("curl_init")) { //$options['use'] == 'fsocketopen'))) { //Don't use curl if it is specifically stated to use fsocketopen in the options 202 203 $page = $url; 204 205 $ch = curl_init($url_parts['host']); 206 207 curl_setopt($ch, CURLOPT_URL, $page) or die("Invalid cURL Handle Resouce"); 208 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Just return the data - not print the whole thing. 209 curl_setopt($ch, CURLOPT_HEADER, true); //We need the headers 210 curl_setopt($ch, CURLOPT_NOBODY, false); //Yes, get the body. 211 212 //Set the headers our spiders sends 213 curl_setopt($ch, CURLOPT_USERAGENT, $send_header['User-Agent']); //The Name of the UserAgent we will be using ;) 214 $custom_headers = array("Accept: " . $send_header['Accept'] ); 215 curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers); 216 217 @curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/binget-cookie.txt"); //If ever needed... 218 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 219 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5); 220 @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 221 222 if(isset($url_parts['user']) and isset($url_parts['pass'])) { 223 $custom_headers = array("Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass'])); 224 curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers); 225 } 226 227 $response = curl_exec($ch); 228 $info = curl_getinfo($ch); //Some information on the fetch 229 if('http://l.yimg.com/g/images/photo_unavailable.gif'==$info['url']) $body = ''; 230 curl_close($ch); //If the session option is not set, close the session. 231 232 //////////////////////////////////////////// FSockOpen ////////////////////////////// 233 } else { //If there is no curl, use fsocketopen - but keep in mind that most advanced features will be lost with this approch. 234 if(isset($url_parts['query'])) { 235 $page = $url_parts['path'] . '?' . $url_parts['query']; 236 } else { 237 $page = $url_parts['path']; 238 } 239 240 if(!isset($url_parts['port'])) $url_parts['port'] = 80; 241 $fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, 30); 242 if ($fp) { 243 $out = "GET $page HTTP/1.0\r\n"; //HTTP/1.0 is much easier to handle than HTTP/1.1 244 $out .= "Host: $url_parts[host]\r\n"; 245 $out .= "Accept: $send_header[Accept]\r\n"; 246 $out .= "User-Agent: {$send_header['User-Agent']}\r\n"; 247 $out .= "Connection: Close\r\n"; 248 249 //HTTP Basic Authorization support 250 if(isset($url_parts['user']) and isset($url_parts['pass'])) { 251 $out .= "Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass']) . "\r\n"; 252 } 253 $out .= "\r\n"; 254 255 fwrite($fp, $out); 256 while (!feof($fp)) { 257 $response .= fgets($fp, 128); 258 } 259 fclose($fp); 260 } 261 } 262 263 //Get the headers in an associative array 264 $headers = array(); 265 266 if($info['http_code'] == 404 || $info['http_code'] == 400) { 267 $body = ''; 268 $headers['Status'] = 404; 269 } else { 270 //Seperate header and content 271 $header_text = substr($response, 0, $info['header_size']); 272 $body = substr($response, $info['header_size']); 273 274 foreach(explode("\n",$header_text) as $line) { 275 $parts = explode(": ",$line); 276 if(count($parts) == 2) $headers[$parts[0]] = chop($parts[1]); 277 } 278 } 279 280 //if($options['return_info']) return array('body' => $body, 'info' => $info, 'curl_handle'=>$ch); 281 return $body; 282 282 } 283 283 284 284 function externimg_backcatalog () { 285 global $externimg_count;286 $count = 0;287 $pp = get_posts( array( 'numberposts'=>-1 ) );288 foreach ($pp as $p) {289 try {290 //echo '<p>' . $p->ID . ': ' . $p->title . '</p>';291 echo '<p>[' . $p->ID . '] ' . $p->post_title . ': ';292 externimg_find_imgs($p->ID);293 echo '<em>' . $externimg_count . ' images processed.</em></p>';294 } catch (Exception $e) {295 echo '<em>an error occurred</em>.</p>';296 }297 $count += $externimg_count;298 }285 global $externimg_count; 286 $count = 0; 287 $pp = get_posts( array( 'numberposts'=>-1 ) ); 288 foreach ($pp as $p) { 289 try { 290 //echo '<p>' . $p->ID . ': ' . $p->title . '</p>'; 291 echo '<p>[' . $p->ID . '] ' . $p->post_title . ': '; 292 externimg_find_imgs($p->ID); 293 echo '<em>' . $externimg_count . ' images processed.</em></p>'; 294 } catch (Exception $e) { 295 echo '<em>an error occurred</em>.</p>'; 296 } 297 $count += $externimg_count; 298 } 299 299 } 300 300 301 301 function externimg_getauthors() { 302 global $wpdb;303 $query = "SELECT $wpdb->users.* FROM $wpdb->users ORDER BY display_name;";304 $authors = $wpdb->get_results($query);305 return $authors;302 global $wpdb; 303 $query = "SELECT $wpdb->users.* FROM $wpdb->users ORDER BY display_name;"; 304 $authors = $wpdb->get_results($query); 305 return $authors; 306 306 } 307 307 308 308 function externimg_menu () { 309 if ( function_exists('add_options_page') ) {310 add_options_page('Linked IMGs to Gallery', 'Linked IMGs', 8, 'externimg', 'externimg_options');311 }309 if ( function_exists('add_options_page') ) { 310 add_options_page('Linked IMGs to Gallery', 'Linked IMGs', 8, 'externimg', 'externimg_options'); 311 } 312 312 } 313 313 314 314 function externimg_init () { 315 //$plugin_dir = basename(dirname(__FILE__));316 //load_plugin_textdomain('externimg', 'wp-content/plugins/'.$plugin_dir, 'externimg');317 318 register_setting('externimg', 'externimg_whichimgs');319 register_setting('externimg', 'externimg_replacesrc');320 register_setting('externimg', 'externimg_custtagname');321 register_setting('externimg', 'externimg_cats');322 register_setting('externimg', 'externimg_auths');323 register_setting('externimg', 'externimg_catlist');324 register_setting('externimg', 'externimg_authlist');315 //$plugin_dir = basename(dirname(__FILE__)); 316 //load_plugin_textdomain('externimg', 'wp-content/plugins/'.$plugin_dir, 'externimg'); 317 318 register_setting('externimg', 'externimg_whichimgs'); 319 register_setting('externimg', 'externimg_replacesrc'); 320 register_setting('externimg', 'externimg_custtagname'); 321 register_setting('externimg', 'externimg_cats'); 322 register_setting('externimg', 'externimg_auths'); 323 register_setting('externimg', 'externimg_catlist'); 324 register_setting('externimg', 'externimg_authlist'); 325 325 } 326 326 327 327 function externimg_install () { 328 //add default options329 $whichimgs = get_option('externimg_whichimgs');330 $replacesrc = get_option('externimg_replacesrc');331 $custtagname = get_option('externimg_custtagname');332 $catlist = get_option('externimg_catlist');333 $authlist = get_option('externimg_authlist');334 335 if(!$whichimgs) update_option('externimg_whichimgs', 'All');336 if(!$replacesrc) update_option('externimg_replacesrc', 'replace');337 if(!$custtagname) update_option('externimg_custtagname', 'externimg');338 if(!$catlist) update_option('externimg_catlist', '');339 if(!$authlist) update_option('externimg_authlist', '');328 //add default options 329 $whichimgs = get_option('externimg_whichimgs'); 330 $replacesrc = get_option('externimg_replacesrc'); 331 $custtagname = get_option('externimg_custtagname'); 332 $catlist = get_option('externimg_catlist'); 333 $authlist = get_option('externimg_authlist'); 334 335 if(!$whichimgs) update_option('externimg_whichimgs', 'All'); 336 if(!$replacesrc) update_option('externimg_replacesrc', 'replace'); 337 if(!$custtagname) update_option('externimg_custtagname', 'externimg'); 338 if(!$catlist) update_option('externimg_catlist', ''); 339 if(!$authlist) update_option('externimg_authlist', ''); 340 340 } 341 341 342 342 function externimg_options () { 343 $_cats = '';344 $_auths = '';345 echo '<div class="wrap">';346 echo '<h2>Linked IMGs to Gallery Attachments</h2>';347 348 if ($_POST['action']=='backcatalog') {349 externimg_backcatalog();350 echo '<div id="message" class="updated fade" style="background-color:rgb(255,251,204);"><p>Finished processing past posts!</p></div>';351 }352 353 if ($_POST['action']=='update') {354 //check_admin_referer('externimg_update-action');355 //$_cats = implode(',', $_POST['externimg_cats']);356 //$_auths = implode(',', $_POST['externimg_auths']);357 update_option('externimg_whichimgs', $_POST['externimg_whichimgs'] );358 update_option('externimg_replacesrc', $_POST['externimg_replacesrc'] );359 update_option('externimg_custtagname', $_POST['externimg_custtagname'] );360 if($_POST['externimg_catlist']) update_option('externimg_catlist', $_cats );361 update_option('externimg_catlist', ($_POST['externimg_catlist'] ) ? implode(',', $_POST['externimg_cats'] ) : '');362 update_option('externimg_authlist', ($_POST['externimg_authlist']) ? implode(',', $_POST['externimg_auths']) : '');363 //if($_POST['externimg_authlist']) update_option('externimg_authlist', $_auths);364 //update_option('externimg_catlist', $_POST['externimg_catlist'] );365 //update_option('externimg_authlist', $_POST['externimg_authlist'] );366 echo '<div id="message" class="updated fade" style="background-color:rgb(255,251,204);"><p>Settings updated.</p></div>';367 }368 echo '<big>Options</big>';369 echo '<form name="externimg-options" method="post" action="">';370 settings_fields('externimg');371 echo '<table class="form-table"><tbody>';372 echo '<tr valign="top"><th scope="row"><strong>Which external IMG links to process:</strong></th>';373 echo '<td><label for="myradio1"><input id="myradio1" type="radio" name="externimg_whichimgs" value="All" ' . (get_option('externimg_whichimgs')!='Flickr'?'checked="checked"':'') . '/> All images</label><br/>';374 echo '<label for="myradio2"><input id="myradio2" type="radio" name="externimg_whichimgs" value="Flickr" ' . (get_option('externimg_whichimgs')=='Flickr'?'checked="checked"':'') . ' /> Only Flickr images</label><br/>';375 echo '<p>By default, all external images are processed. This can be set to only apply to Flickr.</p>';376 echo '</td></tr>';377 echo '<tr valign="top"><th scope="row"><strong>What to do with the images:</th>';378 echo '<td><label for="myradio3"><input id="myradio3" type="radio" name="externimg_replacesrc" value="replace" ' . (get_option('externimg_replacesrc')!='custtag'?'checked="checked"':'') . ' /> Replace SRC attribute with local copy</label><br/>';379 echo '<label for="myradio4"><input id="myradio4" type="radio" name="externimg_replacesrc" value="custtag" ' . (get_option('externimg_replacesrc')=='custtag'?'checked="checked"':'') . ' /> Use custom tag:</label> ';380 echo '<input type="text" size="20" name="externimg_custtagname" value="' . get_option('externimg_custtagname') . '" /><br/>';381 echo '<p>Replacing the SRC attribute will convert the external IMG link to a local link, pointed at the local copy downloaded by this plugin. If the SRC attribute is not replaced, the plugin needs to mark the IMG as having been processed somehow, so this is done by tracking processed images in custom_tag values. You can change the name of the custom tag.</p></td></tr>';382 //echo '<tr valign="top"><th scope="row">This site name:</th><td>' . get_option('siteurl') . '</td></tr>';383 384 echo '<tr align="top"><th scope="row"><strong>Apply to these categories:</strong></th>';385 echo '<td><label for="myradio5"><input type="radio" id="myradio5" name="externimg_catlist" value="" ' . (get_option('externimg_catlist')==''?'checked="checked"':'') . ' /> All categories</label><br/>';386 echo '<label for="myradio6"><input type="radio" id="myradio6" name="externimg_catlist" value="Y" ' . (get_option('externimg_catlist')!=''?'checked="checked"':'') . ' /> Selected categories</label><br/>';387 388 $_cats = explode(',', get_option('externimg_catlist'));389 $chcount = 0;390 $cats = get_categories();391 foreach ($cats as $cat) {392 $chcount++;393 echo '<label for="mycheck'.$chcount.'"><input type="checkbox" id="mycheck'.$chcount.'" name="externimg_cats[]" value="' . $cat->cat_ID . '" '.(in_array($cat->cat_ID, $_cats)?'checked="checked"':'').' /> ' . $cat->cat_name . '</label><br/>';394 }395 echo '</td></tr>';396 echo '<tr align="top"><th scope="row"><strong>Apply to these authors:</strong></th>';397 echo '<td><label for="myradio7"><input type="radio" id="myradio7" name="externimg_authlist" value="" ' . (get_option('externimg_authlist')==''?'checked="checked"':'') . ' /> All authors</label><br/>';398 echo '<label for="myradio8"><input type="radio" id="myradio8" name="externimg_authlist" value="Y" ' . (get_option('externimg_authlist')!=''?'checked="checked"':'') . ' /> Selected authors</label><br/>';399 400 $_auths = explode(',', get_option('externimg_authlist'));401 $auths = externimg_getauthors();402 foreach ($auths as $auth) {403 $chcount++;404 echo '<label for="mycheck'.$chcount.'"><input type="checkbox" id="mycheck'.$chcount.'" name="externimg_auths[]" value="' . $auth->ID . '" '.(in_array($auth->ID, $_auths)?'checked="checked"':'').'/> ' . $auth->display_name . '</label><br/>';405 }406 echo '</td></tr>';407 408 echo '</tbody></table>';409 echo '<div class="submit">';410 //echo '<input type="hidden" name="externimg_update" value="action" />';411 echo '<input type="submit" name="submit" class="button-primary" value="' . __('Save Changes') . '" />';412 echo '</div>';413 echo '</form>';414 415 echo '<form name="externimg-backcatalog" method="post" action="">';416 echo '<div class="wrap">';417 echo '<big>Process all posts</big>';418 echo '<p>Use this function to apply the plugin to all previous posts. The settings specified above will still be respected.</p>';419 echo '<p><em>Please note that this can take a long time for sites with a lot of posts.</em></p>';420 echo '<div class="submit">';421 echo '<input type="hidden" name="action" value="backcatalog">';422 echo '<input type="submit" class="button-primary" value="' . __('Process') . '" />';423 echo '</div>';424 echo '<p> </p>';425 echo '</div>';426 echo '</form>';427 428 echo '<div class="wrap">';429 echo '<big>Donate</big>';430 echo '<p>If you like this plugin consider donating a small amount to the author using PayPal to support further plugin development.</p>';431 echo '<div align="center"><form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="[email protected]"><input type="hidden" name="item_name" value="Donations for WP-Externimage Plugin"><input type="hidden" name="currency_code" value="USD"><input type="image" src="http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"></form></div>';432 echo '<p>If you think donating money is somehow impersonal you could also choose items from my <a href="http://www.amazon.com/registry/wishlist/18LMHOMRM49P8/ref=cm_wl_act_vv">Amazon.com wishlist</a>.</p>';433 echo '</div>';434 echo '';435 echo '</div>';343 $_cats = ''; 344 $_auths = ''; 345 echo '<div class="wrap">'; 346 echo '<h2>Linked IMGs to Gallery Attachments</h2>'; 347 348 if ($_POST['action']=='backcatalog') { 349 externimg_backcatalog(); 350 echo '<div id="message" class="updated fade" style="background-color:rgb(255,251,204);"><p>Finished processing past posts!</p></div>'; 351 } 352 353 if ($_POST['action']=='update') { 354 //check_admin_referer('externimg_update-action'); 355 // $_cats = implode(',', $_POST['externimg_cats']); 356 // $_auths = implode(',', $_POST['externimg_auths']); 357 update_option('externimg_whichimgs', $_POST['externimg_whichimgs'] ); 358 update_option('externimg_replacesrc', $_POST['externimg_replacesrc'] ); 359 update_option('externimg_custtagname', $_POST['externimg_custtagname'] ); 360 if($_POST['externimg_catlist']) update_option('externimg_catlist', $_cats ); 361 update_option('externimg_catlist', ($_POST['externimg_catlist'] ) ? implode(',', $_POST['externimg_cats'] ) : ''); 362 update_option('externimg_authlist', ($_POST['externimg_authlist']) ? implode(',', $_POST['externimg_auths']) : ''); 363 // if($_POST['externimg_authlist']) update_option('externimg_authlist', $_auths); 364 // update_option('externimg_catlist', $_POST['externimg_catlist'] ); 365 // update_option('externimg_authlist', $_POST['externimg_authlist'] ); 366 echo '<div id="message" class="updated fade" style="background-color:rgb(255,251,204);"><p>Settings updated.</p></div>'; 367 } 368 echo '<big>Options</big>'; 369 echo '<form name="externimg-options" method="post" action="">'; 370 settings_fields('externimg'); 371 echo '<table class="form-table"><tbody>'; 372 echo '<tr valign="top"><th scope="row"><strong>Which external IMG links to process:</strong></th>'; 373 echo '<td><label for="myradio1"><input id="myradio1" type="radio" name="externimg_whichimgs" value="All" ' . (get_option('externimg_whichimgs')!='Flickr'?'checked="checked"':'') . '/> All images</label><br/>'; 374 echo '<label for="myradio2"><input id="myradio2" type="radio" name="externimg_whichimgs" value="Flickr" ' . (get_option('externimg_whichimgs')=='Flickr'?'checked="checked"':'') . ' /> Only Flickr images</label><br/>'; 375 echo '<p>By default, all external images are processed. This can be set to only apply to Flickr.</p>'; 376 echo '</td></tr>'; 377 echo '<tr valign="top"><th scope="row"><strong>What to do with the images:</th>'; 378 echo '<td><label for="myradio3"><input id="myradio3" type="radio" name="externimg_replacesrc" value="replace" ' . (get_option('externimg_replacesrc')!='custtag'?'checked="checked"':'') . ' /> Replace SRC attribute with local copy</label><br/>'; 379 echo '<label for="myradio4"><input id="myradio4" type="radio" name="externimg_replacesrc" value="custtag" ' . (get_option('externimg_replacesrc')=='custtag'?'checked="checked"':'') . ' /> Use custom tag:</label> '; 380 echo '<input type="text" size="20" name="externimg_custtagname" value="' . get_option('externimg_custtagname') . '" /><br/>'; 381 echo '<p>Replacing the SRC attribute will convert the external IMG link to a local link, pointed at the local copy downloaded by this plugin. If the SRC attribute is not replaced, the plugin needs to mark the IMG as having been processed somehow, so this is done by tracking processed images in custom_tag values. You can change the name of the custom tag.</p></td></tr>'; 382 // echo '<tr valign="top"><th scope="row">This site name:</th><td>' . get_option('siteurl') . '</td></tr>'; 383 384 echo '<tr align="top"><th scope="row"><strong>Apply to these categories:</strong></th>'; 385 echo '<td><label for="myradio5"><input type="radio" id="myradio5" name="externimg_catlist" value="" ' . (get_option('externimg_catlist')==''?'checked="checked"':'') . ' /> All categories</label><br/>'; 386 echo '<label for="myradio6"><input type="radio" id="myradio6" name="externimg_catlist" value="Y" ' . (get_option('externimg_catlist')!=''?'checked="checked"':'') . ' /> Selected categories</label><br/>'; 387 388 $_cats = explode(',', get_option('externimg_catlist')); 389 $chcount = 0; 390 $cats = get_categories(); 391 foreach ($cats as $cat) { 392 $chcount++; 393 echo '<label for="mycheck'.$chcount.'"><input type="checkbox" id="mycheck'.$chcount.'" name="externimg_cats[]" value="' . $cat->cat_ID . '" '.(in_array($cat->cat_ID, $_cats)?'checked="checked"':'').' /> ' . $cat->cat_name . '</label><br/>'; 394 } 395 echo '</td></tr>'; 396 echo '<tr align="top"><th scope="row"><strong>Apply to these authors:</strong></th>'; 397 echo '<td><label for="myradio7"><input type="radio" id="myradio7" name="externimg_authlist" value="" ' . (get_option('externimg_authlist')==''?'checked="checked"':'') . ' /> All authors</label><br/>'; 398 echo '<label for="myradio8"><input type="radio" id="myradio8" name="externimg_authlist" value="Y" ' . (get_option('externimg_authlist')!=''?'checked="checked"':'') . ' /> Selected authors</label><br/>'; 399 400 $_auths = explode(',', get_option('externimg_authlist')); 401 $auths = externimg_getauthors(); 402 foreach ($auths as $auth) { 403 $chcount++; 404 echo '<label for="mycheck'.$chcount.'"><input type="checkbox" id="mycheck'.$chcount.'" name="externimg_auths[]" value="' . $auth->ID . '" '.(in_array($auth->ID, $_auths)?'checked="checked"':'').'/> ' . $auth->display_name . '</label><br/>'; 405 } 406 echo '</td></tr>'; 407 408 echo '</tbody></table>'; 409 echo '<div class="submit">'; 410 //echo '<input type="hidden" name="externimg_update" value="action" />'; 411 echo '<input type="submit" name="submit" class="button-primary" value="' . __('Save Changes') . '" />'; 412 echo '</div>'; 413 echo '</form>'; 414 415 echo '<form name="externimg-backcatalog" method="post" action="">'; 416 echo '<div class="wrap">'; 417 echo '<big>Process all posts</big>'; 418 echo '<p>Use this function to apply the plugin to all previous posts. The settings specified above will still be respected.</p>'; 419 echo '<p><em>Please note that this can take a long time for sites with a lot of posts.</em></p>'; 420 echo '<div class="submit">'; 421 echo '<input type="hidden" name="action" value="backcatalog">'; 422 echo '<input type="submit" class="button-primary" value="' . __('Process') . '" />'; 423 echo '</div>'; 424 echo '<p> </p>'; 425 echo '</div>'; 426 echo '</form>'; 427 428 echo '<div class="wrap">'; 429 echo '<big>Donate</big>'; 430 echo '<p>If you like this plugin consider donating a small amount to the author using PayPal to support further plugin development.</p>'; 431 echo '<div align="center"><form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="[email protected]"><input type="hidden" name="item_name" value="Donations for WP-Externimage Plugin"><input type="hidden" name="currency_code" value="USD"><input type="image" src="http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"></form></div>'; 432 echo '<p>If you think donating money is somehow impersonal you could also choose items from my <a href="http://www.amazon.com/registry/wishlist/18LMHOMRM49P8/ref=cm_wl_act_vv">Amazon.com wishlist</a>.</p>'; 433 echo '</div>'; 434 echo ''; 435 echo '</div>'; 436 436 } 437 437 438 438 if ( is_admin() ) { // admin actions 439 add_action('admin_menu', 'externimg_menu');440 add_action('admin_init', 'externimg_init');439 add_action('admin_menu', 'externimg_menu'); 440 add_action('admin_init', 'externimg_init'); 441 441 } 442 442 register_activation_hook(__FILE__, 'externimg_install'); -
add-linked-images-to-gallery-v01/trunk/readme.txt
r497894 r685232 1 1 === Add Linked Images To Gallery === 2 Contributors: bbqiguana 2 Contributors: bbqiguana, tiefpunkt 3 3 Donate link: http://www.bbqiguana.com/donate/ 4 4 Tags: images, gallery, photobloggers, attachments, photo, links, external, photographers, Flickr, save, download … … 38 38 = How does this plugin work? = 39 39 40 The plugin examines the HTML source of your post when you save it, inspecting each IMG tag, and processing them according to the options you have selected. 40 The plugin examines the HTML source of your post when you save it, inspecting each IMG tag, and processing them according to the options you have selected. 41 41 42 42 Under the default settings, it will find IMG tags with links to images on other web sites and copy those images to your web site, updating the IMG src to point to your copy. … … 61 61 == Changelog == 62 62 63 = 1.4 = 63 = 1.4 = 64 64 * Updated to fix a bug introduced with WordPress 3.1 65 65 * Default option is now "replace" rather than "custom tag" … … 75 75 * Added a test for DOING_AUTOSAVE to prevent a dowload loop on autosaved drafts 76 76 77 = 1.0.1 = 77 = 1.0.1 = 78 78 * Added require_once for necessary WP library functions 79 79
Note: See TracChangeset
for help on using the changeset viewer.