aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/wallabag/WallabagInstance.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-01-02 20:09:29 +0100
committerVirtualTam <virtualtam@flibidi.net>2016-01-02 20:09:29 +0100
commitdefc8a3f033a44602c598c2028a9ee3ee2a86d1d (patch)
treeefb09f1c0d7b16e2c2dcb0313157d93ece6775b4 /plugins/wallabag/WallabagInstance.php
parent66d86ea521d737b1bc92b16b9c9b4126f545916c (diff)
parent938d9cce77ed5098dd69643795cb4014f3688b35 (diff)
downloadShaarli-defc8a3f033a44602c598c2028a9ee3ee2a86d1d.tar.gz
Shaarli-defc8a3f033a44602c598c2028a9ee3ee2a86d1d.tar.zst
Shaarli-defc8a3f033a44602c598c2028a9ee3ee2a86d1d.zip
Merge pull request #417 from ArthurHoaro/wallabag-improve
Wallabag plugin improvement
Diffstat (limited to 'plugins/wallabag/WallabagInstance.php')
-rw-r--r--plugins/wallabag/WallabagInstance.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/wallabag/WallabagInstance.php b/plugins/wallabag/WallabagInstance.php
new file mode 100644
index 00000000..87352e66
--- /dev/null
+++ b/plugins/wallabag/WallabagInstance.php
@@ -0,0 +1,71 @@
1<?php
2
3/**
4 * Class WallabagInstance.
5 */
6class WallabagInstance
7{
8 /**
9 * @var array Static reference to differrent WB API versions.
10 * - key: version ID, must match plugin settings.
11 * - value: version name.
12 */
13 private static $wallabagVersions = array(
14 1 => '1.x',
15 2 => '2.x',
16 );
17
18 /**
19 * @var array Static reference to WB endpoint according to the API version.
20 * - key: version name.
21 * - value: endpoint.
22 */
23 private static $wallabagEndpoints = array(
24 '1.x' => '?plainurl=',
25 '2.x' => 'bookmarklet?url=',
26 );
27
28 /**
29 * @var string Wallabag user instance URL.
30 */
31 private $instanceUrl;
32
33 /**
34 * @var string Wallabag user instance API version.
35 */
36 private $apiVersion;
37
38 function __construct($instance, $version)
39 {
40 if ($this->isVersionAllowed($version)) {
41 $this->apiVersion = self::$wallabagVersions[$version];
42 } else {
43 // Default API version: 1.x.
44 $this->apiVersion = self::$wallabagVersions[1];
45 }
46
47 $this->instanceUrl = add_trailing_slash($instance);
48 }
49
50 /**
51 * Build the Wallabag URL to reach from instance URL and API version endpoint.
52 *
53 * @return string wallabag url.
54 */
55 public function getWallabagUrl()
56 {
57 return $this->instanceUrl . self::$wallabagEndpoints[$this->apiVersion];
58 }
59
60 /**
61 * Checks version configuration.
62 *
63 * @param mixed $version given version ID.
64 *
65 * @return bool true if it's valid, false otherwise.
66 */
67 private function isVersionAllowed($version)
68 {
69 return isset(self::$wallabagVersions[$version]);
70 }
71}