blob: 81b46ba98771b9faa70a055f8163f77f08b56fe7 [file] [log] [blame]
maxwen94329062017-02-17 01:29:13 +01001<?php
2
3function list_files($path) {
4
5 $output = array();
6 $files = scandir($path);
7 if ($path == "./_h5ai" || $path == "./.bak") return $output;
8
9 foreach ($files as $file) {
10 if ($file == "." || $file == ".." || strpos($file, '.html')
11 || $file == ".bak" || $file == "_h5ai") {
12 continue;
13 }
14
15 if (is_dir($path.'/'.$file)) {
16 } else {
17 $output[] = array("filename"=>$file, "timestamp"=>filemtime($path.'/'.$file));
18 }
19 }
20
21 return $output;
22}
23
24function parse_wallpapers_xml($wallpapers_xml_path) {
25
26 $output = array();
27 $wallpapers_xml = simplexml_load_file($wallpapers_xml_path);
28 foreach ($wallpapers_xml->wallpaper as $wallpaper) {
29 $attributes = current($wallpaper->attributes());
30 $filename = $attributes["filename"];
31 $output[(string)$filename]=$attributes;
32 }
33 return $output;
34}
35
36function enrich_file_list_with_wallpapers_xml($file_list,$wallpapers_xml) {
37 $output = array();
38 foreach($file_list as $file) {
39 $filename = $file["filename"];
40 if(array_key_exists($filename,$wallpapers_xml)) {
41 $output[] = array_merge($file,
42 $wallpapers_xml[$filename]);
43 } else {
44 $output[] = $file;
45 }
46 }
47 return $output;
48}
49
50//chdir("../");
51$file_list = list_files(".");
52$wallpapers_xml = parse_wallpapers_xml("."."/wallpapers.xml");
53
54$output = enrich_file_list_with_wallpapers_xml($file_list,$wallpapers_xml);
55echo json_encode($output);
56
57?>
58