Ejemplo n.º 1
0
 public function create($request)
 {
     if (Session::isActive()) {
         $req = $request->getParameters();
         $resp = $this->index($request);
         if ($req['name'] != '' && $req['channel_id'] != '') {
             if (UserChannel::exists($req['channel_id'])) {
                 if (UserChannel::find($req['channel_id'])->belongToUser(Session::get()->id)) {
                     if (!Playlist::exists(array('conditions' => array('name = ? AND channel_id = ?', $req['name'], $req['channel_id'])))) {
                         Playlist::create(array('name' => $req['name'], 'channel_id' => $req['channel_id'], 'videos_ids' => json_encode(array()), 'timestamp' => Utils::tps()));
                         // Oui cette ligne est dupliquée mais ce n'est pas une erreur, ne pas supprimer SVP
                         $resp = $this->index($request);
                         $resp->addMessage(ViewMessage::success('Playlist ajoutée avec succès !'));
                     } else {
                         $resp->addMessage(ViewMessage::error('Une playlist du même nom existe déjà sur cette chaîne.'));
                     }
                 } else {
                     $resp->addMessage(ViewMessage::error('Cette chaîne ne vous appartient pas.'));
                 }
             } else {
                 $resp->addMessage(ViewMessage::error('Cette chaîne n\'existe pas !'));
             }
         } else {
             $resp->addMessage(ViewMessage::error('Merci de remplir tous les champs'));
         }
     }
     return $resp;
 }
