summaryrefslogtreecommitdiffstats
path: root/templates/55/ad-hominem/rest/pageinfo.php
blob: 2280181ccecdf11638d33ccf6f5394baf879cce5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
 * DokuWiki Information about a page in JSON format
 *
 * @license		GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author		Sascha Leib <sascha.leib (at) kolmio.com>
 */

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');

//ini_set('display_errors', '1');

/* connect to DokuWiki: */
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../../../'); }
require_once(DOKU_INC . 'inc/init.php');

/* get the output style (can be 'preview' or 'all') */
$style = strtolower($_GET['v']);
if ($style !== 'preview') { $style = 'all'; }

/* initialize the storage: */
$result = [
	'type'	=> 'error'
];

/* find the page ID */
$id = $_GET['id'];

if ($id !== null) {
	
	/* get all metadata; */
	$meta = p_get_metadata($id);
	
	if ($meta['title'] && $meta['title'] !== null) {

		if ($style == 'preview') {
			$result['type'] = 'preview';
		} else {
			$result['type'] = 'standard';
			$result['pageid'] = $id;
			$result['lang'] = $conf['lang'];
		}

		$result['title'] = $meta['title'];

		/* The page URL(s) */
		$url = wl($id);
		
		if ($style == 'preview') {
			$result['content_urls'] = [
				'desktop' => [
					'page' => wl($id)
				]
			];
		} else {
			$url = $conf['baseurl'] . wl($id);
			$set = [
				'page' => $url,
				'revisions' => $url . '?do=revisions',
				'edit' => $url . '?do=edit'
			];
			$result['content_urls'] = [
				'desktop' => $set,
				'mobile' => $set
			];
		}

		/* extract the first paragraph:*/
		$parts = explode("\n", $meta['description']['abstract']);
		$result['extract'] = $parts[2];
		$result['extract_html'] = '<p>'.$parts[2].'</p>';
	
	} else {
		$result['extract'] = 'Error: page does not exist.';
		$result['extract_html'] = '<p><strong>' . $result['extract'] . '</strong></p>';
	}
	// $result['conf'] = $conf; /* WARNING: this may expose your configuration to the Internet. Use only for debugging! */
	// $result['meta'] = $meta; /* uncomment if you need additional meta information */
} 

/* output the result: */
echo json_encode($result);