]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/wallabag/WallabagInstance.php
4 * Class WallabagInstance.
9 * @var array Static reference to differrent WB API versions.
10 * - key: version ID, must match plugin settings.
11 * - value: version name.
13 private static $wallabagVersions = array(
19 * @var array Static reference to WB endpoint according to the API version.
20 * - key: version name.
23 private static $wallabagEndpoints = array(
24 '1.x' => '?plainurl=',
25 '2.x' => 'bookmarklet?url=',
29 * @var string Wallabag user instance URL.
34 * @var string Wallabag user instance API version.
38 public function __construct($instance, $version)
40 if ($this->isVersionAllowed($version)) {
41 $this->apiVersion
= self
::$wallabagVersions[$version];
43 // Default API version: 1.x.
44 $this->apiVersion
= self
::$wallabagVersions[1];
47 $this->instanceUrl
= add_trailing_slash($instance);
51 * Build the Wallabag URL to reach from instance URL and API version endpoint.
53 * @return string wallabag url.
55 public function getWallabagUrl()
57 return $this->instanceUrl
. self
::$wallabagEndpoints[$this->apiVersion
];
61 * Checks version configuration.
63 * @param mixed $version given version ID.
65 * @return bool true if it's valid, false otherwise.
67 private function isVersionAllowed($version)
69 return isset(self
::$wallabagVersions[$version]);