diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2015-07-02 14:28:35 +0200 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2015-07-02 14:28:57 +0200 |
commit | 52c427692ff2efa0f5944e3e1feee00a3f61e14b (patch) | |
tree | 57d4068db892ae0b314d41e6bbbedb5bd13eb23c | |
parent | 3f3c818ca9ac12ebdf76d2db101a8a7d8458f0f0 (diff) | |
download | replicant_website-52c427692ff2efa0f5944e3e1feee00a3f61e14b.zip replicant_website-52c427692ff2efa0f5944e3e1feee00a3f61e14b.tar.gz replicant_website-52c427692ff2efa0f5944e3e1feee00a3f61e14b.tar.bz2 |
index: SimplePie for downloading the gitweb page, check in DOM parser
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r-- | index.php | 80 |
1 files changed, 45 insertions, 35 deletions
@@ -69,7 +69,15 @@ if ($feed->error() || !$feed_init) { $gitweb_cache = "cache/gitweb.html"; if (!file_exists($gitweb_cache) || (time() - filemtime($gitweb_cache)) > 3600) { - $gitweb_contents = file_get_contents("http://git.replicant.us/gitweb/"); + $feed = new SimplePie(); + + $feed->set_feed_url("http://git.replicant.us/gitweb/"); + $feed->set_cache_location("cache/"); + $feed->force_feed(true); + $feed_init = $feed->init(); + + $gitweb_contents = $feed->get_raw_data(); + file_put_contents($gitweb_cache, $gitweb_contents); } else { $gitweb_contents = file_get_contents($gitweb_cache); @@ -83,45 +91,47 @@ $tr = $dom->getElementsByTagName("tr"); $count = 0; $limit = 2; -for ($i = 0; $tr->item($i) != null; $i++) { - - $td = $tr->item($i)->getElementsByTagName("td"); - if (!$td) - continue; +if ($tr != null) { + for ($i = 0; $tr->item($i) != null; $i++) { - $td_first = $td->item(0); - if ($td_first != null) { - $class = $td_first->getAttribute("class"); - if ($class == "category") { - $category = $td_first->nodeValue; - print " <li class=\"list-group-item list-group-item-info\">$category</li>\n"; - $limit = 12; + $td = $tr->item($i)->getElementsByTagName("td"); + if (!$td) continue; - } - } - if ($count >= $limit) - continue; + $td_first = $td->item(0); + if ($td_first != null) { + $class = $td_first->getAttribute("class"); + if ($class == "category") { + $category = $td_first->nodeValue; + print " <li class=\"list-group-item list-group-item-info\">$category</li>\n"; + $limit = 12; + continue; + } + } - for ($j = 0; $j < 5; $j++) { - $elem = $td->item($j); - if ($elem == null) - break; + if ($count >= $limit) + continue; - switch($j) { - case 0: - $repo = $elem->nodeValue; - break; - case 1: - $comment = $elem->nodeValue; - break; - case 3: - $time = $elem->nodeValue; - break; - case 4: - print " <li class=\"list-group-item\"><a href=\"//git.replicant.us/gitweb/?p=$repo\">$repo</a> ($comment)<br /><small>Updated <strong>$time</strong> (<a href=\"//git.replicant.us/gitweb/?p=$repo;a=shortlog\">shortlog</a>) .</small></li>\n"; - $count++; - break; + for ($j = 0; $j < 5; $j++) { + $elem = $td->item($j); + if ($elem == null) + break; + + switch($j) { + case 0: + $repo = $elem->nodeValue; + break; + case 1: + $comment = $elem->nodeValue; + break; + case 3: + $time = $elem->nodeValue; + break; + case 4: + print " <li class=\"list-group-item\"><a href=\"//git.replicant.us/gitweb/?p=$repo\">$repo</a> ($comment)<br /><small>Updated <strong>$time</strong> (<a href=\"//git.replicant.us/gitweb/?p=$repo;a=shortlog\">shortlog</a>) .</small></li>\n"; + $count++; + break; + } } } } |