public function deleteMessage(Request $request, Message $message)
 {
     $result = $message->delete();
     if ($result) {
         if ($request->isXmlHttpRequest()) {
             return ['success' => true];
         }
         Flash::info('Message ' . $message->id . ' removed.');
         return redirect()->back();
     }
     if ($request->isXmlHttpRequest()) {
         return ['success' => false, 'message' => 'Can\'t remove message ' . $message->id];
     }
     return redirect()->back()->withErrors(['Can\'t remove message ' . $message->id]);
 }
 /**
  * @description: get town array with deleting duplicate entries
  * @return json array
  */
 public function getTownAutoComplete(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         // set url of data grand Lyon
         $json_url = "database/market.json";
         // get contents of file
         $json = file_get_contents($json_url);
         // decode json datas
         $datas = json_decode($json, TRUE);
         // get the multi json array
         $arrayFeatures = $datas["features"];
         // define a new empty array
         $arrayTown = array();
         // populate the new array with values we need
         foreach ($arrayFeatures as $feature) {
             array_push($arrayTown, $feature["properties"]["commune"]);
         }
         // get unique entry for array
         $result = array_unique($arrayTown);
         // get only vales of array after do array_unique (no index)
         $whatIReallyNeed = array_values($result);
         // set charset
         $charset = "UTF-8";
         //set content type
         $type = "application/json";
         // the best return ever ;)
         return response()->json($whatIReallyNeed)->header('Content-type', $type, 'charset', $charset);
     } else {
         // don't dream
         echo "what do you think dude !!!";
     }
 }
Example #3
0
 /**
  * Determine if the request has a URI that should pass through CSRF verification.
  *
  * @param  \Illuminate\Http\Request $request
  * @return bool
  */
 protected function shouldPassThrough($request)
 {
     if ($request->segment(1) == trim(config('trungtnm.backend.uri'), '/') && $request->isXmlHttpRequest() && Sentinel::check()) {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->isXmlHttpRequest()) {
         $this->errors['reason'] = 'Not XMLHttpRequest';
         return json_encode($this->errors);
     }
     return $next($request);
 }
Example #5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role = false)
 {
     $isAjaxRequest = $request->isXmlHttpRequest() || $request->ajax() || $request->wantsJson();
     if (!$isAjaxRequest) {
         return redirect('/');
     }
     return $next($request);
 }
 public function delete(Request $request, Category $category)
 {
     $category->delete();
     if ($request->isXmlHttpRequest()) {
         return response(json_encode(['success' => true]))->header('Content-type', 'application/json');
     } else {
         return redirect('/category');
     }
 }
Example #7
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $exception)
 {
     if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('remote/*')) {
         $response = response()->json(['error' => $exception instanceof DisplayException ? $exception->getMessage() : 'An unhandled error occured while attempting to process this request.'], 500);
         // parent::render() will log it, we are bypassing it in this case.
         Log::error($exception);
     }
     return isset($response) ? $response : parent::render($request, $exception);
 }
 /**
  * Determine if the given request should be cached;.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return bool
  */
 public function shouldCache(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         return false;
     }
     if ($this->isRunningInConsole()) {
         return false;
     }
     return $request->isMethod('get');
 }
Example #9
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($this->isHttpException($e)) {
         if ($request->isXmlHttpRequest()) {
             return response()->json(['ret' => 404, 'msg' => 'not fund']);
         }
         return $this->renderHttpException($e);
     } else {
         return parent::render($request, $e);
     }
 }
Example #10
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     // add handler for Ajax requests
     if ($request->isXmlHttpRequest()) {
         return Response::json(['status' => '500', 'message' => $e->getMessage()], 500);
     }
     return parent::render($request, $e);
 }
Example #11
0
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot(Request $request)
 {
     if ($this->app->runningInConsole()) {
         return false;
     }
     if ($request->isXmlHttpRequest() || $request->ajax() || $request->wantsJson()) {
         return false;
     }
     $content_pages = Contentpage::pinned()->get();
     view()->share('content_pages', $content_pages);
 }
Example #12
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if (config('app.debug')) {
         if ($request->isJson() || $request->isXmlHttpRequest()) {
             return response(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
         }
         return $this->renderExceptionWithWhoops($e);
     }
     return parent::render($request, $e);
 }
