diff options
-rw-r--r-- | plugins/archiveorg/archiveorg.html | 1 | ||||
-rw-r--r-- | plugins/archiveorg/archiveorg.php | 25 | ||||
-rw-r--r-- | plugins/archiveorg/internetarchive.png | bin | 0 -> 878 bytes | |||
-rw-r--r-- | tests/plugins/PluginArchiveorgTest.php | 48 |
4 files changed, 74 insertions, 0 deletions
diff --git a/plugins/archiveorg/archiveorg.html b/plugins/archiveorg/archiveorg.html new file mode 100644 index 00000000..ce3bc6b7 --- /dev/null +++ b/plugins/archiveorg/archiveorg.html | |||
@@ -0,0 +1 @@ | |||
<span><a href="https://web.archive.org/web/%s"><img width="13" height="13" src="plugins/archiveorg/internetarchive.png" title="View on archive.org" /></a></span> \ No newline at end of file | |||
diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php new file mode 100644 index 00000000..7d172584 --- /dev/null +++ b/plugins/archiveorg/archiveorg.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Plugin Archive.org. | ||
4 | * | ||
5 | * Add an icon in the link list for archive.org. | ||
6 | */ | ||
7 | |||
8 | /** | ||
9 | * Add archive.org icon to link_plugin when rendering linklist. | ||
10 | * | ||
11 | * @param mixed $data - linklist data. | ||
12 | * | ||
13 | * @return mixed - linklist data with archive.org plugin. | ||
14 | */ | ||
15 | function hook_archiveorg_render_linklist($data) | ||
16 | { | ||
17 | $archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html'); | ||
18 | |||
19 | foreach ($data['links'] as &$value) { | ||
20 | $archive = sprintf($archive_html, $value['url']); | ||
21 | $value['link_plugin'][] = $archive; | ||
22 | } | ||
23 | |||
24 | return $data; | ||
25 | } | ||
diff --git a/plugins/archiveorg/internetarchive.png b/plugins/archiveorg/internetarchive.png new file mode 100644 index 00000000..ca070769 --- /dev/null +++ b/plugins/archiveorg/internetarchive.png | |||
Binary files differ | |||
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php new file mode 100644 index 00000000..dbc52bc8 --- /dev/null +++ b/tests/plugins/PluginArchiveorgTest.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * PluginArchiveorgTest.php | ||
5 | */ | ||
6 | |||
7 | require_once 'plugins/archiveorg/archiveorg.php'; | ||
8 | |||
9 | /** | ||
10 | * Class PlugQrcodeTest | ||
11 | * Unit test for the QR-Code plugin | ||
12 | */ | ||
13 | class PluginArchiveorgTest extends PHPUnit_Framework_TestCase | ||
14 | { | ||
15 | /** | ||
16 | * Reset plugin path | ||
17 | */ | ||
18 | function setUp() | ||
19 | { | ||
20 | PluginManager::$PLUGINS_PATH = 'plugins'; | ||
21 | } | ||
22 | |||
23 | /** | ||
24 | * Test render_linklist hook. | ||
25 | */ | ||
26 | function testArchiveorgLinklist() | ||
27 | { | ||
28 | $str = 'http://randomstr.com/test'; | ||
29 | $data = array( | ||
30 | 'title' => $str, | ||
31 | 'links' => array( | ||
32 | array( | ||
33 | 'url' => $str, | ||
34 | ) | ||
35 | ) | ||
36 | ); | ||
37 | |||
38 | $data = hook_archiveorg_render_linklist($data); | ||
39 | $link = $data['links'][0]; | ||
40 | // data shouldn't be altered | ||
41 | $this->assertEquals($str, $data['title']); | ||
42 | $this->assertEquals($str, $link['url']); | ||
43 | |||
44 | // plugin data | ||
45 | $this->assertEquals(1, count($link['link_plugin'])); | ||
46 | $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); | ||
47 | } | ||
48 | } | ||