Archived
1
0
Fork 0

Правка парсера Steam и кода обложек

This commit is contained in:
Alexander Yakovlev 2018-03-28 21:27:29 +07:00
parent ce63ead589
commit 6a26f8b41f
2 changed files with 14 additions and 6 deletions

View file

@ -57,6 +57,10 @@ class Steam extends Source {
$game->title = trim($game_page->filter('div.apphub_AppName')->first()->text());
$game->description = trim($game_page->filter('div.game_description_snippet')->first()->text());
$game->author = trim($game_page->filter('div#developers_list')->first()->text());
if (strpos($game->author, ',') !== FALSE) {
$game->author = explode(',', $game->author);
$game->author = array_map('trim', $game->author);
}
$game->image = $game_page->filter('img.game_header_image_full')->first()->attr('src');
$date = $game_page->filter('div.date')->first()->text();
$game->date = \DateTime::createFromFormat('d M, Y', $date);

View file

@ -15,6 +15,7 @@ class Wikipage {
protected $services;
protected $content;
protected $fileUploader;
protected $covername;
public function __construct($game) {
global $config;
@ -35,18 +36,21 @@ class Wikipage {
global $config;
$slugify = new Slugify();
if (!empty($this->game->image)) {
$filename = preg_replace('/\?.*/', '', basename($this->game->image));
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$this->covername = $slugify->slugify($this->game->title, '_').'.'.$extension;
}
$this->makeContent();
$exists = $this->exists($this->game->title);
if (!$config['DUMMY'] && !$exists) {
if (!empty($this->game->image)) {
$filename = preg_replace('/\?.*/', '', basename($this->game->image));
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$pagename = $slugify->slugify($this->game->title, '_').$extension;
if ($this->services->newPageGetter()->getFromTitle($filename)) {
if ($this->services->newPageGetter()->getFromTitle($this->covername)) {
$image = file_get_contents($this->game->image);
file_put_contents($filename, $image);
$this->fileUploader->upload($filename, $filename);
$this->fileUploader->upload($this->covername, $filename);
unlink($filename);
}
}
@ -96,7 +100,7 @@ class Wikipage {
$this->content .= PHP_EOL.' |вышла='.$date;
}
$this->txtadd('platform', ' |платформа='.$this->game->platform);
$this->txtadd('image', ' |обложка='.basename($this->game->image));
$this->txtadd('image', ' |обложка='.$this->covername);
$this->content .= "\n}}\n";