示例#1
0
	public function view(){
		$v = $this->getView();

		$pages = PageModel::Find(array('admin' => '1'));
		$groups = array();
		$flatlist = array();

		if(isset($_SESSION['user_sudo'])){
			$p = new PageModel('/user/sudo');
			$p->set('title', 'Exit SUDO Mode');
			$groups['SUDO'] = [
				'title' => 'SUDO',
				'href' => '',
				'children' => [
					'Exit SUDO Mode' => $p,
				],
			];
			$flatlist[ 'Exit SUDO Mode' ] = $p;
		}


		if(\Core\user()){
			foreach($pages as $p){
				/** @var PageModel $p */
				if(!\Core\user()->checkAccess($p->get('access'))) continue;

				// Pages can define which sub-menu they get grouped under.
				// The 'Admin' submenu is the default.
				$group = $p->get('admin_group') ? $p->get('admin_group') : 't:STRING_ADMIN';
				// Support i18n here!
				if(strpos($group, 't:') === 0){
					$group = t(substr($group, 2));
				}

				if(!isset($groups[$group])){
					$groups[$group] = [
						'title'    => $group,
						'href'     => '',
						'children' => [],
					];
				}

				if($p->get('baseurl') == '/admin'){
					// Admin gets special treatment.
					$groups[t('STRING_ADMIN')]['href'] = '/admin';
					continue;
				}

				switch($p->get('title')){
					case 'System Configuration':
						$p->set('title', "System Config");
						break;
					case 'Navigation Listings':
						$p->set('title', "Navigation");
						break;
					case 'Content Page Listings':
						$p->set('title', "Content Pages");
						break;
					default:
						$p->set(
							'title',
							trim( str_replace(['Administration', 'Admin'],'', $p->get('title')) )
						);
				}

				$title = $p->get('title');
				// Support i18n here!
				if(strpos($title, 't:') === 0){
					$title = t(substr($title, 2));
				}

				if(isset($groups[$title])){
					// Link the main group to this page instead of an empty link.
					// This removes duplicate links such as the group "User" and page "User".
					$groups[$title]['href'] = $p->get('rewriteurl');
				}
				else{
					// The new grouped pages
					$groups[$group]['children'][ $title ] = $p;
					// And the flattened list to support legacy templates.
					$flatlist[ $title ] = $p;
				}
			}

			// This is a hack to make sure that users can view the /admin link if they can view other admin pages.
			/*if(sizeof($flatlist) && !isset($groups['Admin']['Dashboard'])){
				$p = new PageModel('/admin');
				$p->set('title', 'Dashboard');
				$groups['Admin']['Dashboard'] = $p;
			}*/
		}

		ksort($flatlist);
		ksort($groups);

		foreach($groups as $gname => $dat){
			ksort($groups[$gname]['children']);
		}

		// Build a list of languages that can be set by the user.
		$locales = \Core\i18n\I18NLoader::GetLocalesEnabled();
		$selected = \Core\i18n\I18NLoader::GetUsersLanguage();
		$languages = [];
		if(sizeof($locales) > 1){
			// There is at least 1 language available on the system, YAY!
			foreach($locales as $localeKey => $localeDat){
				if(($pos = strpos($localeKey, '_')) !== false){
					// This locale contains an underscore, that means it has a corresponding country!
					// These are what we want to display to the end user.
					$country = substr($localeKey, $pos+1);

					// Here I am retrieving the language and dialect in the native dialect if at all possible.
					// This is because if you as a user only can read your native language and your browser renders something different,
					// then you want to be able to read what you're switching it to.
					$str1 = new \Core\i18n\I18NString($localeDat['lang']);
					$str1->setLanguage($localeKey);
					$localeTitle = $str1->getTranslation();
					if($localeDat['dialect']){
						$str2 = new \Core\i18n\I18NString($localeDat['dialect']);
						$str2->setLanguage($localeKey);
						$localeTitle .= ' (' . $str2->getTranslation() . ')';
					}

					$languages[] = [
						'key'      => $localeKey,
					    'title'    => $localeTitle,
					    'country'  => $country,
					    'image'    => 'assets/images/iso-country-flags/' . strtolower($country) . '.png',
					    'selected' => $localeKey == $selected,
					];
				}
			}
		}

		$v->templatename = 'widgets/adminmenu/view.tpl';
		$v->assign('pages', $flatlist);
		$v->assign('groups', $groups);
		$v->assign('languages', $languages);

		return $v;
	}
