public function cache_imageAction() { $request = $this->getRequest(); $width = (int) $request->getParam('width'); $height = (int) $request->getParam('height'); $cached_file = $request->getParam('cached_file'); $file = $request->getParam('file') . $request->getParam('extension'); $extension = $request->getParam('extension'); $gray = $request->getParam('gray') == 'gray'; $crop = $request->getParam('crop') == 'crop'; $watermark = $request->getParam('watermark') == 'watermark' ? 'watermark.png' : false; $model_images = new Helper_Images(); $image = false; if ($width && $height) { $image = $model_images->resize('/' . $file, $width, $height, $crop, $watermark, $gray); } else { if ($width) { $image = $model_images->resizeWidth('/' . $file, $width, $watermark, $gray); } else { if ($height) { $image = $model_images->resizeHeight('/' . $file, $height, $watermark, $gray); } else { $this->forward('error', 'error404'); } } } if ($image) { $response = $this->getResponse(); $response->addHeader('Content-type:' . JO_File_Ext::getMimeFromFile($image)); $response->appendBody(file_get_contents($image)); exit; } else { $this->forward('error', 'error404'); } }
public function array_transform($array) { $array_text = ''; if (isset($array['item'])) { foreach ($array['item'] as $values) { $array_text .= "<item>\n"; foreach ($values as $key => $value) { if ($key == 'description') { $array_text .= "<{$key}><![CDATA[{$value}]]></{$key}>\n"; } elseif ($key == 'enclosure') { if ($value) { // $image_info = @getimagesize($value); // if($image_info && isset($image_info['mime'])) { // $array_text .= "<$key url=\"".$value."\" type=\"".$image_info['mime']."\" />\n"; // } else { $ext = explode('?', pathinfo($value, PATHINFO_EXTENSION)); $array_text .= "<{$key} url=\"" . $value . "\" type=\"" . JO_File_Ext::getMimeFromExt($ext[0]) . "\" />\n"; // } } } else { $array_text .= "<{$key}>{$value}</{$key}>\n"; } } $array_text .= "</item>\n"; } } return $array_text; }
public static function upload($image, $image_server) { if (!self::$error) { if (!self::$connect->putObjectFile($image, Helper_Config::get('amazons3_bucklet'), $image_server, JO_Api_Amazon::ACL_PUBLIC_READ, array(), JO_File_Ext::getMimeFromFile($image))) { self::$error = self::translate('Unable to upload to the server!'); } } }
/** * Return file mimetype * * @param string $path file path * @return string **/ protected function _mimetype($path) { if (empty($this->_options['mimeDetect']) || $this->_options['mimeDetect'] == 'auto') { $this->_options['mimeDetect'] = $this->_getMimeDetect(); } switch ($this->_options['mimeDetect']) { case 'finfo': if (empty($this->_finfo)) { $this->_finfo = finfo_open(FILEINFO_MIME); } $type = @finfo_file($this->_finfo, $path); break; case 'php': $type = mime_content_type($path); break; case 'linux': $type = exec('file -ib ' . escapeshellarg($path)); break; case 'bsd': $type = exec('file -Ib ' . escapeshellarg($path)); break; case 'jo': $type = JO_File_Ext::getMimeFromFile(basename($path)); break; default: $pinfo = pathinfo($path); $ext = isset($pinfo['extension']) ? strtolower($pinfo['extension']) : ''; $type = isset($this->_mimeTypes[$ext]) ? $this->_mimeTypes[$ext] : 'unknown;'; } $type = explode(';', $type); if ($this->_options['mimeDetect'] != 'internal' && $type[0] == 'application/octet-stream') { $pinfo = pathinfo($path); $ext = isset($pinfo['extension']) ? strtolower($pinfo['extension']) : ''; if (!empty($ext) && !empty($this->_mimeTypes[$ext])) { $type[0] = $this->_mimeTypes[$ext]; } } return $type[0]; }
public static function getUserImage($user, $prefix = null) { if (!$user['avatar']) { $user['avatar'] = Helper_Config::get('no_avatar'); } $sizes = self::userThumbSizes(); $format_size = false; if ($sizes) { foreach ($sizes as $val => $key) { if ($key == $prefix) { $format_size = $val; break; } } } if (!$format_size) { return false; } $user['user_id'] = $user['user_id'] ? $user['user_id'] : -1; $image_stored = self::userAvatarExist($user['user_id'], $prefix); if ($image_stored) { return $image_stored; } $model_images = new Helper_Images(); $sizes = explode('x', $format_size); $width = (int) isset($sizes[0]) ? $sizes[0] : 0; $height = (int) isset($sizes[1]) ? $sizes[1] : 0; if ($width && $height) { $img = $model_images->resize($user['avatar'], $width, $height, true); } else { if ($width && !$height) { $img = $model_images->resizeWidth($user['avatar'], $width); } else { if ($height && !$width) { $img = $model_images->resizeHeight($user['avatar'], $height); } } } if ($img) { $data = array('image' => $img, 'original' => $model_images->original($user['avatar']), 'width' => $model_images->getSizes('width'), 'height' => $model_images->getSizes('height'), 'mime' => JO_File_Ext::getMimeFromFile($img), 'size' => $prefix, 'user_id' => $user['user_id']); self::userAvatarCreate($data); return $data; } return false; }
public function jscssAction() { $request = $this->getRequest(); $response = $this->getResponse(); $file_path = $request->getQuery('file_path'); if ($file_path && file_exists(BASE_PATH . '/' . $file_path)) { $this->noViewRenderer(true); $type = JO_File_Ext::getMimeFromFile($file_path); $live = 86400 * 365; $response->addHeader("Cache-Control: private, max-age={$live}, pre-check={$live}"); $response->addHeader("Pragma: private"); $response->addHeader("Expires: " . date(DATE_RFC822, time() + $live)); $response->addHeader("Content-type: " . $type); $etag = md5_file(BASE_PATH . '/' . $file_path); $lastmodified = max(0, filemtime(BASE_PATH . '/' . $file_path)); $hash = $lastmodified . '-' . md5_file(BASE_PATH . '/' . $file_path); $response->addHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime(BASE_PATH . '/' . $file_path)) . ' GMT', true, 304); if ($request->getServer('HTTP_IF_MODIFIED_SINCE') && strtotime($request->getServer('HTTP_IF_MODIFIED_SINCE')) == filemtime(BASE_PATH . '/' . $file_path)) { $response->addHeader("HTTP/1.1 304 Not Modified"); $response->appendBody(''); exit; } else { $response->addHeader("Etag: {$hash}"); } $fileData = @file_get_contents(BASE_PATH . '/' . $file_path); $response->addHeader("Content-Length: " . strlen($fileData)); $response->setLevel(9); $response->appendBody($fileData); exit; } else { $this->forward('error', 'error404'); } }
/** * Put an object * * @param mixed $input Input data * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param string $contentType Content type * @return boolean */ public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null) { if ($input == false) { return false; } $rest = new JO_Api_Amazon_S3request('PUT', $bucket, $uri); if (is_string($input)) { $input = array('data' => $input, 'size' => strlen($input), 'md5sum' => base64_encode(md5($input, true))); } // Data if (isset($input['fp'])) { $rest->fp =& $input['fp']; } elseif (isset($input['file'])) { $rest->fp = @fopen($input['file'], 'rb'); } elseif (isset($input['data'])) { $rest->data = $input['data']; } // Content-Length (required) if (isset($input['size']) && $input['size'] > 0) { $rest->size = $input['size']; } else { if (isset($input['file'])) { $rest->size = filesize($input['file']); } elseif (isset($input['data'])) { $rest->size = strlen($input['data']); } } // Content-Type if ($contentType !== null) { $input['type'] = $contentType; } elseif (!isset($input['type']) && isset($input['file'])) { // $input['type'] = self::__getMimeType($input['file']); $input['type'] = JO_File_Ext::getMimeFromFile($input['file']); } else { $input['type'] = 'application/octet-stream'; } // We need to post with the content-length and content-type, MD5 is optional if ($rest->size > 0 && ($rest->fp !== false || $rest->data !== false)) { $rest->setHeader('Content-Type', $input['type']); if (isset($input['md5sum'])) { $rest->setHeader('Content-MD5', $input['md5sum']); } $rest->setAmzHeader('x-amz-acl', $acl); foreach ($metaHeaders as $h => $v) { $rest->setAmzHeader('x-amz-meta-' . $h, $v); } $rest->getResponse(); } else { $rest->response->error = array('code' => 0, 'message' => 'Missing input parameters'); } if ($rest->response->error === false && $rest->response->code !== 200) { $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); } if ($rest->response->error !== false) { //trigger_error(sprintf("JO_Api_Amazon::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING); return false; } return true; }
private static function uploatToServer($image, $image_server) { $s3 = new JO_Api_Amazon(JO_Registry::get('awsAccessKey'), JO_Registry::get('awsSecretKey')); $s3->putBucket(JO_Registry::get('bucklet'), JO_Api_Amazon::ACL_PUBLIC_READ); if ($s3->getBucketLogging(JO_Registry::get('bucklet'))) { if ($s3->putObjectFile($image, JO_Registry::get('bucklet'), $image_server, JO_Api_Amazon::ACL_PUBLIC_READ, array(), JO_File_Ext::getMimeFromFile($image))) { return true; } else { return false; } } return false; }
/** * Evaluates the message and returns modifications for inline images and backgrounds * @access public * @return $message */ public function MsgHTML($message, $basedir = '') { if ($this->attachmendImagesBody && preg_match_all("/(((src|background)=[\"'](.*)[\"'])|((background-image:| )\\s?url\\([\"'](.*)[\"']\\)))/Ui", $message, $match)) { $images = array(); foreach ($match[4] as $r => $img) { $filename = array_shift(explode('?', basename($img ? $img : $match[7][$r]))); $md5 = md5($filename); $cid = 'cid:' . $md5; if (!$img) { $images[] = array('url' => $match[7][$r], 'search' => '/' . preg_quote($match[0][$r], '/') . '/Ui', 'replace' => $match[6][$r] . "url(\"" . $cid . "\")", 'cid' => $cid, 'filename' => $filename, 'md5' => $md5); } else { $images[] = array('url' => $img, 'search' => '/' . preg_quote($match[0][$r], '/') . '/Ui', 'replace' => $match[3][$r] . "=\"" . $cid . "\"", 'cid' => $cid, 'filename' => $filename, 'md5' => $md5); } } if ($images) { foreach ($images as $i => $image) { $ext = pathinfo($image['url'], PATHINFO_EXTENSION); $mimeType = JO_File_Ext::getMimeFromExt($ext); if ($this->AddEmbeddedImage($image['url'], $image['cid'], $image['filename'], 'base64', $mimeType)) { $message = preg_replace($image['search'], $image['replace'], $message); } } } } $this->IsHTML(true); $this->Body = $message; if (empty($this->AltBody)) { $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\\/\\1>/s', '', $message))); if (!empty($textMsg)) { $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); } } if (empty($this->AltBody)) { $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; } return $message; }
/** * Internal check to get the proper mimetype. * * This function would go over the available PHP methods to get * the MIME type. * * By default it will try to use the PHP fileinfo library which is * available from PHP 5.3 or as an PECL extension * (http://pecl.php.net/package/Fileinfo). * * It will get the magic file by default from the system wide file * which is usually available in /usr/share/magic on Unix or try * to use the file specified in the source directory of the API * (share directory). * * if fileinfo is not available it will try to use the internal * mime_content_type function. * * @param string $handle name of file or buffer to guess the type from * @return boolean <kbd>True</kbd> if successful * @throws JO_Api_Rackspace_Exception_Badcontenttype */ function _guess_content_type($handle) { if ($this->content_type) { return; } if (function_exists("finfo_open")) { $local_magic = dirname(__FILE__) . "/share/magic"; $finfo = @finfo_open(FILEINFO_MIME, $local_magic); if (!$finfo) { $finfo = @finfo_open(FILEINFO_MIME); } if ($finfo) { if (is_file((string) $handle)) { $ct = @finfo_file($finfo, $handle); } else { $ct = @finfo_buffer($finfo, $handle); } /* PHP 5.3 fileinfo display extra information like charset so we remove everything after the ; since we are not into that stuff */ if ($ct) { $extra_content_type_info = strpos($ct, "; "); if ($extra_content_type_info) { $ct = substr($ct, 0, $extra_content_type_info); } } if ($ct && $ct != 'application/octet-stream') { $this->content_type = $ct; } @finfo_close($finfo); } } if (!$this->content_type && (string) is_file($handle) && function_exists("mime_content_type")) { $this->content_type = @mime_content_type($handle); } if (!$this->content_type) { $this->content_type = JO_File_Ext::getMimeFromFile($handle); } if (!$this->content_type) { throw new JO_Api_Rackspace_Exception_Badcontenttype("Required Content-Type not set"); } return True; }
public static function getEventImage($user, $prefix = null) { $sizes = self::userThumbSizes(); $format_size = false; if ($sizes) { foreach ($sizes as $val => $key) { if ($key == $prefix) { $format_size = $val; break; } } } if (!$format_size) { return false; } $model_images = new Helper_Images(); $sizes = explode('x', $format_size); $width = (int) isset($sizes[0]) ? $sizes[0] : 0; $height = (int) isset($sizes[1]) ? $sizes[1] : 0; if ($width && $height) { $img = $model_images->resize($user['avatar'], $width, $height, true); } else { if ($width && !$height) { $img = $model_images->resizeWidth($user['avatar'], $width); } else { if ($height && !$width) { $img = $model_images->resizeHeight($user['avatar'], $height); } } } if ($img) { return array('image' => $img, 'original' => $model_images->original($user['avatar']), 'width' => $model_images->getSizes('width'), 'height' => $model_images->getSizes('height'), 'mime' => JO_File_Ext::getMimeFromFile($img)); } return false; }