<?php
require_once '../system/function.php';
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Methods: GET');
$set = $db->query('SELECT * FROM `set`')->fetch_assoc();
$limit = (isset($_GET['limit']) != 0) ? (int)$_GET['limit']: 99999;
$offset = (isset($_GET['offset']) != 0) ? (int)$_GET['offset']: 0;
$get_all = "SELECT * FROM `file` ORDER BY `id` DESC LIMIT $limit OFFSET $offset";
$q = $db->query($get_all) or die();
if ($q->num_rows === 0) {
echo '{
"data": {
"message": "Null Results"
},
"success": false,
"status": 400
}';
exit;
}
$i = 0;
echo '{
"data": [';
while ($a = $q->fetch_assoc()) {
if ($a['del'] != 0) {
$avto = $a['del'] * 86400;
} else {
$avto = $set['del'] * 86400;
}
$a['time_up'] = date($a['time']-$avto);
if ($a['pass'] == 0) {
if ($i > 0) {
echo ', ';
}
echo '{
"id": '.$a['id'].',
"url": "https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'].'",
"name": '.json_encode($a['name'], JSON_UNESCAPED_UNICODE).',
"opis": '.json_encode($a['opis'], JSON_UNESCAPED_UNICODE).',
"file": "https://'.$_SERVER['HTTP_HOST'].'/files/'.$a['file'].'",
"thumbnail": "';if ($a['format'] == 'mp4' or $a['format'] == 'webm') {echo "https://".$_SERVER['HTTP_HOST']."/modules/viewer/video.php?file=".$a['file'];} else {echo "";} echo '",
"load": '.$a['up'].',
"like": '.$a['like'].',
"views": '.$a['views'].',
"comments": '.$db->query('SELECT COUNT(*) FROM `komm` WHERE `file` = '.$a['id'])->fetch_row()[0].',
"format": "'.$a['format'].'",
"time": '.$a['time_up'].',
"time_del": '.$a['time'].',
"author": '.json_encode($a['avtor'], JSON_UNESCAPED_UNICODE).',
"password": false,
"access": '.$a['access'].'
}';
$i++;
} else {
if ($i > 0) {
echo ', ';
}
echo '{
"id": '.$a['id'].',
"url": "https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'].'",
"name": '.json_encode($a['name'], JSON_UNESCAPED_UNICODE).',
"opis": '.json_encode($a['opis'], JSON_UNESCAPED_UNICODE).',
"file": "https://'.$_SERVER['HTTP_HOST'].'/file'.$a['id'].'",
"thumbnail": "",
"load": '.$a['up'].',
"like": '.$a['like'].',
"views": '.$a['views'].',
"comments": '.$db->query('SELECT COUNT(*) FROM `komm` WHERE `file` = '.$a['id'])->fetch_row()[0].',
"format": "locked",
"time": '.$a['time_up'].',
"time_del": '.$a['time'].',
"author": '.json_encode($a['avtor'], JSON_UNESCAPED_UNICODE).',
"password": true,
"access": '.$a['access'].'
}';
$i++;
}
}
echo ']
}';