mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[UnsplashBridge] extend functionality (#1813)
This commit is contained in:
parent
fb28107cc4
commit
6ffe531e4f
@ -1,67 +1,113 @@
|
|||||||
<?php
|
<?php
|
||||||
class UnsplashBridge extends BridgeAbstract {
|
|
||||||
|
|
||||||
const MAINTAINER = 'nel50n';
|
class UnsplashBridge extends BridgeAbstract
|
||||||
|
{
|
||||||
|
const MAINTAINER = 'nel50n, langfingaz';
|
||||||
const NAME = 'Unsplash Bridge';
|
const NAME = 'Unsplash Bridge';
|
||||||
const URI = 'https://unsplash.com/';
|
const URI = 'https://unsplash.com/';
|
||||||
const CACHE_TIMEOUT = 43200; // 12h
|
const CACHE_TIMEOUT = 43200; // 12h
|
||||||
const DESCRIPTION = 'Returns the latests photos from Unsplash';
|
const DESCRIPTION = 'Returns the latest photos from Unsplash';
|
||||||
|
|
||||||
const PARAMETERS = array( array(
|
const PARAMETERS = array(array(
|
||||||
|
'u' => array(
|
||||||
|
'name' => 'Filter by username (optional)',
|
||||||
|
'type' => 'text',
|
||||||
|
'defaultValue' => 'unsplash'
|
||||||
|
),
|
||||||
'm' => array(
|
'm' => array(
|
||||||
'name' => 'Max number of photos',
|
'name' => 'Max number of photos',
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'defaultValue' => 20
|
'defaultValue' => 20,
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'prev_q' => array(
|
||||||
|
'name' => 'Preview quality',
|
||||||
|
'type' => 'list',
|
||||||
|
'values' => array(
|
||||||
|
'full' => 'full',
|
||||||
|
'regular' => 'regular',
|
||||||
|
'small' => 'small',
|
||||||
|
'thumb' => 'thumb',
|
||||||
|
),
|
||||||
|
'defaultValue' => 'regular'
|
||||||
),
|
),
|
||||||
'w' => array(
|
'w' => array(
|
||||||
'name' => 'Width',
|
'name' => 'Max download width (optional)',
|
||||||
'exampleValue' => '1920, 1680, …',
|
'exampleValue' => 1920,
|
||||||
'defaultValue' => '1920'
|
|
||||||
),
|
|
||||||
'q' => array(
|
|
||||||
'name' => 'JPEG quality',
|
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'defaultValue' => 75
|
'defaultValue' => 1920,
|
||||||
|
),
|
||||||
|
'jpg_q' => array(
|
||||||
|
'name' => 'Max JPEG quality (optional)',
|
||||||
|
'exampleValue' => 75,
|
||||||
|
'type' => 'number',
|
||||||
|
'defaultValue' => 75,
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData()
|
||||||
|
{
|
||||||
|
$filteredUser = $this->getInput('u');
|
||||||
$width = $this->getInput('w');
|
$width = $this->getInput('w');
|
||||||
$max = $this->getInput('m');
|
$max = $this->getInput('m');
|
||||||
$quality = $this->getInput('q');
|
$previewQuality = $this->getInput('prev_q');
|
||||||
|
$jpgQuality = $this->getInput('jpg_q');
|
||||||
|
|
||||||
|
$url = 'https://unsplash.com/napi';
|
||||||
|
if (strlen($filteredUser) > 0) $url .= '/users/' . $filteredUser;
|
||||||
|
$url .= '/photos?page=1&per_page=' . $max;
|
||||||
|
$api_response = getContents($url);
|
||||||
|
|
||||||
$api_response = getContents('https://unsplash.com/napi/photos?page=1&per_page=' . $max);
|
|
||||||
$json = json_decode($api_response, true);
|
$json = json_decode($api_response, true);
|
||||||
|
|
||||||
foreach ($json as $json_item) {
|
foreach ($json as $json_item) {
|
||||||
$item = array();
|
$item = array();
|
||||||
|
|
||||||
// Get image URI
|
// Get image URI
|
||||||
$uri = $json_item['urls']['regular'] . '.jpg'; // '.jpg' only for format hint
|
$uri = $json_item['urls']['raw'] . '&fm=jpg';
|
||||||
$uri = str_replace('q=80', 'q=' . $quality, $uri);
|
if ($jpgQuality > 0) $uri .= '&q=' . $jpgQuality;
|
||||||
$uri = str_replace('w=1080', 'w=' . $width, $uri);
|
if ($width > 0) $uri .= '&w=' . $width . '&fit=max';
|
||||||
|
$uri .= '.jpg'; // only for format hint
|
||||||
$item['uri'] = $uri;
|
$item['uri'] = $uri;
|
||||||
|
|
||||||
// Get title from description
|
// Get title from description
|
||||||
if (is_null($json_item['alt_description'])) {
|
if (is_null($json_item['description'])) {
|
||||||
if (is_null($json_item['description'])) {
|
$item['title'] = 'Unsplash picture from ' . $json_item['user']['name'];
|
||||||
$item['title'] = 'Unsplash picture from ' . $json_item['user']['name'];
|
|
||||||
} else {
|
|
||||||
$item['title'] = $json_item['description'];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$item['title'] = $json_item['alt_description'];
|
$item['title'] = $json_item['description'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['timestamp'] = time();
|
$item['timestamp'] = $json_item['created_at'];
|
||||||
$item['content'] = $item['title']
|
$content = 'User: <a href="'
|
||||||
. '<br><a href="'
|
. $json_item['user']['links']['html']
|
||||||
. $item['uri']
|
. '">@'
|
||||||
|
. $json_item['user']['username']
|
||||||
|
. '</a>';
|
||||||
|
if (isset($json_item['location']['name'])) {
|
||||||
|
$content .= ' | Location: ' . $json_item['location']['name'];
|
||||||
|
}
|
||||||
|
$content .= ' | Image on <a href="'
|
||||||
|
. $json_item['links']['html']
|
||||||
|
. '">Unsplash</a><br><a href="'
|
||||||
|
. $uri
|
||||||
. '"><img src="'
|
. '"><img src="'
|
||||||
. $json_item['urls']['thumb']
|
. $json_item['urls'][$previewQuality]
|
||||||
|
. '" alt="Image from '
|
||||||
|
. $filteredUser
|
||||||
. '" /></a>';
|
. '" /></a>';
|
||||||
|
$item['content'] = $content;
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
$filteredUser = $this->getInput('u');
|
||||||
|
if (strlen($filteredUser) > 0) {
|
||||||
|
return $filteredUser . ' - ' . self::NAME;
|
||||||
|
} else {
|
||||||
|
return self::NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user