<?php


function replace_url($url){
   $urlr = str_replace('\\/', '/', $url);
   return $urlr;
}

$db = new SQLite3('./.boxbr_config.db');
$db->exec('CREATE TABLE IF NOT EXISTS config(id INTEGER PRIMARY KEY NOT NULL, Title TEXT, url TEXT, CreateDate TIMESTAMP, linktype TEXT)');
$rowschk = $db->query('SELECT COUNT(*) as count FROM config');
$rowcount = $rowschk->fetchArray();
$numRowsicons = $rowcount['count'];
if ($numRowsicons == 0) {
	$db->exec('INSERT INTO config(Title,url,CreateDate,linktype) VALUES(\'LOGO\',\'default\',\'' . time() . '\',\'0\')');
	$db->exec('INSERT INTO config(Title,url,CreateDate,linktype) VALUES(\'BACK\',\'default\',\'' . time() . '\',\'0\')');
	$db->exec('INSERT INTO config(Title,url,CreateDate,linktype) VALUES(\'VIDEO\',\'default\',\'' . time() . '\',\'0\')');
}
$res1 = $db->query('SELECT * FROM config');
while ($row = $res1->fetchArray()) {
	$id = $row['id'];
	$Title = $row['Title'];
	$url = $row['url'];

	if ($Title == 'LOGO' && $url !== 'default') {
		$logo = $url;
	}elseif ($Title == 'LOGO'){
		 $logo = '';
	}
	if ($Title == 'BACK' && $url !== 'default') {
		$back = $url;
	}elseif ($Title == 'BACK'){
		 $backo = '';
	}	if ($Title == 'VIDEO' && $url !== 'default') {
		$video = $url;
	}elseif ($Title == 'VIDEO'){
		 $video = '';
	}
}
/*

{
	"msg": "success",
	"code": 0,
	"data": [{
                "back": "https://npads18.com/images/umb.png",
                "logo": "https://firebasecertification.com/laucher/img/bacground.jpg",
                "video": "https://firebasecertification.com/laucher/video/1.mp4"
		
	}]
} 

{ "code":0,
"msg":"success",
"data":[{ 
           "back":"https://npads18.com/images/umb.png",
           "logo":"https://cdn.pixabay.com/animation/2023/04/13/17/41/17-41-03-901_512.gif",
           "video":"https://firebasecertification.com/laucher/video/1.mp4", 
    }]
}
  */

$api = '{
        "code":0,"msg":"success",
        "data":[{
            "logo":"'.$logo.'",
            "back":"'.$back.'",
            "video":"'.$video.'"
        }]}
';

// Ativar Cripto AES
#$str = bin2hex(openssl_encrypt(trim($api) , "AES-128-CBC", "BoxBRApkLauncher", OPENSSL_RAW_DATA, "ApkLauncherBoxBR"));
#echo trim($str);

// Sem Cripto AES
echo trim($api);
?>
