diff --git a/parser.php b/parser.php
index 389424f..9c93b0d 100644
--- a/parser.php
+++ b/parser.php
@@ -1,63 +1,81 @@
«".$title."» — $author";
- if ($description) {
- echo "
$description";
- }
- echo "\n";
+function startSection($name) {
+ echo "
$name
\n\n";
+}
+function endSection() {
+ echo "
\n";
}
-echo " Apero
\n";
-$dom->loadFromUrl('http://apero.ru/');
-$games = $dom->find('.tabled-game-block');
-foreach ($games as $game) {
- $date = trim($game->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
- $date = $formatter->parse($date);
- if ($date < $period) continue;
- $author = trim($game->find('.game-author-block')[0]->find('a')->innerHtml);
- $title = trim($game->find('h2')[0]->find('a')[0]->innerHtml);
- $url = trim($game->find('h2')[0]->find('a')[0]->getAttribute('href'));
- $description = trim($game->find('.game-desc-block')[0]->innerHtml);
- printGame($url, $title, $author, $description);
+function apero() {
+ global $dom, $period, $formatter;
+ startSection("Apero");
+ $dom->loadFromUrl('http://apero.ru/');
+ $games = $dom->find('.tabled-game-block');
+ foreach ($games as $gameBlock) {
+ $date = trim($gameBlock->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
+ $date = $formatter->parse($date);
+ if ($date < $period) continue;
+ $game = new Game;
+ $game->author = trim($gameBlock->find('.game-author-block')[0]->find('a')->innerHtml);
+ $game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
+ $game->url = trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
+ $game->description = trim($gameBlock->find('.game-desc-block')[0]->innerHtml);
+ $game->print();
+ }
+ endSection();
}
function insteadfeed($url) {
global $dom, $period, $formatter;
$dom->loadFromUrl($url);
$games = $dom->find('.game');
- foreach ($games as $game) {
- $date = trim($game->find('.b .date b')->innerHtml);
+ foreach ($games as $gameBlock) {
+ $date = trim($gameBlock->find('.b .date b')->innerHtml);
$date = DateTime::createFromFormat('Y.m.d', $date);
$date = $date->format('U');
if ($date < $period) continue;
- $author = str_replace(trim($game->find('span.author')->innerHtml), 'Автор: ', '');
- $title = trim($game->find('h2')[0]->find('a')[0]->innerHtml);
- $url = trim($game->find('h2')[0]->find('a')[0]->getAttribute('href'));
- $description = "";
- printGame($url, $title, $author, $description);
+ $game = new Game;
+ $game->author = str_replace(trim($gameBlock->find('span.author')->innerHtml), 'Автор: ', '');
+ $game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
+ $game->url = 'http://instead-games.ru/'.trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
+ $game->print();
}
}
-echo " Неофициальный INSTEAD репозиторий
\n";
-insteadfeed("http://instead-games.ru/");
-echo " Песочница
\n";
-insteadfeed("http://instead-games.ru/index.php?approved=0");
-
-echo " Storymaze
\n";
-$api = file_get_contents('http://storymaze.ru/api/stories/search?count=10&offset=0&asc=');
-$api = json_decode($api, TRUE);
-foreach ($api as $game) {
- $date = strtotime($game['publishStart']);
- if ($date < $period) continue;
- $title = $game['name'];
- $url = "http://storymaze.ru/story/view/".$game['id'].".html";
- $description = $game['description'];
- $author = $game['authorName'];
- printGame($url, $title, $author, $description);
+function instead() {
+ startSection("Неофициальный INSTEAD репозиторий");
+ insteadfeed("http://instead-games.ru/");
+ endSection();
+ echo " Песочница
\n";
+ insteadfeed("http://instead-games.ru/index.php?approved=0");
+ endSection();
}
+
+function storymaze() {
+ global $dom, $period, $formatter;
+ startSection("Storymaze");
+ $api = file_get_contents('http://storymaze.ru/api/stories/search?count=10&offset=0&asc=');
+ $api = json_decode($api, TRUE);
+ foreach ($api as $gameData) {
+ $date = strtotime($gameData['publishStart']);
+ if ($date < $period) continue;
+ $game = new Game;
+ $game->title = $gameData['name'];
+ $game->url = "http://storymaze.ru/story/view/".$gameData['id'].".html";
+ $game->description = $gameData['description'];
+ $game->author = $gameData['authorName'];
+ $game->print();
+ }
+ endSection();
+}
+
+apero();
+instead();
+storymaze();