Ejemplo n.º 1
0
    private function ModuleHookExec($moduleName, $hook_name)
    {
        $output = '';
        $moduleInstance = Module::getInstanceByName($moduleName);
        if (Validate::isLoadedObject($moduleInstance) && $moduleInstance->id) {
            $altern = 0;
            $id_hook = Hook::getIdByName($hook_name);
            $retro_hook_name = Hook::getRetroHookName($hook_name);
            $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
            if ($disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($moduleInstance->name, self::$native_module)) {
                return '';
            }
            //check disable module
            $device = (int) $this->context->getDevice();
            if (Db::getInstance()->getValue('
			SELECT COUNT(`id_module`) FROM ' . _DB_PREFIX_ . 'module_shop
			WHERE enable_device & ' . (int) $device . ' AND id_module=' . (int) $moduleInstance->id . Shop::addSqlRestriction()) == 0) {
                return '';
            }
            // Check permissions
            $exceptions = $moduleInstance->getExceptions($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)) {
                return '';
            }
            //retro compat of controller names
            $matching_name = array('authentication' => 'auth', 'productscomparison' => 'compare');
            if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                return '';
            }
            if (Validate::isLoadedObject($this->context->employee) && !$moduleInstance->getPermission('view', $this->context->employee)) {
                return '';
            }
            if (!isset($hook_args['cookie']) or !$hook_args['cookie']) {
                $hook_args['cookie'] = $this->context->cookie;
            }
            if (!isset($hook_args['cart']) or !$hook_args['cart']) {
                $hook_args['cart'] = $this->context->cart;
            }
            $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;
            }
        }
        return $output;
    }
 public static function preCall($module_name)
 {
     if (!parent::preCall($module_name)) {
         return false;
     }
     if ($module_instance = Module::getInstanceByName($module_name)) {
         /** @var PaymentModule $module_instance */
         if (!$module_instance->currencies || $module_instance->currencies && count(Currency::checkPaymentCurrencies($module_instance->id))) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
    /**
     * 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;
        }
        // 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 = $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', 'productscomparison' => 'compare');
                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) && 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 = Hook::coreCallHook($moduleInstance, 'hook' . $hook_name, $hook_args);
                } elseif ($hook_retro_callable) {
                    $display = Hook::coreCallHook($moduleInstance, 'hook' . $retro_hook_name, $hook_args);
                }
                // Live edit
                if (!$array_return && $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']);
                } elseif ($array_return) {
                    $output[$moduleInstance->name] = $display;
                } else {
                    $output .= $display;
                }
            }
        }
        if ($different_shop) {
            $context->shop = $old_shop;
            $context->shop->setContext($old_context, $shop->id);
        }
        if ($array_return) {
            return $output;
        } else {
            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>' : '');
        }
        // Return html string
    }
 public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true)
 {
     require_once dirname(__FILE__) . '../../../modules/designerpreview/defines.inc.php';
     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;
     }
     // 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();
     }
     $callableHooks = array('displayLeftColumn', 'displayRightColumn', 'displayFooter', 'displayTop', 'displayHome', 'displayNavigationBar');
     $isDesignerHook = isset($hook_args) && isset($hook_args['designer_hook']);
     // Billion Themler layoutPosition only
     $source_hook_name = $hook_name;
     if (isset($hook_args) && isset($hook_args['blockId'])) {
         // both Prestashop hooks and Designer layoutPosition
         $blockId = $hook_args['blockId'];
         $context->smarty->assign('blockId', $blockId);
         file_put_contents(getThemeDir() . '/includes/' . $hook_name . '.tpl', "{assign var=blockId value={$blockId} scope='parent'}");
         // for blocklayered-ajax
     }
     $count = getModulesCount($hook_name, $module_list);
     foreach ($module_list as $index => $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'], self::$native_module)) {
             continue;
         }
         if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
             continue;
         }
         // Check permissions
         if ($check_exceptions) {
             $exceptions = $moduleInstance->getExceptions($array['id_hook']);
             $controller = Dispatcher::getInstance()->getController();
             if (in_array($controller, $exceptions)) {
                 continue;
             }
             //retro compat of controller names
             $matching_name = array('authentication' => 'auth', 'compare' => 'products-comparison');
             if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                 continue;
             }
             if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) {
                 continue;
             }
         }
         $hook_callable = false;
         $hook_retro_callable = false;
         // Check whether Billion Themler hook is
         if ($isDesignerHook) {
             foreach ($callableHooks as $name) {
                 $hook_name = $name;
                 $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));
                 // modules in layoutPosition Billion Themler hook can be called from $callableHooks (displayLeftColumn etc.)
                 // so we save callable hook name as $hook_name variable and write its output to layoutPosition hook
                 if ($hook_callable || $hook_retro_callable) {
                     break;
                 }
                 // goes to Module::preCall line
             }
         } else {
             // Check which / if method is callable as usual
             $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);
             } else {
                 if ($hook_retro_callable) {
                     $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
                 }
             }
             // Billion Themler edit - $array['live_edit'] defines if module can be moved
             // displayTop and displayFooter hooks can be moved too in Billion Themler but it has live_edit = 0 in DB.hook table
             if (!$array_return && Tools::getValue('theme_name') && ($array['live_edit'] || $hook_name == 'displayTop' || $hook_name == 'displayFooter' || $hook_name == 'displayNavigationBar')) {
                 $display = wrapThemlerEdit($display, $moduleInstance, $array['id_hook']);
             }
             $display = addBootstrapColumn($display, $moduleInstance, $hook_name, $count, $index);
             // Live edit
             if (!$array_return && $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'))) {
                 // We should used in Live Edit mode native PrestaShop hooks only not Billion Themler ones
                 // That's why we remember $source_hook_name and check it
                 if ($isDesignerHook && !in_array($source_hook_name, $callableHooks)) {
                     $output .= $display;
                 } else {
                     $live_edit = true;
                     $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']);
                 }
             } else {
                 if ($array_return) {
                     $output[$moduleInstance->name] = $display;
                 } else {
                     $output .= $display;
                 }
             }
         }
     }
     if ($array_return) {
         return $output;
     } else {
         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>' : '');
         // Return html string
     }
 }
Ejemplo n.º 5
0
 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 '';
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
    /**
     * 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 static 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;
            }
            // 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));
            $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);
                } 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>' : '');
    }
Ejemplo n.º 8
0
 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
 }
Ejemplo n.º 9
0
    /**
     * 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 static function moduleExec($hook_name, $modulename, $hook_args = array(), $id_module = null, $array_return = false, $use_push = false, $id_shop = null)
    {
        static $disable_non_native_modules = null;
        $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;
        $context = Context::getContext();
        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;
            }
        }
        $module_list = array();
        $module_list[] = array('module' => $modulename, 'id_module' => 0);
        $live_edit = false;
        foreach ($module_list as $array) {
            $array['live_edit'] = false;
            // 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'], self::$native_module)) {
                continue;
            }
            if (!($module_instance = Module::getInstanceByName($array['module']))) {
                continue;
            }
            if ($use_push && !$module_instance->allow_push) {
                continue;
            }
            $hook_callable = is_callable(array($module_instance, 'hook' . $hook_name));
            $hook_retro_callable = is_callable(array($module_instance, 'hook' . $retro_hook_name));
            if (($hook_callable || $hook_retro_callable) && Module::preCall($module_instance->name)) {
                $hook_args['altern'] = ++$altern;
                if ($use_push && isset($module_instance->push_filename) && file_exists($module_instance->push_filename)) {
                    Tools::waitUntilFileIsModified($module_instance->push_filename, $module_instance->push_time_limit);
                }
                // Call hook method
                if ($hook_callable) {
                    $display = $module_instance->{'hook' . $hook_name}($hook_args);
                } elseif ($hook_retro_callable) {
                    $display = $module_instance->{'hook' . $retro_hook_name}($hook_args);
                }
                if (!$array_return && $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 .= Hook::wrapLiveEdit($display, $module_instance, $array['id_hook']);
                } else {
                    if ($array_return) {
                        $output[$module_instance->name] = $display;
                    } else {
                        $output .= $display;
                    }
                }
            }
        }
        if ($different_shop) {
            $context->shop = $old_shop;
            $context->shop->setContext($old_context, $shop->id);
        }
        if ($array_return) {
            return $output;
        } else {
            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>' : '');
        }
    }
    /**
     * @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;
    }
Ejemplo n.º 11
0
 /**
  * execute module, return string html
  * */
 private function getModuleAssign($moduleObject, $hook_name)
 {
     if (Validate::isLoadedObject($moduleObject) && $moduleObject->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") {
             $hook_name = strtolower($hook_name);
             if (!Validate::isHookName($hook_name)) {
                 die(Tools::displayError());
             }
             $altern = 0;
             if (is_callable(array($moduleObject, 'hook' . $hook_name))) {
                 $hookArgs['altern'] = ++$altern;
                 $output = call_user_func(array($moduleObject, '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($moduleObject, 'hook' . $hook_name));
             $hook_retro_callable = is_callable(array($moduleObject, 'hook' . $retro_hook_name));
             $output = '';
             if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleObject->name)) {
                 if ($hook_callable) {
                     $output = $moduleObject->{'hook' . $hook_name}($hookArgs);
                 } elseif ($hook_retro_callable) {
                     $output = $moduleObject->{'hook' . $retro_hook_name}($hookArgs);
                 }
             }
             return $output;
         }
     }
     return '';
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 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;
 }