function isCached($image, $cacheParams) { if (!rex_image::isValid($image)) { trigger_error('Given image is not a valid rex_image', E_USER_ERROR); } $original_cache_file = $this->getCacheFile($image, $cacheParams); $cache_files = glob($original_cache_file . '*'); // ----- check for cache file if (is_array($cache_files) && count($cache_files) == 1) { $cache_file = $cache_files[0]; // time of cache $cachetime = filectime($cache_file); $imagepath = $image->getFilePath(); if ($original_cache_file != $cache_file) { $image->img['format'] = strtoupper(OOMedia::_getExtension($cache_file)); $image->img['file'] = $image->img['file'] . '.' . OOMedia::_getExtension($cache_file); } // file exists? if (file_exists($imagepath)) { $filetime = filectime($imagepath); } else { // Missing original file for cache-validation! $image->sendErrorImage(); } // cache is newer? if ($cachetime > $filetime) { return true; } } return false; }
function execute() { global $REX; $from_path = realpath($this->image->img['filepath']); if (($ext = self::getExtension($from_path)) && in_array(strtolower($ext), self::$convert_types)) { // convert possible $convert_path = self::getConvertPath(); if ($convert_path != '') { // convert to image and save in tmp $to_path = $REX['GENERATED_PATH'] . '/files/image_manager__convert2img_' . md5($this->image->img['filepath']) . '_' . $this->image->img['file'] . '.png'; $cmd = $convert_path . ' -density 150 "' . $from_path . '[0]" -colorspace RGB "' . $to_path . '"'; // echo $cmd; exec($cmd, $out, $ret); if ($ret != 0) { return false; } $this->image->img['file'] = $this->image->img['file'] . '.png'; $this->image->img['filepath'] = $to_path; $this->image->img['format'] = strtoupper(OOMedia::_getExtension($to_path)); $this->tmp_imagepath = $to_path; $this->image->prepare(); } } else { // no image } return; }
function rex_image($filepath) { global $REX; // ----- check params if (!file_exists($filepath)) { $this->sendError('Imagefile does not exist - ' . $filepath); exit; } // ----- check filesize $max_file_size = $REX['ADDON']['image_manager']['max_resizekb'] * 1024; $filesize = filesize($filepath); if ($filesize > $max_file_size) { $error = 'Imagefile is to big.'; $error .= ' Only files < ' . $REX['ADDON']['image_manager']['max_resizekb'] . 'kb are allowed'; $error .= '- ' . $filepath . ', ' . OOMedia::_getFormattedSize($filesize); $this->sendError($error); exit; } // ----- imagepfad speichern $this->img = array(); $this->img['file'] = basename($filepath); $this->img['filepath'] = $filepath; $this->img['quality'] = $REX['ADDON']['image_manager']['jpg_quality']; $this->img['format'] = strtoupper(OOMedia::_getExtension($this->img['filepath'])); }
function rex_image($filepath) { global $REX; // ----- check params if (!file_exists($filepath)) { // 'Imagefile does not exist - '. $filepath $this->sendErrorImage(); } // ----- imagepfad speichern $this->img = array(); $this->img['file'] = basename($filepath); $this->img['filepath'] = $filepath; $this->img['quality'] = $REX['ADDON']['image_manager']['jpg_quality']; $this->img['format'] = strtolower(OOMedia::_getExtension($this->img['filepath'])); }
function rex_thumbnail($imgfile) { global $REX; // ----- imagepfad speichern $this->img = array(); $this->imgfile = $imgfile; // ----- gif support ? $this->gifsupport = function_exists('imageGIF'); // ----- detect image format $this->img['format'] = strtoupper(OOMedia::_getExtension($imgfile)); $this->img['src'] = false; if (strpos($imgfile, 'cache/') === false) { if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') { // --- JPEG $this->img['format'] = 'JPEG'; $this->img['src'] = @ImageCreateFromJPEG($imgfile); } elseif ($this->img['format'] == 'PNG') { // --- PNG $this->img['src'] = @ImageCreateFromPNG($imgfile); } elseif ($this->img['format'] == 'GIF') { // --- GIF if ($this->gifsupport) { $this->img['src'] = @ImageCreateFromGIF($imgfile); } } elseif ($this->img['format'] == 'WBMP') { // --- WBMP $this->img['src'] = @ImageCreateFromWBMP($imgfile); } // ggf error image senden if (!$this->img['src']) { $this->sendError(); exit; } $this->img['width'] = imagesx($this->img['src']); $this->img['height'] = imagesy($this->img['src']); $this->img['width_offset_thumb'] = 0; $this->img['height_offset_thumb'] = 0; // --- default quality jpeg $this->img['quality'] = $REX['ADDON']['image_resize']['jpg_quality']; $this->filters = array(); } }
/** * @access public * @static */ function _isImage($filename) { static $imageExtensions; if (!isset($imageExtensions)) { $imageExtensions = array('gif', 'jpeg', 'jpg', 'png', 'bmp'); } return in_array(OOMedia::_getExtension($filename), $imageExtensions); }
<?php // *************************************** Subpage: ADD FILE // ----- METHOD ADD FILE if ($media_method == 'add_file') { if (rex_post('save', 'boolean') || rex_post('saveandexit', 'boolean')) { if ($_FILES['file_new']['name'] != '' && $_FILES['file_new']['name'] != 'none') { if (!rex_mediapool_isAllowedMediaType($_FILES['file_new']['name'], rex_post('args', 'array'))) { $warning = $I18N->msg('pool_file_mediatype_not_allowed') . ' <var>.' . OOMedia::_getExtension($_FILES['file_new']['name'] . '</var>'); $whitelist = rex_mediapool_getMediaTypeWhitelist(rex_post('args', 'array')); $warning .= count($whitelist) > 0 ? '<br />' . $I18N->msg('pool_file_allowed_mediatypes') . ' <var>' . rtrim(implode('</var> <var>', $whitelist), ', ') . '</var>' : '<br />' . $I18N->msg('pool_file_banned_mediatypes') . ' <var>' . rtrim(implode('</var> <var>', rex_mediapool_getMediaTypeBlacklist()), ', ') . '</var>'; } else { $FILEINFOS['title'] = rex_request('ftitle', 'string'); if (!$PERMALL && !$REX['USER']->hasPerm("media[{$rex_file_category}]")) { $rex_file_category = 0; } // function in function.rex_mediapool.inc.php $return = rex_mediapool_saveMedia($_FILES['file_new'], $rex_file_category, $FILEINFOS, $REX['USER']->getValue('login')); if ($return['ok']) { $info = $return['msg']; $subpage = ''; } // ----- EXTENSION POINT if ($return['ok'] == 1) { rex_register_extension_point('MEDIA_ADDED', '', $return); } if (rex_post('saveandexit', 'boolean') && $return['ok'] == 1) { $file_name = $return['filename']; $ffiletype = $return['type']; $title = $return['title']; if ($opener_input_field == 'TINYIMG') {
/** * check if mediatpye(extension) is allowed for upload * * @param string $filename * @param array $args * @return bool */ function rex_mediapool_isAllowedMediaType($filename, $args = array()) { $file_ext = '.' . OOMedia::_getExtension($filename); if ($filename === '' || strpos($file_ext, ' ') !== false || $file_ext === '.') { return false; } $blacklist = rex_mediapool_getMediaTypeBlacklist(); $whitelist = rex_mediapool_getMediaTypeWhitelist($args); if (in_array($file_ext, $blacklist)) { return false; } if (count($whitelist) > 0 && !in_array($file_ext, $whitelist)) { return false; } return true; }