public function install() { if (Db::getInstance()->getValue('SELECT id_module FROM ' . _DB_PREFIX_ . 'module WHERE name =\'' . pSQL($this->name) . '\'')) { return true; } Tools::deleteDirectory($this->cache_data, false); if (!$this->installDb() || !$this->installTab() || !Configuration::updateGlobalValue('GF_INSTALL_CALC', 0) || !Configuration::updateGlobalValue('GF_CURRENT_LEVEL', 1) || !Configuration::updateGlobalValue('GF_CURRENT_LEVEL_PERCENT', 0) || !Configuration::updateGlobalValue('GF_NOTIFICATION', 0) || !parent::install() || !$this->registerHook('displayBackOfficeHeader')) { return false; } return true; }
protected function installTheme($theme_dir, $sandbox = false, $redirect = true) { if (!$sandbox) { $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; mkdir($sandbox); Tools::recurseCopy(_PS_ALL_THEMES_DIR_ . $theme_dir, $sandbox . $theme_dir); } $xml_file = $sandbox . $theme_dir . '/Config.xml'; if (!$this->checkXmlFields($xml_file)) { $this->errors[] = $this->l('Bad configuration file'); } else { $imported_theme = $this->importThemeXmlConfig(simplexml_load_file($xml_file)); foreach ($imported_theme as $theme) { if (Validate::isLoadedObject($theme)) { if (!copy($sandbox . $theme_dir . '/Config.xml', _PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml')) { $this->errors[] = $this->l('Can\'t copy configuration file'); } $target_dir = _PS_ALL_THEMES_DIR_ . $theme->directory; if (file_exists($target_dir)) { Tools::deleteDirectory($target_dir); } $theme_doc_dir = $target_dir . '/docs/'; if (file_exists($theme_doc_dir)) { Tools::deleteDirectory($theme_doc_dir); } mkdir($target_dir); mkdir($theme_doc_dir); Tools::recurseCopy($sandbox . $theme_dir . '/themes/' . $theme->directory . '/', $target_dir . '/'); Tools::recurseCopy($sandbox . $theme_dir . '/doc/', $theme_doc_dir); Tools::recurseCopy($sandbox . $theme_dir . '/modules/', _PS_MODULE_DIR_); } else { $this->errors[] = $theme; } } } if (!count($this->errors)) { if ($redirect) { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=18'); } else { return true; } } else { return false; } }
public function uploadImageZip($product) { // Move the ZIP file to the img/tmp directory if (!($zipfile = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['image_product']['tmp_name'], $zipfile)) { $this->_errors[] = Tools::displayError('An error occurred during the ZIP file upload.'); return false; } // Unzip the file to a subdirectory $subdir = _PS_TMP_IMG_DIR_ . uniqid() . '/'; try { if (!Tools::ZipExtract($zipfile, $subdir)) { throw new Exception(Tools::displayError('An error occurred while unzipping your file.')); } $types = array('.gif' => 'image/gif', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpg', '.png' => 'image/png'); $_POST['id_product'] = (int) $product->id; $imagesTypes = ImageType::getImagesTypes('products'); $highestPosition = Image::getHighestPosition($product->id); foreach (scandir($subdir) as $file) { if ($file[0] == '.') { continue; } // Create image object $image = new Image(); $image->id_product = (int) $product->id; $image->position = ++$highestPosition; $image->cover = $highestPosition == 1 ? true : false; // Call automated copy function $this->validateRules('Image', 'image'); $this->copyFromPost($image, 'image'); if (sizeof($this->_errors)) { throw new Exception(''); } if (!$image->add()) { throw new Exception(Tools::displayError('Error while creating additional image')); } if (filesize($subdir . $file) > $this->maxImageSize) { $image->delete(); throw new Exception(Tools::displayError('Image is too large') . ' (' . filesize($subdir . $file) / 1000 . Tools::displayError('kB') . '). ' . Tools::displayError('Maximum allowed:') . ' ' . $this->maxImageSize / 1000 . Tools::displayError('kB')); } $ext = substr($file, -4) == 'jpeg' ? '.jpeg' : substr($file, -4); $type = isset($types[$ext]) ? $types[$ext] : ''; if (!isPicture(array('tmp_name' => $subdir . $file, 'type' => $type))) { $image->delete(); throw new Exception(Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png')); } if (!($new_path = $image->getPathForCreation())) { throw new Exception(Tools::displayError('An error occurred during new folder creation')); } if (!imageResize($subdir . $file, $new_path . '.' . $image->image_format)) { $image->delete(); throw new Exception(Tools::displayError('An error occurred while resizing image.')); } foreach ($imagesTypes as $k => $imageType) { if (!imageResize($image->getPathForCreation() . '.jpg', $image->getPathForCreation() . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height'])) { $image->delete(); throw new Exception(Tools::displayError('An error occurred while copying image.') . ' ' . stripslashes($imageType['name'])); } } Module::hookExec('watermark', array('id_image' => $image->id, 'id_product' => $image->id_product)); } } catch (Exception $e) { if ($error = $e->getMessage()) { } $this->_errors[] = $error; Tools::deleteDirectory($subdir); return false; } Tools::deleteDirectory($subdir); return true; }
public static function deleteCacheDirectory() { Tools::deleteDirectory(CACHEFS_DIR, false); }
public function downloadAddonsThemes() { if (!$this->logged_on_addons) { return false; } if (!$this->isFresh(self::CACHE_FILE_CUSTOMER_THEMES_LIST, 86400)) { file_put_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_THEMES_LIST, Tools::addonsRequest('customer_themes')); } $customer_themes_list = file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_THEMES_LIST); if (!empty($customer_themes_list) && ($customer_themes_list_xml = @simplexml_load_string($customer_themes_list))) { foreach ($customer_themes_list_xml->theme as $addons_theme) { //get addons theme if folder does not exist $ids_themes = Tools::unSerialize(Configuration::get('PS_ADDONS_THEMES_IDS')); if (!is_array($ids_themes) || is_array($ids_themes) && !in_array((string) $addons_theme->id, $ids_themes)) { $zip_content = Tools::addonsRequest('module', array('id_module' => pSQL($addons_theme->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))); $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; mkdir($sandbox); file_put_contents($sandbox . (string) $addons_theme->getName() . '.zip', $zip_content); if ($this->extractTheme($sandbox . (string) $addons_theme->getName() . '.zip', $sandbox)) { if ($theme_directory = $this->installTheme(self::UPLOADED_THEME_DIR_NAME, $sandbox, false)) { $ids_themes[$theme_directory] = (string) $addons_theme->id; } } Tools::deleteDirectory($sandbox); } Configuration::updateValue('PS_ADDONS_THEMES_IDS', serialize($ids_themes)); } } }
public function submitImportLang() { if (!isset($_FILES['file']['tmp_name']) || !$_FILES['file']['tmp_name']) { $this->errors[] = Tools::displayError('No file has been selected.'); } else { require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php'; $gz = new Archive_Tar($_FILES['file']['tmp_name'], true); $filename = $_FILES['file']['name']; $iso_code = str_replace(array('.tar.gz', '.gzip'), '', $filename); if (Validate::isLangIsoCode($iso_code)) { $themes_selected = Tools::getValue('theme', array(self::DEFAULT_THEME_NAME)); $files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent()); $files_paths = AdminTranslationsController::filesListToPaths($files_list); $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; if ($gz->extractList($files_paths, $sandbox)) { foreach ($files_list as $file2check) { //don't validate index.php, will be overwrite when extract in translation directory if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php') { continue; } if (preg_match('@^[0-9a-z-_/\\\\]+\\.php$@i', $file2check['filename'])) { if (!AdminTranslationsController::checkTranslationFile(file_get_contents($sandbox . $file2check['filename']))) { $this->errors[] = sprintf(Tools::displayError('Validation failed for: %s'), $file2check['filename']); } } elseif (!preg_match('@^[0-9a-z-_/\\\\]+\\.(html|tpl|txt)$@i', $file2check['filename'])) { $this->errors[] = sprintf(Tools::displayError('Unidentified file found: %s'), $file2check['filename']); } } Tools::deleteDirectory($sandbox, true); } if (count($this->errors)) { return false; } if ($gz->extractList($files_paths, _PS_TRANSLATIONS_DIR_ . '../')) { foreach ($files_list as $file2check) { if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php' && file_put_contents(_PS_TRANSLATIONS_DIR_ . '../' . $file2check['filename'], Tools::getDefaultIndexContent())) { continue; } } // Clear smarty modules cache Tools::clearCache(); if (Validate::isLanguageFileName($filename)) { if (!Language::checkAndAddLanguage($iso_code)) { $conf = 20; } else { // Reset cache Language::loadLanguages(); AdminTranslationsController::checkAndAddMailsFiles($iso_code, $files_list); $this->checkAndAddThemesFiles($files_list, $themes_selected); $tab_errors = AdminTranslationsController::addNewTabs($iso_code, $files_list); if (count($tab_errors)) { $this->errors += $tab_errors; return false; } } } $this->redirect(false, isset($conf) ? $conf : '15'); } $this->errors[] = Tools::displayError('The archive cannot be extracted.'); } else { $this->errors[] = sprintf(Tools::displayError('ISO CODE invalid "%1$s" for the following file: "%2$s"'), $iso_code, $filename); } } }
public function processDelete() { $obj = $this->loadObject(); if ($obj && is_dir(_PS_ALL_THEMES_DIR_ . $obj->directory)) { Tools::deleteDirectory(_PS_ALL_THEMES_DIR_ . $obj->directory . '/'); } if ($obj && $obj->isUsed()) { $this->errors[] = $this->l('This theme is already used by at least one shop. Please choose another theme first.'); return false; } return parent::processDelete(); }
public function processImportTheme() { $this->display = 'importtheme'; if (defined('_PS_HOST_MODE_')) { return true; } if (isset($_FILES['themearchive']) && isset($_POST['filename']) && Tools::isSubmit('theme_archive_server')) { $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; mkdir($sandbox); $archive_uploaded = false; if (Tools::getValue('filename') != '') { if ($_FILES['themearchive']['error'] || !file_exists($_FILES['themearchive']['tmp_name'])) { $this->errors[] = sprintf($this->l('An error has occurred during the file upload (%s)'), $_FILES['themearchive']['error']); } elseif (substr($_FILES['themearchive']['name'], -4) != '.zip') { $this->errors[] = $this->l('Only zip files are allowed'); } elseif (!move_uploaded_file($_FILES['themearchive']['tmp_name'], $sandbox . 'uploaded.zip')) { $this->errors[] = $this->l('An error has occurred during the file copy.'); } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) { $archive_uploaded = true; } else { $this->errors[] = $this->l('Zip file seems to be broken'); } } elseif (Tools::getValue('themearchiveUrl') != '') { if (!Validate::isModuleUrl($url = Tools::getValue('themearchiveUrl'), $this->errors)) { $this->errors[] = $this->l('Only zip files are allowed'); } elseif (!move_uploaded_file($url, $sandbox . 'uploaded.zip')) { $this->errors[] = $this->l('Error during the file download'); } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) { $archive_uploaded = true; } else { $this->errors[] = $this->l('Zip file seems to be broken'); } } elseif (Tools::getValue('theme_archive_server') != '') { $filename = _PS_ALL_THEMES_DIR_ . Tools::getValue('theme_archive_server'); if (substr($filename, -4) != '.zip') { $this->errors[] = $this->l('Only zip files are allowed'); } elseif (!copy($filename, $sandbox . 'uploaded.zip')) { $this->errors[] = $this->l('An error has occurred during the file copy.'); } elseif (Tools::ZipTest($sandbox . 'uploaded.zip')) { $archive_uploaded = true; } else { $this->errors[] = $this->l('Zip file seems to be broken'); } } else { $this->errors[] = $this->l('You must upload or enter a location of your zip'); } if ($archive_uploaded) { if (!Tools::ZipExtract($sandbox . '/uploaded.zip', $sandbox . 'uploaded/')) { $this->errors[] = $this->l('Error during zip extraction'); } else { if (!$this->checkXmlFields($sandbox)) { $this->errors[] = $this->l('Bad configuration file'); } else { $imported_theme = $this->importThemeXmlConfig(simplexml_load_file($sandbox . 'uploaded/Config.xml')); if (Validate::isLoadedObject($imported_theme)) { if (!copy($sandbox . 'uploaded/Config.xml', _PS_ROOT_DIR_ . '/config/xml/themes/' . $imported_theme->directory . '.xml')) { $this->errors[] = $this->l('Can\'t copy configuration file'); } $target_dir = _PS_ALL_THEMES_DIR_ . $imported_theme->directory; $theme_doc_dir = $target_dir . '/docs/'; if (file_exists($theme_doc_dir)) { Tools::deleteDirectory($theme_doc_dir); } $this->recurseCopy($sandbox . 'uploaded/themes/' . $imported_theme->directory, $target_dir); $this->recurseCopy($sandbox . 'uploaded/doc/', $theme_doc_dir); $this->recurseCopy($sandbox . 'uploaded/modules/', _PS_MODULE_DIR_); } else { $this->errors[] = $imported_theme; } } } } Tools::deleteDirectory($sandbox); if (count($this->errors) > 0) { $this->display = 'importtheme'; } else { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=18'); } } }
/** * PROCESS : configureShop * Set default shop configuration */ public function configureShop(array $data = array()) { // Clear smarty cache $this->clearSmartyCache(); //clear image cache in tmp folder Tools::deleteDirectory(_PS_TMP_IMG_DIR_, false); $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_server' => '', 'smtp_login' => '', 'smtp_password' => '', 'smtp_encryption' => 'off', 'smtp_port' => 25); foreach ($default_data as $k => $v) { if (!isset($data[$k])) { $data[$k] = $v; } } Context::getContext()->shop = new Shop(1); Configuration::loadConfiguration(); $id_country = Country::getByIso($data['shop_country']); // Set default configuration Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost()); Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_); Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso()); Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']); Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']); Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country); Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']); Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']); Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']); // Set mails configuration Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1); Configuration::updateGlobalValue('PS_MAIL_SERVER', $data['smtp_server']); Configuration::updateGlobalValue('PS_MAIL_USER', $data['smtp_login']); Configuration::updateGlobalValue('PS_MAIL_PASSWD', $data['smtp_password']); Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']); Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']); // Activate rijndael 128 encrypt algorihtm if mcrypt is activated Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0); // Set logo configuration if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) { list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg'); Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width)); Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height)); } // Active only the country selected by the merchant Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country); // Set localization configuration $version = str_replace('.', '', _PS_VERSION_); $version = substr($version, 0, 2); $localization_file_content = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . $data['shop_country'] . '.xml'); if (!@simplexml_load_string($localization_file_content)) { $localization_file_content = false; } if (!$localization_file_content) { $localization_file = _PS_ROOT_DIR_ . '/localization/default.xml'; if (file_exists(_PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml')) { $localization_file = _PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml'; } $localization_file_content = file_get_contents($localization_file); } $locale = new LocalizationPackCore(); $locale->loadLocalisationPack($localization_file_content, '', true); // Create default employee if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) { $employee = new Employee(); $employee->firstname = Tools::ucfirst($data['admin_firstname']); $employee->lastname = Tools::ucfirst($data['admin_lastname']); $employee->email = $data['admin_email']; $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']); $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes')); $employee->bo_theme = 'default'; $employee->active = true; $employee->id_profile = 1; $employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->bo_show_screencast = 1; if (!$employee->add()) { $this->setError($this->language->l('Cannot create admin account')); return false; } } else { $this->setError($this->language->l('Cannot create admin account')); return false; } // Update default contact if (isset($data['admin_email'])) { Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']); $contacts = new Collection('Contact'); foreach ($contacts as $contact) { $contact->email = $data['admin_email']; $contact->update(); } } return true; }
public function postProcessCallback() { $return = false; $installed_modules = array(); foreach ($this->map as $key => $method) { $modules = Tools::getValue($key); if (strpos($modules, '|')) { $modules_list_save = $modules; $modules = explode('|', $modules); } else { $modules = empty($modules) ? false : array($modules); } $module_errors = array(); if ($modules) { foreach ($modules as $name) { $full_report = null; if ($key == 'update') { if (ConfigurationTest::test_dir('modules/' . $name, true, $full_report)) { Tools::deleteDirectory('../modules/' . $name . '/'); } else { $module = Module::getInstanceByName(urldecode($name)); $this->errors[] = $this->l(sprintf("Module %s can't be upgraded : ", $module->displayName)) . $full_report; continue; } } // If Addons module, download and unzip it before installing it if (!file_exists('../modules/' . $name . '/' . $name . '.php')) { $filesList = array(array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1)); foreach ($filesList as $f) { if (file_exists(_PS_ROOT_DIR_ . $f['file'])) { $file = $f['file']; $content = Tools::file_get_contents(_PS_ROOT_DIR_ . $file); $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA); foreach ($xml->module as $modaddons) { if ($name == $modaddons->name && isset($modaddons->id) && ($this->logged_on_addons || $f['loggedOnAddons'] == 0)) { if ($f['loggedOnAddons'] == 0) { if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id))))) { $this->extractArchive('../modules/' . $modaddons->name . '.zip', false); } } if ($f['loggedOnAddons'] == 1 && $this->logged_on_addons) { if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) { $this->extractArchive('../modules/' . $modaddons->name . '.zip', false); } } } } } } } // Check potential error if (!($module = Module::getInstanceByName(urldecode($name)))) { $this->errors[] = $this->l('Module not found'); } elseif ($key == 'install' && $this->tabAccess['add'] !== '1') { $this->errors[] = Tools::displayError('You do not have permission to install this module.'); } elseif ($key == 'uninstall' && ($this->tabAccess['delete'] !== '1' || !$module->getPermission('configure'))) { $this->errors[] = Tools::displayError('You do not have permission to delete this module.'); } elseif ($key == 'configure' && ($this->tabAccess['edit'] !== '1' || !$module->getPermission('configure') || !Module::isInstalled(urldecode($name)))) { $this->errors[] = Tools::displayError('You do not have permission to configure this module.'); } elseif ($key == 'install' && Module::isInstalled($module->name)) { $this->errors[] = Tools::displayError('This module is already installed:') . ' ' . $module->name; } elseif ($key == 'uninstall' && !Module::isInstalled($module->name)) { $this->errors[] = Tools::displayError('This module has already been uninstalled:') . ' ' . $module->name; } else { if ($key == 'update' && !Module::isInstalled($module->name)) { $this->errors[] = Tools::displayError('This module need to be installed in order to be updated:') . ' ' . $module->name; } else { // If we install a module, force temporary global context for multishop if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $method != 'getContent') { Context::getContext()->tmpOldShop = clone Context::getContext()->shop; Context::getContext()->shop = new Shop(); } //retrocompatibility if (Tools::getValue('controller') != '') { $_POST['tab'] = Tools::safeOutput(Tools::getValue('controller')); } $echo = ''; if ($key != 'update') { // We check if method of module exists if (!method_exists($module, $method)) { throw new PrestaShopException('Method of module can\'t be found'); } // Get the return value of current method $echo = $module->{$method}(); } // If the method called is "configure" (getContent method), we show the html code of configure page if ($key == 'configure' && Module::isInstalled($module->name)) { if (isset($module->multishop_context)) { $this->multishop_context = $module->multishop_context; } $backlink = self::$currentIndex . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name; $hooklink = 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . (int) $module->id; $tradlink = 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&lang='; $toolbar = '<table class="table" cellpadding="0" cellspacing="0" style="margin:auto;text-align:center"><tr> <th>' . $this->l('Module') . ' <span style="color: green;">' . $module->name . '</span></th> <th><a href="' . $backlink . '" style="padding:5px 10px">' . $this->l('Back') . '</a></th> <th><a href="' . $hooklink . '" style="padding:5px 10px">' . $this->l('Manage hooks') . '</a></th> <th style="padding:5px 10px">' . $this->l('Manage translations') . ' '; foreach (Language::getLanguages(false) as $language) { $toolbar .= '<a href="' . $tradlink . $language['iso_code'] . '#' . $module->name . '" style="margin-left:5px"><img src="' . _THEME_LANG_DIR_ . $language['id_lang'] . '.jpg" alt="' . $language['iso_code'] . '" title="' . $language['iso_code'] . '" /></a>'; } $toolbar .= '</th></tr>'; // Display checkbox in toolbar if multishop if (Shop::isFeatureActive()) { $activateOnclick = 'onclick="location.href = \'' . $this->getCurrentUrl('enable') . '&enable=\'+(($(this).attr(\'checked\')) ? 1 : 0)"'; $toolbar .= '<tr> <th colspan="4"> <input type="checkbox" name="activateModule" value="1" ' . ($module->active ? 'checked="checked"' : '') . ' ' . $activateOnclick . ' /> ' . $this->l('Activate module for') . ' '; if (Shop::getContext() == Shop::CONTEXT_SHOP) { $toolbar .= 'shop <b>' . $this->context->shop->name . '</b>'; } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_group = new ShopGroup((int) Shop::getContextShopGroupID()); $toolbar .= 'all shops of group shop <b>' . $shop_group->name . '</b>'; } else { $toolbar .= 'all shops'; } $toolbar .= '</th> </tr>'; } $toolbar .= '</table>'; if (Shop::isFeatureActive() && isset(Context::getContext()->tmpOldShop)) { Context::getContext()->shop = clone Context::getContext()->tmpOldShop; unset(Context::getContext()->tmpOldShop); } // Display module configuration $this->context->smarty->assign('module_content', $toolbar . '<div class="clear"> </div>' . $echo . '<div class="clear"> </div>' . $toolbar); } elseif ($echo === true) { $return = 13; if ($method == 'install') { $return = 12; $installed_modules[] = $module->id; } } elseif ($echo === false) { $module_errors[] = array('name' => $name, 'message' => $module->getErrors()); } if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && isset(Context::getContext()->tmpOldShop)) { Context::getContext()->shop = clone Context::getContext()->tmpOldShop; unset(Context::getContext()->tmpOldShop); } } } if ($key != 'configure' && isset($_GET['bpay'])) { Tools::redirectAdmin('index.php?tab=AdminPayment&token=' . Tools::getAdminToken('AdminPayment' . (int) Tab::getIdFromClassName('AdminPayment') . (int) $this->id_employee)); } } } if (count($module_errors)) { // If error during module installation, no redirection $html_error = $this->generateHtmlMessage($module_errors); $this->errors[] = sprintf(Tools::displayError('The following module(s) were not installed properly: %s'), $html_error); $this->context->smarty->assign('error_module', 'true'); } } if ($return) { $params = count($installed_modules) ? '&installed_modules=' . implode('|', $installed_modules) : ''; // If redirect parameter is present and module installed with success, we redirect on configuration module page if (Tools::getValue('redirect') == 'config' && Tools::getValue('module_name') != '' && $return == '12' && Module::isInstalled(pSQL(Tools::getValue('module_name')))) { Tools::redirectAdmin('index.php?controller=adminmodules&configure=' . Tools::getValue('module_name') . '&token=' . Tools::getValue('token') . '&module_name=' . Tools::getValue('module_name') . $params); } Tools::redirectAdmin(self::$currentIndex . '&conf=' . $return . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=anchor' . ucfirst($module->name) . (isset($modules_list_save) ? '&modules_list=' . $modules_list_save : '') . $params); } }
protected function extractTheme($theme_zip_file, $sandbox) { if (!Tools::ZipExtract($theme_zip_file, $sandbox . 'uploaded/')) { $this->errors[] = $this->l('Error during zip extraction'); } else { if (!$this->checkXmlFields($sandbox)) { $this->errors[] = $this->l('Bad configuration file'); } else { $imported_theme = $this->importThemeXmlConfig(simplexml_load_file($sandbox . 'uploaded/Config.xml')); foreach ($imported_theme as $theme) { if (Validate::isLoadedObject($theme)) { if (!copy($sandbox . 'uploaded/Config.xml', _PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml')) { $this->errors[] = $this->l('Can\'t copy configuration file'); } $target_dir = _PS_ALL_THEMES_DIR_ . $theme->directory; $theme_doc_dir = $target_dir . '/docs/'; if (file_exists($theme_doc_dir)) { Tools::deleteDirectory($theme_doc_dir); } Tools::recurseCopy($sandbox . 'uploaded/themes/' . $theme->directory, $target_dir); Tools::recurseCopy($sandbox . 'uploaded/doc/', $theme_doc_dir); Tools::recurseCopy($sandbox . 'uploaded/modules/', _PS_MODULE_DIR_); } else { $this->errors[] = $theme; } } } } if (!count($this->errors)) { return $theme->directory; } return false; }
/** * Delete cache directory */ public static function deleteCacheDirectory() { Tools::deleteDirectory(_PS_CACHEFS_DIRECTORY_, false); }
public function addProductImages3D($product_id, $pack = "3d_image_pack", $dirs = "images3d") { if (isset($_FILES[$pack]) && $_FILES[$pack] && $_FILES[$pack]['name']) { if ($error = checkImageUploadError($_FILES[$pack])) { $this->_errors[] = $error; } if (!sizeof($this->_errors) and !empty($_FILES[$pack]['tmp_name'])) { try { if (!($zipfile = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES[$pack]['tmp_name'], $zipfile)) { return false; //throw new Exception(Tools::displayError('An error occurred during the ZIP file upload.')); } $subdir = _PS_IMG_DIR_ . $dirs . '/' . $product_id . '/'; Tools::deleteDirectory($subdir); if (!Tools::ZipExtract($zipfile, $subdir)) { throw new Exception(Tools::displayError('An error occurred while unzipping your file.')); } $types = array('.gif' => 'image/gif', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpg', '.png' => 'image/png'); $files = array_slice(scandir($subdir), 2); foreach ($files as $file) { if (filesize($subdir . $file) > $this->maxImageSize) { throw new Exception(Tools::displayError('Image is too large') . ' (' . filesize($subdir . $file) / 1000 . Tools::displayError('kB') . '). ' . Tools::displayError('Maximum allowed:') . ' ' . $this->maxImageSize / 1000 . Tools::displayError('kB')); } $ext = substr($file, -4) == 'jpeg' ? '.jpeg' : substr($file, -4); $type = isset($types[$ext]) ? $types[$ext] : ''; if (!isPicture(array('tmp_name' => $subdir . $file, 'type' => $type))) { throw new Exception(Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png')); } imageResize($subdir . $file, $subdir . $file, 600, 600); //Module::hookExec('watermark', array('id_image' => $image->id, 'id_product' => $image->id_product)); } $images_3d_count = count($files); } catch (Exception $e) { $error = $e->getMessage(); $this->_errors[] = $error; Tools::deleteDirectory($subdir); } unlink($zipfile); } } }
/** * ajaxProcessRestoreFiles restore the previously saved files, * and delete files that weren't archived * * @return boolean true if succeed */ public function ajaxProcessRestoreFiles() { // loop $this->next = 'restoreFiles'; if (!file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->fromArchiveFileList) || !file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toRemoveFileList)) { // cleanup current PS tree $fromArchive = $this->_listArchivedFiles($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->restoreFilesFilename); foreach ($fromArchive as $k => $v) { $fromArchive[$k] = '/' . $v; } file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->fromArchiveFileList, serialize($fromArchive)); // get list of files to remove $toRemove = $this->_listFilesToRemove(); $this->nextQuickInfo[] = sprintf($this->l('%s file(s) will be removed before restoring backup files'), count($toRemove)); file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toRemoveFileList, serialize($toRemove)); if ($fromArchive === false || $toRemove === false) { if (!$fromArchive) { $this->nextQuickInfo[] = '[ERROR] ' . sprintf($this->l('backup file %s does not exists'), $this->fromArchiveFileList); } if (!$toRemove) { $this->nextQuickInfo[] = '[ERROR] ' . sprintf($this->l('file "%s" does not exists'), $this->toRemoveFileList); } $this->nextDesc = $this->l('Unable to remove upgraded files.'); $this->next = 'error'; return false; } } // first restoreFiles step if (!isset($toRemove)) { $toRemove = unserialize(file_get_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toRemoveFileList)); } if (count($toRemove) > 0) { for ($i = 0; $i < self::$loopRemoveUpgradedFiles; $i++) { if (count($toRemove) <= 0) { $this->stepDone = true; $this->status = 'ok'; $this->next = 'restoreFiles'; $this->nextDesc = $this->l('Files from upgrade has been removed.'); $this->nextQuickInfo[] = $this->l('files from upgrade has been removed.'); file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toRemoveFileList, serialize($toRemove)); return true; } else { $filename = array_shift($toRemove); $file = rtrim($this->prodRootDir, DIRECTORY_SEPARATOR) . $filename; if (file_exists($file)) { if (is_file($file) && @unlink($file)) { $this->nextQuickInfo[] = sprintf('%s removed', $filename); } else { if (!file_exists($file)) { $this->nextQuickInfo[] = sprintf('[NOTICE] %s does not exists', $filename); } elseif (is_dir($file)) { Tools::deleteDirectory($file, true); $this->nextQuickInfo[] = sprintf('[NOTICE] %s directory deleted', $filename); } else { $this->next = 'error'; $this->nextDesc = sprintf($this->l('error when removing %1$s'), $filename); $this->nextQuickInfo[] = sprintf($this->l('%s not removed'), $filename); return false; } } } } } file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toRemoveFileList, serialize($toRemove)); $this->nextDesc = sprintf($this->l('%s left to remove'), count($toRemove)); $this->next = 'restoreFiles'; return true; } // very second restoreFiles step : extract backup // if (!isset($fromArchive)) // $fromArchive = unserialize(file_get_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->fromArchiveFileList)); $filepath = $this->autoupgradePath . DIRECTORY_SEPARATOR . $this->restoreFilesFilename; $destExtract = $this->prodRootDir; if ($res = $this->ZipExtract($filepath, $destExtract)) { $this->next = 'restoreDb'; $this->nextDesc = $this->l('Files restored. Now restoring database ...'); // get new file list $this->nextQuickInfo[] = $this->l('Files restored.'); // once it's restored, do not delete the archive file. This has to be done manually // and we do not empty the var, to avoid infinite loop. return true; } else { $this->next = "error"; $this->nextDesc = sprintf($this->l('unable to extract %1$s into %2$s .'), $filepath, $destExtract); return false; } return true; }
public static function tearDownAfterClass() { \Tools::deleteDirectory(_PS_CACHE_DIR_ . 'cldr-test'); }
public function submitImportLang() { global $currentIndex; if (!isset($_FILES['file']['tmp_name']) or !$_FILES['file']['tmp_name']) { $this->_errors[] = Tools::displayError('No file selected'); } else { include_once PS_ADMIN_DIR . '/../tools/pear/PEAR.php'; include_once PS_ADMIN_DIR . '/../tools/tar/Archive_Tar.php'; $gz = new Archive_Tar($_FILES['file']['tmp_name'], true); $iso_code = str_replace('.gzip', '', $_FILES['file']['name']); if (Validate::isLangIsoCode($iso_code)) { $files_list = $gz->listContent(); $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; if ($gz->extract($sandbox, false)) { foreach ($files_list as $file2check) { //don't validate index.php, will be overwrite when extract in translation directory if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php') { continue; } if (preg_match('@^[0-9a-z-_/\\\\]+\\.php$@i', $file2check['filename'])) { if (!AdminTranslations::checkTranslationFile(file_get_contents($sandbox . $file2check['filename']))) { $this->_errors[] = sprintf(Tools::displayError('Validation failed for: %s'), $file2check['filename']); } } elseif (is_file($sandbox . $file2check['filename']) && !preg_match('@^[0-9a-z-_/\\\\]+\\.(html|tpl|txt)$@i', $file2check['filename'])) { $this->_errors[] = sprintf(Tools::displayError('Unidentified file found: %s'), $file2check['filename']); } } Tools::deleteDirectory($sandbox, true); } if (count($this->_errors)) { return false; } if ($gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) { $this->checkAndAddMailsFiles($iso_code, $files_list); if (Validate::isLanguageFileName($_FILES['file']['name'])) { if (!Language::checkAndAddLanguage($iso_code)) { $conf = 20; } } Tools::redirectAdmin($currentIndex . '&conf=' . (isset($conf) ? $conf : '15') . '&token=' . $this->token); } else { $this->_errors[] = Tools::displayError('Archive cannot be extracted.'); } } else { $this->_errors[] = Tools::displayError('Iso code invalid'); } } }
public function uninstall() { $id_tab = Configuration::get('PS_AUTOUPDATE_MODULE_IDTAB'); if ($id_tab) { $tab = new Tab($id_tab, 1); $res = $tab->delete(); } else { $res = true; } // for people in 1.4.4.0 or 1.4.4.1, we have to remove that file // and of course delete it in the database. if (file_exists(_PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'tabs' . 'AdminUpgrade.php')) { if ($idOldTab = Tab::getIdFromClassName('AdminUpgrade')) { $tab = new Tab($idOldTab); $res &= $tab->delete(); } $res &= unlink(_PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'tabs' . 'AdminUpgrade.php'); } // if the function does not exists, ignore it // (there is no return value in Tools::deleteDirectory) if (method_exists('Tools', 'deleteDirectory')) { Tools::deleteDirectory(_PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'autoupgrade', false); } if (!$res or !parent::uninstall()) { return false; } return true; }
public function submitImportLang() { if (!isset($_FILES['file']['tmp_name']) || !$_FILES['file']['tmp_name']) { $this->errors[] = $this->trans('No file has been selected.', array(), 'Admin.Notifications.Error'); } else { $gz = new \Archive_Tar($_FILES['file']['tmp_name'], true); $filename = $_FILES['file']['name']; $iso_code = str_replace(array('.tar.gz', '.gzip'), '', $filename); if (Validate::isLangIsoCode($iso_code)) { $themes_selected = Tools::getValue('theme', array(self::DEFAULT_THEME_NAME)); $files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent()); $files_paths = AdminTranslationsController::filesListToPaths($files_list); $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR; if ($gz->extractList($files_paths, $sandbox)) { foreach ($files_list as $file2check) { //don't validate index.php, will be overwrite when extract in translation directory if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php') { continue; } if (preg_match('@^[0-9a-z-_/\\\\]+\\.php$@i', $file2check['filename'])) { if (!@filemtime($sandbox . $file2check['filename']) || !AdminTranslationsController::checkTranslationFile(file_get_contents($sandbox . $file2check['filename']))) { $this->errors[] = sprintf($this->trans('Validation failed for: %s', array(), 'Admin.International.Notification'), $file2check['filename']); } } elseif (!preg_match('@mails[0-9a-z-_/\\\\]+\\.(html|tpl|txt)$@i', $file2check['filename'])) { $this->errors[] = sprintf($this->trans('Unidentified file found: %s', array(), 'Admin.International.Notification'), $file2check['filename']); } } Tools::deleteDirectory($sandbox, true); } $i = 0; $tmp_array = array(); foreach ($files_paths as $files_path) { $path = dirname($files_path); if (is_dir(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !is_writable(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !in_array($path, $tmp_array)) { $this->errors[] = (!$i++ ? $this->trans('The archive cannot be extracted.', array(), 'Admin.International.Notification') . ' ' : '') . $this->trans('The server does not have permissions for writing.', array(), 'Admin.Notifications.Error') . ' ' . sprintf($this->trans('Please check rights for %s', array(), 'Admin.Notifications.Error'), $path); $tmp_array[] = $path; } } if (count($this->errors)) { return false; } if ($error = $gz->extractList($files_paths, _PS_TRANSLATIONS_DIR_ . '../')) { if (is_object($error) && !empty($error->message)) { $this->errors[] = $this->trans('The archive cannot be extracted.', array(), 'Admin.International.Notification') . ' ' . $error->message; } else { foreach ($files_list as $file2check) { if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php' && file_put_contents(_PS_TRANSLATIONS_DIR_ . '../' . $file2check['filename'], Tools::getDefaultIndexContent())) { continue; } } // Clear smarty modules cache Tools::clearCache(); if (Validate::isLanguageFileName($filename)) { if (!Language::checkAndAddLanguage($iso_code)) { $conf = 20; } else { // Reset cache Language::loadLanguages(); AdminTranslationsController::checkAndAddMailsFiles($iso_code, $files_list); $this->checkAndAddThemesFiles($files_list, $themes_selected); $tab_errors = AdminTranslationsController::addNewTabs($iso_code, $files_list); if (count($tab_errors)) { $this->errors += $tab_errors; return false; } } } //fetch cldr datas for the new imported locale $languageCode = explode('-', Language::getLanguageCodeByIso($iso_code)); $cldrUpdate = new Update(_PS_TRANSLATIONS_DIR_); $cldrUpdate->fetchLocale($languageCode[0] . '-' . strtoupper($languageCode[1])); $this->redirect(false, isset($conf) ? $conf : '15'); } } $this->errors[] = $this->trans('The archive cannot be extracted.', array(), 'Admin.International.Notification'); } else { $this->errors[] = sprintf($this->trans('ISO CODE invalid "%1$s" for the following file: "%2$s"', array(), 'Admin.International.Notification'), $iso_code, $filename); } } }
function psmppropertiesIntegration($vars, $install) { Tools::deleteDirectory($vars['base']); if ($install) { if (file_exists($vars['base'])) { return array('error_delete_directory' => $vars['base']); } mkdir($vars['dirname'], 0755, true); Tools::copy(_PS_MODULE_DIR_ . $vars['module']->name . '/ppsetup.php', $vars['ppsetup']); PSM::protectDirectory($vars['base']); if (!is_file($vars['ppsetup'])) { return array('error_create_file' => $vars['ppsetup']); } } return true; }
/** * 删除文件夹 * * @param $dirname * @param bool $delete_self */ public static function deleteDirectory($dirname, $delete_self = true) { $dirname = rtrim($dirname, '/') . '/'; if (is_dir($dirname)) { $files = scandir($dirname); foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != '.svn') { if (is_dir($dirname . $file)) { Tools::deleteDirectory($dirname . $file, true); } elseif (file_exists($dirname . $file)) { unlink($dirname . $file); } } } if ($delete_self) { rmdir($dirname); } } }
private static function install_theme_files($sandbox) { $xmlFile = $sandbox . '/Config.xml'; $errors = array(); if (!self::checkXmlFields($xmlFile)) { echo "Error, bad xml configuration file {$xmlFile}\n"; return false; } $importedTheme = self::importThemeXmlConfig(simplexml_load_file($xmlFile)); if ($importedTheme === false) { echo "Error, could not install theme\n"; return false; } foreach ($importedTheme as $theme) { if (Validate::isLoadedObject($theme)) { if (!copy($sandbox . '/Config.xml', _PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml')) { $errors[] = "Can't copy configuration file"; } $target_dir = _PS_ALL_THEMES_DIR_ . $theme->directory; if (file_exists($target_dir)) { Tools::deleteDirectory($target_dir); } $theme_doc_dir = $target_dir . '/docs/'; if (file_exists($theme_doc_dir)) { Tools::deleteDirectory($theme_doc_dir); } mkdir($target_dir); mkdir($theme_doc_dir); Tools::recurseCopy($sandbox . '/themes/' . $theme->directory . '/', $target_dir . '/'); Tools::recurseCopy($sandbox . '/doc/', $theme_doc_dir); Tools::recurseCopy($sandbox . '/modules/', _PS_MODULE_DIR_); } else { $errors[] = $theme; } } Tools::deleteDirectory($sandbox); if (!count($errors)) { echo "Sucessfully installed theme files\n"; return true; } else { echo "Error while installing theme files\n"; return false; } }
/** * PROCESS : installFixtures * Install fixtures (E.g. demo products) */ public function installFixtures($entity = null, array $data = array()) { $fixtures_path = _PS_INSTALL_FIXTURES_PATH_ . 'apple/'; $fixtures_name = 'apple'; $zip_file = _PS_ROOT_DIR_ . '/download/fixtures.zip'; $temp_dir = _PS_ROOT_DIR_ . '/download/fixtures/'; // try to download fixtures if no low memory mode if ($entity === null) { if (Tools::copy('http://api.prestashop.com/fixtures/' . $data['shop_country'] . '/' . $data['shop_activity'] . '/fixtures.zip', $zip_file)) { Tools::deleteDirectory($temp_dir, true); if (Tools::ZipTest($zip_file)) { if (Tools::ZipExtract($zip_file, $temp_dir)) { $files = scandir($temp_dir); if (count($files)) { foreach ($files as $file) { if (!preg_match('/^\\./', $file) && is_dir($temp_dir . $file . '/')) { $fixtures_path = $temp_dir . $file . '/'; $fixtures_name = $file; break; } } } } } } } // Load class (use fixture class if one exists, or use InstallXmlLoader) if (file_exists($fixtures_path . '/install.php')) { require_once $fixtures_path . '/install.php'; $class = 'InstallFixtures' . Tools::toCamelCase($fixtures_name); if (!class_exists($class, false)) { $this->setError($this->language->l('Fixtures class "%s" not found', $class)); return false; } $xml_loader = new $class(); if (!$xml_loader instanceof InstallXmlLoader) { $this->setError($this->language->l('"%s" must be an instane of "InstallXmlLoader"', $class)); return false; } } else { $xml_loader = new InstallXmlLoader(); } // Install XML data (data/xml/ folder) $xml_loader->setFixturesPath($fixtures_path); if (isset($this->xml_loader_ids) && $this->xml_loader_ids) { $xml_loader->setIds($this->xml_loader_ids); } $languages = array(); foreach (Language::getLanguages(false) as $lang) { $languages[$lang['id_lang']] = $lang['iso_code']; } $xml_loader->setLanguages($languages); if ($entity) { $xml_loader->populateEntity($entity); } else { $xml_loader->populateFromXmlFiles(); Tools::deleteDirectory($temp_dir, true); @unlink($zip_file); } if ($errors = $xml_loader->getErrors()) { $this->setError($errors); return false; } // IDS from xmlLoader are stored in order to use them for fixtures $this->xml_loader_ids = $xml_loader->getIds(); unset($xml_loader); // Index products in search tables Search::indexation(true); return true; }
public function ajaxProcessSvnExport() { if ($this->useSvn) { // first of all, delete the content of the latest root dir just in case if (is_dir($this->latestRootDir)) { Tools::deleteDirectory($this->latestRootDir, false); } if (!file_exists($this->latestRootDir)) { @mkdir($this->latestRootDir); } if (svn_export($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->svnDir, $this->latestRootDir)) { // export means svn means install-dev and admin-dev. // let's rename admin to the correct admin dir // and rename install-dev to install $adminDir = str_replace($this->prodRootDir, '', $this->adminDir); rename($this->latestRootDir . DIRECTORY_SEPARATOR . 'install-dev', $this->latestRootDir . DIRECTORY_SEPARATOR . 'install'); rename($this->latestRootDir . DIRECTORY_SEPARATOR . 'admin-dev', $this->latestRootDir . DIRECTORY_SEPARATOR . $adminDir); // Unsetting to force listing unset($this->nextParams['removeList']); $this->next = "removeSamples"; $this->nextDesc = $this->l('Export svn complete. removing sample files...'); return true; } else { $this->next = 'error'; $this->nextDesc = $this->l('error when svn export '); } } }
protected static function clearAllCaches() { $index = file_exists(_PS_TMP_IMG_DIR_ . 'index.php') ? file_get_contents(_PS_TMP_IMG_DIR_ . 'index.php') : ''; Tools::deleteDirectory(_PS_TMP_IMG_DIR_, false); file_put_contents(_PS_TMP_IMG_DIR_ . 'index.php', $index); Context::getContext()->smarty->clearAllCache(); }
public function delete() { if (!$this->hasMultishopEntries() || Shop::getContext() == Shop::CONTEXT_ALL) { if (empty($this->iso_code)) { $this->iso_code = Language::getIsoById($this->id); } // Database translations deletion $result = Db::getInstance()->executeS('SHOW TABLES FROM `' . _DB_NAME_ . '`'); foreach ($result as $row) { if (isset($row['Tables_in_' . _DB_NAME_]) && !empty($row['Tables_in_' . _DB_NAME_]) && preg_match('/' . preg_quote(_DB_PREFIX_) . '_lang/', $row['Tables_in_' . _DB_NAME_])) { if (!Db::getInstance()->execute('DELETE FROM `' . $row['Tables_in_' . _DB_NAME_] . '` WHERE `id_lang` = ' . (int) $this->id)) { return false; } } } // Delete tags Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'tag WHERE id_lang = ' . (int) $this->id); // Delete search words Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'search_word WHERE id_lang = ' . (int) $this->id); // Files deletion foreach (Language::getFilesList($this->iso_code, _THEME_NAME_, false, false, false, true, true) as $key => $file) { if (file_exists($key)) { unlink($key); } } $modList = scandir(_PS_MODULE_DIR_); foreach ($modList as $mod) { Tools::deleteDirectory(_PS_MODULE_DIR_ . $mod . '/mails/' . $this->iso_code); $files = @scandir(_PS_MODULE_DIR_ . $mod . '/mails/'); if (count($files) <= 2) { Tools::deleteDirectory(_PS_MODULE_DIR_ . $mod . '/mails/'); } if (file_exists(_PS_MODULE_DIR_ . $mod . '/' . $this->iso_code . '.php')) { unlink(_PS_MODULE_DIR_ . $mod . '/' . $this->iso_code . '.php'); $files = @scandir(_PS_MODULE_DIR_ . $mod); if (count($files) <= 2) { Tools::deleteDirectory(_PS_MODULE_DIR_ . $mod); } } } if (file_exists(_PS_MAIL_DIR_ . $this->iso_code)) { Tools::deleteDirectory(_PS_MAIL_DIR_ . $this->iso_code); } if (file_exists(_PS_TRANSLATIONS_DIR_ . $this->iso_code)) { Tools::deleteDirectory(_PS_TRANSLATIONS_DIR_ . $this->iso_code); } $images = array('.jpg', '-default-' . ImageType::getFormattedName('thickbox') . '.jpg', '-default-' . ImageType::getFormattedName('home') . '.jpg', '-default-' . ImageType::getFormattedName('large') . '.jpg', '-default-' . ImageType::getFormattedName('medium') . '.jpg', '-default-' . ImageType::getFormattedName('small') . '.jpg'); $images_directories = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_); foreach ($images_directories as $image_directory) { foreach ($images as $image) { if (file_exists($image_directory . $this->iso_code . $image)) { unlink($image_directory . $this->iso_code . $image); } if (file_exists(_PS_ROOT_DIR_ . '/img/l/' . $this->id . '.jpg')) { unlink(_PS_ROOT_DIR_ . '/img/l/' . $this->id . '.jpg'); } } } } if (!parent::delete()) { return false; } return true; }
/** * Delete directory and subdirectories * * @param string $dirname Directory name */ public static function deleteDirectory($dirname, $delete_self = true) { $dirname = rtrim($dirname, '/') . '/'; if (file_exists($dirname)) { if ($files = scandir($dirname)) { foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != '.svn') { if (is_dir($dirname . $file)) { Tools::deleteDirectory($dirname . $file, true); } elseif (file_exists($dirname . $file)) { @chmod($dirname . $file, 0777); // NT ? unlink($dirname . $file); } } } if ($delete_self && file_exists($dirname)) { if (!rmdir($dirname)) { @chmod($dirname, 0777); // NT ? return false; } } return true; } } return false; }
/** * PROCESS : installFixtures * Install fixtures (E.g. demo products) */ public function installFixtures($entity = null, array $data = array()) { $fixtures_path = _PS_INSTALL_FIXTURES_PATH_ . 'fashion/'; $fixtures_name = 'fashion'; $zip_file = _PS_ROOT_DIR_ . '/download/fixtures.zip'; $temp_dir = _PS_ROOT_DIR_ . '/download/fixtures/'; // Load class (use fixture class if one exists, or use InstallXmlLoader) if (file_exists($fixtures_path . '/install.php')) { require_once $fixtures_path . '/install.php'; $class = 'InstallFixtures' . Tools::toCamelCase($fixtures_name); if (!class_exists($class, false)) { $this->setError($this->translator->trans('Fixtures class "%class%" not found', array('%class%' => $class), 'Install')); return false; } $xml_loader = new $class(); if (!$xml_loader instanceof InstallXmlLoader) { $this->setError($this->translator->trans('"%class%" must be an instance of "InstallXmlLoader"', array('%class%' => $class), 'Install')); return false; } } else { $xml_loader = new InstallXmlLoader(); } // Install XML data (data/xml/ folder) $xml_loader->setFixturesPath($fixtures_path); if (isset($this->xml_loader_ids) && $this->xml_loader_ids) { $xml_loader->setIds($this->xml_loader_ids); } $languages = array(); foreach (Language::getLanguages(false) as $lang) { $languages[$lang['id_lang']] = $lang['iso_code']; } $xml_loader->setLanguages($languages); if ($entity) { $xml_loader->populateEntity($entity); } else { $xml_loader->populateFromXmlFiles(); Tools::deleteDirectory($temp_dir, true); @unlink($zip_file); } if ($errors = $xml_loader->getErrors()) { $this->setError($errors); return false; } // IDS from xmlLoader are stored in order to use them for fixtures $this->xml_loader_ids = $xml_loader->getIds(); unset($xml_loader); // Index products in search tables Search::indexation(true); return true; }