<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::pattern('page', '[0-9]+');

// **********	LOADMORE ROUTE *********//
Route::get('/loadmore/{pageNumber}', 'HomeController@loadmore');
Route::get('/loadmoredownload/{pageNumber}', 'DownloadController@loadmore');
Route::get('/loadmorecategories/{pageNumber}/{url_slug}', 'CategoriesController@loadmore');

// **********	HOME/ROOT ROUTE *********//
Route::get('/{page?}', 'HomeController@home');
Route::get('/home', 'HomeController@home');
Route::get('/latest', 'HomeController@home');
Route::get('/popular', 'HomeController@popular');
Route::post('/like/{id}', 'HomeController@like');
Route::post('/search', 'HomeController@seacrh');
Route::get('/rss', 'HomeController@rss');

// **********	AUTHENTICATION ROUTE *********//
Route::controllers([
	'auth' => 'Auth\AuthController',
	'password' => 'Auth\PasswordController',
]);

// **********	DOWNLOAD ROUTES  ********** //
Route::get('/downloadpage/{id}', [
    'as' => 'downloadpage', 'uses' => 'DownloadController@index'
]);
Route::get('/countdownload/{id}', [
    'as' => 'countdownload', 'uses' => 'DownloadController@countdownload'
]);
Route::get('/imgdownload/{id}', [
    'as' => 'imgdownload', 'uses' => 'DownloadController@download'
]);
Route::get('/afterdownload/{id}', [
    'as' => 'afterdownload', 'uses' => 'DownloadController@afterdownload'
]);

Route::get('/tags/{tagname}', 'TagsController@tags');

Route::get('/category/{url_slug}', 'CategoriesController@showcategory');

// **********	ABOUT ROUTES  ********** //
Route::get('/about', [
	'as' => 'about', 'uses' => 'AboutController@index'
]);

// **********	CONTACT ROUTES  ********** //
Route::get('/contact', [
	'as' => 'contact', 'uses' => 'ContactController@index'
]);
Route::post('/sendcontact', 'ContactController@sendcontact');

// **********	ADMIN ROUTES  ********** //
Route::group(array('middleware' => 'auth'), function(){

	Route::get('admin', 'AdminController@index');

	// ***  Media Route  *** //
	Route::get('/admin/media', [
		'as' => 'media', 'uses' => 'AdminController@media'
	]);
	Route::get('/admin/media/add', 'AdminController@showaddmedia');
	Route::post('/admin/media/add', 'AdminController@addnewmedia');
	Route::get('/admin/media/edit/{slug}', [
		'as' => 'editmedia', 'uses' => 'AdminController@showeditmedia'
	]);
	Route::post('/admin/media/edit/{slug}', 'AdminController@editmedia');
	//Route::get('/admin/delete/{id}', 'AdminController@delete');
	Route::get('/admin/delete/{id}', [
		'as' => 'mediadelete', 'uses' => 'AdminController@delete'
	]);
	// ***  About Route  *** //

	Route::get('/admin/about', [
		'as' => 'about', 'uses' => 'AdminController@showadminabout'
	]);
	Route::post('/admin/about', 'AdminController@updateabout');

	// ***  Settings Route  *** //
	Route::get('/admin/settings', [
		'as' => 'settings', 'uses' => 'AdminController@showsettings'
	]);
	Route::post('/admin/settings', 'AdminController@postsettings');

	// ***  Categories Route  *** //
	Route::get('/admin/categories', [
		'as' => 'getcategories', 'uses' => 'AdminController@showcategories'
	]);
	Route::post('/admin/categories', 'AdminController@addcategory');
	Route::get('/admin/category/edit/{url_slug}', 'AdminController@showcategory');
	Route::post('/admin/category/edit/{id}', 'AdminController@editcategory');
	Route::get('/admin/category/delete/{id}', 'AdminController@deletecategory');
});

$admin_reset_route = env('RESET_ADMIN', false);

if($admin_reset_route):

	Route::get('reset_admin', function(){
		$user = App\User::where('name', '=', 'admin')->first();
		$user->email = 'admin@admin.com';
		$user->password = Hash::make('password');

		$user->save();
		echo 'Admin login has been reset to default values. Be sure to turn off the RESET_ADMIN route in your .env file :) Thanks.';
	});

else:
	Route::get('reset_admin', function(){
		return Redirect::to('/');
	});
endif;
