public function postProcess() { if (Tools::isSubmit('submitLocalizationPack')) { $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); if (Validate::isFileName(Tools::getValue('iso_localization_pack'))) { $pack = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . Tools::getValue('iso_localization_pack') . '.xml'); if (!$pack && !($pack = @Tools::file_get_contents(dirname(__FILE__) . '/../../localization/' . Tools::getValue('iso_localization_pack') . '.xml'))) { $this->errors[] = Tools::displayError('Cannot load localization pack (from prestashop.com and from your local folder "localization")'); } if (!($selection = Tools::getValue('selection'))) { $this->errors[] = Tools::displayError('Please select at least one item to import.'); } else { foreach ($selection as $selected) { if (!Validate::isLocalizationPackSelection($selected)) { $this->errors[] = Tools::displayError('Invalid selection'); return; } } $localization_pack = new LocalizationPack(); if (!$localization_pack->loadLocalisationPack($pack, $selection)) { $this->errors = array_merge($this->errors, $localization_pack->getErrors()); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token); } } } } parent::postProcess(); }
public function postProcess() { if (Tools::isSubmit('submitLocalizationPack')) { $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); if (Validate::isFileName(Tools::getValue('iso_localization_pack'))) { $pack = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . Tools::getValue('iso_localization_pack') . '.xml'); if (!$pack && !($pack = @Tools::file_get_contents(dirname(__FILE__) . '/../../localization/' . Tools::getValue('iso_localization_pack') . '.xml'))) { $this->errors[] = Tools::displayError('Cannot load the localization pack.'); } if (!($selection = Tools::getValue('selection'))) { $this->errors[] = Tools::displayError('Please select at least one item to import.'); } else { foreach ($selection as $selected) { if (!Validate::isLocalizationPackSelection($selected)) { $this->errors[] = Tools::displayError('Invalid selection'); return; } } $localization_pack = new LocalizationPack(); if (!$localization_pack->loadLocalisationPack($pack, $selection)) { $this->errors = array_merge($this->errors, $localization_pack->getErrors()); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token); } } } } // Remove the module list cache if the default country changed if (Tools::isSubmit('submitOptionsconfiguration') && file_exists(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST)) { @unlink(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST); } parent::postProcess(); }
public function postProcess() { if (_PS_MODE_DEMO_) { $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error'); return; } if (!extension_loaded('openssl')) { $this->displayWarning($this->l('Importing a new language may fail without the OpenSSL module. Please enable "openssl.so" on your server configuration.')); } if (Tools::isSubmit('submitLocalizationPack')) { $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); if (($iso_localization_pack = Tools::getValue('iso_localization_pack')) && Validate::isFileName($iso_localization_pack)) { if (Tools::getValue('download_updated_pack') == '1' || defined('_PS_HOST_MODE_')) { $pack = @Tools::file_get_contents(_PS_API_URL_ . '/localization/' . $version . '/' . $iso_localization_pack . '.xml'); } else { $pack = false; } if (defined('_PS_HOST_MODE_')) { $path = _PS_CORE_DIR_ . '/localization/' . $iso_localization_pack . '.xml'; } else { $path = _PS_ROOT_DIR_ . '/localization/' . $iso_localization_pack . '.xml'; } if (!$pack && !($pack = @Tools::file_get_contents($path))) { $this->errors[] = $this->trans('Cannot load the localization pack.', array(), 'Admin.International.Notification'); } if (!($selection = Tools::getValue('selection'))) { $this->errors[] = $this->trans('Please select at least one item to import.', array(), 'Admin.International.Notification'); } else { foreach ($selection as $selected) { if (!Validate::isLocalizationPackSelection($selected)) { $this->errors[] = $this->trans('Invalid selection', array(), 'Admin.Notifications.Error'); return; } } $localization_pack = new LocalizationPack(); if (!$localization_pack->loadLocalisationPack($pack, $selection, false, $iso_localization_pack)) { $this->errors = array_merge($this->errors, $localization_pack->getErrors()); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token); } } } } // Remove the module list cache if the default country changed if (Tools::isSubmit('submitOptionsconfiguration') && file_exists(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST)) { @unlink(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST); } parent::postProcess(); }
public function postProcess() { // Getting key value for display if (Tools::getValue('show_modules') && strval(Tools::getValue('show_modules')) != 'all') { $this->display_key = (int) Tools::getValue('show_modules'); } // Change position in hook if (array_key_exists('changePosition', $_GET)) { if ($this->tabAccess['edit'] === '1') { $id_module = (int) Tools::getValue('id_module'); $id_hook = (int) Tools::getValue('id_hook'); $module = Module::getInstanceById($id_module); if (Validate::isLoadedObject($module)) { $module->updatePosition($id_hook, (int) Tools::getValue('direction')); Tools::redirectAdmin(self::$currentIndex . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } else { $this->errors[] = Tools::displayError('This module cannot be loaded'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitAddToHook')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); if (!$id_module || !Validate::isLoadedObject($module)) { $this->errors[] = Tools::displayError('This module cannot be loaded'); } elseif (!$id_hook || !Validate::isLoadedObject($hook)) { $this->errors[] = Tools::displayError('Hook cannot be loaded.'); } elseif (Hook::getModulesFromHook($id_hook, $id_module)) { $this->errors[] = Tools::displayError('This module has already been transplanted to this hook'); } elseif (!$module->isHookableOn($hook->name)) { $this->errors[] = Tools::displayError('This module cannot be transplanted to this hook.'); } else { if (!$module->registerHook($hook->name, Shop::getContextListShopID())) { $this->errors[] = Tools::displayError('An error occurred while transplanting the module to its hook.'); } else { $exceptions = Tools::getValue('exceptions'); $exceptions = isset($exceptions[0]) ? $exceptions[0] : array(); $exceptions = explode(',', str_replace(' ', '', $exceptions)); foreach ($exceptions as $key => $except) { if (empty($except)) { unset($exceptions[$key]); } else { if (!Validate::isFileName($except)) { $this->errors[] = Tools::displayError('No valid value for field exceptions has been defined.'); } } } if (!$this->errors && !$module->registerExceptions($id_hook, $exceptions, Shop::getContextListShopID())) { $this->errors[] = Tools::displayError('An error occurred while transplanting the module to its hook.'); } } if (!$this->errors) { Tools::redirectAdmin(self::$currentIndex . '&conf=16' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (Tools::isSubmit('submitEditGraft')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); if (!$id_module || !Validate::isLoadedObject($module)) { $this->errors[] = Tools::displayError('This module cannot be loaded'); } elseif (!$id_hook || !Validate::isLoadedObject($hook)) { $this->errors[] = Tools::displayError('Hook cannot be loaded.'); } else { $exceptions = Tools::getValue('exceptions'); if (is_array($exceptions)) { foreach ($exceptions as $id => $exception) { $exception = explode(',', str_replace(' ', '', $exception)); // Check files name foreach ($exception as $except) { if (!Validate::isFileName($except)) { $this->errors[] = Tools::displayError('No valid value for field exceptions has been defined.'); } } $exceptions[$id] = $exception; } // Add files exceptions if (!$module->editExceptions($id_hook, $exceptions)) { $this->errors[] = Tools::displayError('An error occurred while transplanting the module to its hook.'); } if (!$this->errors) { Tools::redirectAdmin(self::$currentIndex . '&conf=16' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } } else { $exceptions = explode(',', str_replace(' ', '', $exceptions)); // Check files name foreach ($exceptions as $except) { if (!Validate::isFileName($except)) { $this->errors[] = Tools::displayError('No valid value for field exceptions has been defined.'); } } // Add files exceptions if (!$module->editExceptions($id_hook, $exceptions, Shop::getContextListShopID())) { $this->errors[] = Tools::displayError('An error occurred while transplanting the module to its hook.'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=16' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } } } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (array_key_exists('deleteGraft', $_GET)) { if ($this->tabAccess['delete'] === '1') { $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); if (!Validate::isLoadedObject($module)) { $this->errors[] = Tools::displayError('This module cannot be loaded'); } elseif (!$id_hook || !Validate::isLoadedObject($hook)) { $this->errors[] = Tools::displayError('Hook cannot be loaded.'); } else { if (!$module->unregisterHook($id_hook, Shop::getContextListShopID()) || !$module->unregisterExceptions($id_hook, Shop::getContextListShopID())) { $this->errors[] = Tools::displayError('An error occurred while deleting the module from its hook.'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=17' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } } elseif (Tools::isSubmit('unhookform')) { if (!($unhooks = Tools::getValue('unhooks')) || !is_array($unhooks)) { $this->errors[] = Tools::displayError('Please select a module to unhook.'); } else { foreach ($unhooks as $unhook) { $explode = explode('_', $unhook); $id_hook = $explode[0]; $id_module = $explode[1]; $module = Module::getInstanceById((int) $id_module); $hook = new Hook((int) $id_hook); if (!Validate::isLoadedObject($module)) { $this->errors[] = Tools::displayError('This module cannot be loaded'); } elseif (!$id_hook || !Validate::isLoadedObject($hook)) { $this->errors[] = Tools::displayError('Hook cannot be loaded.'); } else { if (!$module->unregisterHook((int) $id_hook) || !$module->unregisterExceptions((int) $id_hook)) { $this->errors[] = Tools::displayError('An error occurred while deleting the module from its hook.'); } } } if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex . '&conf=17' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token); } } } else { parent::postProcess(); } }
public function init() { if (isset($this->context->employee) && $this->context->employee->isLoggedBack() && Tools::getValue('file')) { // Admin can directly access to file $filename = Tools::getValue('file'); if (!Validate::isSha1($filename)) { die(Tools::displayError()); } $file = _PS_DOWNLOAD_DIR_ . strval(preg_replace('/\\.{2,}/', '.', $filename)); $filename = ProductDownload::getFilenameFromFilename(Tools::getValue('file')); if (empty($filename)) { $newFileName = Tools::getValue('filename'); if (!empty($newFileName)) { $filename = Tools::getValue('filename'); } else { $filename = 'file'; } } if (!file_exists($file)) { Tools::redirect('index.php'); } } else { if (!($key = Tools::getValue('key'))) { $this->displayCustomError('Invalid key.'); } Tools::setCookieLanguage(); if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key') && !Tools::getValue('id_order')) { Tools::redirect('index.php?controller=authentication&back=get-file.php&key=' . $key); } else { if (!$this->context->customer->isLogged() && Tools::getValue('secure_key') && Tools::getValue('id_order')) { $order = new Order((int) Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->displayCustomError('Invalid key.'); } if ($order->secure_key != Tools::getValue('secure_key')) { $this->displayCustomError('Invalid key.'); } } } /* Key format: <sha1-filename>-<hashOrder> */ $tmp = explode('-', $key); if (count($tmp) != 2) { $this->displayCustomError('Invalid key.'); } $filename = $tmp[0]; $hash = $tmp[1]; if (!($info = OrderDetail::getDownloadFromHash($hash))) { $this->displayCustomError('This product does not exist in our store.'); } /* Product no more present in catalog */ if (!isset($info['id_product_download']) || empty($info['id_product_download'])) { $this->displayCustomError('This product has been deleted.'); } if (!Validate::isFileName($info['filename']) || !file_exists(_PS_DOWNLOAD_DIR_ . $info['filename'])) { $this->displayCustomError('This file no longer exists.'); } if (isset($info['product_quantity_refunded']) && isset($info['product_quantity_return']) && ($info['product_quantity_refunded'] > 0 || $info['product_quantity_return'] > 0)) { $this->displayCustomError('This product has been refunded.'); } $now = time(); $product_deadline = strtotime($info['download_deadline']); if ($now > $product_deadline && $info['download_deadline'] != '0000-00-00 00:00:00') { $this->displayCustomError('The product deadline is in the past.'); } $customer_deadline = strtotime($info['date_expiration']); if ($now > $customer_deadline && $info['date_expiration'] != '0000-00-00 00:00:00') { $this->displayCustomError('Expiration date has passed, you cannot download this product'); } if ($info['download_nb'] >= $info['nb_downloadable'] && $info['nb_downloadable']) { $this->displayCustomError('You have reached the maximum number of allowed downloads.'); } /* Access is authorized -> increment download value for the customer */ OrderDetail::incrementDownload($info['id_order_detail']); $file = _PS_DOWNLOAD_DIR_ . $info['filename']; $filename = $info['display_filename']; } /* Detect mime content type */ $mimeType = false; if (function_exists('finfo_open')) { $finfo = @finfo_open(FILEINFO_MIME); $mimeType = @finfo_file($finfo, $file); @finfo_close($finfo); } else { if (function_exists('mime_content_type')) { $mimeType = @mime_content_type($file); } else { if (function_exists('exec')) { $mimeType = trim(@exec('file -b --mime-type ' . escapeshellarg($file))); if (!$mimeType) { $mimeType = trim(@exec('file --mime ' . escapeshellarg($file))); } if (!$mimeType) { $mimeType = trim(@exec('file -bi ' . escapeshellarg($file))); } } } } if (empty($mimeType)) { $bName = basename($filename); $bName = explode('.', $bName); $bName = strtolower($bName[count($bName) - 1]); $mimeTypes = array('ez' => 'application/andrew-inset', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'hdf' => 'application/x-hdf', 'js' => 'application/x-javascript', 'skp' => 'application/x-koan', 'skd' => 'application/x-koan', 'skt' => 'application/x-koan', 'skm' => 'application/x-koan', 'latex' => 'application/x-latex', 'nc' => 'application/x-netcdf', 'cdf' => 'application/x-netcdf', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texinfo' => 'application/x-texinfo', 'texi' => 'application/x-texinfo', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'roff' => 'application/x-troff', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 'au' => 'audio/basic', 'snd' => 'audio/basic', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'kar' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tif', 'djvu' => 'image/vnd.djvu', 'djv' => 'image/vnd.djvu', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-windowdump', 'igs' => 'model/iges', 'iges' => 'model/iges', 'msh' => 'model/mesh', 'mesh' => 'model/mesh', 'silo' => 'model/mesh', 'wrl' => 'model/vrml', 'vrml' => 'model/vrml', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'asc' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgml' => 'text/sgml', 'sgm' => 'text/sgml', 'tsv' => 'text/tab-seperated-values', 'wml' => 'text/vnd.wap.wml', 'wmls' => 'text/vnd.wap.wmlscript', 'etx' => 'text/x-setext', 'xml' => 'text/xml', 'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference-xcooltalk'); if (isset($mimeTypes[$bName])) { $mimeType = $mimeTypes[$bName]; } else { $mimeType = 'application/octet-stream'; } } if (ob_get_level() && ob_get_length() > 0) { ob_end_clean(); } /* Set headers for download */ header('Content-Transfer-Encoding: binary'); header('Content-Type: ' . $mimeType); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="' . $filename . '"'); //prevents max execution timeout, when reading large files @set_time_limit(0); $fp = fopen($file, 'rb'); while (!feof($fp)) { echo fgets($fp, 16384); } exit; }
public static function isAllowedExt($file, $allowedExts) { if (!Validate::isFileName($file) or !is_array($allowedExts)) { return false; } $extension = pathinfo($file, PATHINFO_EXTENSION); return $extension; if (in_array($extension, $allowedExts)) { return true; } return false; }
public function processUploadFile($dest) { switch ($_FILES['themearchive']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $this->errors[] = $this->trans('The uploaded file is too large.', array(), 'Admin.Design.Notification'); return false; default: $this->errors[] = $this->trans('Unknown error.', array(), 'Admin.Notifications.Error'); return false; } $finfo = new finfo(FILEINFO_MIME_TYPE); $ext = array_search($finfo->file($_FILES['themearchive']['tmp_name']), array('zip' => 'application/zip'), true); if ($ext === false) { $this->errors[] = $this->trans('Invalid file format.', array(), 'Admin.Design.Notification'); return false; } $name = $_FILES['themearchive']['name']; if (!Validate::isFileName($name)) { $name = sha1_file($name) . $ext; } if (!move_uploaded_file($_FILES['themearchive']['tmp_name'], _PS_ALL_THEMES_DIR_ . $name)) { $this->errors[] = $this->trans('Failed to move uploaded file.', array(), 'Admin.Design.Notification'); return false; } return true; }
protected function openUploadedFile() { $filename = $_GET['filename']; $extensions = array('.txt' => 'text/plain', '.rtf' => 'application/rtf', '.doc' => 'application/msword', '.docx' => 'application/msword', '.pdf' => 'application/pdf', '.zip' => 'multipart/x-zip', '.png' => 'image/png', '.jpeg' => 'image/jpeg', '.gif' => 'image/gif', '.jpg' => 'image/jpeg'); $extension = false; foreach ($extensions as $key => $val) { if (substr(Tools::strtolower($filename), -4) == $key || substr(Tools::strtolower($filename), -5) == $key) { $extension = $val; break; } } if (!$extension || !Validate::isFileName($filename)) { die(Tools::displayError()); } if (ob_get_level() && ob_get_length() > 0) { ob_end_clean(); } header('Content-Type: ' . $extension); header('Content-Disposition:attachment;filename="' . $filename . '"'); readfile(_PS_UPLOAD_DIR_ . $filename); die; }
public function postProcess() { global $currentIndex; if (Tools::isSubmit('submitCaching')) { if ($this->tabAccess['edit'] === '1') { $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php'); if (!Tools::getValue('active')) { $cache_active = 0; } else { $cache_active = 1; } if (!($caching_system = Tools::getValue('caching_system'))) { $this->_errors[] = Tools::displayError('Caching system is missing'); } else { $settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]+)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $settings); } if ($cache_active and $caching_system == 'MCached' and !extension_loaded('memcache')) { $this->_errors[] = Tools::displayError('To use Memcached, you must to install the Memcache PECL extension on your server.') . ' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>'; } elseif ($cache_active and $caching_system == 'CacheFS' and !is_writable(_PS_CACHEFS_DIRECTORY_)) { $this->_errors[] = Tools::displayError('To use CacheFS the directory') . ' ' . realpath(_PS_CACHEFS_DIRECTORY_) . ' ' . Tools::displayError('must be writable'); } if ($caching_system == 'CacheFS') { if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) { $this->_errors[] = Tools::displayError('Please set a directory depth'); } if (!sizeof($this->_errors)) { CacheFS::deleteCacheDirectory(); CacheFS::createCacheDirectories((int) $depth); Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth); } } if (!sizeof($this->_errors)) { $settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([0-9])\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $settings); if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) { Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->_errors[] = Tools::displayError('Cannot overwrite settings file.'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitAddServer')) { if ($this->tabAccess['add'] === '1') { if (!Tools::getValue('memcachedIp')) { $this->_errors[] = Tools::displayError('Memcached IP is missing'); } if (!Tools::getValue('memcachedPort')) { $this->_errors[] = Tools::displayError('Memcached port is missing'); } if (!Tools::getValue('memcachedWeight')) { $this->_errors[] = Tools::displayError('Memcached weight is missing'); } if (!sizeof($this->_errors)) { if (MCached::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) { Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->_errors[] = Tools::displayError('Cannot add Memcached server'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } if (Tools::getValue('deleteMemcachedServer')) { if ($this->tabAccess['add'] === '1') { if (MCached::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) { Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->_errors[] = Tools::displayError('Error in deleting Memcached server'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } if (Tools::isSubmit('submitCiphering') and Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) { if ($this->tabAccess['edit'] === '1') { $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM'); $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php'); if ($algo) { if (!function_exists('mcrypt_encrypt')) { $this->_errors[] = Tools::displayError('Mcrypt is not activated on this server.'); } else { if (!strstr($settings, '_RIJNDAEL_KEY_')) { $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $key = Tools::passwdGen($key_size); $settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $settings); } if (!strstr($settings, '_RIJNDAEL_IV_')) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND)); $settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $settings); } } } if (!count($this->_errors)) { if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) { Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo); Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->_errors[] = Tools::displayError('Cannot overwrite settings file.'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitCCC')) { if ($this->tabAccess['edit'] === '1') { if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) or !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) or !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) or !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) or !Configuration::updateValue('PS_HIGH_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HIGH_HTML_THEME_COMPRESSION'))) { $this->_errors[] = Tools::displayError('Unknown error.'); } else { Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitMediaServers')) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('_MEDIA_SERVER_1_') != NULL and !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) { $this->_errors[] = Tools::displayError('Media server #1 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_2_') != NULL and !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) { $this->_errors[] = Tools::displayError('Media server #2 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_3_') != NULL and !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) { $this->_errors[] = Tools::displayError('Media server #3 is invalid'); } if (!sizeof($this->_errors)) { $baseUrls = array(); $baseUrls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_'); $baseUrls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_'); $baseUrls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_'); rewriteSettingsFile($baseUrls, NULL, NULL); unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']); Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitSmartyConfig')) { if ($this->tabAccess['edit'] === '1') { Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', 0)); Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Tools::redirectAdmin($currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } return parent::postProcess(); }
public function postProcess() { global $currentIndex; // Getting key value for display if (Tools::getValue('show_modules') and strval(Tools::getValue('show_modules')) != 'all') { $this->displayKey = (int) Tools::getValue('show_modules'); } // Change position in hook if (array_key_exists('changePosition', $_GET)) { if ($this->tabAccess['edit'] === '1') { $id_module = (int) Tools::getValue('id_module'); $id_hook = (int) Tools::getValue('id_hook'); $module = Module::getInstanceById($id_module); if (Validate::isLoadedObject($module)) { $module->updatePosition($id_hook, (int) Tools::getValue('direction')); Tools::redirectAdmin($currentIndex . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } else { $this->_errors[] = Tools::displayError('module cannot be loaded'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (Tools::isSubmit('submitAddToHook')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts as $except) { if (!Validate::isFileName($except)) { $this->_errors[] = Tools::displayError('No valid value for field exceptions'); } } if (!$id_module or !Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('Hook cannot be loaded.'); } elseif (Hook::getModuleFromHook($id_hook, $id_module)) { $this->_errors[] = Tools::displayError('This module is already transplanted to this hook.'); } elseif (!$module->isHookableOn($hook->name)) { $this->_errors[] = Tools::displayError('This module cannot be transplanted to this hook.'); } elseif (!$module->registerHook($hook->name)) { $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); } elseif (!$module->registerExceptions($id_hook, $excepts)) { $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); } else { Tools::redirectAdmin($currentIndex . '&conf=16' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('submitEditGraft')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts as $except) { if (!Validate::isFileName($except)) { $this->_errors[] = Tools::displayError('No valid value for field exceptions'); } } if (!$id_module or !Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('Hook cannot be loaded.'); } // Adding vars... if (!$module->editExceptions($id_hook, $excepts)) { $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); } else { Tools::redirectAdmin($currentIndex . '&conf=16' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (array_key_exists('deleteGraft', $_GET)) { if ($this->tabAccess['delete'] === '1') { $id_module = (int) Tools::getValue('id_module'); $module = Module::getInstanceById($id_module); $id_hook = (int) Tools::getValue('id_hook'); $hook = new Hook($id_hook); if (!Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('Hook cannot be loaded.'); } else { $position = Db::getInstance()->getValue('SELECT `position` FROM `' . _DB_PREFIX_ . 'hook_module` hm WHERE hm.`id_hook` = ' . $id_hook . ' AND hm.`id_module` = ' . $id_module); if (!$module->unregisterHook($id_hook) or !$module->unregisterExceptions($id_hook)) { $this->_errors[] = Tools::displayError('An error occurred while deleting module from hook.'); } else { $this->placeCorrectlyOtherModules($id_hook, $position); Tools::redirectAdmin($currentIndex . '&conf=17' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('unhookform')) { if (!($unhooks = Tools::getValue('unhooks')) or !is_array($unhooks)) { $this->_errors[] = Tools::displayError('Select a module to unhook.'); } else { foreach ($unhooks as $unhook) { $explode = explode('_', $unhook); $id_hook = $explode[0]; $id_module = $explode[1]; $module = Module::getInstanceById((int) $id_module); $hook = new Hook((int) $id_hook); if (!Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('Hook cannot be loaded.'); } else { $position = Db::getInstance()->getValue('SELECT `position` FROM `' . _DB_PREFIX_ . 'hook_module` hm WHERE hm.`id_hook` = ' . (int) $id_hook . ' AND hm.`id_module` = ' . (int) $id_module); if (!$module->unregisterHook((int) $id_hook) or !$module->unregisterExceptions((int) $id_hook)) { $this->_errors[] = Tools::displayError('An error occurred while deleting module from hook.'); } else { $this->placeCorrectlyOtherModules((int) $id_hook, (int) $position); } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&conf=17' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } } }
$ctype = "image/jpg"; break; default: $ctype = "application/force-download"; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: {$ctype}"); header("Content-Disposition: attachment; filename=\"" . $filename . "_" . time() . ".mtpl\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($path)); readfile("{$path}"); exit; } $key = Tools::getValue('key', false); $file = Tools::getValue('template', false); if (!$key) { die('Invalid token.'); } elseif (!Validate::isMd5($key) || !$key == md5(_COOKIE_KEY_)) { die('Hack attempt.'); } elseif (!$file) { die('Please specify file'); } elseif (!Validate::isFileName($file)) { die('This isn\'t a valid file'); } elseif (!file_exists(dirname(__FILE__) . '/templates/' . $file . '.mtpl')) { die('File does not exist.'); } else { ForceDownload($file); }
public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error'); return; } Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this)); if (Tools::isSubmit('submitAddServer')) { if ($this->access('add')) { if (!Tools::getValue('memcachedIp')) { $this->errors[] = $this->trans('The Memcached IP is missing.', array(), 'Admin.Parameters.Notification'); } if (!Tools::getValue('memcachedPort')) { $this->errors[] = $this->trans('The Memcached port is missing.', array(), 'Admin.Parameters.Notification'); } if (!Tools::getValue('memcachedWeight')) { $this->errors[] = $this->trans('The Memcached weight is missing.', array(), 'Admin.Parameters.Notification'); } if (!count($this->errors)) { if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = $this->trans('The Memcached server cannot be added.', array(), 'Admin.Parameters.Notification'); } } } else { $this->errors[] = $this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error'); } } if (Tools::getValue('deleteMemcachedServer')) { if ($this->access('add')) { if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = $this->trans('There was an error when attempting to delete the Memcached server.', array(), 'Admin.Parameters.Notification'); } } else { $this->errors[] = $this->trans('You do not have permission to delete this.', array(), 'Admin.Notifications.Error'); } } $redirectAdmin = false; if ((bool) Tools::getValue('smarty_up')) { if ($this->access('edit')) { Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_)); if (Configuration::get('PS_SMARTY_CACHE') != Tools::getValue('smarty_cache')) { Tools::clearSmartyCache(); } Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Configuration::updateValue('PS_SMARTY_CLEAR_CACHE', Tools::getValue('smarty_clear_cache')); Configuration::updateValue('PS_SMARTY_LOCAL', Tools::getValue('smarty_local', 0)); $redirectAdmin = true; } else { $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error'); } } if ((bool) Tools::getValue('features_detachables_up')) { if ($this->access('edit')) { if (Tools::isSubmit('combination')) { if ((!Tools::getValue('combination') && Combination::isCurrentlyUsed()) === false) { Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', (bool) Tools::getValue('combination')); } } if (Tools::isSubmit('customer_group')) { if ((!Tools::getValue('customer_group') && Group::isCurrentlyUsed()) === false) { Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', (bool) Tools::getValue('customer_group')); } } Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', (bool) Tools::getValue('feature')); $redirectAdmin = true; } else { $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error'); } } if ((bool) Tools::getValue('ccc_up')) { if ($this->access('edit')) { $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/'; @mkdir($theme_cache_directory, 0777, true); if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) { $this->errors[] = $this->trans('To use Smart Cache, the directory %directorypath% must be writable.', array('%directorypath%' => realpath($theme_cache_directory)), 'Admin.Parameters.Notification'); } if ($tmp = (int) Tools::getValue('PS_CSS_THEME_CACHE')) { $version = (int) Configuration::get('PS_CCCCSS_VERSION'); if (Configuration::get('PS_CSS_THEME_CACHE') != $tmp) { Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); } } if ($tmp = (int) Tools::getValue('PS_JS_THEME_CACHE')) { $version = (int) Configuration::get('PS_CCCJS_VERSION'); if (Configuration::get('PS_JS_THEME_CACHE') != $tmp) { Configuration::updateValue('PS_CCCJS_VERSION', ++$version); } } if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_DEFER', (int) Tools::getValue('PS_JS_DEFER')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) { $this->errors[] = $this->trans('Unknown error.', array(), 'Admin.Notifications.Error'); } else { $redirectAdmin = true; if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) { if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) { Tools::generateHtaccess(); } else { $message = $this->l('Before being able to use this tool, you need to:'); $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.'); $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).'); $this->errors[] = Tools::displayError($message, false); Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false); } } } } else { $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error'); } } if ((bool) Tools::getValue('media_server_up') && !defined('_PS_HOST_MODE_')) { if ($this->access('edit')) { if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) { $this->errors[] = $this->trans('Media server #1 is invalid', array(), 'Admin.Parameters.Notification'); } if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) { $this->errors[] = $this->trans('Media server #2 is invalid', array(), 'Admin.Parameters.Notification'); } if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) { $this->errors[] = $this->trans('Media server #3 is invalid', array(), 'Admin.Parameters.Notification'); } if (!count($this->errors)) { $base_urls = array(); $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_'); $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_'); $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_'); if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) { Configuration::updateValue('PS_MEDIA_SERVERS', 1); } else { Configuration::updateValue('PS_MEDIA_SERVERS', 0); } rewriteSettingsFile($base_urls, null, null); Configuration::updateValue('PS_MEDIA_SERVER_1', Tools::getValue('_MEDIA_SERVER_1_')); Configuration::updateValue('PS_MEDIA_SERVER_2', Tools::getValue('_MEDIA_SERVER_2_')); Configuration::updateValue('PS_MEDIA_SERVER_3', Tools::getValue('_MEDIA_SERVER_3_')); Tools::clearSmartyCache(); Media::clearCache(); if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) { Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_'])); unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']); $redirectAdmin = true; } else { $message = $this->l('Before being able to use this tool, you need to:'); $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.'); $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).'); $this->errors[] = Tools::displayError($message, false); Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false); } } } else { $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error'); } } if ((bool) Tools::getValue('cache_up')) { if ($this->access('edit')) { $config = Yaml::parse(_PS_ROOT_DIR_ . '/app/config/parameters.yml'); $cache_active = (bool) Tools::getValue('cache_active'); if ($caching_system = preg_replace('[^a-zA-Z0-9]', '', Tools::getValue('caching_system'))) { $config['parameters']['ps_caching'] = $caching_system; } else { $cache_active = false; $this->errors[] = $this->trans('The caching system is missing.', array(), 'Admin.Parameters.Notification'); } if ($cache_active) { if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) { $this->errors[] = $this->trans('To use Memcached, you must install the Memcache PECL extension on your server.', array(), 'Admin.Parameters.Notification') . ' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>'; } elseif ($caching_system == 'CacheMemcached' && !extension_loaded('memcached')) { $this->errors[] = $this->trans('To use Memcached, you must install the Memcached PECL extension on your server.', array(), 'Admin.Parameters.Notification') . ' <a href="http://www.php.net/manual/en/memcached.installation.php">http://www.php.net/manual/en/memcached.installation.php</a>'; } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc') && !extension_loaded('apcu')) { $this->errors[] = $this->trans('To use APC cache, you must install the APC PECL extension on your server.', array(), 'Admin.Parameters.Notification') . ' <a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>'; } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) { $this->errors[] = $this->trans('To use Xcache, you must install the Xcache extension on your server.', array(), 'Admin.Parameters.Notification') . ' <a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>'; } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) { $this->errors[] = $this->trans('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).', array(), 'Admin.Parameters.Notification') . ' <a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>'; } elseif ($caching_system == 'CacheFs') { if (!is_dir(_PS_CACHEFS_DIRECTORY_)) { @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true); } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) { $this->errors[] = $this->trans('To use CacheFS, the directory %directorypath% must be writable.', array('%directorypath%' => realpath(_PS_CACHEFS_DIRECTORY_)), 'Admin.Parameters.Notification'); } } if ($caching_system == 'CacheFs') { if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) { $this->errors[] = $this->trans('Please set a directory depth.', array(), 'Admin.Parameters.Notification'); } if (!count($this->errors)) { CacheFs::deleteCacheDirectory(); CacheFs::createCacheDirectories((int) $depth); Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth); } } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') { Cache::getInstance()->flush(); } elseif ($caching_system == 'CacheMemcached' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcached') { Cache::getInstance()->flush(); } } if (!count($this->errors)) { $config['parameters']['ps_cache_enable'] = $cache_active; // If there is not settings file modification or if the backup and replacement of the settings file worked if (file_put_contents(_PS_ROOT_DIR_ . '/app/config/parameters.yml', Yaml::dump($config))) { if (function_exists('opcache_invalidate')) { opcache_invalidate(_PS_ROOT_DIR_ . '/app/config/parameters.yml'); } $redirectAdmin = true; } else { $this->errors[] = $this->trans('The settings file cannot be overwritten.', array(), 'Admin.Parameters.Notification'); } } } else { $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error'); } } if ((bool) Tools::getValue('empty_smarty_cache')) { $redirectAdmin = true; Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); } if ((bool) Tools::getValue('empty_sf2_cache')) { $redirectAdmin = true; $sf2Refresh = new \PrestaShopBundle\Service\Cache\Refresh(); $sf2Refresh->addCacheClear(_PS_MODE_DEV_ ? 'dev' : 'prod'); $sf2Refresh->execute(); } if (Tools::isSubmit('submitAddconfiguration')) { Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module')); Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides')); if (Tools::isSubmit('debug_mode') && (bool) Tools::getValue('debug_mode')) { $debug_mode_status = $this->enableDebugMode(); } else { $debug_mode_status = $this->disableDebugMode(); } if (!empty($debug_mode_status)) { switch ($debug_mode_status) { case self::DEBUG_MODE_ERROR_COULD_NOT_BACKUP: $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.old.php')); break; case self::DEBUG_MODE_ERROR_NO_DEFINITION_FOUND: $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not find whether debug mode is enabled. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php')); break; case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS: $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php')); break; case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS_CUSTOM: $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines_custom.inc.php')); break; case self::DEBUG_MODE_ERROR_NO_READ_ACCESS: $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not read file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php')); break; default: break; } } Tools::generateIndex(); } if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) { Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => '')); Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } }
public static function createLabels($label_data, $tipo) { try { if (Validate::isFileName($label_data['pedido'])) { $label_name = $label_data['pedido']; } else { $module_instance = Module::getInstanceByName('seur'); return SeurLib::displayErrors($label_data['pedido'] . ' ' . $module_instance->l('could not be used as file name', 'Label')); } $sc_options = array('connection_timeout' => 30); $soap_client = new SoapClient((string) Configuration::get('SEUR_URLWS_ET'), $sc_options); $merchant_data = SeurLib::getMerchantData(); $notification = SeurLib::getConfigurationField('notification_advice_radio'); $advice_checkbox = SeurLib::getConfigurationField('advice_checkbox'); $distribution_checkbox = SeurLib::getConfigurationField('distribution_checkbox'); $servicio = 31; $producto = 2; $mercancia = false; $claveReembolso = ''; $valorReembolso = ''; if (SeurLib::getConfigurationField('international_orders') == 1 && ($label_data['iso'] != 'ES' && $label_data['iso'] != 'PT' && $label_data['iso'] != 'AD')) { $servicio = 77; $producto = 70; $mercancia = true; $label_data['total_bultos'] = 1; } if (isset($label_data['reembolso']) && ($label_data['iso'] == 'ES' || $label_data['iso'] == 'PT' || $label_data['iso'] == 'AD')) { $claveReembolso = 'f'; $valorReembolso = (double) $label_data['reembolso']; } if (isset($label_data['cod_centro']) && ($label_data['iso'] == 'ES' || $label_data['iso'] == 'PT' || $label_data['iso'] == 'AD')) { $servicio = 1; $producto = 48; } $total_weight = $label_data['total_kilos']; $total_packages = $label_data['total_bultos']; $pesoBulto = $total_weight / $total_packages; if ($pesoBulto < 1) { $pesoBulto = 1; $total_weight = $total_packages; } $cont = 0; $xml = '<?xml version="1.0" encoding="ISO-8859-1"?><root><exp>'; for ($i = 0; $i <= (double) $total_packages - 1; $i++) { $cont++; $xml .= '<bulto> <ci>' . (int) $merchant_data['cit'] . '</ci> <nif>' . pSQL($merchant_data['nif_dni']) . '</nif> <ccc>' . (int) $merchant_data['ccc'] . '</ccc> <servicio>' . pSQL($servicio) . '</servicio> <producto>' . pSQL($producto) . '</producto>'; if ($mercancia) { $xml .= '<id_mercancia>382</id_mercancia>'; } $xml .= '<cod_centro></cod_centro> <total_bultos>' . pSQL($total_packages) . '</total_bultos> <total_kilos>' . pSQL($total_weight) . '</total_kilos> <pesoBulto>' . pSQL($pesoBulto) . '</pesoBulto> <observaciones>' . pSQL($label_data['info_adicional']) . '</observaciones> <referencia_expedicion>' . pSQL($label_data['pedido']) . '</referencia_expedicion> <ref_bulto>' . pSQL($label_data['pedido'] . sprintf('%03d', (int) $i + 1)) . '</ref_bulto> <clavePortes>F</clavePortes> <clavePod></clavePod> <claveReembolso>' . pSQL($claveReembolso) . '</claveReembolso> <valorReembolso>' . pSQL($valorReembolso) . '</valorReembolso> <libroControl></libroControl> <nombre_consignatario>' . pSQL($label_data['name']) . '</nombre_consignatario> <direccion_consignatario>' . pSQL($label_data['direccion_consignatario']) . '</direccion_consignatario> <tipoVia_consignatario>CL</tipoVia_consignatario> <tNumVia_consignatario>N</tNumVia_consignatario> <numVia_consignatario>.</numVia_consignatario> <escalera_consignatario>.</escalera_consignatario> <piso_consignatario>.</piso_consignatario> <puerta_consignatario>.</puerta_consignatario> <poblacion_consignatario>' . pSQL($label_data['consignee_town']) . '</poblacion_consignatario>'; if (!empty($label_data['codPostal_consignatario'])) { $xml .= '<codPostal_consignatario>' . pSQL($label_data['codPostal_consignatario']) . '</codPostal_consignatario>'; } $xml .= ' <pais_consignatario>' . pSQL($label_data['iso']) . '</pais_consignatario> <codigo_pais_origen>' . pSQL($label_data['iso_merchant']) . '</codigo_pais_origen> <email_consignatario>' . pSQL($label_data['email_consignatario']) . '</email_consignatario> <sms_consignatario>' . ((int) $notification ? pSQL($label_data['movil']) : '') . '</sms_consignatario> <test_sms>' . ((int) $notification ? 'S' : 'N') . '</test_sms> <test_preaviso>' . ((int) $advice_checkbox ? 'S' : 'N') . '</test_preaviso> <test_reparto>' . ((int) $distribution_checkbox ? 'S' : 'N') . '</test_reparto> <test_email>' . ((int) $notification ? 'N' : 'S') . '</test_email> <eci>N</eci> <et>N</et> <telefono_consignatario>' . pSQL($label_data['telefono_consignatario']) . '</telefono_consignatario> <atencion_de>' . pSQL($label_data['companyia']) . '</atencion_de> </bulto> '; } $xml .= '</exp></root>'; $xml_name = (int) $merchant_data['franchise'] . '_' . (int) $merchant_data['cit'] . '_' . date('dmYHi') . '.xml'; $make_pickup = false; $auto = false; $pickup_data = Pickup::getLastPickup(); if (!empty($pickup_data)) { $datepickup = explode(' ', $pickup_data['date']); $datepickup = $datepickup[0]; if (strtotime(date('Y-m-d')) != strtotime($datepickup)) { $make_pickup = true; } if (SeurLib::getConfigurationField('pickup') == 0) { $auto = true; } } if ($tipo == 'pdf') { $data = array('in0' => $merchant_data['user'], 'in1' => $merchant_data['pass'], 'in2' => $xml, 'in3' => $xml_name, 'in4' => $merchant_data['nif_dni'], 'in5' => $merchant_data['franchise'], 'in6' => '-1', 'in7' => 'prestashop'); $response = $soap_client->impresionIntegracionPDFConECBWS($data); if ($response->out == 'ERROR') { return SeurLib::displayErrors((string) $response->out); } if ($response->out->mensaje != 'OK') { return SeurLib::displayErrors((string) $response->out->mensaje); } else { $pdf = base64_decode($response->out->PDF); if (is_writable(_PS_MODULE_DIR_ . 'seur/files/deliveries_labels/')) { file_put_contents(_PS_MODULE_DIR_ . 'seur/files/deliveries_labels/' . $label_name . '.pdf', $pdf); } SeurLib::setSeurOrder($label_data['pedido'], $total_packages, $total_weight, 'PDF'); if ($make_pickup && $auto) { Pickup::createPickup(); } } } elseif ($tipo == 'zebra') { $data = array('in0' => pSQL($merchant_data['user']), 'in1' => pSQL($merchant_data['pass']), 'in2' => 'ZEBRA', 'in3' => 'LP2844-Z', 'in4' => '2C', 'in5' => $xml, 'in6' => $xml_name, 'in7' => pSQL($merchant_data['nif_dni']), 'in8' => pSQL($merchant_data['franchise']), 'in9' => '-1', 'in10' => 'prestashop'); $response = $soap_client->impresionIntegracionConECBWS($data); if ($response->out == 'ERROR' || $response->out->mensaje != 'OK') { return SeurLib::displayErrors('Error al crear el envio y la etiqueta: ' . $response->out->mensaje); } else { if (is_writable(_PS_MODULE_DIR_ . 'seur/files/deliveries_labels/')) { file_put_contents(_PS_MODULE_DIR_ . 'seur/files/deliveries_labels/' . pSQL($label_name) . '.txt', (string) $response->out->traza); } SeurLib::setSeurOrder(pSQL($label_data['pedido']), (double) $total_packages, (double) $total_weight, 'zebra'); if ($make_pickup && $auto) { Pickup::createPickup(); } } } } catch (PrestaShopException $e) { $e->displayMessage(); } return true; }
public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->errors[] = Tools::displayError('This functionality has been disabled.'); return; } Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this)); if (Tools::isSubmit('submitAddServer')) { if ($this->tabAccess['add'] === '1') { if (!Tools::getValue('memcachedIp')) { $this->errors[] = Tools::displayError('The Memcached IP is missing.'); } if (!Tools::getValue('memcachedPort')) { $this->errors[] = Tools::displayError('The Memcached port is missing.'); } if (!Tools::getValue('memcachedWeight')) { $this->errors[] = Tools::displayError('The Memcached weight is missing.'); } if (!count($this->errors)) { if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = Tools::displayError('The Memcached server cannot be added.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } if (Tools::getValue('deleteMemcachedServer')) { if ($this->tabAccess['add'] === '1') { if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = Tools::displayError('There was an error when attempting to delete the Memcached server.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } } $redirectAdmin = false; if ((bool) Tools::getValue('smarty_up')) { if ($this->tabAccess['edit'] === '1') { Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_)); Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0)); Configuration::updateValue('PS_SMARTY_CONSOLE_KEY', Tools::getValue('smarty_console_key', 'SMARTY_DEBUG')); $redirecAdmin = true; } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('features_detachables_up')) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('combination') || !Combination::isCurrentlyUsed()) { Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination')); } if (Tools::getValue('customer_group') && !Group::isCurrentlyUsed()) { Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', Tools::getValue('customer_group')); } Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature')); $redirectAdmin = true; } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('ccc_up')) { if ($this->tabAccess['edit'] === '1') { $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/'; if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) { $this->errors[] = Tools::displayError(sprintf($this->l('To use Smart Cache directory %s must be writable.'), realpath($theme_cache_directory))); } if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) { $this->errors[] = Tools::displayError('Unknown error.'); } else { $redirectAdmin = true; if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) { Tools::generateHtaccess(); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('media_server_up')) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) { $this->errors[] = Tools::displayError('Media server #1 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) { $this->errors[] = Tools::displayError('Media server #2 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) { $this->errors[] = Tools::displayError('Media server #3 is invalid'); } if (!count($this->errors)) { $base_urls = array(); $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_'); $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_'); $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_'); if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) { Configuration::updateValue('PS_MEDIA_SERVERS', 1); } else { Configuration::updateValue('PS_MEDIA_SERVERS', 0); } rewriteSettingsFile($base_urls, null, null); Tools::clearSmartyCache(); Media::clearCache(); Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_'])); unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']); $redirectAdmin = true; } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) { if ($this->tabAccess['edit'] === '1') { $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM'); $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php'); $new_settings = $prev_settings; if ($algo) { if (!function_exists('mcrypt_encrypt')) { $this->errors[] = Tools::displayError('The "Mcrypt" PHP extension is not activated on this server.'); } else { if (!strstr($new_settings, '_RIJNDAEL_KEY_')) { $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $key = Tools::passwdGen($key_size); $new_settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $new_settings); } if (!strstr($new_settings, '_RIJNDAEL_IV_')) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND)); $new_settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $new_settings); } } } if (!count($this->errors)) { // If there is not settings file modification or if the backup and replacement of the settings file worked if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) { Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo); $redirectAdmin = true; } else { $this->errors[] = Tools::displayError('The settings file cannot be overwritten.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('cache_up')) { if ($this->tabAccess['edit'] === '1') { $new_settings = $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php'); $cache_active = (bool) Tools::getValue('cache_active'); if ($caching_system = Tools::getValue('caching_system')) { $new_settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]*)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $new_settings); } else { $cache_active = false; $this->errors[] = Tools::displayError('The caching system is missing.'); } if ($cache_active) { if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) { $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.') . ' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>'; } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc')) { $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.') . ' <a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>'; } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) { $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.') . ' <a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>'; } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) { $this->errors[] = Tools::displayError('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).') . ' <a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>'; } elseif ($caching_system == 'CacheFs') { if (!is_dir(_PS_CACHEFS_DIRECTORY_)) { @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true); } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) { $this->errors[] = sprintf(Tools::displayError('To use CacheFS, the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_)); } } if ($caching_system == 'CacheFs') { if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) { $this->errors[] = Tools::displayError('Please set a directory depth.'); } if (!count($this->errors)) { CacheFs::deleteCacheDirectory(); CacheFs::createCacheDirectories((int) $depth); Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth); } } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') { Cache::getInstance()->flush(); } } if (!count($this->errors)) { $new_settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([01]?)\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $new_settings); // If there is not settings file modification or if the backup and replacement of the settings file worked if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) { $redirectAdmin = true; } else { $this->errors[] = Tools::displayError('The settings file cannot be overwritten.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } if ((bool) Tools::getValue('empty_smarty_cache')) { $redirectAdmin = true; Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); PrestaShopAutoload::getInstance()->generateIndex(); } if (Tools::isSubmit('submitAddconfiguration') && _PS_MODE_DEV_) { Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module')); Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides')); if (Tools::getValue('overrides')) { PrestaShopAutoload::getInstance()->_include_override_path = false; } PrestaShopAutoload::getInstance()->generateIndex(); } if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) { Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => '')); Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } }
public function postProcess() { if (Tools::isSubmit('submitAddServer')) { if ($this->tabAccess['add'] === '1') { if (!Tools::getValue('memcachedIp')) { $this->errors[] = Tools::displayError('Memcached IP is missing'); } if (!Tools::getValue('memcachedPort')) { $this->errors[] = Tools::displayError('Memcached port is missing'); } if (!Tools::getValue('memcachedWeight')) { $this->errors[] = Tools::displayError('Memcached weight is missing'); } if (!count($this->errors)) { if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = Tools::displayError('Cannot add Memcached server'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to add here.'); } } if (Tools::getValue('deleteMemcachedServer')) { if ($this->tabAccess['add'] === '1') { if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { $this->errors[] = Tools::displayError('Error in deleting Memcached server'); } } else { $this->errors[] = Tools::displayError('You do not have permission to delete here.'); } } $redirecAdmin = false; if ((bool) Tools::getValue('smarty_up')) { if ($this->tabAccess['edit'] === '1') { Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_)); Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0)); $redirecAdmin = true; } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ((bool) Tools::getValue('features_detachables_up')) { if ($this->tabAccess['edit'] === '1') { if (!Combination::isCurrentlyUsed()) { Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination')); } Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature')); $redirecAdmin = true; } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ((bool) Tools::getValue('ccc_up')) { if ($this->tabAccess['edit'] === '1') { if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HIGH_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HIGH_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) { $this->errors[] = Tools::displayError('Unknown error.'); } else { $redirecAdmin = true; if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) { Tools::generateHtaccess(); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ((bool) Tools::getValue('media_server_up')) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) { $this->errors[] = Tools::displayError('Media server #1 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) { $this->errors[] = Tools::displayError('Media server #2 is invalid'); } if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) { $this->errors[] = Tools::displayError('Media server #3 is invalid'); } if (!count($this->errors)) { $base_urls = array(); $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_'); $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_'); $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_'); rewriteSettingsFile($base_urls, null, null); unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']); $redirecAdmin = true; } } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ((bool) Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) { if ($this->tabAccess['edit'] === '1') { $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM'); $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php'); if ($algo) { if (!function_exists('mcrypt_encrypt')) { $this->errors[] = Tools::displayError('PHP "Mcrypt" extension is not activated on this server.'); } else { if (!strstr($settings, '_RIJNDAEL_KEY_')) { $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $key = Tools::passwdGen($key_size); $settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $settings); } if (!strstr($settings, '_RIJNDAEL_IV_')) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND)); $settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $settings); } } } if (!count($this->errors)) { if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) { Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo); $redirecAdmin = true; } else { $this->errors[] = Tools::displayError('Cannot overwrite settings file.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ((bool) Tools::getValue('cache_up')) { if ($this->tabAccess['edit'] === '1') { $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php'); if (!Tools::getValue('active')) { $cache_active = 0; } else { $cache_active = 1; } if (!($caching_system = Tools::getValue('caching_system'))) { $this->errors[] = Tools::displayError('Caching system is missing'); } else { $settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]+)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $settings); } if ($cache_active && $caching_system == 'CacheMemcache' && !extension_loaded('memcache')) { $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.') . ' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>'; } else { if ($cache_active && $caching_system == 'CacheApc' && !extension_loaded('apc')) { $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.') . ' <a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>'; } else { if ($cache_active && $caching_system == 'CacheXcache' && !extension_loaded('xcache')) { $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.') . ' <a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>'; } else { if ($cache_active && $caching_system == 'CacheFs' && !is_writable(_PS_CACHEFS_DIRECTORY_)) { $this->errors[] = sprintf(Tools::displayError('To use CacheFS the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_)); } } } } if ($caching_system == 'CacheFs' && $cache_active) { if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) { $this->errors[] = Tools::displayError('Please set a directory depth'); } if (!count($this->errors)) { CacheFs::deleteCacheDirectory(); CacheFs::createCacheDirectories((int) $depth); Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth); } } else { if ($caching_system == 'MCached' && $cache_active && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'MCached') { Cache::getInstance()->flush(); } } if (!count($this->errors)) { $settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([0-9])\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $settings); if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) { $redirecAdmin = true; } else { $this->errors[] = Tools::displayError('Cannot overwrite settings file.'); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit here.'); } } if ($redirecAdmin) { Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4'); } else { return parent::postProcess(); } }
/** * Genrating a export file */ public function generateExport() { $id = Tools::getValue($this->identifier); $export_dir = defined('_PS_HOST_MODE_') ? _PS_ROOT_DIR_ . '/export/' : _PS_ADMIN_DIR_ . '/export/'; if (!Validate::isFileName($id)) { die(Tools::displayError()); } $file = 'request_sql_' . $id . '.csv'; if ($csv = fopen($export_dir . $file, 'w')) { $sql = RequestSql::getRequestSqlById($id); if ($sql) { $results = Db::getInstance()->executeS($sql[0]['sql']); foreach (array_keys($results[0]) as $key) { $tab_key[] = $key; fputs($csv, $key . ';'); } foreach ($results as $result) { fputs($csv, "\n"); foreach ($tab_key as $name) { fputs($csv, '"' . strip_tags($result[$name]) . '";'); } } if (file_exists($export_dir . $file)) { $filesize = filesize($export_dir . $file); $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize')); if ($filesize < $upload_max_filesize) { if (Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')) { $charset = Configuration::get('PS_ENCODING_FILE_MANAGER_SQL'); } else { $charset = self::$encoding_file[0]['name']; } header('Content-Type: text/csv; charset=' . $charset); header('Cache-Control: no-store, no-cache'); header('Content-Disposition: attachment; filename="' . $file . '"'); header('Content-Length: ' . $filesize); readfile($export_dir . $file); die; } else { $this->errors[] = Tools::DisplayError('The file is too large and can not be downloaded. Please use the LIMIT clause in this query.'); } } } } }
public function postProcess() { global $currentIndex; // Getting key value for display if (Tools::getValue('show_modules') and strval(Tools::getValue('show_modules')) != 'all') { $this->displayKey = intval(Tools::getValue('show_modules')); } // Change position in hook if (array_key_exists('changePosition', $_GET)) { if ($this->tabAccess['edit'] === '1') { $id_module = intval(Tools::getValue('id_module')); $id_hook = intval(Tools::getValue('id_hook')); $module = Module::getInstanceById($id_module); if (Validate::isLoadedObject($module)) { $module->updatePosition($id_hook, intval(Tools::getValue('direction'))); Tools::redirectAdmin($currentIndex . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } else { $this->_errors[] = Tools::displayError('module cannot be loaded'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } elseif (Tools::isSubmit('submitAddToHook')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts as $except) { if (!Validate::isFileName($except)) { $this->_errors[] = Tools::displayError('no valid value for field exceptions'); } } if (!$id_module or !Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('hook cannot be loaded'); } elseif (Hook::getModuleFromHook($id_hook, $id_module)) { $this->_errors[] = Tools::displayError('this module is already transplanted to this hook'); } elseif (!$module->registerHook($hook->name)) { $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); } elseif (!$module->registerExceptions($id_hook, $excepts)) { $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); } else { Tools::redirectAdmin($currentIndex . '&conf=16' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif (Tools::isSubmit('submitEditGraft')) { if ($this->tabAccess['add'] === '1') { // Getting vars... $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts as $except) { if (!Validate::isFileName($except)) { $this->_errors[] = Tools::displayError('no valid value for field exceptions'); } } if (!$id_module or !Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('hook cannot be loaded'); } // Adding vars... if (!$module->editExceptions($id_hook, $excepts)) { $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); } else { Tools::redirectAdmin($currentIndex . '&conf=16' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } elseif (array_key_exists('deleteGraft', $_GET)) { if ($this->tabAccess['delete'] === '1') { $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $hook = new Hook($id_hook); if (!Validate::isLoadedObject($module)) { $this->_errors[] = Tools::displayError('module cannot be loaded'); } elseif (!$id_hook or !Validate::isLoadedObject($hook)) { $this->_errors[] = Tools::displayError('hook cannot be loaded'); } else { if (!$module->unregisterHook($id_hook) or !$module->unregisterExceptions($id_hook)) { $this->_errors[] = Tools::displayError('an error occurred while deleting module from hook'); } else { Tools::redirectAdmin($currentIndex . '&conf=17' . ($this->displayKey ? '&show_modules=' . $this->displayKey : '') . '&token=' . $this->token); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } }
private function _postValidation() { $errors = array(); /* Validation for Slider configuration */ if (Tools::isSubmit('submitSlider')) { if (!Validate::isInt(Tools::getValue('CATESLIDER_SPEED')) || !Validate::isInt(Tools::getValue('CATESLIDER_PAUSE')) || !Validate::isInt(Tools::getValue('CATESLIDER_WIDTH')) || !Validate::isInt(Tools::getValue('CATESLIDER_HEIGHT'))) { $errors[] = $this->l('Invalid values'); } } elseif (Tools::isSubmit('changeStatus')) { if (!Validate::isInt(Tools::getValue('id_slide'))) { $errors[] = $this->l('Invalid slide'); } } elseif (Tools::isSubmit('submitSlide')) { /* Checks state (active) */ if (!Validate::isInt(Tools::getValue('active_slide')) || Tools::getValue('active_slide') != 0 && Tools::getValue('active_slide') != 1) { $errors[] = $this->l('Invalid slide state'); } /* Checks position */ if (!Validate::isInt(Tools::getValue('position')) || Tools::getValue('position') < 0) { $errors[] = $this->l('Invalid slide position'); } /* If edit : checks id_slide */ if (Tools::isSubmit('id_slide')) { if (!Validate::isInt(Tools::getValue('id_slide')) && !$this->slideExists(Tools::getValue('id_slide'))) { $errors[] = $this->l('Invalid id_slide'); } } /* Checks title/url/legend/description/image */ $languages = Language::getLanguages(false); foreach ($languages as $language) { if (Tools::strlen(Tools::getValue('title_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The title is too long.'); } if (Tools::strlen(Tools::getValue('legend_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The legend is too long.'); } if (Tools::strlen(Tools::getValue('url_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The URL is too long.'); } if (Tools::strlen(Tools::getValue('description_' . $language['id_lang'])) > 4000) { $errors[] = $this->l('The description is too long.'); } if (Tools::strlen(Tools::getValue('url_' . $language['id_lang'])) > 0 && !Validate::isUrl(Tools::getValue('url_' . $language['id_lang']))) { $errors[] = $this->l('The URL format is not correct.'); } if (Tools::getValue('image_' . $language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_' . $language['id_lang']))) { $errors[] = $this->l('Invalid filename'); } if (Tools::getValue('image_old_' . $language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_' . $language['id_lang']))) { $errors[] = $this->l('Invalid filename'); } } /* Checks title/url/legend/description for default lang */ $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); if (Tools::strlen(Tools::getValue('title_' . $id_lang_default)) == 0) { $errors[] = $this->l('The title is not set.'); } if (Tools::strlen(Tools::getValue('legend_' . $id_lang_default)) == 0) { $errors[] = $this->l('The legend is not set.'); } if (Tools::strlen(Tools::getValue('url_' . $id_lang_default)) == 0) { $errors[] = $this->l('The URL is not set.'); } if (!Tools::isSubmit('has_picture') && (!isset($_FILES['image_' . $id_lang_default]) || empty($_FILES['image_' . $id_lang_default]['tmp_name']))) { $errors[] = $this->l('The image is not set.'); } if (Tools::getValue('image_old_' . $id_lang_default) && !Validate::isFileName(Tools::getValue('image_old_' . $id_lang_default))) { $errors[] = $this->l('The image is not set.'); } } elseif (Tools::isSubmit('delete_id_slide') && (!Validate::isInt(Tools::getValue('delete_id_slide')) || !$this->slideExists((int) Tools::getValue('delete_id_slide')))) { $errors[] = $this->l('Invalid id_slide'); } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); return false; } /* Returns if validation is ok */ return true; }
public function postValidation() { $errors = array(); if (Tools::isSubmit('submitPtsBtTestimonials')) { if (!Validate::isInt(Tools::getValue($this->renderName('limit'))) || !Validate::isInt(Tools::getValue($this->renderName('width'))) || !Validate::isInt(Tools::getValue($this->renderName('height'))) || !Validate::isInt(Tools::getValue($this->renderName('speed')))) { $errors[] = $this->l('Invalid values! check values to input again.'); } } elseif (Tools::isSubmit('changeStatus')) { if (!Validate::isInt(Tools::getValue('id_test'))) { $errors[] = $this->l('Invalid Testimonial'); } } elseif (Tools::isSubmit('submitTestimonial')) { if (Tools::getValue('image') != null && !Validate::isFileName(Tools::getValue('image'))) { $errors[] = $this->l('Invalid filename.'); } if (Tools::getValue('image_old') != null && !Validate::isFileName(Tools::getValue('image_old'))) { $errors[] = $this->l('Invalid filename.'); } if (!Validate::isGenericName(Tools::getValue('name'))) { $errors[] = $this->l('The name is empty or incorrect data input.'); } elseif (Tools::strlen(Tools::getValue('name') > 100)) { $errors[] = $this->l('The name is too long.'); } if (!Validate::isEmail(Tools::getValue('email'))) { $errors[] = $this->l('The email is empty or incorrect data input.'); } elseif (Tools::strlen(Tools::getValue('email') > 100)) { $errors[] = $this->l('The email is too long.'); } if (!Validate::isGenericName(Tools::getValue('address'))) { $errors[] = $this->l('The address is empty or incorrect data input.'); } elseif (Tools::strlen(Tools::getValue('address') > 500)) { $errors[] = $this->l('The address is too long.'); } if (!Validate::isInt(Tools::getValue('active_test')) || Tools::getValue('active_test') != 0 && Tools::getValue('active_test') != 1) { $errors[] = $this->l('Invalid testimonial state.'); } if (Tools::isSubmit('id_test')) { if (!Validate::isInt(Tools::getValue('id_test')) && !$this->testimonialExists(Tools::getValue('id_test'))) { $errors[] = $this->l('Invalid Id_testimonial'); } } foreach ($this->languages() as $language) { if (Tools::strlen(Tools::getValue('content_' . $language['id_lang'])) > 6000) { $errors[] = $this->l('The content is too long.'); } if (Tools::strlen(Tools::getValue('note_' . $language['id_lang'])) > 500) { $errors[] = $this->l('The note is too long.'); } } } elseif (Tools::isSubmit('delete_id_test') && (!Validate::isInt(Tools::getValue('delete_id_test')) || !$this->testimonialExists((int) Tools::getValue('delete_id_test')))) { $errors[] = $this->l('Invalid Id_testimonial'); } /* Display errors if needs */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); return false; } return true; }