2017-09-22 21:24:31 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2018-02-10 01:10:57 +01:00
|
|
|
Copyright 2018 UUP dump API authors
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-29 23:40:56 +02:00
|
|
|
require_once dirname(__FILE__).'/shared/main.php';
|
2017-09-23 17:47:19 +02:00
|
|
|
|
2018-02-10 01:10:57 +01:00
|
|
|
function uupListIds($search = null) {
|
2017-09-23 17:47:19 +02:00
|
|
|
uupApiPrintBrand();
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
if(!file_exists('fileinfo')) return array('error' => 'NO_FILEINFO_DIR');
|
|
|
|
|
|
|
|
$files = scandir('fileinfo');
|
|
|
|
$files = preg_grep('/\.json$/', $files);
|
|
|
|
|
|
|
|
consoleLogger('Parsing database info...');
|
2017-12-13 18:03:52 +01:00
|
|
|
|
2017-10-08 17:10:00 +02:00
|
|
|
$database = @file_get_contents('cache/fileinfo.json');
|
|
|
|
$database = json_decode($database, true);
|
|
|
|
if(empty($database)) $database = array();
|
|
|
|
|
|
|
|
$newDb = array();
|
2017-09-22 21:24:31 +02:00
|
|
|
$builds = array();
|
|
|
|
foreach($files as $file) {
|
|
|
|
if($file == '.' || $file == '..') continue;
|
|
|
|
$uuid = preg_replace('/\.json$/', '', $file);
|
|
|
|
|
2017-10-08 17:10:00 +02:00
|
|
|
if(!isset($database[$uuid])) {
|
|
|
|
$info = @file_get_contents('fileinfo/'.$file);
|
|
|
|
$info = json_decode($info, true);
|
|
|
|
|
|
|
|
$title = isset($info['title']) ? $info['title'] : 'UNKNOWN';
|
|
|
|
$build = isset($info['build']) ? $info['build'] : 'UNKNOWN';
|
|
|
|
$arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN';
|
|
|
|
|
|
|
|
$temp = array(
|
|
|
|
'title' => $title,
|
|
|
|
'build' => $build,
|
|
|
|
'arch' => $arch,
|
|
|
|
);
|
|
|
|
|
2017-12-13 18:03:52 +01:00
|
|
|
$newDb[$uuid] = $temp;
|
2017-10-08 17:10:00 +02:00
|
|
|
} else {
|
|
|
|
$title = $database[$uuid]['title'];
|
|
|
|
$build = $database[$uuid]['build'];
|
|
|
|
$arch = $database[$uuid]['arch'];
|
2017-12-13 18:03:52 +01:00
|
|
|
|
|
|
|
$newDb[$uuid] = $database[$uuid];
|
2017-10-08 17:10:00 +02:00
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
$temp = array(
|
|
|
|
'title' => $title,
|
|
|
|
'build' => $build,
|
|
|
|
'arch' => $arch,
|
|
|
|
'uuid' => $uuid,
|
|
|
|
);
|
|
|
|
|
2017-12-13 18:03:52 +01:00
|
|
|
$tmp = explode('.', $build);
|
2018-08-10 23:55:45 +02:00
|
|
|
if(isset($tmp[1])) {
|
|
|
|
$tmp[0] = str_pad($tmp[0], 10, '0', STR_PAD_LEFT);
|
|
|
|
$tmp[1] = str_pad($tmp[1], 10, '0', STR_PAD_LEFT);
|
|
|
|
$tmp = $tmp[0].$tmp[1];
|
|
|
|
} else {
|
|
|
|
consoleLogger($uuid.'.json appears to be broken and may be useless.');
|
|
|
|
$tmp = 0;
|
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2017-12-13 18:03:52 +01:00
|
|
|
$buildAssoc[$tmp][] = $arch.$title.$uuid;
|
|
|
|
$builds[$tmp.$arch.$title.$uuid] = $temp;
|
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2018-07-19 01:27:40 +02:00
|
|
|
if(empty($buildAssoc)) {
|
|
|
|
return array(
|
|
|
|
'apiVersion' => uupApiVersion(),
|
|
|
|
'builds' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:03:52 +01:00
|
|
|
krsort($buildAssoc);
|
2017-09-22 21:24:31 +02:00
|
|
|
$buildsNew = array();
|
2017-12-13 18:03:52 +01:00
|
|
|
|
|
|
|
foreach($buildAssoc as $key => $val) {
|
|
|
|
sort($val);
|
|
|
|
foreach($val as $id) {
|
|
|
|
$buildsNew[] = $builds[$key.$id];
|
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$builds = $buildsNew;
|
|
|
|
consoleLogger('Done parsing database info.');
|
|
|
|
|
2017-10-10 19:38:04 +02:00
|
|
|
if($newDb != $database) {
|
|
|
|
if(!file_exists('cache')) mkdir('cache');
|
|
|
|
|
|
|
|
$success = @file_put_contents(
|
|
|
|
'cache/fileinfo.json',
|
|
|
|
json_encode($newDb)."\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!$success) consoleLogger('Failed to update database cache.');
|
|
|
|
}
|
2017-10-08 17:10:00 +02:00
|
|
|
|
2018-02-10 01:10:57 +01:00
|
|
|
if($search) {
|
|
|
|
$searchSafe = preg_quote($search, '/');
|
|
|
|
if(preg_match('/^".*"$/', $searchSafe)) {
|
|
|
|
$searchSafe = preg_replace('/^"|"$/', '', $searchSafe);
|
|
|
|
} else {
|
|
|
|
$searchSafe = str_replace(' ', '.*', $searchSafe);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($builds as $key => $val) {
|
|
|
|
$buildString[$key] = $val['title'].' '.$val['build'].' '.$val['arch'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$remove = preg_grep('/.*'.$searchSafe.'.*/i', $buildString, PREG_GREP_INVERT);
|
|
|
|
$removeKeys = array_keys($remove);
|
|
|
|
|
|
|
|
foreach($removeKeys as $value) {
|
|
|
|
unset($builds[$value]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($builds)) {
|
|
|
|
return array('error' => 'SEARCH_NO_RESULTS');
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($remove, $removeKeys, $buildString);
|
|
|
|
}
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
return array(
|
2017-09-23 17:47:19 +02:00
|
|
|
'apiVersion' => uupApiVersion(),
|
2017-09-22 21:24:31 +02:00
|
|
|
'builds' => $builds,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|