Mercurial > hg > lukkari
comparison index.php @ 121:a6af6538777a
Add "last updated" timestamps and version stuff.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Feb 2014 12:28:03 +0200 |
parents | 807c7b90386d |
children | ad7ccdd904b7 |
comparison
equal
deleted
inserted
replaced
120:807c7b90386d | 121:a6af6538777a |
---|---|
5 // Yes, this code is rather horrible. :| | 5 // Yes, this code is rather horrible. :| |
6 // | 6 // |
7 // Include framework | 7 // Include framework |
8 require "mcommon.inc.php"; | 8 require "mcommon.inc.php"; |
9 | 9 |
10 $pageVersion = "2.2"; | |
10 $baseURI = "http://tnsp.org/luk/"; | 11 $baseURI = "http://tnsp.org/luk/"; |
11 $pageLang = "fi"; | 12 $pageLang = "fi"; |
12 $pageLanguages = array("fi", "en"); | 13 $pageLanguages = array("fi", "en"); |
13 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); | 14 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); |
14 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3", "dark" => "4"); | 15 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3", "dark" => "4"); |
33 "contact" => array( | 34 "contact" => array( |
34 "en" => "Contact <b>%1</b> tai <b>%2</b>. The author can't be held responsible for any errors in the data!", | 35 "en" => "Contact <b>%1</b> tai <b>%2</b>. The author can't be held responsible for any errors in the data!", |
35 "fi" => "Yhteydenotot <b>%1</b> tai <b>%2</b>. En vastaa mahdollisista virheistä tiedoissa!", | 36 "fi" => "Yhteydenotot <b>%1</b> tai <b>%2</b>. En vastaa mahdollisista virheistä tiedoissa!", |
36 ), | 37 ), |
37 | 38 |
38 "advert" => array( | 39 "updated" => array( |
39 "en" => "<a href=\"https://www.hdd.fi/\">hdd.fi - Affordable remote disk space</a>", | 40 "en" => "Last updated: <b>%1</b>.", |
40 "fi" => "<a href=\"https://www.hdd.fi/\">hdd.fi - Edullista etälevytilaa</a>", | 41 "fi" => "Päivitetty: <b>%1</b>.", |
41 ), | 42 ), |
42 | 43 |
43 "beta" => array( | 44 "beta" => array( |
44 "en" => " NOTICE! Lukkari v2.1 is still under development. There may be bugs.", | 45 "en" => " NOTICE! Lukkari v%1 is still under development. There may be bugs.", |
45 "fi" => " HUOM! Lukkari v2.1 on vielä kehityksen alla. Bugeja voi löytyä.", | 46 "fi" => " HUOM! Lukkari v%1 on vielä kehityksen alla. Bugeja voi löytyä.", |
46 ), | 47 ), |
47 | 48 |
48 "viikossa" => array( | 49 "viikossa" => array( |
49 "en" => "Total of <b>%1</b> hours in the week.", | 50 "en" => "Total of <b>%1</b> hours in the week.", |
50 "fi" => "Viikossa yhteensä <b>%1</b> tuntia.", | 51 "fi" => "Viikossa yhteensä <b>%1</b> tuntia.", |
238 } | 239 } |
239 return 0; | 240 return 0; |
240 } | 241 } |
241 | 242 |
242 | 243 |
243 function lukReadClassFile($filename) | 244 function lukReadClassFile($filename, &$mtimestamp) |
244 { | 245 { |
245 // Attempt to open file for reading | 246 // Attempt to open file for reading |
246 if (($fp = @fopen($filename, "rb")) === false) | 247 if (($fp = @fopen($filename, "rb")) === false) |
247 return false; | 248 return false; |
248 | 249 |
249 $classes = FALSE; | 250 $mtimestamp = filemtime($filename); |
251 $mclasses = FALSE; | |
250 | 252 |
251 // Lock file so that we do not get clashes | 253 // Lock file so that we do not get clashes |
252 if (flock($fp, LOCK_SH)) | 254 if (flock($fp, LOCK_SH)) |
253 { | 255 { |
254 $classes = array(); | 256 $mclasses = array(); |
255 // Read and parse data | 257 // Read and parse data |
256 while (!feof($fp)) | 258 while (!feof($fp)) |
257 { | 259 { |
258 $str = trim(fgets($fp, 128)); | 260 $str = trim(fgets($fp, 128)); |
259 if (strlen($str) > 2 && $str[0] != "#") | 261 if (strlen($str) > 2 && $str[0] != "#") |
260 $classes[] = $str; | 262 $mclasses[] = $str; |
261 } | 263 } |
262 | 264 |
263 // Release lock | 265 // Release lock |
264 flock($fp, LOCK_UN); | 266 flock($fp, LOCK_UN); |
265 } | 267 } |
266 | 268 |
267 fclose($fp); | 269 fclose($fp); |
268 return $classes; | 270 return $mclasses; |
269 } | 271 } |
270 | 272 |
271 | 273 |
272 // Check given parameters | 274 // Check given parameters |
273 // Language must be the first setting to be validated, | 275 // Language must be the first setting to be validated, |
391 $lastDay = $currDay + 1; | 393 $lastDay = $currDay + 1; |
392 } | 394 } |
393 else | 395 else |
394 { | 396 { |
395 $out = | 397 $out = |
396 "<p>".join("; ", $classInfo["general"])."</p>\n". | 398 "<p>".join("; ", $classInfo["general"])." [".cmQM("viikossa", $classInfo["totalHours"])."]</p>\n". |
397 "<div>".cmQM("viikossa", $classInfo["totalHours"])."</div>\n". | |
398 "<table class=\"timetable\">". | 399 "<table class=\"timetable\">". |
399 " <tr>\n <th></th>\n"; | 400 " <tr>\n <th></th>\n"; |
400 | 401 |
401 $cellWidth = $classInfo["maxDays"] > 0 ? 100 / $classInfo["maxDays"] : 15; | 402 $cellWidth = $classInfo["maxDays"] > 0 ? 100 / $classInfo["maxDays"] : 15; |
402 if ($cellWidth > 25) $cellWidth = 25; | 403 if ($cellWidth > 25) $cellWidth = 25; |
457 // | 458 // |
458 // Main code starts | 459 // Main code starts |
459 // | 460 // |
460 | 461 |
461 // Read classfile | 462 // Read classfile |
462 if (($classes = lukReadClassFile($classIDFile)) === false) | 463 if (($classes = lukReadClassFile($classIDFile, &$timestamp)) === false) |
463 stError(stQM("classListNotFound")); | 464 stError(stQM("classListNotFound")); |
464 | 465 |
465 // Read class data | 466 // Read class data |
466 $dataFile = $cachePath.$luokka.".data"; | 467 $dataFile = $cachePath.$luokka.".data"; |
467 if (!file_exists($dataFile)) | 468 if (!file_exists($dataFile)) |
472 else | 473 else |
473 { | 474 { |
474 require($dataFile); | 475 require($dataFile); |
475 $haveData = isset($classInfo); | 476 $haveData = isset($classInfo); |
476 } | 477 } |
478 | |
477 | 479 |
478 // Set some variables | 480 // Set some variables |
479 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; | 481 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka; |
480 | 482 |
481 $extra = ""; | 483 $extra = ""; |
520 $currURL = $baseURI."?luokka=".$luokka."&lang=".$pageLang. | 522 $currURL = $baseURI."?luokka=".$luokka."&lang=".$pageLang. |
521 (isset($pageCSSIndex) ? "&css=".$pageCSSIndex : ""). | 523 (isset($pageCSSIndex) ? "&css=".$pageCSSIndex : ""). |
522 ($nextPeriod ? "&next" : ""); | 524 ($nextPeriod ? "&next" : ""); |
523 | 525 |
524 echo | 526 echo |
527 " <th class=\"advert\"><a href=\"http://tnsp.org/u/HXh\"><img src=\"img/cell.png\" alt=\"Division Cell\" /></a></th>\n". | |
525 " <th><a href=\"".$currURL."\" title=\"".cmQM("currLukLink")."\">Link</th>\n". | 528 " <th><a href=\"".$currURL."\" title=\"".cmQM("currLukLink")."\">Link</th>\n". |
526 " </tr>\n". | 529 " </tr>\n". |
527 " </table>\n". | 530 " </table>\n". |
528 "</form>\n". | 531 "</form>\n". |
529 "<h1>".$pageTitle."</h1>\n". | 532 "<h1>".$pageTitle."</h1>\n"; |
530 "<div class=\"advert\">".cmQM("advert")."</div>\n"; | |
531 | 533 |
532 // Show error messages | 534 // Show error messages |
533 if ($errorSet) | 535 if ($errorSet) |
534 { | 536 { |
535 echo "<ul>\n"; | 537 echo "<ul>\n"; |
544 } | 546 } |
545 | 547 |
546 echo | 548 echo |
547 "<div id=\"footer\">". | 549 "<div id=\"footer\">". |
548 cmQM("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). | 550 cmQM("contact", "ccr @ IRCNet", "ccr (at) tnsp (dot) org"). |
549 //" <div style=\"color: red;\">".cmQM("beta")."</div>\n". | 551 " / ". |
552 cmQM("updated", strftime("%m.%d.%Y, %H:%M", $timestamp)). | |
553 //" <div style=\"color: red;\">".cmQM("beta", $pageVersion)."</div>\n". | |
550 "</div>\n"; | 554 "</div>\n"; |
551 | 555 |
552 if (!$mobileMode) | 556 if (!$mobileMode) |
553 { | 557 { |
554 echo | 558 echo |
555 "<div id=\"csssel\">\n". | 559 "<div id=\"csssel\">\n". |
556 " <div id=\"ctitle\">Lukkari v2.1</div>\n". | 560 " <div id=\"ctitle\">Lukkari v".$pageVersion."</div>\n". |
557 " <div>".cmQM("Style").": "; | 561 " <div>".cmQM("Style").": "; |
558 | 562 |
559 foreach ($pageCSSAlts as $name => $id) | 563 foreach ($pageCSSAlts as $name => $id) |
560 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; | 564 echo "<a href=\"".$baseURI."?css=".$id."\">".$name."</a>"; |
561 | 565 |