2021-08-15 21:42:28 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
class OpenlyBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Openly Bridge';
|
|
|
|
const URI = 'https://www.openlynews.com/';
|
|
|
|
const DESCRIPTION = 'Returns news articles';
|
|
|
|
const MAINTAINER = 'VerifiedJoseph';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'All News' => [],
|
|
|
|
'All Opinion' => [],
|
|
|
|
'By Region' => [
|
|
|
|
'region' => [
|
|
|
|
'name' => 'Region',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Africa' => 'africa',
|
|
|
|
'Asia Pacific' => 'asia-pacific',
|
|
|
|
'Europe' => 'europe',
|
|
|
|
'Latin America' => 'latin-america',
|
|
|
|
'Middle Easta' => 'middle-east',
|
|
|
|
'North America' => 'north-america'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-08-15 21:42:28 +03:00
|
|
|
],
|
|
|
|
'content' => [
|
|
|
|
'name' => 'Content',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'News' => 'news',
|
|
|
|
'Opinion' => 'people'
|
|
|
|
],
|
|
|
|
'defaultValue' => 'news'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-08-15 21:42:28 +03:00
|
|
|
],
|
|
|
|
'By Tag' => [
|
|
|
|
'tag' => [
|
|
|
|
'name' => 'Tag',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'lgbt-law',
|
|
|
|
],
|
|
|
|
'content' => [
|
|
|
|
'name' => 'Content',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'News' => 'news',
|
|
|
|
'Opinion' => 'people'
|
|
|
|
],
|
|
|
|
'defaultValue' => 'news'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-08-15 21:42:28 +03:00
|
|
|
],
|
|
|
|
'By Author' => [
|
|
|
|
'profileId' => [
|
|
|
|
'name' => 'Profile ID',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => '003D000002WZGYRIA5',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2021-08-15 21:42:28 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
const TEST_DETECT_PARAMETERS = [
|
|
|
|
'https://www.openlynews.com/profile/?id=0033z00002XUTepAAH' => [
|
|
|
|
'context' => 'By Author', 'profileId' => '0033z00002XUTepAAH'
|
|
|
|
],
|
|
|
|
'https://www.openlynews.com/news/?page=1&theme=lgbt-law' => [
|
|
|
|
'context' => 'By Tag', 'content' => 'news', 'tag' => 'lgbt-law'
|
|
|
|
],
|
|
|
|
'https://www.openlynews.com/news/?page=1®ion=north-america' => [
|
|
|
|
'context' => 'By Region', 'content' => 'news', 'region' => 'north-america'
|
|
|
|
],
|
|
|
|
'https://www.openlynews.com/news/?theme=lgbt-law' => [
|
|
|
|
'context' => 'By Tag', 'content' => 'news', 'tag' => 'lgbt-law'
|
|
|
|
],
|
|
|
|
'https://www.openlynews.com/news/?region=north-america' => [
|
|
|
|
'context' => 'By Region', 'content' => 'news', 'region' => 'north-america'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-08-15 21:42:28 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
const CACHE_TIMEOUT = 900; // 15 mins
|
|
|
|
const ARTICLE_CACHE_TIMEOUT = 3600; // 1 hour
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
private $feedTitle = '';
|
|
|
|
private $itemLimit = 10;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
private $profileUrlRegex = '/openlynews\.com\/profile\/\?id=([a-zA-Z0-9]+)/';
|
|
|
|
private $tagUrlRegex = '/openlynews\.com\/([a-z]+)\/\?(?:page=(?:[0-9]+)&)?theme=([\w-]+)/';
|
|
|
|
private $regionUrlRegex = '/openlynews\.com\/([a-z]+)\/\?(?:page=(?:[0-9]+)&)?region=([\w-]+)/';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
public function detectParameters($url)
|
|
|
|
{
|
|
|
|
$params = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if (preg_match($this->profileUrlRegex, $url, $matches) > 0) {
|
|
|
|
$params['context'] = 'By Author';
|
|
|
|
$params['profileId'] = $matches[1];
|
|
|
|
return $params;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if (preg_match($this->tagUrlRegex, $url, $matches) > 0) {
|
|
|
|
$params['context'] = 'By Tag';
|
|
|
|
$params['content'] = $matches[1];
|
|
|
|
$params['tag'] = $matches[2];
|
|
|
|
return $params;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if (preg_match($this->regionUrlRegex, $url, $matches) > 0) {
|
|
|
|
$params['context'] = 'By Region';
|
|
|
|
$params['content'] = $matches[1];
|
|
|
|
$params['region'] = $matches[2];
|
|
|
|
return $params;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
return null;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = $this->getAjaxURI();
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($this->queriedContext === 'By Author') {
|
|
|
|
$url = $this->getURI();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
|
|
|
$html = defaultLinkTo($html, $this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($html->find('h1', 0)) {
|
|
|
|
$this->feedTitle = $html->find('h1', 0)->plaintext;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($html->find('h2.title-v4', 0)) {
|
|
|
|
$html->find('span.tooltiptext', 0)->innertext = '';
|
|
|
|
$this->feedTitle = $html->find('a.tooltipitem', 0)->plaintext;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-10 19:56:24 +03:00
|
|
|
$items = $html->find('div.item');
|
|
|
|
$limit = 5;
|
|
|
|
foreach (array_slice($items, 0, $limit) as $div) {
|
2021-08-15 21:42:28 +03:00
|
|
|
$this->items[] = $this->getArticle($div->find('a', 0)->href);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if (count($this->items) >= $this->itemLimit) {
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-08-15 21:42:28 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'All News':
|
|
|
|
return self::URI . 'news';
|
|
|
|
break;
|
|
|
|
case 'All Opinion':
|
|
|
|
return self::URI . 'people';
|
|
|
|
break;
|
|
|
|
case 'By Tag':
|
|
|
|
return self::URI . $this->getInput('content') . '/?theme=' . $this->getInput('tag');
|
|
|
|
case 'By Region':
|
|
|
|
return self::URI . $this->getInput('content') . '/?region=' . $this->getInput('region');
|
|
|
|
break;
|
|
|
|
case 'By Author':
|
|
|
|
return self::URI . 'profile/?id=' . $this->getInput('profileId');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getURI();
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'All News':
|
|
|
|
return 'News - Openly';
|
|
|
|
break;
|
|
|
|
case 'All Opinion':
|
|
|
|
return 'Opinion - Openly';
|
|
|
|
break;
|
|
|
|
case 'By Tag':
|
|
|
|
if (empty($this->feedTitle)) {
|
|
|
|
$this->feedTitle = $this->getInput('tag');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($this->getInput('content') === 'people') {
|
|
|
|
return $this->feedTitle . ' - Opinion - Openly';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
return $this->feedTitle . ' - Openly';
|
|
|
|
break;
|
|
|
|
case 'By Region':
|
|
|
|
if (empty($this->feedTitle)) {
|
|
|
|
$this->feedTitle = $this->getInput('region');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($this->getInput('content') === 'people') {
|
|
|
|
return $this->feedTitle . ' - Opinion - Openly';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
return $this->feedTitle . ' - Openly';
|
|
|
|
break;
|
|
|
|
case 'By Author':
|
|
|
|
if (empty($this->feedTitle)) {
|
|
|
|
$this->feedTitle = $this->getInput('profileId');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
return $this->feedTitle . ' - Author - Openly';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::getName();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-08-15 21:42:28 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
private function getAjaxURI()
|
|
|
|
{
|
|
|
|
$part = '/ajax.html?';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'All News':
|
|
|
|
return self::URI . 'news' . $part;
|
|
|
|
break;
|
|
|
|
case 'All Opinion':
|
|
|
|
return self::URI . 'people' . $part;
|
|
|
|
break;
|
|
|
|
case 'By Tag':
|
|
|
|
return self::URI . $this->getInput('content') . $part . 'theme=' . $this->getInput('tag');
|
|
|
|
break;
|
|
|
|
case 'By Region':
|
|
|
|
return self::URI . $this->getInput('content') . $part . 'region=' . $this->getInput('region');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
private function getArticle($url)
|
|
|
|
{
|
|
|
|
$article = getSimpleHTMLDOMCached($url, self::ARTICLE_CACHE_TIMEOUT);
|
|
|
|
$article = defaultLinkTo($article, $this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
$item = [];
|
|
|
|
$item['title'] = $article->find('h1', 0)->plaintext;
|
|
|
|
$item['uri'] = $url;
|
|
|
|
$item['content'] = $article->find('div.body-text', 0);
|
|
|
|
$item['enclosures'][] = $article->find('meta[name="twitter:image"]', 0)->content;
|
|
|
|
$item['timestamp'] = $article->find('div.meta.small', 0)->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
if ($article->find('div.meta a', 0)) {
|
|
|
|
$item['author'] = $article->find('div.meta a', 0)->plaintext;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
foreach ($article->find('div.themes li') as $li) {
|
|
|
|
$item['categories'][] = trim(htmlspecialchars($li->plaintext, ENT_QUOTES));
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-15 21:42:28 +03:00
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|