/** * Get image path * * @param int/string $input * @param string $mode * @param string $path * @param bool $return_placeholder * @return string */ public function imagePath($input, $mode = 'medium', $path = 'relative', $return_placeholder = true) { foreach ($GLOBALS['hooks']->load('class.catalogue.imagepath') as $hook) { include $hook; } $defaults = true; if (is_numeric($input)) { if (($result = $GLOBALS['db']->select('CubeCart_filemanager', false, array('file_id' => (int) $input))) !== false) { $file = $result[0]['filepath'] . $result[0]['filename']; $defaults = false; } } else { if (!empty($input)) { $file = str_replace(array('images/cache/', 'images/uploads/'), '', $input); $defaults = false; } } $skins = $GLOBALS['gui']->getSkinData(); // Fetch a default image, just in case... if (is_array($mode)) { foreach ($mode as $mode_name) { if (isset($skins['images'][$mode_name])) { $mode = $mode_name; break; } } } if ($return_placeholder && isset($skins['images'][$mode])) { $default = (string) $skins['images'][$mode]['default']; if (isset($skins['styles'][$GLOBALS['gui']->getStyle()]['images']) && !empty($skins['styles'][$GLOBALS['gui']->getStyle()]['images'])) { // do we use a separate style folder for images? $files = glob('skins/' . $GLOBALS['gui']->getSkin() . '/' . 'images/{common,' . $GLOBALS['gui']->getStyle() . '}/' . $default, GLOB_BRACE); } else { $files = glob('skins/' . $GLOBALS['gui']->getSkin() . '/' . 'images/' . $default, GLOB_BRACE); } if ($files && !empty($files[0])) { $placeholder_image = $files[0]; } } if (isset($file) && !empty($file) && !preg_match('/^skins\\//', $file)) { $source = CC_ROOT_DIR . '/images/source/' . $file; } else { $source = CC_ROOT_DIR . '/' . $placeholder_image; } if (!is_dir($source) && file_exists($source)) { if ($mode == 'source') { $folder = 'source'; $filename = $file; } else { $folder = 'cache'; if (isset($skins['images'][$mode])) { $data = $skins['images'][$mode]; preg_match('#(.*)(\\.\\w+)$#', $file, $match); $size = (int) $data['maximum']; $filename = sprintf('%s.%d%s', $match[1], $size, $match[2]); ## Find the source $image = CC_ROOT_DIR . '/images/' . $folder . '/' . $filename; if (!file_exists($image)) { ## Check if the target folder exists - if not, create it! if (!file_exists(dirname($image))) { mkdir(dirname($image), chmod_writable(), true); } ## Generate the image $gd = new GD(dirname($image), $size, (int) $data['quality']); $gd->gdLoadFile($source); $gd->gdSave(basename($image)); } } else { trigger_error('No image mode set', E_USER_NOTICE); return false; } } ## Generate the required path switch (strtolower($path)) { case 'filename': ## Calculate the from source folder $img = $filename; break; case 'root': ## Calculate the absolute filesystem path $img = CC_ROOT_DIR . '/images/' . $folder . '/' . $filename; break; case 'url': ## Calculate the absolute url $img = $GLOBALS['storeURL'] . '/images/' . $folder . '/' . $filename; break; case 'rel': case 'relative': ## Calculate the relative web path $img = $GLOBALS['rootRel'] . 'images/' . $folder . '/' . $filename; break; default: trigger_error('No image path set', E_USER_NOTICE); return false; } return $img; } else { return ''; } }
public function __construct($mode = false, $sub_dir = false) { // Define some constants if (!defined('FM_DL_ERROR_EXPIRED')) { define('FM_DL_ERROR_EXPIRED', 1); } if (!defined('FM_DL_ERROR_MAXDL')) { define('FM_DL_ERROR_MAXDL', 2); } if (!defined('FM_DL_ERROR_NOFILE')) { define('FM_DL_ERROR_NOFILE', 3); } if (!defined('FM_DL_ERROR_NOPRODUCT')) { define('FM_DL_ERROR_NOPRODUCT', 4); } if (!defined('FM_DL_ERROR_NORECORD')) { define('FM_DL_ERROR_NORECORD', 5); } if (!defined('FM_DL_ERROR_PAYMENT')) { define('FM_DL_ERROR_PAYMENT', 6); } switch ($mode) { case self::FM_FILETYPE_DL: $this->_manage_root = CC_ROOT_DIR . '/files'; break; case self::FM_FILETYPE_IMG: default: $mode = 1; $this->_manage_root = CC_ROOT_DIR . '/images/source'; $this->_manage_cache = CC_ROOT_DIR . '/images/cache'; } $this->_mode = (int) $mode; $this->_manage_dir = str_replace(CC_ROOT_DIR . '/', '', $this->_manage_root); $this->_sub_dir = $sub_dir ? $this->formatPath($sub_dir) : null; //Auto-handler: Create Directory if (isset($_POST['fm']['create-dir']) && !empty($_POST['fm']['create-dir'])) { $create = $this->createDirectory($_POST['fm']['create-dir']); } // Auto-handler: image details & cropping if (isset($_POST['file_id']) && is_numeric($_POST['file_id'])) { if (($file = $GLOBALS['db']->select('CubeCart_filemanager', false, array('file_id' => (int) $_POST['file_id']))) !== false) { if (isset($_POST['details'])) { if (!$this->filename_is_illegal($_POST['details']['filename'])) { // Update details $new_location = $current_location = $this->_manage_root . '/' . urldecode($this->_sub_dir); $new_filename = $current_filename = $file[0]['filename']; $new_subdir = $this->_sub_dir; if ($file[0]['filename'] != $_POST['details']['filename']) { $new_filename = $this->formatName($_POST['details']['filename']); } if (isset($_POST['details']['move']) && !empty($_POST['details']['move'])) { $move_to = $this->_manage_root . '/' . $this->formatPath($_POST['details']['move']); if (is_dir($move_to)) { $new_location = $move_to; $new_subdir = $this->formatPath(str_replace($this->_manage_root, '', $new_location), false); } } // Does it need moving? if ($new_location != $current_location || $new_filename != $current_filename) { if (file_exists($current_location . $current_filename) && rename($current_location . $current_filename, $new_location . $new_filename)) { $this->_sub_dir = $new_subdir; $current_location = $new_location; $current_filename = $new_filename; // Database record $record['filename'] = $new_filename; $record['filepath'] = $this->formatPath($this->_sub_dir); $record['filepath'] = $this->_sub_dir == null ? 'NULL' : $this->formatPath($this->_sub_dir); } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_moved']); } } $record['description'] = strip_tags($_POST['details']['description']); $update = false; foreach ($record as $k => $v) { if (!isset($file[0][$k]) || $file[0][$k] != $v) { $update = true; } } if ($update) { if (!$GLOBALS['db']->update('CubeCart_filemanager', $record, array('file_id' => (int) $_POST['file_id']))) { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_update']); } } } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_update']); } } if (isset($_POST['resize']) && !empty($_POST['resize']['w']) && !empty($_POST['resize']['h'])) { $resize = $_POST['resize']; if (file_exists($this->_manage_root . '/' . $this->_sub_dir . $current_filename)) { // Use Hi-res image $source = $this->_manage_root . '/' . $this->_sub_dir . $current_filename; $size = getimagesize($source); $gd = new GD(dirname($source), false, 100); $gd->gdLoadFile($source); # TO DO: ROTATION $gd->gdCrop((int) $resize['x'], (int) $resize['y'], (int) $resize['w'], (int) $resize['h']); if ($gd->gdSave(basename($source))) { // Delete previously generated images preg_match('#(\\w+)(\\.\\w+)$#', $current_filename, $match); if (($files = glob($current_location . $match[1] . '*', GLOB_NOSORT)) !== false) { foreach ($files as $file) { if ($file != $source) { unlink($file); } } } $GLOBALS['gui']->setNotify($GLOBALS['language']->filemanager['notify_image_update']); } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_image_update']); } } } httpredir(currentPage(null, array('subdir' => $this->formatPath($this->_sub_dir, false)))); } } // Create a directory list $this->findDirectories($this->_manage_root); }