/** * * retrieves all tags used by blog posts along with a count of number of posts for each tag. */ public function all_in_use($opts = array()) { if (isset($opts['section']) && $opts['section']) { $Sections = new PerchBlog_Sections($this->api); $Section = $Sections->get_one_by('sectionSlug', $opts['section']); if (!is_object($Section)) { return false; } $sql = 'SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM ' . PERCH_DB_PREFIX . 'blog_tags t, ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t, ' . PERCH_DB_PREFIX . 'blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus=\'Published\' AND p.postDateTime<=' . $this->db->pdb(date('Y-m-d H:i:00')) . ' AND p.sectionID=' . $this->db->pdb((int) $Section->id()) . ' GROUP BY t.tagID ORDER BY t.tagTitle ASC '; } else { $sql = 'SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM ' . PERCH_DB_PREFIX . 'blog_tags t, ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t, ' . PERCH_DB_PREFIX . 'blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus=\'Published\' AND p.postDateTime<=' . $this->db->pdb(date('Y-m-d H:i:00')) . ' GROUP BY t.tagID ORDER BY t.tagTitle ASC'; } $rows = $this->db->get_rows($sql); $r = $this->return_instances($rows); return $r; }
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; }
<?php $HTML = $API->get('HTML'); // Try to update $Settings = $API->get('Settings'); if ($Settings->get('perch_blog_update')->val() != '5.0') { PerchUtil::redirect($API->app_path() . '/update/'); } $Blog = new PerchBlog_Posts($API); $Paging = $API->get('Paging'); $Paging->set_per_page(15); $Categories = new PerchCategories_Categories(); $categories = $Categories->get_for_set('blog'); $Sections = new PerchBlog_Sections($API); $sections = $Sections->all(); $Lang = $API->get('Lang'); $posts = array(); $filter = 'all'; if (isset($_GET['category']) && $_GET['category'] != '') { $filter = 'category'; $category = $_GET['category']; } if (isset($_GET['section']) && $_GET['section'] != '') { $filter = 'section'; $section = $_GET['section']; } if (isset($_GET['status']) && $_GET['status'] != '') { $filter = 'status'; $status = $_GET['status']; } switch ($filter) {
$template = $Post->postMetaTemplate(); } $Blog = false; if (PERCH_RUNWAY) { if ($Post) { $Blog = $Post->get_blog(); } else { if (PerchUtil::get('blog')) { $Blog = $Blogs->find((int) PerchUtil::get('blog')); } } } if (!$Blog) { $Blog = $Blogs->find(1); } $Sections = new PerchBlog_Sections(); $sections = $Sections->get_by('blogID', $Blog->id()); if (!$template) { $template = $Blog->postMetaTemplate(); } $Template = $API->get('Template'); $Template->set('blog/' . $template, 'blog'); $tags = $Template->find_all_tags_and_repeaters(); $Form = $API->get('Form'); $Form->handle_empty_block_generation($Template); $result = false; $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('postTags', 'postAllowComments', 'postTemplate', 'authorID', 'sectionID'); $data = $Form->receive($postvars); if (!isset($data['postAllowComments'])) {
private function _standard_where_callback($opts) { $preview_mode = self::$preview_mode; $db = $this->db; return function (PerchQuery $Query) use($opts, $preview_mode, $db) { // section if (isset($opts['section'])) { $Sections = new PerchBlog_Sections(); if (is_numeric($opts['section'])) { $Section = $Sections->find($opts['section']); } else { $Section = $Sections->find_by_slug($opts['section']); } if (is_object($Section)) { $Query->where[] = ' sectionID=' . $db->pdb($Section->id()); } else { $Query->where[] = ' sectionID IS NULL '; } } // author if (isset($opts['author'])) { $Authors = new PerchBlog_Authors(); if (is_numeric($opts['author'])) { $Author = $Authors->find($opts['author']); } else { $Author = $Authors->find_by_slug($opts['author']); } if (is_object($Author)) { $Query->where[] = ' authorID=' . $db->pdb($Author->id()); } else { $Query->where[] = ' authorID IS NULL '; } } // tags if (isset($opts['tag'])) { $tags = $opts['tag']; if (!is_array($tags)) { $tags = array($tags); } $do_tag = array(); $do_not_tag = array(); foreach ($tags as $tag) { if (substr($tag, 0, 1) == '!') { $do_not_tag[] = ltrim($tag, '!'); } else { $do_tag[] = $tag; } } if (is_array($tags)) { $Query->select .= ' LEFT JOIN ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t ON tbl.postID=p2t.postID LEFT JOIN ' . PERCH_DB_PREFIX . 'blog_tags t ON p2t.tagID=t.tagID '; if (PerchUtil::count($do_tag)) { $Query->where[] = ' tagSlug IN (' . $db->implode_for_sql_in($do_tag) . ') '; } if (PerchUtil::count($do_not_tag)) { $Query->where[] = ' tbl.postID NOT IN ( SELECT p2.postID FROM ' . $this->table . ' p2, ' . PERCH_DB_PREFIX . 'blog_posts_to_tags p2t2, ' . PERCH_DB_PREFIX . 'blog_tags t2 WHERE p2.postID=p2t2.postID AND p2t2.tagID=t2.tagID AND t2.tagSlug IN (' . $db->implode_for_sql_in($do_not_tag) . ') )'; } } } if ($preview_mode || isset($opts['admin']) && $opts['admin']) { // nothing } else { $Query->where[] = 'postStatus=\'Published\' AND postDateTime<=' . $db->pdb(date('Y-m-d H:i:00')) . ' '; } return $Query; }; }
$cats = $db->get_rows('SELECT * FROM ' . PERCH_DB_PREFIX . 'blog_categories'); if (PerchUtil::count($cats)) { foreach ($cats as $cat) { $dynfields = '[]'; if ($cat['categoryDynamicFields']) { $dynfields = $cat['categoryDynamicFields']; } $NewCat = $Core_Categories->create(array('setID' => $Set->id(), 'catParentID' => 0, 'catTitle' => $cat['categoryTitle'], 'catSlug' => $cat['categorySlug'], 'catPath' => '/blog/' . $cat['categorySlug'] . '/', 'catDynamicFields' => $dynfields)); if (is_object($NewCat)) { $db->update(PERCH_DB_PREFIX . 'blog_categories', array('categoryCoreID' => $NewCat->id()), 'categoryID', $cat['categoryID']); } } } } } $Posts = new PerchBlog_Posts($API); $posts = $Posts->all($Paging); if (PerchUtil::count($posts)) { foreach ($posts as $Post) { $Post->import_legacy_categories(); $Post->index(); } } if ($Paging->is_last_page()) { $Sections = new PerchBlog_Sections($API); $Sections->update_post_counts(); $Posts->update_category_counts(); $Authors = new PerchBlog_Authors($API); $Authors->update_post_counts(); $Settings->set('perch_blog_update', '5.0'); }
<?php $Blog = new PerchBlog_Posts($API); $message = false; $Authors = new PerchBlog_Authors(); $Author = $Authors->find_or_create($CurrentUser); $Sections = new PerchBlog_Sections(); $sections = $Sections->all(); $HTML = $API->get('HTML'); if (!$CurrentUser->has_priv('perch_blog.post.create')) { PerchUtil::redirect($API->app_path()); } if (isset($_GET['id']) && $_GET['id'] != '') { $postID = (int) $_GET['id']; $Post = $Blog->find($postID, true); $details = $Post->to_array(); //PerchUtil::debug($details, 'notice'); $template = $Post->postTemplate(); } else { $Post = false; $postID = false; $details = array(); if (!$CurrentUser->has_priv('perch_blog.post.create')) { PerchUtil::redirect($API->app_path()); } $template = false; } if (!$template) { $template = 'post.html'; } $Template = $API->get('Template');
<?php $Sections = new PerchBlog_Sections($API); $HTML = $API->get('HTML'); $Form = $API->get('Form'); $Form->set_name('delete'); if (!$CurrentUser->has_priv('perch_blog.sections.manage')) { PerchUtil::redirect($API->app_path()); } $message = false; if (isset($_GET['id']) && $_GET['id'] != '') { $Section = $Sections->find($_GET['id']); } else { PerchUtil::redirect($API->app_path()); } if ($Form->submitted()) { if (is_object($Section)) { $Section->delete(); // clear the caches PerchBlog_Cache::expire_all(); if ($Form->submitted_via_ajax) { echo $API->app_path() . '/sections/'; exit; } else { PerchUtil::redirect($API->app_path() . '/sections/'); } } else { $message = $HTML->failure_message('Sorry, that section could not be deleted.'); } } $details = $Section->to_array();
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; }
$blogs = $Blogs->all(); } $Paging = $API->get('Paging'); $Paging->set_per_page(15); $Blog = false; if (PERCH_RUNWAY) { if (PerchUtil::get('blog')) { $Blog = $Blogs->get_one_by('blogSlug', PerchUtil::get('blog')); } } if (!$Blog) { $Blog = $Blogs->find(1); } $Categories = new PerchCategories_Categories(); $categories = $Categories->get_for_set($Blog->setSlug()); $Sections = new PerchBlog_Sections($API); $sections = $Sections->get_by('blogID', (int) $Blog->id()); $Lang = $API->get('Lang'); $posts = array(); $filter = 'all'; if (isset($_GET['category']) && $_GET['category'] != '') { $filter = 'category'; $category = $_GET['category']; } if (isset($_GET['section']) && $_GET['section'] != '') { $filter = 'section'; $section = $_GET['section']; } if (isset($_GET['status']) && $_GET['status'] != '') { $filter = 'status'; $status = $_GET['status'];
<?php $Sections = new PerchBlog_Sections($API); $HTML = $API->get('HTML'); $Form = $API->get('Form'); $message = false; if (!$CurrentUser->has_priv('perch_blog.sections.manage')) { PerchUtil::redirect($API->app_path()); } $Blogs = new PerchBlog_Blogs($API); $blogs = $Blogs->all(); if (isset($_GET['id']) && $_GET['id'] != '') { $sectionID = (int) $_GET['id']; $Section = $Sections->find($sectionID); $details = $Section->to_array(); } else { $sectionID = false; $Section = false; $details = array(); } $Blog = false; if (PERCH_RUNWAY) { if ($Section) { $Blog = $Blogs->find((int) $Section->blogID()); } else { if (PerchUtil::get('blog')) { $Blog = $Blogs->find((int) PerchUtil::get('blog')); } } } if (!$Blog) {