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; }
/** * Shortcut for unpublishing a page. */ public function page_unpublish() { $view = $this->getView(); $request = $this->getPageRequest(); if(!\Core\user()->checkAccess('p:/core/pages/manage')){ return View::ERROR_ACCESSDENIED; } $baseurl = $request->getParameter('baseurl'); $page = new PageModel($baseurl); if(!$page->exists()){ return View::ERROR_NOTFOUND; } if(!$request->isPost()){ return View::ERROR_BADREQUEST; } // Is this page already un-published? if($page->get('published_status') == 'draft'){ \Core\set_message('t:MESSAGE_ERROR_PAGE_ALREADY_UNPUBLISHED'); \Core\go_back(); } $page->set('published_status', 'draft'); $page->save(); \Core\set_message('t:MESSAGE_SUCCESS_PAGE_UNPUBLISHED'); \Core\go_back(); }
public function __construct($atts = null) { error_log(__CLASS__ . ' is candidate for immediate removal, please change this code!', E_USER_DEPRECATED); // Defaults $this->_attributes['name'] = 'page'; if ($atts instanceof PageModel) { parent::__construct(array('name' => 'page')); $page = $atts; } else { if(isset($atts['model']) && $atts['model'] instanceof PageModel){ // Everything is based off the page. $page = $atts['model']; unset($atts['model']); parent::__construct($atts); } else{ parent::__construct($atts); // BaseURL needs to be set for this to work. //if(!$this->get('baseurl')) return null; // Everything is based off the page. $page = new PageModel($this->get('baseurl')); } } $this->_attributes['baseurl'] = $page->get('baseurl'); $name = $this->_attributes['name']; // I need to get a list of pages to offer as a dropdown for selecting the "parent" page. $f = new ModelFactory('PageModel'); if ($this->get('baseurl')) $f->where('baseurl != ' . $this->get('baseurl')); $opts = PageModel::GetPagesAsOptions($f, '-- No Parent Page --'); $this->addElement( 'pageparentselect', array( 'name' => $name . "[parenturl]", 'title' => 'Parent Page', 'value' => strtolower($page->get('parenturl')), 'options' => $opts ) ); // Title $this->addElement( 'text', array( 'name' => $name . "[title]", 'title' => 'Title', 'value' => $page->get('title'), 'description' => 'Every page needs a title to accompany it, this should be short but meaningful.', 'required' => true ) ); // Rewrite url. $this->addElement( 'pagerewriteurl', array( 'name' => $name . "[rewriteurl]", 'title' => 'Page URL', 'value' => $page->get('rewriteurl'), 'description' => 'Starts with a "/", omit ' . ROOT_URL, 'required' => true ) ); $this->addElement( 'access', array( 'name' => $name . "[access]", 'title' => 'Access Permissions', 'value' => $page->get('access') ) ); $this->addElement( 'pagemetas', array( 'name' => $name . '_meta', 'model' => $page, ) ); // Give me all the skins available on the current theme. $skins = array('' => '-- Site Default Skin --'); foreach(ThemeHandler::GetTheme(null)->getSkins() as $s){ $n = ($s['title']) ? $s['title'] : $s['file']; if($s['default']) $n .= ' (default)'; $skins[$s['file']] = $n; } if(sizeof($skins) > 2){ $this->addElement( 'select', array( 'name' => $name . "[theme_template]", 'title' => 'Theme Skin', 'value' => $page->get('theme_template'), 'options' => $skins ) ); } }
/** * Internal function to parse and handle the configs in the component.xml file. * This is used for installations and upgrades. * * @param boolean $install Set to false to force uninstall/disable mode. * @param int $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output. * * @return boolean | int * @throws InstallerException */ public function _parsePages($install = true, $verbosity = 0) { $changes = array(); $overallAction = $install ? 'Installing' : 'Uninstalling'; Core\Utilities\Logger\write_debug($overallAction . ' pages for ' . $this->getName()); // I need to get the schema definitions first. $node = $this->_xmlloader->getElement('pages'); //$prefix = $node->getAttribute('prefix'); // Now, get every table under this node. foreach ($node->getElementsByTagName('page') as $subnode) { /** @var DomElement $subnode */ $baseurl = $subnode->getAttribute('baseurl'); // Insert/Update the defaults for an entry in the database. // These are always global pages. $m = new PageModel(-1, $baseurl); if($verbosity == 2){ CLI::PrintActionStart($overallAction . ' page ' . $baseurl); } // Hard-set pages get removed upon disabling. They'll be recreated if re-enabled. if($install){ // Just something to help the log. $action = ($m->exists()) ? 'Updated' : 'Added'; $admin = $subnode->getAttribute('admin'); $selectable = ($admin ? '0' : '1'); // Defaults $group = ($admin ? $subnode->getAttribute('group') : ''); if($subnode->getAttribute('selectable') !== ''){ $selectable = $subnode->getAttribute('selectable'); } $indexable = ($subnode->getAttribute('indexable') !== '') ? $subnode->getAttribute('indexable') : $selectable; $editurl = $subnode->getAttribute('editurl') ? $subnode->getAttribute('editurl') : ''; $access = ($subnode->getAttribute('access')) ? $subnode->getAttribute('access') : null; // Do not "update" value, keep whatever the user set previously. if (!$m->get('rewriteurl')) { if ($subnode->getAttribute('rewriteurl')) $m->set('rewriteurl', $subnode->getAttribute('rewriteurl')); else $m->set('rewriteurl', $subnode->getAttribute('baseurl')); } // Do not "update" value, keep whatever the user set previously. if (!$m->get('title')) $m->set('title', $subnode->getAttribute('title')); if($access !== null){ $m->set('access', $access); } // Do not update parent urls if the page already exists. if(!$m->exists()) $m->set('parenturl', $subnode->getAttribute('parenturl')); //$m->set('widget', $subnode->getAttribute('widget')); $m->set('admin', $admin); $m->set('admin_group', $group); $m->set('selectable', $selectable); $m->set('indexable', $indexable); $m->set('component', $this->getKeyName()); $m->set('editurl', $editurl); if ($m->save()){ $changes[] = $action . ' page [' . $baseurl . ']'; if($verbosity == 2){ CLI::PrintActionStatus(true); } } else{ if($verbosity == 2){ CLI::PrintActionStatus('skip'); } } } else{ $m->delete(); $changes[] = 'Removed page [' . $subnode->getAttribute('baseurl') . ']'; if($verbosity == 2){ CLI::PrintActionStatus(true); } } } return ($changes > 0) ? $changes : false; }