<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for ionCube Encoder)
*
* @ Version			:	4.1.0.1
* @ Author			:	DeZender
* @ Release on		:	29.08.2020
* @ Official site	:	http://DeZender.Net
*
*/
ini_set("display_errors", 0);
require_once "../includes/functions.php";
$db = new SQLite3("./.db.db");
$resT = $db->querySingle("SELECT type FROM type WHERE id=1");
if ($resT == "rt") {
    rt_();
}
if ($resT == "ua") {
    ua_();
}

function ua_(){
	error_reporting(0);
	$db = new SQLite3('./.db.db');
	$note = $db->query('SELECT * FROM ads');

	while ($notes = $note->fetchArray(SQLITE3_ASSOC)) {
		//$data[]['path'] = ['Title' => $notes['Title'], 'path' => $notes['path'], 'CreateDate' => $notes['CreateDate']];
		
		$path[] = array('path'=>$notes['path']);
	}
	
	if($path){
		$data['result'] = 'success';
		$data['data']['vertical']['adds'] = $path;
		$data['data']['vertical']['count'] = count($data['data']['vertical']['adds']);
		
	}else{
		$data['result'] = 'error';
		$data['msg'] = 'No data found in the database';
	}
	echo json_encode($data);
	die();
	
	

/* 
$jdata = json_encode($data);
echo '{"status":true,' . "\r\n\t\t" . '"response":' . "\r\n\t\t" . $jdata . "\r\n\t\t" . '}';
 */
}
	
function rt_()	
{	{
	    $page = file_get_contents("https://www.rottentomatoes.com/browse/movies_in_theaters/?page=1");
    $doc = new DOMDocument();
    $doc->loadHTML($page);
    $divs = $doc->getElementsByTagName("img");
    $id = 0;
    foreach ($divs as $div) {
        if ($div->getAttribute("slot") === "image") {
            $img = urldecode($div->getAttribute("data-src"));
            if ($img != "") {
                $data[] = ["id" => $id, "title" => "FTG_" . $id, "type" => "image", "link" => "", "description" => "FTG", "orderby" => "0", "position" => "horizontal", "extension" => "png", "createdon" => "2022-05-15 03:32:03", "path" => $img, "orignal" => $img, "thumbpath" => $img];
            }
        }
        $id++;
    }
    $jdata = json_encode($data);
    echo "{\t\"result\":\"success\",\r\n\t\t\"data\":{\r\n\t\t\t\"vertical\":{\r\n\t\t\t\t\"adds\":\r\n\t\t\t" . $jdata . ",\r\n\t\t\t\"count\": 5\r\n\t\t\t}\r\n\t\t}\r\n\t}";
}
	echo json_encode($data);
	die();
	
	

/* 
$jdata = json_encode($data);
echo '{"status":true,' . "\r\n\t\t" . '"response":' . "\r\n\t\t" . $jdata . "\r\n\t\t" . '}';
 */
 }
?>