/** * Render a Foundation 'side-nav' list for placement in #sidebar * */ function renderSubNav(Page $page) { if (!$page->numChildren(true)) { return ''; } $options = array('class' => 'side-nav', 'dividers' => true, 'tree' => true); $out = "<h3><a href='{$page->url}'>{$page->title}</a></h3>"; $out .= renderNav($page->children, $options); return $out; }
/** * Export the page's data to an array that can be later imported * * @param Page $page * @return array * */ public function export(Page $page) { $of = $page->of(); $page->of(false); // todo: make user definable guid, except for ID part $guid = $this->wire('config')->httpHost . $this->wire('config')->urls->root . $page->id; $data = array('id' => $page->id, 'guid' => $guid, 'parent_id' => $page->parent_id, 'parent' => $page->parent->path, 'templates_id' => $page->templates_id, 'template' => $page->template->name, 'name' => $page->name, 'status' => $page->status, 'sort' => $page->sort, 'sortfield' => $page->sortfield, 'num_children' => $page->numChildren(), 'created' => $page->created, 'created_users_id' => $page->created_users_id, 'created_user' => $page->createdUser->name, 'modified' => $page->modified, 'modified_users_id' => $page->modified_users_id, 'modified_user' => $page->modifiedUser->name, 'published' => $page->published, 'core_version' => $this->wire('config')->version, 'export_time' => time(), 'data' => array(), 'types' => array()); foreach ($page->template->fieldgroup as $field) { if ($field->type instanceof FieldtypeFieldsetOpen) { continue; } $data['data'][$field->name] = $this->exportValue($page, $field, $page->get($field->name)); $data['types'][$field->name] = $field->type->className(); } $page->of($of); return $data; }
/** * Debug info specific to Page objects * * @param Page $page * @return array * */ protected function Page(Page $page) { $info = array('instanceID' => $page->instanceID, 'id' => $page->id, 'name' => $page->name, 'namePrevious' => '', 'path' => $page->path(), 'status' => implode(', ', $page->status(true)), 'statusPrevious' => 0, 'template' => $page->template ? $page->template->name : '', 'templatePrevious' => '', 'parent' => $page->parent ? $page->parent->path : '', 'parentPrevious' => '', 'numChildren' => $page->numChildren(), 'sort' => $page->sort, 'sortfield' => $page->sortfield, 'created' => $page->created, 'modified' => $page->modified, 'createdUser' => $page->createdUser ? $page->createdUser->name : $page->created_users_id, 'modifiedUser' => $page->modifiedUser ? $page->modifiedUser->name : $page->modified_users_id); if ($page->namePrevious) { $info['namePrevious'] = $page->namePrevious; } else { unset($info['namePrevious']); } if ($page->statusPrevious !== null) { $info['statusPrevious'] = implode(', ', $page->status(true, $page->statusPrevious)); } else { unset($info['statusPrevious']); } if ($page->templatePrevious) { $info['templatePrevious'] = $page->templatePrevious->name; } else { unset($info['templatePrevious']); } if ($page->parentPrevious) { $info['parentPrevious'] = $page->parentPrevious->path(); } else { unset($info['parentPrevious']); } if ($page->isNew) { $info['isNew'] = 1; } $info['isLoaded'] = (int) $page->isLoaded(); $info['outputFormatting'] = (int) $page->outputFormatting(); if ($page->quietMode) { $info['quietMode'] = 1; } foreach (array('created', 'modified') as $key) { $info[$key] = wireDate($this->wire('config')->dateFormat, $info[$key]) . " " . "(" . wireDate('relative', $info[$key]) . ")"; } return $info; }
/** * Render a side navigation items * * This function designed primarily to be called by the renderSideNavItems() function. * * @param Page $p * @return string * */ public function renderSideNavItem(Page $p) { $isSuperuser = $this->wire('user')->isSuperuser(); $sanitizer = $this->wire('sanitizer'); $modules = $this->wire('modules'); $showItem = $isSuperuser; $children = $p->numChildren() ? $p->children("check_access=0") : array(); $out = ''; $iconName = $p->name; $icon = $this->wire('adminTheme')->{$iconName}; if (!$icon) { $icon = 'fa-file-text-o'; } $numViewable = 0; if (!$showItem) { $checkPages = count($children) ? $children : array($p); foreach ($checkPages as $child) { if ($child->viewable()) { $showItem = true; $numViewable++; if ($numViewable > 1) { break; } // we don't need to know about any more } } } // don't bother with a drop-down here if only 1 child if ($p->name == 'page' && !$isSuperuser && $numViewable < 2) { $children = array(); } if (!$showItem) { return ''; } if ($p->process) { $moduleInfo = $modules->getModuleInfo($p->process); $textdomain = str_replace($this->wire('config')->paths->root, '/', $this->wire('modules')->getModuleFile($p->process)); } else { $moduleInfo = array(); $textdomain = ''; } if (!count($children) && !empty($moduleInfo['nav'])) { $children = $moduleInfo['nav']; } $class = strpos($this->wire('page')->path, $p->path) === 0 ? 'current' : ''; // current class $class .= count($children) > 0 ? " parent" : ''; // parent class $title = $sanitizer->entities1((string) $this->_($p->get('title|name'))); $currentPagePath = $this->wire('page')->url; // use URL to support sub directory installs $out .= "<li>"; if (count($children)) { $out .= "<a href='{$p->url}' class='{$class} {$p->name} '><i class='fa {$icon}'></i> {$title}</a>"; $out .= "<ul>"; foreach ($children as $c) { $navJSON = ''; if (is_array($c)) { // $c is moduleInfo nav array $moduleInfo = array(); if (isset($c['permission']) && !$this->wire('user')->hasPermission($c['permission'])) { continue; } $segments = $this->input->urlSegments ? implode("/", $this->input->urlSegments) . '/' : ''; $class = $currentPagePath . $segments == $p->path . $c['url'] ? 'current' : ''; $title = $sanitizer->entities1(__($c['label'], $textdomain)); $url = $p->url . $c['url']; if (isset($c['navJSON'])) { $navJSON = $c['navJSON']; // url part $moduleInfo['useNavJSON'] = true; } $c = $p; // substitute } else { // $c is a Page object $list = array(wire('config')->urls->admin . "page/", wire('config')->urls->admin . "page/edit/"); in_array($currentPagePath, $list) ? $currentPagePath = wire('config')->urls->admin . "page/list/" : ''; $class = strpos($currentPagePath, $c->url) === 0 ? 'current' : ''; // child current class $name = $c->name; if (!$c->viewable()) { continue; } $moduleInfo = $c->process ? $modules->getModuleInfo($c->process) : array(); $title = $this->getPageTitle($c); if (!strlen($title)) { continue; } $url = $c->url; // The /page/ and /page/list/ are the same process, so just keep them on /page/ instead. if (strpos($url, '/page/list/') !== false) { $url = str_replace('/page/list/', '/page/', $url); } } $quicklinks = ''; if (!empty($moduleInfo['useNavJSON'])) { // NOTE: 'useNavJSON' comes before 'nav' for AdminThemeReno only, since it does not support navJSON beyond one level // meaning this bypasses 'nav' if the module happens to also provide navJSON (see ProcessRecentPages example) if (empty($navJSON)) { $navJSON = "navJSON/"; } $quicklinks = $this->renderQuicklinks($c, array(), $title, $navJSON); } else { if (!empty($moduleInfo['nav'])) { $quicklinks = $this->renderQuicklinks($c, $moduleInfo['nav'], $title); } } $icon = isset($moduleInfo['icon']) ? $moduleInfo['icon'] : ''; $toggle = $quicklinks ? "<i class='quicklink-open fa fa-bolt'></i>" : ""; if ($class == 'current' && $icon) { $title = "<i class='fa fa-fw fa-{$icon} current-icon'></i>{$title}"; } if ($quicklinks) { $class .= " has-quicklinks"; } $out .= "<li><a href='{$url}' class='{$class}' data-icon='{$icon}'><span>{$title}</span>{$toggle}</a>" . $quicklinks; $out .= "</li>"; } $out .= "</ul>"; } else { $class = $class ? " class='{$class} {$p->name}'" : "class='{$p->name}'"; $out .= "<a href='{$p->url}' {$class}><i class='fa {$icon}'></i> <span>{$title}</span></a>"; } $out .= "</li>"; return $out; }