get(); $vorgeschlagen = Film::neuesteVorschlage()->get(); $news = News::aktuell()->get(); $topfilm = DB::table(DB::raw('film_films')) ->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount')) ->leftJoin('votes as film_u', function($join) { $join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE')); }) ->leftJoin('votes as film_d', function($join) { $join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE')); }) ->whereNull('films.gesehen') ->groupBy('id') ->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC') ->first(); $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE); $tmovie = $tmdb->getMovie($topfilm->tvdbid); $image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342'); return View::make('index') ->with('gesehen', $gesehen) ->with('vorgeschlagen', $vorgeschlagen) ->with('image', $image) ->with('news', $news) ->with('topfilm', $topfilm); }); Route::get('film/{id}', array('as' => 'film', function($id) { $film = Film::findOrFail($id); $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE); $tmovie = $tmdb->getMovie($film->tvdbid); $tcast = $tmdb->getMovieCast($film->tvdbid); $ttrail = $tmdb->getMovieTrailers($film->tvdbid); $image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342'); $votes = $film->votes()->count(); $vposi = $film->votes()->where('stimme', true)->count(); $pv = ""; foreach($film->votes()->where('stimme', true)->get() as $v) { $pv .= $v->voter->name . "
"; } $nv = ""; foreach($film->votes()->where('stimme', false)->get() as $v) { $nv = $v->voter->name . "
"; } if(!is_null(Auth::user()) && $film->votes()->where('user', Auth::user()->id)->count() > 0) { $uvote[0] = true; $uvote[1] = $film->votes()->where('user', Auth::user()->id)->first()->stimme; } else { $uvote[0] = false; } $comments = $film->comments()->orderBy('id', 'DESC')->get(); $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success"); return View::make('film') ->with('film', $film) ->with('tfilm', $tmovie) ->with('poster', $image) ->with('comments', $comments) ->with('cast', $tcast) ->with('trail', $ttrail) ->with('votes', $votes) ->with('uvote', $uvote) ->with('pv', $pv) ->with('nv', $nv) ->with('vposi', $vposi) ->with('labels', $labels) ->with('tmdb', $tmdb); })); Route::get('vote/{stimme}/{user}/{film}', function($stimme, $user, $film) { $v = Vote::where('user', $user)->where('film', $film)->first(); if(!is_null($v)) { $v->stimme = $stimme == "yes" ? true : false; } else { $v = new Vote(); $v->user = $user; $v->film = $film; $v->stimme = $stimme == "yes" ? true : false; } $v->save(); return Redirect::to('film/' . $film); }); Route::post('comment', array('as' => 'comment', function() { $c = new Comment(); $c->film = Input::get('film'); $c->user = Input::get('user'); $c->text = Input::get('text'); $c->bewertung = Input::get('rate'); $c->save(); return Redirect::to('film/' . Input::get('film')); })); Route::post('comment/edit', array('as'=> 'modcomment', function () { $c = Comment::findOrFail(Input::get('id')); $c->text = Input::get('text'); $c->bewertung = Input::get('rate'); $c->save(); return Redirect::to('film/' . $c->film); })); Route::get('login', array('as' => 'login', function() { return View::make('login'); })); Route::post('login', function() { $userdata = array( 'name' => Input::get('user'), 'password' => Input::get('password')); if(Auth::attempt($userdata)) { return Redirect::intended('/'); } else { echo "Login gescheitert."; var_dump($userdata); return Redirect::to('login') ->with('login_errors', true); } }); Route::get('logout', array('as' => 'logout', function() { Auth::logout(); return Redirect::to('/'); })); Route::get('vorgeschlagen', function() { $filme = DB::table(DB::raw('film_films')) ->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount')) ->leftJoin('votes as film_u', function($join) { $join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE')); }) ->leftJoin('votes as film_d', function($join) { $join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE')); }) ->whereNull('films.gesehen') ->groupBy('id') ->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC') ->paginate(); return View::make('suggest') ->with('filme', $filme); })->where(array('field' => '[a-z]+', 'order' => 'asc|desc')); Route::get('gesehen/{field?}/{order?}', function($field = "gesehen", $order = "desc") { $filme = Film::whereNotNull('gesehen')->orderBy($field, $order)->paginate(); return View::make('seen') ->with('filme', $filme); })->where(array('field' => '[a-z]+', 'order' => 'asc|desc')); Route::get('neu', array('before' => 'auth', function() { return View::make('new'); })); Route::post('neu', array('before' => 'auth', function() { $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE); $r = $tmdb->searchMovie(Input::get('search')); return View::make('new')->with('result', $r)->with('tmdb', $tmdb); })); Route::get('vorschlag/{id}', array('before' => 'auth', function($id) { $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE); $f = $tmdb->getMovie($id); $film = new Film(); $film ->name = $f['title']; $film->tvdbid = $id; $film->vorgeschlagen = \Carbon\Carbon::today(); $film->user = Auth::user()->id; $film->save(); return Redirect::to('film/' . $film->id); })); Route::get('mark-read/{id}', array('before' => 'auth', function($id) { $film = Film::findOrFail($id); $film->gesehen = \Carbon\Carbon::today(); $film->save(); return Redirect::to('film/' . $film->id); })); Route::get('register', function() { return View::make('register'); }); Route::post('register', function() { $vrules = array( 'name' => 'required|unique:users', 'email' => 'required|email', 'password' => 'required|confirmed', 'fire' => array('required', 'regex:/^Kreis$/i') ); $vfields = array( 'name' => Input::get('user'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'password_confirmation' => Input::get('pw-confirm'), 'fire' => Input::get('fire') ); $val = Validator::make($vfields, $vrules); if($val->fails()) { return View::make('register')->with('errors', $val->messages()); } else { $u = new User(); $u->name = Input::get('user'); $u->email = Input::get('email'); $u->password = Hash::make(Input::get('password')); $u->save(); return Redirect::to('/')->with('message', 'Registriert!'); } }); Route::get('settings', array('before' => 'auth', function() { return View::make('settings'); })); Route::post('settings/{mode}', array('before' => 'auth', function($mode) { Validator::extend('pass', function($attribute, $value, $parameters) { return Hash::check($value, Auth::user()->password); }); if($mode == 'password') { var_dump(Hash::check(Input::get('oldpw'), Auth::user()->password)); $vfields = array('oldpw' => Input::get('oldpw'), 'newpw' => Input::get('newpw'), 'newpw_confirmation' => Input::get('newpw2')); $vrules = array( 'oldpw' => 'required|pass', 'newpw' => 'required|confirmed' ); $val = Validator::make($vfields, $vrules); if($val->passes()) { $u = Auth::user(); $u->password = Hash::make(Input::get('newpw')); $u->save(); return View::make('settings')->with('message', 'Passwort geändert.'); } else { return View::make('settings')->with('errors', $val->messages()); } } if($mode == 'email') { $vfields = array('pw' => Input::get('pw'), 'email' => Input::get('email'), 'email_confirmation' => Input::get('email2')); $vrules = array('pw' => 'required|pass', 'email' => 'required|confirmed'); $val = Validator::make($vfields, $vrules); if($val->passes()) { $u = Auth::user(); $u->email = Input::get('email'); $u->save(); return View::make('settings')->with('message', 'Email geändert.'); } else { return View::make('settings')->with('errors', $val->messages()); } } })); Route::get('users', array('before' => 'auth', function() { if(Auth::user()->admin) { $u = User::orderBy('name')->paginate(); return View::make('users')->with('users', $u); } else { App::abort(401, 'Diese Seite ist nicht für Dich.'); } })); Route::get('users/{operation}/{id}', array('before' => 'auth', function($operation, $id) { if(!Auth::user()->admin) App::abort(401, 'Diese Seite ist nicht für Dich.'); $u = User::findOrFail($id); switch($operation) { case 'mkadm': $u->admin = true; $u->save(); $msg = $u->name . " ist jetzt ein Admin."; break; case 'rmadm': $u->admin = false; $u->save(); $msg = $u->name . " ist kein Admin mehr."; break; case 'rmusr': $msg = $u->name . " wurde gelöscht."; $u->delete(); break; } return Redirect::to('users')->with('message', $msg); })); Route::get('news', array('before' => 'auth', function() { return View::make('news'); })); Route::post('news', array('before' => 'auth', function() { $vrules = array( 'headline' => 'required', 'body' => 'required' ); $vfields = array( 'headline' => Input::get('headline'), 'body' => Input::get('body') ); $val = Validator::make($vfields, $vrules); if($val->fails()) { return View::make('news')->with('errors', $val->messages()); } else { $n = new News(); $n->author = Auth::user()->id; $n->headline = Input::get('headline'); $n->body = Input::get('body'); $n->save(); return Redirect::to('/')->with('message', 'News erstellt!'); } }));