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 (at) kolmio.com>
7 */
8
9header('Content-Type: application/json');
10header('Access-Control-Allow-Origin: *');
11
12//ini_set('display_errors', '1');
13
14/* connect to DokuWiki: */
15if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
16if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../../../'); }
17require_once(DOKU_INC . 'inc/init.php');
18
19/* get the output style (can be 'preview' or 'all') */
20$style = strtolower($_GET['v']);
21if ($style !== 'preview') { $style = 'all'; }
22
23/* initialize the storage: */
24$result = [
25	'type'	=> 'error'
26];
27
28/* find the page ID */
29$id = $_GET['id'];
30
31if ($id !== null) {
32
33	/* get all metadata; */
34	$meta = p_get_metadata($id);
35
36	if ($meta['title'] && $meta['title'] !== null) {
37
38		if ($style == 'preview') {
39			$result['type'] = 'preview';
40		} else {
41			$result['type'] = 'standard';
42			$result['pageid'] = $id;
43			$result['lang'] = $conf['lang'];
44		}
45
46		$result['title'] = $meta['title'];
47
48		/* The page URL(s) */
49		$url = wl($id);
50
51		if ($style == 'preview') {
52			$result['content_urls'] = [
53				'desktop' => [
54					'page' => wl($id)
55				]
56			];
57		} else {
58			$url = $conf['baseurl'] . wl($id);
59			$set = [
60				'page' => $url,
61				'revisions' => $url . '?do=revisions',
62				'edit' => $url . '?do=edit'
63			];
64			$result['content_urls'] = [
65				'desktop' => $set,
66				'mobile' => $set
67			];
68		}
69
70		/* extract the first paragraph:*/
71		$parts = explode("\n", $meta['description']['abstract']);
72		$result['extract'] = $parts[2];
73		$result['extract_html'] = '<p>'.$parts[2].'</p>';
74
75	} else {
76		$result['extract'] = 'Error: page does not exist.';
77		$result['extract_html'] = '<p><strong>' . $result['extract'] . '</strong></p>';
78	}
79	// $result['conf'] = $conf; /* WARNING: this may expose your configuration to the Internet. Use only for debugging! */
80	// $result['meta'] = $meta; /* uncomment if you need additional meta information */
81}
82
83/* output the result: */
84echo json_encode($result);