changeset 3128:5419fc9cbb15

Merge branch 'vnext' into Dev_main
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 28 Nov 2018 13:52:04 +0000
parents a543efc6ef1d (diff) a8455b0766cd (current diff)
children a21b88d212b6
files
diffstat 10 files changed, 48 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/php/comment_parser.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/comment_parser.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 // Comment Parser for PHP
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
@@ -20,7 +21,8 @@
     }
 }
 // XML Saves location - assumes it will be saves/
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 $comment_struct = array();
 if (is_array($saves))
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php/config.php	Wed Nov 28 13:52:04 2018 +0000
@@ -0,0 +1,16 @@
+<?php
+function getSaveLocation() {
+    if (getenv("WAET_SAVES_LOCATION") !== false) {
+        return getenv("WAET_SAVES_LOCATION");
+    } else {
+        return "../saves/";
+    }
+}
+function getTestLocation() {
+    if (getenv("WAET_TEST_LOCATION") !== false) {
+        return getenv("WAET_TEST_LOCATION");
+    } else {
+        return "../tests/";
+    }
+}
+?>
\ No newline at end of file
--- a/php/get_filtered_count.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/get_filtered_count.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
@@ -33,7 +34,8 @@
 }
 
 $files = array();
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/get_tests.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/get_tests.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
@@ -12,7 +13,8 @@
 
 // XML Saves location - assumes it will be saves/
 $data = array();
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/pool.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/pool.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
@@ -37,7 +38,8 @@
 
 $waet_url = rel2abs("pool.php","http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
 
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/pseudo.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/pseudo.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 header('Access-Control-Allow-Origin: *');
 header("Content-type: text/xml");
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
@@ -16,15 +17,16 @@
 } else {
     $dir = $_GET["dir"];
 }
-
-$files = glob('../saves/' . $prefix . '*.xml');
+$saveLocation = getSaveLocation();
+$files = glob($saveLocation . $prefix . '*.xml');
 $numsaves = 0;
 if ( $files !== false )
 {
     $numsaves = count( $files );
 }
 
-$files = glob('../tests/' . $dir . '*.xml');
+$testLocation = getTestLocation();
+$files = glob($testLocation . $dir . '*.xml');
 $numtests = 0;
 
 if ( $numtests !== false )
--- a/php/requestKey.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/requestKey.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,5 +1,5 @@
 <?php
-
+include_once("config.php");
 function generateRandomString($length = 32) {
     // from http://stackoverflow.com/questions/4356289/php-random-string-generator
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
@@ -57,8 +57,8 @@
         $key = $tempKey;
     }
 }
-
-$filename = "../saves/".$saveFilenamePrefix.$key.".xml";
+$saveLocation = getSaveLocation();
+$filename = $saveLocation.$saveFilenamePrefix.$key.".xml";
 $fileHandle = fopen($filename, 'w');
 if ($fileHandle == FALSE) {
     die("<response><state>ERROR</state><key>".$key."</key><message>Could not open file for writing</message></response>");
--- a/php/save.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/save.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,5 +1,5 @@
 <?php
-
+include_once("config.php");
 function findNodeByAttribute($nodeList, $attributeName, $attributeValue) {
     if (empty($attributeName) || empty($attributeValue)) {
         die("Error: Empty findNodeByAttribute");
@@ -39,10 +39,12 @@
     $update = $_GET["update"] == "update";
 }
 
+$saveLocation = getSaveLocation();
+
 if ($update) {
-    $filename = '../saves/update-'.$saveFilenamePrefix.$file_key.".xml";
+    $filename = $saveLocation.'update-'.$saveFilenamePrefix.$file_key.".xml";
 } else {
-    $filename = '../saves/'.$saveFilenamePrefix.$file_key.".xml";
+    $filename = $saveLocation.$saveFilenamePrefix.$file_key.".xml";
 }
 
 if (!file_exists($filename)) {
@@ -144,6 +146,6 @@
 echo $xml;
 
 if (!$update) {
-    unlink('../saves/update-'.$saveFilenamePrefix.$file_key.".xml");
+    unlink($saveLocation.'update-'.$saveFilenamePrefix.$file_key.".xml");
 }
 ?>
--- a/php/score_parser.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/score_parser.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,4 +1,5 @@
 <?php
+include_once("config.php");
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
@@ -51,7 +52,8 @@
 $root = new nestedObject("root");
 
 // XML Saves location - assumes it will be saves/
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/test_write.php	Wed Nov 28 13:51:51 2018 +0000
+++ b/php/test_write.php	Wed Nov 28 13:52:04 2018 +0000
@@ -1,5 +1,7 @@
 <?php
-$file = "../saves/test-save.xml";
+include_once("config.php");
+$saveLocation = getSaveLocation();
+$file = $saveLocation."test-save.xml";
 $state = file_put_contents($file, "<xml></xml>");
 if ($state == FALSE) {
     echo "<response state=\"error\"><message>Could not open file</message></response>";