コード例 #1
0
ファイル: PostController.php プロジェクト: skybird/phalcon
 public function relatedPostsByTextAction()
 {
     $text = $this->dispatcher->getParam('text');
     $limit = $this->dispatcher->getParam('limit', 'int', 5);
     $days = $this->dispatcher->getParam('days', 'int', 30);
     $postSearcher = new Models\PostSearcher();
     return $postSearcher->getRelatedPostsByText($text, $limit, $days);
 }
コード例 #2
0
ファイル: SearchController.php プロジェクト: skybird/phalcon
 public function indexAction()
 {
     $keyword = trim($this->request->getQuery("q"));
     $postSearcher = new PostSearcher();
     $pager = $postSearcher->searchPosts(array('q' => $keyword, 'highlight' => true, 'order' => '-created_at', 'status' => 'published'));
     $this->view->setVar('pager', $pager);
     $this->view->setVar('keyword', $keyword);
     $tag = new Tag();
     $tags = $tag->getPopularTags(6);
     $this->view->setVar('tags', $tags);
 }
コード例 #3
0
ファイル: NodeController.php プロジェクト: skybird/phalcon
 public function nodeAction()
 {
     $id = $this->dispatcher->getParam('id');
     if (is_numeric($id)) {
         $post = PostSearcher::findFirst($id);
     } else {
         $post = PostSearcher::findFirstBySlug($id);
     }
     if (!$post || $post->status != 'published') {
         throw new Exception\ResourceNotFoundException('Request post not found');
     }
     if ($this->getDI()->getModuleManager()->hasModule('Wiki')) {
         $post->text->content = WikiUtil::highlight($post->text->content);
     }
     $posts = null;
     //        if ($post->connections->count() < 1 && $post->tags->count() > 0) {
     //            $tag = new Tag();
     //            $post->connections = $tag->getRelatedPosts($post->id, 3);
     //        }
     $this->view->setVar('relatedPosts', $post->getRelatedPosts($post->id));
     $appKeys4share = array();
     $oauthConfigs = $this->getDI()->getConfig()->oauth->toArray();
     // 支持以下自定义:
     //  "tsina":"sinaweibo",
     //  "tqq":"tencentweibo",
     //  "t163":"netease",
     //  "tsouhu":"sohuweibo",
     //  "tpeople":"renminwang"
     if (isset($oauthConfigs['oauth2']['weibo'])) {
         $appKeys4share['tsina'] = '4ildYm';
     }
     if (isset($oauthConfigs['oauth2']['tencent'])) {
         $appKeys4share['tqq'] = $oauthConfigs['oauth2']['tencent']['consumer_key'];
     }
     if (isset($oauthConfigs['oauth1']['sohu'])) {
         $appKeys4share['tsouhu'] = $oauthConfigs['oauth1']['sohu']['consumer_key'];
     }
     $this->view->setVar('appKeys4share', $appKeys4share);
     $this->view->setVar('post', $post);
 }
コード例 #4
0
ファイル: PostsController.php プロジェクト: skybird/phalcon
 /**
  *
  * @SWG\Api(
  *   path="/posts/search",
  *   description="Posts related API",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="GET",
  *       summary="Search posts",
  *       notes="Returns post list",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="q",
  *           description="Keyword",
  *           paramType="query",
  *           required=false,
  *           type="string"
  *         ),
  *         @SWG\Parameter(
  *           name="uid",
  *           description="User ID",
  *           paramType="query",
  *           required=false,
  *           type="integer"
  *         ),
  *         @SWG\Parameter(
  *           name="cid",
  *           description="Category ID",
  *           paramType="query",
  *           required=false,
  *           type="integer"
  *         ),
  *         @SWG\Parameter(
  *           name="tid",
  *           description="Tag ID",
  *           paramType="query",
  *           required=false,
  *           type="integer"
  *         ),
  *         @SWG\Parameter(
  *           name="order",
  *           description="Order, allow value : +-id, +-created_at, +-sortOrder default is -created_at",
  *           paramType="query",
  *           required=false,
  *           type="string"
  *         ),
  *         @SWG\Parameter(
  *           name="limit",
  *           description="Limit max:100 | min:3; default is 25",
  *           paramType="query",
  *           required=false,
  *           type="integer"
  *         )
  *       )
  *     )
  *   )
  * )
  */
 public function searchAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ? 100 : $limit;
     $limit = $limit < 3 ? 3 : $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => 'published', 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'tid' => $this->request->getQuery('tid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     $postSearcher = new Models\PostSearcher();
     $pager = $postSearcher->searchPosts($query);
     $data = array('paginator' => $this->getApiPaginatorFromPure($pager), 'results' => $pager->items);
     return $this->response->setJsonContent($data);
 }