Skip to content

Commit

Permalink
Merge pull request #13 from nliautaud/0.3.1
Browse files Browse the repository at this point in the history
Fix current page path comparison with no url_rewrite, see #11
  • Loading branch information
nliautaud authored Nov 12, 2017
2 parents 640b18d + 9335370 commit 3aa9d89
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions PicoPagesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
class PicoPagesList extends AbstractPicoPlugin
{
public $items;
private $base_url;
private $current_url;
private $currentPagePath;

/**
* Store the current url and construct the nested pages array.
Expand All @@ -48,7 +47,8 @@ public function onPagesLoaded(
array &$previousPage = null,
array &$nextPage = null
) {
$this->current_url = $currentPage['url'];
$base_url = $this->getConfig('base_url');
$this->currentPagePath = str_replace(array('?', $base_url), '', urldecode($currentPage['url']));
$this->items = $this->nestedPages($pages);
}

Expand Down Expand Up @@ -89,7 +89,6 @@ public function onPageRendering(Twig_Environment &$twig, array &$twigVariables,
*/
private function nestedPages($pages)
{
$this->base_url = $this->getConfig('base_url');
$this->items = array();
foreach ($pages as $page) {
$nested_path = $this->nested_path($page);
Expand All @@ -103,8 +102,7 @@ private function nestedPages($pages)
* Each path fragment is in "_childs" of the parent.
*
* @param array $page the page array
* @param array $base_url the base url, substracted from the page url
* @return array the nested path relative to $base_url
* @return array the nested path
*/
private function nested_path($page)
{
Expand Down Expand Up @@ -182,7 +180,7 @@ public static function filterPages(
* Return if the given path is a subpath of the given parent path(s)
*
* @param string $path
* @param mixed $excludedPaths a path, an array of paths or pathes separated by commas
* @param array $parentPaths array of paths
* @return boolean
*/
private static function isSubPath($path, $parentPaths)
Expand All @@ -200,21 +198,17 @@ private static function isSubPath($path, $parentPaths)
* Return an html nested list based on a nested pages array.
*
* @param array $pages a nested pages array
* @param array $paths_filters array of paths to keep or skip
* @param string $currentPath the current walked path
* @return string the html list
*/
private function output($pages, $currentPath = '')
private function output($pages)
{
if (!is_array($pages)) return;
$html = '<ul>';
foreach ($pages as $pageID => $page)
{
$childPath = $currentPath ? $currentPath.'/'.$pageID : $pageID;

$childsOutput = '';
if(isset($page['_childs'])) {
$childsOutput = $this->output($page['_childs'], $childPath);
$childsOutput = $this->output($page['_childs']);
}

$url = isset($page['url']) ? $page['url'] : false;
Expand All @@ -230,8 +224,8 @@ private function output($pages, $currentPath = '')
$class = $pageID;
$class .= $url ? ' is-page' : ' is-directory';
if ($childsOutput) $class .= ' has-childs';
if ($this->current_url == $url) $class .= ' is-current';
if (strpos($this->current_url, $this->base_url . $childPath) === 0) $class .= ' is-active';
if ($this->currentPagePath == $page['id']) $class .= ' is-current';
if (strpos($this->currentPagePath, $page['id']) === 0) $class .= ' is-active';

$html .= "<li class=\"$class\">$item$childsOutput</li>";
}
Expand Down

0 comments on commit 3aa9d89

Please sign in to comment.