public function getContent() { $output = ''; $errors = array(); if (Tools::isSubmit('submitHomeFeatured')) { $nbr = Tools::getValue('HOME_FEATURED_NBR'); if (!Validate::isInt($nbr) || $nbr <= 0) { $errors[] = $this->l('The number of products is invalid. Please enter a positive number.'); } $cat = Tools::getValue('HOME_FEATURED_CAT'); if (!Validate::isInt($cat) || $cat <= 0) { $errors[] = $this->l('The category ID is invalid. Please choose an existing category ID.'); } $rand = Tools::getValue('HOME_FEATURED_RANDOMIZE'); if (!Validate::isBool($rand)) { $errors[] = $this->l('Invalid value for the "randomize" flag.'); } if (isset($errors) && count($errors)) { $output = $this->displayError(implode('<br />', $errors)); } else { Configuration::updateValue('HOME_FEATURED_NBR', (int) $nbr); Configuration::updateValue('HOME_FEATURED_CAT', (int) $cat); Configuration::updateValue('HOME_FEATURED_RANDOMIZE', (bool) $rand); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('homefeatured.tpl')); $output = $this->displayConfirmation($this->l('Your settings have been updated.')); } } return $output . $this->renderForm(); }
function upgrade_module_0_9($module) { $module_path = $module->getLocalPath(); $img_folder_path = $module->getLocalPath() . 'img'; $fixture_img_path = $module->getLocalPath() . 'img' . DIRECTORY_SEPARATOR . 'fixtures'; if (!Tools::file_exists_cache($img_folder_path)) { mkdir($img_folder_path); } if (!Tools::file_exists_cache($fixture_img_path)) { mkdir($fixture_img_path); } $files = scandir($module->getLocalPath()); foreach ($files as $file) { if (strncmp($file, 'advertising', 11) == 0) { if ($file == 'advertising.jpg') { copy($module_path . $file, $fixture_img_path . DIRECTORY_SEPARATOR . $file); } else { copy($module_path . $file, $img_folder_path . DIRECTORY_SEPARATOR . $file); } unlink($module_path . $file); } } Tools::clearCache(Context::getContext()->smarty, $module->getTemplatePath('blockadvertising.tpl')); return true; }
function upgrade_module_1_3_4($module) { if (Tools::file_exists_cache($module->getLocalPath() . 'img')) { recurseCopy($module->getLocalPath() . 'img', $module->getLocalPath() . 'images', true); } Tools::clearCache(Context::getContext()->smarty, $module->getTemplatePath('homeslider.tpl')); return true; }
public function getContent() { $output = ''; $errors = array(); if (Tools::isSubmit('submitSmartBlogAddThis')) { $api_kay = Tools::getValue('SMARTBBLOG_ADD_THIS_API_KEY'); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('smartblogaddthisbutton.tpl')); Configuration::updateValue('SMARTBBLOG_ADD_THIS_API_KEY', $api_kay); $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } return $output . $this->renderForm(); }
function upgrade_module_1_3_8($module) { // Only img present, just need to rename folder if (file_exists($module->getLocalPath() . 'img') && !file_exists($module->getLocalPath() . 'images')) { rename($module->getLocalPath() . 'img', $module->getLocalPath() . 'images'); } else { if (file_exists($module->getLocalPath() . 'img') && file_exists($module->getLocalPath() . 'images')) { recurseCopy($module->getLocalPath() . 'img', $module->getLocalPath() . 'images', true); } } Tools::clearCache(Context::getContext()->smarty, $module->getTemplatePath('homeslider.tpl')); return true; }
public function getContent() { $output = ''; $errors = array(); $languages = Language::getLanguages(); $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $id_lang = $this->context->language->id; if (Tools::isSubmit('submitGlobal')) { Configuration::updateValue('DEALS', Tools::getValue('DEALS')); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('discountproducts_home.tpl')); $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } $output .= $this->displayForm(); return $output; }
function upgrade_module_2_5($module) { $module_path = $module->getLocalPath(); $img_folder_path = $module->getLocalPath() . 'img'; if (!Tools::file_exists_cache($img_folder_path)) { mkdir($img_folder_path); } $files = scandir($module->getLocalPath()); foreach ($files as $file) { if (strncmp($file, 'homepage_logo', 13) == 0) { copy($module_path . $file, $img_folder_path . DIRECTORY_SEPARATOR . $file); unlink($module_path . $file); } } Tools::clearCache(Context::getContext()->smarty, $module->getTemplatePath('editorial.tpl')); return true; }
public function getContent() { $output = ''; $errors = array(); if (Tools::isSubmit('submitHomeFeatured')) { $nbr = (int) Tools::getValue('HOME_FEATURED_NBR'); if (!$nbr || $nbr <= 0 || !Validate::isInt($nbr)) { $errors[] = $this->l('An invalid number of products has been specified.'); } else { Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('homefeatured.tpl')); Configuration::updateValue('HOME_FEATURED_NBR', (int) $nbr); } if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } else { $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } } return $output . $this->renderForm(); }
public function updateBlockPosition($order = null) { if (is_null($order)) { return false; } $position = explode('::', $order); $res = false; if (count($position) > 0) { foreach ($position as $key => $id_block) { $res = Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'advance_topmenu_blocks` SET `position` = ' . $key . ' WHERE `id_block` = ' . (int) $id_block); if (!$res) { break; } } } Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl')); return $res; }
public static function _deferedClearCache($template_path, $cache_id, $compile_id) { Tools::enableCache(); $number_of_template_cleared = Tools::clearCache(Context::getContext()->smarty, $template_path, $cache_id, $compile_id); Tools::restoreCacheSettings(); return $number_of_template_cleared; }
public function clearSmartyCache() { Tools::enableCache(); Tools::clearCache($this->context->smarty); Tools::restoreCacheSettings(); }
/** * Called when PS_REWRITING_SETTINGS option is saved */ public function updateOptionPsRewritingSettings() { Configuration::updateValue('PS_REWRITING_SETTINGS', (int) Tools::getValue('PS_REWRITING_SETTINGS')); if (Tools::generateHtaccess($this->ht_file, null, null, '', Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS'), false, Tools::getValue('PS_HTACCESS_DISABLE_MODSEC'))) { Tools::enableCache(); Tools::clearCache($this->context->smarty); Tools::restoreCacheSettings(); } else { Configuration::updateValue('PS_REWRITING_SETTINGS', 0); // Message copied/pasted from the information tip $message = $this->l('Before being able to use this tool, you need to:'); $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.'); $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system)'); $this->errors[] = $message; } }
protected function _clearCache($template, $cacheId = NULL, $compileId = NULL) { global $smarty; Tools::clearCache($smarty); }
public function getContent() { $output = ''; $errors = array(); $languages = Language::getLanguages(); $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $id_lang = $this->context->language->id; if (Tools::getValue('confirm_msg')) { $output .= $this->displayConfirmation(Tools::getValue('confirm_msg')); } if (Tools::isSubmit('submitGlobal')) { $id_position = (int) Tools::getValue('id_position', 1); $html_id = $this->getHtmlIdByPosition($id_position); if ($html_id && count($html_id) > 0) { $htmlObject = new HtmlObject($html_id['id_htmlobject']); } else { $htmlObject = new HtmlObject(); } $htmlObject->active = (int) Tools::getValue('active'); //$hook_postition $htmlObject->hook_postition = (int) Tools::getValue('id_position'); foreach ($languages as $language) { $htmlObject->title[$language['id_lang']] = Tools::getValue('item_title_' . $language['id_lang']); $htmlObject->content[$language['id_lang']] = Tools::getValue('item_html_' . $language['id_lang']); } if (!$errors || count($errors) < 1) { /* Update */ if ($html_id && count($html_id) > 0) { if (!$htmlObject->update()) { $errors[] = $this->displayError($this->l('The Advertising slide could not be updated.')); } } elseif (!$htmlObject->add()) { $errors[] = $this->displayError($this->l('The Advertising slide could not be add.')); } /* Adds */ } if (!isset($errors) || count($errors) < 1) { if ($html_id && count($html_id) > 0) { $confirm_msg = $this->l('Slide successfully updated.'); } else { $confirm_msg = $this->l('New slide successfully added.'); } Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('blockhtml.tpl')); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg . '&id_position=' . $id_position); } } if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } return $output . $this->displayForm(); }
/** * This functions make checks about AdminThemes configuration edition only. * * @since 1.4 */ public function postProcess() { // new check compatibility theme feature (1.4) : $val = Tools::getValue('PS_THEME'); Configuration::updateValue('PS_IMG_UPDATE_TIME', time()); if (!empty($val) && !$this->_isThemeCompatible($val)) { // don't submit if errors unset($_POST['submitThemes' . $this->table]); } Tools::clearCache($this->context->smarty); parent::postProcess(); }
protected function _clearCache($template, $cache_id = null, $compile_id = null) { Tools::enableCache(); if ($cache_id === null) { $cache_id = $this->name; } Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath($template), $cache_id, $compile_id); Tools::restoreCacheSettings(); }
protected function ajaxProcessAddComment() { $module_instance = new ProductComments(); $result = true; $id_guest = 0; $id_customer = $this->context->customer->id; if (!$id_customer) { $id_guest = $this->context->cookie->id_guest; } $errors = array(); // Validation if (!Validate::isInt(Tools::getValue('id_product'))) { $errors[] = $module_instance->l('Product ID is incorrect', 'default'); } if (!Tools::getValue('title') || !Validate::isGenericName(Tools::getValue('title'))) { $errors[] = $module_instance->l('Title is incorrect', 'default'); } if (!Tools::getValue('content') || !Validate::isMessage(Tools::getValue('content'))) { $errors[] = $module_instance->l('Comment is incorrect', 'default'); } if (!$id_customer && (!Tools::isSubmit('customer_name') || !Tools::getValue('customer_name') || !Validate::isGenericName(Tools::getValue('customer_name')))) { $errors[] = $module_instance->l('Customer name is incorrect', 'default'); } if (!$this->context->customer->id && !Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS')) { $errors[] = $module_instance->l('You must be connected in order to send a comment', 'default'); } if (!count(Tools::getValue('criterion'))) { $errors[] = $module_instance->l('You must give a rating', 'default'); } $product = new Product(Tools::getValue('id_product')); if (!$product->id) { $errors[] = $module_instance->l('Product not found', 'default'); } if (!count($errors)) { $customer_comment = ProductComment::getByCustomer(Tools::getValue('id_product'), $id_customer, true, $id_guest); if (!$customer_comment || $customer_comment && strtotime($customer_comment['date_add']) + (int) Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') < time()) { $comment = new ProductComment(); $comment->content = strip_tags(Tools::getValue('content')); $comment->id_product = (int) Tools::getValue('id_product'); $comment->id_customer = (int) $id_customer; $comment->id_guest = $id_guest; $comment->customer_name = Tools::getValue('customer_name'); if (!$comment->customer_name) { $comment->customer_name = pSQL($this->context->customer->firstname . ' ' . $this->context->customer->lastname); } $comment->title = Tools::getValue('title'); $comment->grade = 0; $comment->validate = 0; $comment->save(); $grade_sum = 0; foreach (Tools::getValue('criterion') as $id_product_comment_criterion => $grade) { $grade_sum += $grade; $product_comment_criterion = new ProductCommentCriterion($id_product_comment_criterion); if ($product_comment_criterion->id) { $product_comment_criterion->addGrade($comment->id, $grade); } } if (count(Tools::getValue('criterion')) >= 1) { $comment->grade = $grade_sum / count(Tools::getValue('criterion')); // Update Grade average of comment $comment->save(); } $result = true; Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('productcomments-reviews.tpl')); } else { $result = false; $errors[] = $module_instance->l('Please wait before posting another comment', 'default') . ' ' . Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') . ' ' . $module_instance->l('seconds before posting a new comment', 'default'); } } else { $result = false; } die(Tools::jsonEncode(array('result' => $result, 'errors' => $errors))); }
/** * 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->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), 'allow_accented_chars_url' => (string) $xml->allow_accented_chars_url); if (InstallSession::getInstance()->safe_mode) { Language::checkAndAddLanguage($iso, false, true, $params_lang); } else { Language::downloadAndInstallLanguagePack($iso, _PS_INSTALL_VERSION_, $params_lang); } Language::loadLanguages(); Tools::clearCache(); 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; }
/** * Upgrades total_quantity_available after having saved * @see StockAvailableCore::update() * @see StockAvailableCore::add() */ public function postSave() { if ($this->id_product_attribute == 0) { return true; } $id_shop = Shop::getContext() != Shop::CONTEXT_GROUP ? $this->id_shop : null; if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) { $combination = new Combination((int) $this->id_product_attribute); if ($colors = $combination->getColorsAttributes()) { $product = new Product((int) $this->id_product); foreach ($colors as $color) { if ($product->isColorUnavailable((int) $color['id_attribute'], (int) $this->id_shop)) { // Change template dir if called from the BackOffice $current_template_dir = Context::getContext()->smarty->getTemplateDir(); Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_ . 'tpl'); Tools::clearCache(null, 'product-list-colors.tpl', Product::getColorsListCacheId((int) $product->id)); Context::getContext()->smarty->setTemplateDir($current_template_dir); break; } } } } $total_quantity = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(quantity) as quantity FROM ' . _DB_PREFIX_ . 'stock_available WHERE id_product = ' . (int) $this->id_product . ' AND id_product_attribute <> 0 ' . StockAvailable::addSqlShopRestriction(null, $id_shop)); $this->setQuantity($this->id_product, 0, $total_quantity, $id_shop); return true; }
/** * AdminController::postProcess() override * @see AdminController::postProcess() */ public function postProcess() { $this->getInformations(); /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->errors[] = Tools::displayError('This functionality has been disabled.'); return; } /* PrestaShop demo mode */ try { if (Tools::isSubmit('submitCopyLang')) { if ($this->tabAccess['add'] === '1') { $this->submitCopyLang(); } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (Tools::isSubmit('submitExport')) { if ($this->tabAccess['add'] === '1') { $this->submitExportLang(); } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (Tools::isSubmit('submitImport')) { if ($this->tabAccess['add'] === '1') { $this->submitImportLang(); } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (Tools::isSubmit('submitAddLanguage')) { if ($this->tabAccess['add'] === '1') { $this->submitAddLang(); } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } elseif (Tools::isSubmit('submitTranslationsPdf')) { if ($this->tabAccess['edit'] === '1') { // Only the PrestaShop team should write the translations into the _PS_TRANSLATIONS_DIR_ if (!$this->theme_selected) { $this->writeTranslationFile(); } else { $this->writeTranslationFile(true); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitTranslationsBack') || Tools::isSubmit('submitTranslationsErrors') || Tools::isSubmit('submitTranslationsFields') || Tools::isSubmit('submitTranslationsFront')) { if ($this->tabAccess['edit'] === '1') { $this->writeTranslationFile(); } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay')) { if ($this->tabAccess['edit'] === '1') { $this->submitTranslationsMails(); } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::isSubmit('submitTranslationsModules')) { if ($this->tabAccess['edit'] === '1') { // Get list of modules if ($modules = $this->getListModules()) { // Get files of all modules $arr_files = $this->getAllModuleFiles($modules, null, $this->lang_selected->iso_code, true); // Find and write all translation modules files foreach ($arr_files as $value) { $this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']); } // Clear modules cache Tools::clearCache(); // Redirect if (Tools::getValue('submitTranslationsModulesAndStay')) { $this->redirect(true); } else { $this->redirect(); } } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } } catch (PrestaShopException $e) { $this->errors[] = $e->getMessage(); } }
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; }
protected function _clearCache($template, $cache_id = null, $compile_id = null) { if (Configuration::get('PS_SMARTY_CLEAR_CACHE') == 'never') { return 0; } if ($cache_id === null) { $cache_id = $this->name; } Tools::enableCache(); $number_of_template_cleared = Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath($template), $cache_id, $compile_id); Tools::restoreCacheSettings(); return $number_of_template_cleared; }
public function renderList() { $output = ''; if ($this->session_api->connectFromCredentials('email')) { Tools::clearCache($this->context->smarty); $response_array = array(); $parameters = array('account_id' => $this->session_api->account_id, 'max_lines' => 20, 'campaign_id' => (int) Tools::getValue('campaign_id')); if ($this->session_api->call('email', 'campaign', 'enum_last_sent', $parameters, $response_array)) { if (is_array($response_array) && count($response_array)) { // On retrouve tous les jours d'envoi (envois fractionnés sur plusieurs jours) // --------------------------------------------------------------------------- $tools = new EMTools(); $days = array(); foreach ($response_array as $day) { $days[] = array('day_api' => $day['stat_date'], 'day_lang' => $tools->getLocalizableDate($day['stat_date'])); } $this->context->smarty->assign(array('days' => $days, 'current_index' => AdminController::$currentIndex . '&campaign_id=' . $response_array[0]['campaign_id'], 'campaign_id' => $response_array[0]['campaign_id'], 'campaign_name' => Tools::htmlentitiesDecodeUTF8($response_array[0]['name']))); // S'il y a un stat_date, il faut ré-intéroger l'API pour obtenir les stats du jour sélectionné // -------------------------------------------------------------------------------------------- if (Tools::getValue('stat_date')) { $stat_array = array(); $parameters = array('account_id' => $this->session_api->account_id, 'campaign_id' => (int) Tools::getValue('campaign_id'), 'stat_date' => (int) Tools::getValue('stat_date')); if ($this->session_api->call('email', 'campaign', 'get_statistics', $parameters, $stat_array)) { $response_array = array($stat_array); } // Pour rester compatible avec le code ci-dessous } // S'il n'y a pas de stat_date, l'API nous retourne directement les stats du dernier envoi // --------------------------------------------------------------------------------------- $this->context->smarty->assign(array('select_day' => $response_array[0]['stat_date'], 'sent' => $response_array[0]['sent'], 'not_sent' => $response_array[0]['not_sent'], 'delivered' => $response_array[0]['delivered'], 'not_delivered' => $response_array[0]['not_delivered'], 'opened' => $response_array[0]['opened'], 'not_opened' => $response_array[0]['not_opened'], 'unique_clickers' => $response_array[0]['unique_clickers'], 'all_clicks' => $response_array[0]['all_clicks'], 'unsubscribes' => $response_array[0]['unsubscribes'], 'abuses' => $response_array[0]['abuses'], 'ratio_sent' => $response_array[0]['ratio_sent'], 'ratio_not_sent' => $response_array[0]['ratio_not_sent'], 'ratio_delivered' => $response_array[0]['ratio_delivered'], 'ratio_not_delivered' => $response_array[0]['ratio_not_delivered'], 'ratio_opened' => $response_array[0]['ratio_opened'], 'ratio_not_opened' => $response_array[0]['ratio_not_opened'], 'ratio_unique_clickers' => $response_array[0]['ratio_unique_clickers'], 'ratio_unsubscribes' => $response_array[0]['ratio_unsubscribes'], 'ratio_abuses' => $response_array[0]['ratio_abuses'])); // On affiche le tableau des stats // ------------------------------- $diplay = $this->getTemplatePath() . 'marketinge_stats/marketinge_stats.tpl'; $output = $this->context->smarty->fetch($diplay); // On charge les données du graphique des "opened" // ----------------------------------------------- $delivered = array(); /* ne pas utiliser le nom response_array SVP */ $parameters = array('account_id' => $this->session_api->account_id, 'campaign_id' => $response_array[0]['campaign_id'], 'stat_date' => $response_array[0]['stat_date']); $this->session_api->call('email', 'campaign', 'get_graph_delivered_per_hour', $parameters, $delivered); $this->context->smarty->assign('delivered', $delivered); $graph = $this->getTemplatePath() . 'marketinge_stats/marketinge_graph.tpl'; $output .= $this->context->smarty->fetch($graph); } else { // On affiche une liste vide // ------------------------- $helper = new HelperList(); $helper->no_link = true; $helper->shopLinkType = ''; $helper->simple_header = false; // Mettre 'search' => false dans chaque fields_list $helper->table = $this->table; $helper->identifier = 'campaign_id'; $helper->show_toolbar = true; $helper->toolbar_scroll = false; $helper->token = Tools::getAdminTokenLite('AdminMarketingEStats'); $helper->currentIndex = $this->context->link->getAdminLink('AdminMarketingEStats', false); $helper->allow_export = false; $helper->title = '<i class="icon-bar-chart"></i> ' . $this->module->l('Broadcast evolution during last 24/48 hours', 'adminmarketingestats'); $helper->toolbar_btn = array('back' => array('href' => 'index.php?controller=AdminMarketingEList&token=' . Tools::getAdminTokenLite('AdminMarketingEList'), 'desc' => $this->module->l('Back to list', 'adminmarketingestats'))); $helper->actions = array('details'); $this->fields_list = array(); $output .= $helper->generateList($this->fields_list, $this->fields_list); } } } $footer = $this->getTemplatePath() . 'footer.tpl'; $output .= $this->context->smarty->fetch($footer); return $output; }
private function ProcessLayoutColumn() { $theme = new Theme((int) $this->context->shop->id_theme); $layoutColumn = (int) Configuration::get('OVIC_LAYOUT_COLUMN', null, null, $this->context->shop->id); $id_theme_meta = $this->getIdThemeMetaByPage('index'); if ($theme->hasLeftColumn('index')) { if ($layoutColumn === 2 || $layoutColumn === 3) { $this->processLeftMeta($id_theme_meta); } } else { if ($layoutColumn === 0 || $layoutColumn === 1) { $this->processLeftMeta($id_theme_meta); } } if ($theme->hasRightColumn('index')) { if ($layoutColumn === 1 || $layoutColumn === 3) { $this->processRightMeta($id_theme_meta); } } else { if ($layoutColumn === 0 || $layoutColumn === 2) { $this->processRightMeta($id_theme_meta); } } Tools::clearCache(); }
/** * This functions make checks about AdminThemes configuration edition only. * * @since 1.4 */ public function postProcess() { if (Tools::isSubmit('submitOptionstheme') && Tools::isSubmit('id_theme') && !Tools::isSubmit('deletetheme') && Tools::getValue('action') != 'ThemeInstall' && $this->context->shop->id_theme != Tools::getValue('id_theme')) { $this->display = "ChooseThemeModule"; } else { // new check compatibility theme feature (1.4) : $val = Tools::getValue('PS_THEME'); Configuration::updateValue('PS_IMG_UPDATE_TIME', time()); if (!empty($val) && !$this->_isThemeCompatible($val)) { // don't submit if errors unset($_POST['submitThemes' . $this->table]); } Tools::clearCache($this->context->smarty); return parent::postProcess(); } }
/** * Clear Smarty cache and compile folders */ public static function clearSmartyCache() { $smarty = Context::getContext()->smarty; Tools::clearCache($smarty); Tools::clearCompile($smarty); }
public static function clearColorListCache($id_product = false) { // Change template dir if called from the BackOffice $current_template_dir = Context::getContext()->smarty->getTemplateDir(); Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_); Tools::clearCache(null, 'product-list-colors.tpl', $id_product ? 'productlist_colors|' . (int) $id_product . '|' . (int) Context::getContext()->shop->id : 'productlist_colors'); Context::getContext()->smarty->setTemplateDir($current_template_dir); }
public function getContent() { if (Tools::isSubmit('submitSocialSharing')) { foreach (self::$networks as $network) { Configuration::updateValue('PS_SC_' . Tools::strtoupper($network), (int) Tools::getValue('PS_SC_' . Tools::strtoupper($network))); } $this->html .= $this->displayConfirmation($this->l('Settings updated')); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('socialsharing.tpl')); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('socialsharing_compare.tpl')); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } $helper = new HelperForm(); $helper->submit_action = 'submitSocialSharing'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues()); $fields = array(); foreach (self::$networks as $network) { $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->l('Disabled')))); } return $this->html . $helper->generateForm(array(array('form' => array('legend' => array('title' => $this->displayName, 'icon' => 'icon-share'), 'input' => $fields, 'submit' => array('title' => $this->l('Save')))))); }
/** * Update settings in database and configuration files * * @params array $fields Fields settings * * @global string $currentIndex Current URL in order to keep current Tab */ protected function _postConfig($fields) { global $currentIndex, $smarty; $languages = Language::getLanguages(false); Tools::clearCache($smarty); /* Check required fields */ foreach ($fields as $field => $values) { if (isset($values['required']) and $values['required']) { if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { if (($value = Tools::getValue($field . '_' . $language['id_lang'])) == false and (string) $value != '0') { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is required.'); } } } elseif (($value = Tools::getValue($field)) == false and (string) $value != '0') { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is required.'); } } } /* Check fields validity */ foreach ($fields as $field => $values) { if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { if (Tools::getValue($field . '_' . $language['id_lang']) and isset($values['validation'])) { if (!Validate::$values['validation'](Tools::getValue($field . '_' . $language['id_lang']))) { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is invalid.'); } } } } elseif (Tools::getValue($field) and isset($values['validation'])) { if (!Validate::$values['validation'](Tools::getValue($field))) { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is invalid.'); } } } /* Default value if null */ foreach ($fields as $field => $values) { if (!Tools::getValue($field) and isset($values['default'])) { $_POST[$field] = $values['default']; } } /* Save process */ if (!sizeof($this->_errors)) { if (Tools::isSubmit('submitAppearanceconfiguration')) { if (isset($_FILES['PS_LOGO']['error']) && $_FILES['PS_LOGO']['error'] == 1 || isset($_FILES['PS_LOGO_MAIL']['error']) && $_FILES['PS_LOGO_MAIL']['error'] == 1 || isset($_FILES['PS_LOGO_INVOICE']['error']) && $_FILES['PS_LOGO_INVOICE']['error'] == 1 || isset($_FILES['PS_FAVICON']['error']) && $_FILES['PS_FAVICON']['error'] == 1 || isset($_FILES['PS_STORES_ICON']['error']) && $_FILES['PS_STORES_ICON']['error'] == 1) { $uploadMaxSize = (int) str_replace('M', '', ini_get('upload_max_filesize')); $postMaxSize = (int) str_replace('M', '', ini_get('post_max_size')); $maxSize = $uploadMaxSize < $postMaxSize ? $uploadMaxSize : $postMaxSize; $this->_errors[] = Tools::displayError('An error occurred during logo copy. Image size must be below') . ' ' . $maxSize . 'M.'; } if (isset($_FILES['PS_LOGO']['tmp_name']) and $_FILES['PS_LOGO']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['PS_LOGO']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo.jpg')) { $this->_errors[] = Tools::displayError('an error occurred during logo copy'); } unlink($tmpName); } if (isset($_FILES['PS_LOGO_MAIL']['tmp_name']) and $_FILES['PS_LOGO_MAIL']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO_MAIL'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL')) or !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_mail.jpg')) { $this->_errors[] = Tools::displayError('an error occurred during logo copy'); } unlink($tmpName); } if (isset($_FILES['PS_LOGO_INVOICE']['tmp_name']) and $_FILES['PS_LOGO_INVOICE']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO_INVOICE'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_INVOICE')) or !move_uploaded_file($_FILES['PS_LOGO_INVOICE']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_invoice.jpg')) { $this->_errors[] = Tools::displayError('an error occurred during logo copy'); } unlink($tmpName); } if (isset($_FILES['PS_STORES_ICON']['tmp_name']) and $_FILES['PS_STORES_ICON']['tmp_name']) { if ($error = checkImage($_FILES['PS_STORES_ICON'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_STORES_ICON')) or !move_uploaded_file($_FILES['PS_STORES_ICON']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_stores.gif')) { $this->_errors[] = Tools::displayError('an error occurred during logo copy'); } unlink($tmpName); } $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_ . 'favicon.ico'); } /* Update settings in database */ if (!sizeof($this->_errors)) { foreach ($fields as $field => $values) { unset($val); if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { $val[$language['id_lang']] = isset($values['cast']) ? $values['cast'](Tools::getValue($field . '_' . $language['id_lang'])) : Tools::getValue($field . '_' . $language['id_lang']); } } else { $val = isset($values['cast']) ? $values['cast'](Tools::getValue($field)) : Tools::getValue($field); } Configuration::updateValue($field, $val); } Tools::redirectAdmin($currentIndex . '&conf=6' . '&token=' . $this->token); } } }
/** * Checks submitted values * * @since 1.4 */ public function postProcess() { // FPDF does not support PNG images with alpha channel if (isset($_FILES['PS_LOGO_INVOICE']) && $_FILES['PS_LOGO_INVOICE']['type'] == 'image/png') { $this->_errors[] = Tools::displayError('Invoice logo does not accept PNG images.'); } global $smarty; /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); return; } /* PrestaShop demo mode*/ // new check compatibility theme feature (1.4) : $val = Tools::getValue('PS_THEME'); Configuration::updateValue('PS_IMG_UPDATE_TIME', time()); if (!empty($val) and !$this->_isThemeCompatible($val)) { // don't submit if errors unset($_POST['submitThemes' . $this->table]); } Tools::clearCache($smarty); parent::postProcess(); }