2022-05-25 10:43:18 +03:00
|
|
|
<?php
|
|
|
|
class UberNewsroomBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Uber Newsroom Bridge';
|
|
|
|
const URI = 'https://www.uber.com';
|
|
|
|
const URI_API_DATA = 'https://newsroomapi.uber.com/wp-json/newsroom/v1/data?locale=';
|
|
|
|
const URI_API_POST = 'https://newsroomapi.uber.com/wp-json/wp/v2/posts/';
|
|
|
|
const DESCRIPTION = 'Returns news posts';
|
|
|
|
const MAINTAINER = 'VerifiedJoseph';
|
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'region' => array(
|
|
|
|
'name' => 'Region',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
|
|
|
'Africa' => array(
|
2022-06-15 05:18:16 +03:00
|
|
|
'Egypt' => 'ar-EG',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Ghana' => 'en-GH',
|
|
|
|
'Kenya' => 'en-KE',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Morocco' => 'fr-MA',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Nigeria' => 'en-NG',
|
|
|
|
'South Africa' => 'en-ZA',
|
|
|
|
'Tanzania' => 'en-TZ',
|
|
|
|
'Uganda' => 'en-UG',
|
|
|
|
),
|
|
|
|
'Asia' => array(
|
|
|
|
'Bangladesh' => 'en-BD',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Cambodia' => 'km-KH',
|
|
|
|
'China' => 'zh-CN',
|
|
|
|
'Hong Kong' => 'zh-HK',
|
2022-05-25 10:43:18 +03:00
|
|
|
'India' => 'en-IN',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Indonesia' => 'en-ID',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Japan' => 'ja-JP',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Korea' => 'ko-KR',
|
|
|
|
'Macau' => 'zh-MO',
|
|
|
|
'Malaysia' => 'en-MY',
|
|
|
|
'Myanmar' => 'en-MM',
|
|
|
|
'Philippines' => 'en-PH',
|
|
|
|
'Singapore' => 'en-SG',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Sri Lanka' => 'en-LK',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Taiwan' => 'zh-TW',
|
|
|
|
'Thailand' => 'th-TH',
|
|
|
|
'Vietnam' => 'vi-VN',
|
2022-05-25 10:43:18 +03:00
|
|
|
),
|
|
|
|
'Central America' => array(
|
|
|
|
'Costa Rica' => 'es-CR',
|
|
|
|
'Dominican Republic' => 'es-DO',
|
|
|
|
'El Salvador' => 'es-SV',
|
|
|
|
'Guatemala' => 'es-GT',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Honduras' => 'es-HN',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Mexico' => 'es-MX',
|
|
|
|
'Nicaragua' => 'es-NI',
|
|
|
|
'Panama' => 'es-PA',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Puerto Rico' => 'es-PR',
|
2022-05-25 10:43:18 +03:00
|
|
|
),
|
|
|
|
'Europe' => array(
|
|
|
|
'Austria' => 'de-AT',
|
|
|
|
'Azerbaijan' => 'az',
|
|
|
|
'Belarus' => 'ru-BY',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Belgium' => 'fr-BE',
|
|
|
|
'Bulgaria' => 'bg',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Croatia' => 'hr',
|
|
|
|
'Czech Republic' => 'cs-CZ',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Denmark' => 'da-DK',
|
|
|
|
'Estonia' => 'et-EE',
|
|
|
|
'Finland' => 'fi',
|
|
|
|
'France' => 'fr',
|
|
|
|
'Germany' => 'de',
|
|
|
|
'Greece' => 'el-GR',
|
|
|
|
'Hungary' => 'hu',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Ireland' => 'en-IE',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Italy' => 'it',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Kazakhstan' => 'ru-KZ',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Lithuania' => 'lt',
|
|
|
|
'Netherlands' => 'nl',
|
|
|
|
'Norway' => 'nb-NO',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Poland' => 'pl',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Portugal' => 'pt',
|
|
|
|
'Romania' => 'ro',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Russia' => 'ru',
|
|
|
|
'Slovakia' => 'sk',
|
|
|
|
'Spain' => 'es-ES',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Sweden' => 'sv-SE',
|
|
|
|
'Switzerland' => 'fr-CH',
|
|
|
|
'Turkey' => 'tr',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Ukraine' => 'uk-UA',
|
|
|
|
'United Kingdom' => 'en-GB',
|
|
|
|
),
|
|
|
|
'Middle East' => array(
|
|
|
|
'Bahrain' => 'en-BH',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Israel' => 'he-IL',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Jordan' => 'en-JO',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Kuwait' => 'en-KW',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Lebanon' => 'en-LB',
|
|
|
|
'Pakistan' => 'en-PK',
|
|
|
|
'Qatar' => 'en-QA',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Saudi Arabia' => 'ar-SA',
|
2022-05-25 10:43:18 +03:00
|
|
|
'United Arab Emirates' => 'en-AE',
|
|
|
|
),
|
|
|
|
'North America' => array(
|
|
|
|
'Canada' => 'en-CA',
|
|
|
|
'United States' => 'en-US',
|
|
|
|
),
|
|
|
|
'Pacific' => array(
|
|
|
|
'Australia' => 'en-AU',
|
|
|
|
'New Zealand' => 'en-NZ',
|
|
|
|
),
|
|
|
|
'South America' => array(
|
|
|
|
'Argentina' => 'es-AR',
|
|
|
|
'Bolivia' => 'es-BO',
|
|
|
|
'Brazil' => 'pt-BR',
|
|
|
|
'Chile' => 'es-CL',
|
|
|
|
'Colombia' => 'es-CO',
|
|
|
|
'Ecuador' => 'es-EC',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Paraguay' => 'es-PY',
|
2022-05-25 10:43:18 +03:00
|
|
|
'Peru' => 'es-PE',
|
|
|
|
'Trinidad & Tobago' => 'en-TT',
|
|
|
|
'Uruguay' => 'es-UY',
|
2022-06-15 05:18:16 +03:00
|
|
|
'Venezuela' => 'es-VE',
|
2022-05-25 10:43:18 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'defaultValue' => 'en-US',
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
|
2022-06-15 05:18:16 +03:00
|
|
|
private $regionName = '';
|
|
|
|
|
2022-05-25 10:43:18 +03:00
|
|
|
public function collectData() {
|
|
|
|
$json = getContents(self::URI_API_DATA . $this->getInput('region'));
|
|
|
|
$data = json_decode($json);
|
|
|
|
|
2022-06-15 05:18:16 +03:00
|
|
|
$this->regionName = $data->region->name;
|
|
|
|
|
2022-05-25 10:43:18 +03:00
|
|
|
foreach ($data->articles as $article) {
|
|
|
|
$json = getContents(self::URI_API_POST . $article->id);
|
|
|
|
$post = json_decode($json);
|
|
|
|
|
|
|
|
$item = array();
|
|
|
|
$item['title'] = $post->title->rendered;
|
|
|
|
$item['timestamp'] = $post->date;
|
|
|
|
$item['uri'] = $post->link;
|
|
|
|
$item['content'] = $this->formatContent($post->content->rendered);
|
2022-06-15 05:18:16 +03:00
|
|
|
$item['enclosures'][] = $article->image_full;
|
2022-05-25 10:43:18 +03:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
2022-06-15 05:18:16 +03:00
|
|
|
if (is_null($this->getInput('region')) === false) {
|
2022-05-25 10:43:18 +03:00
|
|
|
return self::URI . '/' . $this->getInput('region') . '/newsroom';
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getURI() . '/newsroom';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
if (is_null($this->getInput('region')) === false) {
|
2022-06-15 05:18:16 +03:00
|
|
|
return $this->regionName . ' - Uber Newsroom';
|
2022-05-25 10:43:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function formatContent($html) {
|
|
|
|
$html = str_get_html($html);
|
|
|
|
|
|
|
|
foreach ($html->find('div.wp-video') as $div) {
|
|
|
|
$div->style = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($html->find('video') as $video) {
|
|
|
|
$video->width = '100%';
|
|
|
|
$video->height = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|