Overview
Comment:Allow multiple params for http function
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 1.1.27
Files: files | file ages | folders
SHA3-256: be52882a463fe4794b6a9bc05879a4371e128a28df76bf8ab49def57577d56c5
User & Date: bohwaz on 2022-07-05 01:04:00
Other Links: manifest | tags
Context
2022-07-05
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
00:57
Add parameter to :http function to force download using a filename check-in: c152f1c84a user: bohwaz tags: trunk, stable, 1.1.27
Changes

Modified src/include/lib/Garradin/UserTemplate/Functions.php from [0ce6283faa] to [a1b689de1e].

74
75
76
77
78
79
80




81
82
83
84
85
86
87
	}

	static public function http(array $params, UserTemplate $tpl): void
	{
		if (headers_sent()) {
			return;
		}





		if (isset($params['code'])) {
			static $codes = [
				100 => 'Continue',
				101 => 'Switching Protocols',
				102 => 'Processing',
				200 => 'OK',







>
>
>
>







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	}

	static public function http(array $params, UserTemplate $tpl): void
	{
		if (headers_sent()) {
			return;
		}

		if (isset($params['redirect'])) {
			Utils::redirect($params['redirect']);
		}

		if (isset($params['code'])) {
			static $codes = [
				100 => 'Continue',
				101 => 'Switching Protocols',
				102 => 'Processing',
				200 => 'OK',
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161

			if (!isset($codes[$params['code']])) {
				throw new Brindille_Exception('Code HTTP inconnu');
			}

			header(sprintf('HTTP/1.1 %d %s', $params['code'], $codes[$params['code']]), true);
		}
		elseif (isset($params['redirect'])) {
			Utils::redirect($params['redirect']);
		}
		elseif (isset($params['type'])) {
			header('Content-Type: ' . $params['type'], true);
			$tpl->setContentType($params['type']);
		}

		elseif (isset($params['download'])) {
			header(sprintf('Content-Disposition: attachment; filename="%s"', Utils::safeFileName($params['download'])), true);
		}
		else {
			throw new Brindille_Exception('No valid parameter found for http function');
		}
	}
}







<
<
|
|



>
|


<
<
|
|
<
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159


160
161


			if (!isset($codes[$params['code']])) {
				throw new Brindille_Exception('Code HTTP inconnu');
			}

			header(sprintf('HTTP/1.1 %d %s', $params['code'], $codes[$params['code']]), true);
		}



		if (isset($params['type'])) {
			header('Content-Type: ' . $params['type'], true);
			$tpl->setContentType($params['type']);
		}

		if (isset($params['download'])) {
			header(sprintf('Content-Disposition: attachment; filename="%s"', Utils::safeFileName($params['download'])), true);
		}


	}
}