Example #1
0
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 public function __construct()
 {
     session_name('install_' . md5($_SERVER['HTTP_HOST']));
     $session_started = session_start();
     if (!$session_started || !isset($_SESSION['session_mode']) && (isset($_GET['_']) || isset($_POST['submitNext']) || isset($_POST['submitPrevious']) || isset($_POST['language']))) {
         InstallSession::$_cookie_mode = true;
         InstallSession::$_cookie = new Cookie('ps_install', null, time() + 7200, null, true);
     }
     if ($session_started && !isset($_SESSION['session_mode'])) {
         $_SESSION['session_mode'] = 'session';
         session_write_close();
     }
 }
Example #3
0
 /**
  * PROCESS : installModules
  * Download module from addons and Install all modules in ~/modules/ directory
  */
 public function installModulesAddons($module = null)
 {
     $addons_modules = $module ? array($module) : $this->getAddonsModulesList();
     $modules = array();
     if (!InstallSession::getInstance()->safe_mode) {
         foreach ($addons_modules as $addons_module) {
             if (file_put_contents(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip', Tools::addonsRequest('module', array('id_module' => $addons_module['id_module'])))) {
                 if (Tools::ZipExtract(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip', _PS_MODULE_DIR_)) {
                     $modules[] = (string) $addons_module['name'];
                     //if the module has been unziped we add the name in the modules list to install
                     unlink(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip');
                 }
             }
         }
     }
     return count($modules) ? $this->installModules($modules) : true;
 }
Example #4
0
 /**
  * Get telephone used for this language
  *
  * @return string
  */
 public function getPhone()
 {
     if (InstallSession::getInstance()->support_phone != null) {
         return InstallSession::getInstance()->support_phone;
     }
     if ($this->phone === null) {
         $this->phone = $this->language->getInformation('phone', false);
         if ($iframe = Tools::file_get_contents('http://api.prestashop.com/iframe/install.php?lang=' . $this->language->getLanguageIso(), false, null, 3)) {
             if (preg_match('/<img.+alt="([^"]+)".*>/Ui', $iframe, $matches) && isset($matches[1])) {
                 $this->phone = $matches[1];
             }
         }
     }
     InstallSession::getInstance()->support_phone = $this->phone;
     return $this->phone;
 }
Example #5
0
 /**
  * PROCESS : installModules
  * Download module from addons and Install all modules in ~/modules/ directory
  */
 public function installModules($module = null)
 {
     $modules = $module ? array($module) : $this->getModulesList();
     if (!InstallSession::getInstance()->safe_mode) {
         $addons_modules = $this->getAddonsModulesList();
         foreach ($addons_modules as $addons_module) {
             if (file_put_contents(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip', Tools::addonsRequest('module', array('id_module' => $addons_module['id_module'])))) {
                 if (Tools::ZipExtract(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip', _PS_MODULE_DIR_)) {
                     $modules[] = (string) $addons_module['name'];
                     //if the module has been unziped we add the name in the modules list to install
                     unlink(_PS_MODULE_DIR_ . $addons_module['name'] . '.zip');
                 }
             }
         }
     }
     $errors = array();
     foreach ($modules as $module_name) {
         if (!file_exists(_PS_MODULE_DIR_ . $module_name . '/' . $module_name . '.php')) {
             continue;
         }
         $module = Module::getInstanceByName($module_name);
         if (!$module->install()) {
             $errors[] = $this->language->l('Cannot install module "%s"', $module_name);
         }
     }
     if ($errors) {
         $this->setError($errors);
         return false;
     }
     return true;
 }
 public final function __construct($step)
 {
     $this->step = $step;
     $this->session = InstallSession::getInstance();
     // Set current language
     $this->language = InstallLanguages::getInstance();
     $detect_language = $this->language->detectLanguage();
     if (isset($this->session->lang)) {
         $lang = $this->session->lang;
     } else {
         $lang = isset($detect_language['primarytag']) ? $detect_language['primarytag'] : false;
     }
     if (!in_array($lang, $this->language->getIsoList())) {
         $lang = 'en';
     }
     $this->language->setLanguage($lang);
     $this->init();
 }
Example #7
0
 /**
  * Install languages
  *
  * @return array Association between ID and iso array(id_lang => iso, ...)
  */
 public function installLanguages($languages_list = null)
 {
     if ($languages_list == null || !is_array($languages_list) || !count($languages_list)) {
         $languages_list = $this->language->getIsoList();
     }
     $languages_available = $this->language->getIsoList();
     $languages = array();
     foreach ($languages_list as $iso) {
         if (!in_array($iso, $languages_available)) {
             continue;
         }
         if (!file_exists(_PS_INSTALL_LANGS_PATH_ . $iso . '/language.xml')) {
             throw new PrestashopInstallerException($this->translator->trans('File "language.xml" not found for language iso "%iso%"', array('%iso%' => $iso), 'Install'));
         }
         if (!($xml = @simplexml_load_file(_PS_INSTALL_LANGS_PATH_ . $iso . '/language.xml'))) {
             throw new PrestashopInstallerException($this->translator->trans('File "language.xml" not valid for language iso "%iso%"', array('%iso%' => $iso), 'Install'));
         }
         $params_lang = array('name' => (string) $xml->name, 'iso_code' => substr((string) $xml->language_code, 0, 2), 'allow_accented_chars_url' => (string) $xml->allow_accented_chars_url, 'language_code' => (string) $xml->language_code, 'locale' => (string) $xml->locale);
         if (InstallSession::getInstance()->safe_mode) {
             Language::checkAndAddLanguage($iso, false, true, $params_lang);
         } else {
             if (file_exists(_PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip') == false) {
                 $language = Language::downloadLanguagePack($iso, _PS_INSTALL_VERSION_);
                 if ($language == false) {
                     throw new PrestashopInstallerException($this->translator->trans('Cannot download language pack "%iso%"', array('%iso%' => $iso), 'Install'));
                 }
             }
             Language::installLanguagePack($iso, $params_lang, $errors);
         }
         Language::loadLanguages();
         Tools::clearCache();
         if (!($id_lang = Language::getIdByIso($iso, true))) {
             throw new PrestashopInstallerException($this->translator->trans('Cannot install language "%iso%"', array('%iso%' => $xml->name ? $xml->name : $iso), 'Install'));
         }
         $languages[$id_lang] = $iso;
         // Copy language flag
         if (is_writable(_PS_IMG_DIR_ . 'l/')) {
             if (!copy(_PS_INSTALL_LANGS_PATH_ . $iso . '/flag.jpg', _PS_IMG_DIR_ . 'l/' . $id_lang . '.jpg')) {
                 throw new PrestashopInstallerException($this->translator->trans('Cannot copy flag language "%flag%"', array('%flag%' => _PS_INSTALL_LANGS_PATH_ . $iso . '/flag.jpg => ' . _PS_IMG_DIR_ . 'l/' . $id_lang . '.jpg')));
             }
         }
     }
     return $languages;
 }