From 15c374e317d2c02d92acb863d5611121a1399318 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sun, 2 Jun 2019 00:35:18 +0500 Subject: [PATCH] [PikabuBridge] More options and fixes (#1149) * Add gif support * Use page title as feed title * Implement community support --- bridges/PikabuBridge.php | 49 ++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/bridges/PikabuBridge.php b/bridges/PikabuBridge.php index 1e1d5c8e..8573e6b6 100644 --- a/bridges/PikabuBridge.php +++ b/bridges/PikabuBridge.php @@ -6,6 +6,16 @@ class PikabuBridge extends BridgeAbstract { const DESCRIPTION = 'Выводит посты по тегу'; const MAINTAINER = 'em92'; + const PARAMETERS_FILTER = array( + 'name' => 'Фильтр', + 'type' => 'list', + 'values' => array( + 'Горячее' => 'hot', + 'Свежее' => 'new', + ), + 'defaultValue' => 'hot' + ); + const PARAMETERS = array( 'По тегу' => array( 'tag' => array( @@ -13,21 +23,29 @@ class PikabuBridge extends BridgeAbstract { 'exampleValue' => 'it', 'required' => true ), - 'filter' => array( - 'name' => 'Фильтр', - 'type' => 'list', - 'values' => array( - 'Горячее' => 'hot', - 'Свежее' => 'new', - ), - 'defaultValue' => 'hot' - ) + 'filter' => self::PARAMETERS_FILTER + ), + 'По сообществу' => array( + 'community' => array( + 'name' => 'Сообщество', + 'exampleValue' => 'linux', + 'required' => true + ), + 'filter' => self::PARAMETERS_FILTER ) ); + protected $title = null; + public function getURI() { if ($this->getInput('tag')) { return self::URI . '/tag/' . rawurlencode($this->getInput('tag')) . '/' . rawurlencode($this->getInput('filter')); + } else if ($this->getInput('community')) { + $uri = self::URI . '/community/' . rawurlencode($this->getInput('community')); + if ($this->getInput('filter') != 'hot') { + $uri .= '/' . rawurlencode($this->getInput('filter')); + } + return $uri; } else { return parent::getURI(); } @@ -38,10 +56,10 @@ class PikabuBridge extends BridgeAbstract { } public function getName() { - if (is_string($this->getInput('tag'))) { - return $this->getInput('tag') . ' - ' . parent::getName(); - } else { + if (is_null($this->title)) { return parent::getName(); + } else { + return $this->title . ' - ' . parent::getName(); } } @@ -52,6 +70,8 @@ class PikabuBridge extends BridgeAbstract { $text_html = iconv('windows-1251', 'utf-8', $text_html); $html = str_get_html($text_html); + $this->title = $html->find('title', 0)->innertext; + foreach($html->find('article.story') as $post) { $time = $post->find('time.story__datetime', 0); if (is_null($time)) continue; @@ -67,6 +87,11 @@ class PikabuBridge extends BridgeAbstract { } } + foreach($post->find('[data-type=gifx]') as $el) { + $src = $el->getAttribute('data-source'); + $el->outertext = ''; + } + foreach($post->find('img') as $img) { $src = $img->getAttribute('src'); if (!$src) {