Merge pull request #280 from ArthurHoaro/plugin-readityourself

PLUGIN readityourself
This commit is contained in:
Arthur 2015-11-08 12:45:19 +01:00
commit e760840fea
5 changed files with 122 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

View file

@ -0,0 +1,3 @@
<?php
$GLOBALS['plugins']['READITYOUSELF_URL'] = 'http://someurl.com';

View file

@ -0,0 +1 @@
<span><a href="%s?url=%s"><img width="13" height="13" src="%s/readityourself/book-open.png" title="Read with Readityourself" /></a></span>

View file

@ -0,0 +1,43 @@
<?php
/**
* Plugin readityourself
*/
// If we're talking about https://github.com/memiks/readityourself
// it seems kinda dead.
// Not tested.
// don't raise unnecessary warnings
if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) {
include PluginManager::$PLUGINS_PATH . '/readityourself/config.php';
}
if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
$GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '.
'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '.
'in "plugins/wallabag/config.php" or in your Shaarli config.php file.';
}
/**
* Add readityourself icon to link_plugin when rendering linklist.
*
* @param mixed $data - linklist data.
*
* @return mixed - linklist data with readityourself plugin.
*/
function hook_readityourself_render_linklist($data)
{
if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
return $data;
}
$readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html');
foreach ($data['links'] as &$value) {
$readityourself = sprintf($readityourself_html, $GLOBALS['plugins']['READITYOUSELF_URL'], $value['url'], PluginManager::$PLUGINS_PATH);
$value['link_plugin'][] = $readityourself;
}
return $data;
}

View file

@ -0,0 +1,75 @@
<?php
/**
* PluginReadityourselfTest.php.php
*/
require_once 'plugins/readityourself/readityourself.php';
/**
* Class PluginWallabagTest
* Unit test for the Wallabag plugin
*/
class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testReadityourselfLinklist()
{
$GLOBALS['plugins']['READITYOUSELF_URL'] = 'value';
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_readityourself_render_linklist($data);
$link = $data['links'][0];
// data shouldn't be altered
$this->assertEquals($str, $data['title']);
$this->assertEquals($str, $link['url']);
// plugin data
$this->assertEquals(1, count($link['link_plugin']));
$this->assertNotFalse(strpos($link['link_plugin'][0], $str));
}
/**
* Test without config: nothing should happened.
*/
function testReadityourselfLinklistWithoutConfig()
{
unset($GLOBALS['plugins']['READITYOUSELF_URL']);
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_readityourself_render_linklist($data);
$link = $data['links'][0];
// data shouldn't be altered
$this->assertEquals($str, $data['title']);
$this->assertEquals($str, $link['url']);
// plugin data
$this->assertArrayNotHasKey('link_plugin', $link);
}
}