-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7cfccea
Showing
16 changed files
with
1,152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# v1.0.0 | ||
## 20/08/2017 | ||
|
||
1. [](#new) | ||
* Initial release | ||
* Support for images and collections |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Grav Astrobin Plugin | ||
================== | ||
|
||
This plugin allows you to fetch astrobin images and collections, and display them in page. | ||
|
||
The current template make use of `featherlight`, with the `gallery` option enabled, to open your images in a slideshow. | ||
If you wish to change this behaviour, please modify templates in the `templates/partial` directory. | ||
|
||
Astrobin data is provided via shortcodes, the `shortcode-core` plugin is therefore another dependency. | ||
|
||
Quick usage | ||
----------- | ||
|
||
First you must configure your Astrobin account, getting an API key and secret. Just click on your username on the right, and in the menu select "API Keys", then request a new key if you don't already have one. | ||
|
||
Configure the astrobin plugin (`astrobin.yaml` in `user/config/plugins/`, or even better using Grav Admin), with these values: | ||
|
||
astrobin_api_key: "<your api key>" | ||
astrobin_api_secret: "<your api secret>" | ||
|
||
To test the plugin you need to find the id of the Astrobin daya you want to display. | ||
Currently the plugin supports single images, imagesets (albums) and collections. | ||
The id can usually be found on the url of the resource you are currently browsing. | ||
|
||
### Single image | ||
|
||
[astrobin-image id=<image-id>] | ||
|
||
### Collections | ||
|
||
[astrobin-collection id=<collection-id>] | ||
|
||
|
||
Advanced Options | ||
---------------- | ||
|
||
Each shortcode accepts additional values beside the `id` parameter. | ||
This is a list for each shortcode. | ||
|
||
* astrobin-image: | ||
* `format_image`: single letter, defining the image size to be displayed. Look [Astrobin URL reference](https://www.astrobin.com/services/api/misc.urls.html) for all possible values. | ||
* `format_image_lightbox`: same values as the previous parameter, but used to define image size in the lightbox popup. | ||
* `image_class`: extra css classes for the main image html tag. | ||
* `image_lightbox_class`: extra css classes for the main lightbox html tag. | ||
* astrobin-collection | ||
* `collection_title_tag`: HTML tag to use for the collection title. | ||
* `collection_description_tag`: HTML tag to use for the collection description. | ||
* `collection_class`: extra css classes for the main collection html tag. | ||
* All the parameters for **astrobin-image** are also supported to properly display child images. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
namespace Grav\Plugin; | ||
|
||
use Grav\Common\Plugin; | ||
|
||
|
||
class AstrobinPlugin extends Plugin | ||
{ | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
'onShortcodeHandlers' => ['onShortcodeHandlers', 0], | ||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], | ||
'onPluginsInitialized' => ['onPluginsInitialized', 0], | ||
]; | ||
} | ||
|
||
public function onPluginsInitialized() | ||
{ | ||
$this->config = $this->grav['config']; | ||
$this->enable([ | ||
'onPageInitialized' => ['onPageInitialized', 0], | ||
]); | ||
} | ||
|
||
/** | ||
* Add current directory to twig lookup paths. | ||
*/ | ||
public function onTwigTemplatePaths() | ||
{ | ||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; | ||
} | ||
|
||
/** | ||
* Initialize configuration | ||
*/ | ||
public function onShortcodeHandlers() | ||
{ | ||
$this->grav['shortcode']->registerAllShortcodes(__DIR__.'/shortcodes'); | ||
} | ||
|
||
public function onPageInitialized() | ||
{ | ||
$this->grav['assets']->addCss('plugin://astrobin/css/astrobin.css'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enabled: true | ||
astrobin_api_key: "" | ||
astrobin_api_secret: "" | ||
astrobin_cache_duration: "7200" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Astrobin | ||
version: 1.0.0 | ||
description: "This plugin provides astrobin shortcodes for images and galleries" | ||
icon: picture-o | ||
author: | ||
name: Marco Gulino | ||
email: marco@gulinux.net | ||
url: http://gulinux.net | ||
homepage: https://github.com/GuLinux/grav-plugin-astrobin | ||
keywords: astrobin, media | ||
bugs: https://github.com/GuLinux/grav-plugin-astrobin/issues | ||
license: GPLv3 | ||
|
||
dependencies: | ||
- shortcode-core | ||
- featherlight | ||
|
||
form: | ||
validation: strict | ||
fields: | ||
enabled: | ||
type: toggle | ||
label: Plugin Enabled | ||
highlight: 1 | ||
default: 1 | ||
options: | ||
1: Enabled | ||
0: Disabled | ||
validate: | ||
type: bool | ||
|
||
astrobin_api_key: | ||
type: text | ||
size: medium | ||
label: Astrobin API Key | ||
validate: | ||
required: true | ||
astrobin_api_secret: | ||
type: text | ||
size: medium | ||
label: Astrobin API Secret | ||
validate: | ||
required: true | ||
astrobin_cache_duration: | ||
type: text | ||
size: small | ||
label: Astrobin requests cache duration (seconds, 0 to disable caching) | ||
validate: | ||
type: number | ||
min: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Grav\Plugin\Astrobin; | ||
require_once(__DIR__.'/Image.php'); | ||
require_once(__DIR__.'/Collection.php'); | ||
|
||
use Grav\Common\Grav; | ||
use Grav\Plugin\Astrobin\Collection; | ||
|
||
use Grav\Common\GPM\Response; | ||
use Grav\Common\Cache; | ||
|
||
class AstrobinAPIException extends \Exception { | ||
public function __construct($obj) | ||
{ | ||
parent::__construct("Error during Astrobin API call with code " . $obj['code'] . ": " . $obj['message'], $obj['code'], null); | ||
} | ||
} | ||
|
||
class AstrobinAPI | ||
{ | ||
protected $key; | ||
protected $secret; | ||
protected $user_id; | ||
protected $grav; | ||
protected $config; | ||
protected $cache; | ||
protected $cache_duration; | ||
|
||
/** | ||
* set some instance variable states | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->grav = Grav::instance(); | ||
$this->config = $this->grav['config']; | ||
$this->key = $this->config->get('plugins.astrobin.astrobin_api_key'); | ||
$this->secret = $this->config->get('plugins.astrobin.astrobin_api_secret'); | ||
$this->cache_duration = $this->config->get('plugins.astrobin.astrobin_cache_duration'); | ||
$this->cache = new Cache($this->grav); | ||
} | ||
|
||
public function image($id) | ||
{ | ||
return $this->image_by_uri("/image/" . $id . "/"); | ||
} | ||
|
||
public function image_by_uri($uri, $has_prefix = false) | ||
{ | ||
$info = $this->request($uri, [], ! $has_prefix); | ||
if($info != NULL) | ||
return new Image($info, $this); | ||
return NULL; | ||
} | ||
|
||
public function collection($id) | ||
{ | ||
$info = $this->request( '/collection/' . $id . '/'); | ||
if($info != NULL) | ||
return new Collection($info, $this); | ||
return NULL; | ||
} | ||
|
||
private function request($path, $params = [], $add_prefix = true) { | ||
$prefix = ''; | ||
if($add_prefix) | ||
$prefix = '/api/v1'; | ||
|
||
$url = 'https://www.astrobin.com' . $prefix . $path . "?" . http_build_query(array_merge($params, ['api_key' => $this->key, 'format' => 'json', 'api_secret' => $this->secret])); | ||
if($this->cache_duration > 0) { | ||
$obj = $this->cache->fetch($url); | ||
if($obj) { | ||
return $obj; | ||
} | ||
} | ||
try { | ||
$response = Response::get($url); | ||
$obj = json_decode($response); | ||
if($this->cache_duration > 0) { | ||
$this->cache->save($url, $obj, $this->cache_duration); | ||
} | ||
return $obj; | ||
} catch(Exception $e) { | ||
throw new AstrobinAPIException($e); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Grav\Plugin\Astrobin; | ||
require_once(__DIR__.'/AstrobinAPI.php'); | ||
|
||
class AstrobinCommons { | ||
static function defaultParams() { | ||
return [ | ||
'format_image' => 'regular', | ||
'format_image_lightbox' => 'hd', | ||
'collection_title_tag' => 'h3', | ||
'collection_description_tag' => 'h5' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Grav\Plugin\Astrobin; | ||
require_once(__DIR__.'/Image.php'); | ||
use Grav\Plugin\Astrobin\Image; | ||
|
||
use Grav\Common\Grav; | ||
|
||
class Collection | ||
{ | ||
private $info; | ||
private $images; | ||
|
||
public function __construct($tree, $api) | ||
{ | ||
$this->info = $tree; | ||
$this->images = []; | ||
foreach($this->info->images as $image) { | ||
array_push($this->images, $api->image_by_uri($image, true)); | ||
} | ||
} | ||
|
||
public function images() { | ||
return $this->images; | ||
} | ||
|
||
public function title() { | ||
return $this->info->name; | ||
} | ||
public function description() { | ||
return $this->info->description; | ||
} | ||
|
||
public function user() { | ||
return $this->info->user; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Grav\Plugin\Astrobin; | ||
|
||
use Grav\Common\Grav; | ||
|
||
class Image | ||
{ | ||
private $info; | ||
|
||
public function __construct($info) | ||
{ | ||
$this->info = $info; | ||
} | ||
|
||
public function id() { | ||
return $this->info->id; | ||
} | ||
|
||
public function title() { | ||
return $this->info->title; | ||
} | ||
|
||
public function datetaken() { | ||
// TODO: to be retrieved in astrobin from acquisition details | ||
return NULL; | ||
} | ||
|
||
public function url($format) { | ||
return $this->info->{'url_' . $format}; | ||
} | ||
|
||
public function astrobinPage() { | ||
return 'https://www.astrobin.com/' . $this->info->id; | ||
} | ||
|
||
public function description() { | ||
return $this->info->description; | ||
} | ||
|
||
private function username() { | ||
return $this->info->user; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.astrobin-lightbox { | ||
display: none; | ||
text-align: center; | ||
} | ||
|
||
.astrobin-image { | ||
display: inline-block; | ||
min-width: 150px; | ||
text-align: center; | ||
padding: 20px; | ||
} | ||
|
||
.astrobin-image figcaption { | ||
font-size: smaller; | ||
} | ||
|
||
.astrobin-collection-title { | ||
} | ||
.astrobin-collection-description { | ||
} | ||
|
||
.astrobin-lightbox-links a{ | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
} | ||
.astrobin-lightbox-title { | ||
/* display: inline; */ | ||
} | ||
|
||
.featherlight-next:hover span, .featherlight-previous:hover span { | ||
text-shadow: 0 0 5px #111111; | ||
} |
Oops, something went wrong.