Example #1
0
 public function SmartHookInsert()
 {
     $hookvalue = array();
     require_once dirname(__FILE__) . '/sql/addhook.php';
     foreach ($hookvalue as $hkv) {
         $hookid = Hook::getIdByName($hkv['name']);
         if (!$hookid) {
             $add_hook = new Hook();
             $add_hook->name = pSQL($hkv['name']);
             $add_hook->title = pSQL($hkv['title']);
             $add_hook->description = pSQL($hkv['description']);
             $add_hook->position = pSQL($hkv['position']);
             $add_hook->live_edit = $hkv['live_edit'];
             $add_hook->add();
             $hookid = $add_hook->id;
             if (!$hookid) {
                 return false;
             }
         } else {
             $up_hook = new Hook($hookid);
             $up_hook->update();
         }
     }
     return true;
 }
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     $toret = Hook::add('update', 'post', __CLASS__, array('global' => true, 'description' => 'Create the following revision of a post after the content has been updated.')) && $toret;
     $toret = Hook::add('create', 'post', __CLASS__, array('global' => true, 'description' => 'Add the first revision of the content after the content has been created.')) && $toret;
     return $toret;
 }
Example #3
0
 private function loadAddons()
 {
     $data = S('hooks');
     if (!$data) {
         $hooks = M('hooks')->getField('name,addons', true);
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Addons')->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, $addons);
                 }
             }
         }
         S('hooks', Hook::get());
         //插件标签
         $tpl_tags = array();
         $data = M('addons')->getField('id,name');
         if ($data) {
             foreach ($data as $addon) {
                 if (is_file("HDCMS/Addons/{$addon}/Tag/{$addon}Tag.class.php")) {
                     $tpl_tags[] = "@.Addons.{$addon}.Tag.{$addon}Tag";
                 }
             }
         }
         S('HookTag', array_unique($tpl_tags));
     } else {
         Hook::import($data, false);
         C('TPL_TAGS', array_unique(array_merge(C('TPL_TAGS'), S('HookTag'))));
     }
 }
Example #4
0
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     $toret = Hook::add('output', 'pre', get_called_class(), array('global' => 1)) && $toret;
     $toret = Permission::add('anonymous', 'add', get_called_class()) && $toret;
     $toret = Permission::add('authenticated', 'add', get_called_class()) && $toret;
     return $toret;
 }
Example #5
0
 /**
 @param	key	cookie key to use
 @param	data	if present, this is used as $this->data, otherise, key is used to find cookie for data
 */
 function __construct($key, $data = null, $options = null)
 {
     $this->key = $key;
     if ($data) {
         $this->data = $data;
     } else {
         $this->data = self::get($key);
     }
     self::$cookies[$key] =& $this->data;
     $this->options = $options;
     Hook::add('preHTTPMessageBody', array($this, 'out'), array('deleteAfter' => 1));
 }
function upgrade_module_1_5_1($module)
{
    if (Hook::getIdByName('displayPaymentEu')) {
        return true;
    }
    $new_hook = new Hook();
    $new_hook->name = 'displayPaymentEu';
    $new_hook->title = 'Display EU payment options (helper)';
    $new_hook->description = 'Hook to display payment options';
    $new_hook->position = true;
    $new_hook->live_edit = false;
    return (bool) $new_hook->add() && (bool) $module->registerModulesBackwardCompatHook();
}
Example #7
0
 function install()
 {
     if (Hook::get('orderPriceAdjustment') == false) {
         $hook = new Hook();
         $hook->name = 'orderPriceAdjustment';
         $hook->title = 'Order price adjustment';
         $hook->description = 'Allows modules to adjust prices in an order after the user has logged in and registered an address, e.g. allows prices based on group memberships and the like.';
         $hook->add();
     }
     if (parent::install() == false) {
         return false;
     }
     return true;
 }
