ajout heimdall
This commit is contained in:
93
heimdall/config/www/SupportedApps/Ghost/Ghost.php
Executable file
93
heimdall/config/www/SupportedApps/Ghost/Ghost.php
Executable file
@@ -0,0 +1,93 @@
|
||||
<?php namespace App\SupportedApps\Ghost;
|
||||
use Exception;
|
||||
|
||||
class Ghost extends \App\SupportedApps implements \App\EnhancedApps {
|
||||
public $config;
|
||||
|
||||
function __construct() {
|
||||
$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
$this->authorized = false;
|
||||
}
|
||||
|
||||
public function test() {
|
||||
try {
|
||||
$this->auth();
|
||||
echo "Successfully communicated with the API";
|
||||
} catch (Exception $err) {
|
||||
echo "Error connecting to Ghost: ".$err->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function auth() {
|
||||
if ($this->authorized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->authorized = false;
|
||||
|
||||
$attrs = [
|
||||
'cookies' => $this->jar,
|
||||
'headers' => ['content-type' => 'application/json']
|
||||
];
|
||||
$body["username"] = $this->config->username;
|
||||
$body["password"] = $this->config->password;
|
||||
$vars = [
|
||||
'http_errors' => false,
|
||||
'timeout' => 5,
|
||||
'body' => json_encode($body)
|
||||
];
|
||||
|
||||
$result = parent::execute($this->url('ghost/api/v3/admin/session'), $attrs, $vars, 'POST');
|
||||
|
||||
if (null === $result) {
|
||||
throw new Exception("Error contacting the API");
|
||||
}
|
||||
|
||||
if ($result->getStatusCode() !== 201) {
|
||||
switch ($result->getStatusCode()) {
|
||||
case 404:
|
||||
throw new Exception("User is not found");
|
||||
case 422:
|
||||
throw new Exception("Invalid credentials");
|
||||
}
|
||||
|
||||
throw new Exception("Unknown error");
|
||||
}
|
||||
|
||||
$this->authorized = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function livestats() {
|
||||
$status = 'inactive';
|
||||
|
||||
$this->auth();
|
||||
|
||||
$attrs = [
|
||||
'cookies' => $this->jar,
|
||||
'headers' => ['content-type' => 'application/json']
|
||||
];
|
||||
$result = parent::execute($this->url('ghost/api/v3/admin/posts/'), $attrs, []);
|
||||
if (null === $result) {
|
||||
throw new Exception("Could not connect to Ghost");
|
||||
}
|
||||
|
||||
$response = json_decode($result->getBody());
|
||||
$posts = $response->posts;
|
||||
$statuses = array_count_values(array_column($posts, 'status'));
|
||||
|
||||
$data = [
|
||||
'draft' => isset($statuses['draft']) ? $statuses['draft'] : 0,
|
||||
'scheduled' => isset($statuses['scheduled']) ? $statuses['scheduled'] : 0,
|
||||
'published' => isset($statuses['published']) ? $statuses['published'] : 0
|
||||
];
|
||||
$status = 'active';
|
||||
return parent::getLiveStats($status, $data);
|
||||
|
||||
}
|
||||
|
||||
public function url($endpoint) {
|
||||
$api_url = parent::normaliseurl($this->config->url).$endpoint;
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
10
heimdall/config/www/SupportedApps/Ghost/app.json
Executable file
10
heimdall/config/www/SupportedApps/Ghost/app.json
Executable file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "c4745785181de931cfd5bd79294cb1687d82aea9",
|
||||
"name": "Ghost",
|
||||
"website": "https://github.com/tryghost/ghost",
|
||||
"license": "MIT License",
|
||||
"description": "Fiercely independent, professional publishing. A fully open source, powerful platform for building and running modern publications, we power serious blogs, magazines and journalism from DuckDuckGo to OpenAI & Sky News.",
|
||||
"enhanced": true,
|
||||
"tile_background": "light",
|
||||
"icon": "ghost.png"
|
||||
}
|
||||
19
heimdall/config/www/SupportedApps/Ghost/config.blade.php
Executable file
19
heimdall/config/www/SupportedApps/Ghost/config.blade.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<div class="input">
|
||||
<label>{{ strtoupper(__('app.url')) }}</label>
|
||||
{!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.username') }}</label>
|
||||
{!! Form::text('config[username]', null, array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::password('config[password]', array('placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
BIN
heimdall/config/www/SupportedApps/Ghost/ghost.png
Executable file
BIN
heimdall/config/www/SupportedApps/Ghost/ghost.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
10
heimdall/config/www/SupportedApps/Ghost/livestats.blade.php
Executable file
10
heimdall/config/www/SupportedApps/Ghost/livestats.blade.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<ul class="livestats">
|
||||
<li>
|
||||
<span class="title">Published</span>
|
||||
<strong>{!! $published !!}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">Draft</span>
|
||||
<strong>{!! $draft !!}</strong>
|
||||
</li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user