mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-03 09:35:57 +02:00
Reformat codebase v4 (#2872)
Reformat code base to PSR12 Co-authored-by: rssbridge <noreply@github.com>
This commit is contained in:
parent
66568e3a39
commit
4f75591060
398 changed files with 58607 additions and 56442 deletions
|
@ -1,56 +1,57 @@
|
|||
<?php
|
||||
|
||||
class GiphyBridge extends BridgeAbstract {
|
||||
class GiphyBridge extends BridgeAbstract
|
||||
{
|
||||
const MAINTAINER = 'dvikan';
|
||||
const NAME = 'Giphy Bridge';
|
||||
const URI = 'https://giphy.com/';
|
||||
const CACHE_TIMEOUT = 60 * 60 * 8; // 8h
|
||||
const DESCRIPTION = 'Bridge for giphy.com';
|
||||
|
||||
const MAINTAINER = 'dvikan';
|
||||
const NAME = 'Giphy Bridge';
|
||||
const URI = 'https://giphy.com/';
|
||||
const CACHE_TIMEOUT = 60 * 60 * 8; // 8h
|
||||
const DESCRIPTION = 'Bridge for giphy.com';
|
||||
const PARAMETERS = [ [
|
||||
's' => [
|
||||
'name' => 'search tag',
|
||||
'exampleValue' => 'bird',
|
||||
'required' => true
|
||||
],
|
||||
'noGif' => [
|
||||
'name' => 'Without gifs',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclude gifs from the results'
|
||||
],
|
||||
'noStick' => [
|
||||
'name' => 'Without stickers',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclude stickers from the results'
|
||||
],
|
||||
'n' => [
|
||||
'name' => 'max number of returned items (max 50)',
|
||||
'type' => 'number',
|
||||
'exampleValue' => 3,
|
||||
]
|
||||
]];
|
||||
|
||||
const PARAMETERS = array( array(
|
||||
's' => array(
|
||||
'name' => 'search tag',
|
||||
'exampleValue' => 'bird',
|
||||
'required' => true
|
||||
),
|
||||
'noGif' => array(
|
||||
'name' => 'Without gifs',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclude gifs from the results'
|
||||
),
|
||||
'noStick' => array(
|
||||
'name' => 'Without stickers',
|
||||
'type' => 'checkbox',
|
||||
'title' => 'Exclude stickers from the results'
|
||||
),
|
||||
'n' => array(
|
||||
'name' => 'max number of returned items (max 50)',
|
||||
'type' => 'number',
|
||||
'exampleValue' => 3,
|
||||
)
|
||||
));
|
||||
public function getName()
|
||||
{
|
||||
if (!is_null($this->getInput('s'))) {
|
||||
return $this->getInput('s') . ' - ' . parent::getName();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (!is_null($this->getInput('s'))) {
|
||||
return $this->getInput('s') . ' - ' . parent::getName();
|
||||
}
|
||||
return parent::getName();
|
||||
}
|
||||
|
||||
return parent::getName();
|
||||
}
|
||||
protected function getGiphyItems($entries)
|
||||
{
|
||||
foreach ($entries as $entry) {
|
||||
$createdAt = new \DateTime($entry->import_datetime);
|
||||
|
||||
protected function getGiphyItems($entries){
|
||||
foreach($entries as $entry) {
|
||||
$createdAt = new \DateTime($entry->import_datetime);
|
||||
|
||||
$this->items[] = array(
|
||||
'id' => $entry->id,
|
||||
'uri' => $entry->url,
|
||||
'author' => $entry->username,
|
||||
'timestamp' => $createdAt->format('U'),
|
||||
'title' => $entry->title,
|
||||
'content' => <<<HTML
|
||||
$this->items[] = [
|
||||
'id' => $entry->id,
|
||||
'uri' => $entry->url,
|
||||
'author' => $entry->username,
|
||||
'timestamp' => $createdAt->format('U'),
|
||||
'title' => $entry->title,
|
||||
'content' => <<<HTML
|
||||
<a href="{$entry->url}">
|
||||
<img
|
||||
loading="lazy"
|
||||
|
@ -59,48 +60,49 @@ class GiphyBridge extends BridgeAbstract {
|
|||
height="{$entry->images->downsized->height}" />
|
||||
</a>
|
||||
HTML
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function collectData() {
|
||||
/**
|
||||
* This uses Giphy's own undocumented public prod api key,
|
||||
* which should not have any rate limiting.
|
||||
* There is a documented public beta api key (dc6zaTOxFJmzC),
|
||||
* but it has severe rate limiting.
|
||||
*
|
||||
* https://giphy.api-docs.io/1.0/welcome/access-and-api-keys
|
||||
* https://developers.giphy.com/branch/master/docs/api/endpoint/#search
|
||||
*/
|
||||
$apiKey = 'Gc7131jiJuvI7IdN0HZ1D7nh0ow5BU6g';
|
||||
$bundle = 'low_bandwidth';
|
||||
$limit = min($this->getInput('n') ?: 10, 50);
|
||||
$endpoints = array();
|
||||
if (empty($this->getInput('noGif'))) {
|
||||
$endpoints[] = 'gifs';
|
||||
}
|
||||
if (empty($this->getInput('noStick'))) {
|
||||
$endpoints[] = 'stickers';
|
||||
}
|
||||
public function collectData()
|
||||
{
|
||||
/**
|
||||
* This uses Giphy's own undocumented public prod api key,
|
||||
* which should not have any rate limiting.
|
||||
* There is a documented public beta api key (dc6zaTOxFJmzC),
|
||||
* but it has severe rate limiting.
|
||||
*
|
||||
* https://giphy.api-docs.io/1.0/welcome/access-and-api-keys
|
||||
* https://developers.giphy.com/branch/master/docs/api/endpoint/#search
|
||||
*/
|
||||
$apiKey = 'Gc7131jiJuvI7IdN0HZ1D7nh0ow5BU6g';
|
||||
$bundle = 'low_bandwidth';
|
||||
$limit = min($this->getInput('n') ?: 10, 50);
|
||||
$endpoints = [];
|
||||
if (empty($this->getInput('noGif'))) {
|
||||
$endpoints[] = 'gifs';
|
||||
}
|
||||
if (empty($this->getInput('noStick'))) {
|
||||
$endpoints[] = 'stickers';
|
||||
}
|
||||
|
||||
foreach ($endpoints as $endpoint) {
|
||||
$uri = sprintf(
|
||||
'https://api.giphy.com/v1/%s/search?q=%s&limit=%s&bundle=%s&api_key=%s',
|
||||
$endpoint,
|
||||
rawurlencode($this->getInput('s')),
|
||||
$limit,
|
||||
$bundle,
|
||||
$apiKey
|
||||
);
|
||||
foreach ($endpoints as $endpoint) {
|
||||
$uri = sprintf(
|
||||
'https://api.giphy.com/v1/%s/search?q=%s&limit=%s&bundle=%s&api_key=%s',
|
||||
$endpoint,
|
||||
rawurlencode($this->getInput('s')),
|
||||
$limit,
|
||||
$bundle,
|
||||
$apiKey
|
||||
);
|
||||
|
||||
$result = json_decode(getContents($uri));
|
||||
$result = json_decode(getContents($uri));
|
||||
|
||||
$this->getGiphyItems($result->data);
|
||||
}
|
||||
$this->getGiphyItems($result->data);
|
||||
}
|
||||
|
||||
usort($this->items, function ($a, $b) {
|
||||
return $a['timestamp'] < $b['timestamp'];
|
||||
});
|
||||
}
|
||||
usort($this->items, function ($a, $b) {
|
||||
return $a['timestamp'] < $b['timestamp'];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue