Beispiel #1
0
/**
 * Gets the title of a category from its slug
 *
 * @param string $categorySlug
 * @param string $return
 * @return void
 * @author Drew McLellan
 */
function perch_blog_category($categorySlug, $blog = false, $return = false)
{
    $set = 'blog';
    $categorySlug = rtrim($categorySlug, '/');
    $categoryPath = 'blog/' . $categorySlug . '/';
    if (strpos($categorySlug, '/')) {
        $categoryPath = $categorySlug;
    } else {
        if (is_bool($blog)) {
            $return = $blog;
            $set = 'blog';
        } else {
            $API = new PerchAPI(1.0, 'perch_blog');
            $Blogs = new PerchBlog_Blogs($API);
            $Blog = $Blogs->get_one_by('blogSlug', $blog);
            if ($Blog) {
                $set = $Blog->setSlug();
            }
        }
        $categoryPath = $set . '/' . $categorySlug . '/';
    }
    $cache_key = 'perch_blog_category' . md5($categorySlug);
    $cache = PerchBlog_Cache::get_static($cache_key, 10);
    if ($cache) {
        if ($return) {
            return $cache;
        }
        echo PerchUtil::html($cache);
        return '';
    }
    $Categories = new PerchCategories_Categories();
    $Category = $Categories->get_one_by('catPath', $categoryPath);
    if (is_object($Category)) {
        $r = $Category->catTitle();
        if ($r != '') {
            PerchBlog_Cache::save_static($cache_key, $r);
        }
        if ($return) {
            return $r;
        }
        echo PerchUtil::html($r);
    }
    return false;
}
/**
 * Gets the title of a category from its slug
 *
 * @param string $categorySlug 
 * @param string $return 
 * @return void
 * @author Drew McLellan
 */
function perch_blog_category($categorySlug, $return = false)
{
    $categorySlug = rtrim($categorySlug, '/');
    $cache_key = 'perch_blog_category' . md5($categorySlug);
    $cache = PerchBlog_Cache::get_static($cache_key, 10);
    if ($cache) {
        if ($return) {
            return $cache;
        }
        echo PerchUtil::html($cache);
        return '';
    }
    $Categories = new PerchCategories_Categories();
    $Category = $Categories->get_one_by('catPath', 'blog/' . $categorySlug . '/');
    if (is_object($Category)) {
        $r = $Category->catTitle();
        if ($r != '') {
            PerchBlog_Cache::save_static($cache_key, $r);
        }
        if ($return) {
            return $r;
        }
        echo PerchUtil::html($r);
    }
    return false;
}