/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $data_sent = ApiMessage::where('sent_id', $input['user_id'])->groupBy('receiver_id')->lists('receiver_id');
     $data_recived = ApiMessage::where('receiver_id', $input['user_id'])->groupBy('sent_id')->lists('sent_id');
     $total = array_diff($data_recived, $data_sent);
     $result = array_merge($total, $data_sent);
     if ($result) {
         foreach ($result as $key => $value) {
             $msg = Common::queryCommonMessage($input, $value);
             $msg = $msg->orderBy('created_at', 'desc')->first();
             $block = BlackList::where('user_id', $input['user_id'])->where('black_id', $value)->first();
             if ($msg) {
                 if ($block) {
                     $blockUser = true;
                 } else {
                     $blockUser = false;
                 }
                 $data[] = array('id' => $msg->id, 'chat_avatar' => url(USER_AVATAR . '/' . $value . '/' . User::find($value)->avatar), 'chat_id' => $value, 'chat_name' => User::find($value)->username, 'message' => $msg->message, 'status' => $msg->status, 'created_at' => date('Y-m-d', strtotime($msg->created_at)), 'block' => $blockUser);
             } else {
                 $data = null;
             }
         }
     } else {
         $data = null;
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($blackId)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     BlackList::where('user_id', $input['user_id'])->where('black_id', $blackId)->delete();
     return Common::returnData(200, DELETE_SUCCESS, $input['user_id'], $sessionId);
 }
 public function block($id)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $checkInput = BlackList::where('user_id', $input['user_id'])->where('black_id', $id)->get();
     if (!empty($checkInput)) {
         BlackList::create(['user_id' => $input['user_id'], 'black_id' => $id, 'kind' => 1]);
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId);
 }
 public function save()
 {
     // Get the input
     $input = Request::all();
     $matches = [];
     // Verify the URL
     if (!preg_match("/(?:http(?:s?):\\/\\/|)(?:www\\.)?youtu(?:be\\.com\\/watch\\?v=|\\.be\\/)([\\w\\-\\_]*)(&(amp;)?‌​[\\w\\?‌​=]*)?/i", $input['video_url'], $matches)) {
         Session::flash('error', 'Not a valid YouTube URL');
     } else {
         // Regular expression to check if the video is categorized as music
         if (preg_match('/href="\\/channel\\/UC-9-kyTW8ZkZNDHQJ6FgpwQ"/i', file_get_contents($input['video_url']))) {
             // Make sure that the regular expression did not mess up
             if (!empty($matches)) {
                 // Make sure the song isn't already in the queue
                 $try = MusicQueue::where('url', '=', $matches[1])->first();
                 if (is_null($try)) {
                     // Make sure the video isn't blacklisted
                     $blacklisted_items = BlackList::where('url', '=', $matches[1])->get()->toArray();
                     if (sizeof($blacklisted_items) == 0) {
                         // Video meets all requirements and is not blacklisted
                         // Save to the queue
                         $song = MusicQueue::create(['url' => $matches[1], 'time_in' => Carbon::now(), 'user_in' => Session::getId()]);
                         Session::flash('success', 'Video successfully enqueued.');
                     } else {
                         // Video is blacklisted, do not allow it to enter the queue
                         Session::flash('error', 'That video is blacklisted and cannot be put into the queue.');
                     }
                 } else {
                     // Song is already in the queue
                     Session::flash('info', 'That song is already in the queue.');
                 }
             } else {
                 // Shouldn't happen, but it might. Just in case
                 Session::flash('error', 'Something went wrong... Please try again.');
             }
         } else {
             // Video is not categorized as "Music" on youtube.
             Session::flash('error', 'Video not categorized as Music');
         }
     }
     // Return to the control page
     return redirect('control');
 }
Exemple #5
0
 public static function checkBlackList($userId, $blackId)
 {
     if ($userId == $blackId) {
         return true;
     }
     $blacklist = BlackList::where('user_id', $userId)->where('black_id', $blackId)->first();
     $blacklist2 = BlackList::where('user_id', $blackId)->where('black_id', $userId)->first();
     if (isset($blacklist) || isset($blacklist2)) {
         return true;
     }
     return false;
 }