Example #1
0
 /**
  * @param User $User
  * @param int $title
  * @param int $content
  * @param array $tags
  * @return Post
  */
 public function createPost(User $User, $title, $content, array $tags = [])
 {
     $Post = new Post();
     $Post->set(Post::FIELD_USER_OWNER, $User);
     $Post->set(Post::FIELD_TITLE, $title);
     $Post->set(Post::FIELD_CONTENT, $content);
     $Post->set(Post::FIELD_TAGS, $tags);
     $Post->set(Post::FIELD_CREATE_AT, Time::getTime());
     $Post->save();
     $FeedProvider = $this->getFeedProvider();
     $FeedProvider->getFeed(FeedType::MAIN)->savePost($Post);
     $FeedProvider->getFeed(FeedType::USER)->savePost($Post);
     $FeedProvider->getFeed(FeedType::TAG)->savePost($Post);
     return $Post;
 }
Example #2
0
         $feedType = $feedExplode[0];
         $feedName = $feedExplode[1];
     }
     $Feed = Kernel::getInstance()->getFeedProvider()->getFeed($feedType);
     switch ($feedType) {
         case FeedType::MAIN:
             /** @var FeedMain $Feed */
             $Posts = $Feed->getPosts(Time::getTime(), 0, 10);
             break;
         case FeedType::TAG:
             /** @var FeedTag $Feed */
             $Posts = $Feed->getPosts($feedName, Time::getTime(), 0, 10);
             break;
         case FeedType::USER:
             /** @var FeedUser $Feed */
             $Posts = $Feed->getPosts($feedName, Time::getTime(), 0, 10);
             break;
         default:
             $Posts = [];
     }
     $postsData = [];
     foreach ($Posts as $Post) {
         $postsData[] = $Post->export();
     }
     $content = json_encode($postsData);
     header('Content-Type: application/json');
     break;
 case 'post/add':
     $User = Kernel::getInstance()->getApplication()->getSessionUser();
     $PostProvider = new \Post\PostProvider();
     $Post = $PostProvider->createPost($User, $_GET['title'], $_GET['content'], array_map('trim', explode(',', $_GET['tags'])));