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; }
public static function getSubCategories($id_lang, $active = true, $id_category = 2, $p = 0, $n = 6) { $sql_groups_where = ''; $sql_groups_join = ''; if (Group::isFeatureActive()) { $sql_groups_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)'; $groups = FrontController::getCurrentCustomerGroups(); $sql_groups_where = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . pSQL(implode(',', $groups)) . ')' : '=' . (int) Group::getCurrent()->id); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description FROM `' . _DB_PREFIX_ . 'category` c ' . Shop::addSqlAssociation('category', 'c') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) $id_lang . ' ' . Shop::addSqlRestrictionOnLang('cl') . ') ' . $sql_groups_join . ' WHERE `id_parent` = ' . (int) $id_category . ' ' . ($active ? 'AND `active` = 1' : '') . ' ' . $sql_groups_where . ' GROUP BY c.`id_category` ORDER BY `level_depth` ASC, category_shop.`position` ASC LIMIT ' . (int) $p . ', ' . (int) $n); foreach ($result as &$row) { $row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_ . $row['id_category'] . '.jpg') ? (int) $row['id_category'] : Language::getIsoById($id_lang) . '-default'; $row['legend'] = 'no picture'; } return $result; }
public function setMedia() { parent::setMedia(); $this->addCSS(_PS_MODULE_DIR_ . 'expressmailing/views/css/expressmailing.css'); $this->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js'); $this->addJqueryUI('ui.tabs'); // Try to use employee language for Tiny Editor // -------------------------------------------- $language = new Language($this->context->employee->id_lang); $tiny_file = _PS_MODULE_DIR_ . 'expressmailing/views/js/tinymce_' . $language->iso_code . '.js'; if (Tools::file_exists_cache($tiny_file)) { $this->addJS($tiny_file); } else { $language = new Language(Configuration::get('PS_LANG_DEFAULT')); $tiny_file = _PS_MODULE_DIR_ . 'expressmailing/views/js/tinymce_' . Configuration::get('PS_LANG_DEFAULT') . '.js'; if (Tools::file_exists_cache($tiny_file)) { $this->addJS($tiny_file); } else { $this->addJS(_PS_MODULE_DIR_ . 'expressmailing/views/js/tinymce_en.js'); } } // And add our Tiny config // ----------------------- $this->addJS(_PS_MODULE_DIR_ . 'expressmailing/views/js/tinymce.js'); }
/** * Assign module template * * @param string $template */ public function setTemplate($template) { if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $this->module->name . '/' . $template)) { $this->template = _PS_THEME_DIR_ . 'modules/' . $this->module->name . '/' . $template; } elseif (Tools::file_exists_cache($this->getTemplatePath() . $template)) { $this->template = $this->getTemplatePath() . $template; } else { throw new PrestaShopException("Template '{$template}'' not found"); } }
/** * Finds and returns module front template that take the highest precedence * * @param string $template Template filename * @return string|false */ public function getTemplatePath($template) { if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $this->module->name . '/' . $template)) { return _PS_THEME_DIR_ . 'modules/' . $this->module->name . '/' . $template; } elseif (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $this->module->name . '/views/templates/front/' . $template)) { return _PS_THEME_DIR_ . 'modules/' . $this->module->name . '/views/templates/front/' . $template; } elseif (Tools::file_exists_cache(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/front/' . $template)) { return _PS_MODULE_DIR_ . $this->module->name . '/views/templates/front/' . $template; } return false; }
protected static function _isTemplateOverloadedStatic($module_name, $template) { require_once dirname(__FILE__) . '../../../../modules/designerpreview/defines.inc.php'; if (Tools::file_exists_cache(getThemeDir() . 'modules/' . $module_name . '/' . $template)) { return true; } elseif (Tools::file_exists_cache(_PS_MODULE_DIR_ . $module_name . '/views/templates/hook/' . $template)) { return false; } elseif (Tools::file_exists_cache(_PS_MODULE_DIR_ . $module_name . '/' . $template)) { return false; } return null; }
/** * Fetch a template * * @param string $name template name * @param string $source template source * @param integer $mtime template modification timestamp (epoch) * @return void */ protected function fetch($name, &$source, &$mtime) { foreach ($this->paths as $path) { if (Tools::file_exists_cache($file = $path . $name)) { if (_PS_MODE_DEV_) { $source = implode('', ['<!-- begin ' . $file . ' -->', file_get_contents($file), '<!-- end ' . $file . ' -->']); } else { $source = file_get_contents($file); } $mtime = filemtime($file); return; } } }
public function create($render, $type, $width, $height, $start, $limit, $sort, $dir) { if (!Tools::file_exists_cache($file = dirname(__FILE__) . '/../modules/' . $render . '/' . $render . '.php')) { die(Tools::displayError()); } require_once $file; $this->_render = new $render($type); $this->_start = $start; $this->_limit = $limit; $this->_sort = $sort; $this->_direction = $dir; $this->getData(); $this->_render->setTitle($this->_title); $this->_render->setSize($width, $height); $this->_render->setValues($this->_values); $this->_render->setTotalCount($this->_totalCount); }
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; }
protected function getEmailTemplateContent($template_name, $mail_type, $var) { $email_configuration = Configuration::get('PS_MAIL_TYPE'); if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) { return ''; } $theme_template_path = _PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; $default_mail_template_path = _PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; if (Tools::file_exists_cache($theme_template_path)) { $default_mail_template_path = $theme_template_path; } if (Tools::file_exists_cache($default_mail_template_path)) { $this->context->smarty->assign('list', $var); return $this->context->smarty->fetch($default_mail_template_path); } return ''; }
function deactivate_custom_modules() { $db = Db::getInstance(); $modulesDirOnDisk = array(); $modules = scandir(_PS_MODULE_DIR_); foreach ($modules as $name) { if (is_dir(_PS_MODULE_DIR_ . $name) && Tools::file_exists_cache(_PS_MODULE_DIR_ . $name . '/' . $name . '.php')) { if (!preg_match('/^[a-zA-Z0-9_-]+$/', $name)) { die(Tools::displayError() . ' (Module ' . $name . ')'); } $modulesDirOnDisk[] = $name; } } $module_list_xml = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'modules_list.xml'; $nativeModules = simplexml_load_file($module_list_xml); $nativeModules = $nativeModules->modules; foreach ($nativeModules as $nativeModulesType) { if (in_array($nativeModulesType['type'], array('native', 'partner'))) { $arrNativeModules[] = '""'; foreach ($nativeModulesType->module as $module) { $arrNativeModules[] = '"' . pSQL($module['name']) . '"'; } } } $arrNonNative = $db->ExecuteS(' SELECT * FROM `' . _DB_PREFIX_ . 'module` m WHERE name NOT IN (' . implode(',', $arrNativeModules) . ') '); $uninstallMe = array("undefined-modules"); if (is_array($arrNonNative)) { foreach ($arrNonNative as $aModule) { $uninstallMe[] = $aModule['name']; } } if (!is_array($uninstallMe)) { $uninstallMe = array($uninstallMe); } foreach ($uninstallMe as $k => $v) { $uninstallMe[$k] = '"' . pSQL($v) . '"'; } return Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'module` SET `active`= 0 WHERE `name` IN (' . implode(',', $uninstallMe) . ')'); }
function recurseCopy($src, $dst, $del = false) { $dir = opendir($src); if (!Tools::file_exists_cache($dst)) { mkdir($dst); } while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . DIRECTORY_SEPARATOR . $file)) { recurseCopy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file, $del); } else { copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); if ($del && is_writable($src . DIRECTORY_SEPARATOR . $file)) { unlink($src . DIRECTORY_SEPARATOR . $file); } } } } closedir($dir); if ($del && is_writable($src)) { rmdir($src); } }
function smartyTranslate($params, &$smarty) { /* * Warning : 2 lines have been added to the Smarty class. * "public $currentTemplate = null;" into the class itself * "$this->currentTemplate = substr(basename($resource_name), 0, -4);" into the "display" method */ global $_LANG, $_MODULES, $cookie, $_MODULE; if (!isset($params['js'])) { $params['js'] = 0; } if (!isset($params['mod'])) { $params['mod'] = false; } $msg = false; $string = str_replace('\'', '\\\'', $params['s']); $key = $smarty->currentTemplate . '_' . md5($string); if ($params['mod']) { $iso = Language::getIsoById($cookie->id_lang); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $params['mod'] . '/' . $iso . '.php')) { $translationsFile = _PS_THEME_DIR_ . 'modules/' . $params['mod'] . '/' . $iso . '.php'; $modKey = '<{' . $params['mod'] . '}' . _THEME_NAME_ . '>' . $key; } else { $translationsFile = _PS_MODULE_DIR_ . $params['mod'] . '/' . $iso . '.php'; $modKey = '<{' . $params['mod'] . '}prestashop>' . $key; } if (@(include_once $translationsFile)) { $_MODULES = array_merge($_MODULES, $_MODULE); } $msg = (is_array($_MODULES) and key_exists($modKey, $_MODULES)) ? $params['js'] ? addslashes($_MODULES[$modKey]) : stripslashes($_MODULES[$modKey]) : false; } if (!$msg) { $msg = (is_array($_LANG) and key_exists($key, $_LANG)) ? $params['js'] ? addslashes($_LANG[$key]) : stripslashes($_LANG[$key]) : $params['s']; } return $params['js'] ? $msg : Tools::htmlentitiesUTF8($msg); }
$wishlist->id_shop = $context->shop->id; $wishlist->id_shop_group = $context->shop->id_shop_group; $wishlist->default = 1; $mod_wishlist = new BlockWishList(); $wishlist->name = $mod_wishlist->default_wishlist_name; $wishlist->id_customer = (int) $context->customer->id; list($us, $s) = explode(' ', microtime()); srand($s * $us); $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $context->customer->id), 0, 16)); $wishlist->add(); $context->cookie->id_wishlist = (int) $wishlist->id; } if ($add && $quantity) { WishList::addProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute, $quantity); } else { if ($delete) { WishList::removeProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute); } } } $context->smarty->assign('products', WishList::getProductByIdCustomer($context->cookie->id_wishlist, $context->customer->id, $context->language->id, null, true)); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/blockwishlist-ajax.tpl')) { $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/blockwishlist-ajax.tpl'); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/blockwishlist-ajax.tpl')) { $context->smarty->display(dirname(__FILE__) . '/blockwishlist-ajax.tpl'); } else { echo $module->l('No template found', 'cart'); } } else { echo $module->l('You must be logged in to manage your wishlist.', 'cart'); }
protected static function _isTemplateOverloadedStatic($moduleName, $template) { if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/' . $template)) { return true; } elseif (Tools::file_exists_cache(_PS_MODULE_DIR_ . $moduleName . '/' . $template)) { return false; } return NULL; }
$render = Tools::getValue('render'); $type = Tools::getValue('type'); $option = Tools::getValue('option'); $width = (int) Tools::getValue('width', 600); $height = (int) Tools::getValue('height', 920); $start = (int) Tools::getValue('start', 0); $limit = (int) Tools::getValue('limit', 40); $sort = Tools::getValue('sort', 0); // Should be a String. Default value is an Integer because we don't know what can be the name of the column to sort. $dir = Tools::getValue('dir', 0); // Should be a String : Either ASC or DESC $id_employee = (int) Tools::getValue('id_employee'); $id_lang = (int) Tools::getValue('id_lang'); if (!isset($cookie->id_employee) || !$cookie->id_employee || $cookie->id_employee != $id_employee) { die(Tools::displayError()); } if (!Validate::isModuleName($module)) { die(Tools::displayError()); } if (!Tools::file_exists_cache($module_path = dirname(__FILE__) . '/../modules/' . $module . '/' . $module . '.php')) { die(Tools::displayError()); } require_once $module_path; $grid = new $module(); $grid->setEmployee($id_employee); $grid->setLang($id_lang); if ($option) { $grid->setOption($option); } $grid->create($render, $type, $width, $height, $start, $limit, $sort, $dir); $grid->render();
Mail::Send($context->language->id, 'wishlink', Mail::l('Your wishlist\'s link', $context->language->id), array('{wishlist}' => $wishlist->name, '{message}' => Tools::getProtocol() . htmlentities($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/blockwishlist/view.php?token=' . $wishlist->token), $context->customer->email, $context->customer->firstname . ' ' . $context->customer->lastname, NULL, strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/'); } } } else { if ($add) { WishList::addCardToWishlist($context->customer->id, Tools::getValue('id_wishlist'), $context->language->id); } else { if ($delete and empty($id_wishlist) === false) { $wishlist = new WishList((int) $id_wishlist); if (Validate::isLoadedObject($wishlist)) { $wishlist->delete(); } else { $errors[] = $module->l('Cannot delete this wishlist', 'mywishlist'); } } } } $context->smarty->assign('wishlists', WishList::getByIdCustomer($context->customer->id)); $context->smarty->assign('nbProducts', WishList::getInfosByIdCustomer($context->customer->id)); } else { Tools::redirect('index.php?controller=authentication&back=modules/blockwishlist/mywishlist.php'); } $context->smarty->assign(array('id_customer' => (int) $context->customer->id, 'errors' => $errors)); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/mywishlist.tpl')) { $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/mywishlist.tpl'); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/views/templates/front/mywishlist.tpl')) { $context->smarty->display(dirname(__FILE__) . '/views/templates/front/mywishlist.tpl'); } else { echo $module->l('No template found', 'mywishlist'); } include dirname(__FILE__) . '/../../footer.php';
protected function getSubjectMailContent($directory) { $subject_mail_content = array(); if (Tools::file_exists_cache($directory . '/lang.php')) { // we need to include this even if already included include $directory . '/lang.php'; foreach ($_LANGMAIL as $key => $subject) { $subject = str_replace("\n", " ", $subject); $subject = str_replace("\\'", "\\'", $subject); $subject_mail_content[$key] = htmlentities($subject, ENT_QUOTES, 'UTF-8'); } } else { $this->_errors[] = $this->l('Subject mail translation file not found in') . ' ' . $directory; } return $subject_mail_content; }
/** * Assign smarty variables for the header */ public function initHeader() { header('Cache-Control: no-store, no-cache'); // Multishop $is_multishop = Shop::isFeatureActive(); // Quick access $quick_access = QuickAccess::getQuickAccesses($this->context->language->id); foreach ($quick_access as $index => $quick) { if ($quick['link'] == '../' && Shop::getContext() == Shop::CONTEXT_SHOP) { $url = $this->context->shop->getBaseURL(); if (!$url) { unset($quick_access[$index]); continue; } $quick_access[$index]['link'] = $url; } else { preg_match('/controller=(.+)(&.+)?$/', $quick['link'], $admin_tab); if (isset($admin_tab[1])) { if (strpos($admin_tab[1], '&')) { $admin_tab[1] = substr($admin_tab[1], 0, strpos($admin_tab[1], '&')); } $token = Tools::getAdminToken($admin_tab[1] . (int) Tab::getIdFromClassName($admin_tab[1]) . (int) $this->context->employee->id); $quick_access[$index]['target'] = $admin_tab[1]; $quick_access[$index]['link'] .= '&token=' . $token; } } } //$link = preg_replace('/&token=[a-z0-9]{32}/', '', basename($_SERVER['REQUEST_URI'])); //$currentPage = 'index.php?controller='.$this->context->controller->controller_name."&".$this->display.$this->table; // Tab list $tabs = Tab::getTabs($this->context->language->id, 0); $current_id = Tab::getCurrentParentId(); foreach ($tabs as $index => $tab) { if (!Tab::checkTabRights($tab['id_tab']) || $tab['class_name'] == 'AdminStock' && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 0 || $tab['class_name'] == 'AdminCarrierWizard') { unset($tabs[$index]); continue; } $img_cache_url = 'themes/' . $this->context->employee->bo_theme . '/img/t/' . $tab['class_name'] . '.png'; $img_exists_cache = Tools::file_exists_cache(_PS_ADMIN_DIR_ . $img_cache_url); // retrocompatibility : change png to gif if icon not exists if (!$img_exists_cache) { $img_exists_cache = Tools::file_exists_cache(_PS_ADMIN_DIR_ . str_replace('.png', '.gif', $img_cache_url)); } if ($img_exists_cache) { $path_img = $img = $img_exists_cache; } else { $path_img = _PS_IMG_DIR_ . 't/' . $tab['class_name'] . '.png'; // Relative link will always work, whatever the base uri set in the admin $img = '../img/t/' . $tab['class_name'] . '.png'; } if (trim($tab['module']) != '') { $path_img = _PS_MODULE_DIR_ . $tab['module'] . '/' . $tab['class_name'] . '.png'; // Relative link will always work, whatever the base uri set in the admin $img = '../modules/' . $tab['module'] . '/' . $tab['class_name'] . '.png'; } // retrocompatibility if (!file_exists($path_img)) { $img = str_replace('png', 'gif', $img); } // tab[class_name] does not contains the "Controller" suffix $tabs[$index]['current'] = $tab['class_name'] . 'Controller' == get_class($this) || $current_id == $tab['id_tab']; $tabs[$index]['img'] = $img; $tabs[$index]['href'] = $this->context->link->getAdminLink($tab['class_name']); $sub_tabs = Tab::getTabs($this->context->language->id, $tab['id_tab']); foreach ($sub_tabs as $index2 => $sub_tab) { //check if module is enable and if (isset($sub_tab['module']) && !empty($sub_tab['module'])) { $module = Module::getInstanceByName($sub_tab['module']); if (is_object($module) && !$module->isEnabledForShopContext()) { unset($sub_tabs[$index2]); continue; } } if (Tab::checkTabRights($sub_tab['id_tab']) === true && (bool) $sub_tab['active'] && $sub_tab['class_name'] != 'AdminCarrierWizard') { $sub_tabs[$index2]['href'] = $this->context->link->getAdminLink($sub_tab['class_name']); $sub_tabs[$index2]['current'] = $sub_tab['class_name'] . 'Controller' == get_class($this) || $sub_tab['class_name'] == Tools::getValue('controller'); } elseif ($sub_tab['class_name'] == 'AdminCarrierWizard' && $sub_tab['class_name'] . 'Controller' == get_class($this)) { foreach ($sub_tabs as $i => $tab) { if ($tab['class_name'] == 'AdminCarriers') { break; } } $sub_tabs[$i]['current'] = true; unset($sub_tabs[$index2]); } else { unset($sub_tabs[$index2]); } } $tabs[$index]['sub_tabs'] = $sub_tabs; } if (Validate::isLoadedObject($this->context->employee)) { $accesses = Profile::getProfileAccesses($this->context->employee->id_profile, 'class_name'); /* Hooks are volontary out the initialize array (need those variables already assigned) */ $bo_color = empty($this->context->employee->bo_color) ? '#FFFFFF' : $this->context->employee->bo_color; $this->context->smarty->assign(array('autorefresh_notifications' => Configuration::get('PS_ADMINREFRESH_NOTIFICATION'), 'help_box' => Configuration::get('PS_HELPBOX'), 'round_mode' => Configuration::get('PS_PRICE_ROUND_MODE'), 'brightness' => Tools::getBrightness($bo_color) < 128 ? 'white' : '#383838', 'bo_width' => (int) $this->context->employee->bo_width, 'bo_color' => isset($this->context->employee->bo_color) ? Tools::htmlentitiesUTF8($this->context->employee->bo_color) : null, 'show_new_orders' => Configuration::get('PS_SHOW_NEW_ORDERS') && isset($accesses['AdminOrders']) && $accesses['AdminOrders']['view'], 'show_new_customers' => Configuration::get('PS_SHOW_NEW_CUSTOMERS') && isset($accesses['AdminCustomers']) && $accesses['AdminCustomers']['view'], 'show_new_messages' => Configuration::get('PS_SHOW_NEW_MESSAGES') && isset($accesses['AdminCustomerThreads']) && $accesses['AdminCustomerThreads']['view'], 'employee' => $this->context->employee, 'search_type' => Tools::getValue('bo_search_type'), 'bo_query' => Tools::safeOutput(Tools::stripslashes(Tools::getValue('bo_query'))), 'quick_access' => $quick_access, 'multi_shop' => Shop::isFeatureActive(), 'shop_list' => Helper::renderShopList(), 'shop' => $this->context->shop, 'shop_group' => new ShopGroup((int) Shop::getContextShopGroupID()), 'current_parent_id' => (int) Tab::getCurrentParentId(), 'tabs' => $tabs, 'is_multishop' => $is_multishop, 'multishop_context' => $this->multishop_context, 'default_tab_link' => $this->context->link->getAdminLink(Tab::getClassNameById((int) Context::getContext()->employee->default_tab)), 'collapse_menu' => isset($this->context->cookie->collapse_menu) ? (int) $this->context->cookie->collapse_menu : 0)); } else { $this->context->smarty->assign('default_tab_link', $this->context->link->getAdminLink('AdminDashboard')); } // Shop::initialize() in config.php may empty $this->context->shop->virtual_uri so using a new shop instance for getBaseUrl() $this->context->shop = new Shop((int) $this->context->shop->id); $this->context->smarty->assign(array('img_dir' => _PS_IMG_, 'iso' => $this->context->language->iso_code, 'class_name' => $this->className, 'iso_user' => $this->context->language->iso_code, 'country_iso_code' => $this->context->country->iso_code, 'version' => _PS_VERSION_, 'lang_iso' => $this->context->language->iso_code, 'full_language_code' => $this->context->language->language_code, 'link' => $this->context->link, 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'base_url' => $this->context->shop->getBaseURL(), 'tab' => isset($tab) ? $tab : null, 'current_parent_id' => (int) Tab::getCurrentParentId(), 'tabs' => $tabs, 'install_dir_exists' => file_exists(_PS_ADMIN_DIR_ . '/../install'), 'pic_dir' => _THEME_PROD_PIC_DIR_, 'controller_name' => htmlentities(Tools::getValue('controller')), 'currentIndex' => self::$currentIndex, 'bootstrap' => $this->bootstrap, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'display_addons_connection' => Tab::checkTabRights(Tab::getIdFromClassName('AdminModulesController')))); $module = Module::getInstanceByName('themeconfigurator'); $lang = ''; if (Configuration::get('PS_REWRITING_SETTINGS') && count(Language::getLanguages(true)) > 1) { $lang = Language::getIsoById($this->context->employee->id_lang) . '/'; } if (is_object($module) && $module->active && (int) Configuration::get('PS_TC_ACTIVE') == 1 && $this->context->shop->getBaseURL()) { $this->context->smarty->assign('base_url_tc', $this->context->shop->getBaseUrl() . (Configuration::get('PS_REWRITING_SETTINGS') ? '' : 'index.php') . $lang . '?live_configurator_token=' . $module->getLiveConfiguratorToken() . '&id_employee=' . (int) $this->context->employee->id . '&id_shop=' . (int) $this->context->shop->id . (Configuration::get('PS_TC_THEME') != '' ? '&theme=' . Configuration::get('PS_TC_THEME') : '') . (Configuration::get('PS_TC_FONT') != '' ? '&theme_font=' . Configuration::get('PS_TC_FONT') : '')); } }
$height = (int) Tools::getValue('height', 920); $start = (int) Tools::getValue('start', 0); $limit = (int) Tools::getValue('limit', 40); $sort = Tools::getValue('sort', 0); // Should be a String. Default value is an Integer because we don't know what can be the name of the column to sort. $dir = Tools::getValue('dir', 0); // Should be a String : Either ASC or DESC $id_employee = (int) Tools::getValue('id_employee'); $id_lang = (int) Tools::getValue('id_lang'); if (!isset($cookie->id_employee) || !$cookie->id_employee || $cookie->id_employee != $id_employee) { die(Tools::displayError()); } if (!Validate::isModuleName($module)) { die(Tools::displayError()); } if (!Tools::file_exists_cache($module_path = _PS_ROOT_DIR_ . '/modules/' . $module . '/' . $module . '.php')) { die(Tools::displayError()); } $shop_id = ''; Shop::setContext(Shop::CONTEXT_ALL); if (Context::getContext()->cookie->shopContext) { $split = explode('-', Context::getContext()->cookie->shopContext); if (count($split) == 2) { if ($split[0] == 'g') { if (Context::getContext()->employee->hasAuthOnShopGroup($split[1])) { Shop::setContext(Shop::CONTEXT_GROUP, $split[1]); } else { $shop_id = Context::getContext()->employee->getDefaultShopID(); Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); } } else {
function smartyTranslate($params, &$smarty) { /* * Warning in Smarty-v2 : 2 lines have been added to the Smarty class. * "public $currentTemplate = null;" into the class itself * "$this->currentTemplate = Tools::substr(basename($resource_name), 0, -4);" into the "fetch" method * Notice : before 1.4.2.5, this modification was in the display method * * In Smarty-v3 : No modifications, using the existing var $this->smarty->_current_file instead */ global $_LANG, $_MODULES, $cookie, $_MODULE; if (!isset($params['js'])) { $params['js'] = 0; } if (!isset($params['mod'])) { $params['mod'] = false; } $string = str_replace('\'', '\\\'', $params['s']); $key = ''; if (Configuration::get('PS_FORCE_SMARTY_2')) { /* Keep a backward compatibility for Smarty v2 */ $key = $smarty->currentTemplate . '_' . md5($string); } else { $filename = (!isset($smarty->compiler_object) or !is_object($smarty->compiler_object->template)) ? $smarty->template_filepath : $smarty->compiler_object->template->getTemplateFilepath(); $key = Tools::substr(basename($filename), 0, -4) . '_' . md5($string); } $lang_array = $_LANG; if ($params['mod']) { $iso = Language::getIsoById($cookie->id_lang); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $params['mod'] . '/' . $iso . '.php')) { $translationsFile = _PS_THEME_DIR_ . 'modules/' . $params['mod'] . '/' . $iso . '.php'; $key = '<{' . $params['mod'] . '}' . _THEME_NAME_ . '>' . $key; } else { $translationsFile = _PS_MODULE_DIR_ . $params['mod'] . '/' . $iso . '.php'; $key = '<{' . $params['mod'] . '}prestashop>' . $key; } if (!is_array($_MODULES)) { $_MODULES = array(); } if (@(include_once $translationsFile)) { if (is_array($_MODULE)) { $_MODULES = array_merge($_MODULES, $_MODULE); } } $lang_array = $_MODULES; } if (is_array($lang_array) and key_exists($key, $lang_array)) { $msg = $lang_array[$key]; } elseif (is_array($lang_array) and key_exists(Tools::strtolower($key), $lang_array)) { $msg = $lang_array[Tools::strtolower($key)]; } else { $msg = $params['s']; } if ($msg != $params['s']) { $msg = $params['js'] ? addslashes($msg) : stripslashes($msg); } return $params['js'] ? $msg : Tools::htmlentitiesUTF8($msg); }
} if (!isset($products[$i]['cover'])) { $products[$i]['cover'] = $context->language->iso_code . '-default'; } } $products[$i]['bought'] = false; for ($j = 0, $k = 0; $j < sizeof($bought); ++$j) { if ($bought[$j]['id_product'] == $products[$i]['id_product'] and $bought[$j]['id_product_attribute'] == $products[$i]['id_product_attribute']) { $products[$i]['bought'][$k++] = $bought[$j]; } } } $productBoughts = array(); foreach ($products as $product) { if (sizeof($product['bought'])) { $productBoughts[] = $product; } } $context->smarty->assign(array('products' => $products, 'productsBoughts' => $productBoughts, 'id_wishlist' => $id_wishlist, 'refresh' => $refresh, 'token_wish' => $wishlist->token)); // Instance of module class for translations $module = new BlockWishList(); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/managewishlist.tpl')) { $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/managewishlist.tpl'); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/managewishlist.tpl')) { $context->smarty->display(dirname(__FILE__) . '/managewishlist.tpl'); } else { echo $module->l('No template found', 'managewishlist'); } } } }
/** * This method is used to get the translation for email Object. * For an object is forbidden to use htmlentities, * we have to return a sentence with accents. * * @param string $string raw sentence (write directly in file) */ public static function l($string, $id_lang = null, Context $context = null) { global $_LANGMAIL; if (!$context) { $context = Context::getContext(); } $key = str_replace('\'', '\\\'', $string); if ($id_lang == null) { $id_lang = !isset($context->language) || !is_object($context->language) ? (int) Configuration::get('PS_LANG_DEFAULT') : (int) $context->language->id; } $iso_code = Language::getIsoById((int) $id_lang); $file_core = _PS_ROOT_DIR_ . '/mails/' . $iso_code . '/lang.php'; if (Tools::file_exists_cache($file_core) && empty($_LANGMAIL)) { include_once $file_core; } $file_theme = _PS_THEME_DIR_ . 'mails/' . $iso_code . '/lang.php'; if (Tools::file_exists_cache($file_theme)) { include_once $file_theme; } if (!is_array($_LANGMAIL)) { return str_replace('"', '"', $string); } if (array_key_exists($key, $_LANGMAIL) && !empty($_LANGMAIL[$key])) { $str = $_LANGMAIL[$key]; } else { $str = $string; } return str_replace('"', '"', stripslashes($str)); }
/* SSL Management */ $useSSL = true; include dirname(__FILE__) . '/../../config/config.inc.php'; include dirname(__FILE__) . '/../../header.php'; include_once dirname(__FILE__) . '/mailalerts.php'; // Instance of module class for translations $module = new MailAlerts(); $errors = array(); if ($cookie->isLogged()) { if (Tools::getValue('action') == 'delete') { $id_customer = (int) $cookie->id_customer; if (!($id_product = (int) Tools::getValue('id_product'))) { $errors[] = $module->l('You must have a product to delete an alert.', 'mailalerts-account'); } $id_product_attribute = (int) Tools::getValue('id_product_attribute'); $customer = new Customer((int) $id_customer); MailAlerts::deleteAlert((int) $id_customer, strval($customer->email), (int) $id_product, (int) $id_product_attribute); } $this->context->smarty->assign('mailAlerts', MailAlert::getProductsAlerts((int) $cookie->id_customer, (int) $cookie->id_lang)); } else { $errors[] = $module->l('You must be logged in to manage your alerts.', 'mailalerts-account'); } $this->context->smarty->assign(array('id_customer' => (int) $cookie->id_customer, 'errors' => $errors)); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/mailalerts/myalerts.tpl')) { $smarty->display(_PS_THEME_DIR_ . 'modules/mailalerts/myalerts.tpl'); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/myalerts.tpl')) { $smarty->display(dirname(__FILE__) . '/myalerts.tpl'); } else { echo $module->l('No template found', 'mailalerts-account'); } include dirname(__FILE__) . '/../../footer.php';
public static function display($file, $template, $cacheId = NULL, $compileId = NULL) { if (substr(_PS_VERSION_, 0, 3) != '1.3') { return parent::display($file, $template); } global $smarty; $previousTemplate = $smarty->currentTemplate; $smarty->currentTemplate = substr(basename($template), 0, -4); $smarty->assign('module_dir', __PS_BASE_URI__ . 'modules/' . basename($file, '.php') . '/'); if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . basename($file, '.php') . '/' . $template)) { $smarty->assign('module_template_dir', _THEME_DIR_ . 'modules/' . basename($file, '.php') . '/'); $result = $smarty->fetch(_PS_THEME_DIR_ . 'modules/' . basename($file, '.php') . '/' . $template); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/' . $template)) { $smarty->assign('module_template_dir', __PS_BASE_URI__ . 'modules/' . basename($file, '.php') . '/'); $result = $smarty->fetch(dirname(__FILE__) . '/' . $template); } else { $result = Tools::displayError('No template found'); } $smarty->currentTemplate = $previousTemplate; return $result; }
continue; } else { if ($products[$i]['id_product_attribute'] != 0 && isset($combination_imgs[$products[$i]['id_product_attribute']][0])) { $combination_imgs = $obj->getCombinationImages((int) $cookie->id_lang); $products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image']; } else { $images = $obj->getImages((int) $cookie->id_lang); foreach ($images as $k => $image) { if ($image['cover']) { $products[$i]['cover'] = $obj->id . '-' . $image['id_image']; break; } } if (!isset($products[$i]['cover'])) { $products[$i]['cover'] = Language::getIsoById((int) $cookie->id_lang) . '-default'; } } } } WishList::incCounter((int) $wishlist['id_wishlist']); $ajax = Configuration::get('PS_BLOCK_CART_AJAX'); $smarty->assign(array('current_wishlist' => $wishlist, 'token' => $token, 'ajax' => (isset($ajax) and (int) $ajax == 1) ? '1' : '0', 'wishlists' => WishList::getByIdCustomer((int) $wishlist['id_customer']), 'products' => $products)); } if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl')) { $smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl'); } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/view.tpl')) { $smarty->display(dirname(__FILE__) . '/view.tpl'); } else { echo Tools::displayError('No template found'); } require dirname(__FILE__) . '/../../footer.php';
public function hookActionWatermark($params) { $image = new Image($params['id_image']); $image->id_product = $params['id_product']; $file = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-watermark.jpg'; $str_shop = '-' . (int) $this->context->shop->id; if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__) . '/watermark' . $str_shop . '.gif')) { $str_shop = ''; } //first make a watermark image $return = $this->watermarkByImage(_PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.jpg', dirname(__FILE__) . '/watermark' . $str_shop . '.gif', $file, 23, 0, 0, 'right'); //go through file formats defined for watermark and resize them foreach ($this->imageTypes as $imageType) { $newFile = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg'; if (!ImageManager::resize($file, $newFile, (int) $imageType['width'], (int) $imageType['height'])) { $return = false; } } return $return; }
public function create($render, $type, $width, $height, $layers) { if (!Validate::isModuleName($render)) { die(Tools::displayError()); } if (!Tools::file_exists_cache($file = _PS_ROOT_DIR_ . '/modules/' . $render . '/' . $render . '.php')) { die(Tools::displayError()); } require_once $file; $this->_render = new $render($type); $this->getData($layers); $this->_render->createValues($this->_values); $this->_render->setSize($width, $height); $this->_render->setLegend($this->_legend); $this->_render->setTitles($this->_titles); }
public function setMedia() { // if website is accessed by mobile device // @see FrontControllerCore::setMobileMedia() if ($this->context->getMobileDevice() != false) { $this->setMobileMedia(); return true; } if (Tools::file_exists_cache(_PS_ROOT_DIR_ . Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, _THEME_CSS_DIR_ . 'grid_prestashop.css'))) { $this->addCSS(_THEME_CSS_DIR_ . 'grid_prestashop.css', 'all'); } $this->addCSS(_THEME_CSS_DIR_ . 'global.css', 'all'); $this->addjquery(); $this->addjqueryPlugin('easing'); $this->addJS(_PS_JS_DIR_ . 'tools.js'); if (Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getAdminToken('AdminModulesPositions' . (int) Tab::getIdFromClassName('AdminModulesPositions') . (int) Tools::getValue('id_employee'))) { $this->addJqueryUI('ui.sortable'); $this->addjqueryPlugin('fancybox'); $this->addJS(_PS_JS_DIR_ . 'hookLiveEdit.js'); $this->addCSS(_PS_CSS_DIR_ . 'jquery.fancybox-1.3.4.css', 'all'); // @TODO } if ($this->context->language->is_rtl) { $this->addCSS(_THEME_CSS_DIR_ . 'rtl.css'); } // Execute Hook FrontController SetMedia Hook::exec('actionFrontControllerSetMedia', array()); }
public static function getTemplateFile($template, $moduleName = '') { $context = Context::getContext(); $templatedir = trim(Configuration::get('OVIC_CURRENT_DIR', null, null, $context->shop->id)); if ($moduleName && $moduleName != '') { if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/views/templates/front/' . $templatedir . '/' . $template)) { return _PS_THEME_DIR_ . 'modules/' . $moduleName . '/views/templates/front/' . $templatedir . '/' . $template; } elseif (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/views/templates/hook/' . $templatedir . '/' . $template)) { return _PS_THEME_DIR_ . 'modules/' . $moduleName . '/views/templates/hook/' . $templatedir . '/' . $template; } elseif (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/' . $templatedir . '/' . $template)) { return _PS_THEME_DIR_ . 'modules/' . $moduleName . '/' . $templatedir . '/' . $template; } } else { if (Tools::file_exists_cache(_PS_THEME_DIR_ . $templatedir . '_' . $template)) { return _PS_THEME_DIR_ . $templatedir . '_' . $template; } } return null; }