public static function getDefaultControllerClass() { if (isset(Context::getContext()->employee) && Validate::isLoadedObject(Context::getContext()->employee) && isset(Context::getContext()->employee->default_tab)) { $default_controller = Tab::getClassNameById((int) Context::getContext()->employee->default_tab); } if (empty($default_controller)) { $default_controller = 'AdminDashboard'; } $controllers = Dispatcher::getControllers(array(_PS_ADMIN_DIR_ . '/tabs/', _PS_ADMIN_CONTROLLER_DIR_, _PS_OVERRIDE_DIR_ . 'controllers/admin/')); if (!isset($controllers[strtolower($default_controller)])) { $default_controller = 'adminnotfound'; } $controller_class = $controllers[strtolower($default_controller)]; return $controller_class; }
public function displayModuleExceptionList($file_list, $shop_id) { if (!is_array($file_list)) { $file_list = $file_list ? array($file_list) : array(); } $content = '<input type="text" name="exceptions[' . $shop_id . ']" size="40" value="' . implode(', ', $file_list) . '" id="em_text_' . $shop_id . '" />'; if ($shop_id) { $shop = new Shop($shop_id); $content .= ' (' . $shop->name . ')'; } $content .= ' <br /> <select id="em_list_' . $shop_id . '" size="45" multiple="multiple" style="width:237px"> <option disabled="disabled">' . $this->l('___________ CUSTOM ___________') . '</option>'; // @todo do something better with controllers $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); ksort($controllers); foreach ($file_list as $k => $v) { if (!array_key_exists($v, $controllers)) { $content .= ' <option value="' . $v . '">' . $v . '</option>'; } } $content .= ' <option disabled="disabled">' . $this->l('____________ CORE ____________') . '</option>'; foreach ($controllers as $k => $v) { $content .= ' <option value="' . $k . '">' . $k . '</option>'; } $content .= ' </select> '; return $content; }
/** * Find the controller and instantiate it */ public function dispatch() { $controller_class = ''; // Get current controller $this->getController(); if (!$this->controller) { $this->controller = $this->useDefaultController(); } // Dispatch with right front controller switch ($this->front_controller) { // Dispatch front office controller case self::FC_FRONT: $controllers = Dispatcher::getControllers(array(_PS_FRONT_CONTROLLER_DIR_, _PS_OVERRIDE_DIR_ . 'controllers/front/')); $controllers['index'] = 'IndexController'; if (isset($controllers['auth'])) { $controllers['authentication'] = $controllers['auth']; } if (isset($controllers['compare'])) { $controllers['productscomparison'] = $controllers['compare']; } if (isset($controllers['contact'])) { $controllers['contactform'] = $controllers['contact']; } if (!isset($controllers[strtolower($this->controller)])) { $this->controller = $this->controller_not_found; } $controller_class = $controllers[strtolower($this->controller)]; $params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 0); break; // Dispatch module controller for front office // Dispatch module controller for front office case self::FC_MODULE: $module_name = Validate::isModuleName(Tools::getValue('module')) ? Tools::getValue('module') : ''; $module = Module::getInstanceByName($module_name); $controller_class = 'PageNotFoundController'; if (Validate::isLoadedObject($module) && $module->active) { $controllers = Dispatcher::getControllers(_PS_MODULE_DIR_ . $module_name . '/controllers/front/'); if (isset($controllers[strtolower($this->controller)])) { include_once _PS_MODULE_DIR_ . $module_name . '/controllers/front/' . $this->controller . '.php'; $controller_class = $module_name . $this->controller . 'ModuleFrontController'; } } $params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 1); break; // Dispatch back office controller + module back office controller // Dispatch back office controller + module back office controller case self::FC_ADMIN: if ($this->use_default_controller && !Tools::getValue('token') && Validate::isLoadedObject(Context::getContext()->employee) && Context::getContext()->employee->isLoggedBack()) { Tools::redirectAdmin('index.php?controller=' . $this->controller . '&token=' . Tools::getAdminTokenLite($this->controller)); } $tab = Tab::getInstanceFromClassName($this->controller, Configuration::get('PS_LANG_DEFAULT')); $retrocompatibility_admin_tab = null; if ($tab->module) { if (file_exists(_PS_MODULE_DIR_ . $tab->module . '/' . $tab->class_name . '.php')) { $retrocompatibility_admin_tab = _PS_MODULE_DIR_ . $tab->module . '/' . $tab->class_name . '.php'; } else { $controllers = Dispatcher::getControllers(_PS_MODULE_DIR_ . $tab->module . '/controllers/admin/'); if (!isset($controllers[strtolower($this->controller)])) { $this->controller = $this->controller_not_found; $controller_class = 'AdminNotFoundController'; } else { // Controllers in modules can be named AdminXXX.php or AdminXXXController.php include_once _PS_MODULE_DIR_ . $tab->module . '/controllers/admin/' . $controllers[strtolower($this->controller)] . '.php'; $controller_class = $controllers[strtolower($this->controller)] . (strpos($controllers[strtolower($this->controller)], 'Controller') ? '' : 'Controller'); } } $params_hook_action_dispatcher = array('controller_type' => self::FC_ADMIN, 'controller_class' => $controller_class, 'is_module' => 1); } else { $controllers = Dispatcher::getControllers(array(_PS_ADMIN_DIR_ . '/tabs/', _PS_ADMIN_CONTROLLER_DIR_, _PS_OVERRIDE_DIR_ . 'controllers/admin/')); if (!isset($controllers[strtolower($this->controller)])) { // If this is a parent tab, load the first child if (Validate::isLoadedObject($tab) && $tab->id_parent == 0 && ($tabs = Tab::getTabs(Context::getContext()->language->id, $tab->id)) && isset($tabs[0])) { Tools::redirectAdmin(Context::getContext()->link->getAdminLink($tabs[0]['class_name'])); } $this->controller = $this->controller_not_found; } $controller_class = $controllers[strtolower($this->controller)]; $params_hook_action_dispatcher = array('controller_type' => self::FC_ADMIN, 'controller_class' => $controller_class, 'is_module' => 0); if (file_exists(_PS_ADMIN_DIR_ . '/tabs/' . $controller_class . '.php')) { $retrocompatibility_admin_tab = _PS_ADMIN_DIR_ . '/tabs/' . $controller_class . '.php'; } } // @retrocompatibility with admin/tabs/ old system if ($retrocompatibility_admin_tab) { include_once $retrocompatibility_admin_tab; include_once _PS_ADMIN_DIR_ . '/functions.php'; runAdminTab($this->controller, !empty($_REQUEST['ajaxMode'])); return; } break; default: throw new PrestaShopException('Bad front controller chosen'); } // Instantiate controller try { // Loading controller $controller = Controller::getController($controller_class); // Execute hook dispatcher if (isset($params_hook_action_dispatcher)) { Hook::exec('actionDispatcher', $params_hook_action_dispatcher); } // Running controller $controller->run(); } catch (PrestaShopException $e) { $e->displayMessage(); } }
public function displayModuleExceptionList($file_list, $shop_id) { if (!is_array($file_list)) { $file_list = $file_list ? array($file_list) : array(); } $content = '<p><input type="text" name="exceptions[' . $shop_id . ']" value="' . implode(', ', $file_list) . '" id="em_text_' . $shop_id . '"/></p>'; if ($shop_id) { $shop = new Shop($shop_id); $content .= ' (' . $shop->name . ')'; } $content .= '<p> <select size="25" id="em_list_' . $shop_id . '" multiple="multiple"> <option disabled="disabled">' . $this->l('___________ CUSTOM ___________') . '</option>'; // @todo do something better with controllers $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); ksort($controllers); foreach ($file_list as $k => $v) { if (!array_key_exists($v, $controllers)) { $content .= '<option value="' . $v . '">' . $v . '</option>'; } } $content .= '<option disabled="disabled">' . $this->l('____________ CORE ____________') . '</option>'; foreach ($controllers as $k => $v) { $content .= '<option value="' . $k . '">' . $k . '</option>'; } $modules_controllers_type = array('admin' => $this->l('Admin modules controller'), 'front' => $this->l('Front modules controller')); foreach ($modules_controllers_type as $type => $label) { $content .= '<option disabled="disabled">____________ ' . $label . ' ____________</option>'; $all_modules_controllers = Dispatcher::getModuleControllers($type); foreach ($all_modules_controllers as $module => $modules_controllers) { foreach ($modules_controllers as $cont) { $content .= '<option value="module-' . $module . '-' . $cont . '">module-' . $module . '-' . $cont . '</option>'; } } } $content .= '</select> </p>'; return $content; }
public function displayModuleExceptionList() { $file_list = array(); // $shop_id = 0; $content = '<p><input type="text" name="column_pages" value="" class="em_text"/></p>'; $content .= '<p> <select size="25" name="column_pages_select" class="em_list" multiple="multiple"> <option disabled="disabled">' . $this->l('___________ CUSTOM ___________') . '</option>'; // @todo do something better with controllers $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); $controllers['module'] = $this->l('Module Page'); ksort($controllers); foreach ($file_list as $k => $v) { if (!array_key_exists($v, $controllers)) { $content .= '<option value="' . $v . '">' . $v . '</option>'; } } $content .= '<option disabled="disabled">' . $this->l('____________ CORE ____________') . '</option>'; foreach ($controllers as $k => $v) { $content .= '<option value="' . $k . '">' . $k . '</option>'; } $modules_controllers_type = array('admin' => $this->l('Admin modules controller'), 'front' => $this->l('Front modules controller')); foreach ($modules_controllers_type as $type => $label) { $content .= '<option disabled="disabled">____________ ' . $label . ' ____________</option>'; $all_modules_controllers = Dispatcher::getModuleControllers($type); foreach ($all_modules_controllers as $module => $modules_controllers) { foreach ($modules_controllers as $cont) { $content .= '<option value="module-' . $module . '-' . $cont . '">module-' . $module . '-' . $cont . '</option>'; } } } $content .= '</select> </p>'; return $content; }
public function displayModuleExceptionList($file_list, $shop_id) { if (!is_array($file_list)) { $file_list = $file_list ? array($file_list) : array(); } $content = '<input type="text" name="exceptions[' . $shop_id . ']" size="40" value="' . implode(', ', $file_list) . '" id="em_text_' . $shop_id . '">'; if ($shop_id) { $shop = new Shop($shop_id); $content .= ' (' . $shop->name . ')'; } $content .= '<br /><select id="em_list_' . $shop_id . '">'; // @todo do something better with controllers $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); ksort($controllers); foreach ($controllers as $k => $v) { $content .= '<option value="' . $k . '">' . $k . '</option>'; } $content .= '</select> <input type="button" class="button" value="' . $this->l('Add') . '" onclick="position_exception_add(' . $shop_id . ')" /> <input type="button" class="button" value="' . $this->l('Remove') . '" onclick="position_exception_remove(' . $shop_id . ')" /><br /><br />'; return $content; }
/** all the forms */ private function _displayForm() { $standardHooks = $this->standardHooks; /* permissions*/ $enabled = false; if ($this->context->employee->id_profile == _PS_ADMIN_PROFILE_ || $this->settings['permissions']['hooks'] == 0) { $enabled = true; } if ($sort = Tools::getValue('sort')) { //sort order changed but the variable $this->hook is already set and will not be loaded until next page load so use the sort parameter instead $this->hook = $sort; } /** General hook settings */ if ($enabled) { $this->_html .= ' <form id="sliders_setup" action="' . AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite($this->name) . '" method="post"> <fieldset> <legend><img src="' . $this->module->getBaseUrl() . '/modules/' . $this->module->name . '/logo.png" alt="logo" />' . $this->l('Slides Setup') . ' </legend> <p>' . $this->l('Choose where you want your sliders to appear, add new sliders or delete it.') . '</p> <table class="table confighooks" > <tr > <th>' . $this->l('Slider Name') . '</th> <th>' . $this->l('Top') . '</th> <th>' . $this->l('Home') . '</th> <th>' . $this->l('Left Sidebar') . '</th> <th>' . $this->l('Left Product Sidebar') . '</th> <th>' . $this->l('Right Sidebar') . '</th> <th>' . $this->l('Right Product Sidebar') . '</th> <th>' . $this->l('Footer') . '</th> <th>' . $this->l('Product Footer') . '</th>'; if ($this->module->isPS6) { $this->_html .= ' <th>' . $this->l('Top column') . '</th> <th>' . $this->l('Home Tab Content') . '</th> <th>' . $this->l('Product Tab') . '</th> <th>' . $this->l('Shopping Cart Foot') . '</th> <th>' . $this->l('Banner') . '</th> '; } $this->_html .= ' <th>' . $this->l('Category Image') . '</th> <th><b>' . $this->l('Delete') . '</b></th> </tr>'; if (is_array($this->hook) && !empty($this->hook)) { $i = 0; foreach ($this->hook as $hookid => $hookname) { $this->_html .= '<tr class="' . ($i % 2 == 0 ? 'odd' : 'even') . '"> <td><i class="handle fa fa-arrows-v"></i>' . $hookname . '<input type="hidden" name="sort[]" value="' . $hookname . '"/></td>'; foreach ($this->baseHooks as $shook) { // standard prestashop hooks if (isset($standardHooks[$shook]) && is_array($standardHooks[$shook]) && in_array($hookname, $standardHooks[$shook])) { $checked = "checked='checked'"; $class = 'active'; } else { $checked = ''; $class = ''; } $this->_html .= '<td class="' . $class . '"> <input ' . $checked . ' type="checkbox" name="standardHooks[' . $shook . '][]" value="' . $hookname . '" /> </td>'; } // category hook if (!($chosenCat = $this->module->getCategoryIdBySlide($hookname))) { $chosenCat = ''; } $this->_html .= '<td>' . $this->l('Category ID') . ': <input size="2" class="catnumber" type="number" value="' . $chosenCat . '" name="cat[' . $hookname . ']"/></td>'; $this->_html .= '<td class="delete"><input type="checkbox" name="hooksetup[' . $hookid . ']" value="' . $hookname . '"/></td>'; $this->_html .= '</tr>'; $i++; } } /** save hooks */ $this->_html .= '</table><br/> <div class="margin-form"> <input class="button" type="submit" name="saveHooks" value="' . $this->l('Save Hook Configuration') . '"/> <input class="button deleteSlide" type="submit" name="deleteHook" value="' . $this->l('Delete Selected Slides') . '"/> </div>'; $this->_html .= '<hr/><label><span class="fa fa-plus-circle"></span> ' . $this->l('New Slider name') . '</label> <div class="margin-form"><input type="text" name="newSlide" value=""/> (' . $this->l('Only lowercase letters and underscores, no special characters, no numbers or blank spaces.') . ')</div> <div class="margin-form"><input class="button" type="submit" name="addHook" value="' . $this->l('Add New Slider') . '"/></div>'; $this->_html .= '</fieldset></form>'; } // end if enabled permissions /** End Genearl settings */ /** slide CHOOSER **/ $slideArray = array(); // cache slides to avoide multiple queries $this->_html .= '<div class="slideChooserCont">'; if (is_array($this->hook) && !empty($this->hook)) { foreach ($this->hook as $hookId => $hookname) { $slideArray[$hookname] = $this->module->getSlides(null, $hookname); $empty = !$slideArray[$hookname] ? true : false; $count = count($slideArray[$hookname]); $this->_html .= '<a class="slideChoose ' . ($hookId == 0 ? 'active' : '') . '" href="#' . $hookname . 'slideConf"><span class="anim">' . $hookname . ' ' . ($empty ? '<span title="' . $this->l('You have not yet added any slides.') . '" class="fa fa-exclamation"></span>' : '<span class="number">' . $count . '</span>') . '</span></a>'; } } $this->_html .= '</div>'; /** slides configuration **/ $this->_html .= '<form id="sliders_config" class="fixsize" action="' . AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite($this->name) . '" method="post">'; $confs = $this->configuration; $filterData = array(); // controllers for the filter list; $filterData['controllers'] = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); // categories for the filter list; $filterData['categories'] = Category::getSimpleCategories((int) Context::getContext()->language->id); // manufacturers for the filter list; $filterData['manufacturers'] = Manufacturer::getManufacturers(); // sliders configuration tabs if (is_array($this->hook) && !empty($this->hook)) { foreach ($this->hook as $hookId => $hookname) { $this->_html .= '<fieldset class="position ' . $hookname . ' ' . ($hookId == 0 ? 'open' : '') . '" id="' . $hookname . 'slideConf"><legend><img src="' . $this->module->getBaseUrl() . '/modules/' . $this->module->name . '/logo.png" alt="logo" /> ' . $this->l('Slider') . ': "' . $hookname . '"</legend>'; $this->_html .= '<div class="codes">' . $this->l('Custom hook code') . ': <span class="hookCode">{hook h="displaySlidersPro" slider="' . $hookname . '"}</span> '; $this->_html .= $this->l('Shortcode for editors') . ': <span class="hookCode">[SE:' . $hookname . ']</span></div>'; $this->_html .= '<strong class="add_slide_button"> <a href="' . AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite($this->name) . '&addSlide&hook=' . $hookname . '"> <i class="fa fa-plus-circle addslide"></i> ' . $this->l('Add Slide') . ' </a> </strong>'; // tabbed slide configuration options $this->renderSlideConfigurations($hookId, $hookname, $confs); /* Gets Slides from stored array*/ $slides = $slideArray[$hookname]; //sortable list of slides $this->renderSortableSlideList($slides, $hookname); /* FILTERS */ $this->renderFiltersConfiguration($confs, $hookname, $filterData); $this->_html .= '</fieldset>'; } // enf hook foreach } $this->_html .= '</form>'; $this->_html .= "<script type='text/javascript'>\n\n\t\t\t\$('#hints').click(function(){\n\t\t\t\t\$('#hints').parent().find('.margin-form').slideToggle();\n\t\t\t});\n\t\t\t\$('#slide-save').click(function(){\n\t\t\t\t\$('#sliders_config').submit();\n\t\t\t})\n\t\t\n\t\t\t\$('#sliders_config').submit(function(e){\n\t\t\t\t//e.preventDefault();\n\t\t\t\tvar valid = true;\n\t\t\t\t\$('input.config').each(function(){\n\t\t\t\t\tif (\$(this).val() =='' || isNaN(\$(this).val()) ) {\n\t\t\t\t\t\tvalid = false;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t\n\t\t\t\tif (valid == true) {\n\t\t\t\t\treturn true;\n\t\t\t\t} else {\n\t\t\t\t\talert('" . $this->l('Enter a valid number') . "');\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t})\n\t\t</script>"; $this->_html .= $this->module->getCreds(); }