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; }
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; }