示例#1
0
 public function index($request)
 {
     if (Session::isActive()) {
         $data = array();
         $data['currentPageTitle'] = 'Playlists';
         $data['playlists'] = array();
         $data['channels'] = Session::get()->getOwnedChannels();
         foreach ($data['channels'] as $chan) {
             $data['playlists'][$chan->id] = Playlist::all(array('conditions' => array('channel_id = ?', $chan->id), 'order' => 'timestamp desc'));
         }
         return new ViewResponse('playlists/playlists', $data);
     } else {
         return new RedirectResponse(WEBROOT);
     }
 }
示例#2
0
 public function get($id, $request, $playlist = false)
 {
     if (!Video::exists($id)) {
         return Utils::getNotFoundResponse();
     }
     $video = Video::find($id);
     $author = UserChannel::find($video->poster_id);
     if ($request->acceptsJson()) {
         $videoData = array('id' => $video->id, 'title' => $video->title, 'author' => $video->poster_id, 'description' => $video->description, 'views' => $video->views, 'likes' => $video->likes, 'dislikes' => $video->dislikes);
         return new JsonResponse($videoData);
     }
     $data = array();
     $data['currentPageTitle'] = $video->title;
     if ($video->isSuspended()) {
         $data['author'] = $author;
         $data['video'] = $video;
         return new ViewResponse('video/suspended', $data);
     } elseif ($video->isPrivate() && (!Session::isActive() || $video->poster_id != Session::get()->getMainChannel()->id)) {
         $data['author'] = $author;
         $data['video'] = $video;
         return new ViewResponse('video/private', $data);
     }
     if ($playlist != false) {
         $videos_ids = json_decode($playlist->videos_ids);
         foreach ($videos_ids as $key => $value) {
             if ($value == $video->id) {
                 $nextKey = isset($videos_ids[$key + 1]) ? $key + 1 : 0;
                 break;
             }
         }
         $data['nextVideo'] = WEBROOT . 'playlists/' . $playlist->id . '/watch/' . $videos_ids[$nextKey];
     }
     $ext = explode('.', $video->url);
     $ext = $ext[count($ext) - 1];
     $data['playlist'] = $playlist;
     $data['video'] = $video;
     $data['ext'] = $ext;
     $data['playlists'] = array();
     $data['channels'] = Session::isActive() ? Session::get()->getOwnedChannels() : array();
     foreach ($data['channels'] as $chan) {
         $data['playlists'][$chan->id] = Playlist::all(array('conditions' => array('channel_id = ?', $chan->id), 'order' => 'timestamp desc'));
     }
     $data['title'] = $video->title;
     $data['tags'] = array();
     $tags = explode(' ', $video->tags);
     foreach ($tags as $tag) {
         $tag = trim($tag);
         $tag = str_replace(',', '', $tag);
         $tag = str_replace(';', '', $tag);
         $tag = str_replace(':', '', $tag);
         $tag = str_replace('.', '', $tag);
         $data['tags'][] = $tag;
     }
     $data['poster_id'] = $video->poster_id;
     $data['author'] = $author;
     $data['description'] = $video->description;
     $data['views'] = $video->views;
     $data['likes'] = $video->likes;
     $data['dislikes'] = $video->dislikes;
     $data['thumbnail'] = $video->getThumbnail();
     $data['subscribers'] = $author->getSubscribersNumber();
     $data['subscribed'] = Session::isActive() ? Session::get()->hasSubscribedToChannel($author->id) : false;
     $data['likedByUser'] = Session::isActive() ? $video->isLikedByUser(Session::get()->id) : false;
     $data['dislikedByUser'] = Session::isActive() ? $video->isDislikedByUser(Session::get()->id) : false;
     $data['recommendations'] = $video->getAssociatedVideos(4);
     $data['channels'] = Session::isActive() ? Session::get()->getOwnedChannels() : array();
     $data['flagged'] = $video->isFlagged();
     $data['discover'] = $video->discover;
     $data['currentPage'] = "watch";
     $video->addView();
     return new ViewResponse('video/video', $data);
 }
示例#3
0
 public function playlists($id, $request)
 {
     $channel = UserChannel::exists($id) ? UserChannel::find_by_id($id) : UserChannel::find_by_name($id);
     if (is_object($channel)) {
         $data = array();
         $data['currentPage'] = 'channel';
         $data['currentPageTitle'] = $channel->name . ' - Playlists';
         $data['current'] = 'playlists';
         $data['id'] = $channel->id;
         $data['name'] = $channel->name;
         $data['avatar'] = $channel->getAvatar();
         $data['background'] = $channel->getBackground();
         $data['description'] = $channel->description;
         $data['subscribers'] = $channel->getSubscribedUsersAsList();
         $data['subscribed'] = Session::isActive() ? Session::get()->hasSubscribedToChannel($channel->id) : false;
         $data['playlists'] = Playlist::all(array('conditions' => array('channel_id = ?', $channel->id)));
         $data['channelBelongsToUser'] = Session::isActive() ? $channel->belongToUser(Session::get()->id) : false;
         $data['total_views'] = $channel->getAllViews();
         $data['videos'] = $channel->getPostedVideos();
         $data['owner_id'] = $channel->owner_id;
         $data['verified'] = $channel->verified;
         $data['sub'] = count($data['subscribers']);
         return new ViewResponse('channel/playlists', $data);
     } else {
         return Utils::getNotFoundResponse();
     }
 }