Example #1
0
 public function getPages($query = null)
 {
     $b = Block::getByID($this->bID);
     $exclude_list = array('tags', 'categories', 'tag_cloud', 'archive');
     $template = strtolower($b->getBlockFilename());
     if (!in_array($template, $exclude_list)) {
         $pl = new ProblogList();
         $db = Loader::db();
         $bID = $this->bID;
         if ($this->bID) {
             $q = "select * from btProBlogList where bID = '{$bID}'";
             $r = $db->query($q);
             if ($r) {
                 $row = $r->fetchRow();
             }
         } else {
             $row['num'] = $this->num;
             $row['cParentID'] = $this->cParentID;
             $row['cThis'] = $this->cThis;
             $row['orderBy'] = $this->orderBy;
             $row['ctID'] = $this->ctID;
             $row['rss'] = $this->rss;
             $row['category'] = $this->category;
             $row['title'] = $this->title;
             $row['paginate'] = $this->paginate;
             $row['displayAliases'] = $this->displayAliases;
             $row['subscribe'] = $this->subscribe;
             $row['rssTitle'] = $this->rssTitle;
             $row['rssDescription'] = $this->rssDescription;
             $row['truncateSummaries'] = $this->truncateSummaries;
             $row['truncateChars'] = $this->truncateChars;
             $row['use_content'] = $this->use_content;
             $row['author'] = $this->author;
         }
         $cArray = array();
         switch ($row['orderBy']) {
             case 'display_asc':
                 $pl->sortByDisplayOrder();
                 break;
             case 'display_desc':
                 $pl->sortByDisplayOrderDescending();
                 break;
             case 'chrono_asc':
                 $pl->sortByPublicDateTime();
                 break;
             case 'alpha_asc':
                 $pl->sortByName();
                 break;
             case 'alpha_desc':
                 $pl->sortByNameDescending();
                 break;
             default:
                 $pl->sortByPublicDateDescending();
                 break;
         }
         $num = (int) $row['num'];
         if ($num > 0) {
             $pl->setItemsPerPage($num);
         }
         $c = Page::getCurrentPage();
         if (is_object($c)) {
             $this->cID = $c->getCollectionID();
         }
         $cParentID = $row['cThis'] ? $this->cID : $row['cParentID'];
         //$pl->filter(false,"(CHAR_LENGTH(cv.cvName) > 4 OR cv.cvName NOT REGEXP '^[0-9]')");
         $pl->filter(false, "ak_is_canonical_page < 1");
         $pl->filterByPublicDate(date('Y-m-d H:i:s'), '<=');
         //filter by publish date
         Loader::model('attribute/categories/collection');
         if ($this->displayFeaturedOnly == 1) {
             $cak = CollectionAttributeKey::getByHandle('is_featured');
             if (is_object($cak)) {
                 $pl->filterByIsFeatured(1);
             }
         }
         if (!$row['displayAliases']) {
             $pl->filterByIsAlias(0);
         }
         $pl->filter('cvName', '', '!=');
         if ($row['ctID']) {
             $ctID = $row['ctID'];
             $pl->filter(false, "p.ptID = {$ctID}");
         }
         $columns = $db->MetaColumns(CollectionAttributeKey::getIndexedSearchTable());
         if (isset($columns['AK_EXCLUDE_PAGE_LIST'])) {
             $pl->filter(false, '(ak_exclude_page_list = 0 or ak_exclude_page_list is null)');
         }
         if (intval($cParentID) != 0) {
             $path = Page::getByID($cParentID)->getCollectionPath();
             $pl->filterByPath($path);
         }
         if ($row['author']) {
             $pl->filterByBlogAuthor($row['author']);
         }
         if ($this->category != t('All Categories')) {
             $selected_cat = explode(', ', $this->category);
             if ($this->filter_strict > 0) {
                 $condition = ' AND ';
             } else {
                 $condition = ' OR ';
             }
             foreach ($selected_cat as $cat) {
                 $cat = str_replace("'", "\\'", $cat);
                 if ($fi) {
                     $category_filter .= $condition;
                 }
                 $category_filter .= "ak_blog_category LIKE '%\n{$cat}\n%'";
                 $fi++;
             }
             $pl->filter(false, "(" . $category_filter . ")");
         }
         //$pl->debug();
         //Pagination...
         $showPagination = false;
         if ($this->paginate > 0) {
             $pagination = $pl->getPagination();
             $pages = $pagination->getCurrentPageResults();
             if ($pagination->getTotalPages() > 1 && $this->paginate) {
                 $showPagination = true;
                 $pagination = $pagination->renderDefaultView();
                 $this->set('pagination', $pagination);
             }
         } else {
             $pages = $pl->getResults();
         }
         if ($showPagination) {
             $this->requireAsset('css', 'core/frontend/pagination');
         }
         $this->set('pl', $pl);
     }
     return $pages;
 }