File: D:/HostingSpaces/SBogers10/franciscaansebeweging.komma.pro/app/Komma/Routes/RouteResolver.php
<?php
namespace Komma\Routes;
class RouteResolver
{
/**
* Resolve route
*
* @return bool
*/
public function resolve()
{
// Return false when we are in the control panel
if($this->isControlPanel()) return false;
\Route::get('/_debugbar/assets/stylesheets', [
'as' => 'debugbar-css',
'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@css'
]);
\Route::get('/_debugbar/assets/javascript', [
'as' => 'debugbar-js',
'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@js'
]);
// Maybe we are receiving an alias
// Check for a REST-route that belongs to this alias and dispatch a new Request
\Route::get(\Request::path(), function ()
{
// Return a 404 when the alias is not found in the database
if( ! $dispatch = $this->dispatchRoute()) \App::abort(404);
return $dispatch;
});
\Route::post(\Request::path(), function ()
{
// Return a 404 when the alias is not found in the database
if( ! $dispatch = $this->dispatchPostRoute()) \App::abort(404);
return $dispatch;
});
//\Route::get('test-searchpage', 'Komma\Search\SearchController@searchPages');
//Project Routes
// \Route::get('projects', 'Komma\Projects\ProjectController@index');
// \Route::get('projects/{projectId}', 'Komma\Projects\ProjectController@show');
//News Routes
// \Route::get('news', 'Komma\Posts\PostController@index');
// \Route::get('news/{newsId}', 'Komma\Posts\PostController@show');
\Route::get('posts', 'Komma\Posts\PostController@index');
\Route::get('posts/{postId}', 'Komma\Posts\PostController@show');
\Route::get('category/{categoryId}', 'Komma\Posts\PostController@category');
// Activities
\Route::get('activities', 'Komma\Activities\ActivityController@index');
\Route::get('activities/{postId}', 'Komma\Activities\ActivityController@show');
// retreats
\Route::get('retreats', 'Komma\Retreats\RetreatController@index');
\Route::get('retreats/{retreatId}', 'Komma\Retreats\RetreatController@show');
// vacancies
\Route::get('vacancies', 'Komma\Vacancies\VacancyController@index');
\Route::get('vacancies/{vacancyId}', 'Komma\Vacancies\VacancyController@show');
// Travels
\Route::get('travels/{travelId}', 'Komma\Travels\TravelController@show');
// Forms
\Route::post('subscribe/process', [
'before' => 'csrf',
'as' => 'subscribe.process',
'uses' => 'Komma\Contact\ContactController@subscribeProcess'
]);
\Route::post('becomeFriend/process', [
'before' => 'csrf',
'as' => 'becomeFriend.process',
'uses' => 'Komma\Contact\ContactController@becomeFriendProcess'
]);
\Route::get('over-de-beweging/lidmaatschap/bedankt-voor-het-inschrijven', ['as' => 'subscribe.success',
'uses' => 'Komma\Contact\ContactController@thanks'
]);
\Route::get('over-de-beweging/vriend-worden/bedankt-voor-het-inschrijven', ['as' => 'becomeFriend.success',
'uses' => 'Komma\Contact\ContactController@thanks'
]);
// Forms
\Route::post('travels/process', [
'before' => 'csrf',
'as' => 'travelSubscribe.process',
'uses' => 'Komma\Contact\ContactController@travelProcess'
]);
\Route::get('reizen/bedankt-voor-het-inschrijven', ['as' => 'travelSubscribe.success',
'uses' => 'Komma\Travels\TravelController@successSubscribe'
]);
// Page Routes
\Route::resource('pages', 'Komma\Pages\PageController');
// Forms
\Route::post('contact/process', [
'before' => 'csrf',
'as' => 'contact.process',
'uses' => 'Komma\Contact\ContactController@contactFormProcess'
]);
\Route::get('contact', ['as' => 'contact.form',
'uses' => 'Komma\Contact\ContactController@contactForm'
]);
\Route::get('contact/succes', ['as' => 'contact.success',
'uses' => 'Komma\Contact\ContactController@thanks'
]);
// \Route::any('trial', [
// 'as' => 'trial.page',
// 'uses' => 'Komma\Contact\ContactController@freeTrialForm']);
//
// \Route::post('trial/process', [
// 'as' => 'trial.process',
// 'uses' => 'Komma\Contact\ContactController@freeTrialProcess'
// ]);
//
// \Route::get('trial/in-use', [
// 'as' => 'trial.in-use',
// 'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
// ]);
// \Route::get('trial/succes', [
// 'as' => 'trial.success',
// 'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
// ]);
//
// \Route::get('trial/error', [
// 'as' => 'trial.error',
// 'uses' => 'Komma\Contact\ContactController@freeTrialSuccess'
// ]);
// \Route::post('setLanguage', 'BaseController@setCurrentLanguage');
// SEO routes
\Route::get('robots.txt', 'Komma\Sitemap\SitemapController@robots');
\Route::get('sitemap.xml', 'Komma\Sitemap\SitemapController@sitemap');
// \Route::get('sitemap', 'Komma\Sitemap\SitemapController@showSitemap');
//404 route for maps in wwwroot
\Route::get('404', 'BaseController@abortPage');
}
/**
* Dispatch new custom event with REST-route
*
* @return mixed
*/
private function dispatchRoute()
{
$requestUri = \Request::path();
// Get route by URI
if( ! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) {
return $this->redirectOldPages($requestUri);
};
// Create get request
$request = \Request::create('/' . $route->rest_route, 'GET');
// Dispatch request
return \Route::dispatch($request);
}
private function dispatchPostRoute()
{
$requestUri = \Request::path();
// Get route by URI
if( ! $route = \DB::table('routes')
->where('route', '=', $requestUri)
->first()
) return false;
if( ! (in_array($route->rest_route, ['contact', 'trial']) || starts_with($route->rest_route, 'photo_albums'))) return false;
// Create get request
$request = \Request::create('/' . $route->rest_route, 'POST');
// Dispatch request
return \Route::dispatch($request);
}
/**
* Check if the routes starts with "KMS"
*
* @return mixed
*/
private function isControlPanel()
{
return \Str::startsWith(\Request::path(), 'kms');
}
/**
* Dispatch Old routes
*
* @return mixed
*/
private function redirectOldPages($requestUri = null)
{
switch ($requestUri){
case 'content/over-de-beweging/lid-worden/317':
return \Redirect::to('over-de-beweging/lidmaatschap', 301);
break;
case 'content/over-de-beweging/vriend-worden/267':
return \Redirect::to('over-de-beweging/vriend-worden', 301);
break;
case 'shop/1':
return \Redirect::to('webshop', 301);
break;
case 'content/links/127':
return \Redirect::to('familie', 301);
break;
case 'content/contact/108':
return \Redirect::to('contact', 301);
break;
case 'content/sitemap/111':
return \Redirect::to('sitemap', 301);
break;
default:
break;
}
if(starts_with($requestUri, ['shop/varia'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/reisgidsen'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/kinderboeken'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/kaarten'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/boeken'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/studies'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/tijdschriften'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['shop/aanmelden'])) return \Redirect::to('webshop', 301);
if(starts_with($requestUri, ['content/publicaties'])) return \Redirect::to('blog', 301);
if(starts_with($requestUri, ['content/activiteiten'])) return \Redirect::to('activiteiten', 301);
if(starts_with($requestUri, ['content/over-de-beweging'])) return \Redirect::to('over-de-beweging', 301);
return false;
}
}