コード例 #1
0
ファイル: runtime.php プロジェクト: jimcurran/bdmusichub
/**
 * Gets the title of a category from its slug
 *
 * @param string $categorySlug 
 * @param string $return 
 * @return void
 * @author Drew McLellan
 */
function perch_events_category($id_or_slug, $opts = array(), $return = false)
{
    $id_or_slug = rtrim($id_or_slug, '/');
    $default_opts = array('template' => 'category.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;
    }
    if ($opts['cache']) {
        $cache_key = 'perch_events_category' . md5($id_or_slug);
        $cache = PerchEvents_Cache::get_static($cache_key, 10);
    }
    if ($cache) {
        if ($return) {
            return $cache;
        }
        echo $cache;
        return '';
    }
    $API = new PerchAPI(1.0, 'perch_events');
    $Categories = new PerchEvents_Categories($API);
    if (is_numeric($id_or_slug)) {
        $catID = intval($id_or_slug);
        $Category = $Categories->find_by_slug($catID);
    } else {
        $Category = $Categories->find_by_slug($id_or_slug);
    }
    if (is_object($Category)) {
        $Template = $API->get('Template');
        $Template->set('events/' . $opts['template'], 'events');
        $r = $Template->render($Category);
        if ($r != '' && $opts['cache']) {
            PerchEvents_Cache::save_static($cache_key, $r);
        }
        if ($return) {
            return $r;
        }
        echo $r;
    }
    return false;
}