Example #13
0
 /**
  * @param Storage $storage
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|string
  */
 public function store(Storage $storage, Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $image = $request->file('image');
         $timestamp = $this->getFormattedTimestamp();
         $savedImageName = $this->getSavedImageName($timestamp, $image);
         $imageUploaded = $this->uploadImage($image, $savedImageName, $storage);
         if ($imageUploaded) {
             $data = ['original_path' => asset('/images/' . $savedImageName)];
             return json_encode($data, JSON_UNESCAPED_SLASHES);
         }
         return "uploading failed";
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show(Request $request)
 {
     //Recupera los datos de referencia para crear la tabla de préstamos
     if ($request->isXmlHttpRequest()) {
         $monto = $request->get('monto');
         $quincenas = $request->get('quincenas');
         $interes_anual = DB::table('references')->where('months', $quincenas)->value('value') / 100;
         $mi_prestamo = new FinantialClass($interes_anual, $quincenas, $monto, 0.16);
         $mi_tabla = FinantialClass::create_amorti($mi_prestamo);
         return json_encode($mi_tabla);
     } else {
         return "Datos invalidos";
     }
 }
Example #15
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($request->isXmlHttpRequest()) {
         // moze lepiej bedzie uzyc wantsJson()?
         $response = ['error' => 'Przepraszamy, ale coś poszło nie tak. Prosimy o kontakt z administratorem.'];
         if (config('app.debug')) {
             $response['exception'] = get_class($e);
             $response['message'] = $e->getMessage();
             $response['trace'] = $e->getTrace();
         }
         $status = 500;
         if ($this->isHttpException($e)) {
             $status = $e->getStatusCode();
         }
         return response()->json($response, $status);
     }
     return parent::render($request, $e);
 }
Example #16
0
 public function show(Request $request, $id)
 {
     $session = $this->sessionManager->read($id);
     if (is_null($session)) {
         return redirect('/');
     }
     if ($session->isPrivate()) {
         $password = \Session::get('session.' . $session->getId() . '.password', '');
         if (!$session->unlock($password)) {
             return redirect('/');
         }
     }
     $categories = new \App\Models\CategoryList($session);
     if ($request->isXmlHttpRequest()) {
         return $session->getObjects();
     } else {
         return view('show', compact('categories', 'session'));
     }
 }
Example #17
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($e instanceof TokenMismatchException) {
         return response()->view('errors.tokenmismatch');
     }
     $isAjaxRequest = $request->isXmlHttpRequest() || $request->ajax() || $request->wantsJson();
     // if($isAjaxRequest)
     // {
     // 	return response()->json([
     // 		'error' => [
     // 			'exception' => class_basename( $e ) . ' in ' . basename( $e->getFile() ) . ' line ' . $e->getLine() . ': ' . $e->getMessage(),
     // 		]
     // 	], $e->getStatusCode());
     // }
     if (config('app.debug')) {
         //return $this->renderExceptionWithWhoops($e);
     }
     return parent::render($request, $e);
 }
Example #18
0
 public function show(Request $request, $id)
 {
     $session = $this->sessionManager->read($id);
     if (is_null($session)) {
         return redirect('/');
     }
     if ($session->isPrivate()) {
         $password = \Session::get('session.' . $session->getId() . '.password', '');
         if (!$session->unlock($password)) {
             return redirect('/');
         }
     }
     $categories = new \App\Models\CategoryList($session);
     $token = array();
     $token['timestamp'] = time();
     $client = new \phpcent\Client(env('CENT_HOST'));
     $client->setSecret(env('CENT_SECRET'));
     $token['hash'] = $client->generateClientToken('', $token['timestamp']);
     if ($request->isXmlHttpRequest()) {
         return $session->getObjects();
     } else {
         return view('show', compact('categories', 'session', 'token'));
     }
 }
