Esempio 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;
 }
Esempio n. 2
0
 public function create($request)
 {
     $req = $request->getParameters();
     $response = new ViewResponse('assist/ticket');
     if (trim($req['bug']) != '') {
         if (Session::isActive()) {
             $user_id = Session::get()->id;
         } else {
             if (trim($req['email']) != '') {
                 $user_id = $req['email'];
             } else {
                 $user_id = 0;
             }
         }
         if (!empty(Ticket::find('all', ['conditions' => ['ip = ? AND timestamp < ' . (Utils::tps() + 60), $_SERVER['REMOTE_ADDR']]]))) {
             $r = $this->index($request);
             $r->addMessage(ViewMessage::error('Trop d\'envois avec la même IP en une minute, réssayez plus tard.'));
             return $r;
         }
         $ticket = Ticket::create(array('user_id' => $user_id, 'description' => $req['bug'], 'timestamp' => time(), 'ip' => $_SERVER['REMOTE_ADDR']));
         StaffNotification::createNotif('ticket', $user_id, null, $ticket->id);
         $ticket_id = $ticket->id;
         $response->addMessage(ViewMessage::success('Envoyé ! Vous serez notifié de l\'avancement par E-Mail ou Message Privé (Ticket #' . $ticket_id . ')'));
         /*$username = (Session::isActive()) ? Session::get()->username : '******';
         		$notif = new PushoverNotification();
         		$notif->setMessage('Nouveau ticket de '.$username);
         		$notif->setReceiver('all');
         		$notif->setExtraParameter('url', 'http://dreamvids.fr'.WEBROOT.'admin/tickets');
         		$notif->send();*/
     } else {
         $response->addMessage(ViewMessage::error('Merci de nous décrire votre problème.'));
     }
     return $response;
 }
Esempio n. 3
0
 /**
  * Add an entry if not already exist into `subscriptions` table that associate a `users` and a `users_channel`
  * @param User|int $user
  * @param UserChannel|string $channel
  */
 public static function subscribeUserToChannel($user, $channel)
 {
     $user_id = $user instanceof User ? $user->id : $user;
     $channel_id = $channel instanceof UserChannel ? $channel->id : $channel;
     if (!self::exists(['user_id' => $user_id, 'user_channel_id' => $channel_id])) {
         self::create(['user_id' => $user_id, 'user_channel_id' => $channel_id, 'timestamp' => Utils::tps()]);
     }
 }
Esempio n. 4
0
 public function create($request)
 {
     $data = $request->getParameters();
     if (isset($data['submitLogin']) && !Session::isActive()) {
         $is_admin = isset($data['is_admin']) && $data['is_admin'] == 1;
         $username = Utils::secure($data['username']);
         $password = Utils::secure($data['pass']);
         if (User::find_by_username($username)) {
             $user = User::find_by_username($username);
             $current_log_fail = $user->getLogFails();
             if (!$user->isAllowedToAttemptLogin()) {
                 $next_timestamp = $current_log_fail['next_try'];
                 $last_try_timestamp = $current_log_fail['last_try'];
                 $nb_try = $current_log_fail['nb_try'];
                 $next_try_tps = $next_timestamp - Utils::tps();
                 $next_try_min = floor($next_try_tps / 60);
                 $next_try_sec = round($next_try_tps - $next_try_min * 60);
                 $next_try_str = "{$next_try_min} m et {$next_try_sec} s";
                 $data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
                 $data['currentPageTitle'] = 'Connexion';
                 $response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
                 $response->addMessage(ViewMessage::error($nb_try . " tentatives de connexions à la suite pour ce compte. Veuillez patienter {$next_try_str}"));
                 return $response;
             }
             $realPass = User::find_by_username($username)->getPassword();
             if (password_verify($password, $realPass)) {
                 User::connect($username, 1);
                 $user->resetLogFails();
                 return new RedirectResponse($data['redirect'] ? urldecode($data['redirect']) : WEBROOT);
             } else {
                 if (sha1($password) == $realPass) {
                     $user->resetLogFails();
                     User::connect($username, 1)->setPassword(password_hash($password, PASSWORD_BCRYPT));
                     return new RedirectResponse($data['redirect'] ? urldecode($data['redirect']) : WEBROOT);
                 }
                 if (!$user->isIntervalBetweenTwoLogAttemptElapsed() || !$current_log_fail) {
                     $user->addLogFail();
                 } else {
                     $user->resetLogFails();
                     $user->addLogFail();
                 }
                 $data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
                 $data['currentPageTitle'] = 'Connexion';
                 $response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
                 $response->addMessage(ViewMessage::error('Mot de passe incorrect'));
                 return $response;
             }
         } else {
             $data = isset($data['redirect']) ? ['redirect' => $data['redirect']] : [];
             $data['currentPageTitle'] = 'Connexion';
             $response = !$is_admin ? new ViewResponse('login/login', $data) : new ViewResponse('admin/login/login', $data, true, 'layouts/admin_login.php', 401);
             $response->addMessage(ViewMessage::error('Ce nom d\'utilisateur n\'existe pas'));
             return $response;
         }
     }
 }
