? LICENSE.txt
? get_image_mod.module
? get_image_new_functions.patch
Index: get_image.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/get_image/get_image.info,v
retrieving revision 1.1
diff -u -p -r1.1 get_image.info
--- get_image.info	14 Dec 2008 10:06:42 -0000	1.1
+++ get_image.info	21 Aug 2010 12:15:57 -0000
@@ -3,4 +3,10 @@ name = "get_image"
 description = Long-range images will be saved to the local server.
 version = "6.x-1.0-beta1"
 core = "6.x"
-project = "get_image"
\ No newline at end of file
+project = "get_image"
+; Information added by drupal.org packaging script on 2010-04-14
+version = "6.x-1.0-beta5"
+core = "6.x"
+project = "get_image"
+datestamp = "1271206505"
+
Index: get_image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/get_image/get_image.module,v
retrieving revision 1.6
diff -u -p -r1.6 get_image.module
--- get_image.module	18 May 2010 09:05:21 -0000	1.6
+++ get_image.module	21 Aug 2010 12:15:58 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: get_image.module,v 1.6 2010/05/18 09:05:21 eastcn Exp $
+// $Id: get_image.module,v 1.5 2010/04/13 14:50:51 eastcn Exp $
 
 /**
  * @file: 分析节点 body 中的 img 标签，将远程图片保存到本地服务器
@@ -25,16 +25,29 @@ function get_image_menu(){
  * Implementation of hook_nodeapi()
  */
 function get_image_nodeapi(&$node, $op) {
+  
   switch ($op) {
-    case 'presave':
-      if(variable_get('get_image_'.$node->type, 0) && $node->body){
-        global $get_image_node;
-        
-        $get_image_node = & $node;
-        
-        $node->body = preg_replace_callback('/(<img.*?src=")(.*?)"/ms', '_get_image_save', $node->body);
+    case 'view':
+	//drupal_set_message(t('view'));
+	//drupal_set_message(t('view %nid',array('%nid' => $nodeId)));
+	break;
+    case 'update':
+	//drupal_set_message(t('update'));
+	//drupal_set_message(t('update @nid',array('@nid' => $node->nid)));
+    case 'presave':	
+	//drupal_set_message(t('presave'));
+      if( $node->status == '1' && variable_get('get_image_'.$node->type, 0) && $node->body){
+	variable_set('get_image_nid',$node->nid);
+	//drupal_set_message(t('presave @nid',array('@nid' => $node->nid)));
+        $node->body = preg_replace_callback('/(<[iI][mM][gG].*?[sS][rR][cC]=["])(.*?)["]/ms', '_get_image_save_double', $node->body);
+        $node->body = preg_replace_callback('/(<[iI][mM][gG].*?[sS][rR][cC]=[\'])(.*?)[\']/ms', '_get_image_save_simple', $node->body);
         $node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL);
       }
+      break;
+    default:
+	//drupal_set_message(t('default'));
+	//drupal_set_message(t('default @nid',array('@nid' => $node->nid)));
+	break;
   }
 }
 
