omni: online wallpaper scripts
added script "json_wallpapers_xml" that adds info about existing
wallpapers from wallpapers.xml to json
maxwen: Changed json_wallpapers_xml to also inclcude files that have
no entry in wallpapers.xml unless we have some scripting in place
that makes sure we always upload a consistent set
Change-Id: I1e31feaf3d5fdaa24d99b9010746265e6440e7e1
diff --git a/prebuilt/wallpapers/json_wallpapers_xml.php b/prebuilt/wallpapers/json_wallpapers_xml.php
new file mode 100644
index 0000000..81b46ba
--- /dev/null
+++ b/prebuilt/wallpapers/json_wallpapers_xml.php
@@ -0,0 +1,58 @@
+<?php
+
+function list_files($path) {
+
+ $output = array();
+ $files = scandir($path);
+ if ($path == "./_h5ai" || $path == "./.bak") return $output;
+
+ foreach ($files as $file) {
+ if ($file == "." || $file == ".." || strpos($file, '.html')
+ || $file == ".bak" || $file == "_h5ai") {
+ continue;
+ }
+
+ if (is_dir($path.'/'.$file)) {
+ } else {
+ $output[] = array("filename"=>$file, "timestamp"=>filemtime($path.'/'.$file));
+ }
+ }
+
+ return $output;
+}
+
+function parse_wallpapers_xml($wallpapers_xml_path) {
+
+ $output = array();
+ $wallpapers_xml = simplexml_load_file($wallpapers_xml_path);
+ foreach ($wallpapers_xml->wallpaper as $wallpaper) {
+ $attributes = current($wallpaper->attributes());
+ $filename = $attributes["filename"];
+ $output[(string)$filename]=$attributes;
+ }
+ return $output;
+}
+
+function enrich_file_list_with_wallpapers_xml($file_list,$wallpapers_xml) {
+ $output = array();
+ foreach($file_list as $file) {
+ $filename = $file["filename"];
+ if(array_key_exists($filename,$wallpapers_xml)) {
+ $output[] = array_merge($file,
+ $wallpapers_xml[$filename]);
+ } else {
+ $output[] = $file;
+ }
+ }
+ return $output;
+}
+
+//chdir("../");
+$file_list = list_files(".");
+$wallpapers_xml = parse_wallpapers_xml("."."/wallpapers.xml");
+
+$output = enrich_file_list_with_wallpapers_xml($file_list,$wallpapers_xml);
+echo json_encode($output);
+
+?>
+