本文整理汇总了PHP中Language::checkAndAddLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::checkAndAddLanguage方法的具体用法?PHP Language::checkAndAddLanguage怎么用?PHP Language::checkAndAddLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::checkAndAddLanguage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAndAddLang
public function checkAndAddLang($languages, $add = true)
{
$errors = '';
$moduleName = Tools::getValue('moduleName');
$this->alterTable('language');
foreach ($languages as $language) {
$iso = $language['iso_code'];
if (!Language::isInstalled($iso)) {
if ($add) {
if (@fsockopen('www.prestashop.com', 80)) {
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $iso))) {
if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $iso . '.gzip')) {
$file = _PS_TRANSLATIONS_DIR_ . $iso . '.gzip';
if (file_put_contents($file, $content)) {
require_once '../../tools/tar/Archive_Tar.php';
$gz = new Archive_Tar($file, true);
if ($gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
if (!Language::checkAndAddLanguage($iso)) {
$errors[] = $this->l('Archive cannot be extracted.');
} else {
$newId = Language::getIdByIso($iso);
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'lang`
SET `id_lang_' . bqSQL($moduleName) . '` = ' . (int) $language['id_lang'] . '
WHERE `id_lang` = ' . (int) $newId);
}
}
$errors[] = $this->l('Archive cannot be extracted.');
} else {
$errors[] = $this->l('Server does not have permissions for writing.');
}
} else {
$errors[] = $this->l('Language not found');
}
} else {
$errors[] = $this->l('archive cannot be downloaded from prestashop.com.');
}
} else {
$errors[] = $this->l('archive cannot be downloaded from prestashop.com.');
}
}
} else {
$newId = Language::getIdByIso($iso);
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'lang`
SET `id_lang_' . bqSQL($moduleName) . '` = ' . (int) $language['id_lang'] . '
WHERE `id_lang` = ' . (int) $newId);
}
}
}
示例2: submitAddLang
public function submitAddLang()
{
global $currentIndex;
$arr_import_lang = explode('|', Tools::getValue('params_import_language'));
/* 0 = Language ISO code, 1 = PS version */
if (Validate::isLangIsoCode($arr_import_lang[0])) {
if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . $arr_import_lang[0] . '.gzip', false, @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5))))) {
$file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
if (file_put_contents($file, $content)) {
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
if ($gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$this->checkAndAddMailsFiles($arr_import_lang[0], $files_list);
if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
$conf = 20;
}
if (!unlink($file)) {
$this->_errors[] = Tools::displayError('Cannot delete archive');
}
Tools::redirectAdmin($currentIndex . '&conf=' . (isset($conf) ? $conf : '15') . '&token=' . $this->token);
}
$this->_errors[] = Tools::displayError('Archive cannot be extracted.');
if (!unlink($file)) {
$this->_errors[] = Tools::displayError('Cannot delete archive');
}
} else {
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
} else {
$this->_errors[] = Tools::displayError('Language not found');
}
} else {
$this->_errors[] = Tools::displayError('Invalid parameter');
}
}
示例3: _installLanguages
protected function _installLanguages($xml, $install_mode = false)
{
$attributes = array();
if (isset($xml->languages->language)) {
foreach ($xml->languages->language as $data) {
$attributes = $data->attributes();
if (Language::getIdByIso($attributes['iso_code'])) {
continue;
}
$native_lang = Language::getLanguages();
$native_iso_code = array();
foreach ($native_lang as $lang) {
$native_iso_code[] = $lang['iso_code'];
}
if (in_array((string) $attributes['iso_code'], $native_iso_code) and !$install_mode or !in_array((string) $attributes['iso_code'], $native_iso_code)) {
$errno = 0;
}
$errstr = '';
if (@fsockopen('www.prestashop.com', 80, $errno, $errstr, 10)) {
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $attributes['iso_code']))) {
if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $attributes['iso_code'] . '.gzip')) {
$file = _PS_TRANSLATIONS_DIR_ . $attributes['iso_code'] . '.gzip';
if (file_put_contents($file, $content)) {
$gz = new Archive_Tar($file, true);
if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$this->_errors[] = Tools::displayError('Cannot decompress the translation file of the language: ') . (string) $attributes['iso_code'];
return false;
}
if (!Language::checkAndAddLanguage((string) $attributes['iso_code'])) {
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $attributes['iso_code'];
return false;
}
@unlink($file);
} else {
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
}
} else {
$this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
}
} else {
$this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
}
}
}
// change the default language if there is only one language in the localization pack
if (!sizeof($this->_errors) and $install_mode and isset($attributes['iso_code']) and sizeof($xml->languages->language) == 1) {
$this->iso_code_lang = $attributes['iso_code'];
}
return true;
}
示例4: installLanguages
/**
* 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 = array();
foreach ($languages_list as $iso) {
if (!file_exists(_PS_INSTALL_LANGS_PATH_ . $iso . '/language.xml')) {
throw new PrestashopInstallerException($this->language->l('File "language.xml" not found for language iso "%s"', $iso));
}
if (!($xml = @simplexml_load_file(_PS_INSTALL_LANGS_PATH_ . $iso . '/language.xml'))) {
throw new PrestashopInstallerException($this->language->l('File "language.xml" not valid for language iso "%s"', $iso));
}
$params_lang = array('name' => (string) $xml->name, 'iso_code' => substr((string) $xml->language_code, 0, 2));
if (InstallSession::getInstance()->safe_mode) {
Language::checkAndAddLanguage($iso, false, true, $params_lang);
} else {
Language::downloadAndInstallLanguagePack($iso, _PS_INSTALL_VERSION_, $params_lang);
}
if (!($id_lang = Language::getIdByIso($iso))) {
throw new PrestashopInstallerException($this->language->l('Cannot install language "%s"', $xml->name ? $xml->name : $iso));
}
$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->language->l('Cannot copy flag language "%s"', _PS_INSTALL_LANGS_PATH_ . $iso . '/flag.jpg => ' . _PS_IMG_DIR_ . 'l/' . $id_lang . '.jpg'));
}
}
}
return $languages;
}
示例5: downloadAndInstallLanguagePack
public static function downloadAndInstallLanguagePack($iso, $version = null, $params = null, $install = true)
{
if (!Validate::isLanguageIsoCode((string) $iso)) {
return false;
}
if ($version == null) {
$version = _PS_VERSION_;
}
$lang_pack = false;
$lang_pack_ok = false;
$errors = array();
$file = _PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip';
if (!($lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $version . '&iso_lang=' . Tools::strtolower((string) $iso)))) {
$errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
} elseif (!($lang_pack = Tools::jsonDecode($lang_pack_link))) {
$errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
} elseif (empty($lang_pack->error) && ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . Tools::strtolower($lang_pack->iso_code . '.gzip')))) {
if (!@file_put_contents($file, $content)) {
if (is_writable(dirname($file))) {
@unlink($file);
@file_put_contents($file, $content);
} elseif (!is_writable($file)) {
$errors[] = Tools::displayError('Server does not have permissions for writing.') . ' (' . $file . ')';
}
}
}
if (!file_exists($file)) {
$errors[] = Tools::displayError('No language pack is available for your version.');
} elseif ($install) {
require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php';
$gz = new Archive_Tar($file, true);
$files_list = AdminTranslationsController::filterTranslationFiles(Language::getLanguagePackListContent((string) $iso, $gz));
$files_paths = AdminTranslationsController::filesListToPaths($files_list);
$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)) {
$errors[] = (!$i++ ? Tools::displayError('The archive cannot be extracted.') . ' ' : '') . Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check rights for %s'), $path);
$tmp_array[] = $path;
}
}
if (defined('_PS_HOST_MODE_')) {
$mails_files = array();
$other_files = array();
foreach ($files_list as $key => $data) {
if (substr($data['filename'], 0, 5) == 'mails') {
$mails_files[] = $data;
} else {
$other_files[] = $data;
}
}
$files_list = $other_files;
}
if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
$errors[] = sprintf(Tools::displayError('Cannot decompress the translation file for the following language: %s'), (string) $iso);
}
// Clear smarty modules cache
Tools::clearCache();
if (!Language::checkAndAddLanguage((string) $iso, $lang_pack, false, $params)) {
$errors[] = sprintf(Tools::displayError('An error occurred while creating the language: %s'), (string) $iso);
} else {
// Reset cache
Language::loadLanguages();
AdminTranslationsController::checkAndAddMailsFiles((string) $iso, $files_list);
AdminTranslationsController::addNewTabs((string) $iso, $files_list);
}
}
return count($errors) ? $errors : true;
}
示例6: _installLanguages
protected function _installLanguages($xml, $install_mode = false)
{
$attributes = array();
if (isset($xml->languages->language)) {
foreach ($xml->languages->language as $data) {
$attributes = $data->attributes();
if (Language::getIdByIso($attributes['iso_code'])) {
continue;
}
$native_lang = Language::getLanguages();
$native_iso_code = array();
foreach ($native_lang as $lang) {
$native_iso_code[] = $lang['iso_code'];
}
// if we are not in an installation context or if the pack is not available in the local directory
if (!$install_mode || !in_array((string) $attributes['iso_code'], $native_iso_code)) {
$errno = 0;
$errstr = '';
if (!@fsockopen('api.prestashop.com', 80, $errno, $errstr, 5)) {
$this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
} elseif (!($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $attributes['iso_code'])))) {
$this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
} elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $attributes['iso_code'] . '.gzip')) {
$file = _PS_TRANSLATIONS_DIR_ . $attributes['iso_code'] . '.gzip';
if (file_put_contents($file, $content)) {
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$this->_errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ') . (string) $attributes['iso_code'];
return false;
} else {
AdminTranslationsController::checkAndAddMailsFiles($attributes['iso_code'], $files_list);
AdminTranslationsController::addNewTabs($attributes['iso_code'], $files_list);
}
if (!Language::checkAndAddLanguage((string) $attributes['iso_code'])) {
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $attributes['iso_code'];
return false;
}
@unlink($file);
} else {
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
}
}
}
}
// change the default language if there is only one language in the localization pack
if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->languages->language) == 1) {
$this->iso_code_lang = $attributes['iso_code'];
}
return true;
}
示例7: submitAddLang
public function submitAddLang()
{
$arr_import_lang = explode('|', Tools::getValue('params_import_language'));
/* 0 = Language ISO code, 1 = PS version */
if (Validate::isLangIsoCode($arr_import_lang[0])) {
$array_stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 10)));
$content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . Tools::strtolower($arr_import_lang[0]) . '.gzip', false, $array_stream_context);
if ($content) {
$file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
if ((bool) @file_put_contents($file, $content)) {
require_once _PS_TOOL_DIR_ . '/tar/Archive_Tar.php';
$gz = new Archive_Tar($file, true);
$files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent());
if ($error = $gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
if (is_object($error) && !empty($error->message)) {
$this->errors[] = Tools::displayError('The archive cannot be extracted.') . ' ' . $error->message;
} else {
if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
$conf = 20;
} else {
// Reset cache
Language::loadLanguages();
// Clear smarty modules cache
Tools::clearCache();
AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
if ($tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list)) {
$this->errors += $tab_errors;
}
}
if (!unlink($file)) {
$this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
}
$this->redirect(false, isset($conf) ? $conf : '15');
}
} elseif (!unlink($file)) {
$this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
}
} else {
$this->errors[] = Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check rights for %s'), dirname($file));
}
} else {
$this->errors[] = Tools::displayError('Language not found.');
}
} else {
$this->errors[] = Tools::displayError('Invalid parameter');
}
}
示例8: installLanguagePack
public static function installLanguagePack($iso, $params, &$errors = array())
{
$file = _PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip';
$gz = new \Archive_Tar($file, true);
$files_list = AdminTranslationsController::filterTranslationFiles(Language::getLanguagePackListContent((string) $iso, $gz));
$files_paths = AdminTranslationsController::filesListToPaths($files_list);
$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)) {
$error = Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check permissions for %s'), $path);
$errors[] = count($tmp_array) == 0 ? Tools::displayError('The archive cannot be extracted.') . ' ' . $error : $error;
$tmp_array[] = $path;
}
}
if (defined('_PS_HOST_MODE_')) {
$mails_files = array();
$other_files = array();
foreach ($files_list as $key => $data) {
if (substr($data['filename'], 0, 5) == 'mails') {
$mails_files[] = $data;
}
}
$files_list = array_diff($files_list, $mails_files);
}
if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
$errors[] = sprintf(Tools::displayError('Cannot decompress the translation file for the following language: %s'), (string) $iso);
}
// Clear smarty modules cache
Tools::clearCache();
if (!Language::checkAndAddLanguage((string) $iso, false, false, $params)) {
$errors[] = sprintf(Tools::displayError('An error occurred while creating the language: %s'), (string) $iso);
} else {
// Reset cache
Language::loadLanguages();
AdminTranslationsController::checkAndAddMailsFiles((string) $iso, $files_list);
AdminTranslationsController::addNewTabs((string) $iso, $files_list);
}
self::installSfLanguagePack(self::getLocaleByIso($iso), $errors);
return count($errors) ? $errors : true;
}
示例9: import_language
public static function import_language($isoCode, $imports, $fromLocalPack = true)
{
//todo
// from localization directory; or from prestashop.com (api ?)
if ($imports == 'all') {
$selection = array('states', 'taxes', 'currencies', 'languages', 'units', 'groups');
} else {
$selection = split(',', $imports);
foreach ($selection as $selected) {
if (!Validate::isLocalizationPackSelection($selected)) {
echo "{$selected} is not a valid selection !\n";
return false;
}
}
}
if ($fromLocalPack) {
if (defined('_PS_HOST_MODE_')) {
$localizationPackFileName = _PS_CORE_DIR_ . '/localization/' . $isoCode . '.xml';
} else {
$localizationPackFileName = _PS_ROOT_DIR_ . '/localization/' . $isoCode . '.xml';
}
if (!is_readable($localizationPackFileName)) {
echo "Could not read localization pack !\n";
return false;
}
$pack = @Tools::file_get_contents($localizationPackFileName);
} else {
//todo: get content from prestashop servers
$pack = false;
}
//todo: IN PROGRESS seems this installs the language pack ?
$localizationPack = new LocalizationPack();
if (!$localizationPack->loadLocalisationPack($pack, $selection, false, $isoCode)) {
echo "Could not load localization pack\n";
return false;
}
// import lang pack
Language::checkAndAddLanguage($isoCode, $localizationPack, false, null);
}
示例10: submitAddLang
public function submitAddLang()
{
$arr_import_lang = explode('|', Tools::getValue('params_import_language'));
/* 0 = Language ISO code, 1 = PS version */
if (Validate::isLangIsoCode($arr_import_lang[0])) {
$array_stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 10)));
$content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . Tools::strtolower($arr_import_lang[0]) . '.gzip', false, $array_stream_context);
if ($content) {
$file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
if ((bool) @file_put_contents($file, $content)) {
$gz = new \Archive_Tar($file, true);
if (_PS_MODE_DEV_) {
$gz->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);
}
$files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent());
if ($error = $gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _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 {
if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
$conf = 20;
} else {
// Reset cache
Language::loadLanguages();
// Clear smarty modules cache
Tools::clearCache();
AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
if ($tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list)) {
$this->errors += $tab_errors;
}
}
if (!unlink($file)) {
$this->errors[] = sprintf($this->trans('Cannot delete the archive %s.', array(), 'Admin.International.Notification'), $file);
}
//fetch cldr datas for the new imported locale
$languageCode = explode('-', Language::getLanguageCodeByIso($arr_import_lang[0]));
$cldrUpdate = new Update(_PS_TRANSLATIONS_DIR_);
$cldrUpdate->fetchLocale($languageCode[0] . '-' . Tools::strtoupper($languageCode[1]));
$this->redirect(false, isset($conf) ? $conf : '15');
}
} else {
$this->errors[] = sprintf($this->trans('Cannot decompress the translation file for the following language: %s', array(), 'Admin.International.Notification'), $arr_import_lang[0]);
$checks = array();
foreach ($files_list as $f) {
if (isset($f['filename'])) {
if (is_file(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename']) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename'])) {
$checks[] = dirname($f['filename']);
} elseif (is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename']) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . dirname($f['filename']))) {
$checks[] = dirname($f['filename']);
}
}
}
$checks = array_unique($checks);
foreach ($checks as $check) {
$this->errors[] = sprintf($this->trans('Please check rights for folder and files in %s', array(), 'Admin.Notifications.Error'), $check);
}
if (!unlink($file)) {
$this->errors[] = sprintf($this->trans('Cannot delete the archive %s.', array(), 'Admin.International.Notification'), $file);
}
}
} else {
$this->errors[] = $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'), dirname($file));
}
} else {
$this->errors[] = $this->trans('Language not found.', array(), 'Admin.International.Notification');
}
} else {
$this->errors[] = $this->trans('Invalid parameter.', array(), 'Admin.Notifications.Error');
}
}
示例11: install
public function install()
{
include dirname(__FILE__) . '/sql-install.php';
foreach ($sql as $s) {
if (!Db::getInstance()->Execute($s)) {
return false;
}
}
if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('adminOrder') || !$this->registerHook('paymentReturn') || !$this->registerHook('orderConfirmation')) {
return false;
}
$this->registerHook('displayPayment');
$this->registerHook('rightColumn');
$this->registerHook('extraRight');
$this->registerHook('header');
if (!Configuration::get('KLARNA_PAYMENT_ACCEPTED')) {
Configuration::updateValue('KLARNA_PAYMENT_ACCEPTED', $this->addState('Klarna: Payment accepted', '#DDEEFF'));
}
if (!Configuration::get('KLARNA_PAYMENT_PENDING')) {
Configuration::updateValue('KLARNA_PAYMENT_PENDING', $this->addState('Klarna : payment in pending verification', '#DDEEFF'));
}
/*auto install currencies*/
$currencies = array('Euro' => array('iso_code' => 'EUR', 'iso_code_num' => 978, 'symbole' => '€', 'format' => 2), 'Danish Krone' => array('iso_code' => 'DKK', 'iso_code_num' => 208, 'symbole' => 'DAN kr.', 'format' => 2), 'krone' => array('iso_code' => 'NOK', 'iso_code_num' => 578, 'symbole' => 'NOK kr', 'format' => 2), 'Krona' => array('iso_code' => 'SEK', 'iso_code_num' => 752, 'symbole' => 'SEK kr', 'format' => 2));
$languages = array('Swedish' => array('iso_code' => 'se', 'language_code' => 'sv', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'sweden.png'), 'Deutsch' => array('iso_code' => 'de', 'language_code' => 'de', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'germany.png'), 'Dutch' => array('iso_code' => 'nl', 'language_code' => 'nl', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'netherlands.png'), 'Finnish' => array('iso_code' => 'fi', 'language_code' => 'fi', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'finland.jpg'), 'Norwegian' => array('iso_code' => 'no', 'language_code' => 'no', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'norway.png'), 'Danish' => array('iso_code' => 'da', 'language_code' => 'da', 'date_format_lite' => 'Y-m-d', 'date_format_full' => 'Y-m-d H:i:s', 'flag' => 'denmark.png'));
foreach ($currencies as $key => $val) {
if (_PS_VERSION_ >= 1.5) {
$exists = Currency::exists($val['iso_code_num'], $val['iso_code_num']);
} else {
$exists = Currency::exists($val['iso_code_num']);
}
if (!$exists) {
$currency = new Currency();
$currency->name = $key;
$currency->iso_code = $val['iso_code'];
$currency->iso_code_num = $val['iso_code_num'];
$currency->sign = $val['symbole'];
$currency->conversion_rate = 1;
$currency->format = $val['format'];
$currency->decimals = 1;
$currency->active = true;
$currency->add();
}
}
Currency::refreshCurrencies();
$version = str_replace('.', '', _PS_VERSION_);
$version = substr($version, 0, 2);
foreach ($languages as $key => $val) {
$pack = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . $val['language_code'] . '.xml');
if ($pack || ($pack = @Tools::file_get_contents(dirname(__FILE__) . '/../../localization/' . $val['language_code'] . '.xml'))) {
$localizationPack = new LocalizationPack();
$localizationPack->loadLocalisationPack($pack, array('taxes', 'languages'));
}
if (!Language::getIdByIso($val['language_code'])) {
if (_PS_VERSION_ >= 1.5) {
Language::checkAndAddLanguage($val['language_code']);
} else {
$lang = new Language();
$lang->name = $key;
$lang->iso_code = $val['iso_code'];
$lang->language_code = $val['language_code'];
$lang->date_format_lite = $val['date_format_lite'];
$lang->date_format_full = $val['date_format_full'];
$lang->add();
$insert_id = (int) $lang->id;
$pack = Tools::file_get_contents('http://www.prestashop.com/download/localization/' . $val['iso_code'] . '.xml');
$lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $val['iso_code']));
if ($lang_pack) {
$flag = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/flags/jpeg/' . $val['iso_code'] . '.jpg');
if ($flag != null && !preg_match('/<body>/', $flag)) {
$file = fopen(dirname(__FILE__) . '/../../img/l/' . $insert_id . '.jpg', 'w');
if ($file) {
fwrite($file, $flag);
fclose($file);
}
}
}
}
}
}
foreach ($this->countries as $key => $val) {
$country = new Country(Country::getByIso($key));
$country->active = true;
$country->update();
}
return true;
}
示例12: current
$meth = $refl->getMethod('_deleteOldLabels');
$meth->setAccessible(true);
$meth->invoke($customizableProduct);
// First, create the label
$customizableProduct->createLabels($fileFields = 0, $textFields = 1);
$fields = $customizableProduct->getCustomizationFields();
$id_customization_field = current(current(current($fields)))['id_customization_field'];
// And inform the product that it has become customizable
$customizableProduct->customizable = 1;
$customizableProduct->text_fields = 1;
$customizableProduct->save();
// Then define it. There is unfortunately no API, so we encode the data in $_POST...
$_POST[implode('_', ['label', 1, $id_customization_field, $language->id, $shop->id])] = 'my field';
$_POST[implode('_', ['require', 1, $id_customization_field])] = true;
$customizableProduct->updateLabels();
echo "- added a required customizable text field to product #1\n";
// We need 2 languages for some tests
Language::checkAndAddLanguage('fr');
echo "- added French language just so that we have 2\n";
$order = new Order(5);
$history = new OrderHistory();
$history->id_order = $order->id;
$history->id_employee = 1;
$use_existings_payment = false;
if (!$order->hasInvoice()) {
$use_existings_payment = true;
}
$history->changeIdOrderState(5, $order, $use_existings_payment);
$history->add();
echo "- Order number 5 is now delivered\n";
echo "Shop fixtures prepared for tests!\n";
示例13: downloadAndInstallLanguagePack
public static function downloadAndInstallLanguagePack($iso, $version = null, $params = null)
{
require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php';
if (!Validate::isLanguageIsoCode($iso)) {
return false;
}
if ($version == null) {
$version = _PS_VERSION_;
}
$lang_pack = false;
$lang_pack_ok = false;
$errors = array();
$file = _PS_TRANSLATIONS_DIR_ . $iso . '.gzip';
if (!($lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $version . '&iso_lang=' . $iso))) {
$errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
} elseif (!($lang_pack = Tools::jsonDecode($lang_pack_link))) {
$errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
} elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $lang_pack->iso_code . '.gzip')) {
if (!@file_put_contents($file, $content)) {
$errors[] = Tools::displayError('Server does not have permissions for writing.');
}
}
if (file_exists($file)) {
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ') . (string) $iso;
}
if (!Language::checkAndAddLanguage((string) $iso, $lang_pack, false, $params)) {
$errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $iso;
} else {
// Reset cache
Language::loadLanguages();
AdminTranslationsController::checkAndAddMailsFiles($iso, $files_list);
AdminTranslationsController::addNewTabs($iso, $files_list);
}
@unlink($file);
} else {
$errors[] = Tools::displayError('No language pack is available for your version.');
}
return count($errors) ? $errors : true;
}
示例14: installLanguages
/**
* 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;
}