private function _runAction($params)
 {
     extract($params);
     $isSaveSuccess = false;
     $image = $avatar;
     if (!empty($image) && ($imageData = WebUtils::httpRequest($image)) != '') {
         $savePath = UploadUtils::getTempAvatarPath();
         if (!empty($savePath)) {
             $config = Yii::app()->params['mobcent']['user'];
             $this->_deleteTempAvatarFiles($uid);
             $avatarFiles = $this->_getTempAvatarFiles($uid);
             $avatarBigFile = $savePath . '/' . $avatarFiles['big'];
             $avatarMidFile = $savePath . '/' . $avatarFiles['mid'];
             $avatarSmallFile = $savePath . '/' . $avatarFiles['small'];
             file_put_contents($avatarBigFile, $imageData);
             file_put_contents($avatarMidFile, $imageData);
             file_put_contents($avatarSmallFile, $imageData);
             require_once MOBCENT_APP_ROOT . '/components/discuz/source/class/class_image.php';
             $thumb = new Mobcent_Image();
             $zoomRes = true;
             $zoomRes &= $thumb->makeThumb($avatarBigFile, '', $config['avatarBigLength']);
             $zoomRes &= $thumb->makeThumb($avatarMidFile, '', $config['avatarMidLength']);
             $zoomRes &= $thumb->makeThumb($avatarSmallFile, '', $config['avatarSmallLength']);
             $isSaveSuccess = $zoomRes && $this->_saveAvatarByUcenter($uid, $this->flashdata_encode(file_get_contents($avatarBigFile)), $this->flashdata_encode(file_get_contents($avatarMidFile)), $this->flashdata_encode(file_get_contents($avatarSmallFile)));
             $this->_deleteTempAvatarFiles($uid);
         }
     }
     if ($isSaveSuccess) {
         $this->_updateAvatarStatus();
         return $res;
     } else {
         return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('保存文件失败'));
     }
     // return $isSaveSuccess ? $res : WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('保存文件失败'));
 }
Example #2
0
 public static function getThumbImageEx($image, $timeout = 15, $getImageInfo = false, $inBackgroud = false, $force = false)
 {
     $res = array('image' => $image, 'ratio' => '1');
     if (empty($image)) {
         return $res;
     }
     $config = self::_getThumbConfig();
     $allowDiscuzThumb = WebUtils::getDzPluginAppbymeAppConfig('image_thumb_allow_discuz');
     if (!$force && !$config['isThumb'] && $allowDiscuzThumb < 0) {
         return $res;
     }
     $thumbImage = $image;
     global $_G;
     $attachFile = '';
     // 是否用discuz生成的缩略图
     if ($allowDiscuzThumb === false || $allowDiscuzThumb > 0) {
         if ($_G['setting']['ftp']['on'] == 0) {
             $attachUrl = self::getAttachUrl();
             $attachUrl = str_replace($attachUrl, '', $image);
             $attachFile = $_G['setting']['attachdir'] . $attachUrl;
             $attachThumbFile = $attachFile . self::DISCUZ_THUMB_SUFFIX;
             if (file_exists($attachThumbFile)) {
                 $res['image'] = $thumbImage . self::DISCUZ_THUMB_SUFFIX;
                 if ($getImageInfo) {
                     $imageInfo = ImageUtils::getImageInfo($attachThumbFile);
                     $res['ratio'] = $imageInfo['ratio'];
                 }
                 return $res;
             }
         }
     }
     if (!$force && !$config['isThumb']) {
         return $res;
     }
     // 获取缩略图文件名
     $savePath = sprintf('%s/%s', MOBCENT_THUMB_PATH, self::_getThumbTempPath($image));
     $tempFileName = self::_getThumbTempFile($image);
     $smallFileName = $savePath . '/mobcentSmallPreview_' . $tempFileName;
     $bigFileName = $savePath . '/mobcentBigPreview_' . $tempFileName;
     if (file_exists($smallFileName) && file_exists($bigFileName)) {
         $res['image'] = self::_getThumbUrlFile($image, $tempFileName);
         if ($getImageInfo) {
             $imageInfo = ImageUtils::getImageInfo($smallFileName);
             $res['ratio'] = $imageInfo['ratio'];
         }
         return $res;
     }
     if ($inBackgroud) {
         CacheUtils::addThumbTaskList($image);
         return $res;
     }
     if (!is_dir($savePath)) {
         mkdir($savePath, 0777, true);
     }
     if (is_writable($savePath)) {
         // $timer = new CountTimer;
         // 先查看是否是本地附件的图片, 如果不是才去网络取图片数据
         $imageData = '';
         if ($attachFile != '' && file_exists($attachFile)) {
             $imageData = file_get_contents($attachFile);
         }
         if ($imageData == '') {
             $imageData = WebUtils::httpRequest($image, $timeout);
             if ($imageData == '') {
                 return $res;
             }
         }
         $thumb = null;
         $zoomRes = true;
         require_once MOBCENT_APP_ROOT . '/components/discuz/source/class/class_image.php';
         if (!file_exists($smallFileName)) {
             if (file_put_contents($smallFileName, $imageData) == false) {
                 return $res;
             }
             $thumb = new Mobcent_Image();
             $zoomRes &= $thumb->makeThumb($smallFileName, '', $config['imageSmallLength']);
         }
         if (!file_exists($bigFileName)) {
             if (file_put_contents($bigFileName, $imageData) == false) {
                 return $res;
             }
             $thumb == null && ($thumb = new Mobcent_Image());
             $zoomRes &= $thumb->makeThumb($bigFileName, '', $config['imageBigLength']);
         }
         if (file_exists($smallFileName) && file_exists($bigFileName) && $zoomRes) {
             $thumbImage = self::_getThumbUrlFile($image, $tempFileName);
             if ($getImageInfo) {
                 $imageInfo = ImageUtils::getImageInfo($smallFileName);
                 $res['ratio'] = $imageInfo['ratio'];
             }
         } else {
             FileUtils::safeDeleteFile($smallFileName);
             FileUtils::safeDeleteFile($bigFileName);
         }
         // var_dump($timer->stop());
     }
     $res['image'] = $thumbImage;
     return $res;
 }