[EconomistWorldInBriefBridge] indent with tabs instead of spaces (#2781)

This commit is contained in:
Korytov Pavel 2022-06-05 19:40:48 +03:00 committed by GitHub
parent 713d06ba08
commit 4260be26a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 129 additions and 129 deletions

View File

@ -1,141 +1,141 @@
<?php <?php
class EconomistWorldInBriefBridge extends BridgeAbstract class EconomistWorldInBriefBridge extends BridgeAbstract
{ {
const MAINTAINER = 'sqrtminusone'; const MAINTAINER = 'sqrtminusone';
const NAME = 'Economist the World in Brief Bridge'; const NAME = 'Economist the World in Brief Bridge';
const URI = 'https://www.economist.com/the-world-in-brief'; const URI = 'https://www.economist.com/the-world-in-brief';
const CACHE_TIMEOUT = 3600; // 1 hour const CACHE_TIMEOUT = 3600; // 1 hour
const DESCRIPTION = 'Returns stories from the World in Brief section'; const DESCRIPTION = 'Returns stories from the World in Brief section';
const PARAMETERS = array( const PARAMETERS = array(
'' => array( '' => array(
'splitGobbets' => array( 'splitGobbets' => array(
'name' => 'Split the short stories', 'name' => 'Split the short stories',
'type' => 'checkbox', 'type' => 'checkbox',
'defaultValue' => false, 'defaultValue' => false,
'title' => 'Whether to split the short stories into separate entries' 'title' => 'Whether to split the short stories into separate entries'
), ),
'limit' => array( 'limit' => array(
'name' => 'Truncate headers for the short stories', 'name' => 'Truncate headers for the short stories',
'type' => 'number', 'type' => 'number',
'defaultValue' => 100 'defaultValue' => 100
), ),
'agenda' => array( 'agenda' => array(
'name' => 'Add agenda for the day', 'name' => 'Add agenda for the day',
'type' => 'checkbox', 'type' => 'checkbox',
'defaultValue' => 'checked' 'defaultValue' => 'checked'
), ),
'agendaPictures' => array( 'agendaPictures' => array(
'name' => 'Include pictures to the agenda', 'name' => 'Include pictures to the agenda',
'type' => 'checkbox', 'type' => 'checkbox',
'defaultValue' => 'checked' 'defaultValue' => 'checked'
), ),
'quote' => array( 'quote' => array(
'name' => 'Include the quote of the day', 'name' => 'Include the quote of the day',
'type' => 'checkbox' 'type' => 'checkbox'
) )
) )
); );
public function collectData() public function collectData()
{ {
$html = getSimpleHTMLDOM(self::URI); $html = getSimpleHTMLDOM(self::URI);
$gobbets = $html->find('._gobbets', 0); $gobbets = $html->find('._gobbets', 0);
if ($this->getInput('splitGobbets') == 1) { if ($this->getInput('splitGobbets') == 1) {
$this->splitGobbets($gobbets); $this->splitGobbets($gobbets);
} else { } else {
$this->mergeGobbets($gobbets); $this->mergeGobbets($gobbets);
}; };
if ($this->getInput('agenda') == 1) { if ($this->getInput('agenda') == 1) {
$articles = $html->find('._articles', 0); $articles = $html->find('._articles', 0);
$this->collectArticles($articles); $this->collectArticles($articles);
} }
if ($this->getInput('quote') == 1) { if ($this->getInput('quote') == 1) {
$quote = $html->find('._quote-container', 0); $quote = $html->find('._quote-container', 0);
$this->addQuote($quote); $this->addQuote($quote);
} }
} }
private function splitGobbets($gobbets) private function splitGobbets($gobbets)
{ {
$today = new Datetime(); $today = new Datetime();
$today->setTime(0, 0, 0, 0); $today->setTime(0, 0, 0, 0);
$limit = $this->getInput('limit'); $limit = $this->getInput('limit');
foreach ($gobbets->find('._gobbet') as $gobbet) { foreach ($gobbets->find('._gobbet') as $gobbet) {
$title = $gobbet->plaintext; $title = $gobbet->plaintext;
$match = preg_match('/[\.,]/', $title, $matches, PREG_OFFSET_CAPTURE); $match = preg_match('/[\.,]/', $title, $matches, PREG_OFFSET_CAPTURE);
if ($match > 0) { if ($match > 0) {
$point = $matches[0][1]; $point = $matches[0][1];
$title = mb_substr($title, 0, $point); $title = mb_substr($title, 0, $point);
} }
if ($limit && mb_strlen($title) > $limit) { if ($limit && mb_strlen($title) > $limit) {
$title = mb_substr($title, 0, $limit) . '...'; $title = mb_substr($title, 0, $limit) . '...';
} }
$item = array( $item = array(
'uri' => self::URI, 'uri' => self::URI,
'title' => $title, 'title' => $title,
'content' => $gobbet->innertext, 'content' => $gobbet->innertext,
'timestamp' => $today->format('U'), 'timestamp' => $today->format('U'),
'uid' => md5($gobbet->plaintext) 'uid' => md5($gobbet->plaintext)
); );
$this->items[] = $item; $this->items[] = $item;
} }
} }
private function mergeGobbets($gobbets) private function mergeGobbets($gobbets)
{ {
$today = new Datetime(); $today = new Datetime();
$today->setTime(0, 0, 0, 0); $today->setTime(0, 0, 0, 0);
$contents = ''; $contents = '';
foreach ($gobbets->find('._gobbet') as $gobbet) { foreach ($gobbets->find('._gobbet') as $gobbet) {
$contents .= "<p>{$gobbet->innertext}"; $contents .= "<p>{$gobbet->innertext}";
} }
$this->items[] = array( $this->items[] = array(
'uri' => self::URI, 'uri' => self::URI,
'title' => 'World in brief at ' . $today->format('Y.m.d'), 'title' => 'World in brief at ' . $today->format('Y.m.d'),
'content' => $contents, 'content' => $contents,
'timestamp' => $today->format('U'), 'timestamp' => $today->format('U'),
'uid' => 'world-in-brief-' . $today->format('U') 'uid' => 'world-in-brief-' . $today->format('U')
); );
} }
private function collectArticles($articles) private function collectArticles($articles)
{ {
$i = 0; $i = 0;
$today = new Datetime(); $today = new Datetime();
$today->setTime(0, 0, 0, 0); $today->setTime(0, 0, 0, 0);
foreach ($articles->find('._article') as $article) { foreach ($articles->find('._article') as $article) {
$title = $article->find('._headline', 0)->plaintext; $title = $article->find('._headline', 0)->plaintext;
$image = $article->find('._main-image', 0); $image = $article->find('._main-image', 0);
$content = $article->find('._content', 0); $content = $article->find('._content', 0);
$res_content = ''; $res_content = '';
if ($image != null && $this->getInput('agendaPictures') == 1) { if ($image != null && $this->getInput('agendaPictures') == 1) {
$img = $image->find('img', 0); $img = $image->find('img', 0);
$res_content .= '<img src="' . $img->src . '" />'; $res_content .= '<img src="' . $img->src . '" />';
} }
$res_content .= $content->innertext; $res_content .= $content->innertext;
$this->items[] = array( $this->items[] = array(
'uri' => self::URI, 'uri' => self::URI,
'title' => $title, 'title' => $title,
'content' => $res_content, 'content' => $res_content,
'timestamp' => $today->format('U'), 'timestamp' => $today->format('U'),
'uid' => 'story-' . $today->format('U') . "{$i}", 'uid' => 'story-' . $today->format('U') . "{$i}",
); );
$i++; $i++;
} }
} }
private function addQuote($quote) { private function addQuote($quote) {
$today = new Datetime(); $today = new Datetime();
$today->setTime(0, 0, 0, 0); $today->setTime(0, 0, 0, 0);
$this->items[] = array( $this->items[] = array(
'uri' => self::URI, 'uri' => self::URI,
'title' => 'Quote of the day ' . $today->format('Y.m.d'), 'title' => 'Quote of the day ' . $today->format('Y.m.d'),
'content' => $quote->innertext, 'content' => $quote->innertext,
'timestamp' => $today->format('U'), 'timestamp' => $today->format('U'),
'uid' => 'quote-' . $today->format('U') 'uid' => 'quote-' . $today->format('U')
); );
} }
} }