Mercurial > hg > lukkari
comparison index.php @ 171:66c871dacbc2
Improve course ID handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 24 Aug 2015 11:19:52 +0300 |
parents | 074a4a00af08 |
children | 14117fd8a083 |
comparison
equal
deleted
inserted
replaced
170:34ce8339b956 | 171:66c871dacbc2 |
---|---|
186 " - ". | 186 " - ". |
187 lukGetHourStamp($classHourTimes[$end]["end"]); | 187 lukGetHourStamp($classHourTimes[$end]["end"]); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 function lukFetchCourseData($uri, &$cache) | 191 function lukFetchCourseData($id, $uri, &$cache) |
192 { | 192 { |
193 global $pageCharset; | 193 global $pageCharset; |
194 | 194 |
195 if (($data = @file_get_contents($uri)) !== FALSE) | 195 if (($data = @file_get_contents($uri)) !== FALSE) |
196 { | 196 { |
197 $data = @iconv("iso8859-15", $pageCharset, $data); | 197 $data = @iconv("iso8859-15", $pageCharset, $data); |
198 | |
198 // <td id="oj_nimi" class="smallheadercell"><strong>Korjausrakentamisen rakennussuunnittelu 3 op</strong></td> | 199 // <td id="oj_nimi" class="smallheadercell"><strong>Korjausrakentamisen rakennussuunnittelu 3 op</strong></td> |
199 if (preg_match("#<td id=\"oj_nimi\" class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m)) | 200 if (preg_match("#<td id=\"oj_nimi\" class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m)) |
200 { | 201 { |
201 $cache = array("desc" => $m[1], "op" => intval($m[2]), "uri" => $uri); | 202 $cache = array("desc" => $m[1], "op" => intval($m[2]), "uri" => $uri); |
202 return TRUE; | 203 return TRUE; |
203 } | 204 } |
204 else | 205 else |
205 // <td><strong>... (N op)</strong></td> | 206 // <td><strong>... (N op)</strong></td> |
206 if (preg_match("#<td><strong>(.+?)\s+\((\d+)\s*(op|ECTS\s+cr)\)\s*</strong></td>#", $data, $m)) | 207 if (preg_match("#<td><strong>(.+?)\s+\((\d+)\s*(op|ECTS\s+cr|cr)\)\s*</strong></td>#i", $data, $m)) |
207 { | 208 { |
208 $cache = array("desc" => $m[1], "op" => intval($m[2]), "uri" => $uri); | 209 $cache = array("desc" => $m[1], "op" => intval($m[2]), "uri" => $uri); |
209 return TRUE; | 210 return TRUE; |
210 } | 211 } |
211 } | 212 } |
224 // Check if course exists in cache | 225 // Check if course exists in cache |
225 if (!isset($cache[$id][$pageLang])) | 226 if (!isset($cache[$id][$pageLang])) |
226 { | 227 { |
227 // Not cached, try to fetch data | 228 // Not cached, try to fetch data |
228 $uri = "http://www.oamk.fi/opinto-opas/opintojaksohaku/?sivu=oj_kuvaus&koodi1=".$id."&kieli=".strtoupper($pageLang); | 229 $uri = "http://www.oamk.fi/opinto-opas/opintojaksohaku/?sivu=oj_kuvaus&koodi1=".$id."&kieli=".strtoupper($pageLang); |
229 if (lukFetchCourseData($uri."&opas=2015-2016", $cache[$id][$pageLang]) || | 230 if ( |
230 lukFetchCourseData($uri."&opas=2014-2015", $cache[$id][$pageLang])) | 231 lukFetchCourseData($id, $uri."&opas=2014-2015", $cache[$id][$pageLang]) || |
232 lukFetchCourseData($id, $uri."&opas=2015-2016", $cache[$id][$pageLang]) | |
233 ) | |
231 $cacheDirty = TRUE; | 234 $cacheDirty = TRUE; |
232 } | 235 } |
233 | 236 |
234 if (isset($cache[$id]) && isset($cache[$id][$pageLang])) | 237 if (isset($cache[$id]) && isset($cache[$id][$pageLang])) |
235 { | 238 { |