]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - plugins/wallabag/WallabagInstance.php
Increase buffer size for cURL download
[github/shaarli/Shaarli.git] / plugins / wallabag / WallabagInstance.php
CommitLineData
c0a50f36
A
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
93b1fe54 38 public function __construct($instance, $version)
c0a50f36
A
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}