/** * Returns the URL for a given $taxonomy and $taxonomy_slug * * @param string $folder Folder to use * @param string $taxonomy Taxonomy to use * @param string $taxonomy_slug Taxonomy slug to use * @return string */ public static function getURL($folder, $taxonomy, $taxonomy_slug) { $url = Config::getSiteRoot() . '/' . $folder . '/' . $taxonomy . '/'; $url .= Config::getTaxonomySlugify() ? Slug::make($taxonomy_slug) : $taxonomy_slug; // if taxonomies are not case-sensitive, make it lowercase if (!Config::getTaxonomyCaseSensitive()) { $url = strtolower($url); } return Path::tidy($url); }
/** * Returns a taxonomy slug's name if stored in cache * * @param string $taxonomy Taxonomy to use * @param string $taxonomy_slug Taxonomy slug to use * @return mixed */ public static function getTaxonomyName($taxonomy, $taxonomy_slug) { self::loadCache(); if (Config::getTaxonomySlugify()) { $taxonomy_slug = Slug::humanize($taxonomy_slug); } if (!isset(self::$cache['taxonomies'][$taxonomy]) || !isset(self::$cache['taxonomies'][$taxonomy][$taxonomy_slug])) { return null; } return self::$cache['taxonomies'][$taxonomy][$taxonomy_slug]['name']; }
/** * Gets a list of taxonomy values by type * * @param string $type Taxonomy type to retrieve * @return TaxonomySet */ public static function getTaxonomiesByType($type) { self::loadCache(); $data = array(); // taxonomy type doesn't exist, return empty if (!isset(self::$cache['taxonomies'][$type])) { return new TaxonomySet(array()); } $url_root = Config::getSiteRoot() . $type; $values = self::$cache['taxonomies'][$type]; $slugify = Config::getTaxonomySlugify(); // what we need // - name // - count of related content // - related foreach ($values as $key => $parts) { $set = array(); $prepared_key = $slugify ? Slug::make($key) : rawurlencode($key); foreach ($parts['files'] as $url) { if (!isset(self::$cache['urls'][$url])) { continue; } $set[$url] = self::$cache["content"][self::$cache['urls'][$url]['folder']][self::$cache['urls'][$url]['file']]['data']; } $data[$key] = array('content' => new ContentSet($set), 'name' => $parts['name'], 'url' => $url_root . '/' . $prepared_key, 'slug' => $type . '/' . $prepared_key); $data[$key]['count'] = $data[$key]['content']->count(); } return new TaxonomySet($data); }