/** * Action - feed * actions with news user tape * you can get all the news * and the user can receive news only on a separate tag * * Access to the action is possible in the following paths: * router pattern - user/all/feed/:tag/* or controller/:action/* * * - /user/all/feed/reports * or * - /index/feed * * @return void */ public function feedAction() { //Получим параметр метки $tag = trim($this->_request->getUserParam('tag')); // first retrieve all recent posts $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'limit' => 10, 'order' => 'p.ts_created desc', 'public_only' => true); if ($tag) { $options['tag'] = $tag; } $recentPosts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options); // base URL for generated links if ($this->getRequest()->getServer('HTTPS') == 'on') { $domain = 'https://'; } else { $domain = 'http://'; } $domain .= $this->getRequest()->getServer('HTTP_HOST'); // url for web feed if ($tag) { $url = $this->getCustomUrl(array('tag' => $tag), 'feed_tag_all'); } else { $url = $this->getUrl('feed'); } $feedData = array('link' => $domain . $url, 'charset' => 'UTF-8', 'entries' => array()); if ($tag) { $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag); $title = $this->Translate('Сообщения авторов') . ' ' . $this->Translate('для метки') . ' - ' . $tagLabel; } else { $title = $this->Translate('Сообщения всех авторов'); } $feedData['title'] = $title; // determine which users' posts were retrieved $user_ids = array(); foreach ($recentPosts as $post) { $user_ids[$post->user_id] = $post->user_id; } // load the user records if (count($user_ids) > 0) { $options = array('user_id' => $user_ids); $users = Default_Model_DbTable_User::GetUsers($this->db, $options); } else { $users = array(); } // build feed entries based on returned posts foreach ($recentPosts as $post) { $user = $users[$post->user_id]; $url = $this->getCustomUrl(array('username' => $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()); // attach tags to each entry foreach ($post->getTags() as $tag) { $entry['category'][] = array('term' => $tag); } $feedData['entries'][] = $entry; } // create feed based on created data $feed = Zend_Feed::importArray($feedData, 'atom'); // disable auto-rendering since we're outputting an image $this->_helper->viewRenderer->setNoRender(); // output the feed to the browser $feed->send(); }
/** * Load row table * * @param array $row * @param int $id * * @return bool */ public function loadRowTable($row, $id) { $result = parent::loadRowTable($row, $id); if ($result) { // Загрузим все записи пользователя $options = array('user_id' => array($id)); $row->posts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options); } return $result; }
/** * Action - rebuild * rebuild the search index * * Access to the action is possible in the following paths: * - /search/rebuild * @return void */ public function rebuildAction() { $result = TRUE; $err_msg = ''; $json = array(); //------------------- try { // Задержка условная sleep(3); $indexFullpath = Default_Model_DbTable_BlogPost::getIndexFullpath(); if (is_dir($indexFullpath)) { // Получим обьект построения дерева файлов $ft = new Default_Plugin_FileTree($indexFullpath); // создадим дерево файлов $ft->readTree(); // удалим файлы и директории $result = $ft->delFiles(); if ($result) { // удалим пустую директорию $result = rmdir($indexFullpath); } } $index = Zend_Search_Lucene::create($indexFullpath); $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE); $posts = Default_Model_DbTable_BlogPost::GetPosts(Zend_Registry::get('db'), $options); foreach ($posts as $post) { $index->addDocument($post->getIndexableDocument()); } $index->commit(); $message = array('<em>' . $this->Translate("Восстановление поискового индекса") . '!</em>', $this->Translate("Восстановление поискового индекса завершилось успешно") . '.'); if ($this->_isAjaxRequest) { $json['class_message'] = 'information'; $json['messages'] = $message; $json['$result'] = $result; } } catch (Exception $ex) { $err_msg = $ex->getMessage(); $message = array('<em>' . $this->Translate("Ошибка восстановления поискового индекса") . '!</em>', $err_msg); if ($this->_isAjaxRequest) { $json['class_message'] = 'warning'; $json['messages'] = $message; $json['$result'] = $result; } else { $logger = Zend_Registry::get('Zend_Log'); $logger->warn('Error rebuilding search index: ' . $ex->getMessage()); $result = FALSE; } } if ($this->_isAjaxRequest) { $this->sendJson($json); } else { $this->view->result = $result; if ($result) { $this->view->class_message = 'information'; } else { $this->view->err_msg = $err_msg; $this->view->class_message = 'warning'; } $this->view->message = $message; $this->_breadcrumbs->addStep($this->Translate('Восстановление поискового индекса')); } }
/** * Action - images * obtain images via ajax request * * Access to the action is possible in the following paths: * router pattern - user/:username/post/:post_id/images/* * * - /user/user1/post/27/images * * @return void */ public function imagesAction() { if ($this->_isAjaxRequest) { $jsons = array(); try { $request = $this->getRequest(); $username = trim($request->getUserParam('username')); $post_id = (int) $request->getUserParam('post_id'); $params = $request->getParams(); $_from = (int) $params['from']; $_to = (int) $params['to']; // Получим сообщение $posts = Default_Model_DbTable_BlogPost::GetPosts($this->db, array('post_id' => array($post_id))); if ($posts) { $images = $posts[$post_id]->images; $images = array_values($images); $indexMax = count($images) - 1; // Создадим обьект шаблона $templater = Default_Plugin_SysBox::createViewSmarty(); //Установим параметры шаблона $templater->images = $images; $templater->username = $username; $templater->_from = $_from; $templater->_to = $_to; // Получим результат шаблона $html = $templater->render('user/images.tpl'); $jsons['html'] = $html; $more = $indexMax > $_to; $jsons['more'] = $more; if ($_to > $indexMax) { $_to = $indexMax; } $jsons['to'] = $_to; $jsons['from'] = $_from; } $this->sendJson($jsons); } catch (Exception $exc) { $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка получения изображений') . '</em>', Default_Plugin_SysBox::getMessageError($exc))); $this->sendJson($jsons); return; } } }