array( 'controller' => 'eurl_admin_ui', 'path' => null, 'ui' => 'eurl_admin_form_ui', 'uipath' => null ) ); protected $adminMenu = array( 'main/config' => array('caption'=> LAN_EURL_MENU_CONFIG, 'perm' => 'L'), 'main/alias' => array('caption'=> LAN_EURL_MENU_ALIASES, 'perm' => 'L'), 'main/settings' => array('caption'=> LAN_EURL_MENU_SETTINGS, 'perm' => 'L'), 'main/help' => array('caption'=> LAN_EURL_MENU_HELP, 'perm' => 'L'), ); protected $adminMenuAliases = array(); protected $defaultAction = 'config'; protected $menuTitle = LAN_EURL_MENU; } class eurl_admin_ui extends e_admin_controller_ui { public $api; protected $prefs = array( 'url_disable_pathinfo' => array('title'=>LAN_EURL_SETTINGS_PATHINFO, 'type'=>'boolean', 'help'=>LAN_EURL_MODREWR_DESCR), 'url_main_module' => array('title'=>LAN_EURL_SETTINGS_MAINMODULE, 'type'=>'dropdown', 'data' => 'string','help'=>LAN_EURL_SETTINGS_MAINMODULE_HELP), 'url_error_redirect' => array('title'=>LAN_EURL_SETTINGS_REDIRECT, 'type'=>'boolean', 'help'=>LAN_EURL_SETTINGS_REDIRECT_HELP), ); public function init() { $this->api = e107::getInstance(); $this->addTitle(LAN_EURL_NAME); if($this->getAction() != 'settings') return; } public function HelpObserver() { } public function HelpPage() { $this->addTitle(LAN_EURL_NAME_HELP); return LAN_EURL_UC; } public function SettingsObserver() { $this->prefs['url_main_module']['writeParms'][''] = 'None'; $modules = e107::getPref('url_config', array()); ksort($modules); foreach ($modules as $module => $location) { $labels = array(); $obj = eDispatcher::getConfigObject($module, $location); if(!$obj) continue; $config = $obj->config(); if(!$config || !vartrue($config['config']['allowMain'])) continue; $admin = $obj->admin(); $labels = vartrue($admin['labels'], array()); $this->prefs['url_main_module']['writeParms'][$module] = vartrue($section['name'], eHelper::labelize($module)); } if(isset($_POST['etrigger_save'])) { $this->getConfig() ->setPostedData($this->getPosted(), null, false, false) //->setPosted('not_existing_pref_test', 1) ->save(true); $this->getConfig()->setMessages(); } } public function SettingsPage() { $this->addTitle(LAN_EURL_NAME_SETTINGS); return $this->getUI()->urlSettings(); } public function AliasObserver() { if(isset($_POST['update'])) { $posted = is_array($_POST['eurl_aliases']) ? e107::getParser()->post_toForm($_POST['eurl_aliases']) : ''; $aliases = array(); foreach ($posted as $lan => $als) { foreach ($als as $module => $alias) { $alias = trim($alias); $module = trim($module); if($module !== $alias) { // TODO - basic validation $aliases[$lan][$alias] = $module; } } } e107::getConfig()->set('url_aliases', e107::getParser()->post_toForm($aliases))->save(false); } } public function AliasPage() { $this->addTitle(LAN_EURL_NAME_ALIASES); $aliases = e107::getPref('url_aliases', array()); $form = $this->getUI(); $text = "
".LAN_EURL_LEGEND_ALIASES." "; $text .= $this->renderAliases($aliases); $text .= "
".$form->admin_button('update', LAN_UPDATE, 'update')."
"; return $text; } public function ConfigObserver() { if(isset($_POST['update'])) { $config = is_array($_POST['eurl_config']) ? e107::getParser()->post_toForm($_POST['eurl_config']) : ''; $modules = eRouter::adminReadModules(); $locations = eRouter::adminBuildLocations($modules); $aliases = eRouter::adminSyncAliases(e107::getPref('url_aliases'), $config); e107::getConfig() ->set('url_aliases', $aliases) ->set('url_config', $config) ->set('url_modules', $modules) ->set('url_locations', $locations) ->save(); eRouter::clearCache(); } } public function ConfigPage() { $this->addTitle(LAN_EURL_NAME_CONFIG); $active = e107::getPref('url_config'); //echo(e107::getUrl()->create('system/error/notfound', '', 'full=1')); $set = array(); // all available URL modules $set['url_modules'] = eRouter::adminReadModules(); // set by user URL config locations $set['url_config'] = eRouter::adminBuildConfig($active, $set['url_modules']); // all available URL config locations $set['url_locations'] = eRouter::adminBuildLocations($set['url_modules']); $form = $this->getUI(); $text = "
".LAN_EURL_LEGEND_CONFIG." "; $text .= $this->renderConfig($set['url_config'], $set['url_locations']); $text .= "
".$form->admin_button('update', LAN_UPDATE, 'update')."
"; return $text; } public function renderConfig($current, $locations) { $ret = array(); $url = e107::getUrl(); ksort($locations); foreach ($locations as $module => $l) { $data = new e_vars(array( 'current' => $current, )); $obj = eDispatcher::getConfigObject($module, $l[0]); if(null === $obj) $obj = new eurlAdminEmptyConfig; $data->module = $module; $data->locations = $l; $data->defaultLocation = $l[0]; $data->config = $obj; $ret[] = $data; } return $this->getUI()->moduleRows($ret); } public function renderAliases($aliases) { $ret = array(); $lans = array(); $lng = e107::getLanguage(); $lanList = $lng->installed(); sort($lanList); $lanDef = e107::getPref('sitelanguage') ? e107::getPref('sitelanguage') : e_LANGUAGE; $lanDef = array($lng->convert($lanDef), $lanDef); foreach ($lanList as $index => $lan) { $lanCode = $lng->convert($lan); if($lanDef[0] == $lanCode) continue; $lans[$lanCode] = $lan; } $modules = e107::getPref('url_config'); if(!$modules) { $modules = array(); e107::getConfig()->set('url_aliases', array())->save(false); // do not output message e107::getMessage()->reset(false, 'default'); } foreach ($modules as $module => $location) { $data = new e_vars(); $obj = eDispatcher::getConfigObject($module, $location); if(null === $obj) $obj = new eurlAdminEmptyConfig; $data->module = $module; $data->location = $location; $data->config = $obj; $modules[$module] = $data; } return $this->getUI()->aliasesRows($aliases, $modules, $lanDef, $lans); } /** * Set extended (UI) Form instance * @return e_admin_ui */ public function _setUI() { $this->_ui = $this->getParam('ui'); $this->setParam('ui', null); return $this; } /** * Set Config object * @return e_admin_ui */ protected function _setConfig() { $this->_pref = e107::getConfig(); $dataFields = $validateRules = array(); foreach ($this->prefs as $key => $att) { // create dataFields array $dataFields[$key] = vartrue($att['data'], 'string'); // create validation array if(vartrue($att['validate'])) { $validateRules[$key] = array((true === $att['validate'] ? 'required' : $att['validate']), varset($att['rule']), $att['title'], varset($att['error'], $att['help'])); } /* Not implemented in e_model yet elseif(vartrue($att['check'])) { $validateRules[$key] = array($att['check'], varset($att['rule']), $att['title'], varset($att['error'], $att['help'])); }*/ } $this->_pref->setDataFields($dataFields)->setValidationRules($validateRules); return $this; } } class eurl_admin_form_ui extends e_admin_form_ui { public function urlSettings() { return $this->getSettings(); } public function moduleRows($data) { $text = ''; $tp = e107::getParser(); if(empty($data)) { return " ".LAN_EURL_EMPTY." "; } foreach ($data as $obj) { $admin = $obj->config->admin(); $section = vartrue($admin['labels'], array()); $text .= " ".vartrue($section['name'], eHelper::labelize($obj->module))." "; foreach ($obj->locations as $index => $location) { $objSub = $obj->defaultLocation != $location ? eDispatcher::getConfigObject($obj->module, $location) : false; if($objSub) { $admin = $objSub->admin(); $section = vartrue($admin['labels'], array()); } elseif($obj->defaultLocation != $location) $section = array(); $id = 'eurl-'.str_replace('_', '-', $obj->module).'-'.$index; $module = $obj->module; $checked = varset($obj->current[$module]) == $location ? ' checked="checked"' : ''; $path = eDispatcher::getConfigPath($module, $location, false); if(!is_readable($path)) $path = str_replace('/e_url.php', '/', $tp->replaceConstants(eDispatcher::getConfigPath($module, $location, true), true)).' ('.LAN_EURL_LOCATION_NONE.')'; else $path = $tp->replaceConstants(eDispatcher::getConfigPath($module, $location, true), true); $label = vartrue($section['label'], $index == 0 ? LAN_EURL_DEFAULT : eHelper::labelize(ltrim(strstr($location, '/'), '/'))); $cssClass = $checked ? 'e-showme' : 'e-hideme'; // XXX use e_form $text .= "
".LAN_EURL_LOCATION." ".$path."

".vartrue($section['description'], LAN_EURL_PROFILE_INFO)."

"; } $text .= " "; } return $text; } public function aliasesRows($currentAliases, $modules, $lanDef, $lans) { if(empty($modules)) { return " ".LAN_EURL_EMPTY." "; } $text = ''; $tp = e107::getParser(); foreach ($modules as $module => $obj) { $help = array(); $admin = $obj->config->admin(); $lan = $lanDef[0]; $url = e107::getUrl()->create($module, '', array('full' => 1)); $defVal = isset($currentAliases[$lan]) && in_array($module, $currentAliases[$lan]) ? array_search($module, $currentAliases[$lan]) : $module; $section = vartrue($admin['labels'], array()); $text .= " ".vartrue($section['name'], ucfirst(str_replace('_', ' ', $obj->module)))."
".LAN_EURL_FORM_HELP_ALIAS_0." {$module}
"; // default language $text .= $this->text('eurl_aliases['.$lanDef[0].']['.$module.']', $defVal).' ['.$lanDef[1].']'.$this->help(LAN_EURL_FORM_HELP_DEFAULT); $help[] = '['.$lanDef[1].'] '.LAN_EURL_FORM_HELP_EXAMPLE.'
'.$url.''; if($lans) { foreach ($lans as $code => $lan) { $url = e107::getUrl()->create($module, '', array('lan' => $code, 'full' => 1)); $defVal = isset($currentAliases[$code]) && in_array($module, $currentAliases[$code]) ? array_search($module, $currentAliases[$code]) : $module; $text .= "
"; $text .= $this->text('eurl_aliases['.$code.']['.$module.']', $defVal).' ['.$lan.']'.$this->help(LAN_EURL_FORM_HELP_ALIAS_1.' '.$lan.''); $help[] = '['.$lan.'] '.LAN_EURL_FORM_HELP_EXAMPLE.'
'.$url.''; } } $text .= " ".implode("
", $help)." "; } return $text; } } class eurlAdminEmptyConfig extends eUrlConfig { public function config() { return array(); } } new eurl_admin(); require_once(e_ADMIN.'auth.php'); e107::getAdminUI()->runPage(); require_once(e_ADMIN.'footer.php');