mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-06 08:37:30 +02:00
Reformat codebase v4 (#2872)
Reformat code base to PSR12 Co-authored-by: rssbridge <noreply@github.com>
This commit is contained in:
@@ -1,150 +1,141 @@
|
||||
<?php
|
||||
class ElloBridge extends BridgeAbstract {
|
||||
|
||||
const MAINTAINER = 'teromene';
|
||||
const NAME = 'Ello Bridge';
|
||||
const URI = 'https://ello.co/';
|
||||
const CACHE_TIMEOUT = 4800; //2hours
|
||||
const DESCRIPTION = 'Returns the newest posts for Ello';
|
||||
class ElloBridge extends BridgeAbstract
|
||||
{
|
||||
const MAINTAINER = 'teromene';
|
||||
const NAME = 'Ello Bridge';
|
||||
const URI = 'https://ello.co/';
|
||||
const CACHE_TIMEOUT = 4800; //2hours
|
||||
const DESCRIPTION = 'Returns the newest posts for Ello';
|
||||
|
||||
const PARAMETERS = array(
|
||||
'By User' => array(
|
||||
'u' => array(
|
||||
'name' => 'Username',
|
||||
'required' => true,
|
||||
'exampleValue' => 'zteph',
|
||||
'title' => 'Username'
|
||||
)
|
||||
),
|
||||
'Search' => array(
|
||||
's' => array(
|
||||
'name' => 'Search',
|
||||
'required' => true,
|
||||
'exampleValue' => 'bird',
|
||||
'title' => 'Search'
|
||||
)
|
||||
)
|
||||
);
|
||||
const PARAMETERS = [
|
||||
'By User' => [
|
||||
'u' => [
|
||||
'name' => 'Username',
|
||||
'required' => true,
|
||||
'exampleValue' => 'zteph',
|
||||
'title' => 'Username'
|
||||
]
|
||||
],
|
||||
'Search' => [
|
||||
's' => [
|
||||
'name' => 'Search',
|
||||
'required' => true,
|
||||
'exampleValue' => 'bird',
|
||||
'title' => 'Search'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
public function collectData() {
|
||||
public function collectData()
|
||||
{
|
||||
$header = [
|
||||
'Authorization: Bearer ' . $this->getAPIKey()
|
||||
];
|
||||
|
||||
$header = array(
|
||||
'Authorization: Bearer ' . $this->getAPIKey()
|
||||
);
|
||||
if (!empty($this->getInput('u'))) {
|
||||
$postData = getContents(self::URI . 'api/v2/users/~' . urlencode($this->getInput('u')) . '/posts', $header) or
|
||||
returnServerError('Unable to query Ello API.');
|
||||
} else {
|
||||
$postData = getContents(self::URI . 'api/v2/posts?terms=' . urlencode($this->getInput('s')), $header) or
|
||||
returnServerError('Unable to query Ello API.');
|
||||
}
|
||||
|
||||
if(!empty($this->getInput('u'))) {
|
||||
$postData = getContents(self::URI . 'api/v2/users/~' . urlencode($this->getInput('u')) . '/posts', $header) or
|
||||
returnServerError('Unable to query Ello API.');
|
||||
} else {
|
||||
$postData = getContents(self::URI . 'api/v2/posts?terms=' . urlencode($this->getInput('s')), $header) or
|
||||
returnServerError('Unable to query Ello API.');
|
||||
}
|
||||
$postData = json_decode($postData);
|
||||
$count = 0;
|
||||
foreach ($postData->posts as $post) {
|
||||
$item = [];
|
||||
$item['author'] = $this->getUsername($post, $postData);
|
||||
$item['timestamp'] = strtotime($post->created_at);
|
||||
$item['title'] = strip_tags($this->findText($post->summary));
|
||||
$item['content'] = $this->getPostContent($post->body);
|
||||
$item['enclosures'] = $this->getEnclosures($post, $postData);
|
||||
$item['uri'] = self::URI . $item['author'] . '/post/' . $post->token;
|
||||
$content = $post->body;
|
||||
|
||||
$postData = json_decode($postData);
|
||||
$count = 0;
|
||||
foreach($postData->posts as $post) {
|
||||
$this->items[] = $item;
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
$item = array();
|
||||
$item['author'] = $this->getUsername($post, $postData);
|
||||
$item['timestamp'] = strtotime($post->created_at);
|
||||
$item['title'] = strip_tags($this->findText($post->summary));
|
||||
$item['content'] = $this->getPostContent($post->body);
|
||||
$item['enclosures'] = $this->getEnclosures($post, $postData);
|
||||
$item['uri'] = self::URI . $item['author'] . '/post/' . $post->token;
|
||||
$content = $post->body;
|
||||
private function findText($path)
|
||||
{
|
||||
foreach ($path as $summaryElement) {
|
||||
if ($summaryElement->kind == 'text') {
|
||||
return $summaryElement->data;
|
||||
}
|
||||
}
|
||||
|
||||
$this->items[] = $item;
|
||||
$count += 1;
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
private function getPostContent($path)
|
||||
{
|
||||
$content = '';
|
||||
foreach ($path as $summaryElement) {
|
||||
if ($summaryElement->kind == 'text') {
|
||||
$content .= $summaryElement->data;
|
||||
} elseif ($summaryElement->kind == 'image') {
|
||||
$alt = '';
|
||||
if (property_exists($summaryElement->data, 'alt')) {
|
||||
$alt = $summaryElement->data->alt;
|
||||
}
|
||||
$content .= '<img src="' . $summaryElement->data->url . '" alt="' . $alt . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function findText($path) {
|
||||
private function getEnclosures($post, $postData)
|
||||
{
|
||||
$assets = [];
|
||||
foreach ($post->links->assets as $asset) {
|
||||
foreach ($postData->linked->assets as $assetLink) {
|
||||
if ($asset == $assetLink->id) {
|
||||
$assets[] = $assetLink->attachment->original->url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($path as $summaryElement) {
|
||||
return $assets;
|
||||
}
|
||||
|
||||
if($summaryElement->kind == 'text') {
|
||||
return $summaryElement->data;
|
||||
}
|
||||
private function getUsername($post, $postData)
|
||||
{
|
||||
foreach ($postData->linked->users as $user) {
|
||||
if ($user->id == $post->links->author->id) {
|
||||
return $user->username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private function getAPIKey()
|
||||
{
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
return '';
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache->setScope(get_called_class());
|
||||
$cache->setKey(['key']);
|
||||
$key = $cache->loadData();
|
||||
|
||||
}
|
||||
if ($key == null) {
|
||||
$keyInfo = getContents(self::URI . 'api/webapp-token') or
|
||||
returnServerError('Unable to get token.');
|
||||
$key = json_decode($keyInfo)->token->access_token;
|
||||
$cache->saveData($key);
|
||||
}
|
||||
|
||||
private function getPostContent($path) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
foreach($path as $summaryElement) {
|
||||
public function getName()
|
||||
{
|
||||
if (!is_null($this->getInput('u'))) {
|
||||
return $this->getInput('u') . ' - Ello Bridge';
|
||||
}
|
||||
|
||||
if($summaryElement->kind == 'text') {
|
||||
$content .= $summaryElement->data;
|
||||
} elseif ($summaryElement->kind == 'image') {
|
||||
$alt = '';
|
||||
if(property_exists($summaryElement->data, 'alt')) {
|
||||
$alt = $summaryElement->data->alt;
|
||||
}
|
||||
$content .= '<img src="' . $summaryElement->data->url . '" alt="' . $alt . '" />';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
||||
}
|
||||
|
||||
private function getEnclosures($post, $postData) {
|
||||
|
||||
$assets = array();
|
||||
foreach($post->links->assets as $asset) {
|
||||
foreach($postData->linked->assets as $assetLink) {
|
||||
if($asset == $assetLink->id) {
|
||||
$assets[] = $assetLink->attachment->original->url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $assets;
|
||||
|
||||
}
|
||||
|
||||
private function getUsername($post, $postData) {
|
||||
|
||||
foreach($postData->linked->users as $user) {
|
||||
if($user->id == $post->links->author->id) {
|
||||
return $user->username;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getAPIKey() {
|
||||
$cacheFac = new CacheFactory();
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache->setScope(get_called_class());
|
||||
$cache->setKey(array('key'));
|
||||
$key = $cache->loadData();
|
||||
|
||||
if($key == null) {
|
||||
$keyInfo = getContents(self::URI . 'api/webapp-token') or
|
||||
returnServerError('Unable to get token.');
|
||||
$key = json_decode($keyInfo)->token->access_token;
|
||||
$cache->saveData($key);
|
||||
}
|
||||
|
||||
return $key;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
if(!is_null($this->getInput('u'))) {
|
||||
return $this->getInput('u') . ' - Ello Bridge';
|
||||
}
|
||||
|
||||
return parent::getName();
|
||||
}
|
||||
return parent::getName();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user