private static function tryParsePostUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo) { $postsDir = $pieCrust->getPostsDir(); if ($postsDir === false) { return false; } $matches = array(); $postsPattern = UriBuilder::buildPostUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/post_url')); if (preg_match($postsPattern, $uri, $matches)) { $fs = $pieCrust->getEnvironment()->getFileSystem(); $pathInfo = $fs->getPostPathInfo($blogKey, $matches, FileSystem::PATHINFO_PARSING); $date = mktime(0, 0, 0, intval($pathInfo['month']), intval($pathInfo['day']), intval($pathInfo['year'])); $pageInfo['type'] = IPage::TYPE_POST; $pageInfo['blogKey'] = $blogKey; $pageInfo['date'] = $date; $pageInfo['path'] = $pathInfo['path']; return true; } return false; }
private function findPages($context, $pages, $fromBlog = false) { $logger = $context->getLog(); $pieCrust = $context->getApp(); $result = $context->getResult(); $rootDir = $pieCrust->getRootDir(); $rootDir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $rootDir); $exact = $result->command->options['exact']; $pattern = $result->command->args['pattern']; $fullPath = $result->command->options['full_path']; $returnComponents = $result->command->options['page_components']; $foundAny = false; foreach ($pages as $page) { if ($result->command->options['no_special']) { // Skip special pages. if ($page->getUri() == PieCrustDefaults::CATEGORY_PAGE_NAME or $page->getUri() == PieCrustDefaults::TAG_PAGE_NAME) { continue; } } if ($exact) { // Match the path exactly, or pass. if (str_replace('\\', '/', $pattern) != str_replace('\\', '/', $page->getPath())) { continue; } } else { if ($pattern) { // Match the regex, or pass. if (!preg_match($pattern, $page->getUri())) { continue; } } } $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $page->getPath()); if (!$fullPath) { if (substr($path, 0, strlen($rootDir)) == $rootDir) { $path = PieCrustHelper::getRelativePath($pieCrust, $path); } } if ($returnComponents) { $components = array('path' => $path, 'type' => 'page', 'uri' => $page->getUri(), 'slug' => $page->getUri()); if (PageHelper::isPost($page)) { $timestamp = $page->getDate(true); $components['type'] = 'post'; $components['year'] = date('Y', $timestamp); $components['month'] = date('m', $timestamp); $components['day'] = date('d', $timestamp); $components['hour'] = date('H', $timestamp); $components['minute'] = date('i', $timestamp); $components['second'] = date('s', $timestamp); $matches = array(); $postsPattern = UriBuilder::buildPostUriPattern($pieCrust->getConfig()->getValue($fromBlog . '/post_url'), $fromBlog); if (preg_match($postsPattern, $page->getUri(), $matches)) { $components['slug'] = $matches['slug']; } } foreach ($components as $k => $v) { $logger->info("{$k}: {$v}"); } $logger->info(""); $foundAny = true; } else { $logger->info($path); $foundAny = true; } } return $foundAny; }