Example #8
0
 function install()
 {
     if (Hook::get('orderAddressVerification') == false) {
         $hook = new Hook();
         $hook->name = 'orderAddressVerification';
         $hook->title = 'Order address verificatio';
         $hook->description = 'Allows modules to verify delivery and billing address in an order, e.g. require them to be in the same country';
         $hook->add();
     }
     if (parent::install() == false) {
         return false;
     }
     return true;
 }
 private function checkOwnerHooks()
 {
     $hookspos = array('displayTop', 'displayHeaderRight', 'displaySlideshow', 'topNavigation', 'displayPromoteTop', 'displayRightColumn', 'displayLeftColumn', 'displayHome', 'displayFooter', 'displayBottom', 'displayContentBottom', 'displayFootNav', 'displayFooterTop', 'displayFooterBottom');
     foreach ($hookspos as $hook) {
         if (Hook::getIdByName($hook)) {
         } else {
             $new_hook = new Hook();
             $new_hook->name = pSQL($hook);
             $new_hook->title = pSQL($hook);
             $new_hook->add();
         }
     }
     return true;
 }
Example #10
0
 function install()
 {
     if (Hook::get('orderPages') == false) {
         $hook = new Hook();
         $hook->name = 'orderPages';
         $hook->title = 'Order process pages';
         $hook->description = 'Adds new pages in the order process';
         $hook->add();
     }
     if (parent::install() == false or $this->registerHook('orderPages') == false) {
         return false;
     }
     return true;
 }
Example #11
0
 function install()
 {
     if (Hook::get('extraCarrierDetails') == false) {
         $hook = new Hook();
         $hook->name = 'extraCarrierDetails';
         $hook->title = 'Extra carrier dietails';
         $hook->description = 'Extra carrier dietails display part';
         $hook->add();
     }
     if (Hook::get('extraCarrierDetailsProcess') == false) {
         $hook = new Hook();
         $hook->name = 'extraCarrierDetailsProcess';
         $hook->title = 'Extra carrier dietails';
         $hook->description = 'Extra carrier dietails processing part';
         $hook->add();
     }
     return parent::install();
 }
Example #12
0
 function __construct($admin_path)
 {
     $this->check_magic_quotes();
     require $admin_path . '/core/library/config.php';
     $config = $this->config = new Config($admin_path);
     require $config->library_path . '/string.php';
     require $config->library_path . '/file.php';
     spl_autoload_register(array($this, 'autoload'));
     $is_config_loaded = $this->config->load();
     $this->setup_error_reporting();
     if (!$is_config_loaded) {
         $router = new Router($config, null, '/setup/install/');
     } else {
         $router = new Router($config);
     }
     $hook = new Hook();
     $admin_script = new Admin\Scripts($router->admin_url, $router, $config);
     $admin_style = new Admin\Styles($router->admin_url, $router, $config);
     $hook->add('admin_head', array($admin_style, 'do_items'), 0, 10);
     $hook->add('admin_head', array($admin_script, 'do_head_items'), 0, 10);
     $hook->add('admin_footer', array($admin_script, 'do_footer_items'), 0, 100);
     $settings = new Settings($config);
     $router->settings = $settings;
     $active_template = $settings->get_template_about();
     $template_script = new Template\Scripts('', $router, $config, $active_template['version']);
     $template_style = new Template\Styles('', $router, $config, $active_template['version']);
     $hook->add('head', array($template_style, 'do_items'), 0, 10);
     $hook->add('head', array($template_script, 'do_head_items'), 0, 10);
     $hook->add('footer', array($template_script, 'do_footer_items'), 0, 100);
     $user = new User($config, $router);
     $view = new View($config, $router, $hook);
     if ($settings->get('connection', 'type') && 'direct' != $settings->get('connection', 'type')) {
         $class_name = Filesystem::get_class_name($settings->get('connection', 'type'));
         $filesystem = new $class_name($config, array('connection_type' => $settings->get('connection', 'type'), 'hostname' => $settings->get('connection', 'hostname'), 'username' => $settings->get('connection', 'username'), 'password' => $settings->get('connection', 'password')));
     } else {
         $filesystem = new Filesystem\Direct($config);
     }
     $addon = new Addon($config, $settings, $hook, $admin_script, $admin_style, $template_script, $template_style, $filesystem, $router);
     $addon->load_active();
     $content = new Content($config, $filesystem, $router, $settings, $hook);
     $template = new Template($config, $filesystem, $router, $settings, $hook, $template_script, $template_style, $content);
     $router->parse_request_url();
     $router->set_controller_class();
     $controller_class = $router->controller_class;
     $controller = new $controller_class($router, $view, $filesystem, $config, $user, $template, $settings, $hook, $content, $addon);
     if (!$user->is_logged_in() && !$controller->is_no_auth_action()) {
         Router::redirect($router->admin_url('/user/login/'));
         exit;
     }
     $controller->call_action();
 }
 public function install()
 {
     $this->clearCache();
     if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header')) {
         return false;
     }
     $res = $this->createTables();
     if ($res) {
         $this->installSamples();
     }
     $hookspos = array('displayTop', 'displayHeaderRight', 'displaySlideshow', 'topNavigation', 'displayPromoteTop', 'displayRightColumn', 'displayLeftColumn', 'displayHome', 'displayFooter', 'displayBottom', 'displayContentBottom', 'displayFootNav', 'displayFooterTop', 'displayFooterBottom');
     foreach ($hookspos as $hook) {
         if (!Hook::getIdByName($hook)) {
             $new_hook = new Hook();
             $new_hook->name = pSQL($hook);
             $new_hook->title = pSQL($hook);
             $new_hook->add();
         }
     }
     return true;
 }
