parseRequest($request_string); } } /** * Parse request data * @param string|array $request_data * @return e_admin_request */ protected function parseRequest($request_data) { if(is_string($request_data)) { parse_str($request_data, $request_data); } $this->_request_qry = (array) $request_data; // Set current mode if(isset($this->_request_qry[$this->_mode_key])) { $this->_mode = preg_replace('/[\W]/', '', $this->_request_qry[$this->_mode_key]); } // Set current action if(isset($this->_request_qry[$this->_action_key])) { $this->_action = preg_replace('/[\W]/', '', $this->_request_qry[$this->_action_key]); } // Set current id if(isset($this->_request_qry[$this->_id_key])) { $this->_id = preg_replace('/[^\w\-:\.]/', '', $this->_request_qry[$this->_id_key]); } $this->_posted_qry =& $_POST; //raw? return $this; } /** * Retrieve variable from GET scope * If $key is null, all GET data will be returned * * @param string $key [optional] * @param mixed $default [optional] * @return mixed */ public function getQuery($key = null, $default = null) { if($key === null) { return $this->_request_qry; } return (isset($this->_request_qry[$key]) ? $this->_request_qry[$key] : $default); } /** * Set/Unset GET variable * If $key is array, $value is not used. * If $value is null, (string) $key is unset * * @param string|array $key * @param mixed $value [optional] * @return e_admin_request */ public function setQuery($key, $value = null) { if(is_array($key)) { foreach ($key as $k=>$v) { $this->setQuery($k, $v); } return $this; } if($value === null) { unset($this->_request_qry[$key], $_GET[$key]); return $this; } $this->_request_qry[$key] = $value; $_GET[$key] = $value; return $this; } /** * Retrieve variable from POST scope * If $key is null, all POST data will be returned * * @param string $key [optional] * @param mixed $default [optional] * @return mixed */ public function getPosted($key = null, $default = null) { if($key === null) { return $this->_posted_qry; } return (isset($this->_posted_qry[$key]) ? $this->_posted_qry[$key] : $default); } /** * Set/Unset POST variable * If $key is array, $value is not used. * If $value is null, (string) $key is unset * * @param string|array $key * @param object $value [optional] * @return e_admin_request */ public function setPosted($key, $value = null) { if(is_array($key)) { if(empty($key)) { $this->_posted_qry = array(); //POST reset return $this; } foreach ($key as $k=>$v) { $this->setPosted($k, $v); } return $this; } if($value === null) { unset($this->_posted_qry[$key]); return $this; } $tp = e107::getParser(); $this->_posted_qry[$tp->post_toForm($key)] = $tp->post_toForm($value); return $this; } /** * Get current mode * @return string */ public function getMode() { if(!$this->_mode) { return $this->getDefaultMode(); } return $this->_mode; } /** * Get default mode * @return string */ public function getDefaultMode() { return $this->_default_mode; } /** * Get current mode name * * @return string */ public function getModeName() { return strtolower(str_replace('-', '_', $this->getMode())); } /** * Reset current mode * @param string $mode * @return e_admin_request */ public function setMode($mode) { $this->_mode = preg_replace('/[\W]/', '', $mode); $this->setQuery($this->_mode_key, $this->_mode); return $this; } /** * Set default mode * @param string $mode * @return e_admin_request */ public function setDefaultMode($mode) { if($mode) { $this->_default_mode = $mode; } return $this; } /** * Set mode key name * @param string $key * @return e_admin_request */ public function setModeKey($key) { $this->_mode_key = $key; return $this; } /** * Get current action * @return string */ public function getAction() { if(!$this->_action) { return $this->getDefaultAction(); } return $this->_action; } /** * Get default action * @return string */ public function getDefaultAction() { return $this->_default_action; } /** * Get current action name * @return string camelized action */ public function getActionName() { return $this->camelize($this->getAction()); } /** * Reset current action * * @param string $action * @return e_admin_request */ public function setAction($action) { $this->_action = preg_replace('/[\W]/', '', $action); $this->setQuery($this->_action_key, $this->_action); return $this; } /** * Set default action * * @param string $action * @return e_admin_request */ public function setDefaultAction($action) { if($action) { $this->_default_action = $action; } return $this; } /** * Set action key name * @param string $key * @return e_admin_request */ public function setActionKey($key) { $this->_action_key = $key; return $this; } /** * Get current ID * @return integer */ public function getId() { return $this->_id; } /** * Reset current ID * @param string $id * @return e_admin_request */ public function setId($id) { $id = (int) $id; $this->_id = $id; $this->setQuery($this->_id_key, $id); return $this; } /** * Set id key name * @param string $key * @return e_admin_request */ public function setIdKey($key) { $this->_id_key = $key; return $this; } /** * Build query string from current request array * NOTE: changing url separator to & ($encode==true) (thus URL XHTML compliance) works in PHP 5.1.2+ environment * * @param string|array $merge_with [optional] override request values * @param boolean $encode if true & separator will be used, all values will be http encoded, default true * @param string|array $exclude_from_query numeric array/comma separated list of vars to be excluded from current query, true - don't use current query at all * @param boolean $keepSpecial don't exclude special vars as 'mode' and 'action' * @return string url encoded query string */ public function buildQueryString($merge_with = array(), $encode = true, $exclude_from_query = '', $keepSpecial = true) { $ret = $this->getQuery(); //special case - exclude all current if($exclude_from_query === true) { $exclude_from_query = array_keys($ret); } // to array if(is_string($exclude_from_query)) { $exclude_from_query = array_map('trim', explode(',', $exclude_from_query)); } if($exclude_from_query) { foreach ($exclude_from_query as $var) { if($keepSpecial && $var != $this->_action_key && $var != $this->_mode_key) { unset($ret[$var]); } } } if(is_string($merge_with)) { parse_str($merge_with, $merge_with); } $ret = array_merge($ret, (array) $merge_with); $separator = '&'; if($encode) { $separator = '&'; //$ret = array_map('rawurlencode', $ret); } $ret = http_build_query($ret, 'numeric_', $separator); if(!$encode) { return rawurldecode($ret); } return $ret; } /** * Convert string to CamelCase * * @param string $str * @return string */ public function camelize($str) { return implode('', array_map('ucfirst', explode('-', str_replace('_', '-', $str)))); } } /** * TODO - front response parent, should do all the header.php work */ class e_admin_response { /** * Body segments * * @var array */ protected $_body = array(); /** * Title segments * * @var unknown_type */ protected $_title = array(); /** * e107 meta title * * @var array */ protected $_e_PAGETITLE = array(); /** * e107 meta description * * @var array */ protected $_META_DESCRIPTION = array(); /** * e107 meta keywords * * @var array */ protected $_META_KEYWORDS = array(); /** * Render mods * * @var array */ protected $_render_mod = array(); /** * Meta title segment description * * @var string */ protected $_meta_title_separator = ' - '; /** * Title segment separator * * @var string */ protected $_title_separator = ' » '; /** * Constructor * */ public function __construct() { $this->_render_mod['default'] = 'admin_page'; } /** * Set body segments for a namespace * * @param string $content * @param string $namespace segment namesapce * @return e_admin_response */ public function setBody($content, $namespace = 'default') { $this->_body[$namespace] = $content; return $this; } /** * Append body segment to a namespace * * @param string $content * @param string $namespace segment namesapce * @return e_admin_response */ public function appendBody($content, $namespace = 'default') { if(!isset($this->_body[$namespace])) { $this->_body[$namespace] = array(); } $this->_body[$namespace][] = $content; return $this; } /** * Prepend body segment to a namespace * * @param string $content * @param string $namespace segment namespace * @return e_admin_response */ public function prependBody($content, $namespace = 'default') { if(!isset($this->_body[$namespace])) { $this->_body[$namespace] = array(); } $this->_body[$namespace] = array_merge(array($content), $this->_body[$namespace]); return $this; } /** * Get body segments from a namespace * * @param string $namespace segment namesapce * @param boolean $reset reset segment namespace * @param string|boolean $glue if false return array, else return string * @return string|array */ public function getBody($namespace = 'default', $reset = false, $glue = '') { $content = vartrue($this->_body[$namespace], array()); if($reset) { $this->_body[$namespace] = array(); } if(is_bool($glue)) { return ($glue ? $content : implode('', $content)); } return implode($glue, $content); } /** * Set title segments for a namespace * * @param string $title * @param string $namespace * @return e_admin_response */ public function setTitle($title, $namespace = 'default') { $this->_title[$namespace] = array($title); return $this; } /** * Append title segment to a namespace * * @param string $title * @param string $namespace segment namesapce * @return e_admin_response */ public function appendTitle($title, $namespace = 'default') { if(empty($title)) { return $this; } if(!isset($this->_title[$namespace])) { $this->_title[$namespace] = array(); } $this->_title[$namespace][] = $title; return $this; } /** * Prepend title segment to a namespace * * @param string $title * @param string $namespace segment namespace * @return e_admin_response */ public function prependTitle($title, $namespace = 'default') { if(empty($title)) { return $this; } if(!isset($this->_title[$namespace])) { $this->_title[$namespace] = array(); } $this->_title[$namespace] = array_merge(array($title), $this->_title[$namespace]); return $this; } /** * Get title segments from namespace * * @param string $namespace * @param boolean $reset * @param boolean|string $glue * @return string|array */ public function getTitle($namespace = 'default', $reset = false, $glue = ' ') { $content = array(); if(isset($this->_title[$namespace]) && is_array($this->_title[$namespace])) { $content = $this->_title[$namespace]; } if($reset) { unset($this->_title[$namespace]); } if(is_bool($glue) || empty($glue)) { return ($glue ? $content : implode($this->_title_separator, $content)); } $glue = deftrue('SEP',' - '); // Defined by admin theme. // admin-ui used only by bootstrap. return implode($glue, $content); // return $head. implode($glue, $content).$foot; } /** * Set render mode for a namespace * * @param string $render_mod * @param string $namespace * @return e_admin_response */ public function setRenderMod($render_mod, $namespace = 'default') { $this->_render_mod[$namespace] = $render_mod; return $this; } /** * Set render mode for namespace * * @param string $namespace * @return string */ public function getRenderMod($namespace = 'default') { return varset($this->_render_mod[$namespace], null); } /** * Add meta title, description and keywords segments * * @param string $meta property name * @param string $content meta content * @return e_admin_response */ public function addMetaData($meta, $content) { $tp = e107::getParser(); $meta = '_' . $meta; if(isset($this->{$meta}) && !empty($content)) { $this->{$meta}[] = strip_tags($content); } return $this; } /** * Add meta title segment * * @param string $title * @return e_admin_response */ public function addMetaTitle($title) { $this->addMetaData('e_PAGETITLE', $title); return $this; } /** * Add meta description segment * * @param string $description * @return e_admin_response */ public function addMetaDescription($description) { $this->addMetaData('META_DESCRIPTION', $description); return $this; } /** * Add meta keywords segment * * @param string $keyword * @return e_admin_response */ public function addMetaKeywords($keyword) { $this->addMetaData('META_KEYWORDS', $keyword); return $this; } /** * Send e107 meta-data * * @return e_admin_response */ public function sendMeta() { //HEADERF already included or meta content already sent if(e_AJAX_REQUEST || defined('HEADER_INIT') || defined('e_PAGETITLE')) { return $this; } if(!defined('e_PAGETITLE') && !empty($this->_e_PAGETITLE)) { define('e_PAGETITLE', implode($this->_meta_title_separator, $this->_e_PAGETITLE)); } if(!defined('META_DESCRIPTION') && !empty($this->_META_DESCRIPTION)) { define('META_DESCRIPTION', implode(' ', $this->_META_DESCRIPTION)); } if(!defined('META_KEYWORDS') && !empty($this->_META_KEYWORDS)) { define('META_KEYWORDS', implode(', ', $this->_META_KEYWORDS)); } return $this; } /** * Add content segment to the header namespace * * @param string $content * @return e_admin_response */ public function addHeaderContent($content) { $this->appendBody($content, 'header_content'); return $this; } /** * Get page header namespace content segments * * @param boolean $reset * @param boolean $glue * @return string */ public function getHeaderContent($reset = true, $glue = "\n\n") { return $this->getBody('header_content', $reset, $glue); } /** * Switch to iframe mod * FIXME - implement e_IFRAME to frontend - header_default.php * * @return e_admin_response */ public function setIframeMod() { global $HEADER, $FOOTER, $CUSTOMHEADER, $CUSTOMFOOTER; $FOOTER = ''; $HEADER = $FOOTER; $CUSTOMFOOTER = array(); $CUSTOMHEADER = $CUSTOMFOOTER; //TODO generic $_GET to activate for any page of admin. // New if(!defined('e_IFRAME')) { define('e_IFRAME', true); } return $this; } /** * Send Response Output * * @param string $name segment * @param array $options valid keys are: messages|render|meta|return|raw|ajax * @return array|string|null */ public function send($name = 'default', $options = array()) { if(is_string($options)) { parse_str($options, $options); } // Merge with all available default options $options = array_merge(array( 'messages' => true, 'render' => true, 'meta' => false, 'return' => false, 'raw' => false, 'ajax' => false ), $options); $content = $this->getBody($name, true); $title = $this->getTitle($name, true); $return = $options['return']; if($options['ajax'] || e_AJAX_REQUEST) { $type = $options['ajax'] && is_string($options['ajax']) ? $options['ajax'] : ''; $this->getJsHelper()->sendResponse($type); } if($options['messages']) { $content = e107::getMessage()->render().$content; } if($options['meta']) { $this->sendMeta(); } // raw output expected - force return array if($options['raw']) { return array($title, $content, $this->getRenderMod($name)); } //render disabled by the controller if(!$this->getRenderMod($name)) { $options['render'] = false; } if($options['render']) { return e107::getRender()->tablerender($title, $content, $this->getRenderMod($name), $return); } if($return) { return $content; } print($content); return ''; } /** * Get JS Helper instance * * @return e_jshelper */ public function getJsHelper() { return e107::getSingleton('e_jshelper', true, 'admin_response'); } } /** * TODO - request related code should be moved to core * request handler */ class e_admin_dispatcher { /** * @var e_admin_request */ protected $_request; /** * @var e_admin_response */ protected $_response; /** * @var e_admin_controller */ protected $_current_controller; /** * Required (set by child class). * Controller map array in format * 'MODE' => array('controller' =>'CONTROLLER_CLASS_NAME'[, 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => extend of 'comments_admin_form_ui', 'uipath' => 'path/to/ui/']); * * @var array */ protected $modes = array(); /** * Optional - access restrictions per action * Access array in format (similar to adminMenu) * 'MODE/ACTION' => e_UC_* (userclass constant, or custom userclass ID if dynamically set) * * @var array */ protected $access = array(); /** * Optional - generic entry point access restriction (via getperms()) * Value of this for plugins would be always 'P'. * When an array is detected, route mode/action = admin perms is used. (similar to $access) * More detailed access control is granted with $access and $modes[MODE]['perm'] or $modes[MODE]['userclass'] settings * * @var string|array */ protected $perm; /** * @var string */ protected $defaultMode = ''; /** * @var string */ protected $defaultAction = ''; /** * Optional - map 'mode/action' pair to 'modeAlias/actionAlias' * @var string */ protected $adminMenuAliases = array(); /** * Optional (set by child class). * Required for admin menu render * Format: 'mode/action' => array('caption' => 'Link title'[, 'perm' => '0', 'url' => '{e_PLUGIN}plugname/admin_config.php'], ...); * Note that 'perm' and 'userclass' restrictions are inherited from the $modes, $access and $perm, so you don't have to set that vars if * you don't need any additional 'visual' control. * All valid key-value pair (see e107::getNav()->admin function) are accepted. * @var array */ protected $adminMenu = array(); protected $adminMenuIcon; /** * Optional (set by child class). * Page titles for pages not in adminMenu (e.g. main/edit) * Format array(mod/action => Page Title) * @var string */ protected $pageTitles = array( 'main/edit' => LAN_MANAGE, ); /** * Optional (set by child class). * @var string */ protected $menuTitle = 'Menu'; /** * @var string */ protected $pluginTitle = ''; /** * Constructor * * @param string|array|e_admin_request $request [optional] * @param e_admin_response $response */ public function __construct($auto_observe = true, $request = null, $response = null) { // we let know some admin routines we are in UI mod - related with some legacy checks and fixes if(!defined('e_ADMIN_UI')) { define('e_ADMIN_UI', true); } if(!empty($_GET['iframe']) && !defined('e_IFRAME')) { define('e_IFRAME', true); } require_once(e_ADMIN.'boot.php'); if($request === null || !is_object($request)) { $request = new e_admin_request($request); } if($response === null) { $response = new e_admin_response(); } $this->setRequest($request)->setResponse($response)->init(); if(!$this->defaultMode || !$this->defaultAction) { $this->setDefaults(); } // current user does not have access to default route, so find a new one. if(!$hasAccess = $this->hasRouteAccess($this->defaultMode.'/'.$this->defaultAction)) { if($newRoute = $this->getApprovedAccessRoute()) { list($this->defaultMode,$this->defaultAction) = explode('/',$newRoute); } } $request->setDefaultMode($this->defaultMode)->setDefaultAction($this->defaultAction); // register itself e107::setRegistry('admin/ui/dispatcher', $this); // permissions and restrictions $this->checkAccess(); if($auto_observe) { $this->runObservers(); } } /** * User defined constructor - called before _initController() method * @return void */ public function init() { } /** * @return bool */ public function checkAccess() { $request = $this->getRequest(); $currentMode = $request->getMode(); // access based on mode setting - general controller access if(!$this->hasModeAccess($currentMode)) { $request->setAction('e403'); e107::getMessage()->addError(LAN_NO_PERMISSIONS) ->addDebug('Mode access restriction triggered.'); return false; } // access based on $access settings - access per action $currentAction = $request->getAction(); $route = $currentMode.'/'.$currentAction; if(!$this->hasRouteAccess($route)) { $request->setAction('e403'); e107::getMessage()->addError(LAN_NO_PERMISSIONS) ->addDebug('Route access restriction triggered:'.$route); return false; } return true; } /** * @param $mode * @return bool */ public function hasModeAccess($mode) { // mode userclass (former check_class()) if(isset($this->modes[$mode]['userclass']) && !e107::getUser()->checkClass($this->modes[$mode]['userclass'], false)) { return false; } // mode admin permission (former getperms()) if(isset($this->modes[$mode]['perm']) && !e107::getUser()->checkAdminPerms($this->modes[$mode]['perm'])) { return false; } // generic dispatcher admin permission (former getperms()) if($this->perm !== null && is_string($this->perm) && !e107::getUser()->checkAdminPerms($this->perm)) { return false; } return true; } /** * @param $route * @return bool */ public function hasRouteAccess($route) { if(isset($this->access[$route]) && !e107::getUser()->checkClass($this->access[$route], false)) { e107::getMessage()->addDebug('Userclass Permissions Failed: ' .$this->access[$route]); return false; } if(is_array($this->perm) && isset($this->perm[$route]) && !e107::getUser()->checkAdminPerms($this->perm[$route])) { e107::getMessage()->addDebug('Admin Permissions Failed.' .$this->perm[$route]); return false; } return true; } /** * Retrieve missing default action/mode * @return e_admin_dispatcher */ public function setDefaults() { // try Admin menu first if($this->adminMenu) { reset($this->adminMenu); list($mode, $action) = explode('/', key($this->adminMenu), 3); } else { reset($this->modes); $mode = key($this->modes); $action = $this->modes[$mode]['index']; } if(!$this->defaultMode) { $this->defaultMode = $mode; } if(!$this->defaultAction) { $this->defaultAction = $action; } return $this; } /** * Search through access for an approved route. * Returns false if no approved route found. * * @return string|bool */ private function getApprovedAccessRoute() { if(empty($this->access)) { return false; } foreach($this->access as $route=>$uclass) { if(check_class($uclass)) { return $route; } } return false; } /** * Get admin menu array * @return array */ public function getMenuData() { return $this->adminMenu; } /** * Get admin menu array * @return array */ public function getPageTitles() { return $this->pageTitles; } /** * Get admin menu array * @return array */ public function getMenuAliases() { return $this->adminMenuAliases; } /** * Get request object * @return e_admin_request */ public function getRequest() { return $this->_request; } /** * Set request object * @param e_admin_request $request * @return e_admin_dispatcher */ public function setRequest($request) { $this->_request = $request; return $this; } /** * Get response object * @return e_admin_response */ public function getResponse() { return $this->_response; } /** * Set response object * @param e_admin_response $response * @return e_admin_dispatcher */ public function setResponse($response) { $this->_response = $response; return $this; } /** * Dispatch & render all * * @param boolean $run_header see runObservers() * @param boolean $return see runPage() * @return string|array current admin page body */ public function run($run_header = true, $return = 'render') { return $this->runObservers()->runPage($return); } /** * Run observers/headers only, should be called before header.php call * * @return e_admin_dispatcher */ public function runObservers($run_header = true) { //search for $actionName.'Observer' method. Additional $actionName.$triggerName.'Trigger' methods will be called as well $this->getController()->dispatchObserver(); //search for $actionName.'Header' method, js manager should be used inside for sending JS to the page, // meta information should be created there as well if($run_header) { $this->getController()->dispatchHeader(); } return $this; } /** * Run page action. * If return type is array, it should contain allowed response options (see e_admin_response::send()) * Available return type string values: * - render_return: return rendered content ( see e107::getRender()->tablerender()), add system messages, send meta information * - render: outputs rendered content ( see e107::getRender()->tablerender()), add system messages * - response: return response object * - raw: return array(title, content, render mode) * - ajax: force ajax output (and exit) * * @param string|array $return_type expected string values: render|render_out|response|raw|ajax[_text|_json|_xml] * @return array|e_admin_response|string|null */ public function runPage($return_type = 'render') { $response = $this->getController()->dispatchPage(); if(is_array($return_type)) { return $response->send('default', $return_type); } switch($return_type) { case 'render_return': $options = array( 'messages' => true, 'render' => true, 'meta' => true, 'return' => true, 'raw' => false ); break; case 'raw': $options = array( 'messages' => false, 'render' => false, 'meta' => false, 'return' => true, 'raw' => true ); break; case 'ajax': case 'ajax_text': case 'ajax_xml'; case 'ajax_json'; $options = array( 'messages' => false, 'render' => false, 'meta' => false, 'return' => false, 'raw' => false, 'ajax' => str_replace(array('ajax_', 'ajax'), array('', 'text'), $return_type) ); break; case 'response': return $response; break; case 'render': default: $options = array( 'messages' => true, 'render' => true, 'meta' => false, 'return' => false, 'raw' => false ); break; } return $response->send('default', $options); } /** * Get perms * @return array|string */ public function getPerm() { return $this->perm; } /** * Proxy method * * @return string */ public function getHeader() { return $this->getController()->getHeader(); } /** * Get current controller object * @return e_admin_controller */ public function getController() { if($this->_current_controller === null) { $this->_initController(); } return $this->_current_controller; } /** * Try to init Controller from request using current controller map * * @return e_admin_dispatcher */ protected function _initController() { $request = $this->getRequest(); $response = $this->getResponse(); if(isset($this->modes[$request->getModeName()]) && isset($this->modes[$request->getModeName()]['controller'])) { $class_name = $this->modes[$request->getModeName()]['controller']; $class_path = vartrue($this->modes[$request->getModeName()]['path']); if($class_path) { require_once(e107::getParser()->replaceConstants($class_path)); } if($class_name && class_exists($class_name))//NOTE: autoload in the play { $this->_current_controller = new $class_name($request, $response); //give access to current request object, user defined init $this->_current_controller->setRequest($this->getRequest())->init(); } // Known controller (found in e_admin_dispatcher::$modes), class not found exception else { // TODO - admin log // get default controller $this->_current_controller = $this->getDefaultController(); // add messages e107::getMessage()->add('Can\'t find class "'.($class_name ? $class_name : 'n/a').'" for controller "'.ucfirst($request->getModeName()).'"', E_MESSAGE_ERROR) ->add('Requested: '.e_REQUEST_SELF.'?'.$request->buildQueryString(), E_MESSAGE_DEBUG); // $request->setMode($this->getDefaultControllerName())->setAction('e404'); $this->_current_controller->setRequest($request)->init(); } if(!empty($this->modes[$request->getModeName()]['ui'])) { $class_name = $this->modes[$request->getModeName()]['ui']; $class_path = vartrue($this->modes[$request->getModeName()]['uipath']); if($class_path) { require_once(e107::getParser()->replaceConstants($class_path)); } if(class_exists($class_name))//NOTE: autoload in the play { $this->_current_controller->setParam('ui', new $class_name($this->_current_controller)); } } $this->_current_controller->setParam('modes', $this->modes); } // Not known controller (not found in e_admin_dispatcher::$modes) exception else { // TODO - admin log $this->_current_controller = $this->getDefaultController(); // add messages e107::getMessage()->add('Can\'t find class for controller "'.ucfirst($request->getModeName()).'"', E_MESSAGE_ERROR) ->add('Requested: '.e_REQUEST_SELF.'?'.$request->buildQueryString(), E_MESSAGE_DEBUG); // go to not found page $request->setMode($this->getDefaultControllerName())->setAction('e404'); $this->_current_controller->setRequest($request)->init(); } return $this; } /** * Default controller object - needed if controller not found * @return e_admin_controller */ public function getDefaultController() { $class_name = $this->getDefaultControllerName(); return new $class_name($this->getRequest(), $this->getResponse()); } /** * Default controller name - needed if controller not found * @return string name of controller */ public function getDefaultControllerName() { return 'e_admin_controller'; } /** * Generic Admin Menu Generator * @return string */ public function renderMenu() { $tp = e107::getParser(); $var = array(); $selected = false; foreach($this->adminMenu as $key => $val) { if(isset($val['perm']) && $val['perm']!=='' && !getperms($val['perm'])) { continue; } $tmp = explode('/', trim($key, '/'), 3); // sync with mode/route access if(!$this->hasModeAccess($tmp[0]) || !$this->hasRouteAccess($tmp[0].'/'.varset($tmp[1]))) { continue; } // custom 'selected' check if(isset($val['selected']) && $val['selected']) { $selected = $val['selected'] === true ? $key : $val['selected']; } foreach ($val as $k=>$v) { switch($k) { case 'caption': $k2 = 'text'; $v = defset($v, $v); break; case 'url': $k2 = 'link'; $qry = (isset($val['query'])) ? $val['query'] : '?mode='.$tmp[0].'&action='.$tmp[1]; $v = $tp->replaceConstants($v, 'abs').$qry; break; case 'uri': $k2 = 'link'; $v = $tp->replaceConstants($v, 'abs'); if(!empty($v) && ($v === e_REQUEST_URI)) { $selected = $key; } break; case 'badge': // array('value'=> int, 'type'=>'warning'); $k2 = 'badge'; $v = (array) $v; break; case 'icon': $k2 = 'image_src'; $v = (string) $v.'.glyph'; break; default: $k2 = $k; break; } // Access check done above // if($val['perm']!= null) // check perms // { // if(getperms($val['perm'])) // { // $var[$key][$k2] = $v; // } // } // else { $var[$key][$k2] = $v; } } // guess an icon. if(!isset($var[$key]['image_src'])) { $var[$key]['image_src'] = e_navigation::guessMenuIcon($key); } // TODO slide down menu options? if(!vartrue($var[$key]['link'])) { $var[$key]['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&action='.$tmp[1]; // FIXME - URL based on $modes, remove url key } if(varset($val['tab'])) { $var[$key]['link'] .= '&tab=' .$val['tab']; } /*$var[$key]['text'] = $val['caption']; $var[$key]['link'] = (vartrue($val['url']) ? $tp->replaceConstants($val['url'], 'abs') : e_SELF).'?mode='.$tmp[0].'&action='.$tmp[1]; $var[$key]['perm'] = $val['perm']; */ if(!empty($val['modal'])) { $var[$key]['link_class'] = ' e-modal'; if(!empty($val['modal-caption'])) { $var[$key]['link_data'] = array('data-modal-caption' => $val['modal-caption']); } } } if(empty($var)) { return ''; } $request = $this->getRequest(); if(!$selected) { $selected = $request->getMode() . '/' . $request->getAction(); } $selected = vartrue($this->adminMenuAliases[$selected], $selected); $icon = ''; if(!empty($this->adminMenuIcon)) { $icon = e107::getParser()->toIcon($this->adminMenuIcon); } elseif(deftrue('e_CURRENT_PLUGIN')) { $icon = e107::getPlug()->load(e_CURRENT_PLUGIN)->getIcon(24); } $toggle = ""; $var['_extras_'] = array('icon'=> $icon, 'return'=>true); // $var['_icon_'] = $icon; return e107::getNav()->admin($this->menuTitle, $selected, $var); } /** * Render Help Text in