public static function renderImages($image, $output, $type = 'listing_small', $output_url = true, $catId = null, $listingId = null)
 {
     $params = self::getParams($catId, $listingId);
     if (preg_match('/^https?:\\/\\/[^\\/]+/i', $image)) {
         $image = str_replace(JUri::root(), '', $image);
     }
     $timthumb_params = array();
     $timthumb_params['src'] = $image;
     switch ($type) {
         case "listing_small":
         default:
             $timthumb_params['w'] = $params->get('listing_small_image_width', 100);
             $timthumb_params['h'] = $params->get('listing_small_image_height', 100);
             $timthumb_params['a'] = $params->get('listing_small_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('listing_small_image_zoomcrop', 1);
             break;
         case "listing_big":
             $timthumb_params['w'] = $params->get('listing_big_image_width', 600);
             $timthumb_params['h'] = $params->get('listing_big_image_height', 600);
             $timthumb_params['a'] = $params->get('listing_big_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('listing_big_image_zoomcrop', 3);
             break;
         case "category_intro":
             $timthumb_params['w'] = $params->get('category_intro_image_width', 200);
             $timthumb_params['h'] = $params->get('category_intro_image_height', 200);
             $timthumb_params['a'] = $params->get('category_intro_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('category_intro_image_zoomcrop', 1);
             break;
         case "category_detail":
             $timthumb_params['w'] = $params->get('category_detail_image_width', 200);
             $timthumb_params['h'] = $params->get('category_detail_image_height', 200);
             $timthumb_params['a'] = $params->get('category_detail_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('category_detail_image_zoomcrop', 1);
             break;
         case "avatar":
             $timthumb_params['w'] = $params->get('avatar_width', 120);
             $timthumb_params['h'] = $params->get('avatar_height', 120);
             $timthumb_params['a'] = $params->get('avatar_alignment', 'c');
             $timthumb_params['zc'] = $params->get('avatar_zoomcrop', 1);
             break;
         case "listing_image":
             $timthumb_params['w'] = $params->get('listing_image_width', 100);
             $timthumb_params['h'] = $params->get('listing_image_height', 100);
             $timthumb_params['a'] = $params->get('listing_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('listing_image_zoomcrop', 1);
             break;
         case "location_image":
             $timthumb_params['w'] = $params->get('location_image_width', 100);
             $timthumb_params['h'] = $params->get('location_image_height', 120);
             $timthumb_params['a'] = $params->get('location_image_alignment', 'c');
             $timthumb_params['zc'] = $params->get('location_image_zoomcrop', 1);
             break;
         case "collection":
             $timthumb_params['w'] = $params->get('collection_icon_width', 100);
             $timthumb_params['h'] = $params->get('collection_icon_height', 100);
             $timthumb_params['a'] = $params->get('collection_icon_alignment', 'c');
             $timthumb_params['zc'] = $params->get('collection_icon_zoomcrop', 1);
             break;
     }
     $timthumb_params['q'] = $params->get('imagequality', 90);
     if ($params->get('customfilters', '') != '') {
         $timthumb_params['f'] = $params->get('customfilters', '');
     } else {
         $filters = $params->get('filters');
         if (!empty($filters)) {
             $filters = implode("|", $filters);
             $timthumb_params['f'] = $filters;
         }
     }
     $timthumb_params['s'] = $params->get('sharpen', 0);
     $timthumb_params['cc'] = trim($params->get('canvascolour', 'FFFFFF'), '#');
     $timthumb_params['ct'] = $params->get('canvastransparency', 1);
     $timthumb_params['output'] = $output;
     $tim = new jutimthumb($timthumb_params);
     $output = $tim->start();
     if ($output_url) {
         $output = str_replace(JPATH_SITE, substr(JUri::root(), 0, -1), $output);
     }
     return $output;
 }
Beispiel #2
0
 protected function getURL($url, $tempfile)
 {
     $this->lastURLError = false;
     $url = preg_replace('/ /', '%20', $url);
     if (function_exists('curl_init')) {
         $this->debug(3, "Curl is installed so using it to fetch URL.");
         self::$curlFH = fopen($tempfile, 'w');
         if (!self::$curlFH) {
             $this->error("Could not open {$tempfile} for writing.");
             return false;
         }
         self::$curlDataWritten = 0;
         $this->debug(3, "Fetching url with curl: {$url}");
         $curl = curl_init($url);
         curl_setopt($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
         curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'jutimthumb::curlWrite');
         @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         @curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
         $curlResult = curl_exec($curl);
         fclose(self::$curlFH);
         $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         if ($httpStatus == 404) {
             $this->set404();
         }
         if ($httpStatus == 302) {
             $this->error("External Image is Redirecting. Try alternate image url");
             return false;
         }
         if ($curlResult) {
             curl_close($curl);
             return true;
         } else {
             $this->lastURLError = curl_error($curl);
             curl_close($curl);
             return false;
         }
     } else {
         $img = @file_get_contents($url);
         if ($img === false) {
             $err = error_get_last();
             if (is_array($err) && $err['message']) {
                 $this->lastURLError = $err['message'];
             } else {
                 $this->lastURLError = $err;
             }
             if (preg_match('/404/', $this->lastURLError)) {
                 $this->set404();
             }
             return false;
         }
         if (!file_put_contents($tempfile, $img)) {
             $this->error("Could not write to {$tempfile}.");
             return false;
         }
         return true;
     }
 }