Overview
Comment:Fix Web API
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 1.1.27
Files: files | file ages | folders
SHA3-256: 7df7dadab8aab9d23eaf54e8be8989fcb7f57a1b97ce3153ab30052aadc60a8e
User & Date: bohwaz on 2022-07-05 11:37:02
Other Links: manifest | tags
Context
2022-07-05
20:59
Make sure we use the correct base URL as private files might not be available if WWW_URL is on a different domain check-in: d8269955a0 user: bohwaz tags: trunk, stable
11:37
Fix Web API check-in: 7df7dadab8 user: bohwaz tags: trunk, stable, 1.1.27
01:04
Allow multiple params for http function check-in: be52882a46 user: bohwaz tags: trunk, stable, 1.1.27
Changes

Modified src/include/lib/Garradin/API.php from [6a882227fb] to [208f05a8c5].

1
2
3
4
5

6
7
8
9
10
11
12
<?php

namespace Garradin;

use Garradin\Membres\Session;


use KD2\ErrorManager;

class API
{
	protected $body;
	protected $params;





>







1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

namespace Garradin;

use Garradin\Membres\Session;
use Garradin\Web\Web;

use KD2\ErrorManager;

class API
{
	protected $body;
	protected $params;
113
114
115
116
117
118
119

120


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
		}

		$fn = strtok($uri, '/');
		$param = strtok('');

		switch ($fn) {
			case 'list':

				return ['categories' => Web::listCategories($param), 'pages' => Web::listPages($param)];


			case 'attachment':
				$attachment = Web::getAttachmentFromURI($param);

				if (!$attachment) {
					throw new APIException('Page not found', 404);
				}

				$attachment->serve();
				return null;
			case 'html':
			case 'page':
				$page = Web::getByURI($param);

				if (!$page) {
					throw new APIException('Page not found', 404);
				}

				if ($fn == 'page') {
					$out = compact('page');

					if ($this->hasParam('html')) {
						$out['html'] = $page->render();
					}

					return $out;
				}







>
|
>
>


















|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		}

		$fn = strtok($uri, '/');
		$param = strtok('');

		switch ($fn) {
			case 'list':
				return [
					'categories' => array_map(fn($p) => $p->asArray(true), Web::listCategories($param)),
					'pages' => array_map(fn($p) => $p->asArray(true), Web::listPages($param)),
				];
			case 'attachment':
				$attachment = Web::getAttachmentFromURI($param);

				if (!$attachment) {
					throw new APIException('Page not found', 404);
				}

				$attachment->serve();
				return null;
			case 'html':
			case 'page':
				$page = Web::getByURI($param);

				if (!$page) {
					throw new APIException('Page not found', 404);
				}

				if ($fn == 'page') {
					$out = $page->asArray(true);

					if ($this->hasParam('html')) {
						$out['html'] = $page->render();
					}

					return $out;
				}
156
157
158
159
160
161
162




163
164
165
166
167
168
169
	public function errors(string $uri)
	{
		$fn = strtok($uri, '/');

		if (!ini_get('error_log')) {
			throw new APIException('The error log is disabled', 404);
		}





		if ($uri == 'report') {
			if ($this->method != 'POST') {
				throw new APIException('Wrong request method', 400);
			}

			$this->requireAccess(Session::ACCESS_ADMIN);







>
>
>
>







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	public function errors(string $uri)
	{
		$fn = strtok($uri, '/');

		if (!ini_get('error_log')) {
			throw new APIException('The error log is disabled', 404);
		}

		if (!ENABLE_TECH_DETAILS) {
			throw new APIException('Access to error log is disabled.', 403);
		}

		if ($uri == 'report') {
			if ($this->method != 'POST') {
				throw new APIException('Wrong request method', 400);
			}

			$this->requireAccess(Session::ACCESS_ADMIN);