public function indexAction() { $request = $this->getRequest(); $q = trim($request->getQuery('q')); $search = array('performed' => false, 'limit' => 5, 'total' => 0, 'start' => 0, 'finish' => 0, 'page' => (int) $request->getQuery('p'), 'pages' => 1, 'result' => array()); try { if (strlen($q) == 0) { throw new Exception('No search term specified'); } $path = DatabaseObject_BlogPost::getIndexFullpath(); $index = Zend_Search_Lucene::open($path); $hits = $index->find($q); $search['performed'] = true; $search['total'] = count($hits); $search['pages'] = ceil($search['total'] / $search['limit']); $search['page'] = max(1, min($search['pages'], $search['page'])); $offset = ($search['page'] - 1) * $search['limit']; $search['start'] = $offset + 1; $search['finish'] = min($search['total'], $search['start'] + $search['limit'] - 1); $hits = array_slice($hits, $offset, $search['limit']); $post_ids = array(); foreach ($hits as $hit) { $post_ids[] = (int) $hit->post_id; } $options = array('status' => DatabaseObject_BlogPost::STATUS_LIVE, 'post_id' => $post_ids); $posts = DatabaseObject_BlogPost::GetPosts($this->db, $options); foreach ($post_ids as $post_id) { if (array_key_exists($post_id, $posts)) { $search['results'][$post_id] = $posts[$post_id]; } } $user_ids = array(); foreach ($posts as $post) { $user_ids[$post->user_id] = $post->user_id; } if (count($user_ids) > 0) { $options = array('user_id' => $user_ids); $users = DatabaseObject_User::GetUsers($this->db, $options); } else { $users = array(); } } catch (Exception $ex) { $users = array(); } if ($search['performed']) { $this->breadcrumbs->addStep('Search Results for ' . $q); } else { $this->breadcrumbs->addStep('Search'); } $this->view->q = $q; $this->view->search = $search; $this->view->users = $users; }
public function indexAction() { $month = $this->getRequest()->getQuery('month'); if (preg_match('/^(\\d{4})-(\\d{2})$/', $month, $matches)) { $y = $matches[1]; $m = max(1, min(12, $matches[2])); } else { $y = date('Y'); $m = date('n'); } $from = mktime(0, 0, 0, $m, 1, $y); $to = mktime(0, 0, 0, $m + 1, 1, $y) - 1; $options = array('user_id' => $this->identity->user_id, 'from' => date('Y-m-d H:i:s', $from), 'to' => date('Y-m-d H:i:s', $to), 'order' => 'p.ts_created desc'); $recentPosts = DatabaseObject_BlogPost::GetPosts($this->db, $options); $totalPosts = DatabaseObject_BlogPost::GetPostsCount($this->db, array('user_id' => $this->identity->user_id)); $this->view->month = $from; $this->view->recentPosts = $recentPosts; $this->view->totalPosts = $totalPosts; }
public function feedAction() { $options = array('user_id' => $this->user->getId(), 'status' => DatabaseObject_BlogPost::STATUS_LIVE, 'limit' => 10, 'order' => 'p.ts_created desc'); $recentPosts = DatabaseObject_BlogPost::GetPosts($this->db, $options); $domain = 'http://' . $this->getRequest()->getServer('HTTP_HOST'); $url = $this->getCustomUrl(array('username' => $this->user->username, 'action' => 'index'), 'user'); $feedData = array('title' => sprintf("%s's Blog", $this->user->username), 'link' => $domain . $url, 'charset' => 'UTF-8', 'entries' => array()); foreach ($recentPosts as $post) { $url = $this->getCustomUrl(array('username' => $this->user->username, 'url' => $post->url), 'post'); $entry = array('title' => $post->profile->title, 'link' => $domain . $url, 'description' => $post->getTeaser(200), 'lastUpdate' => $post->ts_created, 'category' => array()); foreach ($post->getTags() as $tag) { $entry['category'][] = array('term' => $tag); } $feedData['entries'][] = $entry; } $feed = Zend_Feed::importArray($feedData, 'atom'); $this->_helper->viewRenderer->setNoRender(); $feed->send(); }