Ejemplo n.º 1
0
 public function autoSaveRemoteImage($str, $baseURI = '')
 {
     $str = stripslashes($str);
     $watermark = bpBase::loadSysCLass('watermark');
     $img_array = array();
     //$str = stripslashes($str);
     if (get_magic_quotes_gpc()) {
         $str = stripslashes($str);
     }
     preg_match_all('#src="(http://(((?!").)+).(jpg|gif|bmp|png))"#i', $str, $img_array);
     $img_array_urls = array_unique($img_array[1]);
     $dstFolder = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'images';
     @chmod($dstFolder, 0777);
     if ($baseURI) {
         $img_array_urls = $this->_expandlinks($img_array_urls, $baseURI);
         if ($img_array_urls) {
             exit;
         }
     }
     if ($img_array_urls) {
         $i = 0;
         $time = SYS_TIME;
         foreach ($img_array_urls as $k => $v) {
             if (!strpos($v, $_SERVER['HTTP_HOST'])) {
                 //不保存本站的
                 $filenames = explode('.', $v);
                 $filenamesCount = count($filenames);
                 //
                 $year = date('Y', $time);
                 $month = date('m', $time);
                 $pathInfo = upFileFolders($time);
                 $dstFolder = $pathInfo['path'];
                 $rand = randStr(4);
                 $filePath = $dstFolder . $time . $rand . '.' . $filenames[$filenamesCount - 1];
                 //
                 @httpCopy($v, $filePath, 5);
                 //自动缩放
                 $imgInfo = @getimagesize($filePath);
                 $maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth'));
                 $maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth;
                 if ($imgInfo[0] > $maxPicWidth) {
                     $newWidth = $maxPicWidth;
                     $newHeight = $imgInfo[1] * $newWidth / $imgInfo[0];
                     bpBase::loadSysClass('image');
                     image::zfResize($filePath, $filePath, $newWidth, $newHeight, 1, 2, 0, 0, 1);
                 }
                 //
                 if (file_exists($filePath)) {
                     $watermark->wm($filePath);
                     $str = str_replace($v, 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.' . $filenames[$filenamesCount - 1], $str);
                 }
             }
             $i++;
         }
     }
     return $str;
 }
Ejemplo n.º 2
0
 function _setFirstImageAsThumb($thisChannel, $contentStr, $imgNo = 1)
 {
     $thumbWidht = $thisChannel->thumbwidth;
     $thmbHeight = $thisChannel->thumbheight;
     if (!$thumbWidht || !$thmbHeight) {
         return '';
     }
     //get image url
     $contentStr = stripslashes($contentStr);
     @preg_match_all('#src="((((?!").)+).(jpg|bmp))"#i', $contentStr, $img_array);
     $img_array_urls = $img_array[1];
     if ($img_array_urls) {
         $imgNo = abs(intval($imgNo));
         $imgNo = $imgNo < 1 ? 1 : $imgNo;
         $imgUrl = $img_array_urls[$imgNo - 1];
         if (!strpos($imgUrl, 'ttp://')) {
             $imgUrl = MAIN_URL_ROOT . $imgUrl;
         }
         $time = SYS_TIME;
         $pathInfo = upFileFolders($time);
         $dstFolder = $pathInfo['path'];
         $rand = rand(0, 10000);
         $tempImgPath = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg';
         if (file_exists($tempImgPath)) {
             @unlink($tempImgPath);
         }
         @httpCopy($imgUrl, $tempImgPath);
         //new start,带水印的图片加缩略图需要裁切掉水印
         if (file_exists(ABS_PATH . 'constant' . DIRECTORY_SEPARATOR . 'watermark.config.php')) {
             @(include_once ABS_PATH . 'constant' . DIRECTORY_SEPARATOR . 'watermark.config.php');
             if (USE_WATERMARK) {
                 if (WATERMARK_TYPE != 'text') {
                     $oImgSize = getimagesize($tempImgPath);
                     //原图尺寸
                     //水印尺寸
                     $watermarkImageAttr = @getimagesize(ABS_PATH . 'editor' . DIRECTORY_SEPARATOR . 'ckfinder' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'watermark' . DIRECTORY_SEPARATOR . 'logo.png');
                     $width = $oImgSize[0];
                     $height = $oImgSize[1] - $watermarkImageAttr[1];
                     //新图高度为原图高度减水印高度
                     //
                     $firstImg = imagecreatefromjpeg($tempImgPath);
                     if (function_exists("imagecreatetruecolor")) {
                         //GD2.0.1
                         $dstScaleImg = imagecreatetruecolor($width, $height);
                     } else {
                         $dstScaleImg = imagecreate($width, $height);
                     }
                     imagecopy($dstScaleImg, $firstImg, 0, 0, 0, 0, $oImgSize[0], $oImgSize[1]);
                     //裁切
                     ImageJPEG($dstScaleImg, ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg');
                     //保存图片
                     imagedestroy($dstScaleImg);
                     imagedestroy($firstImg);
                 }
             }
         }
         //new end,裁切水印end
         bpBase::loadSysClass('image');
         image::zfResize(ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg', $dstFolder . $time . $rand . '.jpg', $thumbWidht, $thmbHeight, 1 | 4, 2);
         $this->_setThumb($thisChannel, ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg', $dstFolder, $time . $rand, 'jpg');
         @unlink(ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg');
         //
         $year = date('Y', $time);
         $month = date('m', $time);
         $day = date('d', $time);
         $url = $pathInfo['url'] . $time . $rand . '.jpg';
         //
         $location = 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $url;
         return $location;
     } else {
         return '';
     }
     //
 }