/** * 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 ''; } }
} if (empty($contents)) { $GLOBALS['main']->setACPWarning($lang['maintain']['files_upgrade_download_fail']); httpredir('?_g=maintenance&node=index#upgrade'); } else { if (stristr($contents, 'DOCTYPE')) { $GLOBALS['main']->setACPWarning("Sorry. CubeCart-" . $_GET['upgrade'] . ".zip was not found. Please try again later."); httpredir('?_g=maintenance&node=index#upgrade'); } $destination_path = CC_ROOT_DIR . '/backup/CubeCart-' . $_GET['upgrade'] . '.zip'; $fp = fopen($destination_path, 'w'); fwrite($fp, $contents); fclose($fp); if (file_exists($destination_path)) { ## Make the new file read/writable which is probably not needed chmod($destination_path, chmod_writable()); require_once $pclzip_path; $archive = new PclZip($destination_path); ## Get file contents to compare filesize afterwards shame we have no md5 but filesize should be ok if (($package_contents = $archive->listContent()) == 0) { $GLOBALS['main']->setACPWarning("Error: " . $archive->errorInfo(true)); httpredir('?_g=maintenance&node=index#upgrade'); } $extract = $archive->extract(PCLZIP_OPT_PATH, CC_ROOT_DIR, PCLZIP_OPT_REPLACE_NEWER); if ($extract == 0) { $GLOBALS['main']->setACPWarning("Error: " . $archive->errorInfo(true)); httpredir('?_g=maintenance&node=index#upgrade'); } $error_log = '----- Upgrade log to ' . $_GET['upgrade'] . " (" . date("d M Y - H:i:s") . ") -----\r\n\r\n"; ## Check the file have been updated $fail_status = array('newer_exist', 'write_protected', 'path_creation_fail', 'write_error', 'read_error', 'invalid_header', 'filename_too_long');
// Stage 3: Permissions Check if (!file_exists($global_file)) { touch($global_file); } $targets = array('backup/', 'cache/', 'cache/skin/', 'files/', 'images/', 'images/cache/', 'images/logos/', 'images/source/', 'includes/', 'includes/extra/', 'includes/global.inc.php', 'language/'); if (file_exists(CC_ROOT_DIR . '/images/uploads')) { $targets[] = 'images/uploads/'; } sort($targets); $permissions = true; foreach ($targets as $target) { $target = str_replace('/', '/', $target); $perm_status = true; if (!is_writable(CC_ROOT_DIR . '/' . $target)) { // Attempt to chmod if (!chmod(CC_ROOT_DIR . '/' . $target, chmod_writable())) { $perm_status = false; $permissions = false; $errors[] = sprintf($strings['setup']['error_x_not_writable'], $target); } } $GLOBALS['smarty']->append('PERMISSIONS', array('name' => $target, 'status' => (bool) $perm_status)); } if (!$permissions) { $proceed = false; $retry = true; } else { $GLOBALS['smarty']->assign('PERMS_PASS', true); } $GLOBALS['smarty']->assign('MODE_PERMS', true); } else {
* ======================================== * CubeCart is a registered trade mark of CubeCart Limited * Copyright CubeCart Limited 2015. All rights reserved. * UK Private Limited Company No. 5323904 * ======================================== * Web: http://www.cubecart.com * Email: sales@cubecart.com * License: GPL-3.0 https://www.gnu.org/licenses/quick-guide-gplv3.html */ require_once preg_replace('/setup/', '', realpath(dirname(__FILE__))) . 'ini.inc.php'; require_once CC_INCLUDES_DIR . 'functions.inc.php'; @ini_set('memory_limit', '512M'); @set_time_limit('600'); define('SKIP_DB_SETUP', true); /*! Check cache folder is writable! */ @chmod(CC_CACHE_DIR, chmod_writable()); if (!is_writable(CC_CACHE_DIR)) { $cache_dir = str_replace(CC_ROOT_DIR, '', CC_CACHE_DIR); die('<p>Please make sure the following folders are writable in order to continue.</p><pre>' . $cache_dir . '</pre>'); } $gitignore = CC_ROOT_DIR . '/images/source/.gitignore'; if (file_exists($gitignore)) { @unlink($gitignore); if (file_exists($gitignore)) { die('Please delete the images/source/.gitignore file before proceeding.'); } } $global_file = CC_INCLUDES_DIR . 'global.inc.php'; $setup_path = CC_ROOT_DIR . '/setup' . '/'; session_start(); if (isset($_GET['autoupdate']) && $_GET['autoupdate']) {
unset($product_files, $category_files, $filemanager_files); ## Update FileManager table first $fm = new FileManager(); $fm->buildDatabase(); $config_string = $db->select('CubeCart_config', array('array'), array('name' => 'config')); $v4config = json_decode(base64_decode($config_string[0]['array']), true); foreach (glob('../images/logos/*') as $file) { if (!preg_match('/[.][a-z]{3}/', $file, $match)) { $mime = $fm->getMimeType($file); $size = getimagesize($file); if (preg_match('/(png|jpg|jpeg|gif)/', $mime, $match)) { $match[0] = $match[0] == 'jpeg' ? 'jpg' : $match[0]; $new_name = $file . '.' . $match[0]; chmod($file, chmod_writable()); rename($file, $new_name); chmod($new_name, chmod_writable()); } $file_name = preg_replace('/..\\/images\\/logos\\//', '', $file); $new_file_name = preg_replace('/..\\/images\\/logos\\//', '', $new_name); if ($file_name == $v4config['skinDir']) { $db->insert('CubeCart_logo', array('status' => 1, 'filename' => $new_file_name, 'mimetype' => $mime, 'width' => $size[0], 'height' => $size[1])); } } } build_logos($new_file_name); ## Remap category images if ($indexes = $db->select('CubeCart_category', array('cat_id', 'cat_image'))) { foreach ($indexes as $index) { if (empty($index['cat_image'])) { continue; }
/** * Upload file * * @param string $type * @param bool $thumbnail * * @return int/false */ public function upload($type = false, $thumbnail = false) { if (!is_writable($this->_manage_root)) { return false; } if (!empty($_FILES)) { $finfo = extension_loaded('fileinfo') ? new finfo(FILEINFO_SYMLINK | FILEINFO_MIME) : false; foreach ($_FILES as $file) { if ($this->filename_is_illegal($file['name'])) { continue; } if (is_array($file['tmp_name'])) { foreach ($file['tmp_name'] as $offset => $tmp_name) { $gd = new GD($this->_manage_root . '/' . $this->_sub_dir); if (!empty($tmp_name) && is_uploaded_file($tmp_name)) { if ($this->_mode == self::FM_FILETYPE_IMG && $file['size'][$offset] > $this->_max_upload_image_size) { $GLOBALS['gui']->setError(sprintf($GLOBALS['lang']['filemanager']['error_file_upload_size'], $file['name'][$offset], formatBytes($this->_max_upload_image_size, true, 0))); continue; } if ($file['error'][$offset] !== UPLOAD_ERR_OK) { $this->uploadError($file['error'][$offset]); continue; } $target = $target_old = $this->_manage_root . '/' . $this->_sub_dir . $file['name'][$offset]; $newfilename = $this->makeFilename($file['name'][$offset]); $oldfilename = $file['name'][$offset]; if ($newfilename !== $oldfilename) { $target = str_replace($oldfilename, $newfilename, $target); } $filepath_record = $this->formatPath(str_replace($this->_manage_root, '', dirname($target))); $filepath_record = empty($filepath_record) ? 'NULL' : $filepath_record; $filepath_record = str_replace(chr(92), "/", $filepath_record); $record = array('type' => (int) $this->_mode, 'filepath' => $filepath_record, 'filename' => $newfilename, 'filesize' => $file['size'][$offset], 'mimetype' => $file['type'][$offset] ? $file['type'][$offset] : $this->getMimeType($tmp_name), 'md5hash' => md5_file($tmp_name)); if ($GLOBALS['db']->insert('CubeCart_filemanager', $record)) { $file_id[] = $GLOBALS['db']->insertid(); move_uploaded_file($tmp_name, $target); chmod($target, chmod_writable()); } } } } else { $gd = new GD($this->_manage_root . '/' . $this->_sub_dir); if (!empty($file['tmp_name']) && is_uploaded_file($file['tmp_name'])) { if ($this->_mode == self::FM_FILETYPE_IMG && $file['size'] > $this->_max_upload_image_size) { $GLOBALS['gui']->setError(sprintf($GLOBALS['lang']['filemanager']['error_file_upload_size'], $file['name'], formatBytes($this->_max_upload_image_size, true, 0))); return false; } if ($file['error'] !== UPLOAD_ERR_OK) { $this->uploadError($file['error']); continue; } $target = $target_old = $this->_manage_root . '/' . $this->_sub_dir . $file['name']; $newfilename = $this->makeFilename($file['name']); $oldfilename = $file['name']; if ($newfilename !== $oldfilename) { $target = str_replace($oldfilename, $newfilename, $target); } $filepath_record = $this->formatPath(str_replace($this->_manage_root, '', dirname($target))); $filepath_record = empty($filepath_record) ? 'NULL' : $filepath_record; $filepath_record = str_replace(chr(92), "/", $filepath_record); $record = array('type' => (int) $this->_mode, 'filepath' => $filepath_record, 'filename' => $newfilename, 'filesize' => $file['size'], 'mimetype' => $file['type'] ? $file['type'] : $this->getMimeType($file['tmp_name']), 'md5hash' => md5_file($file['tmp_name'])); if ($GLOBALS['db']->insert('CubeCart_filemanager', $record)) { $file_id[] = $GLOBALS['db']->insertid(); move_uploaded_file($file['tmp_name'], $target); chmod($target, chmod_writable()); } } } } return isset($file_id) ? $file_id : true; } return false; }