stanley-king 9 роки тому
батько
коміт
d3caef7a44
2 змінених файлів з 31 додано та 28 видалено
  1. 17 18
      crontab/crawl/body_filter.php
  2. 14 10
      mobile/control/goods.php

+ 17 - 18
crontab/crawl/body_filter.php

@@ -11,6 +11,11 @@
 class body_filder
 {
     private $goods_common;
+    static $save_path = BASE_DATA_PATH . '/upload/detail';
+    static $down_path = BASE_DATA_PATH . '/Download/detail';
+
+    //static $req_path = 'http://p.lrlz.com/upload/detail/';
+    static $req_path = 'http://localhost/data/upload/detail/';
 
     public function __construct()
     {
@@ -28,13 +33,10 @@ class body_filder
         return $val;
     }
 
-    private function download($url,&$path)
+    private function download($url,$path)
     {
         $info = pathinfo($url);
-        $name = md5($url) . '.' . $info['extension'];
 
-        $path = BASE_DATA_PATH . '/upload/detail';
-        $path = $path . '/' . $name;
         if(!file_exists($path)) {
             $pic_url = $info['dirname'] . '/' . urlencode($info['basename']);
             exec("wget -O $path $pic_url");
@@ -45,6 +47,7 @@ class body_filder
             if(filesize($path) > 0) {
                 return true;
             } else {
+                unlink($path);
                 return false;
             }
         } else {
@@ -56,11 +59,6 @@ class body_filder
     //
     private function filterex($val,$commid)
     {
-        static $save_path = BASE_DATA_PATH . '/upload/detail';
-        static $req_path = 'http://p.lrlz.com/upload/detail/';
-
-        //static $req_path = 'http://localhost/data/upload/detail/';
-
         $style = '/\s*<img\s*[^>]*src\s*=\s*\"([^>\"]*)\"\s*[^>]*>/i';
         $val = preg_match_all($style,$val,$match);
         if(!empty($val) && $val > 0)
@@ -70,21 +68,23 @@ class body_filder
             foreach($match[1] as $url)
             {
                 $info = pathinfo($url);
-
                 if(empty($info['extension'])) continue;
-                //if(strtolower($info['extension']) == 'gif') continue;
 
-                if($this->download($url,$path))
+                $name = md5($url) . '.' . $info['extension'];
+                $path = self::$down_path . '/' . $name;
+
+                if(file_exists($path) || $this->download($url,$path))
                 {
                     $name = "{$commid}-{$num}.{$info['extension']}";
-                    $newpath = "{$save_path}/{$name}";
+                    $newpath = self::$save_path . "/{$name}";
 
-                    if(file_exists($newpath)) unlink($newpath);
+                    if(file_exists($newpath)) {
+                        unlink($newpath);
+                    }
+                    copy($path,$newpath);
 
-                    rename($path,$newpath);
                     ++$num;
-
-                    $html .= "<img src=\"{$req_path}{$name}\">";
+                    $html .= "<img src=\"" . self::$req_path . "{$name}\">";
                 }
             }
 
@@ -105,7 +105,6 @@ class body_filder
             $body = $val['description'];
             $this->goods_common->where(array('num_iid' => $num_iid))->update(array('goods_body' => $body));
         }
-
     }
 
     public function proc()

+ 14 - 10
mobile/control/goods.php

@@ -630,18 +630,23 @@ class goodsControl extends mobileHomeControl
 
     public function detailOp()
     {
-        Log::record('detailOp start');
         $goods_id = intval($_GET['goods_id']);
-        if($goods_id <= 0) {
-            Log::record('detailOp end 1');
-            return Tpl::showpage('goods_detail');
+        if(empty($_GET['goods_id']) || $goods_id <= 0)
+        {
+            if(!empty($_GET['goods_commonid'])) {
+                $commonid = intval($_GET['goods_commonid']);
+            }
         }
-
-        $items = Model()->table('goods')->field('goods_commonid')->where(array('goods_id' => $goods_id))->limit(1)->select();
-        if(!empty($items) && count($items) > 0) {
-            $commonid = $items[0]['goods_commonid'];
+        else
+        {
+            $items = Model()->table('goods')->field('goods_commonid')->where(array('goods_id' => $goods_id))->limit(1)->select();
+            if(!empty($items) && count($items) > 0) {
+                $commonid = intval($items[0]['goods_commonid']);
+            }
         }
-        if(isset($commonid))
+
+
+        if(isset($commonid) && $commonid > 0)
         {
             $items = Model()->table('goods_common')->field('goods_body')->where(array('goods_commonid' => $commonid))->select();
             if(!empty($items) && count($items) > 0) {
@@ -650,6 +655,5 @@ class goodsControl extends mobileHomeControl
         }
 
         Tpl::showpage('goods_detail');
-        Log::record('detailOp end 2');
     }
 }