From 9a0248a8d97c06a12f1cc13c48e5fe16d215aa7c Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sun, 1 Apr 2018 23:58:07 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=20=D0=9A=D0=B2=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Kvester.php | 16 ++++++++++++++++ Wikipage.php | 25 ++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Source/Kvester.php b/Source/Kvester.php index d145245..c51ed14 100644 --- a/Source/Kvester.php +++ b/Source/Kvester.php @@ -27,4 +27,20 @@ class Kvester extends Source { $this->output .= $game->print(); }); } + public function checkPage($url) { + return (strpos($url,'http://kvester.ru/game/') !== FALSE); + } + public function page($url) { + $game = new Game; + $game->url = $url; + $game->platform = 'Квестер'; + $game->title = trim($this->dom->filter(".qt-in-1 h2")->first()->text()); + $game->author = trim($this->dom->filter('.quest-info .author a')->text()); + $game->date = \DateTime::createFromFormat( + 'd.m.y', + trim($this->dom->filter('.quest-info .date')->first()->text()) + ); + $game->description = trim($this->dom->filter('.quest-profile .description')->first()->text()); + return $game; + } } diff --git a/Wikipage.php b/Wikipage.php index 8ded6f8..1796a70 100644 --- a/Wikipage.php +++ b/Wikipage.php @@ -23,13 +23,20 @@ class Wikipage { $this->game = $game; if (!$config['DUMMY']) { - // Log in to a wiki - $api = new MediawikiApi( $config['WIKI'] ); - $api->login( new ApiUser( $config['WIKIUSER'], $config['WIKIPASSWORD'] ) ); - $services = new MediawikiFactory( $api ); - $this->api = $api; - $this->services = $services; - $this->fileUploader = $services->newFileUploader(); + try { + // Log in to a wiki + $api = new MediawikiApi( $config['WIKI'] ); + $api->login( new ApiUser( $config['WIKIUSER'], $config['WIKIPASSWORD'] ) ); + $services = new MediawikiFactory( $api ); + $this->api = $api; + $this->services = $services; + $this->fileUploader = $services->newFileUploader(); + } catch (\Exception $e) { + echo 'Ошибка соединения.'.PHP_EOL; + echo $e->getMessage(); + echo $e->getTraceAsString(); + $config['DUMMY'] = true; + } } } public function create() { @@ -147,6 +154,10 @@ class Wikipage { * @return boolean */ protected function exists($pagename) { + global $config; + if ($config['DUMMY']) { + return false; + } $page = $this->services->newPageGetter()->getFromTitle((string) $pagename); return !($page->getId() === 0); }