'Heading for first-level childless pages.', 'expanded' =>'Expand all pages. If false only the current branch will be expanded.', 'only_leafs_active' =>'Link only leaf pages.'); var $default_context = LP_CONTEXT_ALL; var $description = 'Display list of nested pages'; var $active = true; var $hooks = array('sidebar'); var $title = 'Content'; var $expanded = true; var $only_leafs_active = true; function NestedPages(&$frontend, $args, $dummy_run=false) { $this->LightPressPlugin($frontend, $args, $dummy_run); } function &run($hook, &$post) { // TODO: run current code for the 'render' hook and add code for the // 'parse_post' hook that sets the post content to a list // of child pages if it's empty $tpl =& $this->_frontend->tpl; // easier to do this without a template, can always convert it later $pages =& $this->_frontend->getPages(); $out = ''; $this->_recurse($pages, $out, 0, true); $tpl->setVar('PLUGIN_NESTEDPAGES', $out); } function _recurse(&$tree, &$out, $level, $root=false) { // TODO: track parent/ancestor names when recursing so as to use the faster permalink algorithm if ($root) { $sorted = array(); $childless = array(); foreach ($tree as $id=>$page) { if (!$page['root_page']) continue; if (count($page['children']) > 0) $sorted[$page['post_title']] =& $tree[$id]; else $childless[$page['post_title']] =& $tree[$id]; } ksort($sorted); if (count($childless) > 0) { ksort($childless); $out .= '
  • ' . $this->title . '

  • '; } } else { ksort($tree); $sorted =& $tree; } $url = $this->_frontend->options['url']; foreach ($sorted as $title=>$page) { if (count($page['children']) == 0) { // leaf $out .= sprintf( '
  • %s
  • ', $url, $this->_frontend->getPagePermalink($page['id'], $page['post_name']), $page['post_title']); } else { if ($this->only_leafs_active) { if ($level == 0) { $out .= '
  • ' . $page['post_title'] . '