public function install() { set_time_limit(0); if (version_compare(phpversion(), '5.3', '<')) { $this->_errors[] = sprintf($this->l('Requres PHP version %s or above. Currently running PHP %s version.'), '5.3', phpversion()); return false; } psmHelperIntegrate(array($this->name)); Tools::deleteFile(_PS_ROOT_DIR_ . '/classes/PP.php'); if (!psmIntegrateCore($this, dirname(__FILE__) . '/psm.php', $this->_errors) || !psmIntegrateCore($this, dirname(__FILE__) . '/PP.php', $this->_errors, 'PP_VERSION[')) { return false; } if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } $setup = $this->setupInstance(); $setup->cleanupOverriddenFiles(); if (!parent::install() || !$setup->installAdminTab('AdminPproperties')) { return false; } if (!$this->registerHook('displayNav') || !$this->registerHook('displayHeader') || !$this->registerHook('displayFooter') || !$this->registerHook('displayProductPriceBlock') || !$this->registerHook('displayPpropertiesProduct') || !$this->registerHook('displayBackOfficeHeader') || !$this->registerHook('displayAdminProductsExtra') || !$this->registerHook('displayProductsListLeadin') || !$this->registerHook('actionModuleInstallAfter') || !$this->registerHook('actionModuleUpgradeAfter') || !$this->registerHook('actionProductAdd') || !$this->registerHook('actionProductUpdate') || !$this->registerHook('actionProductDelete') || !$this->registerHook('actionProductAttributeDelete') || !$this->registerHook('actionObjectCombinationDeleteAfter')) { return false; } if ((int) Configuration::get('PP_MEASUREMENT_SYSTEM') == 0) { $w = Configuration::get('PS_WEIGHT_UNIT'); Configuration::updateValue('PP_MEASUREMENT_SYSTEM', Tools::strtolower($w) == 'lb' ? 2 : 1); } if (!Configuration::hasKey('PP_POWEREDBY')) { Configuration::updateValue('PP_POWEREDBY', 1); } if (!Configuration::hasKey('PP_TEMPLATE_NAME_IN_CATALOG')) { Configuration::updateValue('PP_TEMPLATE_NAME_IN_CATALOG', 1); } Configuration::updateValue('PP_INSTALL_TIME', time()); $setup->install(); Configuration::deleteByName('PP_LAST_VERSION'); Configuration::updateValue('PP_VERSION', $this->version); psmClearCache(); return true; }
public static function log() { static $file = null; if ($file === null) { $file = _PS_ROOT_DIR_ . '/log/psm.log'; if (self::$append === null) { self::$append = Tools::getValue('ajax') || Configuration::get('PSM_LOG'); } if (!self::$append) { Tools::deleteFile($file); } } $formatted_message = '----------------------------- ' . date('Y/m/d - H:i:s') . PHP_EOL; foreach (func_get_args() as $message) { if (!is_string($message)) { if (is_bool($message)) { $message = $message ? 'true' : 'false'; } elseif ($message === null) { $message = 'null'; } else { $message = print_r($message, true); } } $formatted_message .= $message . PHP_EOL; } file_put_contents($file, $formatted_message, FILE_APPEND); }
public static function clearCache() { foreach (array(_PS_THEME_DIR_ . 'cache') as $dir) { if (file_exists($dir)) { foreach (scandir($dir) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile($dir . DIRECTORY_SEPARATOR . $file, array('index.php')); } } } } $version = (int) Configuration::get('PS_CCCJS_VERSION'); Configuration::updateValue('PS_CCCJS_VERSION', ++$version); $version = (int) Configuration::get('PS_CCCCSS_VERSION'); Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); }
/** * PROCESS : configureShop * Set default shop configuration */ public function configureShop(array $data = array()) { //clear image cache in tmp folder if (file_exists(_PS_TMP_IMG_DIR_)) { foreach (scandir(_PS_TMP_IMG_DIR_) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file); } } } $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(); // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation if (InstallSession::getInstance()->safe_mode) { Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1); } $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->default_tab = 1; $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; }
/** * PROCESS : configureShop * Set default shop configuration */ public function configureShop(array $data = array()) { //clear image cache in tmp folder if (file_exists(_PS_TMP_IMG_DIR_)) { foreach (scandir(_PS_TMP_IMG_DIR_) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file); } } } $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_encryption' => 'off', 'smtp_port' => 25, 'rewrite_engine' => false); foreach ($default_data as $k => $v) { if (!isset($data[$k])) { $data[$k] = $v; } } Context::getContext()->shop = new Shop(1); Configuration::loadConfiguration(); // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation if (InstallSession::getInstance()->safe_mode) { Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1); } $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_SMTP_ENCRYPTION', $data['smtp_encryption']); Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']); // Set default rewriting settings Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', $data['rewrite_engine']); // Activate rijndael 128 encrypt algorihtm if mcrypt is activated Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0); $groups = Group::getGroups((int) Configuration::get('PS_LANG_DEFAULT')); $groups_default = Db::getInstance()->executeS('SELECT `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_%_GROUP" ORDER BY `id_configuration`'); foreach ($groups_default as &$group_default) { if (is_array($group_default) && isset($group_default['name'])) { $group_default = $group_default['name']; } } if (is_array($groups) && count($groups)) { foreach ($groups as $key => $group) { if (Configuration::get($groups_default[$key]) != $groups[$key]['id_group']) { Configuration::updateGlobalValue($groups_default[$key], (int) $groups[$key]['id_group']); } } } $states = Db::getInstance()->executeS('SELECT `id_order_state` FROM ' . _DB_PREFIX_ . 'order_state ORDER by `id_order_state`'); $states_default = Db::getInstance()->executeS('SELECT MIN(`id_configuration`), `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_OS_%" GROUP BY `value` ORDER BY`id_configuration`'); foreach ($states_default as &$state_default) { if (is_array($state_default) && isset($state_default['name'])) { $state_default = $state_default['name']; } } if (is_array($states) && count($states)) { foreach ($states as $key => $state) { if (Configuration::get($states_default[$key]) != $states[$key]['id_order_state']) { Configuration::updateGlobalValue($states_default[$key], (int) $states[$key]['id_order_state']); } } /* deprecated order state */ Configuration::updateGlobalValue('PS_OS_OUTOFSTOCK_PAID', (int) Configuration::get('PS_OS_OUTOFSTOCK')); } // 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)); } // Disable cache for debug mode if (_PS_MODE_DEV_) { Configuration::updateGlobalValue('PS_SMARTY_CACHE', 1); } // 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 = $this->getLocalizationPackContent($version, $data['shop_country']); $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->default_tab = 1; $employee->active = true; $employee->optin = (bool) $data['send_informations']; $employee->id_profile = 1; $employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->bo_menu = 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 PrestaShopCollection('Contact'); foreach ($contacts as $contact) { $contact->email = $data['admin_email']; $contact->update(); } } if (!@Tools::generateHtaccess(null, $data['rewrite_engine'])) { Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', 0); } return true; }
/** * Return if the module is provided by addons.prestashop.com or not * * @param string $name The module name (the folder name) * @param string $key The key provided by addons * @return integer */ public static final function isModuleTrusted($module_name) { static $trusted_modules_list_content = null; static $modules_list_content = null; static $default_country_modules_list_content = null; static $untrusted_modules_list_content = null; $context = Context::getContext(); // If the xml file exist, isn't empty, isn't too old // and if the theme hadn't change // we use the file, otherwise we regenerate it if (!(file_exists(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) && filesize(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) > 0 && time() - filemtime(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) < 86400)) { self::generateTrustedXml(); } if ($trusted_modules_list_content === null) { $trusted_modules_list_content = Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST); if (strpos($trusted_modules_list_content, $context->theme->name) === false) { self::generateTrustedXml(); } } if ($modules_list_content === null) { $modules_list_content = Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_MODULES_LIST); } if ($default_country_modules_list_content === null) { $default_country_modules_list_content = Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST); } if ($untrusted_modules_list_content === null) { $untrusted_modules_list_content = Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_UNTRUSTED_MODULES_LIST); } // If the module is trusted, which includes both partner modules and modules bought on Addons if (strpos($trusted_modules_list_content, $module_name) !== false) { // If the module is not a partner, then return 1 (which means the module is "trusted") if (strpos($modules_list_content, '<module name="' . $module_name . '"/>') == false) { return 1; } elseif (strpos($default_country_modules_list_content, '<name><![CDATA[' . $module_name . ']]></name>') !== false) { return 1; } // The module seems to be trusted, but it does not seem to be dedicated to this country return 2; } elseif (strpos($untrusted_modules_list_content, $module_name) !== false) { return 0; } else { // If the module isn't in one of the xml files // It might have been uploaded recenlty so we check // Addons API and clear XML files to be regenerated next time Tools::deleteFile(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST); Tools::deleteFile(_PS_ROOT_DIR_ . self::CACHE_FILE_UNTRUSTED_MODULES_LIST); return (int) Module::checkModuleFromAddonsApi($module_name); } }
public function addAsTrusted() { if (defined('self::CACHE_FILE_TRUSTED_MODULES_LIST') == true) { if (isset($this->context->controller->controller_name) && $this->context->controller->controller_name == 'AdminModules') { $sxe = new SimpleXMLElement('<theme/>'); $modules = $sxe->addChild('modules'); $module = $modules->addChild('module'); $module->addAttribute('action', 'install'); $module->addAttribute('name', $this->name); $trusted = $sxe->saveXML(); file_put_contents(_PS_ROOT_DIR_ . '/config/xml/themes/' . $this->name . '.xml', $trusted); if (is_file(_PS_ROOT_DIR_ . Module::CACHE_FILE_UNTRUSTED_MODULES_LIST)) { Tools::deleteFile(_PS_ROOT_DIR_ . Module::CACHE_FILE_UNTRUSTED_MODULES_LIST); } } } }
private function restoreFile($file) { if (is_file($file)) { $dir = self::getBackupDirectory(); $rel_file = str_replace(_PS_ROOT_DIR_, '', $file); $backup_file = $dir . $rel_file; if (is_file($backup_file)) { Tools::copy($backup_file, $file); $timestamp = filemtime($backup_file); if ($timestamp !== false) { touch($file, $timestamp); } Tools::deleteFile($backup_file); } } }
function psmDownloadModule($module_name) { $success = false; if (!is_dir(_PS_MODULE_DIR_ . $module_name)) { $content = Tools::file_get_contents('http://store.psandmore.com/query/download.php?ps=' . _PS_VERSION_ . '&module=' . $module_name); if ($content) { $zip_file = _PS_MODULE_DIR_ . $module_name . '.zip'; Tools::deleteFile($zip_file); if (file_put_contents($zip_file, $content) !== false) { if (Tools::ZipTest($zip_file)) { $success = Tools::ZipExtract($zip_file, _PS_MODULE_DIR_); } Tools::deleteFile($zip_file); } } } return $success; }
/** * Return if the module is provided by addons.prestashop.com or not * * @param string $name The module name (the folder name) * @param string $key The key provided by addons * @return boolean */ public static function isModuleTrusted($module_name) { $context = Context::getContext(); $theme = new Theme($context->shop->id_theme); // If the xml file exist, isn't empty, isn't too old // and if the theme hadn't change // we use the file, otherwise we regenerate it if (!(file_exists(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) && filesize(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) > 0 && time() - filemtime(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST) < 86400 && strstr(Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST), $theme->name))) { self::generateTrustedXml(); } if (strstr(Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST), $module_name)) { return true; } elseif (strstr(Tools::file_get_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_UNTRUSTED_MODULES_LIST), $module_name)) { return false; } else { // If the module isn't in one of the xml files // It might have been uploaded recenlty so we check // Addons API and clear XML files to be regenerated next time Tools::deleteFile(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST); Tools::deleteFile(_PS_ROOT_DIR_ . self::CACHE_FILE_UNTRUSTED_MODULES_LIST); return Module::checkModuleFromAddonsApi($module_name); } }
public static function clearCache() { foreach (array(_PS_THEME_DIR_ . 'cache') as $dir) { if (file_exists($dir)) { foreach (scandir($dir) as $file) { if ($file[0] != '.' && $file != 'index.php') { Tools::deleteFile($dir . DIRECTORY_SEPARATOR . $file, array('index.php')); } } } } }
$files_added[] = $filename; } } } } // Close $zip->close(); echo $nb_files_added . ' index added. <br />'; echo '<ul>'; foreach ($files_added as $file_added) { echo '<li>' . $file_added . '</li>'; } echo '</ul>'; echo '<a href="download.php?uniqid=' . $uniqid . '&filename=' . $zip_name . '" target="_blank">[download]</a> - <a href="index.php?deleteZip=1&uniqid=' . $uniqid . '">[delete]</a><br /><br />------<br /><br />'; } else { throw new ApplicationException('Error. ' . Zip::displayError((int) $result_code)); } } elseif (Tools::isSubmit('deleteZip')) { $uniqid = Tools::getValue('uniqid', 0); if ($uniqid) { Tools::deleteFile(dirname(__FILE__) . '/tmp/' . $uniqid . '.zip'); } } } catch (ApplicationException $ex) { if ($uniqid !== false) { Tools::deleteFile(dirname(__FILE__) . '/tmp/' . $uniqid . '.zip'); } $ex->displayMessage(); } // Show form include_once 'form.php';