@@ -60,50 +73,81 @@ function get_image_form_alter(&$form, $f
  * save image
  * 分析内容中的 img 标签，将远程图片保存到本地服务器
  */
-function _get_image_save($mat){
-	global $get_image_node;
-  static $files;
-	
+function _get_image_save_simple($mat){
+	static $files;
+  //drupal_set_message(t('get_image_save ,@nid ,@nodeId ,@varGetImg',array('@nid'=>$node->nid,'@nodeId' => $nodeId, '@varGetImg' => variable_get('get_image_nid',0))));
 	if(!isset($files[$mat[2]])){
-	  
-	  $files[$mat[2]] = $mat[0];
-	  
 	  if(!strstr($mat[2], $GLOBALS['base_url']) && strstr($mat[2], 'http://')){
-	    $file = new stdClass();
-	    
-	    // image url
-	    $file->uri =  $mat[2];
-      
-	    if($data = @file_get_contents($file->uri)){
-  	    $file->filename = basename($file->uri);
+	    if($data = @file_get_contents($mat[2])){
+	      $filename = end(explode('/', $mat[2]));
         
-        if(variable_get('get_image_rename', 0)){
-          $filename = md5($file->filename) .'.'. end(explode('.', $file->filename));
+	      if(variable_get('get_image_rename', 0)){
+	        $filename = md5($filename) .'.'. end(explode('.', $filename));
         }
         
-        if($path = get_image_path()){
-          $file->filepath = $path.'/'.$file->filename;
+	      if($path = get_image_path()){
+		      $file = file_save_data($data, $path.'/'.$filename);
+		      
+		      drupal_set_message(t('Save "@name" success. @path', array('@name' => $mat[2], '@path' => $path)));
+		      
+		      if(variable_get('get_image_absolute', 0)){
+		      	$file = $GLOBALS['base_url'] . $GLOBALS['base_path'] . $file;
+		      }else{
+		      	$file = $GLOBALS['base_path'] . $file;
+		      }
+		      
+		      $files[$mat[2]] = $mat[1] . $file.'\'';
+	      }else{
+	      	drupal_set_message(t('Save "@name" failed', array('@name' => $mat[2])), 'error');
+	      	$files[$mat[2]] = $mat[0];
+	      }
+	    }else{
+	    	$files[$mat[2]] = $mat[0];
+	    }
+	  }else{
+	  	$files[$mat[2]] = $mat[0];
+	  }
+  }
+  return $files[$mat[2]];
+}
+
+/**
+ * save image
+ * 分析内容中的 img 标签，将远程图片保存到本地服务器
+ */
+function _get_image_save_double($mat){
+	static $files;
+  //drupal_set_message(t('get_image_save ,@nid ,@nodeId ,@varGetImg',array('@nid'=>$node->nid,'@nodeId' => $nodeId, '@varGetImg' => variable_get('get_image_nid',0))));
+	if(!isset($files[$mat[2]])){
+	  if(!strstr($mat[2], $GLOBALS['base_url']) && strstr($mat[2], 'http://')){
+	    if($data = @file_get_contents($mat[2])){
+	      $filename = end(explode('/', $mat[2]));
+        
+	      if(variable_get('get_image_rename', 0)){
+	        $filename = md5($filename) .'.'. end(explode('.', $filename));
         }
-	      
-	      if($file->filepath = file_save_data($data, $file->filepath)){
-	        
-  	      if($error = file_validate_is_image($file)){
-  	        // is images
-  	        unlink($file->filepath);
-  	      }else{
-    	      drupal_set_message(t('Save "@name" success', array('@name' => $file->uri)));
-    	      
-    	      if(variable_get('get_image_absolute', 0)){
-    	      	$file->filepath = $GLOBALS['base_url'] . $GLOBALS['base_path'] . $file->filepath;
-    	      }else{
-    	      	$file->filepath = $GLOBALS['base_path'] . $file->filepath;
-    	      }
-    	      
-    	      $files[$mat[2]] = $mat[1] . $file->filepath.'"';
-  	      }
+        
+	      if($path = get_image_path()){
+		      $file = file_save_data($data, $path.'/'.$filename);
+		      
+		      drupal_set_message(t('Save "@name" success. @path', array('@name' => $mat[2], '@path' => $path)));
+		      
+		      if(variable_get('get_image_absolute', 0)){
+		      	$file = $GLOBALS['base_url'] . $GLOBALS['base_path'] . $file;
+		      }else{
+		      	$file = $GLOBALS['base_path'] . $file;
+		      }
+		      
+		      $files[$mat[2]] = $mat[1] . $file.'"';
+	      }else{
+	      	drupal_set_message(t('Save "@name" failed', array('@name' => $mat[2])), 'error');
+	      	$files[$mat[2]] = $mat[0];
 	      }
-	      
+	    }else{
+	    	$files[$mat[2]] = $mat[0];
 	    }
+	  }else{
+	  	$files[$mat[2]] = $mat[0];
 	  }
   }
   return $files[$mat[2]];
@@ -111,6 +155,7 @@ function _get_image_save($mat){
 
 /**
  * create folder
+ * 创建文件夹
  */
 function get_image_path() {
 	global $user;
@@ -120,9 +165,10 @@ function get_image_path() {
 	}else{
 		$mm = format_date(time(), 'custom', "Y|m|d");
     $m = explode('|', $mm);
-		$a = array('%uid' => $user->uid, '%username' => $user->name, '%Y' => $m[0], '%m' => $m[1], '%d' => $m[2]);
+		$a = array('%uid' => $user->uid, '%username' => $user->name, '%Y' => $m[0], '%m' => $m[1], '%d' => $m[2], '%nid' => variable_get('get_image_nid',0));
 		$b = strtr(variable_get('get_image_path', 'get_image'), $a);
 		$path = explode('/',$b);
+		
 	}
 
 	$dirs = array();
@@ -145,7 +191,7 @@ function get_image_settings_form() {
 		'#type'=> 'textfield',
 		'#title' => t('Path of saving'),
 		'#default_value' => variable_get('get_image_path', 'get_image'),
-		'#description' => t('The path where the files should be saved, may save by user id or user name or time, e.g.: get_image/%uid or photos/%username or image/%Y/%m/%d. Available variables: %uid, %username, %Y, %m, %d.'),
+		'#description' => t('The path where the files should be saved, may save by user id or user name or time, e.g.: get_image/%uid or photos/%username or image/%Y/%m/%d. Available variables: %uid, %username, %Y, %m, %d, %nid ¿?.'),
 		'#size' => '40',
 		'#required' => TRUE,
 	);
@@ -175,4 +221,4 @@ function get_image_settings_form() {
   }
   
 	return system_settings_form($form);
-}
\ No newline at end of file
+}
