xref: /template/ad-hominem/rest/pageinfo.php (revision fdeb3ab57a5c049adca2a955b5a438a99b05dd62)
1<?php
2/**
3 * DokuWiki Information about a page in JSON format
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Sascha Leib <sascha@leib.be>
7 */
8
9header('Content-Type: application/json');
10
11//ini_set('display_errors', '1');
12
13/* connect to DokuWiki: */
14if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
15if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../../../'); }
16require_once(DOKU_INC . 'inc/init.php');
17
18/* get the output style (can be 'preview' or 'all') */
19$style = strtolower($_GET['v']);
20if ($style !== 'preview') { $style = 'all'; }
21
22/* initialize the storage: */
23$result = [
24	'type'	=> 'error'
25];
26
27/* find the page ID */
28$id = $_GET['id'];
29
30if ($id !== null) {
31
32	/* get all metadata; */
33	$meta = p_get_metadata($id);
34
35	if ($meta['title'] !== null) {
36
37		if ($style == 'preview') {
38			$result['type'] = 'preview';
39		} else {
40			$result['type'] = 'standard';
41			$result['pageid'] = $id;
42			$result['lang'] = $conf['lang'];
43		}
44
45		$result['title'] = $meta['title'];
46
47		/* The page URL(s) */
48		$url = wl($id);
49
50		if ($style == 'preview') {
51			$result['content_urls'] = [
52				'desktop' => [
53					'page' => wl($id)
54				]
55			];
56		} else {
57			$url = $conf['baseurl'] . wl($id);
58			$set = [
59				'page' => $url,
60				'revisions' => $url . '?do=revisions',
61				'edit' => $url . '?do=edit'
62			];
63			$result['content_urls'] = [
64				'desktop' => $set,
65				'mobile' => $set
66			];
67		}
68
69		/* extract the first paragraph:*/
70		$parts = explode("\n", $meta['description']['abstract']);
71		$result['extract'] = $parts[2];
72		$result['extract_html'] = '<p>'.$parts[2].'</p>';
73
74	} else {
75		$result['extract'] = 'Error: page does not exist.';
76		$result['extract_html'] = '<p><strong>' . $result['extract'] . '</strong></p>';
77	}
78	 $result['conf'] = $conf;
79	// $result['meta'] = $meta;
80}
81
82/* output the result: */
83echo json_encode($result);