Пример #1
0
 public function processThumb($imgsrc, $_id, $isUrl = true)
 {
     $_id = empty($_id) ? $this->_id : $_id;
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     if ($isUrl) {
         $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     } else {
         $fileSystem = new Filesystem();
         $res_get_file = $fileSystem->copy($imgsrc, $tmpFile);
     }
     if (file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         /*$fileSystem = new Filesystem();
           $copy = $fileSystem->copy($tmpFile,$fileDest);*/
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $rs = $resizeObj->resizeImage($width, $height, 0);
         $res = $resizeObj->saveImage($fileDest, 100);
         if ($resizeObj) {
             $feed = self::model()->findByPk(new MongoId($_id));
             $fileDest = str_replace($storage, '', $fileDest);
             $feed->thumb = $fileDest;
             $res = $feed->save();
             return $res;
         }
     } else {
         throw new Exception("create file temp error!", 7);
     }
 }
Пример #2
0
 protected function beforeGetContentBody()
 {
     $sn = time();
     $i = 0;
     $tmpFile = $temp = Yii::app()->params['temp'];
     $storage = Yii::app()->params['feed_path'];
     $cdn = Yii::app()->params['cdn_url'];
     $contentParttern = $this->config['content_pattern'];
     foreach ($this->html->find("{$contentParttern} img") as $e) {
         $imgSrc = $e->src;
         if (!empty($imgSrc)) {
             $fileInfo = explode('.', $imgSrc);
             $fileType = $fileInfo[count($fileInfo) - 1];
             $fileName = 'tmp_' . $sn . $i . "." . $fileType;
             $sfile = $tmpFile . DS . $fileName;
             $res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
             if ($res_get_file && file_exists($sfile)) {
                 $fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
                 $fileSystem = new Filesystem();
                 $copy = $fileSystem->copy($sfile, $fileDest);
                 if ($copy) {
                     echo $fileDest . "\n";
                     $fileDestUrl = str_replace($storage, $cdn, $fileDest);
                     $fileDestUrl = str_replace(DS, "/", $fileDestUrl);
                     echo $fileDestUrl . "\n";
                     $e->src = $fileDestUrl;
                     echo 'replace file content success' . "\n";
                 } else {
                     echo 'replace file content error' . "\n";
                 }
             }
             $i++;
         }
     }
 }
Пример #3
0
 private function processThumb($_id, $imgsrc)
 {
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     if ($res_get_file && file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         $fileSystem = new Filesystem();
         //$copy = $fileSystem->copy($tmpFile,$fileDest);
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $resizeObj->resizeImage($width, $height, 0);
         $resizeObj->saveImage($fileDest, 100);
         //$resize = $imageCrop->resizeCrop($fileDest,$width,$height);
         if ($resizeObj) {
             echo 'copy file success!' . "\n";
             $feed = FeedModel::model()->findByPk(new MongoId($_id));
             $thumbPath = str_replace($storage, '', $fileDest);
             $feed->thumb = $thumbPath;
             $feed->status = 1;
             return $feed->save();
         }
     }
 }
Пример #4
0
 public function actionIndex()
 {
     $my_file = Yii::app()->params['storage'] . DS . 'meme_page.txt';
     $handle = fopen($my_file, 'r');
     $page = fread($handle, filesize($my_file));
     $page = intval($page);
     for ($i = $page; $i < $page + 2; $i++) {
         echo $url = 'http://www.lolhappens.com/page/' . $i;
         echo "\n";
         $html = file_get_html($url);
         $content = $html->find(".content-wrap", 0);
         foreach ($content->find(".social-bar") as $e) {
             $e->outertext = "";
         }
         //echo $content;exit;
         $storage = Yii::app()->params['storage'];
         $temp = Yii::app()->params['temp'];
         $j = 0;
         foreach ($content->find(".hentry") as $e) {
             $title = $e->find(".post-title h2 a", 0)->plaintext;
             $link = $e->find(".post-title h2 a", 0)->href;
             $imageUrl = $img = $e->find(".post-content p img", 0)->src;
             $fileInfo = explode('.', $img);
             $fileType = $fileInfo[count($fileInfo) - 1];
             $fileName = 's_' . $j . '_' . $i . time() . "." . $fileType;
             $fileDesc = $storage . DS . $fileName;
             $tmpFile = $temp . DS . $fileName;
             if (!$this->isExists($link)) {
                 $res_get_file = FileRemote::getFromUrl($img, $tmpFile);
                 if ($res_get_file && file_exists($tmpFile)) {
                     $meme = new MemeLink();
                     $meme->title = trim($title);
                     $meme->code = trim($link);
                     $meme->link = trim($link);
                     $meme->content = $imageUrl;
                     $meme->type = 'image';
                     $meme->source = 'lolhappens.com';
                     $meme->status = 0;
                     $meme->created_datetime = date('Y-m-d H:i:s');
                     if ($meme->save()) {
                         //copy file
                         $storage = Yii::app()->params['meme_path'];
                         $mId = $meme->_id;
                         $fileDest = StorageHelper::generalStoragePath($meme->_id, $fileType, $storage);
                         $fileSystem = new Filesystem();
                         $copy = $fileSystem->copy($tmpFile, $fileDest);
                         if ($copy) {
                             echo 'Copy file success' . "\n";
                             $img = str_replace($storage, '', $fileDest);
                             $img = str_replace(DS, '_', $img);
                             $meme->img = $img;
                             $meme->save();
                         } else {
                             if ($meme->delete()) {
                                 echo 'deleted:' . $mId . "\n";
                             }
                         }
                         echo 'save success!' . "\n";
                         echo $meme->_id . "\n";
                     } else {
                         $error = $meme->getErrors();
                         var_dump($error);
                     }
                 }
             } else {
                 continue;
             }
             echo 'File source:' . $img . "<br />";
             echo 'File dest:' . $fileDesc . "<br />";
             $j++;
         }
     }
     //write page end
     $data = $i;
     $handle = fopen($my_file, 'w') or die('Cannot open file:  ' . $my_file);
     fwrite($handle, $data);
     fclose($handle);
 }
