From aa1bc077a785986889e737d4b2c2715284571fff Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 14 Jul 2016 00:24:06 +0200 Subject: [PATCH] Add $dropIndex parameter to Pico::getPageUrl() method This allows one to prevent Pico from removing the last "index" path component. Example use case: Pico's official admin plugin. We must distinguish between "content/sub.md" and "content/sub/index.md", otherwise it wouldn't be possible to edit both pages. --- lib/Pico.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index 1f129b4..b2f04a6 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1424,9 +1424,11 @@ class Pico * @param string $page identifier of the page to link to * @param array|string $queryData either an array containing properties to * create a URL-encoded query string from, or a already encoded string + * @param boolean $dropIndex when the last path component is "index", + * then passing TRUE (default) leads to removing this path component * @return string URL */ - public function getPageUrl($page, $queryData = null) + public function getPageUrl($page, $queryData = null, $dropIndex = true) { if (is_array($queryData)) { $queryData = http_build_query($queryData, '', '&'); @@ -1438,11 +1440,13 @@ class Pico } // drop "index" - if ($page === 'index') { - $page = ''; - } elseif (($pagePathLength = strrpos($page, '/')) !== false) { - if (substr($page, $pagePathLength + 1) === 'index') { - $page = substr($page, 0, $pagePathLength); + if ($dropIndex) { + if ($page === 'index') { + $page = ''; + } elseif (($pagePathLength = strrpos($page, '/')) !== false) { + if (substr($page, $pagePathLength + 1) === 'index') { + $page = substr($page, 0, $pagePathLength); + } } }