Esempio n. 5
0
 public function create($request)
 {
     $params = $request->getParameters();
     $data = ['success' => false];
     $user = Session::get();
     if ($params['title'] != '' && $params['content'] != '') {
         $new = News::create(['user_id' => $user->id, 'title' => $params['title'], 'content' => $params['content'], 'icon' => $params['icon'], 'level' => $params['level'], 'timestamp' => Utils::tps()]);
         $data['success'] = is_object($new);
     }
     return new JsonResponse($data);
 }
Esempio n. 6
0
 public function create($request)
 {
     $req = $request->getParameters();
     $data = [];
     $new_question = ['timestamp' => Utils::tps()];
     foreach (self::$fields as $field) {
         $new_question[$field] = isset($req[$field]) ? $req[$field] : 0;
     }
     $faq = Faq::create($new_question);
     $r = $this->edit($faq->id, $request);
     $r->addMessage(ViewMessage::success("Nouvelle Question/Réponse créée. <a href=\"" . WEBROOT . "admin/faq\">Retour à la liste</a>"));
     return $r;
 }
Esempio n. 7
0
 public static function init()
 {
     if (isset($_COOKIE['SESSID'])) {
         if (UserSession::exists(array('session_id' => $_COOKIE['SESSID']))) {
             $session = User::find_by_id(UserSession::find_by_session_id($_COOKIE['SESSID'])->user_id);
             session_id($_COOKIE['SESSID']);
             self::set($session);
         } else {
             setcookie("SESSID", "", -1);
             self::set(-1);
         }
         session_start();
     }
     UserSession::delete_all(array('conditions' => array('expiration < ?', Utils::tps())));
 }
 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);
 }
Esempio n. 9
0
 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');
     }
 }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
 /**
  * 
  * @param string $class_name
  * @param string $timestamp_field
  * @param number $long_ago
  * @param number $step
  * @param string $date_format
  * @return array
  */
 public static function getDataForGraph($class_name, $timestamp_field = 'timestamp', $long_ago = 2592000, $step = 86400, $date_format = "Y-m-d")
 {
     $table_name = $class_name::$table_name == '' ? strtolower($class_name) . 's' : $class_name::$table_name;
     $min_timestamp = Utils::tps() - $long_ago;
     $request = "SELECT DISTINCT time, count(*) AS count FROM (\nSELECT *, ((ROUND(`{$timestamp_field}` / ({$step}))-1)*({$step})) as time FROM `{$table_name}`\nHAVING `{$timestamp_field}` > {$min_timestamp}\nORDER BY {$timestamp_field}  DESC) AS temp\nGROUP BY time";
     $temp = $class_name::find_by_sql($request);
     $result = [];
     foreach ($temp as $k => $value) {
         $result[date($date_format, $value->time)] = [date($date_format, $value->time), $value->count];
     }
     foreach (range($min_timestamp, Utils::tps(), $step) as $index => $v) {
         $temp_date = date($date_format, $v);
         if (!isset($result[$temp_date])) {
             $result[$temp_date] = [$temp_date, 0];
         }
     }
     return $result;
 }
