public function executeDefault() { $this->setView('Post/default'); $pageSize = 20; $taxonomy = $this->request()->get('taxonomy', 'STRING', 'post'); $page_title = Plugin::getTaxonomyOption($taxonomy, 'post', 'label', t('Post Management')); if ($this->request()->isPostRequest()) { $ordering = $this->request()->post('ordering', 'ARRAY', array()); foreach ($ordering as $id => $value) { $_p = \Posts::retrieveById($id); if ($_p) { $_p->setOrdering($value); $_p->save(); } } } $this->document()->title .= $page_title; $filter = $this->request()->get('filter', 'ARRAY', array()); $query = \Posts::select()->where('`taxonomy`=:taxonomy')->andWhere('`is_draft` = :is_draft')->setParameter(':is_draft', false, \PDO::PARAM_INT)->setParameter(':taxonomy', $taxonomy, \PDO::PARAM_STR); if (isset($filter['keyword']) && !empty($filter['keyword'])) { $query->andWhere('`title` LIKE "%' . $filter['keyword'] . '%"'); } if (isset($filter['status']) && '' != $filter['status'] && 'All' != $filter['status']) { $query->andWhere('`status` = "' . $filter['status'] . '"'); } if (isset($filter['language']) && '*' != $filter['language']) { $query->andWhere('`language` = "' . $filter['language'] . '"'); } if (isset($filter['cat_id']) && $filter['cat_id'] != 0) { $cat = \Terms::retrieveById($filter['cat_id']); $_c = array(); if ($cat) { $branches = $cat->getBranch(); foreach ($branches as $branch) { $_c[] = $branch->getId(); } $query->andWhere('`term_id` IN (' . implode(',', $_c) . ')'); } } $countQuery = clone $query; $total = $countQuery->count()->execute(); $orderBy = Plugin::applyFilters('default_' . $taxonomy . '_ordering', array('id', 'DESC')); //paging $page = $this->request()->get('page', 'INIT', 1); $query->setMaxResults($pageSize)->setFirstResult(($page - 1) * $pageSize)->orderBy($orderBy[0], $orderBy[1]); $list = $query->execute(); $taxonomy_term = Plugin::getTaxonomyOption($taxonomy, 'post', 'term_taxonomy', 'category'); $table = new PostList($taxonomy); $table->setItems($list); $this->view()->assign(array('page_title' => $page_title, 'taxonomy' => $taxonomy, 'taxonomy_term' => $taxonomy_term, 'table' => $table, 'list' => $list, 'filter' => $filter, 'total' => $total, 'page_size' => $pageSize)); return $this->renderComponent(); }
public function executeDefault() { if (!($cat = \Terms::retrieveById($this->request()->get('id')))) { $this->raise404(); } $viewProp = $cat->getProperty('cat_view'); if ($viewProp) { $this->setView('Category/' . $viewProp->getPropertyValue()); } else { $this->setView('Category/default'); } $child = $cat->getDescendants(); $q = \Posts::select()->where('`status` = :status AND `is_draft` = 0')->setParameter(':status', 'PUBLISH', \PDO::PARAM_STR); //Filter $catId = array($cat->getId()); foreach ($child as $c) { $catId[] = $c->getId(); } $q->andWhere('`term_id` IN (' . implode(',', $catId) . ')'); //Filter by time $day = $this->request()->get('day'); $month = $this->request()->get('month'); $year = $this->request()->get('year'); if ($day || $month || $year) { if ($day) { $q->andWhere('DAY(`created_time`) = :day')->setParameter(':day', $day, \PDO::PARAM_STR); } if ($month) { $q->andWhere('MONTH(`created_time`) = :month')->setParameter(':month', $month, \PDO::PARAM_STR); } if ($year) { $q->andWhere('YEAR(`created_time`) = :year')->setParameter(':year', $year, \PDO::PARAM_STR); } } //Keyword if ($keyword = $this->request()->get('keyword')) { $q->andWhere('`title` LIKE "%' . $keyword . '%"'); } //Ordering $orderingProp = $cat->getProperty('post_ordering'); if ($orderingProp) { switch ($orderingProp->getPropertyValue()) { case 'created_time': $q->addOrderBy('created_time'); break; case 'ordering': $q->addOrderBy('ordering'); break; case 'modified_time': case 'default': default: $q->addOrderBy('created_time', 'DESC'); break; } } else { $q->addOrderBy('created_time', 'DESC'); } $qCount = clone $q; $total = $qCount->count()->execute(); //Paging $pageSizeProp = $cat->getProperty('page_size'); if ($pageSizeProp) { $page_size = $cat->getProperty('page_size')->getPropertyValue(); if (-1 != $pageSizeProp->getPropertyValue()) { $q->setMaxResults($pageSizeProp->getPropertyValue()); $page = $this->request()->get('page', 'INT', 1); $q->setFirstResult(($page - 1) * $pageSizeProp->getPropertyValue()); } } else { $page_size = 25; $q->setMaxResults(25); $page = $this->request()->get('page', 'INT', 1); $q->setFirstResult(($page - 1) * $page_size); } $posts = $q->execute(); $this->view()->assign(array('page_size' => $page_size, 'total' => $total, 'cat' => $cat, 'child' => $child, 'posts' => $posts)); return $this->renderComponent(); }
/** * @todo Remove when done */ public function fixAction() { $posts = new Posts(); $tposts = $posts->fetchAll($posts->select()->where('id > 0')); $defaultFilterChain = new Zend_Filter(); $defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean()); $defaultFilterChain->addFilter(new Zend_Filter_StringTrim()); $defaultFilterChain->addFilter(new Zend_Filter_StripTags()); $defaultFilterChain->addFilter(new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES, 'charset' => 'UTF-8'))); $defaultFilterChain->addFilter(new Ifphp_Filter_HtmlEntityNames()); foreach ($tposts as $post) { $post->title = $defaultFilterChain->filter($post->title); $post->description = $defaultFilterChain->filter($post->description); $post->feedId = $defaultFilterChain->filter($post->feedId); $post->link = $defaultFilterChain->filter($post->link); $post->publishDate = $post->publishDate; // Zend_Debug::dump($post->description); $post->save(); } $feeds = new Feeds(); $tfeeds = $feeds->fetchAll($feeds->select()->where('id > 0')); $inflector = new Zend_Filter_Inflector(':title'); $inflector->setRules(array(':title' => array('Word_SeparatorToDash', 'StringToLower', 'HtmlEntities'))); foreach ($tfeeds as $feed) { $feed->title = $defaultFilterChain->filter($feed->title); $feed->description = $defaultFilterChain->filter($feed->description); $feed->slug = $inflector->filter(array('title' => $feed->title)); $feed->save(); } die; }