[PikabuBridge] More options and fixes (#1149)
* Add gif support * Use page title as feed title * Implement community support
This commit is contained in:
parent
052844f5e1
commit
15c374e317
1 changed files with 37 additions and 12 deletions
|
@ -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 = '<img src="' . $src . '">';
|
||||
}
|
||||
|
||||
foreach($post->find('img') as $img) {
|
||||
$src = $img->getAttribute('src');
|
||||
if (!$src) {
|
||||
|
|
Loading…
Reference in a new issue