private static function tryParseTagUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo) { $blogKeyDir = ''; if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) { $blogKeyDir = $blogKey . '/'; } $tagPageName = array(); $themeTagPageName = array(); $autoFormats = $pieCrust->getConfig()->getValueUnchecked('site/auto_formats'); foreach ($autoFormats as $ext => $format) { $tagPageName[] = $blogKeyDir . PieCrustDefaults::TAG_PAGE_NAME . '.' . $ext; $themeTagPageName[] = PieCrustDefaults::TAG_PAGE_NAME . '.' . $ext; } $path = PathHelper::getUserOrThemePath($pieCrust, $tagPageName, $themeTagPageName); if ($path === false) { return false; } $matches = array(); $flags = $pieCrust->getConfig()->getValueUnchecked('site/slugify_flags'); $tagsPattern = UriBuilder::buildTagUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/tag_url')); if (preg_match($tagsPattern, $uri, $matches)) { $tags = explode('/', trim($matches['tag'], '/')); if (count($tags) > 1) { // Check the tags were specified in alphabetical order. //TODO: temporary check until I find a way to make it cheap to support all permutations in the baker. sort($tags); if (implode('/', $tags) != $matches['tag']) { throw new PieCrustException("Multi-tags must be specified in alphabetical order, sorry."); } $tags = array_filter($tags, function ($t) use($flags) { $t = rawurldecode($t); return UriBuilder::slugify($t, $flags); }); } else { $tags = rawurldecode($matches['tag']); $tags = UriBuilder::slugify($tags, $flags); } $pageInfo['type'] = IPage::TYPE_TAG; $pageInfo['blogKey'] = $blogKey; $pageInfo['key'] = $tags; $pageInfo['path'] = $path; $pageInfo['was_path_checked'] = true; return true; } return false; }
private static function tryParseTagUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo) { $blogKeyDir = ''; if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) { $blogKeyDir = $blogKey . '/'; } $relativeTagPage = $blogKeyDir . PieCrustDefaults::TAG_PAGE_NAME . '.html'; $path = PathHelper::getUserOrThemeOrResPath($pieCrust, $relativeTagPage); if ($path === false) { return false; } $matches = array(); $tagsPattern = UriBuilder::buildTagUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/tag_url')); if (preg_match($tagsPattern, $uri, $matches)) { $tags = explode('/', trim($matches['tag'], '/')); if (count($tags) > 1) { // Check the tags were specified in alphabetical order. //TODO: temporary check until I find a way to make it cheap to support all permutations in the baker. sort($tags); if (implode('/', $tags) != $matches['tag']) { throw new PieCrustException("Multi-tags must be specified in alphabetical order, sorry."); } } else { $tags = $matches['tag']; } $pageInfo['type'] = IPage::TYPE_TAG; $pageInfo['blogKey'] = $blogKey; $pageInfo['key'] = $tags; $pageInfo['path'] = $path; $pageInfo['was_path_checked'] = true; return true; } return false; }