Example #14
0
function upgrade_module_1_4($object, $install = false)
{
    // First uninstall old override
    try {
        $object->uninstallOldOverrides();
    } catch (Exception $e) {
        $object->add_error(sprintf(Tools::displayError('Unable to uninstall old override: %s'), $e->getMessage()));
        //$this->uninstallOverrides(); remove this line because if module a install an override, then module b install same override, this line will remove override of module a (if you find a bug related to this line please don't forget what i say before)
        return false;
    }
    // Install overrides
    try {
        $object->installOverrides();
    } catch (Exception $e) {
        $object->add_error(sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage()));
        //$this->uninstallOverrides(); remove this line because if module a install an override, then module b install same override, this line will remove override of module a (if you find a bug related to this line please don't forget what i say before)
        return false;
    }
    if (!Hook::getIdByName('actionBeforeAddOrder')) {
        $hook = new Hook();
        $hook->name = 'actionBeforeAddOrder';
        $hook->title = 'New orders before order is added';
        $hook->description = 'Custom hook for PaymentModule ValidateOrder function';
        $hook->position = true;
        $hook->live_edit = false;
        $hook->add();
    }
    $id_new_hook = Hook::getIdByName('actionBeforeAddOrder');
    $id_old_hook = Hook::getIdByName('actionValidateOrder');
    $mod_new_hook = Hook::getModulesFromHook($id_new_hook, $object->id);
    $mod_old_hook = Hook::getModulesFromHook($id_old_hook, $object->id);
    if (empty($mod_new_hook)) {
        $object->registerHook('actionBeforeAddOrder');
    }
    if (!empty($mod_old_hook)) {
        $object->unregisterHook('actionValidateOrder');
    }
    return true;
}
Example #15
0
 public function run(&$content)
 {
     $data = S('hooks');
     if (!$data) {
         $hooks = M('Hooks')->getField('name,plugins');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Plugins')->where($map)->getField('id,name');
                 if ($data) {
                     $plugins = array_intersect($names, $data);
                     Hook::add($key, $plugins);
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
Example #16
0
 public function install()
 {
     if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('displayFooter')) {
         return false;
     }
     $langs = Language::getLanguages(false);
     $des = array();
     foreach ($langs as $lang) {
         $des[$lang['id_lang']] = '';
     }
     Configuration::updateValue($this->getConfigName('height'), 500);
     Configuration::updateValue($this->getConfigName('description'), $des, true);
     $hookspos = array('displayTop', 'displayHeaderRight', 'displaySlideshow', 'topNavigation', 'displayPromoteTop', 'displayRightColumn', 'displayLeftColumn', 'displayHome', 'displayFooter', 'displayBottom', 'displayContentBottom', 'displayFootNav', 'displayFooterTop', 'displayMapLocal', 'displayFooterBottom');
     foreach ($hookspos as $hook) {
         if (!Hook::getIdByName($hook)) {
             $new_hook = new Hook();
             $new_hook->name = pSQL($hook);
             $new_hook->title = pSQL($hook);
             $new_hook->add();
         }
     }
     return true;
 }
Example #17
0
 /**
  * 加载系统插件
  */
 private function loadAddons()
 {
     $data = S('hooks');
     if (!$data || DEBUG) {
         $hooks = M('hooks')->where("status=1")->getField('name,addons', true);
         if ($hooks) {
             foreach ($hooks as $key => $value) {
                 if ($value) {
                     $map['status'] = 1;
                     $names = explode(',', $value);
                     $map['name'] = array('IN', $names);
                     $data = M('addons')->where($map)->getField('id,name');
                     if ($data) {
                         $addons = array_intersect($names, $data);
                         Hook::add($key, $addons);
                     }
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
Example #18
0
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     $toret = Hook::add('display', 'post', get_called_class(), array('global' => 1)) && $toret;
     return $toret;
 }
Example #19
0
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     $toret = Hook::add('start', 'pre', __CLASS__, array('global' => true, 'sequence' => 1000)) && $toret;
     return $toret;
 }
Example #20
0
    /**
     * 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;
    }
Example #21
0
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     Hook::add('init', 'pre', get_called_class()) && $toret;
     return $toret;
 }
Example #22
0
function upgrade_module_1_5($object, $install = false)
{
    // Install overrides
    try {
        $object->installOverrides();
    } catch (Exception $e) {
        Tools::displayError(sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage()));
        //$this->uninstallOverrides(); remove this line because if module a install an override, then module b install same override, this line will remove override of module a (if you find a bug related to this line please don't forget what i say before)
        return false;
    }
    $classindex = realpath(dirname(__FILE__) . '/../..') . '/cache/class_index.php';
    unset($classindex);
    if (version_compare(_PS_VERSION_, '1.6', '>=')) {
        PrestashopAutoload::getInstance()->generateIndex();
    } else {
        Autoload::getInstance()->generateIndex();
    }
    if (!Hook::getIdByName('actionBeforeAddOrder')) {
        $hook = new Hook();
        $hook->name = 'actionBeforeAddOrder';
        $hook->title = 'Execute actions before order is added to database';
        $hook->description = 'Custom hook for Order Add function';
        $hook->position = true;
        $hook->live_edit = false;
        $hook->add();
    }
    if (!Hook::getIdByName('actionBeforeAddOrderInvoice')) {
        $hook2 = new Hook();
        $hook2->name = 'actionBeforeAddOrderInvoice';
        $hook2->title = 'Execute actions before invoice is added to database';
        $hook2->description = 'Custom hook for Order setLastInvoiceNumber function';
        $hook2->position = true;
        $hook2->live_edit = false;
        $hook2->add();
    }
    if (!Hook::getIdByName('actionBeforeAddDeliveryNumber')) {
        $hook3 = new Hook();
        $hook3->name = 'actionBeforeAddDeliveryNumber';
        $hook3->title = 'Execute actions before delivery number is added to database';
        $hook3->description = 'Custom hook for Order setDeliveryNumber function';
        $hook3->position = true;
        $hook3->live_edit = false;
        $hook3->add();
    }
    $id_new_hook = Hook::getIdByName('actionBeforeAddOrder');
    $id_new_hook2 = Hook::getIdByName('actionBeforeAddOrderInvoice');
    $id_new_hook3 = Hook::getIdByName('actionBeforeAddDeliveryNumber');
    $id_old_hook = Hook::getIdByName('actionValidateOrder');
    $mod_new_hook = Hook::getModulesFromHook($id_new_hook, $object->id);
    $mod_new_hook2 = Hook::getModulesFromHook($id_new_hook2, $object->id);
    $mod_new_hook3 = Hook::getModulesFromHook($id_new_hook3, $object->id);
    $mod_old_hook = Hook::getModulesFromHook($id_old_hook, $object->id);
    if (empty($mod_new_hook)) {
        $object->registerHook('actionBeforeAddOrder');
    }
    if (empty($mod_new_hook2)) {
        $object->registerHook('actionBeforeAddOrderInvoice');
    }
    if (empty($mod_new_hook3)) {
        $object->registerHook('actionBeforeAddDeliveryNumber');
    }
    if (!empty($mod_old_hook)) {
        $object->unregisterHook('actionValidateOrder');
    }
    return true;
}
Example #23
0
 public static function install(array $options = array())
 {
     $toret = parent::install($options);
     $toret = Permission::add('anonymous', 'display', get_called_class()) && $toret;
     $toret = Permission::add('authenticated', 'display', get_called_class()) && $toret;
     $toret = Permission::add('anonymous', 'list', get_called_class()) && $toret;
     $toret = Permission::add('authenticated', 'list', get_called_class()) && $toret;
     $toret = Hook::add('table_display', 'post', get_called_class(), array('global' => 1)) && $toret;
     $toret = Hook::add('table_update', 'pre', get_called_class(), array('global' => 1)) && $toret;
     $toret = Hook::add('table_update', 'post', get_called_class(), array('global' => 1)) && $toret;
     $toret = Hook::add('table_create', 'post', get_called_class(), array('global' => 1)) && $toret;
     return $toret;
 }
Example #24
0
 private function _installHookCustomer()
 {
     $hookspos = array('brandSlider');
     foreach ($hookspos as $hook) {
         if (Hook::getIdByName($hook)) {
         } else {
             $new_hook = new Hook();
             $new_hook->name = pSQL($hook);
             $new_hook->title = pSQL($hook);
             $new_hook->add();
             $id_hook = $new_hook->id;
         }
     }
     return true;
 }
Example #25
0
<?php

namespace think;

// 不做任何异常处理
// error_reporting(0);
// 初始化常量
define('TA_PATH', ROOT_PATH . 'ta/');
define('IS_GET', Request::instance()->isGet());
define('IS_POST', Request::instance()->isPost());
define('IS_AJAX', Request::instance()->isAjax());
define('NOW_TIME', Request::instance()->time());
// 增加行为定义
Hook::add('app_init', 'ta\\behavior\\AppInit');
Hook::add('module_init', 'ta\\behavior\\ModuleInit');
// 执行应用
App::run()->send();
 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;
 }
 /**
  * Install Hooks using for framework
  */
 private function _installHook()
 {
     $hookspos = LeoFrameworkHelper::getHookPositions();
     foreach ($hookspos as $hook) {
         if (Hook::getIdByName($hook)) {
         } else {
             $new_hook = new Hook();
             $new_hook->name = pSQL($hook);
             $new_hook->title = pSQL($hook);
             $new_hook->live_edit = 1;
             $new_hook->position = 1;
             $new_hook->add();
             $id_hook = $new_hook->id;
         }
     }
     return true;
 }
Example #28
0
 /**
  * Sets up the controller and figures out the view that needs to be loaded.
  * 
  * @access private
  * @final
  */
 private final function _controllerSetup()
 {
     // call hook
     Hook::call('Controller.setup.before');
     // Construct Code
     $this->params = Reg::get("URI.working");
     if (!strlen($this->params['view'])) {
         $this->params['view'] = Reg::get("URI.map.view");
     }
     $this->viewToLoad = Config::uriToMethod($this->params['view']);
     $this->formhandler = new Formhandler($this);
     // add hooks for designer fix and form handler
     Hook::add("Controller.loadView.after", array($this, "_designerFix"));
     Hook::add("Controller.loadView.after", array($this->formhandler, "decode"));
     // call hook
     Hook::call('Controller.setup.after', array(&$this));
 }
Example #29
0
 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;
     }
 }
    /**
     * render list of modules following positions in the layout editor.
     */
    public function renderList()
    {
        $filePath = _PS_ALL_THEMES_DIR_ . $this->theme_name . '';
        $showed = true;
        $xml = simplexml_load_file($filePath . '/config.xml');
        if (isset($xml->theme_key)) {
            $this->themeKey = trim((string) $xml->theme_key);
        }
        if ($this->themeKey) {
            $this->initToolbarTitle();
            $this->initToolbar();
            $hookspos = $this->hookspos;
            foreach ($hookspos as $hook) {
                if (Hook::getIdByName($hook)) {
                } else {
                    $new_hook = new Hook();
                    $new_hook->name = pSQL($hook);
                    $new_hook->title = pSQL($hook);
                    $new_hook->add();
                    $id_hook = $new_hook->id;
                }
            }
            Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
				UPDATE `' . _DB_PREFIX_ . 'hook` SET position=1, live_edit=1
						WHERE name in ("' . implode('","', $hookspos) . '")  ');
            $modules = Module::getModulesInstalled(0);
            $assoc_modules_id = array();
            $assoc_modules_id = $module_instances = array();
            foreach ($modules as $module) {
                if ($tmp_instance = Module::getInstanceById((int) $module['id_module'])) {
                    // We want to be able to sort modules by display name
                    $module_instances[$tmp_instance->displayName] = $tmp_instance;
                    // But we also want to associate hooks to modules using the modules IDs
                    $assoc_modules_id[(int) $module['id_module']] = $tmp_instance->displayName;
                }
            }
            $hooks = Hook::getHooks(!(int) Tools::getValue('hook_position'));
            $hookModules = array();
            $hookedModules = array();
            foreach ($hooks as $key => $hook) {
                // $key = $hook['name'];
                $k = $hook['name'];
                $k = Tools::strtolower(Tools::substr($k, 0, 1)) . Tools::substr($k, 1);
                if (in_array($k, $hookspos)) {
                    // Get all modules for this hook or only the filtered module
                    $hookModules[$k]['modules'] = Hook::getModulesFromHook($hook['id_hook'], $this->display_key);
                    $hookModules[$k]['module_count'] = count($hookModules[$k]['modules']);
                    if (is_array($hookModules[$k]['modules']) && !empty($hookModules[$k]['modules'])) {
                        foreach ($hookModules[$k]['modules'] as $module_key => $module) {
                            if (isset($assoc_modules_id[$module['id_module']])) {
                                $hookedModules[] = $module['id_module'];
                                $hookModules[$k]['modules'][$module_key]['instance'] = $module_instances[$assoc_modules_id[$module['id_module']]];
                            }
                        }
                    }
                }
            }
            //		  	echo '<pre>'.print_r($hookedModules,1); die;
            $instances = array();
            foreach ($modules as $module) {
                if ($tmp_instance = Module::getInstanceById($module['id_module'])) {
                    if (!in_array($module['id_module'], $hookedModules)) {
                        foreach ($hookspos as $hk) {
                            $retro_hook_name = Hook::getRetroHookName($hk);
                            $hook_callable = is_callable(array($tmp_instance, 'hook' . $hk));
                            $hook_retro_callable = is_callable(array($tmp_instance, 'hook' . $retro_hook_name));
                            if ($hook_retro_callable || $hook_callable) {
                                $instances[$tmp_instance->displayName] = $tmp_instance;
                                break;
                            }
                        }
                        //	echo '<pre>'.print_r( $instances, 1 ); die;
                    }
                }
            }
            ksort($instances);
            $modules = $instances;
            $tpl = $this->createTemplate('panel.tpl');
            $this->context->controller->addCss(__PS_BASE_URI__ . str_replace("//", "/", 'modules/leotempcp') . '/assets/admin/style.css', 'all');
            $this->context->controller->addJs(__PS_BASE_URI__ . str_replace("//", "/", 'modules/leotempcp') . '/assets/admin/jquery-ui-1.10.3.custom.min.js', 'all');
            $tpl->assign(array('showed' => $showed, 'toolbar' => $this->context->smarty->fetch('toolbar.tpl'), 'modules' => $modules, 'hookspos' => $hookspos, 'URI' => __PS_BASE_URI__ . 'modules/', 'hookModules' => $hookModules, 'noModuleConfig' => $this->l('No Configuration For This Module'), 'currentURL' => 'index.php?tab=AdminLeotempcpPanel&token=' . Tools::getAdminTokenLite('AdminLeotempcpPanel') . '', 'moduleEditURL' => 'index.php?controller=adminmodules&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=Home'));
            return $tpl->fetch();
        } else {
            $tpl = $this->createTemplate('error.tpl');
            $tpl->assign(array('showed' => false, 'themeURL' => 'index.php?controller=AdminThemes&token=' . Tools::getAdminTokenLite('AdminThemes')));
            return $tpl->fetch();
        }
    }