/** * Retrieve the parent page * @return Array Array containing the content of the parent page */ private function getParent() { $parent = URL::assemble(URL::popLastSegment(URL::getCurrent())); if (Taxonomy::isTaxonomyURL($parent)) { $parent = URL::popLastSegment($parent); } return Content::get($parent); }
$data['current_url'] = $current_url; $data['slug'] = basename($current_url); // if this is an entry, default to the `post` template if ($data['_is_entry']) { $template_list[] = array_get($data, '_template', 'default'); $template_list[] = "post"; } if ($path !== "/404") { $content_found = true; } // url is taxonomy-based } elseif (Taxonomy::isTaxonomyURL($path)) { list($type, $slug) = Taxonomy::getCriteria($path); // create data array $data = array_merge(Config::getAll(), array( 'homepage' => Config::getSiteRoot(), 'raw_url' => Request::getResourceURI(), 'page_url' => Request::getResourceURI(), 'taxonomy_slug' => urldecode($slug), 'taxonomy_name' => Taxonomy::getTaxonomyName($type, $slug) )); $template_list[] = "taxonomies"; $template_list[] = $type; $content_found = true; }
public static function get_content_tree($directory = '/', $depth = 1, $max_depth = 5, $folders_only = false, $include_entries = false, $hide_hidden = true, $include_content = false, $site_root = false) { // $folders_only = true only page.md // folders_only = false includes any numbered or non-numbered page (excluding anything with a fields.yaml file) // if include_entries is true then any numbered files are included $content_root = Config::getContentRoot(); $content_type = Config::getContentType(); $site_root = $site_root ? $site_root : Config::getSiteRoot(); $current_url = Path::tidy($site_root . '/' . Request::getResourceURI()); $taxonomy_url = false; if (Taxonomy::isTaxonomyURL($current_url)) { list($taxonomy_type, $taxonomy_name) = Taxonomy::getCriteria($current_url); $taxonomy_url = self::remove_taxonomy_from_path($current_url, $taxonomy_type, $taxonomy_name); } $directory = '/' . $directory . '/'; #ensure proper slashing if ($directory != '/') { $base = Path::tidy("{$content_root}/{$directory}"); } elseif ($directory == '/') { $base = "{$content_root}"; } else { $base = "{$content_root}"; } $files = glob("{$base}/*"); $data = array(); if ($files) { foreach ($files as $path) { $current_name = basename($path); if (!Pattern::endsWith($current_name, '.yaml')) { // Hidden page that should be removed if ($hide_hidden && Pattern::startsWith($current_name, '_')) { continue; } $node = array(); $file = substr($path, strlen($base) + 1, strlen($path) - strlen($base) - strlen($content_type) - 2); if (is_dir($path)) { $folder = substr($path, strlen($base) + 1); $node['type'] = 'folder'; $node['slug'] = basename($folder); $node['title'] = ucwords(basename($folder)); $node['numeric'] = Slug::getOrderNumber($folder); $node['file_path'] = Path::tidy($site_root . '/' . $directory . '/' . $folder . '/page'); if (Slug::isNumeric($folder)) { $pos = strpos($folder, "."); if ($pos !== false) { $node['raw_url'] = Path::tidy(Path::clean($site_root . '/' . $directory . '/' . $folder)); $node['url'] = Path::clean($node['raw_url']); $node['title'] = ucwords(basename(substr($folder, $pos + 1))); } else { $node['title'] = ucwords(basename($folder)); $node['raw_url'] = Path::tidy($site_root . '/' . $directory . '/' . $folder); $node['url'] = Path::clean($node['raw_url']); } } else { $node['title'] = ucwords(basename($folder)); $node['raw_url'] = Path::tidy($site_root . '/' . $directory . '/' . $folder); $node['url'] = Path::clean($node['raw_url']); } $node['depth'] = $depth; $node['children'] = $depth < $max_depth ? self::get_content_tree($directory . $folder . '/', $depth + 1, $max_depth, $folders_only, $include_entries, $hide_hidden, $include_content, $site_root) : null; $node['is_current'] = $node['raw_url'] == $current_url || $node['url'] == $current_url ? true : false; $node['is_parent'] = false; if ($node['url'] == URL::popLastSegment($current_url) || $taxonomy_url && $node['url'] == $taxonomy_url) { $node['is_parent'] = true; } $node['has_children'] = $node['children'] ? true : false; // has entries? if (File::exists(Path::tidy($path . "/fields.yaml"))) { $node['has_entries'] = true; } else { $node['has_entries'] = false; } $meta = self::get_content_meta("page", Path::tidy($directory . "/" . $folder), false, true); //$meta = self::get_content_meta("page", Statamic_Helper::reduce_double_slashes($directory."/".$folder)); if (isset($meta['title'])) { $node['title'] = $meta['title']; } if (isset($meta['last_modified'])) { $node['last_modified'] = $meta['last_modified']; } if ($hide_hidden === true && (isset($meta['status']) && ($meta['status'] == 'hidden' || $meta['status'] == 'draft'))) { // placeholder condition } else { $data[] = $include_content ? array_merge($meta, $node) : $node; // print_r($data); } } else { if (Pattern::endsWith($path, $content_type)) { if ($folders_only == false) { if ($file == 'page' || $file == 'feed' || $file == '404') { // $node['url'] = $directory; // $node['title'] = basename($directory); // $meta = self::get_content_meta('page', substr($directory, 1)); // $node['depth'] = $depth; } else { $include = true; // date based is never included if (Config::getEntryTimestamps() && Slug::isDateTime(basename($path))) { $include = false; } elseif (Slug::isDate(basename($path))) { $include = false; } elseif (Slug::isNumeric(basename($path))) { if ($include_entries == false) { if (File::exists(Path::tidy(dirname($path) . "/fields.yaml"))) { $include = false; } } } if ($include) { $node['type'] = 'file'; $node['raw_url'] = Path::tidy($directory) . basename($path); $pretty_url = Path::clean($node['raw_url']); $node['url'] = substr($pretty_url, 0, -1 * (strlen($content_type) + 1)); $node['is_current'] = $node['url'] == $current_url || $node['url'] == $current_url ? true : false; $node['slug'] = substr(basename($path), 0, -1 * (strlen($content_type) + 1)); $meta = self::get_content_meta(substr(basename($path), 0, -1 * (strlen($content_type) + 1)), substr($directory, 1), false, true); //$node['meta'] = $meta; if (isset($meta['title'])) { $node['title'] = $meta['title']; } $node['depth'] = $depth; if ($hide_hidden === true && (isset($meta['status']) && ($meta['status'] == 'hidden' || $meta['status'] == 'draft'))) { } else { $data[] = $include_content ? array_merge($meta, $node) : $node; } } } } } } } } } return $data; }
public static function is_taxonomy_url($path) { Log::warn("Use of Statamic::is_taxonomy_url() is deprecated. Use Taxonomy::isTaxonomyURL() instead.", "core", "Statamic"); return Taxonomy::isTaxonomyURL($path); }