Пример #1
0
function perch_category($path, $opts = array(), $return = false)
{
    $path = rtrim(ltrim($path, '/'), '/') . '/';
    $opts = PerchUtil::extend(array('set' => false, 'skip-template' => false, 'template' => 'category.html', 'filter' => 'catPath', 'match' => 'eq', 'value' => $path), $opts);
    $Categories = new PerchCategories_Categories();
    $r = $Categories->get_custom($opts);
    if ($opts['skip-template']) {
        $return = true;
    }
    if ($return) {
        return $r;
    }
    echo $r;
}
Пример #2
0
/**
 *
 * Builds an archive listing of categories. Echoes out the resulting mark-up and content
 * @param string $template
 * @param bool $return if set to true returns the output rather than echoing it
 */
function perch_blog_categories($opts = 'category_link.html', $return = false)
{
    $default_opts = array('template' => 'category_link.html', 'skip-template' => false, 'split-items' => false, 'cache' => true, 'count-type' => 'blog.post', 'include-empty' => false, 'filter' => false, 'section' => false, 'set' => 'blog');
    if (!is_array($opts)) {
        $opts = array('template' => $opts);
    }
    if (is_array($opts)) {
        $opts = array_merge($default_opts, $opts);
    } else {
        $opts = $default_opts;
    }
    $opts['template'] = '~perch_blog/templates/blog/' . str_replace('blog/', '', $opts['template']);
    if ($opts['skip-template'] || $opts['split-items']) {
        $return = true;
    }
    if (isset($opts['pagination_var'])) {
        $opts['pagination-var'] = $opts['pagination_var'];
    }
    $cache = false;
    if ($opts['cache']) {
        $cache_key = 'perch_blog_categories' . md5(serialize($opts));
        $cache = PerchBlog_Cache::get_static($cache_key, 10);
    }
    if ($cache) {
        if ($return) {
            return $cache;
        }
        echo $cache;
        return '';
    }
    $API = new PerchAPI(1.0, 'perch_blog');
    $BlogPosts = new PerchBlog_Posts($API);
    if (isset($opts['blog']) && $opts['blog'] != '') {
        $Blogs = new PerchBlog_Blogs($API);
        $Blog = $Blogs->get_one_by('blogSlug', $opts['blog']);
        $opts['set'] = $Blog->setSlug();
    }
    $Categories = new PerchCategories_Categories();
    $r = $Categories->get_custom($opts, $API);
    if ($r != '' && $opts['cache']) {
        PerchBlog_Cache::save_static($cache_key, $r);
    }
    if ($return) {
        return $r;
    }
    echo $r;
    return false;
}