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/create_thumbs.sh b/prebuilt/wallpapers/create_thumbs.sh
new file mode 100755
index 0000000..03cf599
--- /dev/null
+++ b/prebuilt/wallpapers/create_thumbs.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ ! -d "thumbs" ]; then
+    mkdir "thumbs"
+    cp json.php "thumbs"
+fi
+
+for file in `ls *.png`
+do
+    convert $file -resize 300 "thumbs/$file"
+done
+
+for file in `ls *.jpg`
+do
+    convert $file -resize 300 "thumbs/$file"
+done
diff --git a/prebuilt/wallpapers/json.php b/prebuilt/wallpapers/json.php
new file mode 100644
index 0000000..1418c78
--- /dev/null
+++ b/prebuilt/wallpapers/json.php
@@ -0,0 +1,30 @@
+<?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;
+}
+
+//chdir("../");
+echo json_encode(list_files("."));
+
+
+
+
+?>
+
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);
+
+?>
+
diff --git a/prebuilt/wallpapers/upload.sh b/prebuilt/wallpapers/upload.sh
new file mode 100644
index 0000000..fa939fd
--- /dev/null
+++ b/prebuilt/wallpapers/upload.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+scp -P 9122 -i common *.jpg omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/
+scp -P 9122 -i common *.png omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/
+scp -P 9122 -i common thumbs/*.jpg omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/thumbs
+scp -P 9122 -i common thumbs/*.png omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/thumbs
+scp -P 9122 -i common json_wallpapers_xml.php omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/thumbs
+scp -P 9122 -i common wallpapers.xml omnirom@207.244.74.108:/var/www/dl.omnirom.org/images/wallpapers/thumbs
diff --git a/prebuilt/wallpapers/wallpapers.xml b/prebuilt/wallpapers/wallpapers.xml
new file mode 100644
index 0000000..ffc69f7
--- /dev/null
+++ b/prebuilt/wallpapers/wallpapers.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--  Copyright (C) 2017 The OmniROM Project
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<wallpapers>
+    <wallpaper filename="wall01.png" creator="PartimusPrime" name="Default" />
+    <wallpaper filename="wall02.png" />
+    <wallpaper filename="wall03.png" />
+    <wallpaper filename="wall04.png" />
+    <wallpaper filename="wall05.png" />
+    <wallpaper filename="wall06.png" />
+    <wallpaper filename="wall07.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall08.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall09.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall10.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall11.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall12.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall13.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall14.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall15.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall16.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall17.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall18.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall19.jpg" creator="JP Kenji" />
+    <wallpaper filename="wall20.jpg" creator="JP Kenji" />
+    <wallpaper filename="2.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="3.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="4.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="5.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="6.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="7.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="8.jpg" creator="Siddharth Gupta" />
+    <wallpaper filename="Omni1.jpg" creator="JayRod" />
+    <wallpaper filename="Omni2.jpg" creator="JayRod" />
+    <wallpaper filename="Omni3.jpg" creator="JayRod" />
+    <wallpaper filename="Omni4.jpg" creator="JayRod" />
+    <wallpaper filename="Omni5.jpg" creator="JayRod" />
+    <wallpaper filename="Omni12.jpg" creator="JayRod" />
+    <wallpaper filename="Omni13.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021317.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021417.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_02172017_1.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_1.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_2.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_3.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_4.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_5.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_6.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_021917_7.jpg" creator="JayRod" />
+    <wallpaper filename="Omni_02192017.jpg" creator="JayRod" />
+</wallpapers>