<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

$link_base = Cache::rememberForever('link_base', function () {
                Cache::increment('total_cached');
                return DB::table('settings')->whereIn('id', [27, 28, 29, 30, 31, 32, 33])->pluck('value', 'name');
});

Route::get('/', 'App\Http\Controllers\SiteController@index');
Route::get("/$link_base[category_base]/{slug}", 'App\Http\Controllers\SiteController@category');
Route::get("/$link_base[platform_base]/{slug}", 'App\Http\Controllers\SiteController@platform');
Route::get("/$link_base[app_base]/random", 'App\Http\Controllers\SiteController@random');
Route::get("/$link_base[tag_base]/{slug}", 'App\Http\Controllers\SiteController@tags');
Route::get('/redirect/{slug}', 'App\Http\Controllers\SiteController@redirect');
Route::get("/$link_base[app_base]/{slug}", 'App\Http\Controllers\SiteController@app');
Route::get("/$link_base[page_base]/{slug}", 'App\Http\Controllers\SiteController@page');
Route::get("/$link_base[news_base]", 'App\Http\Controllers\SiteController@allnews');
Route::get("/$link_base[topic_base]", 'App\Http\Controllers\SiteController@topic');
Route::get("/$link_base[news_base]/{slug}", 'App\Http\Controllers\SiteController@news');
Route::get("/$link_base[topic_base]/{slug}", 'App\Http\Controllers\SiteController@topicitem');
Route::get('/crontab/{slug}', 'App\Http\Controllers\SiteController@crontab');
Route::get('/hourly-crontab/{slug}', 'App\Http\Controllers\SiteController@hourly_crontab');
Route::post('/search', 'App\Http\Controllers\SiteController@search');
Route::get('/rss', 'App\Http\Controllers\RSSController@index');
Route::get('/sitemap.xml', 'App\Http\Controllers\SitemapController@index');
Route::get("/sitemap/$link_base[app_base]", 'App\Http\Controllers\SitemapController@apps');
Route::get("/sitemap/$link_base[page_base]", 'App\Http\Controllers\SitemapController@pages');
Route::get("/sitemap/$link_base[news_base]", 'App\Http\Controllers\SitemapController@news');
Route::get("/sitemap/$link_base[category_base]", 'App\Http\Controllers\SitemapController@categories');
Route::get("/sitemap/$link_base[platform_base]", 'App\Http\Controllers\SitemapController@platforms');
Route::get("/sitemap/$link_base[topic_base]", 'App\Http\Controllers\SitemapController@topics');
Route::get("/sitemap/$link_base[tag_base]", 'App\Http\Controllers\SitemapController@tags');
Route::get('/download/{id}', 'App\Http\Controllers\FileDownloadController@show');
Route::post('/comment', 'App\Http\Controllers\FrontendCommentController@store');
Route::get('/submit-app', 'App\Http\Controllers\SiteController@submission');
Route::post('/submission', 'App\Http\Controllers\FrontendSubmissionController@store');
Route::post('/vote/{id}', 'App\Http\Controllers\VoteController@show');
Route::get('/admin/settings/clear_cache', 'App\Http\Controllers\SettingController@clear_cache');
Route::get('/admin/platforms/order', 'App\Http\Controllers\PlatformController@order');
Route::get('/admin/categories/order', 'App\Http\Controllers\CategoryController@order');
Route::get('/admin/pages/order', 'App\Http\Controllers\PageController@order');
Route::get('/admin/sliders/status/{id}', 'App\Http\Controllers\SliderController@status');
Route::get('/new-apps', 'App\Http\Controllers\SiteController@new_apps');
Route::get('/featured-apps', 'App\Http\Controllers\SiteController@featured_apps');
Route::get('/must-have-apps', 'App\Http\Controllers\SiteController@must_have_apps');
Route::get('/popular-apps-in-last-24-hours', 'App\Http\Controllers\SiteController@popular_apps_24_hours');
Route::post('/admin/topics/details', 'App\Http\Controllers\TopicController@details');
Route::resource('/admin/apps', App\Http\Controllers\ApplicationController::class);
Route::resource('/admin/news', App\Http\Controllers\NewsController::class);
Route::resource('/admin/comments', App\Http\Controllers\CommentController::class);
Route::resource('/admin/scraper', App\Http\Controllers\ScraperController::class);
Route::resource('/admin/categories', App\Http\Controllers\CategoryController::class);
Route::resource('/admin/platforms', App\Http\Controllers\PlatformController::class);
Route::resource('/admin/translations', App\Http\Controllers\TranslationController::class);
Route::resource('/admin/submissions', App\Http\Controllers\SubmissionController::class);
Route::resource('/admin/sliders', App\Http\Controllers\SliderController::class);
Route::resource('/admin/topics', App\Http\Controllers\TopicController::class);
Route::resource('/admin/topic', App\Http\Controllers\TopicItemController::class);
Route::resource('/admin/pages', App\Http\Controllers\PageController::class);
Route::resource('/admin/ads', App\Http\Controllers\AdController::class);
Route::post('/admin/multiple-file-upload/upload', 'App\Http\Controllers\MultipleUploadController@upload')->name('upload');
Route::post('/admin/multiple-file-upload/delete', 'App\Http\Controllers\MultipleUploadController@delete')->name('delete');
Route::get('/admin/settings', 'App\Http\Controllers\SettingController@index');
Route::post('/admin/settings', 'App\Http\Controllers\SettingController@update');
Route::get('/admin/permalinks', 'App\Http\Controllers\SettingController@permalinks');
Route::post('/admin/permalinks', 'App\Http\Controllers\SettingController@permalinksupdate');
Route::get('/admin/scraper_categories', 'App\Http\Controllers\CrawlerController@index');
Route::post('/admin/scraper_categories', 'App\Http\Controllers\CrawlerController@update');
Route::get('/admin/search', 'App\Http\Controllers\ApplicationController@search');
Route::get('/admin/account_settings', 'App\Http\Controllers\HomeController@accountsettingsform');
Route::post('/admin/account_settings', 'App\Http\Controllers\HomeController@accountsettings')->name('accountsettings');
Route::get('/admin', 'App\Http\Controllers\ApplicationController@index');
Route::get('/crawler/{slug}', 'App\Http\Controllers\AppCrawlerController@index');

Auth::routes([
    'login' => true,
    'register' => false,
    'reset' => true,
    'verify' => false,
]);

Route::get('/admin/random_key', function () {
    define('AES_256_CBC', 'aes-256-cbc');
    $encryption_key = openssl_random_pseudo_bytes(32);
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(AES_256_CBC));
    $data = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, 32);
    return openssl_encrypt($data, AES_256_CBC, $encryption_key, 0, $iv);
})->middleware('auth');