Esempio n. 12
0
 public function index($request)
 {
     $data = [];
     $data['dv_eggs'] = Eggs::getDreamvidsEggs();
     $data['cavi_eggs'] = Eggs::getCaviconEggs();
     $now = Utils::tps();
     $date_now = new DateTime(date("c", $now));
     foreach ($data as $k => $eggs) {
         foreach ($eggs as $k2 => $egg) {
             if ($egg->show_timestamp < $now) {
                 $data['intervals'][$egg->id] = '';
             } else {
                 $interval = abs($now - $egg->show_timestamp);
                 $futur = new DateTime(date("c", $egg->show_timestamp));
                 $diff = $futur->diff($date_now)->format("%Y ans, %m mois, %d j et %H:%I:%S restant");
                 $data['intervals'][$egg->id] = $diff;
             }
         }
     }
     return new ViewResponse('admin/egg/index', $data);
 }
Esempio n. 13
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);
 }
Esempio n. 14
0
 public function index($request)
 {
     if (Session::isActive()) {
         $sess = Session::get();
         $data = array();
         $data['currentPageTitle'] = 'Flux d\'activité';
         $data['actions'] = array();
         $data['subscriptions'] = array();
         $data['last_visit'] = $sess->last_visit;
         $sess->last_visit = Utils::tps();
         $sess->save();
         $actions = Session::get()->getNotifications();
         $data['subscriptions'] = Session::get()->getSubscribedChannels();
         if (count($actions) > 0) {
             $data['actions'] = $actions;
         }
         $data = $this->regroupPmFeeds($data);
         $data = $this->regroupLikeFeeds($data);
         $data = $this->regroupSubscribeFeeds($data);
         return new ViewResponse('feed/feed', $data);
     } else {
         return new RedirectResponse(Utils::generateLoginURL());
     }
 }
Esempio n. 15
0
 public static function createNotif($type, $id_one = null, $id_two = null, $value = null, $level = '', $viewers = 'team_or_more', $force_push = false)
 {
     $staff_notif = StaffNotification::create(['type' => $type, 'id_one' => $id_one, 'id_two' => $id_two, 'value' => $value, 'viewers' => $viewers, 'level' => $level, 'timestamp' => Utils::tps()]);
     $emails = [];
     $title = 'DreamVids';
     $sub_title = '';
     $is_link = !is_null($staff_notif->getLink());
     $link_url = "http://" . @$_SERVER['HTTP_HOST'] . WEBROOT . $staff_notif->getLink();
     foreach (User::getTeam() as $user) {
         $content = $staff_notif->getContent();
         if (Utils::getRankArray($user)[$viewers] && (self::isEnabled($user) || $force_push)) {
             if (!is_null($user->details->push_bullet_email) && $user->details->push_bullet_email != '') {
                 switch ($type) {
                     case 'ticket_level_change':
                         $ticket = $staff_notif->getAssociatedValue('Ticket');
                         $sub_title = 'Tickets';
                         if (in_array($ticket->ticket_levels_id, $user->getAssignedLevelsIds()) || $user->isAdmin()) {
                             $emails[] = $user->details->push_bullet_email;
                         }
                         break;
                     case 'ticket':
                         $sub_title = 'Tickets';
                         $emails[] = $user->details->push_bullet_email;
                         break;
                     case 'news':
                         $sub_title = 'News';
                         $emails[] = $user->details->push_bullet_email;
                         break;
                     case 'private':
                         $sub_title = "Message privé";
                         $content = $staff_notif->value;
                         if ($staff_notif->id_two == $user->id) {
                             $emails[] = $user->details->push_bullet_email;
                         }
                         break;
                     case 'private':
                         $sub_title = "Message";
                         $content = $staff_notif->value;
                         $emails[] = $user->details->push_bullet_email;
                         break;
                     default:
                         $emails[] = $user->details->push_bullet_email;
                         break;
                 }
             }
         }
     }
     $notif = new PushBulletNotification($title . ($sub_title != '' ? ' - ' . $sub_title : ''), $content, $emails, $is_link, $link_url);
     $notif->send();
 }
Esempio n. 16
0
        ?>
