[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,14 +6,7 @@ class PikabuBridge extends BridgeAbstract {
|
||||||
const DESCRIPTION = 'Выводит посты по тегу';
|
const DESCRIPTION = 'Выводит посты по тегу';
|
||||||
const MAINTAINER = 'em92';
|
const MAINTAINER = 'em92';
|
||||||
|
|
||||||
const PARAMETERS = array(
|
const PARAMETERS_FILTER = array(
|
||||||
'По тегу' => array(
|
|
||||||
'tag' => array(
|
|
||||||
'name' => 'Тег',
|
|
||||||
'exampleValue' => 'it',
|
|
||||||
'required' => true
|
|
||||||
),
|
|
||||||
'filter' => array(
|
|
||||||
'name' => 'Фильтр',
|
'name' => 'Фильтр',
|
||||||
'type' => 'list',
|
'type' => 'list',
|
||||||
'values' => array(
|
'values' => array(
|
||||||
|
@ -21,13 +14,38 @@ class PikabuBridge extends BridgeAbstract {
|
||||||
'Свежее' => 'new',
|
'Свежее' => 'new',
|
||||||
),
|
),
|
||||||
'defaultValue' => 'hot'
|
'defaultValue' => 'hot'
|
||||||
)
|
);
|
||||||
|
|
||||||
|
const PARAMETERS = array(
|
||||||
|
'По тегу' => array(
|
||||||
|
'tag' => array(
|
||||||
|
'name' => 'Тег',
|
||||||
|
'exampleValue' => 'it',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'filter' => self::PARAMETERS_FILTER
|
||||||
|
),
|
||||||
|
'По сообществу' => array(
|
||||||
|
'community' => array(
|
||||||
|
'name' => 'Сообщество',
|
||||||
|
'exampleValue' => 'linux',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'filter' => self::PARAMETERS_FILTER
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected $title = null;
|
||||||
|
|
||||||
public function getURI() {
|
public function getURI() {
|
||||||
if ($this->getInput('tag')) {
|
if ($this->getInput('tag')) {
|
||||||
return self::URI . '/tag/' . rawurlencode($this->getInput('tag')) . '/' . rawurlencode($this->getInput('filter'));
|
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 {
|
} else {
|
||||||
return parent::getURI();
|
return parent::getURI();
|
||||||
}
|
}
|
||||||
|
@ -38,10 +56,10 @@ class PikabuBridge extends BridgeAbstract {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName() {
|
public function getName() {
|
||||||
if (is_string($this->getInput('tag'))) {
|
if (is_null($this->title)) {
|
||||||
return $this->getInput('tag') . ' - ' . parent::getName();
|
|
||||||
} else {
|
|
||||||
return parent::getName();
|
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);
|
$text_html = iconv('windows-1251', 'utf-8', $text_html);
|
||||||
$html = str_get_html($text_html);
|
$html = str_get_html($text_html);
|
||||||
|
|
||||||
|
$this->title = $html->find('title', 0)->innertext;
|
||||||
|
|
||||||
foreach($html->find('article.story') as $post) {
|
foreach($html->find('article.story') as $post) {
|
||||||
$time = $post->find('time.story__datetime', 0);
|
$time = $post->find('time.story__datetime', 0);
|
||||||
if (is_null($time)) continue;
|
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) {
|
foreach($post->find('img') as $img) {
|
||||||
$src = $img->getAttribute('src');
|
$src = $img->getAttribute('src');
|
||||||
if (!$src) {
|
if (!$src) {
|
||||||
|
|
Loading…
Reference in a new issue