Add integration with Wallabag2 (#574)
This commit is contained in:
parent
ade7569f0c
commit
0e2bf8417f
@ -232,7 +232,7 @@ Router\get_action('services', function () {
|
||||
|
||||
// Update bookmark services
|
||||
Router\post_action('services', function () {
|
||||
$values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0);
|
||||
$values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0, 'wallabag_enabled' => 0);
|
||||
Helper\check_csrf_values($values);
|
||||
|
||||
if (Model\Config\save($values)) {
|
||||
|
@ -18,6 +18,10 @@ function sync($item_id)
|
||||
if ((bool) Config\get('instapaper_enabled')) {
|
||||
instapaper_sync($item);
|
||||
}
|
||||
|
||||
if ((bool) Config\get('wallabag_enabled')) {
|
||||
wallabag_sync($item);
|
||||
}
|
||||
}
|
||||
|
||||
function instapaper_sync(array $item)
|
||||
@ -31,7 +35,7 @@ function instapaper_sync(array $item)
|
||||
|
||||
$url = 'https://www.instapaper.com/api/add?'.http_build_query($params);
|
||||
|
||||
$client = api_call($url);
|
||||
$client = api_get_call($url);
|
||||
|
||||
if ($client !== false) {
|
||||
return $client->getStatusCode() === 201;
|
||||
@ -52,7 +56,7 @@ function pinboard_sync(array $item)
|
||||
|
||||
$url = 'https://api.pinboard.in/v1/posts/add?'.http_build_query($params);
|
||||
|
||||
$client = api_call($url);
|
||||
$client = api_get_call($url);
|
||||
|
||||
if ($client !== false) {
|
||||
$response = json_decode($client->getContent(), true);
|
||||
@ -62,14 +66,122 @@ function pinboard_sync(array $item)
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_call($url)
|
||||
function wallabag_sync(array $item)
|
||||
{
|
||||
return wallabag_has_url($item['url'])
|
||||
? false
|
||||
: wallabag_add_item($item['url'], $item['title']);
|
||||
}
|
||||
|
||||
function wallabag_has_url($url)
|
||||
{
|
||||
$token = wallabag_get_access_token();
|
||||
if ($token === false) {
|
||||
return false;
|
||||
}
|
||||
$apiUrl = rtrim(Config\get('wallabag_url'), '\/') . '/api/entries/exists.json?url=' . urlencode($url);
|
||||
$headers = array('Authorization: Bearer ' . $token);
|
||||
$response = api_get_call($apiUrl, $headers);
|
||||
if ($response !== false) {
|
||||
$response = json_decode($response->getContent(), true);
|
||||
}
|
||||
return !empty($response['exists']);
|
||||
}
|
||||
|
||||
function wallabag_add_item($url, $title)
|
||||
{
|
||||
$token = wallabag_get_access_token();
|
||||
if ($token === false) {
|
||||
return false;
|
||||
}
|
||||
$apiUrl = rtrim(Config\get('wallabag_url'), '\/') . '/api/entries.json';
|
||||
$headers = array('Authorization: Bearer ' . $token);
|
||||
$data = array(
|
||||
'url' => $url,
|
||||
'title' => $title,
|
||||
);
|
||||
$response = api_post_call($apiUrl, $data, $headers);
|
||||
if ($response !== false) {
|
||||
$response = json_decode($response, true);
|
||||
}
|
||||
return !empty($response['id']);
|
||||
}
|
||||
|
||||
function wallabag_get_access_token()
|
||||
{
|
||||
if (!empty($_SESSION['wallabag_access_token'])) {
|
||||
return $_SESSION['wallabag_access_token'];
|
||||
}
|
||||
$url = rtrim(Config\get('wallabag_url'), '\/') . '/oauth/v2/token';
|
||||
$data = array(
|
||||
'grant_type' => 'password',
|
||||
'client_id' => Config\get('wallabag_client_id'),
|
||||
'client_secret' => Config\get('wallabag_client_secret'),
|
||||
'username' => Config\get('wallabag_username'),
|
||||
'password' => Config\get('wallabag_password')
|
||||
);
|
||||
$response = api_post_call($url, $data);
|
||||
if ($response !== false) {
|
||||
$response = json_decode($response, true);
|
||||
if (!empty($response['access_token'])) {
|
||||
$_SESSION['wallabag_access_token'] = $response['access_token'];
|
||||
return $_SESSION['wallabag_access_token'];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function api_get_call($url, array $headers = array())
|
||||
{
|
||||
try {
|
||||
$client = Client::getInstance();
|
||||
$client->setUserAgent(Config\HTTP_USER_AGENT);
|
||||
if ($headers) {
|
||||
$client->setHeaders($headers);
|
||||
}
|
||||
$client->execute($url);
|
||||
return $client;
|
||||
} catch (ClientException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function api_post_call($url, array $data, array $headers = array())
|
||||
{
|
||||
return function_exists('curl_init')
|
||||
? post_curl($url, $data, $headers)
|
||||
: post_stream($url, $data, $headers);
|
||||
}
|
||||
|
||||
function post_curl($url, array $data, array $headers = array())
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
if ($headers) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function post_stream($url, array $data, array $headers = array())
|
||||
{
|
||||
$contentType = array('Content-Type: application/x-www-form-urlencoded');
|
||||
$headers = $headers
|
||||
? array_merge($headers, $contentType)
|
||||
: $contentType;
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => implode("\r\n", $headers),
|
||||
'content' => http_build_query($data)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($url, false, $context);
|
||||
return $result;
|
||||
}
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
'Last login:' => 'Poslední přihlášení:',
|
||||
'Search' => 'Hledat',
|
||||
'There are no results for your search' => 'Žádné výsledky pro toto hledání',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
'Last login:' => 'Letzte Anmeldung:',
|
||||
'Search' => 'Suchen',
|
||||
'There are no results for your search' => 'Deine Suche lieferte keine Ergebnisse',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
'Last login:' => 'Dernière connexion :',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -249,4 +249,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
'Last login:' => 'Последний вход:',
|
||||
'Search' => 'Поиск',
|
||||
'There are no results for your search' => 'По вашему запросу ничего не нашлось',
|
||||
'Send bookmarks to Wallabag' => 'Отправлять закладки в Wallabag',
|
||||
'Wallabag username' => 'Имя пользователя Wallabag',
|
||||
'Wallabag password' => 'Пароль Wallabag',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
'Last login:' => 'En son sisteme giriş zamanı:',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -247,4 +247,7 @@ return array(
|
||||
// 'Last login:' => '',
|
||||
// 'Search' => '',
|
||||
// 'There are no results for your search' => '',
|
||||
// 'Send bookmarks to Wallabag' => '',
|
||||
// 'Wallabag username' => '',
|
||||
// 'Wallabag password' => '',
|
||||
);
|
||||
|
@ -16,7 +16,7 @@
|
||||
<form method="post" action="?action=services" autocomplete="off" id="config-form">
|
||||
|
||||
<?php echo Miniflux\Helper\form_hidden('csrf', $values) ?>
|
||||
|
||||
|
||||
<h3><?php echo t('Pinboard') ?></h3>
|
||||
<div class="options">
|
||||
<?php echo Miniflux\Helper\form_checkbox('pinboard_enabled', t('Send bookmarks to Pinboard'), 1, isset($values['pinboard_enabled']) && $values['pinboard_enabled'] == 1) ?><br />
|
||||
@ -39,7 +39,27 @@
|
||||
<?php echo Miniflux\Helper\form_label(t('Instapaper password'), 'instapaper_password') ?>
|
||||
<?php echo Miniflux\Helper\form_password('instapaper_password', $values, $errors) ?><br/>
|
||||
</div>
|
||||
|
||||
|
||||
<h3><?php echo t('Wallabag') ?></h3>
|
||||
<div class="options">
|
||||
<?php echo Miniflux\Helper\form_checkbox('wallabag_enabled', t('Send bookmarks to Wallabag'), 1, isset($values['wallabag_enabled']) && $values['wallabag_enabled'] == 1) ?><br />
|
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Wallabag URL'), 'wallabag_url') ?>
|
||||
<?php echo Miniflux\Helper\form_text('wallabag_url', $values, $errors) ?><br/>
|
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Wallabag client_id'), 'wallabag_client_id') ?>
|
||||
<?php echo Miniflux\Helper\form_text('wallabag_client_id', $values, $errors) ?><br/>
|
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Wallabag client_secret'), 'wallabag_client_secret') ?>
|
||||
<?php echo Miniflux\Helper\form_text('wallabag_client_secret', $values, $errors) ?><br/>
|
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Wallabag username'), 'wallabag_username') ?>
|
||||
<?php echo Miniflux\Helper\form_text('wallabag_username', $values, $errors) ?><br/>
|
||||
|
||||
<?php echo Miniflux\Helper\form_label(t('Wallabag password'), 'wallabag_password') ?>
|
||||
<?php echo Miniflux\Helper\form_text('wallabag_password', $values, $errors) ?><br/>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?php echo t('Save') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
|
12
vendor/composer/ClassLoader.php
vendored
12
vendor/composer/ClassLoader.php
vendored
@ -53,8 +53,8 @@ class ClassLoader
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
|
||||
private $classMapAuthoritative = false;
|
||||
private $missingClasses = array();
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
@ -322,20 +322,20 @@ class ClassLoader
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative) {
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if ($file === null && defined('HHVM_VERSION')) {
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
return $this->classMap[$class] = false;
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
@ -399,6 +399,8 @@ class ClassLoader
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user