2015-07-15 12:05:36 +02:00
|
|
|
<?php
|
|
|
|
|
2015-11-08 12:00:06 +01:00
|
|
|
/**
|
|
|
|
* Plugin Wallabag.
|
|
|
|
*/
|
|
|
|
|
2015-12-22 10:20:27 +01:00
|
|
|
require_once 'WallabagInstance.php';
|
2017-05-09 18:12:15 +02:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2015-12-22 10:20:27 +01:00
|
|
|
|
2016-10-14 13:22:58 +02:00
|
|
|
/**
|
|
|
|
* Init function, return an error if the server is not set.
|
|
|
|
*
|
|
|
|
* @param $conf ConfigManager instance.
|
|
|
|
*
|
|
|
|
* @return array Eventual error.
|
|
|
|
*/
|
|
|
|
function wallabag_init($conf)
|
|
|
|
{
|
|
|
|
$wallabagUrl = $conf->get('plugins.WALLABAG_URL');
|
|
|
|
if (empty($wallabagUrl)) {
|
2017-05-09 18:12:15 +02:00
|
|
|
$error = t('Wallabag plugin error: '.
|
|
|
|
'Please define the "WALLABAG_URL" setting in the plugin administration page.');
|
2016-10-14 13:22:58 +02:00
|
|
|
return array($error);
|
|
|
|
}
|
2015-07-15 12:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add wallabag icon to link_plugin when rendering linklist.
|
|
|
|
*
|
2016-06-09 20:04:32 +02:00
|
|
|
* @param mixed $data Linklist data.
|
|
|
|
* @param ConfigManager $conf Configuration Manager instance.
|
2015-11-08 12:00:06 +01:00
|
|
|
*
|
2015-07-15 12:05:36 +02:00
|
|
|
* @return mixed - linklist data with wallabag plugin.
|
|
|
|
*/
|
2016-06-09 20:04:32 +02:00
|
|
|
function hook_wallabag_render_linklist($data, $conf)
|
2015-11-08 12:00:06 +01:00
|
|
|
{
|
2016-05-29 14:41:30 +02:00
|
|
|
$wallabagUrl = $conf->get('plugins.WALLABAG_URL');
|
|
|
|
if (empty($wallabagUrl)) {
|
2015-11-08 12:00:06 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2016-05-29 14:41:30 +02:00
|
|
|
$version = $conf->get('plugins.WALLABAG_VERSION');
|
|
|
|
$wallabagInstance = new WallabagInstance($wallabagUrl, $version);
|
2015-12-22 10:20:27 +01:00
|
|
|
|
|
|
|
$wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html');
|
2015-07-15 12:05:36 +02:00
|
|
|
|
2017-05-09 18:12:15 +02:00
|
|
|
$linkTitle = t('Save to wallabag');
|
2015-07-15 12:05:36 +02:00
|
|
|
foreach ($data['links'] as &$value) {
|
2015-12-22 10:20:27 +01:00
|
|
|
$wallabag = sprintf(
|
|
|
|
$wallabagHtml,
|
|
|
|
$wallabagInstance->getWallabagUrl(),
|
|
|
|
urlencode($value['url']),
|
2017-05-09 18:12:15 +02:00
|
|
|
PluginManager::$PLUGINS_PATH,
|
|
|
|
$linkTitle
|
2015-12-22 10:20:27 +01:00
|
|
|
);
|
2015-07-15 12:05:36 +02:00
|
|
|
$value['link_plugin'][] = $wallabag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2015-12-22 10:20:27 +01:00
|
|
|
|
2017-05-09 18:12:15 +02:00
|
|
|
/**
|
|
|
|
* This function is never called, but contains translation calls for GNU gettext extraction.
|
|
|
|
*/
|
|
|
|
function wallabag_dummy_translation()
|
|
|
|
{
|
|
|
|
// meta
|
|
|
|
t('For each link, add a QRCode icon.');
|
|
|
|
t('Wallabag API URL');
|
|
|
|
t('Wallabag API version (1 or 2)');
|
|
|
|
}
|