public function index($request) { $data = []; $counts = []; $counts['videos'] = Video::count(); $counts['users'] = User::count(); $counts['channels'] = UserChannel::count(); $counts['comments'] = Comment::count(); $counts['total_views'] = Video::sumViews(); $counts['channel_user_ratio'] = round($counts['channels'] / $counts['users'], 2); $counts['videos_that_has_comments'] = Statistic::countVideosHavingComments(); $counts['channels_having_videos'] = Video::find_by_sql('SELECT count(DISTINCT poster_id) as count from `videos`')[0]->count; $counts['part_of_commented_videos'] = round($counts['videos_that_has_comments'] / $counts['videos'] * 100, 2); $counts['part_of_channels_having_videos'] = round($counts['channels_having_videos'] / $counts['channels'] * 100, 2); $counts['user_1_channel'] = Statistic::countUserHavingChannels('= 1'); $counts['user_2_channel'] = Statistic::countUserHavingChannels('= 2'); $counts['user_3_channel'] = Statistic::countUserHavingChannels('= 3'); $counts['user_more3_channel'] = Statistic::countUserHavingChannels('> 3'); $counts['user_1_channel_part'] = round($counts['user_1_channel'] / $counts['users'] * 100, 2); $counts['user_2_channel_part'] = round($counts['user_2_channel'] / $counts['users'] * 100, 2); $counts['user_3_channel_part'] = round($counts['user_3_channel'] / $counts['users'] * 100, 2); $counts['user_more3_channel_part'] = round($counts['user_more3_channel'] / $counts['users'] * 100, 2); $data['counts'] = $counts; return new ViewResponse('admin/statistic/index', $data); }
/** * @param $channel Channel ID or channel object * @return array of User */ public static function getSubscribersFromChannel($channel) { if (!$channel instanceof UserChannel) { $channel = UserChannel::find($channel); } return $channel->subscribed_users; }
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 update($id, $request) { $data = $request->getParameters(); $channel = UserChannel::find($id); $channel->verified = $data['verified']; $channel->description = $data['description']; $channel->save(); $data['channel'] = $channel; $data['channel_admin'] = User::find($channel->owner_id); $r = new ViewResponse('admin/channel/edit', $data); $r->addMessage(ViewMessage::success("Chaîne modifiée")); return $r; }
public static function sendNew($sender, $conversation, $content, $timeOffset = 0) { $id = Message::generateId(6); $timestamp = Utils::tps() + $timeOffset; $message = Message::create(array('id' => $id, 'sender_id' => $sender, 'conversation_id' => $conversation, 'content' => $content, 'timestamp' => $timestamp)); $recep = array(); $members = explode(';', trim(Conversation::find($conversation)->members_ids, ';')); foreach ($members as $id) { if ($id != $sender) { $recep[] = trim(UserChannel::find($id)->admins_ids, ';'); } } $recep = ';' . implode(';', $recep) . ';'; $recep = ChannelAction::filterReceiver($recep, "pm"); ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => userChannel::find($sender)->id, 'recipients_ids' => $recep, 'type' => 'pm', 'target' => $conversation, 'timestamp' => $timestamp)); return $message; }
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(); } }
public function get($id, $request) { if (UserChannel::find($id)->belongToUser(Session::get()->id)) { $uploadId = Upload::generateId(6); Upload::create(array('id' => $uploadId, 'channel_id' => $id, 'video_id' => Video::generateId(6), 'expire' => Utils::tps() + 86400)); $data = array(); $data['currentPageTitle'] = 'Mettre en ligne'; $data['uploadId'] = $uploadId; $data['thumbnail'] = Config::getValue_('default-thumbnail'); $data['channelId'] = $id; $data['currentPage'] = 'upload'; //$data['predefined_descriptions'] = PredefinedDescription::getDescriptionByChannelsids($id); return new ViewResponse('upload/upload', $data); } else { return new RedirectResponse(WEBROOT . 'upload'); } }
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); }
public function index($request) { $data = array(); $data['currentPageTitle'] = 'Accueil'; $data['discoverVids'] = Video::getDiscoverVideos(2); $data['bestVids'] = Video::getBestVideos(6); if (Session::isActive()) { $channel = Session::get()->getMainChannel(); $data['subscriptions'] = Session::get()->getSubscribedChannels(); if ($data['subscriptions'] instanceof UserChannel) { $data['subscriptions'] = [$data['subscriptions']]; } $data['subscriptions_vids'] = Video::getSubscriptionsVideos(Session::get()->id, 20); $data['channelId'] = $channel->id; $data['channelName'] = $channel->name; $data['avatar'] = $channel->getAvatar(); $data['background'] = $channel->getBackground(); return new ViewResponse('home/logged', $data); } else { $data['best_chans'] = UserChannel::getBestChannels(); $data['news_vids'] = Video::getLastVideos(); return new ViewResponse('home/guest', $data); } }
public static function register($username, $password, $mail) { $appConfig = new Config(CONFIG . 'app.json'); $appConfig->parseFile(); $userRank = $appConfig->getValue('rankUser'); User::create(array('username' => $username, 'email' => $mail, 'pass' => password_hash($password, PASSWORD_BCRYPT), 'subscriptions' => '', 'reg_timestamp' => Utils::tps(), 'reg_ip' => $_SERVER['REMOTE_ADDR'], 'actual_ip' => $_SERVER['REMOTE_ADDR'], 'rank' => $userRank, 'settings' => json_encode(array()))); UserChannel::create(array('id' => UserChannel::generateId(6), 'name' => $username, 'description' => 'Chaîne de ' . $username, 'owner_id' => User::getIdByName($username), 'admins_ids' => ';' . User::getIdByName($username) . ';', 'avatar' => Config::getValue_('default-avatar'), 'background' => Config::getValue_('default-background'), 'subscribers' => 0, 'subs_list' => 0, 'views' => 0, 'verified' => 0)); }
<div id="upload-large-modal"> <div class="bg-loader" id="backgroundLoader" data-background="<?php echo UserChannel::find($channelId)->getBackground(); ?> "></div> <section id="message-upload"> <h3>Déposez votre fichier vidéo dans cette zone pour l'uploader</h3> <p>(Ou selectionnez votre fichier manuellement en cliquant sur le nuage)</p> </section> <section id="uploader"> <span id="upload-illustration"> <span class="cloud"> <span id="arrowUpload" data-uploaded-message="Uploaded"></span> </span> </span> <input id="upload-input" type="file" name="video" accept="video/*"> <div id="file-name"></div> </section> <div id="progress-upload"> <div id="progress-bar"></div> </div> </div> <div id="upload-content"> <form id="upload-form" class="form middle" method="post" action="<?php echo WEBROOT . 'videos'; ?> " enctype="multipart/form-data">
public function channel($id, $request) { if (Session::isActive() && ($channel = UserChannel::find($id)) && $channel->belongToUser(Session::get()->id)) { if ($request->acceptsJson()) { $conversations = Conversation::getByChannel($channel); $conversationsData = array(); foreach ($conversations as $conv) { $conversationsData[] = array('id' => $conv->id, 'title' => $conv->object, 'members' => $conv->getMemberChannelsName(), 'avatar' => $conv->getThumbnail(), 'text' => $conv->getLastMessage() ? $conv->getLastMessage()->content : 'Aucun message'); } return new JsonResponse($conversationsData); } } else { return Utils::getUnauthorizedResponse(); } return new Response(500); }
public function destroy($id, $request) { if (Session::isActive() && UserChannel::find(Playlist::find($id)->channel_id)->belongToUser(Session::get()->id)) { Playlist::find($id)->delete(); Playlist::delete_all(array('conditions' => 'id = ?'), $id); return new Response(200); } else { ob_clean(); return new Response(500); } }
public function destroy($id, $request) { if (Session::isActive()) { $user = Session::get(); if (ChannelPost::exists($id)) { $post = ChannelPost::find($id); if (UserChannel::find($post->channel_id) && UserChannel::find($post->channel_id)->belongToUser($user->id)) { $post->erase(); } } } return new Response(200); }
public static function getSearchVideos($query, $order = "none") { if ($order == "none") { $order = "timestamp desc"; } $query = trim(urldecode($query)); if ($query != '') { if ($query[0] == '#') { $query = trim($query, '#'); $all = Video::all(array('conditions' => array('tags LIKE ? AND visibility = ?', '%' . $query . '%', Config::getValue_('vid_visibility_public')), 'order' => $order)); } else { $all = Video::all(array('conditions' => array('(title LIKE ? OR description LIKE ? OR tags LIKE ? OR poster_id=?) AND visibility = ?', '%' . $query . '%', '%' . $query . '%', '%' . $query . '%', UserChannel::getIdByName($query), Config::getValue_('vid_visibility_public')), 'order' => $order)); } return $all; } }
<br><br> </div> <?php } ?> <?php if ($action->type == 'comment' && Utils::relative_time($action->timestamp)) { ?> <div> <p> <a href="<?php echo WEBROOT . 'channel/' . $action->channel_id; ?> "><?php echo UserChannel::getNameById($action->channel_id); ?> </a> a commenté votre vidéo <a href="<?php echo WEBROOT . 'watch/' . $action->target; ?> "><?php echo Video::find($action->target)->title; ?> :</a> <p>"<?php echo Comment::getByChannelAction($action)->comment; ?> "</p> </p>
public function videos($id, $request) { if (Session::isActive() && UserChannel::find($id)->belongToUser(Session::get()->id)) { $data['videos'] = UserChannel::find($id)->getPostedVideos(false); $data['currentPageTitle'] = 'Mon compte'; $data['current'] = 'videos'; $response = new ViewResponse('account/videos', $data); if (empty($data['videos'])) { $response->addMessage(ViewMessage::error('Vous n\'avez posté aucune vidéo')); } return $response; } else { return new RedirectResponse(Utils::generateLoginURL()); } }
<div class="content"> <aside class="full-cards-list"> <h3 class="title">Lives en cours</h3> <?php if (count($lives) > 0) { foreach ($lives as $live) { $channel = UserChannel::find($live->channel_id); ?> <div class="card video card--live"> <div class="thumbnail bg-loader" data-background-load-in-view data-background="<?php echo $channel->avatar; ?> "> <a href="<?php echo WEBROOT . 'lives/' . $channel->name; ?> " class="overlay"></a> </div> <div class="description"> <a href="<?php echo WEBROOT . 'lives/' . $channel->name; ?> "><h4>Live de <?php echo $channel->name; ?> </h4></a> <div> <span class="view"><?php echo $live->viewers; ?>
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)); }
public function checkNameAvailable($name, $request) { $data = []; $data['available'] = UserChannel::isNameFree($name) && User::isNameFree($name); return new JsonResponse($data); }
public function getTechChannel() { if ($this->is_ticket) { return UserChannel::find_by_owner_id($this->tech_id); } else { return null; } }
public function index($request) { /* SECURING */ if (!(isset($_GET['q']) || isset($_GET['advanced']))) { return Utils::getNotFoundResponse(); } $filteredFileds = []; foreach ($_GET as $k => $value) { if (in_array($k, array_merge(self::$acceptableSearchFields, ["q", "advanced"])) && !empty($value)) { $filteredFileds[$k] = $value; } } if (empty($filteredFileds)) { return Utils::getNotFoundResponse(); } /* END SECURING */ $data = []; $data['filteredFields'] = $filteredFileds; $order = "none"; if (isset($_GET["order"], $_GET["order_way"])) { if (in_array($_GET['order'], ['views', 'likes', 'timestamp']) && in_array($_GET['order_way'], ['ASC', 'DESC'])) { $order = $_GET['order'] . " " . $_GET['order_way']; $filteredFileds['oreder'] = $_GET['order']; $filteredFileds['oreder_way'] = $_GET['order_way']; } } /* Advanced */ if (@$filteredFileds['advanced'] == 1) { $data['currentPageTitle'] = 'Recherche avancée'; $tags_select_type = "or"; if (isset($filteredFileds['tags_select_type'])) { if (in_array($filteredFileds['tags_select_type'], ["or", "and"])) { $tags_select_type = $filteredFileds['tags_select_type']; } } foreach ($filteredFileds as $k => $value) { switch ($k) { case "video": $data['videos'] = Video::getSearchVideos($value, $order); break; case "channel": $data['channels'] = UserChannel::getSearchChannels($value); break; case "tags": if (isset($data['videos'])) { $data['videos'] = array_merge($data['videos'], Video::getSearchVideosByTags(explode(" ", $value), $order, $tags_select_type == "and")); } else { $data['videos'] = Video::getSearchVideosByTags(explode(" ", $value), $order, $tags_select_type == "and"); } break; } $_SESSION["last_search"] = ""; } $data['currentPageTitle'] = 'Recherche avancée'; $data['search'] = "avancée"; } else { /* Normal search */ $q = urldecode($_GET['q']); $data['currentPageTitle'] = $q . ' - Recherche'; $data['search'] = $q; $data['videos'] = Video::getSearchVideos($q, $order); $data['channels'] = UserChannel::getSearchChannels($q); $_SESSION["last_search"] = $q; } if (empty($data['videos']) && empty($data['channels']) || strlen($_GET['q']) < 3) { $data['error'] = array("message" => "La recherche n'a retourné aucun resultat.", "level" => "error"); return new ViewResponse('search/error', $data); } return new ViewResponse('search/search', $data); }
public function video($id, $request) { $video = Video::exists($id) ? Video::find($id) : false; if (!$request->acceptsJson()) { return new RedirectResponse(WEBROOT . 'watch/' . $id); } if (is_object($video)) { $comments = $video->getComments(); $commentsData = array(); foreach ($comments as $comment) { $commentsData[] = array('id' => $comment->id, 'author' => UserChannel::find($comment->poster_id)->name, 'video_id' => $comment->video_id, 'comment' => $comment->comment, 'relativeTime' => Utils::relative_time($comment->timestamp), 'timestamp' => $comment->timestamp, 'likes' => $comment->likes, 'dislikes' => $comment->dislikes); } return new JsonResponse($commentsData); } return new Response(500); }
public static function getSearchChannels($query) { $query = trim(urldecode($query)); if ($query != '') { return UserChannel::find_by_sql('SELECT * FROM users_channels LEFT OUTER JOIN (SELECT user_channel_id, COUNT(*) AS total_sub FROM subscriptions GROUP BY user_channel_id) AS total_sub ON(total_sub.user_channel_id = users_channels.id) WHERE name LIKE ? OR description LIKE ? ORDER BY total_sub DESC LIMIT 6', ["%{$query}%", "%{$query}%"]); } }
public function getChannel() { return UserChannel::find($this->channel_id); }
function displayComments($video, $parent, $i) { $comments = $video->getComments($parent); if (empty($comments)) { ?> <p>Aucun commentaire à propos de cette video</p> <?php } foreach ($comments as $comment) { $comment->comment = Utils::makeLinks(Utils::secure($comment->comment)); $margin = $i * 8; ?> <div style="width: <?php echo 100 - $margin; ?> %; margin-left:<?php echo $margin; ?> %" class="comment" id="c-<?php echo $comment->id; ?> "> <div class="comment-head"> <div class="user"> <img src="<?php echo UserChannel::find($comment->poster_id)->getAvatar(); ?> " alt="[Avatar]"> <a href="<?php echo WEBROOT . 'channel/' . UserChannel::find($comment->poster_id)->name; ?> "><?php echo UserChannel::getNameById($comment->poster_id); ?> </a> </div> <div class="date"> <p><?php echo Utils::relative_time($comment->timestamp); echo $comment->last_updated_timestamp ? ' (Edité ' . Utils::relative_time($comment->last_updated_timestamp) . ')' : ''; ?> </p> </div> </div> <div class="comment-text"> <p style="word-wrap:break-word"><?php echo $comment->comment; ?> </p> </div> <div class="comment-notation"> <ul> <li class="plus" id="plus-<?php echo $comment->id; ?> " onclick="likeComment('<?php echo $comment->id; ?> ')">+<?php echo $comment->likes; ?> </li> <li class="moins" id="moins-<?php echo $comment->id; ?> " onclick="dislikeComment('<?php echo $comment->id; ?> ')">-<?php echo $comment->dislikes; ?> </li> <li onclick="reportComment('<?php echo $comment->id; ?> ', this)" style="cursor:pointer">Signaler</li> <li onclick="document.location.href='#comments';document.getElementById('response').innerHTML='<b>Répondre à <?php echo UserChannel::getNameById($comment->poster_id); ?> :</b>';document.getElementById('textarea-comment').focus();document.getElementById('parent-comment').value='<?php echo $comment->id; ?> ';" style="cursor:pointer">Répondre</li> <?php if (Session::isActive() && (Session::get()->isModerator() || Session::get()->isAdmin() || $comment->getAuthor()->belongToUser(Session::get()->id))) { ?> <li onclick="editComment('<?php echo $comment->id; ?> ', this)" style="cursor:pointer">Editer</li> <?php } ?> <?php if (Session::isActive() && (Session::get()->isModerator() || Session::get()->isAdmin() || $video->getAuthor()->belongToUser(Session::get()->id) || $comment->getAuthor()->belongToUser(Session::get()->id))) { ?> <li onclick="deleteComment('<?php echo $comment->id; ?> ', this)" style="cursor:pointer">Supprimer</li> <?php } ?> </ul> </div> </div> <?php if (Comment::count(array('conditions' => array('parent = ?', $comment->id))) >= 1) { displayComments($video, $comment->id, $i + 1); } } }
public function edit($id, $request) { if (Session::isActive() && UserChannel::find(Video::find($id)->poster_id)->belongToUser(Session::get()->id)) { if ($video = Video::find($id)) { $data = array(); $data['currentPageTitle'] = $video->title . ' - Modification'; $data['video'] = $video; return new ViewResponse('video/edit', $data); } else { return new RedirectResponse(WEBROOT . 'account/videos'); } } else { return new RedirectResponse(Utils::generateLoginURL()); } }
<?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(); ?> "></div> <p><b><?php echo Utils::secure($channel_action->name); ?> </b> s'est abonné à votre chaîne "<b><?php echo Utils::secure(UserChannel::find($action->target)->name); ?> </b>"</p> <?php } else { ?> <a href="<?php echo WEBROOT . 'channel/' . $target_channel->name; ?> "> <div class="avatar bg-loader" data-background-load-in-view data-background="<?php echo $target_channel->getBackground(); ?> "></div> <p><b><?php echo $action->infos['nb_subscription'];
public static function postNew($authorId, $videoId, $commentContent, $parent) { $timestamp = Utils::tps(); $poster_channel = UserChannel::find(Video::find($videoId)->poster_id); $admins_ids = $poster_channel->admins_ids; $admins_ids = ChannelAction::filterReceiver($admins_ids, "comment"); $admin_ids_array = $poster_channel->getArrayAdminsIds($admins_ids); foreach ($admin_ids_array as $k => $value) { if ($value == Session::get()->id) { unset($admin_ids_array[$k]); break; } } $recipients_ids = ';' . trim(implode(';', $admin_ids_array), ';') . ';'; $comment = Comment::create(array('id' => Comment::generateId(6), 'poster_id' => $authorId, 'video_id' => $videoId, 'comment' => $commentContent, 'likes' => 0, 'dislikes' => 0, 'timestamp' => $timestamp, 'parent' => $parent)); ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $authorId, 'recipients_ids' => $recipients_ids, 'type' => 'comment', 'target' => $videoId, 'complementary_id' => $comment->id, 'timestamp' => $timestamp)); return $comment; }
</thead> <tbody> <?php foreach ($videos as $vid) { ?> <tr> <td><a href="<?php echo WEBROOT . 'watch/' . $vid->id; ?> "><?php echo $vid->title; ?> </a></td> <td><?php echo UserChannel::find($vid->poster_id)->name; ?> </td> <td><?php echo number_format($vid->views); ?> </td> <td><?php echo $vid->likes; ?> </td> <td><?php echo $vid->dislikes; ?> </td> <td>