示例#1
0
$Form->handle_empty_block_generation($Template);
$tags = $Template->find_all_tags_and_repeaters();
$Form->require_field('blogTitle', 'Required');
$Form->set_required_fields_from_template($Template, $details);
if ($Form->submitted()) {
    $postvars = array('blogTitle', 'setSlug', 'postTemplate');
    $data = $Form->receive($postvars);
    $prev = false;
    if (isset($details['blogDynamicFields'])) {
        $prev = PerchUtil::json_safe_decode($details['blogDynamicFields'], true);
    }
    $dynamic_fields = $Form->receive_from_template_fields($Template, $prev, $Blogs, $Blog);
    $data['blogDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields);
    if (!is_object($Blog)) {
        $data['blogSlug'] = PerchUtil::urlify($data['blogTitle']);
        $Blog = $Blogs->create($data);
        PerchUtil::redirect($API->app_path() . '/blogs/edit/?id=' . $Blog->id() . '&created=1');
    }
    $Blog->update($data);
    if (is_object($Blog)) {
        $message = $HTML->success_message('Your blog has been successfully edited. Return to %sblog listing%s', '<a href="' . $API->app_path() . '/blogs">', '</a>');
    } else {
        $message = $HTML->failure_message('Sorry, that blog could not be edited.');
    }
    // clear the caches
    PerchBlog_Cache::expire_all();
    $details = $Blog->to_array();
}
if (isset($_GET['created']) && !$message) {
    $message = $HTML->success_message('Your blog has been successfully created. Return to %sblog listing%s', '<a href="' . $API->app_path() . '/blogs">', '</a>');
}
 public static function disable()
 {
     self::$disabled = true;
 }
 private function _load_blog()
 {
     $Cache = PerchBlog_Cache::fetch();
     $cached_blogs = $Cache->get('blogs');
     if (!$cached_blogs) {
         $Blogs = new PerchBlog_Blogs();
         $blogs = $Blogs->all();
         if (PerchUtil::count($blogs)) {
             $cached_blogs = array();
             foreach ($blogs as $Blog) {
                 $cached_blogs[$Blog->id()] = $Blog;
             }
             $Cache->set('blogs', $cached_blogs);
         }
     }
     if ($cached_blogs) {
         if (isset($cached_blogs[$this->blogID()])) {
             $this->Blog = $cached_blogs[$this->blogID()];
             return true;
         }
     }
     return false;
 }
 public function get_months_for_year($year, $sectionID = false)
 {
     $Cache = PerchBlog_Cache::fetch();
     $cache_key = 'months_for_year_' . $year;
     if ($sectionID) {
         $cache_key .= '_' . $sectionID;
     }
     if ($Cache->exists($cache_key)) {
         return $Cache->get($cache_key);
     }
     $sql = 'SELECT DISTINCT 
 	            year(postDateTime) AS year,
 	            month(postDateTime) AS month,
 	            CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS postDateTime,
 	            COUNT(*) AS month_qty
             FROM ' . $this->table . ' p
         	WHERE year(postDateTime) = ' . $this->db->pdb($year) . ' 
         	    AND p.postStatus=\'Published\'
                 AND p.postDateTime<=' . $this->db->pdb(date('Y-m-d H:i:00'));
     if ($sectionID) {
         $sql .= ' AND p.sectionID=' . $this->db->pdb($sectionID);
     }
     $sql .= ' GROUP BY year, month
         	ORDER BY month DESC';
     $rows = $this->db->get_rows($sql);
     $Cache->set($cache_key, $rows);
     return $rows;
 }
示例#5
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;
}
 private function _load_section()
 {
     $Cache = PerchBlog_Cache::fetch();
     $cached_sections = $Cache->get('sections');
     if (!$cached_sections) {
         $Sections = new PerchBlog_Sections();
         $sections = $Sections->all();
         if (PerchUtil::count($sections)) {
             $cached_sections = array();
             foreach ($sections as $Section) {
                 $cached_sections[$Section->id()] = $Section;
             }
             $Cache->set('sections', $cached_sections);
         }
     }
     if ($cached_sections) {
         if (isset($cached_sections[$this->sectionID()])) {
             $this->Section = $cached_sections[$this->sectionID()];
             return true;
         }
     }
     return false;
 }
示例#7
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;
}
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;
}