Ejemplo n.º 2
0
 public function getMemberChannelsName()
 {
     $names = array();
     $membersStr = $this->members_ids;
     if ($this->isTicketConv()) {
         $tech_channel = $this->getTechChannel();
         $tech_user = $this->getTechUser();
     }
     if (Utils::stringStartsWith($membersStr, ';')) {
         $membersStr = substr_replace($membersStr, '', 0, 1);
     }
     if (Utils::stringEndsWith($membersStr, ';')) {
         $membersStr = substr_replace($membersStr, '', -1);
     }
     if (strpos($membersStr, ';') !== false) {
         $membersIds = explode(';', $membersStr);
         foreach ($membersIds as $memberId) {
             if (UserChannel::exists($memberId)) {
                 if (isset($tech_channel) && $tech_channel->id == $memberId) {
                     $names[] = StaffContact::getShownName($tech_user);
                 } else {
                     $names[] = UserChannel::find($memberId)->name;
                 }
             }
         }
     }
     return $names;
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 public function edit($id, $request)
 {
     $data = [];
     if ($id == '' || !UserChannel::exists(['id' => $id])) {
         return new RedirectResponse(WEBROOT . 'admin/channel');
     }
     $channel = UserChannel::find_by_id($id);
     $data['channel_admin'] = User::find($channel->owner_id);
     $data['channel'] = $channel;
     return new ViewResponse('admin/channel/edit', $data);
 }
Ejemplo n.º 5
0
 public function get($id, $request)
 {
     if (Session::isActive()) {
         Session::get()->last_visit = Utils::tps();
         Session::get()->save();
         if ($conv = Conversation::find($id)) {
             if (!$conv->isUserAllowed(Session::get())) {
                 return Utils::getUnauthorizedResponse();
             }
             if ($conv->isTicketConv()) {
                 $tech['channel'] = $conv->getTechChannel();
                 $tech['user'] = $conv->getTechUser();
             } else {
                 $tech = null;
             }
             $messages = $conv->getMessages();
             foreach ($messages as $message) {
                 $sender = UserChannel::exists($message->sender_id) ? UserChannel::find($message->sender_id) : false;
                 if (is_object($sender)) {
                     $senderAvatar = $sender->getAvatar();
                     $pseudo = $sender->name;
                     if (isset($tech['channel'], $tech['user']) && $sender->id == $tech['channel']->id) {
                         $pseudo = StaffContact::getShownName($tech['user']);
                         $senderAvatar = StaffContact::getImageName($tech['user']);
                     }
                     $messagesData[] = array('id' => 'id', 'pseudo' => $pseudo, 'channel_name' => $sender->name, 'avatar' => $senderAvatar, 'text' => $message->content, 'mine' => $sender->belongToUser(Session::get()->id));
                 }
             }
             $conversationsData = array();
             $avatar = $conv->thumbnail;
             /*if(!is_array(getimagesize($avatar))) { // if the image is invalid
             			if(is_array(getimagesize(WEBROOT.$avatar)))
             				$avatar = WEBROOT.$avatar;
             			else
             				$avatar = Config::getValue_('default-avatar');
             		}*/
             //var_dump($conv->isTicketConv());
             $conversationsData['infos'] = array('id' => $conv->id, 'title' => $conv->object, 'members' => $conv->getMemberChannelsName(), 'avatar' => $avatar, 'text' => isset(end($messages)->content) ? end($messages)->content : 'Aucun message');
             if (isset($messagesData)) {
                 $conversationsData['messages'] = $messagesData;
             }
             return new JsonResponse($conversationsData);
         }
     } else {
         return Utils::getUnauthorizedResponse();
     }
     return new Response(500);
 }
Ejemplo n.º 6
0
 public function chat($id, $request)
 {
     if (UserChannel::exists(array('name' => $id))) {
         $data = [];
         $channel = UserChannel::find(['name' => $id]);
         $data['channel'] = $channel;
         $access = LiveAccess::find(array('channel_id' => $channel->id));
         if (is_object($access)) {
             $data['viewers'] = $access->viewers;
         } else {
             $data['viewers'] = 0;
         }
         return new ViewResponse('embed/chat', $data, false);
     } else {
         return Utils::getNotFoundResponse();
     }
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 public function create($request)
 {
     if (Session::isActive()) {
         $req = $request->getParameters();
         Session::get()->last_visit = Utils::tps();
         Session::get()->save();
         if (isset($req['sender'], $req['conversation'], $req['content']) && !empty($req['conversation']) && !empty($req['sender']) && !empty($req['content'])) {
             $sender = Utils::secure($req['sender']);
             $conversation = Utils::secure($req['conversation']);
             $content = Utils::secure($req['content']);
             $channel = UserChannel::exists($sender) ? UserChannel::find($sender) : false;
             if ($channel && $channel->belongToUser(Session::get()->id) && ($conv = Conversation::find($conversation))) {
                 if (!$conv->containsChannel($channel)) {
                     return Utils::getUnauthorizedResponse();
                 }
                 $message = Message::sendNew($sender, $conversation, $content);
                 $messageData = array('id' => $message->id, 'avatar' => $channel->getAvatar(), 'pseudo' => $channel->name, 'text' => $content, 'mine' => 'true');
                 return new JsonResponse($messageData);
             }
         }
     }
     return new Response(500);
 }
Ejemplo n.º 9
0
 public function create($request)
 {
     $req = $request->getParameters();
     if (isset($req['commentSubmit'], $req['from-channel'], $req['video-id']) && Session::isActive()) {
         $channelId = Utils::secure($req['from-channel']);
         $min_timestamp = Utils::tps() - Config::getValue_("time_between_comments");
         if (Comment::exists(array('conditions' => array("poster_id=? AND timestamp > ?", $channelId, $min_timestamp)))) {
             return new Response(500);
         }
         if (UserChannel::exists($channelId) && UserChannel::find($channelId)->belongToUser(Session::get()->id)) {
             $content = Utils::secure($req['comment-content']);
             $content = trim($content);
             $parent = isset($req['parent']) ? Utils::secure($req['parent']) : '';
             if (!empty($content)) {
                 $vidId = Utils::secure($req['video-id']);
                 $comment = Comment::postNew($channelId, $vidId, $content, $parent);
                 $commentData = array('id' => $comment->id, 'author' => UserChannel::find($comment->poster_id)->name, 'video_id' => $vidId, 'comment' => $content, 'relativeTime' => Utils::relative_time($comment->timestamp), 'likes' => $comment->likes, 'dislikes' => $comment->dislikes);
                 return new JsonResponse($commentData);
             }
         }
     }
     return new Response(500);
 }
Ejemplo n.º 10
0
 public function getAuthor()
 {
     return UserChannel::exists($this->poster_id) ? UserChannel::find($this->poster_id) : false;
 }
Ejemplo n.º 11
0
 public static function isNameFree($name)
 {
     return !UserChannel::exists(array('name' => $name));
 }
Ejemplo n.º 12
0
 public function hasSubscribedToChannel($channelId)
 {
     if (UserChannel::exists($channelId)) {
         return in_array($channelId, $this->getSubscribedChannelsAsList());
     } else {
         return false;
     }
 }
Ejemplo n.º 13
0
 public function update($id, $request)
 {
     if (!Session::isActive()) {
         return new RedirectResponse(Utils::generateLoginURL());
     }
     $req = $request->getParameters();
     $data = $req;
     $data['current'] = 'account';
     $data['email'] = Session::get()->email;
     $data['currentPageTitle'] = 'Mon compte';
     if ($id == 'infos') {
         if (isset($req['profileSubmit']) && Session::isActive()) {
             $user = Session::get();
             $currentMail = Session::get()->email;
             $currentUsername = Session::get()->username;
             if (isset($req['email']) && $req['email'] != $currentMail) {
                 $newMail = Utils::secure($req['email']);
                 if (Utils::validateMail($newMail)) {
                     $user->email = $newMail;
                     $user->save();
                     $data['email'] = $newMail;
                 } else {
                     $response = new ViewResponse('account/profile', $data);
                     $response->addMessage(ViewMessage::error('L\'adresse E-Mail n\'est pas valide'));
                     return $response;
                 }
             }
             if (isset($req['username']) && $req['username'] != $currentUsername) {
                 $newUsername = Utils::secure($req['username']);
                 if (Utils::validateUsername($newUsername) && !User::exists(array('username' => $newUsername)) && !UserChannel::exists(['name' => $newUsername])) {
                     $channel = Session::get()->getMainChannel();
                     $user->username = $newUsername;
                     $user->save();
                     $channel->name = $newUsername;
                     $channel->save();
                     $data['username'] = $newUsername;
                 } else {
                     $response = new ViewResponse('account/profile', $data);
                     $response->addMessage(ViewMessage::error('Le nom d\'utilisateur doit être disponible, contenir uniquement des lettres, des chiffres, des points, des traits d\'union et des _ et doit être compris entre 3 et 40 caractères.'));
                     return $response;
                 }
             }
             $response = new ViewResponse('account/profile', $data);
             $response->addMessage(ViewMessage::success('Préférences enregistrées !'));
             return $response;
         }
     }
     if ($id == 'password') {
         if (isset($req['passwordSubmit']) && Session::isActive()) {
             if (isset($req['newPass']) && isset($req['newPassConfirm']) && isset($req['currentPass'])) {
                 if ($req['newPass'] == $req['newPassConfirm']) {
                     $currentPass = $req['currentPass'];
                     $newPass = $req['newPass'];
                     $data = $req;
                     $data['current'] = 'password';
                     if (password_verify($currentPass, Session::get()->pass)) {
                         Session::get()->setPassword(password_hash($newPass, PASSWORD_BCRYPT));
                         $response = new ViewResponse('account/password', $data);
                         $response->addMessage(ViewMessage::success('Préférences enregistrées !'));
                         return $response;
                     } else {
                         $response = new ViewResponse('account/password', $data);
                         $response->addMessage(ViewMessage::error('Le mot de passe actuel est erroné'));
                         return $response;
                     }
                 } else {
                     $response = new ViewResponse('account/password', $data);
                     $response->addMessage(ViewMessage::error('Les mots de passe ne sont pas identiques'));
                     return $response;
                 }
             }
         }
     }
     if ($id == 'volume') {
         $data = $req;
         Session::get()->setSoundSetting($data["volume"]);
         return new Response(200);
     }
     if ($id == 'definition') {
         $data = $req;
         Session::get()->setDefinitionSetting($data["definition"]);
         return new Response(200);
     }
     if ($id == 'notifications') {
         $data = $request->getParameters();
         $data['current'] = 'notifications';
         Session::get()->setNotificationSettings($data);
         $data = array_merge($data, Session::get()->getNotificationSettings());
         $response = new ViewResponse('account/notifications', $data);
         $response->addMessage(ViewMessage::success("Paramètres de notifications sauvegardés"));
         return $response;
     }
     if ($id == 'language') {
         $data['currentPageTitle'] = "Paramètre de langues";
         $data['current'] = 'language';
         Session::get()->setLanguageSetting($req['language']);
         $data['settings'] = Session::get()->getSettings();
         $data['avaiable_languages'] = Translator::getLanguagesList();
         $data['lang_setting'] = Session::get()->getLanguageSetting();
         return new RedirectResponse('account/language', $data);
     } else {
         return new ViewResponse('account/profile', $data);
     }
 }
Ejemplo n.º 14
0
 public function viewers($id, $request)
 {
     if (UserChannel::exists($id)) {
         $channel_id = $id;
     } elseif (UserChannel::exists(array('name' => $id))) {
         $channel_id = UserChannel::find(array('name' => $id))->id;
     } else {
         return Utils::getNotFoundResponse();
     }
     return new JsonResponse(array(LiveAccess::find(array('channel_id' => $channel_id))->viewers));
 }
Ejemplo n.º 15
0
 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());
     }
 }
Ejemplo n.º 16
0
    ?>
			<p style="text-align: center; color: #858484;">Aucun évenement récent</p>
		<?php 
}
?>

		<?php 
foreach (@$actions as $action) {
    if ($action) {
        $supp_class = $action->timestamp > $last_visit ? ' card--new' : '';
        $channel_action = UserChannel::exists($action->channel_id) ? Utils::secureActiveRecordModel(UserChannel::find($action->channel_id)) : false;
        if ($channel_action !== false) {
            if ($action->type == 'upload' && Video::exists($action->target)) {
                echo Utils::getVideoCardHTML(Utils::secureActiveRecordModel(Video::find($action->target)), $supp_class);
            } else {
                if ($action->type == "subscription" && UserChannel::exists($action->target)) {
                    $target_channel = UserChannel::find($action->target);
                    ?>
								<div class="card<?php 
                    echo $supp_class;
                    ?>
 channel">
									<?php 
                    if ($action->infos['nb_subscription'] <= 1) {
                        ?>
									<a href="<?php 
                        echo WEBROOT . 'channel/' . $channel_action->name;
                        ?>
">
										<div class="avatar bg-loader" data-background-load-in-view data-background="<?php 
                        echo $channel_action->getBackground();