// AdminTab compatibility: Dispatcher for BO now search tabs in database, not on the disk. AdminTabs now uses the new BO theme.

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10236 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-11-17 18:15:07 +00:00
parent 60272fbce4
commit 740ac7c843
9 changed files with 163 additions and 145 deletions
+2 -3
View File
@@ -61,7 +61,7 @@ class AdminControllerCore extends Controller
/** @var integer Tab id */
public $id = -1;
/** @var array noTabLink array of admintab names witch have no content */
/** @var array noTabLink array of admintabs with no content */
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
/** @var string Security token */
@@ -748,7 +748,6 @@ class AdminControllerCore extends Controller
if ($this->tabAccess['edit'] === '1')
{
$this->beforeUpdateOptions();
$languages = Language::getLanguages(false);
foreach ($this->options as $category => $category_data)
@@ -852,7 +851,7 @@ class AdminControllerCore extends Controller
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
// todo : return value ?
}
+3
View File
@@ -199,6 +199,9 @@ abstract class AdminTabCore
'AdminStatsTab' => 'AdminStats'
);
/** @var array noTabLink array of admintabs with no content */
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
public function __construct()
{
$this->context = Context::getContext();
+64 -12
View File
@@ -144,12 +144,12 @@ class DispatcherCore
/**
* @var string Set default controller, which will be used if http parameter 'controller' is empty
*/
protected $default_controller = 'index';
protected $default_controller = 'Index';
/**
* @var string Controller to use if found controller doesn't exist
*/
protected $controller_not_found = 'pagenotfound';
protected $controller_not_found = 'PageNotFound';
/**
* @var array List of controllers where are stored controllers
@@ -217,6 +217,30 @@ class DispatcherCore
$this->controller_directories = $dir;
}
public static function getAdminController($name)
{
if (!Validate::isTabName($name))
return false;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, class_name, module FROM `'._DB_PREFIX_.'tab` WHERE LOWER(class_name) = \''.pSQL($name).'\'');
return $row;
}
public static function includeModuleClass($module, $name)
{
if (file_exists(_PS_MODULE_DIR_.$module.'/'.$name.'Controller.php'))
{
include(_PS_MODULE_DIR_.$module.'/'.$name.'Controller.php');
return true;
}
if (file_exists(_PS_MODULE_DIR_.$module.'/'.$name.'.php'))
{
include(_PS_MODULE_DIR_.$module.'/'.$name.'.php');
return false;
}
}
/**
* Find the controller and instantiate it
*/
@@ -234,26 +258,54 @@ class DispatcherCore
// Get current controller and list of controllers
$this->getController();
$controllers = Dispatcher::getControllers($this->controller_directories);
if (!$this->controller)
$this->controller = $this->default_controller;
// For retrocompatibility with admin/tabs/ old system
if (isset($controllers[$this->controller]) && defined('_PS_ADMIN_DIR_') && file_exists(_PS_ADMIN_DIR_.'/tabs/'.$controllers[$this->controller].'.php'))
// FO dispatch
if (!defined('_PS_ADMIN_DIR_'))
{
require_once(_PS_ADMIN_DIR_.'/functions.php');
$ajaxMode = !empty($_REQUEST['ajaxMode']);
runAdminTab($ajaxMode);
return;
$controllers = self::getControllers($this->controller_directories);
if (isset($controllers[$this->controller]))
$this->controller = $controllers[$this->controller];
else
$this->controller = $this->controller_not_found;
}
// BO dispatch
else
{
// Get controller class name
$controller_row = self::getAdminController($this->controller);
if (empty($controller_row))
$this->controller = $this->controller_not_found;
else
$this->controller = $controller_row['class_name'];
// If Tab/Controller is in module, include it
if (!empty($controller_row['module']))
$is_controller = self::includeModuleClass($controller_row['module'], $this->controller);
// If it is an AdminTab, include it
elseif (file_exists(_PS_ADMIN_DIR_.'/tabs/'.$this->controller.'.php'))
{
include(_PS_ADMIN_DIR_.'/tabs/'.$this->controller.'.php');
$is_controller = false;
}
// For retrocompatibility with admin/tabs/ old system
if (isset($is_controller) && !$is_controller)
{
require_once(_PS_ADMIN_DIR_.'/functions.php');
$ajaxMode = !empty($_REQUEST['ajaxMode']);
runAdminTab($this->controller, $ajaxMode);
return;
}
else
$this->controller = $this->controller.'Controller';
}
else if (!isset($controllers[$this->controller]))
$this->controller = $this->controller_not_found;
// Instantiate controller
try
{
Controller::getController($controllers[$this->controller])->run();
Controller::getController($this->controller)->run();
}
catch (PrestashopException $e)
{