<th>Page d'apparition</th><?php 
    }
    ?>
					<th>Points</th>
					<th>Moment d'apparition</th>
					<th>Etat</th>
					<th>Action</th>
				</tr>
			</thead>

			<tbody>
				<?php 
    foreach ($eggs as $k => $egg) {
        $color_class = $egg->show_timestamp > Utils::tps() ? 'warning' : ($egg->found ? 'success' : 'info');
        $state = $egg->show_timestamp > Utils::tps() ? 'Pas encore apparu' : ($egg->found ? 'Trouvé' : 'Caché');
        ?>
					
				
					<tr class="<?php 
        echo $color_class;
        ?>
">
						<td><?php 
        echo $egg->id;
        ?>
</td>
						<?php 
        if ($key == 'Dreamvids') {
            ?>
<td><?php 
Esempio n. 17
0
 public function update($id, $request)
 {
     $req = $request->getParameters();
     if (!Session::isActive()) {
         return Utils::getUnauthorizedResponse();
     }
     if ($video = Video::find($id)) {
         if (isset($req['video-edit-submit'], $req['video-title'], $req['video-description'], $req['video-tags'])) {
             $data = array();
             $data['currentPageTitle'] = $video->title . ' - Modification';
             if (UserChannel::find(Video::find($id)->poster_id)->belongToUser(Session::get()->id) || Session::get()->isModerator() || Session::get()->isAdmin()) {
                 $data['video'] = $video;
                 $title = $req['video-title'];
                 $description = $req['video-description'];
                 $tags = $req['video-tags'];
                 $visibility = $req['video-visibility'];
                 if (Utils::validateVideoInfo($title, $description, $tags) && in_array($visibility, array(0, 1, 2))) {
                     $video->updateInfo($title, $description, $tags, $req['_FILES_']['tumbnail'], $visibility);
                     $data['video'] = $video;
                     $response = new ViewResponse('video/edit', $data);
                     $response->addMessage(ViewMessage::success('Votre video a bien été modifiée !'));
                     return $response;
                 } else {
                     $response = new ViewResponse('video/edit', $data);
                     $response->addMessage(ViewMessage::error('Les informations ne sont pas valides.'));
                     return $response;
                 }
             }
         } else {
             if (isset($req['flag']) && !empty($req['flag'])) {
                 $flag = $req['flag'];
                 if ($flag == 'false' && (Session::get()->isModerator() || Session::get()->isAdmin())) {
                     $video->unFlag(Session::get()->id);
                     return new Response(200);
                 } else {
                     if ($flag == 'true') {
                         $video->flag(Session::get()->id);
                         return new Response(200);
                     }
                 }
             } else {
                 if (isset($req['suspend']) && !empty($req['suspend']) && (Session::get()->isModerator() || Session::get()->isAdmin())) {
                     $suspend = $req['suspend'];
                     if ($suspend == 'false') {
                         $video->unSuspend(Session::get()->id);
                         return new Response(200);
                     } else {
                         if ($suspend == 'true') {
                             $video->suspend(Session::get()->id);
                             return new Response(200);
                         }
                     }
                 } else {
                     if (isset($req['like'])) {
                         $userId = Session::get()->id;
                         if (!$video->isLikedByUser($userId)) {
                             if ($video->isDislikedByUser($userId)) {
                                 $video->removeDislike($userId);
                             }
                             $video->like($userId);
                             return new Response(200);
                         }
                     } else {
                         if (isset($req['dislike'])) {
                             $userId = Session::get()->id;
                             if (!$video->isDislikedByUser($userId)) {
                                 if ($video->isLikedByUser($userId)) {
                                     $video->removeLike($userId);
                                 }
                                 $video->dislike($userId);
                                 return new Response(200);
                             }
                         } else {
                             if (isset($req['unlike'])) {
                                 $userId = Session::get()->id;
                                 if ($video->isLikedByUser($userId)) {
                                     $video->removeLike($userId);
                                     return new Response(200);
                                 }
                             } else {
                                 if (isset($req['undislike'])) {
                                     $userId = Session::get()->id;
                                     if ($video->isDislikedByUser($userId)) {
                                         $video->removeDislike($userId);
                                         return new Response(200);
                                     }
                                 } else {
                                     if (isset($req['discover']) && (Session::get()->isModerator() || Session::get()->isAdmin())) {
                                         $video->discover = Utils::tps();
                                         $video->save();
                                         $author = $video->getAuthor();
                                         $receiver = ChannelAction::filterReceiver($author->admins_ids, "staff_select");
                                         ChannelAction::create(['id' => ChannelAction::generateId(6), 'channel_id' => $author->id, 'recipients_ids' => $receiver, 'type' => 'staff_select', 'target' => $video->id, 'timestamp' => Utils::tps()]);
                                         return new Response(200);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return new Response(500);
 }
Esempio n. 18
0
 public function unsubscribe($subscriber)
 {
     Subscription::unsubscribeUserFromChannel($subscriber, $this);
     $unsubscriberUser = User::find_by_id($subscriber);
     $unsubscribingChannel = $this;
     $channel_id = $this->id;
     ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $unsubscriberUser->getMainChannel()->id, 'recipients_ids' => ChannelAction::filterReceiver($unsubscribingChannel->admins_ids, "unsubscription"), 'type' => 'unsubscription', 'target' => $channel_id, 'timestamp' => Utils::tps()));
 }
Esempio n. 19
0
 /**
  * @return User
  */
 public static function connect($username, $remember)
 {
     if (User::find_by_username($username)) {
         $sessid = md5(uniqid());
         $expiration = $remember ? Utils::tps() + 365 * 86400 : Utils::tps() + 24 * 3600;
         $user = User::find_by_username($username);
         UserSession::create(array('user_id' => $user->id, 'session_id' => $sessid, 'expiration' => $expiration, 'remember' => $remember));
         setcookie('SESSID', $sessid, $expiration);
         return $user;
     }
 }
Esempio n. 20
0
//<script>

var imported = document.createElement('script');
var _webroot_ = "http://<?php 
echo $_SERVER["SERVER_NAME"] . WEBROOT;
?>
";
imported.src = _webroot_ + "<?php 
echo 'assets/js/eggs_event.js';
?>
";
document.body.appendChild(imported);

testEggLoaded = setInterval(function() {
	if(typeof Egg !== "undefined"){
		clearInterval(testEggLoaded);
		loadEggs();
	}
}, 10);

function loadEggs(){
	<?php 
foreach ($eggs as $egg) {
    if ($egg->show_timestamp > Utils::tps()) {
        continue;
    }
    $type = $egg->points == 3 ? "gold" : "normal";
    echo "new Egg('{$egg->id}', '{$type}');" . PHP_EOL;
}
?>
}
Esempio n. 21
0
 public static function getEggsFromUri($uri)
 {
     return self::find('all', ['conditions' => ['site = "dreamvids" AND emplacement = ? AND found = 0 AND show_timestamp < ' . Utils::tps(), $uri]]);
 }
 public function _handleUpload($request)
 {
     $req = $request->getParameters();
     if (!isset($req['_FILES_']['team_img_name'])) {
         return null;
     }
     $ext = pathinfo($req['_FILES_']['team_img_name']['name'], PATHINFO_EXTENSION);
     if (!in_array(strtolower($ext), ['jpeg', 'jpg', 'png', 'gif', 'tiff', 'svg'])) {
         return null;
     }
     $file_name = Session::get()->username . '_' . Utils::tps() . '.' . $ext;
     if (move_uploaded_file($req['_FILES_']['team_img_name']['tmp_name'], ROOT . 'assets/img/team/' . $file_name)) {
         return $file_name;
     } else {
         return null;
     }
 }
Esempio n. 23
0
 public function update($id, $request)
 {
     $req = $request->getParameters();
     $data = $req;
     $data['current'] = 'channels';
     $name = @$req['name'];
     $descr = @$req['description'];
     $admins = @json_decode($req['_admins']);
     if (isset($req['editChannelSubmit']) && Session::isActive()) {
         $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
         if (!is_object($channel)) {
             return Utils::getNotFoundResponse();
         }
         if (!$channel->belongToUser(Session::get()->id)) {
             return Utils::getForbiddenResponse();
         }
         $data['mainChannel'] = $channel->isUsersMainChannel(Session::get()->id);
         $data['name'] = $channel->name;
         $data['description'] = $channel->description;
         $data['currentPageTitle'] = $channel->name . ' - Edition';
         $data['owner_id'] = $channel->owner_id;
         $admins_array_ids = explode(';', trim($channel->admins_ids, ';'));
         $data['admins_ids'] = $admins_array_ids;
         $data['admins'] = array();
         foreach ($admins_array_ids as $adm) {
             $data['admins'][] = User::find_by_id($adm)->getMainChannel();
         }
         if (isset($req['name'], $req['description'])) {
             if (strlen($name) >= 3 && strlen($name) <= 40) {
                 if (preg_match("#^[a-zA-Z0-9\\_\\-\\.]+\$#", $name)) {
                     if ($channel->isUsersMainChannel(Session::get()->id)) {
                         if ($channel->name != $req['name']) {
                             $data['name'] = $channel->name;
                             $response = new ViewResponse('channel/edit', $data);
                             $response->addMessage(ViewMessage::error('Vous ne pouvez pas changer le nom de votre chaîne principale !'));
                             return $response;
                         }
                     } else {
                         $adm = trim($channel->admins_ids, ';');
                         $adm = explode(';', $adm);
                         foreach ($admins as $admin) {
                             if ($admin > 0) {
                                 if (!in_array($admin, $adm)) {
                                     $adm[] = $admin;
                                     ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $channel->id, 'recipients_ids' => ';' . $admin . ';', 'type' => 'admin', 'target' => $channel->id, 'timestamp' => Utils::tps()));
                                 }
                             } else {
                                 $value = -1 * $admin;
                                 if (in_array($value, $adm) && $channel->owner_id != $value) {
                                     $id = array_keys($adm, $value);
                                     unset($adm[$id[0]]);
                                     ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $channel->id, 'recipients_ids' => ';' . $admin . ';', 'type' => 'unadmin', 'target' => $channel->id, 'timestamp' => Utils::tps()));
                                 }
                             }
                         }
                         $adm = ';' . implode(';', $adm) . ';';
                     }
                     UserChannel::edit($channel->id, $name, $descr, $adm, $req['_FILES_']['avatar'], $req['_FILES_']['background']);
                     //TODO: Support logo/background
                     $data['channels'] = Session::get()->getOwnedChannels();
                     $data['currentPageTitle'] = 'Mes chaines';
                     $response = new ViewResponse('account/channels', $data);
                     $response->addMessage(ViewMessage::success('Votre chaîne ' . $name . ' a bien été modifiée !'));
                     return $response;
                 } else {
                     $response = new ViewResponse('channel/edit', $data);
                     $response->addMessage(ViewMessage::error('Le nom de la chaîne doit contenir uniquement des lettres (majuscules et minuscules), des traits-d\'union, des _ et des points.'));
                     return $response;
                 }
             } else {
                 $response = new ViewResponse('channel/edit', $data);
                 $response->addMessage(ViewMessage::error('Le nom de la chaîne doit être compris entre 3 et 40 caractères.'));
                 return $response;
             }
         } else {
             $response = new ViewResponse('channel/edit', $data);
             $response->addMessage(ViewMessage::error('Tous les champs doivent être remplis.'));
             return $response;
         }
     } else {
         if (isset($req['subscribe'])) {
             if (Session::isActive()) {
                 $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
                 if (is_object($channel) && !$channel->belongToUser(Session::get()->id)) {
                     $channel->subscribe(Session::get()->id);
                     $response = new Response(200);
                     return $response;
                 }
             } else {
                 return new Response(500);
             }
         } else {
             if (isset($req['unsubscribe'])) {
                 if (Session::isActive()) {
                     $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
                     if (is_object($channel) && !$channel->belongToUser(Session::get()->id)) {
                         $channel->unsubscribe(Session::get()->id);
                         $response = new Response(200);
                         return $response;
                     }
                 } else {
                     return new Response(500);
                 }
             } else {
                 if (isset($req['admin_edit'])) {
                     if (Session::isActive()) {
                         $channel = UserChannel::exists($id) ? UserChannel::find($id) : UserChannel::find_by_name($id);
                         if (!$channel) {
                             return Utils::getNotFoundResponse();
                         }
                         if (!$channel->isUsersMainChannel(Session::get()->id) && $channel->owner_id != Session::get()->id) {
                             if (in_array($channel, Session::get()->getOwnedChannels())) {
                                 $current_admins = $channel->admins_ids;
                                 $current_admins = trim($current_admins, ";");
                                 $current_admins = explode(";", $current_admins);
                                 foreach ($current_admins as $k => $admin) {
                                     if ($admin == Session::get()->id) {
                                         unset($current_admins[$k]);
                                         $channel->admins_ids = ";" . implode($current_admins, ";") . ";";
                                         $channel->save();
                                         return new RedirectResponse(WEBROOT . "channel/{$id}");
                                     }
                                 }
                             }
                         }
                     }
                     return Utils::getForbiddenResponse();
                 }
             }
         }
     }
 }
Esempio n. 24
0
 public static function sendUploadNotification($videoId, $channelId)
 {
     ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $channelId, 'recipients_ids' => ChannelAction::filterReceiver(';' . implode(';', Subscription::getSubscribersFromChannelAsList($channelId)) . ';', "upload"), 'type' => 'upload', 'target' => $videoId, 'timestamp' => Utils::tps()));
 }
Esempio n. 25
0
 public function update($id, $request)
 {
     $req = $request->getParameters();
     if (isset($req['like']) && Session::isActive() && Comment::exists($id)) {
         $comment = Comment::find($id);
         if (!$comment->isLikedByUser(Session::get())) {
             $comment->like(Session::get());
             $commentData = 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), 'likes' => $comment->likes, 'dislikes' => $comment->dislikes);
             return new JsonResponse($commentData);
         } else {
             // The comment is already liked by the user, so we remove the like
             $comment->unlike(Session::get());
             $commentData = 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), 'likes' => $comment->likes, 'dislikes' => $comment->dislikes);
             return new JsonResponse($commentData);
         }
     } else {
         if (isset($req['dislike']) && Session::isActive() && Comment::exists($id)) {
             $comment = Comment::exists($id) ? Comment::find($id) : false;
             if (!$comment->isDislikedByUser(Session::get())) {
                 $comment->dislike(Session::get());
                 $commentData = 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), 'likes' => $comment->likes, 'dislikes' => $comment->dislikes);
                 return new JsonResponse($commentData);
             } else {
                 // The comment is already disliked by the user, so we remove the dislike
                 $comment->undislike(Session::get());
                 $commentData = 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), 'likes' => $comment->likes, 'dislikes' => $comment->dislikes);
                 return new JsonResponse($commentData);
             }
         } else {
             if (isset($req['flag']) && Session::isActive() && Comment::exists($id)) {
                 $comment = Comment::exists($id) ? Comment::find($id) : false;
                 if (!$comment->isReported() && $req['flag'] == 'true') {
                     $comment->report(Session::get());
                 } else {
                     if ((Session::get()->isAdmin() || Session::get()->isModerator()) && $req['flag'] == 'false') {
                         $comment->unflag(Session::get());
                     }
                 }
                 return new Response(200);
             } else {
                 if (isset($req['comment']) && Session::isActive() && Comment::exists($id)) {
                     $comment = Comment::find($id);
                     if ($comment->getAuthor() && ($comment->getAuthor()->belongToUser(Session::get()->id) || Session::get()->isModerator() || Session::get()->isAdmin())) {
                         $comment->comment = $req['comment'];
                         $comment->last_updated_timestamp = Utils::tps();
                         $comment->save();
                         return new Response(200);
                     }
                 }
             }
         }
     }
     return new Response(500);
 }
Esempio n. 26
0
 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;
 }
Esempio n. 27
0
 public function messages($param1, $param2 = 'nope')
 {
     if ($param2 != 'nope') {
         $id = $param1;
         $request = $param2;
     } else {
         $request = $param1;
     }
     if (Session::isActive()) {
         $data = array();
         if (isset($id)) {
             $data['pre_load'] = $id;
         }
         $data['current'] = 'messages';
         $data['currentPageTitle'] = 'Mon compte';
         $data['channels'] = Session::get()->getOwnedChannels();
         Session::get()->last_visit = Utils::tps();
         Session::get()->save();
         return new ViewResponse('account/messages', $data);
     } else {
         return new RedirectResponse(Utils::generateLoginURL());
     }
 }