示例#1
0
function perch_blogs($opts = array(), $return = false)
{
    if (!PERCH_RUNWAY) {
        return false;
    }
    $default_opts = array('template' => 'blog.html', 'skip-template' => false, 'split-items' => false, 'cache' => true, 'include-empty' => false, 'filter' => false);
    if (is_array($opts)) {
        $opts = array_merge($default_opts, $opts);
    } else {
        $opts = $default_opts;
    }
    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_blogs' . 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');
    $Blogs = new PerchBlog_Blogs($API);
    $r = $Blogs->get_custom($opts);
    if ($r != '' && $opts['cache']) {
        PerchBlog_Cache::save_static($cache_key, $r);
    }
    if ($return) {
        return $r;
    }
    echo $r;
    return false;
}
示例#2
0
/**
 * 
 * Gets the categories used for an event
 * @param string $id_or_slug id or slug of the current event
 * @param string $template template to render the categories
 * @param bool $return if set to true returns the output rather than echoing it
 */
function perch_events_event_categories($id_or_slug, $opts = 'event_category_link.html', $return = false)
{
    $id_or_slug = rtrim($id_or_slug, '/');
    $default_opts = array('template' => 'event_category_link.html', 'skip-template' => false, 'cache' => true);
    if (!is_array($opts)) {
        $opts = array('template' => $opts);
    }
    if (is_array($opts)) {
        $opts = array_merge($default_opts, $opts);
    } else {
        $opts = $default_opts;
    }
    if ($opts['skip-template']) {
        $return = true;
    }
    $cache = false;
    $template = $opts['template'];
    if ($opts['cache']) {
        $cache_key = 'perch_events_event_categories' . md5($id_or_slug . serialize($opts));
        $cache = PerchEvents_Cache::get_static($cache_key, 10);
        if ($opts['skip-template']) {
            $cache = unserialize($cache);
        }
    }
    if ($cache) {
        if ($return) {
            return $cache;
        }
        echo $cache;
        return '';
    }
    $API = new PerchAPI(1.0, 'perch_events');
    $Events = new PerchEvents_Events($API);
    $eventID = false;
    if (is_numeric($id_or_slug)) {
        $eventID = intval($id_or_slug);
    } else {
        $Event = $Events->find_by_slug($id_or_slug);
        if (is_object($Event)) {
            $eventID = $Event->id();
        }
    }
    if ($eventID !== false) {
        $Categories = new PerchEvents_Categories();
        $cats = $Categories->get_for_event($eventID);
        if ($opts['skip-template']) {
            $out = array();
            foreach ($cats as $Cat) {
                $out[] = $Cat->to_array();
            }
            if ($opts['cache']) {
                PerchEvents_Cache::save_static($cache_key, serialize($out));
            }
            return $out;
        }
        $Template = $API->get('Template');
        $Template->set('events/' . $template, 'events');
        $r = $Template->render_group($cats, true);
        if ($r != '') {
            PerchBlog_Cache::save_static($cache_key, $r);
        }
        if ($return) {
            return $r;
        }
        echo $r;
    }
    return false;
}
function perch_blog_section($id_or_slug, $opts = array(), $return = false)
{
    $id_or_slug = rtrim($id_or_slug, '/');
    $default_opts = array('template' => 'section.html', 'skip-template' => false, 'split-items' => false, 'cache' => true);
    if (is_array($opts)) {
        $opts = array_merge($default_opts, $opts);
    } else {
        $opts = $default_opts;
    }
    if ($opts['skip-template'] || $opts['split-items']) {
        $return = true;
    }
    $cache = false;
    if ($opts['cache']) {
        $cache_key = 'perch_blog_section' . md5($id_or_slug . 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');
    $Sections = new PerchBlog_Sections();
    if (is_numeric($id_or_slug)) {
        $Section = $Sections->find($id_or_slug);
    } else {
        $Section = $Sections->find_by_slug($id_or_slug);
    }
    if (is_object($Section)) {
        if ($opts['skip-template']) {
            return $Section->to_array();
        }
        $Template = $API->get('Template');
        $Template->set('blog/' . $opts['template'], 'blog');
        $r = $Template->render($Section);
        if ($r != '') {
            PerchBlog_Cache::save_static($cache_key, $r);
        }
        if ($return) {
            return $r;
        }
        echo $r;
    }
    return false;
}