Example #19
0
 /**
  * Modify the response and inject the debugbar (or data in headers)
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function modifyResponse($request, $response)
 {
     $app = $this->app;
     if ($app->runningInConsole() or !$this->isEnabled() || $this->isDebugbarRequest()) {
         return $response;
     }
     if ($this->shouldCollect('config', false)) {
         try {
             $configCollector = new ConfigCollector();
             $configCollector->setData($app['config']->getItems());
             $this->addCollector($configCollector);
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     /** @var \Illuminate\Session\SessionManager $sessionManager */
     $sessionManager = $app['session'];
     $httpDriver = new SymfonyHttpDriver($sessionManager, $response);
     $this->setHttpDriver($httpDriver);
     if ($this->shouldCollect('symfony_request', true) and !$this->hasCollector('request')) {
         try {
             $this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
         } catch (\Exception $e) {
             $this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($response->isRedirection()) {
         try {
             $this->stackData();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($request->isXmlHttpRequest() || $request->wantsJson() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)) {
         try {
             $this->sendDataInHeaders(true);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->format()) {
         //Do nothing
     } elseif ($app['config']->get('laravel-debugbar::config.inject', true)) {
         try {
             $this->injectDebugbar($response);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     }
     // Stop further rendering (on subrequests etc)
     $this->disable();
     return $response;
 }
Example #20
0
 /**
  * Returns true if the request is a XMLHttpRequest.
  * 
  * It works if your JavaScript library sets an X-Requested-With HTTP header.
  * It is known to work with common JavaScript frameworks:
  *
  * @link http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
  * @return bool true if the request is an XMLHttpRequest, false otherwise
  * @static 
  */
 public static function isXmlHttpRequest()
 {
     //Method inherited from \Symfony\Component\HttpFoundation\Request
     return \Illuminate\Http\Request::isXmlHttpRequest();
 }
Example #21
0
 /**
  * Modify the laravel response, if needed, to add the toolbar.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Illuminate\Http\Response $response
  *
  * @return \Illuminate\Http\Response
  * @return mixed
  */
 public function modifyResponse($request, $response)
 {
     $app = $this->app;
     if ($app->runningInConsole() || $request->isXmlHttpRequest() || $request->wantsJson()) {
         return $response;
     } elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || 'html' !== $request->format()) {
         return $response;
     } elseif (!$response instanceof Response) {
         return $response;
     }
     $this->injectToolbar($response);
     return $response;
 }
Example #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     Role::destroy($id);
     if ($request->isXmlHttpRequest()) {
         return 'ok';
     } else {
         $this->alert('删除成功');
         return redirect(route('role.index'));
     }
 }
 public function newTopic(Request $request)
 {
     $user = Auth::user();
     if ($user && $user->role == "editor") {
         // Als de gebruiker ingelogd is en editor is, anders niets doen
         try {
             $filename = uniqid();
             DB::beginTransaction();
             $topic = new Artefact();
             $topic->author = $user->id;
             $thread = DB::table('artefacts')->max('thread') + 1;
             $topic->thread = $thread;
             if ($request->input('topic_title')) {
                 $topic->title = $request->input('topic_title');
             } else {
                 $topic->title = 'No title';
             }
             if ($request->input('topic_copyright')) {
                 $topic->copyright = $request->input('topic_copyright');
             }
             // De eigenlijke inhoud verwerken en het type bepalen en juist zetten
             $at = null;
             switch ($request->input('topic_temp_type')) {
                 case 'text':
                     if ($request->input('topic_text')) {
                         $topic->contents = $request->input('topic_text');
                     }
                     $at = ArtefactType::where('description', 'text')->first();
                     break;
                 case 'video':
                     if ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL meegegeven voor video
                         $url = $request->input('topic_url');
                         if (strpos($url, 'youtube') !== false || strpos($url, 'youtu.be') !== false) {
                             // Youtube video
                             $yt = BmoocController::parseYoutube($url);
                             if ($yt && $yt != '') {
                                 $topic->url = 'http://www.youtube.com/embed/' . $yt;
                                 $at = ArtefactType::where('description', 'video_youtube')->first();
                             } else {
                                 throw new Exception('The URL you entered is not a valid link to a YouTube video');
                             }
                         } elseif (strpos($url, 'vimeo.com') !== false) {
                             // Vimeo video
                             $topic->url = '//player.vimeo.com/video/' . substr($url, strpos($url, 'vimeo.com/') + 10);
                             $at = ArtefactType::where('description', 'video_vimeo')->first();
                         } else {
                             throw new Exception('The URL you entered is not a valid link to a YouTube or Vimeo video.');
                         }
                     } else {
                         // Kan niet voorkomen, maar voor de veiligheid wel fout opwerpen
                         //$topic->url = 'https://www.youtube.com/embed/YecyKnQUcBY'; // Dummy video
                         throw new Exception('No video URL provided for new topic of type video');
                     }
                     break;
                 case 'image':
                     if (Input::file('topic_upload') && Input::file('topic_upload')->isValid()) {
                         $extension = strtolower(Input::file('topic_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg'])) {
                             $destinationPath = 'uploads';
                             Input::file('topic_upload')->move($destinationPath, $filename);
                             $topic->url = $filename;
                             $at = ArtefactType::where('description', 'local_image')->first();
                         } else {
                             throw new Exception('Image should be a JPEG, PNG or GIF.');
                         }
                     } elseif ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('topic_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $topic->url = $request->input('topic_url');
                             $at = ArtefactType::where('description', 'remote_image')->first();
                         } else {
                             throw new Exception('The document in the url is not an image');
                         }
                     }
                     break;
                 case 'file':
                     if (Input::file('topic_upload') && Input::file('topic_upload')->isValid()) {
                         $extension = strtolower(Input::file('topic_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['pdf'])) {
                             $destinationPath = 'uploads';
                             Input::file('topic_upload')->move($destinationPath, $filename);
                             $topic->url = $filename;
                             $at = ArtefactType::where('description', 'local_pdf')->first();
                         } else {
                             throw new Exception('File should be a PDF.');
                         }
                     } elseif ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('topic_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $topic->url = $request->input('topic_url');
                             $at = ArtefactType::where('description', 'remote_pdf')->first();
                         }
                     }
                     break;
             }
             // Thumbnails opslaan
             if (isset($topic->url)) {
                 // small
                 if ($request->input('thumbnail_small') && $request->input('thumbnail_small') != null && $request->input('thumbnail_small') != '') {
                     $destinationPath = 'uploads/thumbnails/small/' . $topic->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_small')));
                     file_put_contents($destinationPath, $data);
                 }
                 // large
                 if ($request->input('thumbnail_large') && $request->input('thumbnail_large') != null && $request->input('thumbnail_large') != '') {
                     $destinationPath = 'uploads/thumbnails/large/' . $topic->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_large')));
                     file_put_contents($destinationPath, $data);
                 }
             }
             if ($at) {
                 $at->artefacts()->save($topic);
             } else {
                 throw new Exception('Selected file is not a valid image or PDF.');
             }
             // Einde inhoud verwerken en type bepalen
             // Bijlage verwerken
             if (Input::file('topic_attachment') && Input::file('topic_attachment')->isValid()) {
                 $extension = strtolower(Input::file('topic_attachment')->getClientOriginalExtension());
                 if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg', 'pdf'])) {
                     $destinationPath = 'uploads/attachments';
                     $filename = base64_encode(Input::file('topic_attachment')->getClientOriginalName() . time()) . '.' . $extension;
                     Input::file('topic_attachment')->move($destinationPath, $filename);
                     //$topic->url = $filename;
                     $topic->attachment = $filename;
                 } else {
                     throw new Exception('Attachment should be a JPG, PNG, GIF or PDF');
                 }
             }
             // Topic opslaan
             $topic->save();
             // Tags verwerken
             if ($request->input('topic_new_tag')) {
                 foreach ($request->input('topic_new_tag') as $newtag) {
                     if ($newtag != '') {
                         $existingtag = Tags::where('tag', strtolower($newtag))->first();
                         if ($existingtag) {
                             $existingtag->artefacts()->save($topic);
                         } else {
                             $newTag = Tags::create(['tag' => strtolower($newtag), 'times_used' => 1]);
                             $newTag->artefacts()->save($topic);
                         }
                     } else {
                         throw new Exception('Tags must not be empty!');
                     }
                 }
             }
             DB::commit();
             // add handler for Ajax requests
             if ($request->isXmlHttpRequest()) {
                 return Response::json(['status' => '200', 'url' => URL::to('/')], 200);
             } else {
                 return Redirect::back();
             }
         } catch (Exception $e) {
             DB::rollback();
             //return view('errors.topic', ['error' => $e]);
             throw $e;
         }
     }
     // End if ($user)
 }