本文整理汇总了PHP中Validate::isHookName方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::isHookName方法的具体用法?PHP Validate::isHookName怎么用?PHP Validate::isHookName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::isHookName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* 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;
}
示例2: ajaxProcessremoveModuleHook
/**
* 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));
}
示例3: hookactionModuleUnRegisterHookAfter
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']);
}
}
示例4: hookExec
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>' : '');
}
示例5: hookactionModuleRegisterHookAfter
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);
}
}
}
}
}
}
}
示例6: getModuleAssign
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 '';
}
示例7: registerHook
/**
* 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;
}
示例8: hookactionModuleRegisterHookAfter
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);
}
}
}
}
}
}
示例9: hookExec
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;
}
示例10: exec
/**
* 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>' : '');
}
示例11: frontGetItemContents
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;
}
示例12: buildContentWithLayout
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 {
//.........这里部分代码省略.........
示例13: hookExec
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;
}
示例14: execModuleHook
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;
}
示例15: renderModuleByHookV15
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;
}