docs
[mirrors/Programs.git] / php / rozvrh.atom.phps
1 <?php
2 header("Content-Type: application/atom+xml");
3
4 $url = 'http://www.ssps.cz/pages/rozvrhy/index.php';
5
6 # E.g. $croom = '1.A';
7 $croom = "x";
8 $croom = trim($_GET['q']);
9
10 function atomPrintItem($title, $id, $update, $link, $desc='') {
11 echo("\n<entry>\n");
12 echo("\t<id>$id</id>\n");
13 echo("\t<updated>" . strftime("%Y-%m-%dT%H:%M:%SZ", $update) . "</updated>\n");
14 echo("\t<title>$title</title>\n");
15 echo("\t<link href=\"$link\" />\n");
16 echo("\t<content>$desc</content>\n");
17 echo("</entry>\n\n");
18 }
19 echo('<?xml'); ?> version="1.0" encoding="UTF-8"?>
20 <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="cs">
21 <title>Změny v rozvrhu SSPŠ</title>
22 <subtitle>Aktuální změny v rozvrhu SSPŠ</subtitle>
23 <link href="<?php echo($url); ?>" />
24 <icon>http://www.ssps.cz/favicon.ico</icon>
25 <id>tag:ssps.cz,2008:</id>
26 <author>
27 <name>SSPŠ</name>
28 </author>
29 <?php
30 $croom = str_replace('.', '\.', $croom);
31 $feed = split('<[^>]+>', iconv('WINDOWS-1250', 'UTF-8', file_get_contents($url)));
32 $date = 0;
33 $update = 0;
34 $lastUpdate = 0;
35
36 ob_start();
37
38 foreach($feed as $line) {
39 $line = trim($line);
40 if($line == '' || eregi('rozvrhy', $line)) continue;
41
42 # Last update?
43 if (eregi("^Aktualizováno: (..)\.(..)\.(....)&nbsp;(..:..:..)$", $line, $r))
44 {
45 $update = strtotime("{$r[3]}-{$r[2]}-{$r[1]} {$r[4]}");
46
47 # This is the last update of the whole feed
48 if ($lastUpdate < $update)
49 $lastUpdate = $update;
50 continue;
51 }
52
53 # What day are we reading?
54 if (eregi("^[^ ]+&nbsp;(..)\.(..)\.(....)$", $line, $r))
55 {
56 $date = strtotime("{$r[3]}-{$r[2]}-{$r[1]}");
57 continue;
58 }
59
60 # Found a line about our class
61 if ($date && eregi($croom, $line))
62 {
63 $days = array('Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So');
64 $wday = localtime($date, TRUE);
65 $wday = $days[$wday['tm_wday']];
66 atomPrintItem($wday . strftime(" %d.%m. ", $date) . $line,
67 "tag:ssps.cz," . strftime("%Y-%m-%d:", $date) . md5($line),
68 $update, $url, $line);
69 }
70 }
71 $feed = ob_get_contents();
72 ob_end_clean();
73 # Must appear before the items
74 echo ("\t<updated>" . strftime("%Y-%m-%dT%H:%M:%SZ", $lastUpdate) . "</updated>\n");
75 echo $feed;
76 ?>
77 </feed>
78
This page took 0.326233 seconds and 4 git commands to generate.