Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SplCenterBridge] Add new bridge #1177

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions bridges/SplCenterBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
class SplCenterBridge extends FeedExpander {

const NAME = 'Southern Poverty Law Center Bridge';
const URI = 'https://www.splcenter.org';
const DESCRIPTION = 'Returns the newest posts from the Southern Poverty Law Center';
const MAINTAINER = 'VerifiedJoseph';
const PARAMETERS = array(array(
'content' => array(
'name' => 'Content',
'type' => 'list',
'values' => array(
'News' => 'news',
'Hatewatch' => 'hatewatch',
),
'defaultValue' => 'news',
)
)
);

const CACHE_TIMEOUT = 3600; // 1 hour

protected function parseItem($item) {
$item = parent::parseItem($item);

$articleHtml = getSimpleHTMLDOMCached($item['uri'])
or returnServerError('Could not request: ' . $item['uri']);

foreach ($articleHtml->find('.file') as $index => $media) {
$articleHtml->find('div.file', $index)->outertext = '<em>' . $media->outertext . '</em>';
}

$item['content'] = $articleHtml->find('div#group-content-container', 0)->innertext;
$item['enclosures'][] = $articleHtml->find('meta[name="twitter:image"]', 0)->content;

return $item;
}

public function collectData() {
$this->collectExpandableDatas($this->getURI() . '/rss.xml');
}

public function getURI() {

if (!is_null($this->getInput('content'))) {
return self::URI . '/' . $this->getInput('content');
}

return parent::getURI();
}

public function getName() {

if (!is_null($this->getInput('content'))) {
$parameters = $this->getParameters();

$contentValues = array_flip($parameters[0]['content']['values']);

return $contentValues[$this->getInput('content')] . ' - Southern Poverty Law Center';
}

return parent::getName();
}
}