Пример #1
0
 function images()
 {
     ini_set('memory_limit', '128M');
     require 'include/cypher.class.php';
     require 'include/timthumb/timthumb.class.php';
     $ecode_str = base64_decode(str_replace(preg_split('~~u', '-_,', null, PREG_SPLIT_NO_EMPTY), preg_split('~~u', '+/=', null, PREG_SPLIT_NO_EMPTY), $this->args[0]));
     $cypher = new Cypher();
     $cypher->key = Core::inst()->img_password;
     $images_param['src'] = '../view/upload/images/' . $cypher->decrypt(mb_substr($ecode_str, mb_strlen(Core::inst()->img_prefix, 'UTF-8') - mb_strlen($ecode_str, 'UTF-8')));
     $this('db')->query('SELECT * FROM `di.album_gallery`, `di.album_photo` WHERE `di.album_gallery`.`album_gallery_id` = `di.album_photo`.`album_photo_gallery_id` AND `di.album_photo`.`album_photo_name` = ? AND `di.album_gallery`.`album_gallery_visible` = 1;', $cypher->decrypt(mb_substr($ecode_str, mb_strlen(Core::inst()->img_prefix, 'UTF-8') - mb_strlen($ecode_str, 'UTF-8'))));
     if ($this('db')->affected_rows() == 0) {
         exit(0);
     }
     if (isset($this->args[1]) && $this->args[1] != 0) {
         $images_param['w'] = $this->args[1];
     }
     if (isset($this->args[2]) && $this->args[2] != 0) {
         $images_param['h'] = $this->args[2];
     }
     $images_param['q'] = 100;
     timthumb::start($images_param);
 }
Пример #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, 'timthumb::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;
     }
 }
Пример #3
0
 public static function start()
 {
     $tim = new timthumb();
     $tim->handleErrors();
     $tim->securityChecks();
     if ($tim->tryBrowserCache()) {
         exit(0);
     }
     $tim->handleErrors();
     if (FILE_CACHE_ENABLED && $tim->tryServerCache()) {
         exit(0);
     }
     $tim->handleErrors();
     $tim->run();
     $tim->handleErrors();
     exit(0);
 }
Пример #4
0
 /**
  *
  */
 protected function setMemoryLimit()
 {
     $inimem = ini_get('memory_limit');
     $inibytes = timthumb::returnBytes($inimem);
     $ourbytes = timthumb::returnBytes(static::$options['memory_limit']);
     if ($inibytes < $ourbytes) {
         ini_set('memory_limit', static::$options['memory_limit']);
         $this->debug(3, "Increased memory from {$inimem} to " . static::$options['memory_limit']);
     } else {
         $this->debug(3, "Not adjusting memory size because the current setting is " . $inimem . " and our size of " . static::$options['memory_limit'] . " is smaller.");
     }
 }
Пример #5
0
 /**
  * timthumb::setMemoryLimit()
  * 
  * @return
  */
 protected function setMemoryLimit()
 {
     $inimem = ini_get('memory_limit');
     $inibytes = timthumb::returnBytes($inimem);
     $ourbytes = timthumb::returnBytes(MEMORY_LIMIT);
     if ($inibytes < $ourbytes) {
         ini_set('memory_limit', MEMORY_LIMIT);
     }
 }
Пример #6
0
 /**
  *
  * Render resized image
  * @param string $image
  * @param int $width
  * @param int $height
  * @return string image
  */
 function renderImage($image, $width = 0, $height = 0)
 {
     if ($image) {
         if ($this->params->get('thumbnailmode', 1)) {
             $timthumb_params = array();
             if (preg_match('/^https?:\\/\\/[^\\/]+/i', $image)) {
                 $timthumb_params['src'] = $image;
             } else {
                 $timthumb_params['src'] = JURI::Base() . $image;
             }
             $timthumb_params['w'] = $width;
             $timthumb_params['h'] = $height;
             $timthumb_params['q'] = $this->params->get('imagequality', '90');
             $timthumb_params['a'] = $this->params->get('alignment', 'c');
             $timthumb_params['zc'] = $this->params->get('zoomcrop', '1');
             if ($this->params->get('customfilters', '') != '') {
                 $timthumb_params['f'] = $this->params->get('customfilters', '');
             } else {
                 $filters = $this->params->get('filters');
                 if (!empty($filters)) {
                     $filters = implode("|", $filters);
                     $timthumb_params['f'] = $filters;
                 }
             }
             $timthumb_params['s'] = $this->params->get('sharpen', '0');
             $timthumb_params['cc'] = $this->params->get('canvascolour', 'FFFFFF');
             $timthumb_params['ct'] = $this->params->get('canvastransparency', '1');
             $tb_image = timthumb::start($timthumb_params);
             // If can resize image -> return resized image, else keep original image
             if (trim($tb_image) != '') {
                 $image = $tb_image;
             }
             return $image;
         } else {
             return $image;
         }
     } else {
         return '';
     }
 }