Beispiel #1
0
 public function get($id, $request)
 {
     $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
     if ($channel) {
         $access = LiveAccess::find(array('channel_id' => $channel->id));
         if (is_object($access)) {
             $data = array();
             $data['currentPage'] = 'live';
             $data['channel'] = $channel;
             $data['viewers'] = $access->viewers;
             $data['currentPageTitle'] = 'Live de ' . $channel->name;
             $data['subscribers'] = count($channel->getSubscribedUsersAsList());
             $data['subscribed'] = Session::isActive() ? Session::get()->hasSubscribedToChannel($channel->id) : false;
             $data['onAir'] = is_object($access) ? $access->isOnline() : false;
             $data['liveKey'] = is_object($access) ? $access->key : '';
         } else {
             $data['currentPage'] = 'live';
             $data['channel'] = $channel;
             $data['viewers'] = 0;
             $data['currentPageTitle'] = 'Live de ' . $channel->name;
             $data['subscribers'] = count($channel->getSubscribedUsersAsList());
             $data['subscribed'] = Session::isActive() ? Session::get()->hasSubscribedToChannel($channel->id) : false;
             $data['onAir'] = false;
             $data['liveKey'] = '';
         }
         return new ViewResponse('channel/live', $data);
     } else {
         return Utils::getNotFoundResponse();
     }
 }
Beispiel #2
0
 public function subscription($subscriptionId)
 {
     $subscription = UserChannel::exists($subscriptionId) ? UserChannel::find($subscriptionId) : UserChannel::find_by_name($subscriptionId);
     if (is_object($subscription) && !$subscription->belongToUser(Session::get()->id)) {
         $data = array();
         $data['subscriptions'] = Session::get()->getSubscribedChannels();
         $data['vids'] = Session::get()->getSubscriptionsVideosFromChannel($subscription->id, 6);
         return new ViewResponse('feed/feed', $data);
     }
 }
 public function create($request)
 {
     $req = $request->getParameters();
     if (isset($req['post-message-submit'], $req['channel'], $req['post-content']) && Session::isActive()) {
         $channelId = $req['channel'];
         $channel = UserChannel::exists($channelId) ? UserChannel::find($channelId) : UserChannel::find_by_name($channelId);
         if (is_object($channel) && $channel->belongToUser(Session::get()->id)) {
             $postContent = $req['post-content'];
             $postContent = trim($postContent);
             if (!empty($postContent)) {
                 $post = $channel->postMessage($postContent);
                 $postData = array('id' => $post->id, 'channel_id' => $post->channel_id, 'content' => Utils::secure($post->content), 'timestamp' => $post->timestamp);
                 return new JsonResponse($postData);
             }
         }
     }
     return new Response(500);
 }
Beispiel #4
0
 public static function getIdByName($channelName)
 {
     return @UserChannel::find_by_name($channelName)->id;
 }
Beispiel #5
0
 public function getMainChannel()
 {
     return UserChannel::find_by_name($this->username);
 }
 public function create($request)
 {
     if (Session::isActive()) {
         $req = $request->getParameters();
         if (isset($req['members'], $req['creator'], $req['subject']) && !empty($req['members']) && !empty($req['creator'])) {
             $membersStr = Utils::secure($req['members']);
             $creator = Utils::secure($req['creator']);
             $subject = Utils::secure($req['subject']);
             $subject = !empty($subject) ? $subject : 'Sans titre';
             if ($sender = UserChannel::find($creator)) {
                 if (Utils::stringStartsWith($membersStr, ';')) {
                     $membersStr = substr_replace($membersStr, '', 0, 1);
                 }
                 if (Utils::stringEndsWith($membersStr, ';')) {
                     $membersStr = substr_replace($membersStr, '', -1);
                 }
                 $membersStr = preg_replace('/\\s+/', '', $membersStr);
                 $membersIdsFinal = ';';
                 if (strpos($membersStr, ';')) {
                     foreach (explode(';', $membersStr) as $destId) {
                         if ($dest = UserChannel::find_by_name($destId)) {
                             $membersIdsFinal .= $dest->id . ';';
                         } else {
                             $response = new Response(500);
                             $response->setBody('Error: Le destinataire <' . $destId . '> n\'existe pas !');
                             return $response;
                         }
                     }
                 } else {
                     if ($chann = UserChannel::find_by_name($membersStr)) {
                         $membersIdsFinal .= $chann->id . ';';
                     } else {
                         $response = new Response(500);
                         $response->setBody('Error: les destinataires doivent être séparés par un \';\' !');
                         return $response;
                     }
                 }
                 if ($membersIdsFinal != ';') {
                     $membersIdsFinal .= $sender->id . ';';
                     Conversation::createNew($subject, $sender, $membersIdsFinal);
                     return new Response(200);
                 }
             }
         }
     }
     return new Response(500);
 }
 public function edit($id, $request)
 {
     if (Session::isActive()) {
         $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
         if (!$channel->belongToUser(Session::get()->id)) {
             return Utils::getForbiddenResponse();
         }
         if (is_object($channel)) {
             $data = array();
             $data['currentPage'] = 'channel';
             $data['current'] = 'channels';
             $data['currentPageTitle'] = $channel->name . ' - Edition';
             $data['id'] = $channel->id;
             $data['mainChannel'] = $channel->isUsersMainChannel(Session::get()->id);
             $data['owner_id'] = $channel->owner_id;
             $data['name'] = $channel->name;
             $data['description'] = $channel->description;
             $data['avatar'] = $channel->getAvatar();
             $data['background'] = $channel->getBackground();
             $admins = explode(';', trim($channel->admins_ids, ';'));
             $data['admins_ids'] = $admins;
             $data['admins'] = array();
             foreach ($admins as $adm) {
                 $data['admins'][] = User::find_by_id($adm)->getMainChannel();
             }
             return new ViewResponse('channel/edit', $data);
         } else {
             return Utils::getNotFoundResponse();
         }
     } else {
         return new RedirectResponse(Utils::generateLoginURL());
     }
 }