Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source/Textadventures.php

39 lines
1.4 KiB
PHP

<?php
namespace Source;
use \Game;
use \Symfony\Component\DomCrawler\Crawler;
class Textadventures extends Source {
public $title = "Textadventures.co.uk";
protected function parse() {
$text = $this->get_text('http://textadventures.co.uk/games/latest');
$this->loadStr($text);
unset($text);
$this->dom->filter('.games-item')->each(function($gameBlock){
$game = new Game;
$game->url = 'http://textadventures.co.uk'.$gameBlock->filter('.games-title a')->attr('href');
$game->title = $gameBlock->filter('.games-title a')->text();
$date = strtotime($gameBlock->filter('.games-date')->text());
if ($date < $this->period) return;
$text = $this->get_text($game->url);
$game_page = new Crawler($text);
unset($text);
$game->author = str_replace('by ', '', $game_page->filter('h1 small')->text());
$image = $game_page->filter('img.cover-image')->first();
if ($image->count()) {
$game->image = $image->attr('src');
}
$game_page = $game_page->filter('.col-md-12 .col-md-9 > .col-md-12')->first();
if (!$game_page->count()) {
$game_page = $game_page->filter('.col-md-12 .col-md-9 > .col-md-7')->first();
}
if ($game_page->count()) {
$game->desc = trim($game_page->children()->first()->text());
}
$this->output .= $game->print();
});
}
}