public function renderForm() { // Init toolbar $this->initToolbarTitle(); // toolbar (save, cancel, new, ..) $this->initToolbar(); $id_module = (int) Tools::getValue('id_module'); $id_hook = (int) Tools::getValue('id_hook'); if (Tools::isSubmit('editGraft')) { // Check auth for this page if (!$id_module || !$id_hook) { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token); } $sql = 'SELECT id_module FROM ' . _DB_PREFIX_ . 'hook_module WHERE id_module = ' . $id_module . ' AND id_hook = ' . $id_hook . ' AND id_shop IN(' . implode(', ', Shop::getContextListShopID()) . ')'; if (!Db::getInstance()->getValue($sql)) { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token); } $sl_module = Module::getInstanceById($id_module); $excepts_list = $sl_module->getExceptions($id_hook, true); $excepts_diff = false; $excepts = ''; if ($excepts_list) { $first = current($excepts_list); foreach ($excepts_list as $k => $v) { if (array_diff($v, $first) || array_diff($first, $v)) { $excepts_diff = true; } } if (!$excepts_diff) { $excepts = implode(', ', $first); } } } else { $excepts_diff = false; $excepts_list = Tools::getValue('exceptions', array(array())); } $modules = Module::getModulesInstalled(0); $instances = array(); foreach ($modules as $module) { if ($tmp_instance = Module::getInstanceById($module['id_module'])) { $instances[$tmp_instance->displayName] = $tmp_instance; } } ksort($instances); $modules = $instances; $hooks = Hook::getHooks(0); $exception_list_diff = array(); foreach ($excepts_list as $shop_id => $file_list) { $exception_list_diff[] = $this->displayModuleExceptionList($file_list, $shop_id); } $tpl = $this->createTemplate('form.tpl'); $tpl->assign(array('url_submit' => self::$currentIndex . '&token=' . $this->token, 'edit_graft' => Tools::isSubmit('editGraft'), 'id_module' => (int) Tools::getValue('id_module'), 'id_hook' => (int) Tools::getValue('id_hook'), 'show_modules' => Tools::getValue('show_modules'), 'hooks' => $hooks, 'exception_list' => $this->displayModuleExceptionList(array_shift($excepts_list), 0), 'exception_list_diff' => $exception_list_diff, 'except_diff' => isset($excepts_diff) ? $excepts_diff : null, 'display_key' => $this->display_key, 'modules' => $modules, 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => $this->toolbar_scroll, 'title' => $this->toolbar_title, 'table' => 'hook_module')); return $tpl->fetch(); }
/** * 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(); } }
public function displayForm() { global $currentIndex; $id_module = intval(Tools::getValue('id_module')); $id_hook = intval(Tools::getValue('id_hook')); if ($id_module and $id_hook and Tools::isSubmit('editGraft')) { $slModule = Module::getInstanceById($id_module); $exceptsList = $slModule->getExceptions($id_hook); $excepts = ''; foreach ($exceptsList as $key => $except) { $excepts .= ($key ? ',' : '') . $except['file_name']; } } $excepts = strval(Tools::getValue('exceptions', (isset($slModule) and Validate::isLoadedObject($slModule)) ? $excepts : '')); $modules = Module::getModulesInstalled(0); $instances = array(); foreach ($modules as $module) { if ($tmpInstance = Module::getInstanceById($module['id_module'])) { $instances[$tmpInstance->displayName] = $tmpInstance; } } ksort($instances); $modules = $instances; $hooks = Hook::getHooks(0); echo ' <form action="' . $currentIndex . '&token=' . $this->token . '" method="post">'; if ($this->displayKey) { echo '<input type="hidden" name="show_modules" value="' . $this->displayKey . '" />'; } echo '<fieldset class="width3" style="width:700px;"><legend><img src="../img/t/AdminModulesPositions.gif" />' . $this->l('Transplant a module') . '</legend> <label>' . $this->l('Module') . ' :</label> <div class="margin-form"> <select name="id_module"' . (Tools::isSubmit('editGraft') ? ' disabled="disabled"' : '') . '>'; foreach ($modules as $module) { echo ' <option value="' . $module->id . '" ' . ($id_module == $module->id ? 'selected="selected" ' : '') . '>' . stripslashes($module->displayName) . '</option>'; } echo ' </select><sup> *</sup> </div> <label>' . $this->l('Hook into') . ' :</label> <div class="margin-form"> <select name="id_hook"' . (Tools::isSubmit('editGraft') ? ' disabled="disabled"' : '') . '>'; foreach ($hooks as $hook) { echo ' <option value="' . $hook['id_hook'] . '" ' . ($id_hook == $hook['id_hook'] ? 'selected="selected" ' : '') . '>' . $hook['title'] . '</option>'; } echo ' </select><sup> *</sup> </div> <label>' . $this->l('Exceptions') . ' :</label> <div class="margin-form"> <input type="text" name="exceptions" size="40" ' . (!empty($excepts) ? 'value="' . $excepts . '"' : '') . '><br />Ex: identity.php, history.php, order.php, product.php<br /><br /> ' . $this->l('Please specify those files in which you do not want the module to be displayed') . '.<br /> ' . $this->l('These files are located in your base directory') . ', ' . $this->l('e.g., ') . ' <b>identity.php</b>.<br /> ' . $this->l('Please type each filename separated by a comma') . '. <br /><br /> </div> <div class="margin-form"> '; if (Tools::isSubmit('editGraft')) { echo ' <input type="hidden" name="id_module" value="' . $id_module . '" /> <input type="hidden" name="id_hook" value="' . $id_hook . '" />'; } echo ' <input type="submit" value="' . $this->l('Save') . '" name="' . (Tools::isSubmit('editGraft') ? 'submitEditGraft' : 'submitAddToHook') . '" class="button" /> </div> <div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div> </fieldset> </form>'; }
/** * Return the hooks list where this module can be hooked. * * @return array Hooks list. */ public function getPossibleHooksList() { $hooks_list = Hook::getHooks(); $possible_hooks_list = array(); foreach ($hooks_list as &$current_hook) { $hook_name = $current_hook['name']; $retro_hook_name = Hook::getRetroHookName($hook_name); if (is_callable(array($this, 'hook' . ucfirst($hook_name))) || is_callable(array($this, 'hook' . ucfirst($retro_hook_name)))) { $possible_hooks_list[] = array('id_hook' => $current_hook['id_hook'], 'name' => $hook_name, 'title' => $current_hook['title']); } } return $possible_hooks_list; }
public static function removeAllHooksFromModule(\Module &$module) { foreach (\Hook::getHooks() as $k => $hook) { $module->unregisterHook((int) $hook['id_hook']); } }
public function initMain() { // Init toolbar $this->initToolbarTitle(); $admin_dir = basename(_PS_ADMIN_DIR_); $modules = Module::getModulesInstalled(); $assoc_modules_id = 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; } } ksort($module_instances); $hooks = Hook::getHooks(false, true); foreach ($hooks as $key => $hook) { // Get all modules for this hook or only the filtered module $hooks[$key]['modules'] = Hook::getModulesFromHook($hook['id_hook'], $this->display_key); $hooks[$key]['module_count'] = count($hooks[$key]['modules']); if ($hooks[$key]['module_count']) { // If modules were found, link to the previously created Module instances if (is_array($hooks[$key]['modules']) && !empty($hooks[$key]['modules'])) { foreach ($hooks[$key]['modules'] as $module_key => $module) { if (isset($assoc_modules_id[$module['id_module']])) { $hooks[$key]['modules'][$module_key]['instance'] = $module_instances[$assoc_modules_id[$module['id_module']]]; } } } } else { unset($hooks[$key]); } } $this->addJqueryPlugin('tablednd'); $this->toolbar_btn['save'] = array('href' => self::$currentIndex . '&addToHook' . ($this->display_key ? '&show_modules=' . $this->display_key : '') . '&token=' . $this->token, 'desc' => $this->l('Transplant a module')); $this->context->smarty->assign(array('show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->toolbar_title, 'toolbar_scroll' => 'false', 'token' => $this->token, 'url_show_modules' => self::$currentIndex . '&token=' . $this->token . '&show_modules=', 'modules' => $module_instances, 'url_show_invisible' => self::$currentIndex . '&token=' . $this->token . '&show_modules=' . (int) Tools::getValue('show_modules') . '&hook_position=', 'display_key' => $this->display_key, 'hooks' => $hooks, 'url_submit' => self::$currentIndex . '&token=' . $this->token, 'can_move' => Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP ? false : true)); return $this->createTemplate('list_modules.tpl')->fetch(); }