Example #1
0
 /**
  * Save to pages_access table to indicate what template each page is getting it's access from
  *
  * This should be called a page has been saved and it's parent or template has changed. 
  * Or, when a new page is added. 
  *
  * If there is no entry in this table, then the page is getting it's access from it's existing template. 
  *
  * This is used by PageFinder to determine what pages to include in a find() operation based on user access.
  *
  * @param Page $page
  *
  */
 public function updatePage(Page $page)
 {
     if (!$page->id) {
         return;
     }
     // this is the template where access is defined for this page
     $accessParent = $page->getAccessParent();
     $accessTemplate = $accessParent->template;
     if (!$accessParent->id || $accessParent->id == $page->id) {
         // page is the same as the one that defines access, so it doesn't need to be here
         $this->db->query("DELETE FROM pages_access WHERE pages_id=" . (int) $page->id);
     } else {
         $sql = "INSERT INTO pages_access (pages_id, templates_id) " . "VALUES({$page->id}, {$accessParent->template->id}) " . "ON DUPLICATE KEY UPDATE templates_id=VALUES(templates_id) ";
         $this->db->query($sql);
     }
     if ($page->numChildren > 0) {
         if ($page->parentPrevious && $accessParent->id != $page->id) {
             // the page has children, it's parent was changed, and access is coming from the parent
             // so the children entries need to be updated to reflect this change
             $this->rebuild($page->id, $accessTemplate->id);
         } else {
             if ($page->templatePrevious) {
                 // the page's template changed, so this may affect the children as well
                 $this->rebuild($page->id, $accessTemplate->id);
             }
         }
     }
 }
Example #2
0
 /**
  * Save to pages_access table to indicate what template each page is getting it's access from
  *
  * This should be called a page has been saved and it's parent or template has changed. 
  * Or, when a new page is added. 
  *
  * If there is no entry in this table, then the page is getting it's access from it's existing template. 
  *
  * This is used by PageFinder to determine what pages to include in a find() operation based on user access.
  *
  * @param Page $page
  *
  */
 public function updatePage(Page $page)
 {
     $page_id = (int) $page->id;
     if (!$page_id) {
         return;
     }
     // this is the template where access is defined for this page
     $accessParent = $page->getAccessParent();
     $accessTemplate = $accessParent->template;
     $database = $this->wire('database');
     if (!$accessParent->id || $accessParent->id == $page->id) {
         // page is the same as the one that defines access, so it doesn't need to be here
         $query = $database->prepare("DELETE FROM pages_access WHERE pages_id=:page_id");
         $query->bindValue(":page_id", $page_id, PDO::PARAM_INT);
         $query->execute();
     } else {
         $template_id = (int) $accessParent->template->id;
         $sql = "INSERT INTO pages_access (pages_id, templates_id) " . "VALUES(:page_id, :template_id) " . "ON DUPLICATE KEY UPDATE templates_id=VALUES(templates_id) ";
         $query = $database->prepare($sql);
         $query->bindValue(":page_id", $page_id, PDO::PARAM_INT);
         $query->bindValue(":template_id", $template_id, PDO::PARAM_INT);
         $query->execute();
     }
     if ($page->numChildren > 0) {
         if ($page->parentPrevious && $accessParent->id != $page->id) {
             // the page has children, it's parent was changed, and access is coming from the parent
             // so the children entries need to be updated to reflect this change
             $this->rebuild($page->id, $accessTemplate->id);
         } else {
             if ($page->templatePrevious) {
                 // the page's template changed, so this may affect the children as well
                 $this->rebuild($page->id, $accessTemplate->id);
             }
         }
     }
 }
 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;
 }