summaryrefslogtreecommitdiffstats
path: root/application/core/MY_Input.php
blob: 4d43774c0bade99034d1aef679044b15997db42d (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
<?php
/*
 * Copyright 2017 Florian "Bluewind" Pritz <bluewind@server-speed.net>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

class MY_Input extends CI_Input {
	public function post($key = null, $xss_clean = false) {
		$ret = parent::post($key, $xss_clean);
		if (is_array($ret) || is_object($ret)) {
			$data = [
				"key" => $key,
				"ret" => $ret
			];
			if (preg_match("/^[a-zA-Z0-9_\.-]+$/", $key)) {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input in field $key", $data);
			} else {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
			}
		}
		return $ret;
	}

	public function post_array($key) {
		$ret = parent::post($key);
		if ($ret === false) {
			return false;
		} elseif (!is_array($ret)) {
			$data = [
				"key" => $key,
				"ret" => $ret
			];
			throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
		}
		return $ret;
	}
}