Пример #5
0
 protected function afterGetContentBody()
 {
     $sn = time();
     $tmpFile = $temp = Yii::app()->params['temp'];
     $storage = Yii::app()->params['feed_path'];
     $cdn = Yii::app()->params['cdn_url'];
     $contentParttern = $this->config['content_pattern'];
     $contentPage = '';
     $k = 0;
     foreach ($this->html->find("{$contentParttern} .item-list ul li") as $e) {
         $k++;
     }
     if ($k > 0) {
         $numPage = $k - 1;
         for ($j = 2; $j < $numPage; $j++) {
             $link = $this->url . '&page=' . $j;
             echo $link . "\n";
             $htmlBodyPage = file_get_html($link);
             if (is_object($htmlBodyPage)) {
                 if (isset($this->config['remove_pattern']) || !empty($this->config['remove_pattern'])) {
                     $removePattern = explode('|', $this->config['remove_pattern']);
                     foreach ($removePattern as $rpt) {
                         if ($rpt != '') {
                             foreach ($htmlBodyPage->find("{$rpt}") as $e) {
                                 $e->outertext = '';
                             }
                         }
                     }
                 }
                 foreach ($htmlBodyPage->find("a") as $e) {
                     $innerText = $e->plaintext;
                     $e->outertext = $innerText;
                     //$e->href = '#';
                 }
                 //get image for content
                 $i = 0;
                 foreach ($htmlBodyPage->find("{$contentParttern} img") as $e) {
                     $imgSrc = $e->src;
                     if (!empty($imgSrc)) {
                         $fileInfo = explode('.', $imgSrc);
                         $fileType = $fileInfo[count($fileInfo) - 1];
                         $fileName = 'tmp_' . $sn . $i . "." . $fileType;
                         $sfile = $tmpFile . DS . $fileName;
                         $res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
                         if ($res_get_file && file_exists($sfile)) {
                             $fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
                             list($width, $height) = getimagesize($sfile);
                             if ($width > 500) {
                                 $width = 500;
                                 $height = 0;
                                 $resizeObj = new ResizeImage($sfile);
                                 $resizeObj->resizeImage($width, $height);
                                 $resizeObj->saveImage($fileDest, 100);
                             } else {
                                 $fileSystem = new Filesystem();
                                 $copy = $fileSystem->copy($sfile, $fileDest);
                             }
                             //resize image
                             unlink($sfile);
                             if (file_exists($fileDest)) {
                                 echo $fileDest . "\n";
                                 $fileDestUrl = str_replace($storage, $cdn, $fileDest);
                                 $fileDestUrl = str_replace(DS, "/", $fileDestUrl);
                                 echo $fileDestUrl . "\n";
                                 //$e->src = $fileDestUrl;
                                 $e->outertext = '<img src="' . $fileDestUrl . '" title="' . $e->title . '" alt="' . $e->alt . '" />';
                                 echo 'replace file content success in page' . $j . "\n";
                             } else {
                                 echo 'replace file content error' . "\n";
                             }
                         }
                         $i++;
                     }
                 }
                 $contentPage .= $htmlBodyPage->find($this->config['content_pattern'], 0)->innertext;
             }
         }
     }
     $this->content .= $contentPage;
 }