<?php
require_once __DIR__ . '/config/init.php';
$Template = realpath(__DIR__ . '/templates/' . TEMPLATE);
$request_uri = getURL();
$request_path = $request_uri;
$ADS_NETWORK = 'DEFAULT';
if ($Ads = $db->where('ads_url', $request_path)->getOne('adschanger', 'ads_network')) {
    if ($Ads['ads_network'] != 'OFF') {
        $ADS_NETWORK = $Ads['ads_network'];
    }
} else {
    $ADS_NETWORK = DEFAULT_ADS;
}
$AppProtocol = (APP_HTTPS == 1) ? 'https://' : 'http://';
$endRoute  = ROUTE_END;
$AdsPath = __DIR__ . '/templates/ads/' . $ADS_NETWORK;
$categoryExp = '/\/(categorie|album)\/([a-z0-9-]+)' . $endRoute . '$/'; // category Expression
$catExp_page = '/\/(categorie|album)\/([0-9]+)\/([a-z0-9-]+)' . $endRoute . '$/';

$artistExp = '/\/artist\/([a-z0-9-]+)' . $endRoute . '$/i';
$artistExp_page = '/artist\/([0-9]+)\/([a-z0-9-]+)' . $endRoute . '$/';

$allcollectionlist = '/\/(artists)\/([0-9]+)\/([a-z0-9-]+)' . $endRoute . '$/';

$fileExp = '/\/tonuri\/([a-z0-9-]+)' . $endRoute . '$/';
$downloadPageExp = "/\/download\/([a-z0-9-]+)$/"; // Download Page Lang Code;
$searchPageExp = "/\/search\/list$/"; // Download Page Lang Code;
$PageExp = '/\/page\/([a-z0-9-]+)'. $endRoute. '$/';; // Page Lang Code;

$profileExp = '/\/user\/([a-z0-9-]+)' . $endRoute . '$/';
$uploadExp = '/\/upload' . $endRoute . '$/';
$browseExp = '/\/browse' . $endRoute . '$/';


$speExp_page = '/\/musics\/([0-9]+)\/([a-z0-9-]+)' . $endRoute . '$/';
$homeExp = '/' . BASE_URL . '$/i';
$output = array();
$output2 = array();
if (preg_match($homeExp, $request_path, $output)) {
    require __DIR__ . '/controller/Home.php';
} else if (preg_match($categoryExp, $request_path, $output) || preg_match($catExp_page, $request_path, $output2)) {
    require __DIR__ . '/controller/Category.php';
} else if (preg_match($fileExp, $request_path, $output)) {
    require __DIR__ . '/controller/File.php';
} else if (preg_match($artistExp, $request_path, $output) || preg_match($artistExp_page, $request_path, $output2)) {
    require __DIR__ . '/controller/Artist.php';
} else if (preg_match($speExp_page, $request_path, $output)) {
    require __DIR__ . '/controller/AllSongs.php';
} else if (preg_match($allcollectionlist, $request_path, $output)) {
    require __DIR__ . '/controller/AllCollection.php';
} else if (preg_match($searchPageExp, $request_path, $output)) {
    require __DIR__ . '/controller/Search.php';
} else if (preg_match($downloadPageExp, $request_path, $output)) {
    require __DIR__ . '/controller/DownloadFile.php';
} else if (preg_match($PageExp, $request_path, $output)) {
    require __DIR__ . '/controller/Page.php';
} else if (preg_match($browseExp, $request_path, $output)) {
    require __DIR__ . '/controller/Browse.php';
} else if (preg_match($profileExp, $request_path, $output)) {
    require __DIR__ . '/controller/Profile.php';
} else if (preg_match($uploadExp, $request_path, $output)) {
    require __DIR__ . '/controller/Upload.php';
} else if (preg_match('/\/ajax$/', $request_path, $output)) {
    require __DIR__ . '/controller/Ajax.php';
} else if (preg_match('/\/account$/', $request_path, $output)) {
    require __DIR__ . '/controller/Account.php';
} else {
    if (ERROR_PAGE == true) {
        require __DIR__ . '/controller/ErrorPage.php';
    } else {
        Redirect(APP_URL);
    }
}
$db->disconnect();