示例#2
0
	/**
	 * Page to view and test the i18n settings and strings of this site.
	 *
	 * Also useful for viewing what strings are currently installed and where they came from!
	 *
	 * @return int
	 */
	public function i18n(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('g:admin')){
			// This test page is an admin-only utility.
			return View::ERROR_ACCESSDENIED;
		}

		/*$locales = Core\i18n\I18NLoader::GetLocalesAvailable();

		// Languages will be the current languages/locales available on the system.
		$languages = [];

		foreach($locales as $lang => $dat){
			if(strpos($lang, '_') !== false){
				$base = substr($lang, 0, strpos($lang, '_'));

				if(!isset($languages[$base])){
					// Add the base language, (useful here because the editor may want to edit only the base language and not specific dialects).
					$languages[$base] = t($dat['lang']);
				}
			}

			$languages[$lang] = t($dat['lang']) . (($dat['dialect']) ? ' (' . t($dat['dialect']) . ')' : '');
		}*/
		// I need to use GetLocalesAvailable because the higher level functions will only return what's currently enabled,
		// which is the entire point of this page!
		$locales = Core\i18n\I18NLoader::GetLocalesAvailable();
		
		// Make this full list a more flat list suitable for populating directly into the form element.
		$all = [];
		foreach($locales as $key => $dat){
			$all[$key] = t($dat['lang']) . ' (' . t($dat['dialect']) . ')';
		}
		
		$enabled = \ConfigHandler::Get('/core/language/languages_enabled');
		// This is expected to be a pipe-seperated list of languages/locales enabled.
		$enabled = array_map('trim', explode('|', $enabled));

		// Did the user request a specific language?
		$requested = $request->getParameter('lang');
		if($requested){
			$showStrings = false;
			$showForm = true;
		}
		else{
			$showStrings = true;
			$showForm = false;
			$requested = \Core\i18n\I18NLoader::GetUsersLanguage();
		}

		$strings = \Core\i18n\I18NLoader::GetAllStrings($requested);

		$form = new Form();
		$form->set('callsmethod', 'AdminController::_i18nSaveHandler');
		
		$form->addElement(
			'checkboxes', 
			[
				'name' => 'languages[]',
				'title' => t('STRING_CONFIG_CORE_LANGUAGE_LANGUAGES_ENABLED'),
				'description' => t('MESSAGE_CONFIG_CORE_LANGUAGE_LANGUAGES_ENABLED'),
			    'options' => $all,
			    'value' => $enabled,
			]
		);
		
		/*

		$form->addElement('system', ['name' => 'lang', 'value' => $requested]);

		foreach($strings as $dat){
			$type = strpos($dat['key'], 'MESSAGE_') === 0 ? 'textarea' : 'text';

			$form->addElement(
				$type,
				[
					'name' => $dat['key'],
				    'title' => $dat['key'],
				    'value' => $dat['found'] ? $dat['match_str'] : '',
				    'description' => $dat['results']['DEFAULT'] ? $dat['results']['DEFAULT'] : $dat['results']['FALLBACK'],
				]
			);
		}
		*/

		$form->addElement('submit', ['value' => t('STRING_SAVE')]);

		$view->addBreadcrumb('t:STRING_ADMIN', '/admin');
		$view->title = 't:STRING_I18N_LANGUAGES';
		//$view->assign('languages', $languages);
		$view->assign('form', $form);
		$view->assign('strings', $strings);
		$view->assign('show_strings', $showStrings);
		$view->assign('show_form', $showForm);
		$view->assign('requested', $requested);
	}