Example #1
0
 /**
  * Get this user's permissions, optionally within the context of a Page
  *
  * Does not currently include page-add or page-create permissions. 
  *
  * @param Page $page Optional page to check against
  * @return bool
  *
  */
 public function getPermissions(Page $page = null)
 {
     if ($this->isSuperuser()) {
         return $this->fuel('permissions');
     }
     $permissions = new PageArray();
     $roles = $this->get('roles');
     if (empty($roles)) {
         return $permissions;
     }
     foreach ($roles as $key => $role) {
         if ($page && !$page->hasAccessRole($role)) {
             continue;
         }
         foreach ($role->permissions as $permission) {
             if ($page && $permission->name == 'page-edit' && !in_array($role->id, $page->getAccessTemplate()->editRoles)) {
                 continue;
             }
             $permissions->add($permission);
         }
     }
     return $permissions;
 }
 public function renderChild(Page $page)
 {
     $outputFormatting = $page->outputFormatting;
     $page->setOutputFormatting(true);
     $class = '';
     $type = '';
     $note = '';
     $label = '';
     $icons = array();
     if (in_array($page->id, $this->systemIDs)) {
         $type = 'System';
         if ($page->id == $this->config->http404PageID) {
             $label = $this->_('404 Page Not Found');
         } else {
             if ($page->id == $this->config->adminRootPageID) {
                 $label = $this->_('Admin');
             } else {
                 if ($page->id == $this->config->trashPageID && isset($this->actionLabels['trash'])) {
                     $label = $this->actionLabels['trash'];
                 }
             }
         }
         // Label for 'Trash' page in PageList // Overrides page title if used
         // if label is not overridden by a language pack, make $label blank to use the page title instead
         if (in_array($label, array('Trash', 'Admin', '404 Page Not Found'))) {
             $label = '';
         }
     }
     if ($page->getAccessParent() === $page && $page->parent->id) {
         $accessTemplate = $page->getAccessTemplate();
         if ($accessTemplate && $accessTemplate->hasRole('guest')) {
             $accessTemplate = $page->parent->getAccessTemplate();
             if ($accessTemplate && !$accessTemplate->hasRole('guest') && !$page->isTrash()) {
                 $class .= ' PageListAccessOn';
                 $icons[] = 'key fa-flip-horizontal';
             }
         } else {
             $accessTemplate = $page->parent->getAccessTemplate();
             if ($accessTemplate && $accessTemplate->hasRole('guest')) {
                 $class .= ' PageListAccessOff';
                 $icons[] = 'key';
             }
         }
     }
     if ($page->id == $this->config->trashPageID) {
         $note = "< " . $this->_("Trash open: drag pages below here to trash them");
         // Message that appears next to the Trash page when open
         $icons = array('trash-o');
         // override any other icons
     } else {
         if ($page->hasStatus(Page::statusTemp)) {
             $icons[] = 'bolt';
         }
         if ($page->hasStatus(Page::statusLocked)) {
             $icons[] = 'lock';
         }
         if ($page->hasStatus(Page::statusDraft)) {
             $icons[] = 'paperclip';
         }
     }
     if (!$label) {
         $label = $this->getPageLabel($page);
     }
     if (count($icons)) {
         foreach ($icons as $n => $icon) {
             $label .= "<i class='PageListStatusIcon fa fa-fw fa-{$icon}'></i>";
         }
     }
     $a = array('id' => $page->id, 'label' => $label, 'status' => $page->status, 'numChildren' => $page->numChildren(1), 'path' => $page->template->slashUrls || $page->id == 1 ? $page->path() : rtrim($page->path(), '/'), 'template' => $page->template->name, 'actions' => array_values($this->getPageActions($page)));
     if ($class) {
         $a['addClass'] = trim($class);
     }
     if ($type) {
         $a['type'] = $type;
     }
     if ($note) {
         $a['note'] = $note;
     }
     $page->setOutputFormatting($outputFormatting);
     return $a;
 }