mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[UberNewsroomBridge] Add more regions & use region name from JSON (#2817)
This commit is contained in:
parent
33e3d9b596
commit
c6100d95ca
@ -12,9 +12,10 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
'type' => 'list',
|
'type' => 'list',
|
||||||
'values' => array(
|
'values' => array(
|
||||||
'Africa' => array(
|
'Africa' => array(
|
||||||
'Egypt' => 'en-EG',
|
'Egypt' => 'ar-EG',
|
||||||
'Ghana' => 'en-GH',
|
'Ghana' => 'en-GH',
|
||||||
'Kenya' => 'en-KE',
|
'Kenya' => 'en-KE',
|
||||||
|
'Morocco' => 'fr-MA',
|
||||||
'Nigeria' => 'en-NG',
|
'Nigeria' => 'en-NG',
|
||||||
'South Africa' => 'en-ZA',
|
'South Africa' => 'en-ZA',
|
||||||
'Tanzania' => 'en-TZ',
|
'Tanzania' => 'en-TZ',
|
||||||
@ -22,66 +23,76 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
),
|
),
|
||||||
'Asia' => array(
|
'Asia' => array(
|
||||||
'Bangladesh' => 'en-BD',
|
'Bangladesh' => 'en-BD',
|
||||||
'Hong Kong' => 'en-HK',
|
'Cambodia' => 'km-KH',
|
||||||
|
'China' => 'zh-CN',
|
||||||
|
'Hong Kong' => 'zh-HK',
|
||||||
'India' => 'en-IN',
|
'India' => 'en-IN',
|
||||||
|
'Indonesia' => 'en-ID',
|
||||||
'Japan' => 'ja-JP',
|
'Japan' => 'ja-JP',
|
||||||
'Korea' => 'en-KR',
|
'Korea' => 'ko-KR',
|
||||||
'Macau' => 'en-MO',
|
'Macau' => 'zh-MO',
|
||||||
|
'Malaysia' => 'en-MY',
|
||||||
|
'Myanmar' => 'en-MM',
|
||||||
|
'Philippines' => 'en-PH',
|
||||||
|
'Singapore' => 'en-SG',
|
||||||
'Sri Lanka' => 'en-LK',
|
'Sri Lanka' => 'en-LK',
|
||||||
'Taiwan' => 'en-TW',
|
'Taiwan' => 'zh-TW',
|
||||||
|
'Thailand' => 'th-TH',
|
||||||
|
'Vietnam' => 'vi-VN',
|
||||||
),
|
),
|
||||||
'Central America' => array(
|
'Central America' => array(
|
||||||
'Costa Rica' => 'es-CR',
|
'Costa Rica' => 'es-CR',
|
||||||
'Dominican Republic' => 'es-DO',
|
'Dominican Republic' => 'es-DO',
|
||||||
'El Salvador' => 'es-SV',
|
'El Salvador' => 'es-SV',
|
||||||
'Guatemala' => 'es-GT',
|
'Guatemala' => 'es-GT',
|
||||||
'Honduras' => 'en-HN',
|
'Honduras' => 'es-HN',
|
||||||
'Mexico' => 'es-MX',
|
'Mexico' => 'es-MX',
|
||||||
'Nicaragua' => 'es-NI',
|
'Nicaragua' => 'es-NI',
|
||||||
'Panama' => 'es-PA',
|
'Panama' => 'es-PA',
|
||||||
'Puerto Rico' => 'en-PR',
|
'Puerto Rico' => 'es-PR',
|
||||||
),
|
),
|
||||||
'Europe' => array(
|
'Europe' => array(
|
||||||
'Austria' => 'de-AT',
|
'Austria' => 'de-AT',
|
||||||
'Azerbaijan' => 'az',
|
'Azerbaijan' => 'az',
|
||||||
'Belarus' => 'ru-BY',
|
'Belarus' => 'ru-BY',
|
||||||
'Belgium' => 'en-BE',
|
'Belgium' => 'fr-BE',
|
||||||
'Bulgaria' => 'en-BG',
|
'Bulgaria' => 'bg',
|
||||||
'Croatia' => 'hr',
|
'Croatia' => 'hr',
|
||||||
'Czech Republic' => 'cs-CZ',
|
'Czech Republic' => 'cs-CZ',
|
||||||
'Denmark' => 'en-DK',
|
'Denmark' => 'da-DK',
|
||||||
'Estonia' => 'en-EE',
|
'Estonia' => 'et-EE',
|
||||||
'Finland' => 'en-FI',
|
'Finland' => 'fi',
|
||||||
'France' => 'en-FR',
|
'France' => 'fr',
|
||||||
'Germany' => 'en-DE',
|
'Germany' => 'de',
|
||||||
'Greece' => 'en-GR',
|
'Greece' => 'el-GR',
|
||||||
'Hungary' => 'en-HU',
|
'Hungary' => 'hu',
|
||||||
'Ireland' => 'en-IE',
|
'Ireland' => 'en-IE',
|
||||||
'Italy' => 'en-IT',
|
'Italy' => 'it',
|
||||||
'Kazakhstan' => 'ru-KZ',
|
'Kazakhstan' => 'ru-KZ',
|
||||||
'Lithuania' => 'en-LT',
|
'Lithuania' => 'lt',
|
||||||
'Netherlands' => 'en-NL',
|
'Netherlands' => 'nl',
|
||||||
'Norway' => 'en-NO',
|
'Norway' => 'nb-NO',
|
||||||
'Poland' => 'pl',
|
'Poland' => 'pl',
|
||||||
'Portugal' => 'en-PT',
|
'Portugal' => 'pt',
|
||||||
'Romania' => 'en-RO',
|
'Romania' => 'ro',
|
||||||
'Russia' => 'ru',
|
'Russia' => 'ru',
|
||||||
'Slovakia' => 'sk',
|
'Slovakia' => 'sk',
|
||||||
'Spain' => 'es-ES',
|
'Spain' => 'es-ES',
|
||||||
'Sweden' => 'en-SE',
|
'Sweden' => 'sv-SE',
|
||||||
'Switzerland' => 'en-CH',
|
'Switzerland' => 'fr-CH',
|
||||||
'Turkey' => 'en-TR',
|
'Turkey' => 'tr',
|
||||||
'Ukraine' => 'uk-UA',
|
'Ukraine' => 'uk-UA',
|
||||||
'United Kingdom' => 'en-GB',
|
'United Kingdom' => 'en-GB',
|
||||||
),
|
),
|
||||||
'Middle East' => array(
|
'Middle East' => array(
|
||||||
'Bahrain' => 'en-BH',
|
'Bahrain' => 'en-BH',
|
||||||
'Israel' => 'en-IL',
|
'Israel' => 'he-IL',
|
||||||
'Jordan' => 'en-JO',
|
'Jordan' => 'en-JO',
|
||||||
|
'Kuwait' => 'en-KW',
|
||||||
'Lebanon' => 'en-LB',
|
'Lebanon' => 'en-LB',
|
||||||
'Pakistan' => 'en-PK',
|
'Pakistan' => 'en-PK',
|
||||||
'Qatar' => 'en-QA',
|
'Qatar' => 'en-QA',
|
||||||
'Saudi Arabia' => 'en-SA',
|
'Saudi Arabia' => 'ar-SA',
|
||||||
'United Arab Emirates' => 'en-AE',
|
'United Arab Emirates' => 'en-AE',
|
||||||
),
|
),
|
||||||
'North America' => array(
|
'North America' => array(
|
||||||
@ -99,11 +110,11 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
'Chile' => 'es-CL',
|
'Chile' => 'es-CL',
|
||||||
'Colombia' => 'es-CO',
|
'Colombia' => 'es-CO',
|
||||||
'Ecuador' => 'es-EC',
|
'Ecuador' => 'es-EC',
|
||||||
'Paraguay' => 'en-PY',
|
'Paraguay' => 'es-PY',
|
||||||
'Peru' => 'es-PE',
|
'Peru' => 'es-PE',
|
||||||
'Trinidad & Tobago' => 'en-TT',
|
'Trinidad & Tobago' => 'en-TT',
|
||||||
'Uruguay' => 'es-UY',
|
'Uruguay' => 'es-UY',
|
||||||
'Venezuela' => 'en-VE',
|
'Venezuela' => 'es-VE',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'defaultValue' => 'en-US',
|
'defaultValue' => 'en-US',
|
||||||
@ -112,10 +123,14 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
|
|
||||||
const CACHE_TIMEOUT = 3600;
|
const CACHE_TIMEOUT = 3600;
|
||||||
|
|
||||||
|
private $regionName = '';
|
||||||
|
|
||||||
public function collectData() {
|
public function collectData() {
|
||||||
$json = getContents(self::URI_API_DATA . $this->getInput('region'));
|
$json = getContents(self::URI_API_DATA . $this->getInput('region'));
|
||||||
$data = json_decode($json);
|
$data = json_decode($json);
|
||||||
|
|
||||||
|
$this->regionName = $data->region->name;
|
||||||
|
|
||||||
foreach ($data->articles as $article) {
|
foreach ($data->articles as $article) {
|
||||||
$json = getContents(self::URI_API_POST . $article->id);
|
$json = getContents(self::URI_API_POST . $article->id);
|
||||||
$post = json_decode($json);
|
$post = json_decode($json);
|
||||||
@ -125,14 +140,14 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
$item['timestamp'] = $post->date;
|
$item['timestamp'] = $post->date;
|
||||||
$item['uri'] = $post->link;
|
$item['uri'] = $post->link;
|
||||||
$item['content'] = $this->formatContent($post->content->rendered);
|
$item['content'] = $this->formatContent($post->content->rendered);
|
||||||
$item['enclosures'][] = $this->getImage($post->yoast_head);
|
$item['enclosures'][] = $article->image_full;
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURI() {
|
public function getURI() {
|
||||||
if (is_null($this->getInput('region')) === false && $this->getInput('region') !== 'all') {
|
if (is_null($this->getInput('region')) === false) {
|
||||||
return self::URI . '/' . $this->getInput('region') . '/newsroom';
|
return self::URI . '/' . $this->getInput('region') . '/newsroom';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,35 +156,12 @@ class UberNewsroomBridge extends BridgeAbstract {
|
|||||||
|
|
||||||
public function getName() {
|
public function getName() {
|
||||||
if (is_null($this->getInput('region')) === false) {
|
if (is_null($this->getInput('region')) === false) {
|
||||||
return $this->getRegionName() . ' - Uber Newsroom';
|
return $this->regionName . ' - Uber Newsroom';
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getName();
|
return parent::getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRegionName() {
|
|
||||||
$parameters = $this->getParameters();
|
|
||||||
|
|
||||||
foreach ($parameters[0]['region']['values'] as $values) {
|
|
||||||
foreach ($values as $name => $code) {
|
|
||||||
|
|
||||||
if ($code === $this->getInput('region')) {
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getImage($html) {
|
|
||||||
$html = str_get_html($html);
|
|
||||||
|
|
||||||
if ($html->find('meta[property="og:image"]', 0)) {
|
|
||||||
return $html->find('meta[property="og:image"]', 0)->content;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function formatContent($html) {
|
private function formatContent($html) {
|
||||||
$html = str_get_html($html);
|
$html = str_get_html($html);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user