diff options
| author | Max | 2019-05-13 15:50:36 +0200 |
|---|---|---|
| committer | Max | 2019-05-13 15:50:36 +0200 |
| commit | 7149647b729b2aa30d76346a7cc3da37c1c692ca (patch) | |
| tree | b773b7c02a3434ea46d12659302abc586b0fdb7b /app/Http/Controllers | |
| download | kategorischeraperitif-7149647b729b2aa30d76346a7cc3da37c1c692ca.tar.gz | |
Initial commit.
Diffstat (limited to 'app/Http/Controllers')
| -rw-r--r-- | app/Http/Controllers/Auth/ForgotPasswordController.php | 32 | ||||
| -rw-r--r-- | app/Http/Controllers/Auth/LoginController.php | 39 | ||||
| -rw-r--r-- | app/Http/Controllers/Auth/RegisterController.php | 71 | ||||
| -rw-r--r-- | app/Http/Controllers/Auth/ResetPasswordController.php | 39 | ||||
| -rw-r--r-- | app/Http/Controllers/Controller.php | 13 | ||||
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 40 | ||||
| -rw-r--r-- | app/Http/Controllers/LookupController.php | 26 | ||||
| -rw-r--r-- | app/Http/Controllers/OfferController.php | 95 | ||||
| -rw-r--r-- | app/Http/Controllers/RSSController.php | 132 | ||||
| -rw-r--r-- | app/Http/Controllers/SearchController.php | 80 |
10 files changed, 567 insertions, 0 deletions
diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php new file mode 100644 index 0000000..6a247fe --- /dev/null +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -0,0 +1,32 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use Illuminate\Foundation\Auth\SendsPasswordResetEmails; + +class ForgotPasswordController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Password Reset Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling password reset emails and + | includes a trait which assists in sending these notifications from + | your application to your users. Feel free to explore this trait. + | + */ + + use SendsPasswordResetEmails; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest'); + } +} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php new file mode 100644 index 0000000..b2ea669 --- /dev/null +++ b/app/Http/Controllers/Auth/LoginController.php @@ -0,0 +1,39 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use Illuminate\Foundation\Auth\AuthenticatesUsers; + +class LoginController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Login Controller + |-------------------------------------------------------------------------- + | + | This controller handles authenticating users for the application and + | redirecting them to your home screen. The controller uses a trait + | to conveniently provide its functionality to your applications. + | + */ + + use AuthenticatesUsers; + + /** + * Where to redirect users after login. + * + * @var string + */ + protected $redirectTo = '/home'; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest')->except('logout'); + } +} diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php new file mode 100644 index 0000000..f77265a --- /dev/null +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -0,0 +1,71 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\User; +use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\Validator; +use Illuminate\Foundation\Auth\RegistersUsers; + +class RegisterController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Register Controller + |-------------------------------------------------------------------------- + | + | This controller handles the registration of new users as well as their + | validation and creation. By default this controller uses a trait to + | provide this functionality without requiring any additional code. + | + */ + + use RegistersUsers; + + /** + * Where to redirect users after registration. + * + * @var string + */ + protected $redirectTo = '/home'; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest'); + } + + /** + * Get a validator for an incoming registration request. + * + * @param array $data + * @return \Illuminate\Contracts\Validation\Validator + */ + protected function validator(array $data) + { + return Validator::make($data, [ + 'name' => 'required|string|max:255', + 'email' => 'required|string|email|max:255|unique:users', + 'password' => 'required|string|min:6|confirmed', + ]); + } + + /** + * Create a new user instance after a valid registration. + * + * @param array $data + * @return \App\User + */ + protected function create(array $data) + { + return User::create([ + 'name' => $data['name'], + 'email' => $data['email'], + 'password' => bcrypt($data['password']), + ]); + } +} diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php new file mode 100644 index 0000000..cf726ee --- /dev/null +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -0,0 +1,39 @@ +<?php + +namespace App\Http\Controllers\Auth; + +use App\Http\Controllers\Controller; +use Illuminate\Foundation\Auth\ResetsPasswords; + +class ResetPasswordController extends Controller +{ + /* + |-------------------------------------------------------------------------- + | Password Reset Controller + |-------------------------------------------------------------------------- + | + | This controller is responsible for handling password reset requests + | and uses a simple trait to include this behavior. You're free to + | explore this trait and override any methods you wish to tweak. + | + */ + + use ResetsPasswords; + + /** + * Where to redirect users after resetting their password. + * + * @var string + */ + protected $redirectTo = '/home'; + + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('guest'); + } +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php new file mode 100644 index 0000000..03e02a2 --- /dev/null +++ b/app/Http/Controllers/Controller.php @@ -0,0 +1,13 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Foundation\Bus\DispatchesJobs; +use Illuminate\Routing\Controller as BaseController; +use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; + +class Controller extends BaseController +{ + use AuthorizesRequests, DispatchesJobs, ValidatesRequests; +} diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php new file mode 100644 index 0000000..d0ad32d --- /dev/null +++ b/app/Http/Controllers/IndexController.php @@ -0,0 +1,40 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +class IndexController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function showPage(Request $request) { + + + $views = array("whisky", "wodka", "gin", "rum", "misc"); + $query = ""; + + foreach($views as $view) { + if ($query != "") { + $query .= " UNION "; + } + # subquery to get procent, because cheap spirits don't look good + #$query .= "(SELECT name, image_url, spirit_type, spirit_type AS url, spirit_type AS angebotsname, (SELECT MAX(procent) FROM " . $view . "_view) as procent, '' AS linktext FROM ". $view ."_view WHERE original_price > 19.98 AND shop != \"Drankdozijn\" ORDER BY procent DESC LIMIT 1)"; + $query .= "(SELECT name, image_url, spirit_type, spirit_type AS url, spirit_type AS angebotsname, (SELECT MAX(procent) FROM " . $view . "_view) as procent, '' AS linktext FROM ". $view ."_view WHERE original_price > 19.98 ORDER BY procent DESC LIMIT 1)"; + } + $query .= " UNION (SELECT 'Alle Angebote' as name, 'https://angebote.fuselkoenig.de/img/feed-icon-gray.jpg' as image_url, 'RSS-Feeds' as spirit_type, 'feeds' AS url, 'RSS-Feeds' AS angebotsname, (SELECT MAX(procent) FROM all_view) as procent, 'Zu den RSS-Feeds' AS linktext FROM all_view LIMIT 1)"; + + $data = DB::select($query); + + $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + #$data = DB::table('whisky_view')->orderBy('procent', 'DESC')->limit(100)->simplePaginate(20); + + #$views[] = "rss-feeds"; + + return view('fk-index', ['data' => $data, 'views' => $views, 'hits' => $count]); + } +} diff --git a/app/Http/Controllers/LookupController.php b/app/Http/Controllers/LookupController.php new file mode 100644 index 0000000..3a876a9 --- /dev/null +++ b/app/Http/Controllers/LookupController.php @@ -0,0 +1,26 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +use Illuminate\Support\Facades\Input; + +class LookupController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function showPage(Request $request) { + + // Used by external linkshorter for better reporting in web analytics. + $query = "SELECT name, shop, spirit_type FROM all_view WHERE short_url = ? LIMIT 1)"; + + $data = DB::table('all_view')->select('name', 'shop', 'spirit_type')->where('url', "https://l.fuselkoenig.de/" . Input::get('short_url'))->limit(1)->get(); + + return response()->json($data); + } +} diff --git a/app/Http/Controllers/OfferController.php b/app/Http/Controllers/OfferController.php new file mode 100644 index 0000000..9182206 --- /dev/null +++ b/app/Http/Controllers/OfferController.php @@ -0,0 +1,95 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +use Carbon; +use Illuminate\Support\Facades\Input; + +class OfferController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function showPage(Request $request) { + + /* + * Sorting + */ + $sort_by = Input::get("sort"); + switch ($sort_by) { + case("price"): + $sort_by = "discounted_price"; + break; + case("discounted_price"): + $sort_by = "discounted_price"; + break; + case("name"): + $sort_by = "name"; + break; + case("shop"): + $sort_by = "shop"; + break; + case("procent"): + $sort_by = "procent"; + break; + case("time"): + $sort_by = "created_at"; + break; + case("created_at"): + $sort_by = "created_at"; + break; + default: + $sort_by = "created_at"; + break; + } + + $order_by = $request->input("order"); + if ( "asc" != $order_by ) { + $order_by = "desc"; + } + + /* + * Database query + */ + $view_name = \Request::route()->getName(); + #$data = DB::table($view_name . '_view')->whereNotNull('url')->orderBy($sort_by, $order_by)->simplePaginate(10); + $data = DB::table($view_name . '_view')->whereNotNull('url')->orderBy($sort_by, $order_by)->paginate(10); + $count = DB::table($view_name . '_view')->whereNotNull('url')->count(); + + $rss_feed = "/angebote/" . $view_name . "/feed/"; + $query_string = ""; + $query_params = Input::except('page'); + foreach( $query_params as $key => $value) { + $query_string .= "&" . $key . "=" . $value; + } + if ( "search" == $view_name && "" != $query_string ) { + $query_string = ltrim($query_string, "&"); + $rss_feed .= "?" . $query_string; + } + + if ( "misc" == $view_name ) { + $view_name = "Andere Angebote"; + if ( $data->count() ) { + $title = "andere Angebote"; + } else { + $title = "anderen Angebote"; + } + } else if ( "all" == $view_name ) { + $view_name = "Alle Angebote"; + if ( $data->count() ) { + $title = "alle Angebote"; + } else { + $title = "Angebote"; + } + } else { + $title = ucfirst($view_name) . "-Angebote"; + } + + return view('fk-offer', ['data' => $data, 'count' => $count, 'spirit_type' => $view_name, 'rss_feed' => $rss_feed, 'title' => $title ]); + } +} diff --git a/app/Http/Controllers/RSSController.php b/app/Http/Controllers/RSSController.php new file mode 100644 index 0000000..5c30bd9 --- /dev/null +++ b/app/Http/Controllers/RSSController.php @@ -0,0 +1,132 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +use Carbon; +use Illuminate\Support\Facades\Input; +use App\Libraries\Utility; + +class RSSController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function showPage(Request $request) { + + /* + * Sorting + */ + $sort_by = Input::get("sort"); + switch ($sort_by) { + case("price"): + $sort_by = "discounted_price"; + break; + case("discounted_price"): + $sort_by = "discounted_price"; + break; + case("name"): + $sort_by = "name"; + break; + case("shop"): + $sort_by = "shop"; + break; + case("procent"): + $sort_by = "procent"; + break; + case("time"): + $sort_by = "created_at"; + break; + case("created_at"): + $sort_by = "created_at"; + break; + default: + $sort_by = "created_at"; + break; + } + + $order_by = $request->input("order"); + if ( "asc" != $order_by ) { + $order_by = "desc"; + } + + /* + * Database query + */ + $view_name = str_replace("_feed", "", \Request::route()->getName()); + $view_name = str_replace("/angebote/", "", $view_name); + + if ( "search" == $view_name ) { + $query = Input::get("q"); + $q = "%" . Utility::escapeLike($query) . "%"; + $data = DB::table('all_view')->whereNotNull('url')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orderBy($sort_by, $order_by)->limit(20)->get(); + } else { + $data = DB::table($view_name . '_view')->orderBy($sort_by, $order_by)->limit(20)->get(); + } + + /* + * For strftime(). + */ + setlocale(LC_TIME, 'de_DE.utf8'); + + /* + if ( "" != env('PIWIK_RSS_ID') ) { + $piwik = new \PiwikTracker( env('PIWIK_RSS_ID'), env('PIWIK_RSS_URL') ); + $piwik->setTokenAuth( env('PIWIK_RSS_AUTH_TOKEN') ); + $piwik->setVisitorId( $piwik->getVisitorId() ); + $piwik->setIp( $request->header('X_REAL_IP') ); + $piwik->setUrl( $request->fullUrl() ); + + $piwik->setUrlReferrer( $request->server('HTTP_REFERER') ); + $piwik->setBrowserLanguage( $request->server('HTTP_ACCEPT_LANGUAGE') ); + $piwik->setUserAgent( $request->server('HTTP_USER_AGENT') ); + + $piwik->doTrackPageView( ucfirst($view_name) . "-Feed" ); + + if ( "" != Input::get('sort') ) { + $piwik->doTrackEvent("sort", Input::get('sort') ); + } + if ( "" != Input::get('order') ) { + $piwik->doTrackEvent("order", Input::get('order') ); + } + if ( "" != Input::get('q') ) { + $piwik->doTrackEvent("search_phrase", Input::get('q') ); + } + } + */ + + + + $feed = \App::make("feed"); + + $feed->title = "Sonderangebote"; + $feed->description = 'Finde immer die günstigsten Angebote im Bereich Spirituosen. Regelmäßig neue Schnäppchen.'; + $feed->logo = url('https://angebote.fuselkoenig.de/img/paw-400-400.png'); + $feed->link = url( $request->fullUrl() ); + $feed->setDateFormat('timestamp'); // 'datetime', 'timestamp' or 'carbon' + $feed->pubdate = $data[0]->created_at; + $feed->lang = 'de'; + $feed->setShortening(true); // true or false + $feed->setTextLimit(5000); // maximum length of description text + + foreach ( $data as $offer ) { + + # Adds campagin + $offer->url = $offer->url . "?pk_campaign=feed&pk_kwd=" . urlencode($offer->name) . "&pk_source=" . $view_name . "_feed"; + + if ( "" != env('PIWIK_RSS_ID') ) { + // $piwik->doTrackContentImpression($offer->spirit_type, $offer->name, $offer->long_url); + } + + $desc = '<p><img src="'.$offer->image_url.'"></p><p><strong>'.$offer->spirit_type.'</strong><br>'. $offer->name . ' gesenkt auf <strong>' . \TF::fF($offer->discounted_price) . '€</strong> statt ' . \TF::fF($offer->original_price) . '€ ('.$offer->procent.'% Rabatt auf '. $offer->shop .').'; + $feed->add($offer->name, $offer->shop, $offer->url, $offer->created_at, $desc, $desc); + } + + return $feed->render('atom'); + + } +} diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php new file mode 100644 index 0000000..5092f30 --- /dev/null +++ b/app/Http/Controllers/SearchController.php @@ -0,0 +1,80 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +use Illuminate\Support\Facades\Input; + +use App\Libraries\Utility; + +class SearchController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function showPage(Request $request) { + + /* + * Sorting + */ + $sort_by = Input::get("sort"); + switch ($sort_by) { + case("price"): + $sort_by = "discounted_price"; + break; + case("discounted_price"): + $sort_by = "discounted_price"; + break; + case("name"): + $sort_by = "name"; + break; + case("shop"): + $sort_by = "shop"; + break; + case("procent"): + $sort_by = "procent"; + break; + case("time"): + $sort_by = "created_at"; + break; + case("created_at"): + $sort_by = "created_at"; + break; + default: + $sort_by = "created_at"; + break; + } + + $order_by = $request->input("order"); + if ( "desc" != $order_by ) { + if ( "created_at" == $sort_by &&"asc" != $order_by ) { + $order_by = "desc"; + } else { + $order_by = "asc"; + } + } + + $query = Input::get("q"); + $q = "%" . Utility::escapeLike($query) . "%"; + $data = DB::table('all_view')->whereNotNull('url')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orWhere('shop', 'like', $q)->orderBy($sort_by, $order_by)->paginate(20); + $count = DB::table('all_view')->whereNotNull('url')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orWhere('shop', 'like', $q); + + $query_string = ""; + $query_params = Input::except('page'); + foreach( $query_params as $key => $value) { + $query_string .= "&" . $key . "=" . $value; + } + $query_string = ltrim($query_string, "&"); + + /* + * For strftime() in view. + */ + #setlocale(LC_TIME, 'de_DE.utf8'); + + return view('fk-search', ['data' => $data, 'count' => $count, 'search_phrase' => $query, 'rss_feed' => '/angebote/search/feed/?' . $query_string ]); + } +} |
