# HG changeset patch # User Matti Hamalainen # Date 1351070688 -10800 # Node ID c553ad61e9c26879d2a3cb87cbe9dc333c55748e # Parent 8501f1b9bba374ba6cf420a487623aa4dd293ca7 Make original data links work for both current and next period mode. diff -r 8501f1b9bba3 -r c553ad61e9c2 index.php --- a/index.php Wed Oct 24 12:00:53 2012 +0300 +++ b/index.php Wed Oct 24 12:24:48 2012 +0300 @@ -8,8 +8,8 @@ $pageCharset = "utf-8"; $internalCharset = "utf-8"; $classDefault = "TTE9SNO"; -$classFile = "classes.txt"; -$cacheFile = "coursecache.txt"; +$classIDFile = "classes.txt"; +$courseCacheFile = "coursecache.txt"; $baseURI = "http://tnsp.org/luk/"; $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); @@ -237,6 +237,8 @@ // Check given parameters +$mobileMode = isset($_GET["mobile"]) || isset($_COOKIE["lukmobile"]); + if (isset($_GET["luokka"])) { $luokka = $_GET["luokka"]; @@ -280,12 +282,17 @@ if (isset($_GET["next"])) { $nextPeriod = TRUE; - $dataFile = "cache-next/".$luokka.".data"; + $cachePath = "cache-next/"; } else { $nextPeriod = FALSE; - $dataFile = "cache/".$luokka.".data"; + $cachePath = "cache/"; +} + +if (file_exists($cachePath."baseuri.data")) +{ + require $cachePath."baseuri.data"; } @@ -294,12 +301,12 @@ $cacheDirty = FALSE; // Try to read cachefile, if we can get file lock on it -$fp = @fopen($cacheFile, "rb"); +$fp = @fopen($courseCacheFile, "rb"); if ($fp) { if (flock($fp, LOCK_SH)) { - require($cacheFile); + require($courseCacheFile); flock($fp, LOCK_UN); } fclose($fp); @@ -308,7 +315,7 @@ // Read classfile $classes = array(); -$fp = @fopen($classFile, "rb"); +$fp = @fopen($classIDFile, "rb"); if ($fp) { if (flock($fp, LOCK_SH)) @@ -329,6 +336,7 @@ } +$dataFile = $cachePath.$luokka.".data"; if (!file_exists($dataFile)) { errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ". @@ -432,7 +440,7 @@ " - ".lukMsg("Original")." + ".lukMsg("Original")." ". ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))." @@ -486,7 +494,7 @@ if ($cacheDirty) { $str = ""; - if (file_put_contents($cacheFile, $str, LOCK_EX) === FALSE) { + if (file_put_contents($courseCacheFile, $str, LOCK_EX) === FALSE) { // Can't do much anything here .. } } diff -r 8501f1b9bba3 -r c553ad61e9c2 update.sh --- a/update.sh Wed Oct 24 12:00:53 2012 +0300 +++ b/update.sh Wed Oct 24 12:24:48 2012 +0300 @@ -15,12 +15,13 @@ createdir "${OLDCACHEDIR}" createdir "${CACHEDIR}" - URLPREFIX="$1" CLASSFILE="$2" LISTFILE="$2.tmp" PATPREFIX="$3" +echo "" > "${CACHEDIR}baseuri.data"; + if wget -q -O "$LISTFILE" "$URLPREFIX"; then perl -ne "if (//) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE" echo -n "* Fetched classfile $CLASSFILE: "