7 * Micropub endpoint URL
14 * Micropub media endpoint URL
21 * Access token endpoint URL
28 * Authorization endpoint URL
32 public $authorization;
34 public function incomplete()
36 return $this->authorization === null
37 || $this->token === null
38 || $this->micropub === null;
41 public function discover($server)
43 //TODO: discovery via link headers
44 $baseUrl = new \Net_URL2($server);
46 $doc = new \DOMDocument();
47 @$doc->loadHTMLFile($server);
48 $sx = simplexml_import_dom($doc);
50 Log::err('Error loading URL: ' . $server);
53 //$sx->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');
56 '/html/head/link[@rel="authorization_endpoint" and @href]'
59 Log::err('No authorization endpoint found at ' . $server);
62 $this->authorization = (string) $baseUrl->resolve(
63 (string) $auths[0]['href']
67 '/html/head/link[@rel="token_endpoint" and @href]'
69 if (!count($tokens)) {
70 Log::err('No token endpoint found');
73 $this->token = (string) $baseUrl->resolve(
74 (string) $tokens[0]['href']
78 '/html/head/link[@rel="micropub" and @href]'
81 Log::err('No micropub endpoint found');
84 $this->micropub = (string) $baseUrl->resolve(
85 (string) $mps[0]['href']
89 public function load($server)
91 $file = $this->getCacheFilePath($server, false);
92 if ($file === false || !file_exists($file)) {
95 $data = parse_ini_file($file);
96 foreach ($data as $prop => $val) {
97 if (!property_exists($this, $prop)) {
98 Log::err('Invalid cache config key "' . $prop . '"');
106 public function save($server)
108 $file = $this->getCacheFilePath($server, true);
109 if ($file === false) {
115 'micropub=' . Config::quoteIniValue($this->micropub) . "\n"
116 . 'media=' . Config::quoteIniValue($this->media) . "\n"
117 . 'token=' . Config::quoteIniValue($this->token) . "\n"
119 . Config::quoteIniValue($this->authorization) . "\n"
123 public function getCacheFilePath($server, $create = false)
125 if (isset($_SERVER['XDG_CACHE_HOME'])
126 && $_SERVER['XDG_CACHE_HOME'] != ''
128 $cacheBaseDir = $_SERVER['XDG_CACHE_HOME'];
130 if (!isset($_SERVER['HOME']) || $_SERVER['HOME'] == '') {
131 Log::err('Cannot determine home directory');
134 $cacheBaseDir = $_SERVER['HOME'] . '/.cache';
137 $cacheDir = $cacheBaseDir . '/shpub';
138 if (!is_dir($cacheDir) && $create) {
139 mkdir($cacheDir, 0700, true);
141 $file = $cacheDir . '/' . urlencode($server) . '.ini';