function write_controller_rules($hash) { set_if_not_set($hash["except"], array()); set_if_not_set($hash["binet_prefix"], false); set_if_not_set($hash["action_on_collection"], array()); set_if_not_set($hash["action_on_member"], array()); set_if_not_set($hash["root"], "index"); $collection_actions = array_merge(array_diff(array("index", "new", "create"), $hash["except"]), $hash["action_on_collection"]); $member_actions = array_merge(array_diff(array("show", "edit", "update", "delete"), $hash["except"]), $hash["action_on_member"]); if (!in_array("index", $hash["except"])) { write_path_rule(path("", $hash["controller"], "", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($hash["root"], $hash["controller"], "", $hash["binet_prefix"] ? "binet/\$1/\$2" : "")); } foreach ($collection_actions as $action) { write_path_rule(path($action, $hash["controller"], "", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($action, $hash["controller"], "", $hash["binet_prefix"] ? "binet/\$1/\$2" : "")); } foreach ($member_actions as $action) { write_path_rule(path($action, $hash["controller"], "([0-9]+)", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($action, $hash["controller"], "\$" . ($hash["binet_prefix"] ? "3" : "1"), $hash["binet_prefix"] ? "binet/\$1/\$2" : "")); } }
function validate_input($required_parameters, $optional_parameters = array(), $method = "get") { switch ($method) { case "get": $input_parameters = $_GET; break; case "post": $input_parameters = $_POST; break; case "session": $input_parameters = $_SESSION; break; } $valid = true; foreach ($required_parameters as $parameter) { $valid = $valid && isset($input_parameters[$parameter]); } if ($valid) { foreach ($input_parameters as $parameter => $value) { if (in_array($parameter, array_merge($required_parameters, $optional_parameters))) { switch ($parameter) { case "action": $valid = $valid && preg_does_match("/^[a-z_]+|[0-9]+\$/", $value); break; case "controller": $valid = $valid && preg_does_match("/^[a-z_]+\$/", $value); break; case "prefix": $valid = $valid && in_array($value, array("binet")); break; case "tags": $tags = explode(" ", $value); foreach ($tags as $tag) { $valid = $valid && $tag == preg_does_match("/^([" . allowed_clean_string_characters() . "])+\$/", $tag); } break; case "binet": $valid = $valid && preg_does_match("/^([" . allowed_clean_string_characters() . "])+\$/", $value); break; case "term": $valid = $valid && is_numeric($value); break; case "budget": $valid = $valid && is_numeric($value); break; case "operation": $valid = $valid && is_numeric($value); break; case "tag": $valid = $valid && is_numeric($value); break; case "wave": $valid = $valid && is_numeric($value); break; case "member": $valid = $valid && is_numeric($value); break; case "student": $valid = $valid && is_numeric($value); break; } } } return $valid; } else { return false; } }