/** * Return hook ID from name * * @param string $hookName Hook name * @return integer Hook ID */ public static function get($hookName) { if (!Validate::isHookName($hookName)) { die(Tools::displayError()); } $result = Db::getInstance()->GetRow(' SELECT `id_hook`, `name` FROM `' . _DB_PREFIX_ . 'hook` WHERE `name` = \'' . pSQL($hookName) . '\''); return $result ? $result['id_hook'] : false; }
/** * remove a module from a hook */ public function ajaxProcessremoveModuleHook() { $result = array(); $hookname = Tools::getValue('hookname'); $id_option = (int) Tools::getValue('id_option'); $option = new Options($id_option); $hookexec_name = Tools::getValue('hookexec_name'); $module_name = Tools::getValue('module_name'); if ($option && Validate::isLoadedObject($option) && $module_name && Validate::isModuleName($module_name) && $hookname && Validate::isHookName($hookname) && $hookexec_name && Validate::isHookName($hookexec_name)) { $HookedModulesArr = OvicLayoutControl::getModulesHook($option->theme, $option->alias, $hookname); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); $HookedModulesArr = array_values($HookedModulesArr); $moduleHook = array(); $moduleHook[] = $module_name; $moduleHook[] = $hookexec_name; if ($HookedModulesArr && is_array($HookedModulesArr) && sizeof($HookedModulesArr)) { $key = array_search($moduleHook, $HookedModulesArr); unset($HookedModulesArr[$key]); } $HookedModulesArr = array_values($HookedModulesArr); $result['status'] = OvicLayoutControl::registerHookModule($option, $hookname, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); $result['msg'] = $this->l('Successful deletion'); //$this->displayError } Tools::clearCache(); die(Tools::jsonEncode($result)); }
public function hookactionModuleUnRegisterHookAfter($params) { if (!Validate::isHookName($params['hook_name'])) { return; } if (Configuration::get('BLA_ISLOG_MODUREG')) { self::logObjectEvent('Unregister Hook ' . $params['hook_name'], $params['object']); } }
public static function hookExec($hook_name, $hookArgs = array(), $id_module = NULL) { global $cookie; if (!empty($id_module) and !Validate::isUnsignedId($id_module) or !Validate::isHookName($hook_name)) { die(Tools::displayError()); } global $cart, $cookie; $live_edit = false; if (!isset($hookArgs['cookie']) or !$hookArgs['cookie']) { $hookArgs['cookie'] = $cookie; } if (!isset($hookArgs['cart']) or !$hookArgs['cart']) { $hookArgs['cart'] = $cart; } $hook_name = strtolower($hook_name); if (!isset(self::$_hookModulesCache)) { $db = Db::getInstance(_PS_USE_SQL_SLAVE_); $result = $db->ExecuteS(' SELECT h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit` FROM `' . _DB_PREFIX_ . 'module` m LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook` AND m.`active` = 1 ORDER BY hm.`position`', false); self::$_hookModulesCache = array(); if ($result) { while ($row = $db->nextRow()) { $row['hook'] = strtolower($row['hook']); if (!isset(self::$_hookModulesCache[$row['hook']])) { self::$_hookModulesCache[$row['hook']] = array(); } self::$_hookModulesCache[$row['hook']][] = array('id_hook' => $row['id_hook'], 'module' => $row['module'], 'id_module' => $row['id_module'], 'live_edit' => $row['live_edit']); } } } if (!isset(self::$_hookModulesCache[$hook_name])) { return; } $altern = 0; $output = ''; foreach (self::$_hookModulesCache[$hook_name] as $array) { if ($id_module and $id_module != $array['id_module']) { continue; } if (!($moduleInstance = Module::getInstanceByName($array['module']))) { continue; } $exceptions = $moduleInstance->getExceptions((int) $array['id_hook'], (int) $array['id_module']); foreach ($exceptions as $exception) { if (strstr(basename($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING'], $exception['file_name']) && !strstr($_SERVER['QUERY_STRING'], $exception['file_name'])) { continue 2; } } if (is_callable(array($moduleInstance, 'hook' . $hook_name))) { $hookArgs['altern'] = ++$altern; $display = call_user_func(array($moduleInstance, 'hook' . $hook_name), $hookArgs); if ($array['live_edit'] && (Tools::isSubmit('live_edit') and Tools::getValue('ad') and Tools::getValue('liveToken') == sha1(Tools::getValue('ad') . _COOKIE_KEY_))) { $live_edit = true; $output .= '<script type="text/javascript"> modules_list.push(\'' . $moduleInstance->name . '\');</script> <div id="hook_' . $array['id_hook'] . '_module_' . $moduleInstance->id . '_moduleName_' . $moduleInstance->name . '" class="dndModule" style="border: 1px dotted red;' . (!strlen($display) ? 'height:50px;' : '') . '"> <span><img src="' . $moduleInstance->_path . '/logo.gif">' . $moduleInstance->displayName . '<span style="float:right"> <a href="#" id="' . $array['id_hook'] . '_' . $moduleInstance->id . '" class="moveModule"> <img src="' . _PS_ADMIN_IMG_ . 'arrow_out.png"></a> <a href="#" id="' . $array['id_hook'] . '_' . $moduleInstance->id . '" class="unregisterHook"> <img src="' . _PS_ADMIN_IMG_ . 'delete.gif"></span></a> </span>' . $display . '</div>'; } else { $output .= $display; } } } return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\'); </script><!--<div id="add_' . $hook_name . '" class="add_module_live_edit"> <a class="exclusive" href="#">Add a module</a></div>--><div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $output . ($live_edit ? '</div>' : ''); }
public function hookactionModuleRegisterHookAfter($params) { $module = $params['object']; $current_theme = Theme::getThemeInfo($this->context->shop->id_theme); if (!$this->IsOvicThemes($current_theme['theme_name'])) { return; } if ($module->name != $this->name) { $hook_name = $params['hook_name']; if ($hook_name && Validate::isHookName($hook_name)) { $id_hook = Hook::getIdByName($hook_name); $hook_name = Hook::getNameById($id_hook); // get full hookname //order possition hook $id_hook_header = Hook::getIdByName('Header'); if ($id_hook && $id_hook === $id_hook_header) { $this->changeHeaderPosition(); } if (in_array($hook_name, self::$OptionHookAssign)) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', true); } elseif (in_array($hook_name, self::getHookexecuteList())) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', false); } else { return; } $id_shop = (int) $this->context->shop->id; $current_id_option = Configuration::get('OVIC_CURRENT_OPTION', null, null, $id_shop); $current_option = new Options($current_id_option); $moduleHook = array(); $moduleHook[] = $module->name; $moduleHook[] = $hook_name; if ($current_option && Validate::isLoadedObject($current_option)) { //insert module to current option $HookedModulesArr = self::getModulesHook($current_option->theme, $current_option->alias, $hook_name); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerHookModule($current_option, $hook_name, Tools::jsonEncode($HookedModulesArr), $id_shop); } } $pagelist = Meta::getMetas(); $sidebarPages = array(); $theme = new Theme((int) $this->context->shop->id_theme); if ($hook_name == 'displayLeftColumn' || $hook_name == 'displayRightColumn') { foreach ($pagelist as $page) { if ($hook_name == 'displayLeftColumn' && $theme->hasLeftColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'left', false); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'left', Tools::jsonEncode($HookedModulesArr), $id_shop); } } if ($hook_name == 'displayRightColumn' && $theme->hasRightColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'right', false); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'right', Tools::jsonEncode($HookedModulesArr), $id_shop); } } } } } } }
public function getModuleAssign($module_name = '', $hook_name = '') { $module = Module::getInstanceByName($module_name); if (_PS_VERSION_ <= "1.5") { $id_hook = Hook::get($hook_name); } else { $id_hook = Hook::getIdByName($hook_name); } if (Validate::isLoadedObject($module) && $module->id) { if (!isset($hookArgs['cookie']) or !$hookArgs['cookie']) { $hookArgs['cookie'] = $this->context->cookie; } if (!isset($hookArgs['cart']) or !$hookArgs['cart']) { $hookArgs['cart'] = $this->context->cart; } if (_PS_VERSION_ < "1.5") { //return self::lofHookExec( $hook_name, array(), $module->id, $array ); $hook_name = strtolower($hook_name); if (!Validate::isHookName($hook_name)) { die(Tools::displayError()); } $altern = 0; if (is_callable(array($module, 'hook' . $hook_name))) { $hookArgs['altern'] = ++$altern; $output = call_user_func(array($module, 'hook' . $hook_name), $hookArgs); } return $output; } else { $hook_name = substr($hook_name, 7, strlen($hook_name)); if (!Validate::isHookName($hook_name)) { die(Tools::displayError()); } $retro_hook_name = Hook::getRetroHookName($hook_name); $hook_callable = is_callable(array($module, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($module, 'hook' . $retro_hook_name)); $output = ''; if (($hook_callable || $hook_retro_callable) && Module::preCall($module->name)) { if ($hook_callable) { $output = $module->{'hook' . $hook_name}($hookArgs); } else { if ($hook_retro_callable) { $output = $module->{'hook' . $retro_hook_name}($hookArgs); } } } return $output; } } return ''; }
/** * Connect module to a hook * * @param string $hook_name Hook name * @param array $shop_list List of shop linked to the hook (if null, link hook to all shops) * @return boolean result */ public function registerHook($hook_name, $shop_list = null) { // Check hook name validation and if module is installed if (!Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid hook name'); } if (!isset($this->id) || !is_numeric($this->id)) { return false; } // Retrocompatibility $hook_name_bak = $hook_name; if ($alias = Hook::getRetroHookName($hook_name)) { $hook_name = $alias; } Hook::exec('actionModuleRegisterHookBefore', array('object' => $this, 'hook_name' => $hook_name)); // Get hook id $id_hook = Hook::getIdByName($hook_name); $live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak)); // If hook does not exist, we create it if (!$id_hook) { $new_hook = new Hook(); $new_hook->name = pSQL($hook_name); $new_hook->title = pSQL($hook_name); $new_hook->live_edit = pSQL($live_edit); $new_hook->add(); $id_hook = $new_hook->id; if (!$id_hook) { return false; } } // If shop lists is null, we fill it with all shops if (is_null($shop_list)) { $shop_list = Shop::getShops(true, null, true); } $return = true; foreach ($shop_list as $shop_id) { // Check if already register $sql = 'SELECT hm.`id_module` FROM `' . _DB_PREFIX_ . 'hook_module` hm, `' . _DB_PREFIX_ . 'hook` h WHERE hm.`id_module` = ' . (int) $this->id . ' AND h.`id_hook` = ' . $id_hook . ' AND h.`id_hook` = hm.`id_hook` AND `id_shop` = ' . (int) $shop_id; if (Db::getInstance()->getRow($sql)) { continue; } // Get module position in hook $sql = 'SELECT MAX(`position`) AS position FROM `' . _DB_PREFIX_ . 'hook_module` WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id; if (!($position = Db::getInstance()->getValue($sql))) { $position = 0; } // Register module in hook $return &= Db::getInstance()->insert('hook_module', array('id_module' => (int) $this->id, 'id_hook' => (int) $id_hook, 'id_shop' => (int) $shop_id, 'position' => (int) ($position + 1))); } Hook::exec('actionModuleRegisterHookAfter', array('object' => $this, 'hook_name' => $hook_name)); return $return; }
public function hookactionModuleRegisterHookAfter($params) { $module = $params['object']; if ($module->name != $this->name) { $hook_name = $params['hook_name']; if ($hook_name && Validate::isHookName($hook_name)) { $id_hook = Hook::getIdByName($hook_name); $hook_name = Hook::getNameById($id_hook); if (in_array($hook_name, self::$OptionHookAssign)) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', true); } elseif (in_array($hook_name, self::getHookexecuteList())) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', false); } $id_shop = $this->context->shop->id; $current_id_option = Configuration::get('OVIC_CURRENT_OPTION'); $moduleHook = array(); $moduleHook[] = $module->name; $moduleHook[] = $hook_name; if ($current_id_option && Validate::isUnsignedId($current_id_option)) { //insert module to current option $HookedModulesArr = self::getModulesHook($current_id_option, $hook_name); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if (!array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerHookModule($current_id_option, $hook_name, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } } $pagelist = Meta::getMetas(); $sidebarPages = array(); $theme = new Theme((int) $this->context->shop->id_theme); if ($hook_name == 'displayLeftColumn' || $hook_name == 'displayRightColumn') { foreach ($pagelist as $page) { if ($hook_name == 'displayLeftColumn' && $theme->hasLeftColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'left', false); $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'left', Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } if ($hook_name == 'displayRightColumn' && $theme->hasRightColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'right', false); $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'right', Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } } } } } }
public static function hookExec($hook_name, $hookArgs = array(), $id_module = NULL) { if (!empty($id_module) and !Validate::isUnsignedId($id_module) or !Validate::isHookName($hook_name)) { die(Tools::displayError()); } global $cart, $cookie; $altern = 0; if (!isset($hookArgs['cookie']) or !$hookArgs['cookie']) { $hookArgs['cookie'] = $cookie; } if (!isset($hookArgs['cart']) or !$hookArgs['cart']) { $hookArgs['cart'] = $cart; } $result = Db::getInstance()->ExecuteS(' SELECT h.`id_hook`, m.`name`, hm.`position` FROM `' . _DB_PREFIX_ . 'module` m LEFT JOIN `' . _DB_PREFIX_ . 'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `' . _DB_PREFIX_ . 'hook` h ON hm.`id_hook` = h.`id_hook` WHERE h.`name` = \'' . pSQL($hook_name) . '\' AND m.`active` = 1 ' . ($id_module ? 'AND m.`id_module` = ' . intval($id_module) : '') . ' ORDER BY hm.`position`, m.`name` DESC'); if (!$result) { return false; } $output = ''; foreach ($result as $k => $module) { $moduleInstance = Module::getInstanceByName($module['name']); if (!$moduleInstance) { continue; } $exceptions = $moduleInstance->getExceptions(intval($module['id_hook']), intval($moduleInstance->id)); $fileindex = basename($_SERVER['PHP_SELF']); $show = true; if (!empty($exceptions) and is_array($exceptions)) { foreach ($exceptions as $exception) { if ($fileindex == $exception['file_name']) { $show = false; } } } if (is_callable(array($moduleInstance, 'hook' . $hook_name)) and $show) { $hookArgs['altern'] = ++$altern; $output .= call_user_func(array($moduleInstance, 'hook' . $hook_name), $hookArgs); } } return $output; }
/** * Execute modules for specified hook * * @param string $hook_name Hook Name * @param array $hook_args Parameters for the functions * @param int $id_module Execute hook for this module only * @return string modules output */ public function exec($hook_name, $hook_args = array(), $id_module = null) { // Check arguments validity if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid id_module or hook_name'); } // If no modules associated to hook_name or recompatible hook name, we stop the function if (!($module_list = Hook::getHookModuleExecList($hook_name))) { return ''; } // Check if hook exists if (!($id_hook = Hook::getIdByName($hook_name))) { return false; } // Store list of executed hooks on this page Hook::$executed_hooks[$id_hook] = $hook_name; $live_edit = false; $context = Context::getContext(); if (!isset($hook_args['cookie']) || !$hook_args['cookie']) { $hook_args['cookie'] = $context->cookie; } if (!isset($hook_args['cart']) || !$hook_args['cart']) { $hook_args['cart'] = $context->cart; } $retro_hook_name = Hook::getRetroHookName($hook_name); // Look on modules list $altern = 0; $output = ''; foreach ($module_list as $array) { // Check errors if ($id_module && $id_module != $array['id_module']) { continue; } if (!($moduleInstance = Module::getInstanceByName($array['module']))) { continue; } // echo '<pre>'.print_r( $this->overrideHooks, 1 ); die; // Check permissions $exceptions = $moduleInstance->getExceptions($array['id_hook']); if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) { continue; } if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) { continue; } // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name)); $ohook = $orhook = ""; $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name)); if (array_key_exists($moduleInstance->id, $this->overrideHooks)) { $ohook = Hook::getRetroHookName($this->overrideHooks[$moduleInstance->id]); $orhook = $this->overrideHooks[$moduleInstance->id]; $hook_callable = is_callable(array($moduleInstance, 'hook' . $orhook)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $ohook)); } if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) { $hook_args['altern'] = ++$altern; if (array_key_exists($moduleInstance->id, $this->overrideHooks)) { if ($hook_callable) { $display = $moduleInstance->{'hook' . $orhook}($hook_args); } else { if ($hook_retro_callable) { $display = $moduleInstance->{'hook' . $ohook}($hook_args); } } } else { // Call hook method if ($hook_callable) { $display = $moduleInstance->{'hook' . $hook_name}($hook_args); } else { if ($hook_retro_callable) { $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args); } } } // Live edit if ($array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions' . (int) Tab::getIdFromClassName('AdminModulesPositions') . (int) Tools::getValue('id_employee'))) { $live_edit = true; $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']); } else { $output .= $display; } } } // Return html string return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\'); </script> <div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $output . ($live_edit ? '</div>' : ''); }
function frontGetItemContents($moduleId, $rowId, $groupId) { $contents = array(); $langId = $this->context->language->id; $shopId = $this->context->shop->id; $items = Db::getInstance()->executeS("Select m.*, ml.link, ml.image, ml.alt, ml.description \n\t\t\tFrom " . _DB_PREFIX_ . "flexgroupbanners_banner AS m \n\t\t\tInner Join " . _DB_PREFIX_ . "flexgroupbanners_banner_lang AS ml On m.id = ml.banner_id \n\t\t\tWhere m.group_id = " . $groupId . " AND m.status = 1 AND ml.id_lang = " . $langId . " \n\t\t\tOrder By m.ordering"); $contents = array(); if ($items) { foreach ($items as &$item) { //$item['description'] = Tools::htmlentitiesDecodeUTF8($item['description']); $content = $item['description']; if ($content) { // short code deal $pattern = '/\\{module\\}(.*?)\\{\\/module\\}/'; $check = preg_match_all($pattern, $content, $match); if ($check) { $results = $match[1]; if ($results) { foreach ($results as $result) { $module_content = ''; $config = json_decode(str_replace(array('\\', '\''), array('', '"'), $result)); if ($config) { if (is_object($config)) { if (isset($config->mod) && $config->mod != '' && isset($config->hook) && $config->hook != '') { $module = @Module::getInstanceByName($config->mod); if ($module) { if (Validate::isLoadedObject($module) && $module->id) { if (Validate::isHookName($config->hook)) { $functionName = 'hook' . $config->hook; if (method_exists($module, $functionName)) { $hookArgs = array(); $hookArgs['cookie'] = $this->context->cookie; $hookArgs['cart'] = $this->context->cart; $module_content = $module->{$functionName}($hookArgs); $item['description'] = str_replace('{module}' . $result . '{/module}', $module_content, $item['description']); } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } else { $item['description'] = str_replace('{module}' . $result . '{/module}', '', $item['description']); } } } else { $item['description'] = preg_replace($pattern, '', $item['description']); } } } $item['full_path'] = $this->getImageSrc($item['image']); } } return $items; }
protected function buildContentWithLayout($item, $hookName, $shopId, $langId, $cacheKey = '') { if (!$this->isCached('customparallax.' . $item['layout'] . '.tpl', Tools::encrypt($cacheKey))) { $params = Tools::jsonDecode($item['params']); $item['parallax_image'] = $this->_getImageSrc($params->parallax->image); $item['parallax_ratio'] = $params->parallax->ratio; $item['parallax_responsive'] = $params->parallax->responsive; $item['parallax_parallaxBackgrounds'] = $params->parallax->parallaxBackgrounds; $item['parallax_parallaxElements'] = $params->parallax->parallaxElements; $item['parallax_hideDistantElements'] = $params->parallax->hideDistantElements; $item['parallax_horizontalOffset'] = $params->parallax->horizontalOffset; $item['parallax_verticalOffset'] = $params->parallax->verticalOffset; $item['parallax_horizontalScrolling'] = $params->parallax->horizontalScrolling; $item['parallax_verticalScrolling'] = $params->parallax->verticalScrolling; $item['parallax_scrollProperty'] = $params->parallax->scrollProperty; $item['parallax_positionProperty'] = $params->parallax->positionProperty; unset($item['params']); if ($item['content_type'] == 'module') { $module = @Module::getInstanceByName($params->module->name); if ($module) { if (Validate::isLoadedObject($module) && $module->id) { if (Validate::isHookName($params->module->hook)) { $functionName = 'hook' . $params->module->hook; $hookArgs = array(); $hookArgs['cookie'] = $this->context->cookie; $hookArgs['cart'] = $this->context->cart; $item['content'] = $module->{$functionName}($hookArgs); } else { $item['content'] = ''; } } } else { $item['content'] = ''; } } else { // short codes //if($item['content']) $item['content'] = Tools::htmlentitiesDecodeUTF8($item['content']); $content = $item['content']; if ($content) { // short code module $pattern = '/\\{module\\}(.*?)\\{\\/module\\}/'; $check = preg_match_all($pattern, $content, $match); if ($check) { $results = $match[1]; if ($results) { foreach ($results as $result) { $module_content = ''; $config = json_decode(str_replace(array('\\', '\''), array('', '"'), $result)); if ($config) { if (is_object($config)) { if (isset($config->mod) && $config->mod != '' && isset($config->hook) && $config->hook != '') { $module = @Module::getInstanceByName($config->mod); if ($module) { if (Validate::isLoadedObject($module) && $module->id) { if (Validate::isHookName($config->hook)) { $functionName = 'hook' . $config->hook; if (method_exists($module, $functionName)) { $hookArgs = array(); $hookArgs['cookie'] = $this->context->cookie; $hookArgs['cart'] = $this->context->cart; $module_content = $module->{$functionName}($hookArgs); $item['content'] = str_replace('{module}' . $result . '{/module}', $module_content, $item['content']); } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } } else { $item['content'] = preg_replace($pattern, '', $item['content']); } } $pattern = '/\\{product\\}(.*?)\\{\\/product\\}/'; $check = preg_match_all($pattern, $item['content'], $match); if ($check) { $results = $match[1]; if ($results) { foreach ($results as $result) { $module_content = ''; $config = json_decode(str_replace(array('\\', '\''), array('', '"'), $result)); if ($config) { if (is_object($config)) { if (isset($config->id) && (int) $config->id > 0) { $product = $this->buildProduct($config->id, $item['layout'], $cacheKey . '|' . $item['id']); $item['content'] = str_replace('{product}' . $result . '{/product}', $product, $item['content']); } else { $item['content'] = str_replace('{product}' . $result . '{/product}', '', $item['content']); } } else { $item['content'] = str_replace('{product}' . $result . '{/product}', '', $item['content']); } } else { $item['content'] = str_replace('{product}' . $result . '{/product}', '', $item['content']); } } } else { $item['content'] = preg_replace($pattern, '', $item['content']); } } } } $this->context->smarty->assign('customparallax', $item); } return $this->display(__FILE__, 'customparallax.' . $item['layout'] . '.tpl', Tools::encrypt($cacheKey)); }
public static function hookExec($hook_name, $hook_args = array(), $id_module = null, $array = array()) { if (!empty($id_module) && !Validate::isUnsignedId($id_module) || !Validate::isHookName($hook_name)) { die(Tools::displayError()); } $context = Context::getContext(); if (!isset($hook_args['cookie']) || !$hook_args['cookie']) { $hook_args['cookie'] = $context->cookie; } if (!isset($hook_args['cart']) || !$hook_args['cart']) { $hook_args['cart'] = $context->cart; } if ($id_module && $id_module != $array['id_module']) { return; } if (!($module_instance = Module::getInstanceByName($array['module'])) || !$module_instance->active) { return; } $retro_hook_name = Hook::getRetroHookName($hook_name); $hook_callable = is_callable(array($module_instance, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($module_instance, 'hook' . $retro_hook_name)); $output = ''; if (($hook_callable || $hook_retro_callable) && Module::preCall($module_instance->name)) { if ($hook_callable) { $output = $module_instance->{'hook' . $hook_name}($hook_args); } else { if ($hook_retro_callable) { $output = $module_instance->{'hook' . $retro_hook_name}($hook_args); } } } return $output; }
public function execModuleHook($hook_name, $hook_args = array(), $id_module = null, $id_shop = null) { // Check arguments validity if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid id_module or hook_name'); } // Check if hook exists if (!($id_hook = Hook::getIdByName($hook_name))) { return false; } // Store list of executed hooks on this page Hook::$executed_hooks[$id_hook] = $hook_name; $live_edit = false; $context = Context::getContext(); if (!isset($hook_args['cookie']) || !$hook_args['cookie']) { $hook_args['cookie'] = $context->cookie; } if (!isset($hook_args['cart']) || !$hook_args['cart']) { $hook_args['cart'] = $context->cart; } $retro_hook_name = Hook::getRetroHookName($hook_name); // Look on modules list $altern = 0; $output = ''; $different_shop = false; if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) { $old_context_shop_id = $context->shop->getContextShopID(); $old_context = $context->shop->getContext(); $old_shop = clone $context->shop; $shop = new Shop((int) $id_shop); if (Validate::isLoadedObject($shop)) { $context->shop = $shop; $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id); $different_shop = true; } } if (!($moduleInstance = Module::getInstanceById($id_module))) { continue; } // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name)); if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) { $hook_args['altern'] = ++$altern; // Call hook method if ($hook_callable) { $display = $moduleInstance->{'hook' . $hook_name}($hook_args); } elseif ($hook_retro_callable) { $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args); } $output .= $display; } if ($different_shop) { $context->shop = $old_shop; $context->shop->setContext($old_context, $shop->id); } return $output; }
public static function renderModuleByHookV15($hook_name, $hookArgs = array(), $id_module = NULL, $array = array()) { global $cart, $cookie; if (!$hook_name || !$id_module) { return; } if (!empty($id_module) and !Validate::isUnsignedId($id_module) or !Validate::isHookName($hook_name)) { die(Tools::displayError()); } if (!isset($hookArgs['cookie']) or !$hookArgs['cookie']) { $hookArgs['cookie'] = $cookie; } if (!isset($hookArgs['cart']) or !$hookArgs['cart']) { $hookArgs['cart'] = $cart; } if ($id_module and $id_module != $array['id_module']) { return; } if (!($moduleInstance = Module::getInstanceByName($array['module']))) { return; } $retro_hook_name = Hook::getRetroHookName($hook_name); $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name)); $output = ''; if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) { if ($hook_callable) { $output = $moduleInstance->{'hook' . $hook_name}($hookArgs); } else { if ($hook_retro_callable) { $output = $moduleInstance->{'hook' . $retro_hook_name}($hookArgs); } } } return $output; }
/** * @param string $content */ public static function parseHookOutput($themeDir, $hook_name, $hook_list) { $context = Context::getContext(); $output = ''; if (!Validate::isHookName($hook_name) || !($module_list = Hook::getHookModuleExecList($hook_name))) { return null; } $id_hook = Hook::getIdByName($hook_name); $dataRequirePosAttr = implode(';', $hook_list); foreach ($module_list as $array) { if (!($moduleInstance = Module::getInstanceByName($array['module']))) { continue; } $exceptions = $moduleInstance->getExceptions($array['id_hook']); if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) { continue; } if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) { continue; } $name = $moduleInstance->name; if (Module::preCall($name)) { $blockDataAttr = 'hook_' . $id_hook . '_module_' . $moduleInstance->id . '_moduleName_' . $name; if ($name === 'blocklayered') { $output .= <<<EOT {if \$page_name eq 'category'} {literal} \t<script type="text/javascript"> \t\t//<![CDATA[ \t\t\$(document).ready(function() \t\t{ \t\t\t\$('#selectPrductSort').unbind('change').bind('change', function() \t\t\t{ \t\t\t\treloadContent(); \t\t\t}) \t\t}); \t\t//]]> \t</script> {/literal} {/if} EOT; } elseif (file_exists($themeDir . "/modules/{$name}/{$name}.tpl")) { $output .= <<<EOT {assign var=blockDataAttr value='{$blockDataAttr}'} {assign var=blockDataRequirePosAttr value='{$dataRequirePosAttr}'} {include file="{\$tpl_dir}./modules/{$name}/{$name}.tpl" blockId=\$blockId blockDataAttr=\$blockDataAttr blockDataRequirePosAttr=\$blockDataRequirePosAttr} EOT; } elseif (file_exists(_PS_MODULE_DIR_ . "{$name}/{$name}.tpl")) { $output .= <<<EOT {include file="{\$modules_dir}./{$name}/{$name}.tpl"} EOT; } } } return $output; }
public function processImportConditions($conditions, $id_lang) { foreach ($conditions as $condition) { try { if (Condition::getIdByIdPs($condition->id_ps_condition)) { continue; } //only add new condition, if already exist we continue $cond = new Condition(); $cond->hydrate((array) $condition, (int) $id_lang); $time = 86400; if ($cond->calculation_type == 'time') { $time = 86400 * (int) $cond->calculation_detail; } $cond->date_upd = date('Y-m-d H:i:s', time() - $time); $cond->date_add = date('Y-m-d H:i:s'); $condition->calculation_detail = trim($condition->calculation_detail); $cond->add(false); if ($condition->calculation_type == 'hook' && !$this->isRegisteredInHook($condition->calculation_detail) && Validate::isHookName($condition->calculation_detail)) { $this->registerHook($condition->calculation_detail); } unset($cond); } catch (Exception $e) { continue; } } }
protected function buildContentWithLayout($item, $hookName, $shopId, $langId, $cacheKey) { if (!$this->isCached('customhtml.' . $item['layout'] . '.tpl', Tools::encrypt($cacheKey))) { // short codes //if($item['content']) $item['content'] = Tools::htmlentitiesDecodeUTF8($item['content']); $content = $item['content']; if ($content) { // short code deal $pattern = '/\\{module\\}(.*?)\\{\\/module\\}/'; $check = preg_match_all($pattern, $content, $match); if ($check) { $results = $match[1]; if ($results) { foreach ($results as $result) { $module_content = ''; $config = json_decode(str_replace(array('\\', '\''), array('', '"'), $result)); if ($config) { if (is_object($config)) { if (isset($config->mod) && $config->mod != '' && isset($config->hook) && $config->hook != '') { $module = @Module::getInstanceByName($config->mod); if ($module) { if (Validate::isLoadedObject($module) && $module->id) { if (Validate::isHookName($config->hook)) { $functionName = 'hook' . $config->hook; if (method_exists($module, $functionName)) { $hookArgs = array(); $hookArgs['cookie'] = $this->context->cookie; $hookArgs['cart'] = $this->context->cart; $module_content = $module->{$functionName}($hookArgs); $item['content'] = str_replace('{module}' . $result . '{/module}', $module_content, $item['content']); } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } else { $item['content'] = str_replace('{module}' . $result . '{/module}', '', $item['content']); } } } else { $item['content'] = preg_replace($pattern, '', $item['content']); } } } $this->context->smarty->assign('customhtml_item', $item); } return $this->display(__FILE__, 'customhtml.' . $item['layout'] . '.tpl', Tools::encrypt($cacheKey)); }
public static function registerDesignerHook($hook_name) { // Check hook name validation and if module is installed if (!Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid hook name'); } // Retrocompatibility $hook_name_bak = $hook_name; if ($alias = Hook::getRetroHookName($hook_name)) { $hook_name = $alias; } // Get hook id $id_hook = Hook::getIdByName($hook_name); $live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak)); // If hook does not exist, we create it if (!$id_hook) { $new_hook = new Hook(); $new_hook->name = pSQL($hook_name); $new_hook->title = pSQL($hook_name); $new_hook->live_edit = pSQL($live_edit); $new_hook->add(); $id_hook = $new_hook->id; if (!$id_hook) { return false; } } return $id_hook; }
/** * Change hook execute off module */ public function ajaxProcessChangeModuleHook() { $result = array(); $pagemeta = Tools::getValue('pagemeta'); $hookcolumn = Tools::getValue('hookcolumn'); $id_hookexec = (int) Tools::getValue('id_hookexec'); $hookexec_name = Hook::getNameById($id_hookexec); $old_hook = (int) Tools::getValue('old_hook'); $id_module = (int) Tools::getValue('id_module'); if ($id_module && Validate::isUnsignedId($id_module) && $hookexec_name && Validate::isHookName($hookexec_name)) { $result['status'] = true; $moduleObject = Module::getInstanceById($id_module); $HookedModulesArr = OvicLayoutControl::getSideBarModulesByPage($pagemeta, $hookcolumn, false); if (!is_array($HookedModulesArr)) { $result['status'] = false; } if ($result['status']) { $moduleHook = array(); $moduleHook[] = $moduleObject->name; $moduleHook[] = Hook::getNameById($old_hook); $key = array_search($moduleHook, $HookedModulesArr); if (array_key_exists($key, $HookedModulesArr)) { $moduleHook[1] = $hookexec_name; $HookedModulesArr[$key] = $moduleHook; $result['status'] = OvicLayoutControl::registerSidebarModule($pagemeta, $hookcolumn, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); $result['moduleinfo'] = $moduleObject->name . '-' . $hookexec_name; } } } Tools::clearCache(); die(Tools::jsonEncode($result)); }
protected function _getMenuItemLevel1($moduleId, $rowId, $groupId) { $contents = array(); $langId = $this->context->language->id; $shopId = $this->context->shop->id; $sql = "Select m.*, ml.name, ml.link, ml.image, ml.imageAlt, ml.html \n\t\t\tFrom " . _DB_PREFIX_ . "megaboxs_menuitem AS m \n\t\t\tInner Join " . _DB_PREFIX_ . "megaboxs_menuitem_lang AS ml \n\t\t\t\tOn m.id = ml.menuitem_id \n\t\t\tWhere\n\t\t\t\tm.parent_id = 0 \n\t\t\t\tAND m.group_id = " . $groupId . " \n\t\t\t\tAND m.status = 1 \n\t\t\t\tAND ml.id_lang = " . $langId . " \n\t\t\tOrder By \n\t\t\t\tm.ordering"; $items = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $contents = array(); if ($items) { foreach ($items as &$item) { if ($item['link_type'] == 'CUSTOMLINK|0') { } elseif ($item['link_type'] == 'PRODUCT|0') { $item['link'] = $this->generateUrl('PRD|' . $item['product_id'], $item['link']); } else { $item['link'] = $this->generateUrl($item['link_type'], $item['link']); } $item['icon'] = $this->getIconSrc($item['icon']); $item['content'] = ''; if ($item['menu_type'] == 'module') { $module = @Module::getInstanceByName($item['module_name']); if ($module) { if (Validate::isLoadedObject($module) && $module->id) { if (Validate::isHookName($item['hook_name'])) { $item['content'] = Module::hookExec($item['hook_name'], array(), $module->id); } } } } elseif ($item['menu_type'] == 'html') { $item['content'] = $item['html']; } elseif ($item['menu_type'] == 'image') { $item['content'] = $this->_getImageSrc($item['image'], true); } $item['submenus'] = $this->_getMenuItemLevel2($moduleId, $rowId, $groupId, $item['id']); } } return $items; }
public static function execModuleHook($hook_name, $hook_args = array(), $module_name, $use_push = false, $id_shop = null) { static $disable_non_native_modules = null; if ($disable_non_native_modules === null) { $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE'); } // Check arguments validity if (!Validate::isModuleName($module_name) || !Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid module name or hook name'); } // If no modules associated to hook_name or recompatible hook name, we stop the function if (!Hook::getHookModuleExecList($hook_name)) { return ''; } // Check if hook exists if (!($id_hook = Hook::getIdByName($hook_name))) { return false; } // Store list of executed hooks on this page Hook::$executed_hooks[$id_hook] = $hook_name; // $live_edit = false; $context = Context::getContext(); if (!isset($hook_args['cookie']) || !$hook_args['cookie']) { $hook_args['cookie'] = $context->cookie; } if (!isset($hook_args['cart']) || !$hook_args['cart']) { $hook_args['cart'] = $context->cart; } $retro_hook_name = Hook::getRetroHookName($hook_name); // Look on modules list $altern = 0; $output = ''; if ($disable_non_native_modules && !isset(Hook::$native_module)) { Hook::$native_module = Module::getNativeModuleList(); } $different_shop = false; if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) { // $old_context_shop_id = $context->shop->getContextShopID(); $old_context = $context->shop->getContext(); $old_shop = clone $context->shop; $shop = new Shop((int) $id_shop); if (Validate::isLoadedObject($shop)) { $context->shop = $shop; $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id); $different_shop = true; } } // Check errors if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($module_name, self::$native_module)) { return; } if (!($moduleInstance = Module::getInstanceByName($module_name))) { return; } if ($use_push && !$moduleInstance->allow_push) { continue; } // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name)); if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) { $hook_args['altern'] = ++$altern; if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) { Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit); } // Call hook method if ($hook_callable) { $display = $moduleInstance->{'hook' . $hook_name}($hook_args); } elseif ($hook_retro_callable) { $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args); } $output .= $display; } if ($different_shop) { $context->shop = $old_shop; $context->shop->setContext($old_context, $shop->id); } return $output; // Return html string }
public function processImportConditions($conditions, $id_lang) { $current_conditions = array(); $result = Db::getInstance()->ExecuteS('SELECT `id_ps_condition` FROM ' . _DB_PREFIX_ . 'condition'); foreach ($result as $row) { $current_conditions[] = (int) $row['id_ps_condition']; } foreach ($conditions as $condition) { if (isset($condition->id)) { unset($condition->id); } try { $cond = new Condition(); if (in_array($condition->id_ps_condition, $current_conditions)) { $cond = new Condition(Condition::getIdByIdPs($condition->id_ps_condition)); unset($current_conditions[(int) array_search($condition->id_ps_condition, $current_conditions)]); } $cond->hydrate((array) $condition, (int) $id_lang); $cond->date_upd = date('Y-m-d H:i:s', strtotime('-' . (int) $cond->calculation_detail . 'DAY')); $cond->date_add = date('Y-m-d H:i:s'); $condition->calculation_detail = trim($condition->calculation_detail); $cond->save(false, false); if ($condition->calculation_type == 'hook' && !$this->isRegisteredInHook($condition->calculation_detail) && Validate::isHookName($condition->calculation_detail)) { $this->registerHook($condition->calculation_detail); } unset($cond); } catch (Exception $e) { continue; } } // Delete conditions that are not in the file anymore foreach ($current_conditions as $id_ps_condition) { $cond = new Condition(Condition::getIdByIdPs((int) $id_ps_condition)); $cond->delete(); } }
public function process() { $seo_url = Tools::getValue('seo_url', false); if ($seo_url == 'products-comparison') { ob_end_clean(); header("Status: 301 Moved Permanently", false, 301); Tools::redirect('products-comparison.php?ajax=' . (int) Tools::getValue('ajax') . '&action=' . Tools::getValue('action') . '&id_product=' . (int) Tools::getValue('id_product')); die; } if ($seo_url && $this->id_seo && !Tools::getValue('getShareBlock')) { $resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int) $this->id_seo, (int) $this->context->cookie->id_lang); if (!$resultSeoUrl) { Tools::redirect('404.php'); die; } if ($resultSeoUrl[0]['deleted']) { header("Status: 301 Moved Permanently", false, 301); Tools::redirect('index.php'); die; } $currentUri = explode('?', $_SERVER['REQUEST_URI']); $currentUri = $currentUri[0]; $this->realURI = __PS_BASE_URI__ . (Language::countActiveLanguages() > 1 ? Language::getIsoById($this->context->cookie->id_lang) . '/' : '') . 's/' . $resultSeoUrl[0]['id_seo'] . '/' . $resultSeoUrl[0]['seo_url']; if (!preg_match('#([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*)#', $_SERVER['REQUEST_URI'])) { header("Status: 301 Moved Permanently", false, 301); header("Location: " . $this->realURI . ((int) Tools::getValue('p') > 1 ? '?p=' . (int) Tools::getValue('p') : '')); die; } if (!Tools::getValue('id_seo_id_search') && ($resultSeoUrl[0]['seo_url'] != $seo_url || $currentUri != $this->realURI)) { header("Status: 301 Moved Permanently", false, 301); header("Location: " . $this->realURI); die; } $this->id_search = $resultSeoUrl[0]['id_search']; $AdvancedSearchClass = new AdvancedSearchClass((int) $this->id_search, (int) $this->context->cookie->id_lang); if (!$AdvancedSearchClass->active) { header("Status: 302 Moved Temporarily", false, 302); Tools::redirect('index.php'); die; } $criteria = unserialize($resultSeoUrl[0]['criteria']); if (is_array($criteria) && sizeof($criteria)) { $this->criterions = PM_AdvancedSearch4::getArrayCriteriaFromSeoArrayCriteria($criteria); } $_GET['id_seo_id_search'] = (int) $this->id_search; $_GET['as4c'] = $this->criterions; $this->hookName = AdvancedSearchClass::getHookName($AdvancedSearchClass->id_hook); $hasPriceCriterionGroup = false; if (is_array($this->criterions) && sizeof($this->criterions)) { $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay((int) $this->id_search, array_keys($this->criterions)); if (is_array($selected_criteria_groups_type) && sizeof($selected_criteria_groups_type)) { foreach ($selected_criteria_groups_type as $criterionGroup) { if ($criterionGroup['criterion_group_type'] == 'price') { $hasPriceCriterionGroup = true; break; } } } } if ($hasPriceCriterionGroup && $resultSeoUrl[0]['id_currency'] && $this->context->cookie->id_currency != (int) $resultSeoUrl[0]['id_currency']) { $this->context->cookie->id_currency = $resultSeoUrl[0]['id_currency']; header('Refresh: 1; URL=' . $_SERVER['REQUEST_URI']); die; } $this->context->smarty->assign('as_cross_links', AdvancedSearchSeoClass::getCrossLinksSeo($this->context->cookie->id_lang, $resultSeoUrl[0]['id_seo'])); } else { if (Tools::getValue('setCollapseGroup')) { ob_end_clean(); $this->id_search = (int) Tools::getValue('id_search'); $id_criterion_group = (int) Tools::getValue('id_criterion_group'); $state = (int) Tools::getValue('state'); $id_criterion_group = $this->id_search . '_' . $id_criterion_group; $criterion_state = array($id_criterion_group => $state); $previous_criterion = array(); if (isset($this->context->cookie->criterion_group_state)) { $previous_criterion = unserialize($this->context->cookie->criterion_group_state); if (is_array($previous_criterion) && sizeof($previous_criterion)) { foreach ($previous_criterion as $k => $v) { if ($k == $id_criterion_group) { $criterion_state[$k] = (int) $state; } else { $criterion_state[$k] = (int) $v; } } $this->context->cookie->criterion_group_state = serialize($criterion_state); die; } else { $this->context->cookie->criterion_group_state = serialize($criterion_state); } die; } else { $this->context->cookie->criterion_group_state = serialize($criterion_state); } die; } elseif (Tools::getValue('setHideCriterionStatus')) { ob_end_clean(); $this->id_search = (int) Tools::getValue('id_search'); $state = (int) Tools::getValue('state'); if (isset($this->context->cookie->hidden_criteria_state)) { $hidden_criteria_state = unserialize($this->context->cookie->hidden_criteria_state); if (is_array($hidden_criteria_state)) { $hidden_criteria_state[$this->id_search] = $state; } else { $hidden_criteria_state = array(); } $this->context->cookie->hidden_criteria_state = serialize($hidden_criteria_state); } else { $this->context->cookie->hidden_criteria_state = serialize(array($this->id_search => $state)); } die; } elseif (Tools::getValue('getShareBlock')) { ob_end_clean(); echo Module::getInstanceByName('pm_advancedsearch4')->getShareBlock(Tools::safeOutput(Tools::getValue('ASSearchTitle')), Tools::safeOutput(Tools::getValue('ASSearchUrl'))); die; } else { if (Tools::getValue('resetSearchSelection')) { ob_end_clean(); $this->id_search = (int) Tools::getValue('id_search'); Module::getInstanceByName('pm_advancedsearch4')->resetSearchSelection($this->id_search); die('1'); } } $this->criterions = Tools::getValue('as4c', array()); if (is_array($this->criterions)) { $this->criterions = AdvancedSearchClass::cleanArrayCriterion($this->criterions); } else { $this->criterions = array(); } $this->criterions_hidden = Tools::getValue('as4c_hidden', array()); if (is_array($this->criterions_hidden)) { $this->criterions_hidden = AdvancedSearchClass::cleanArrayCriterion($this->criterions_hidden); } else { $this->criterions_hidden = array(); } $this->next_id_criterion_group = (int) Tools::getValue('next_id_criterion_group', false); $this->reset = (int) Tools::getValue('reset', false); $this->reset_group = (int) Tools::getValue('reset_group', false); if ($this->reset) { $this->criterions = array(); } if ($this->reset_group && isset($this->criterions[$this->reset_group])) { unset($this->criterions[$this->reset_group]); } $this->hookName = Tools::getValue('hookName'); if (!Validate::isHookName($this->hookName)) { die('Invalid hook name'); } $this->id_search = (int) Tools::getValue('id_search'); $this->context->cookie->{'next_id_criterion_group_' . (int) $this->id_search} = $this->next_id_criterion_group; } }
public function ajaxProcessSaveDashConfig() { $return = array('has_errors' => false, 'errors' => array()); $module = Tools::getValue('module'); $hook = Tools::getValue('hook'); $configs = Tools::getValue('configs'); $params = array('date_from' => $this->context->employee->stats_date_from, 'date_to' => $this->context->employee->stats_date_to); if (Validate::isModuleName($module) && ($module_obj = Module::getInstanceByName($module))) { if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'validateDashConfig')) { $return['errors'] = $module_obj->validateDashConfig($configs); } if (!count($return['errors'])) { if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'saveDashConfig')) { $return['has_errors'] = $module_obj->saveDashConfig($configs); } elseif (is_array($configs) && count($configs)) { foreach ($configs as $name => $value) { if (Validate::isConfigName($name)) { Configuration::updateValue($name, $value); } } } } else { $return['has_errors'] = true; } } if (Validate::isHookName($hook) && method_exists($module_obj, $hook)) { $return['widget_html'] = $module_obj->{$hook}($params); } die(Tools::jsonEncode($return)); }
/** * remove a module from a hook */ public function ajaxProcessremoveModuleHook() { $result = array(); $hookname = Tools::getValue('hookname'); $id_option = (int) Tools::getValue('id_option'); $id_hookexec = (int) Tools::getValue('id_hookexec'); $hookexec_name = Hook::getNameById($id_hookexec); $id_module = (int) Tools::getValue('id_module'); if ($id_module && Validate::isUnsignedId($id_module) && $hookname && Validate::isHookName($hookname) && $hookexec_name && Validate::isHookName($hookexec_name)) { $moduleObject = Module::getInstanceById($id_module); $HookedModulesArr = OvicLayoutControl::getModulesHook($id_option, $hookname); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); $HookedModulesArr = array_values($HookedModulesArr); $moduleHook = array(); $moduleHook[] = $moduleObject->name; $moduleHook[] = $hookexec_name; if ($HookedModulesArr && is_array($HookedModulesArr) && sizeof($HookedModulesArr)) { $key = array_search($moduleHook, $HookedModulesArr); unset($HookedModulesArr[$key]); } $HookedModulesArr = array_values($HookedModulesArr); $result['status'] = OvicLayoutControl::registerHookModule($id_option, $hookname, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); $result['msg'] = $this->l('Successful deletion'); //$this->displayError } Tools::clearCache(); die(Tools::jsonEncode($result)); }
public function autoregisterhook($hook_name = 'moduleRoutes', $module_name = 'smartblog', $shop_list = null) { if (Module::isEnabled($module_name) == 1 && Module::isInstalled($module_name) == 1) { $return = true; $id_sql = 'SELECT `id_module` FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = "' . $module_name . '"'; $id_module = Db::getInstance()->getValue($id_sql); if (is_array($hook_name)) { $hook_names = $hook_name; } else { $hook_names = array($hook_name); } foreach ($hook_names as $hook_name) { if (!Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid hook name'); } if (!isset($id_module) || !is_numeric($id_module)) { return false; } //$hook_name_bak = $hook_name; if ($alias = Hook::getRetroHookName($hook_name)) { $hook_name = $alias; } $id_hook = Hook::getIdByName($hook_name); //$live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak)); if (!$id_hook) { $new_hook = new Hook(); $new_hook->name = pSQL($hook_name); $new_hook->title = pSQL($hook_name); $new_hook->live_edit = (bool) preg_match('/^display/i', $new_hook->name); $new_hook->position = (bool) $new_hook->live_edit; $new_hook->add(); $id_hook = $new_hook->id; if (!$id_hook) { return false; } } if (is_null($shop_list)) { $shop_list = Shop::getShops(true, null, true); } foreach ($shop_list as $shop_id) { $sql = 'SELECT hm.`id_module` FROM `' . _DB_PREFIX_ . 'hook_module` hm, `' . _DB_PREFIX_ . 'hook` h WHERE hm.`id_module` = ' . (int) $id_module . ' AND h.`id_hook` = ' . $id_hook . ' AND h.`id_hook` = hm.`id_hook` AND `id_shop` = ' . (int) $shop_id; if (Db::getInstance()->getRow($sql)) { continue; } $sql = 'SELECT MAX(`position`) AS position FROM `' . _DB_PREFIX_ . 'hook_module` WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id; if (!($position = Db::getInstance()->getValue($sql))) { $position = 0; } $return &= Db::getInstance()->insert('hook_module', array('id_module' => (int) $id_module, 'id_hook' => (int) $id_hook, 'id_shop' => (int) $shop_id, 'position' => (int) ($position + 1))); } } return $return; } else { return false; } }
/** * Execute modules for specified hook * * @param string $hook_name Hook Name * @param array $hook_args Parameters for the functions * @param int $id_module Execute hook for this module only * @param bool $array_return If specified, module output will be set by name in an array * @param bool $check_exceptions Check permission exceptions * @param bool $use_push Force change to be refreshed on Dashboard widgets * @param int $id_shop If specified, hook will be execute the shop with this ID * * @throws PrestaShopException * * @return string/array modules output */ public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null) { if (defined('PS_INSTALLATION_IN_PROGRESS')) { return; } static $disable_non_native_modules = null; if ($disable_non_native_modules === null) { $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE'); } // Check arguments validity if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) { throw new PrestaShopException('Invalid id_module or hook_name'); } // If no modules associated to hook_name or recompatible hook name, we stop the function if (!($module_list = Hook::getHookModuleExecList($hook_name))) { return ''; } // Check if hook exists if (!($id_hook = Hook::getIdByName($hook_name))) { return false; } if (array_key_exists($hook_name, self::$deprecated_hooks)) { $deprecVersion = isset(self::$deprecated_hooks[$hook_name]['from']) ? self::$deprecated_hooks[$hook_name]['from'] : _PS_VERSION_; Tools::displayAsDeprecated('The hook ' . $hook_name . ' is deprecated in PrestaShop v.' . $deprecVersion); } // Store list of executed hooks on this page Hook::$executed_hooks[$id_hook] = $hook_name; $context = Context::getContext(); if (!isset($hook_args['cookie']) || !$hook_args['cookie']) { $hook_args['cookie'] = $context->cookie; } if (!isset($hook_args['cart']) || !$hook_args['cart']) { $hook_args['cart'] = $context->cart; } $retro_hook_name = Hook::getRetroHookName($hook_name); // Look on modules list $altern = 0; if ($array_return) { $output = array(); } else { $output = ''; } if ($disable_non_native_modules && !isset(Hook::$native_module)) { Hook::$native_module = Module::getNativeModuleList(); } $different_shop = false; if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) { $old_context = $context->shop->getContext(); $old_shop = clone $context->shop; $shop = new Shop((int) $id_shop); if (Validate::isLoadedObject($shop)) { $context->shop = $shop; $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id); $different_shop = true; } } foreach ($module_list as $array) { // Check errors if ($id_module && $id_module != $array['id_module']) { continue; } if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($array['module'], Hook::$native_module)) { continue; } // Check permissions if ($check_exceptions) { $exceptions = Module::getExceptionsStatic($array['id_module'], $array['id_hook']); $controller = Dispatcher::getInstance()->getController(); $controller_obj = Context::getContext()->controller; //check if current controller is a module controller if (isset($controller_obj->module) && Validate::isLoadedObject($controller_obj->module)) { $controller = 'module-' . $controller_obj->module->name . '-' . $controller; } if (in_array($controller, $exceptions)) { continue; } //Backward compatibility of controller names $matching_name = array('authentication' => 'auth'); if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) { continue; } if (Validate::isLoadedObject($context->employee) && !Module::getPermissionStatic($array['id_module'], 'view', $context->employee)) { continue; } } if (!($moduleInstance = Module::getInstanceByName($array['module']))) { continue; } if ($use_push && !$moduleInstance->allow_push) { continue; } // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name)); if ($hook_callable || $hook_retro_callable) { $hook_args['altern'] = ++$altern; if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) { Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit); } // Call hook method if ($hook_callable) { $display = Hook::coreCallHook($moduleInstance, 'hook' . $hook_name, $hook_args); } elseif ($hook_retro_callable) { $display = Hook::coreCallHook($moduleInstance, 'hook' . $retro_hook_name, $hook_args); } if ($array_return) { $output[$moduleInstance->name] = $display; } else { $output .= $display; } } elseif (Hook::isDisplayHookName($hook_name)) { if ($moduleInstance instanceof WidgetInterface) { $display = Hook::coreRenderWidget($moduleInstance, $hook_name, $hook_args); if ($array_return) { $output[$moduleInstance->name] = $display; } else { $output .= $display; } } } } if ($different_shop) { $context->shop = $old_shop; $context->shop->setContext($old_context, $shop->id); } return $output; }