コード例 #1
0
    /**
     *
     * 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())
    {
        $blogSQL = false;
        // SQL for refining by blog
        if (isset($opts['blog']) && PERCH_RUNWAY) {
            $Blogs = new PerchBlog_Blogs($this->api);
            $Blog = $Blogs->get_one_by('blogSlug', $opts['blog']);
            if ($Blog) {
                $blogSQL = ' AND p.blogID=' . $this->db->pdb((int) $Blog->id()) . ' ';
            }
        }
        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()) . $blogSQL . '
                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')) . $blogSQL . '
                GROUP BY t.tagID
                ORDER BY t.tagTitle ASC';
        }
        $rows = $this->db->get_rows($sql);
        $r = $this->return_instances($rows);
        return $r;
    }
コード例 #2
0
<?php

if (!PERCH_RUNWAY) {
    exit;
}
$Blogs = new PerchBlog_Blogs($API);
$CategorySets = new PerchCategories_Sets($API);
$category_sets = $CategorySets->all();
$HTML = $API->get('HTML');
$Form = $API->get('Form');
$message = false;
if (!$CurrentUser->has_priv('perch_blog.blogs.manage')) {
    PerchUtil::redirect($API->app_path());
}
if (isset($_GET['id']) && $_GET['id'] != '') {
    $blogID = (int) $_GET['id'];
    $Blog = $Blogs->find($blogID);
    $details = $Blog->to_array();
} else {
    $blogID = false;
    $Blog = false;
    $details = array();
}
$Template = $API->get('Template');
$Template->set('blog/blog.html', 'blog');
$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');
コード例 #3
0
 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;
 }
コード例 #4
0
<?php

$Blogs = new PerchBlog_Blogs($API);
$Posts = new PerchBlog_Posts($API);
$message = false;
$Authors = new PerchBlog_Authors();
$Author = $Authors->find_or_create($CurrentUser);
$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 = $Posts->find($postID, true);
    $details = $Post->to_array();
    $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();
コード例 #5
0
 public function get_custom($opts)
 {
     $API = new PerchAPI(1.0, 'perch_blog');
     $blogSQL = '';
     if ($opts['blog']) {
         $BlogPosts = new PerchBlog_Posts($API);
         $Blogs = new PerchBlog_Blogs($API);
         $Blog = $Blogs->get_one_by('blogSlug', $opts['blog']);
         if ($Blog) {
             $blogID = (int) $Blog->id();
             $blogSQL = ' AND blogID=' . $this->db->pdb($blogID) . ' ';
         }
     }
     if ($opts['include-empty']) {
         $sql = 'SELECT *, sectionID AS _id, sectionPostCount as qty FROM ' . $this->table . ' WHERE 1=1 ' . $blogSQL . ' ORDER BY sectionTitle ASC';
     } else {
         $sql = 'SELECT *, sectionID AS _id, sectionPostCount as qty FROM ' . $this->table . ' WHERE sectionPostCount>0 ' . $blogSQL . ' ORDER BY sectionTitle ASC';
     }
     $rows = $this->db->get_rows($sql);
     $sections = $this->return_instances($rows);
     $content = array();
     if (PerchUtil::count($sections)) {
         foreach ($sections as $Section) {
             $content[] = $Section->to_array();
         }
     }
     if (isset($opts['filter']) && (isset($opts['value']) || is_array($opts['filter']))) {
         if (PerchUtil::count($content)) {
             $out = array();
             // if it's not a multi-filter, make it look like one to unify what we're working with
             if (!is_array($opts['filter']) && isset($opts['value'])) {
                 $filters = array(array('filter' => $opts['filter'], 'value' => $opts['value'], 'match' => isset($opts['match']) ? $opts['match'] : 'eq'));
                 $filter_mode = 'AND';
             } else {
                 $filters = $opts['filter'];
                 $filter_mode = 'AND';
                 if (isset($opts['match']) && strtolower($opts['match']) == 'or') {
                     $filter_mode = 'OR';
                 }
             }
             $filter_content = $content;
             foreach ($filters as $filter) {
                 $key = $filter['filter'];
                 $val = $filter['value'];
                 $match = isset($filter['match']) ? $filter['match'] : 'eq';
                 foreach ($filter_content as $item) {
                     // If 'AND' mode, remove the item, as we only want it if it's added by this filter too.
                     // ninja code.
                     if ($filter_mode == 'AND' && isset($out[$item['_id']])) {
                         unset($out[$item['_id']]);
                     }
                     if (!isset($item[$key])) {
                         $item[$key] = false;
                     }
                     if (isset($item[$key])) {
                         $this_item = $this->_resolve_to_value($item[$key]);
                         switch ($match) {
                             case 'eq':
                             case 'is':
                             case 'exact':
                                 if ($this_item == $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'neq':
                             case 'ne':
                             case 'not':
                                 if ($this_item != $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'gt':
                                 if ($this_item > $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'gte':
                                 if ($this_item >= $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'lt':
                                 if ($this_item < $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'lte':
                                 if ($this_item <= $val) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'contains':
                                 $value = str_replace('/', '\\/', $val);
                                 if (preg_match('/\\b' . $value . '\\b/i', $this_item)) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'regex':
                             case 'regexp':
                                 if (preg_match($val, $this_item)) {
                                     $out[$item['_id']] = $item;
                                 }
                                 break;
                             case 'between':
                             case 'betwixt':
                                 $vals = explode(',', $val);
                                 if (PerchUtil::count($vals) == 2) {
                                     if ($this_item > trim($vals[0]) && $this_item < trim($vals[1])) {
                                         $out[$item['_id']] = $item;
                                     }
                                 }
                                 break;
                             case 'eqbetween':
                             case 'eqbetwixt':
                                 $vals = explode(',', $val);
                                 if (PerchUtil::count($vals) == 2) {
                                     if ($this_item >= trim($vals[0]) && $this_item <= trim($vals[1])) {
                                         $out[$item['_id']] = $item;
                                     }
                                 }
                                 break;
                             case 'in':
                             case 'within':
                                 $vals = explode(',', $val);
                                 if (PerchUtil::count($vals)) {
                                     foreach ($vals as $value) {
                                         if ($this_item == trim($value)) {
                                             $out[$item['_id']] = $item;
                                             break;
                                         }
                                     }
                                 }
                                 break;
                         }
                     }
                 }
                 // if 'AND' mode, run the next filter against the already filtered list
                 if ($filter_mode == 'AND') {
                     $filter_content = $out;
                 } else {
                     $filter_content = $content;
                 }
             }
             $content = $out;
         }
     }
     // reindex array
     $new_content = array();
     foreach ($content as $c) {
         $new_content[] = $c;
     }
     $content = $new_content;
     // sort
     if (isset($opts['sort'])) {
         if (isset($opts['sort-order']) && $opts['sort-order'] == 'DESC') {
             $desc = true;
         } else {
             $desc = false;
         }
         $content = PerchUtil::array_sort($content, $opts['sort'], $desc);
     }
     if (isset($opts['sort-order']) && $opts['sort-order'] == 'RAND') {
         shuffle($content);
     }
     // Pagination
     if (isset($opts['paginate'])) {
         $Paging = $API->get('Paging');
         if (isset($opts['pagination-var'])) {
             $Paging->set_qs_param($opts['pagination-var']);
         }
         $Paging->set_per_page(isset($opts['count']) ? (int) $opts['count'] : 10);
         $opts['count'] = $Paging->per_page();
         $opts['start'] = $Paging->lower_bound() + 1;
         $Paging->set_total(PerchUtil::count($content));
     } else {
         $Paging = false;
     }
     // limit
     if (isset($opts['count']) || isset($opts['start'])) {
         // count
         if (isset($opts['count'])) {
             $count = (int) $opts['count'];
         } else {
             $count = PerchUtil::count($content);
         }
         // start
         if (isset($opts['start'])) {
             if ($opts['start'] === 'RAND') {
                 $start = rand(0, PerchUtil::count($content) - 1);
             } else {
                 $start = (int) $opts['start'] - 1;
             }
         } else {
             $start = 0;
         }
         // loop through
         $out = array();
         for ($i = $start; $i < $start + $count; $i++) {
             if (isset($content[$i])) {
                 $out[] = $content[$i];
             } else {
                 break;
             }
         }
         $content = $out;
     }
     if (isset($opts['skip-template']) && $opts['skip-template'] == true) {
         if (isset($opts['raw']) && $opts['raw'] == true) {
             if (PerchUtil::count($content)) {
                 foreach ($content as &$item) {
                     if (PerchUtil::count($item)) {
                         foreach ($item as &$field) {
                             if (is_array($field) && isset($field['raw'])) {
                                 $field = $field['raw'];
                             }
                         }
                     }
                 }
             }
             return $content;
         }
     }
     // template
     $Template = $API->get('Template');
     $Template->set('blog/' . $opts['template'], 'blog');
     // post process
     $tags = $Template->find_all_tags_and_repeaters('blog');
     $processed_vars = array();
     $used_items = array();
     foreach ($content as $item) {
         $tmp = $item;
         if (PerchUtil::count($tags)) {
             foreach ($tags as $Tag) {
                 if (isset($item[$Tag->id()])) {
                     $used_items[] = $item;
                 }
             }
         }
         if ($tmp) {
             $processed_vars[] = $tmp;
         }
     }
     // Paging to template
     if (is_object($Paging) && $Paging->enabled()) {
         $paging_array = $Paging->to_array($opts);
         // merge in paging vars
         foreach ($processed_vars as &$item) {
             foreach ($paging_array as $key => $val) {
                 $item[$key] = $val;
             }
         }
     }
     if (PerchUtil::count($processed_vars)) {
         $html = $Template->render_group($processed_vars, true);
     } else {
         $Template->use_noresults();
         $html = $Template->render(array());
     }
     if (isset($opts['skip-template']) && $opts['skip-template'] == true) {
         $out = array();
         if (PerchUtil::count($processed_vars)) {
             foreach ($processed_vars as &$item) {
                 if (PerchUtil::count($item)) {
                     foreach ($item as &$field) {
                         if (is_array($field) && isset($field['processed'])) {
                             $field = $field['processed'];
                         }
                         if (is_array($field) && isset($field['_default'])) {
                             $field = $field['_default'];
                         }
                     }
                 }
             }
         }
         for ($i = 0; $i < PerchUtil::count($content); $i++) {
             $out[] = array_merge($content[$i], $processed_vars[$i]);
         }
         if (isset($opts['return-html']) && $opts['return-html'] == true) {
             $out['html'] = $html;
         }
         return $out;
     }
     return $html;
 }
コード例 #6
0
<?php

if (!PERCH_RUNWAY) {
    exit;
}
$Blogs = new PerchBlog_Blogs($API);
$HTML = $API->get('HTML');
if (!$CurrentUser->has_priv('perch_blog.blogs.manage')) {
    PerchUtil::redirect($API->app_path());
}
$blogs = $Blogs->all();
コード例 #7
0
ファイル: runtime.php プロジェクト: jimcurran/bdmusichub
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;
}
コード例 #8
0
ファイル: list.pre.php プロジェクト: jimcurran/bdmusichub
<?php

$HTML = $API->get('HTML');
// Try to update
$Settings = $API->get('Settings');
if ($Settings->get('perch_blog_update')->val() != '5.0.1') {
    PerchUtil::redirect($API->app_path() . '/update/');
}
$Posts = new PerchBlog_Posts($API);
$Blogs = new PerchBlog_Blogs($API);
$blogs = $Blogs->all();
if (!PerchUtil::count($blogs)) {
    $Posts->attempt_install();
    $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');
コード例 #9
0
<?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) {
コード例 #10
0
<?php

if (!PERCH_RUNWAY) {
    exit;
}
$Blogs = new PerchBlog_Blogs($API);
$HTML = $API->get('HTML');
$Form = $API->get('Form');
$Form->set_name('delete');
if (!$CurrentUser->has_priv('perch_blog.blogs.manage')) {
    PerchUtil::redirect($API->app_path());
}
$message = false;
if (isset($_GET['id']) && $_GET['id'] != '') {
    $Blog = $Blogs->find($_GET['id']);
} else {
    PerchUtil::redirect($API->app_path());
}
if ($Form->submitted()) {
    if (is_object($Blog)) {
        $Blog->delete();
        // clear the caches
        PerchBlog_Cache::expire_all();
        if ($Form->submitted_via_ajax) {
            echo $API->app_path() . '/blogs/';
            exit;
        } else {
            PerchUtil::redirect($API->app_path() . '/blogs/');
        }
    } else {
        $message = $HTML->failure_message('Sorry, that blog could not be deleted.');