Skip to content

Commit

Permalink
loooooooads of artists refactoring and tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Sep 27, 2015
1 parent 5d188a9 commit 793bc36
Show file tree
Hide file tree
Showing 7 changed files with 914 additions and 905 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ data
images
thumbs
!lib/images
*.phar
*.sqlite


# Created by http://www.gitignore.io
Expand Down
4 changes: 2 additions & 2 deletions core/database.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public function get_all($query, $args=array()) {
*
* @param string $query
* @param array $args
* @return mixed|null
* @return array|null
*/
public function get_row($query, $args=array()) {
$_start = microtime(true);
Expand Down Expand Up @@ -702,7 +702,7 @@ public function get_one($query, $args=array()) {
* Get the ID of the last inserted row.
*
* @param string|null $seq
* @return string
* @return int
*/
public function get_last_insert_id($seq) {
if($this->engine->name == "pgsql") {
Expand Down
33 changes: 28 additions & 5 deletions core/util.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,18 @@ function validate_input($inputs) {

foreach($inputs as $key => $validations) {
$flags = explode(',', $validations);

if(in_array('optional', $flags)) {
if(!isset($_POST[$key])) {
if(!isset($_POST[$key]) || trim($_POST[$key]) == "") {
$outputs[$key] = null;
continue;
}
}

if(!isset($_POST[$key])) {
if(!isset($_POST[$key]) || trim($_POST[$key]) == "") {
throw new InvalidInput("Input '$key' not set");
}

$value = $_POST[$key];
$value = trim($_POST[$key]);

if(in_array('user_id', $flags)) {
$id = int_escape($value);
Expand Down Expand Up @@ -325,11 +326,33 @@ function validate_input($inputs) {
$outputs[$key] = $value;
}
else if(in_array('email', $flags)) {
$outputs[$key] = $value;
$outputs[$key] = trim($value);
}
else if(in_array('password', $flags)) {
$outputs[$key] = $value;
}
else if(in_array('int', $flags)) {
$value = trim($value);
if(empty($value) || !is_numeric($value)) {
throw new InvalidInput("Invalid int: ".html_escape($value));
}
$outputs[$key] = (int)$value;
}
else if(in_array('string', $flags)) {
if(in_array('trim', $flags)) {
$value = trim($value);
}
if(in_array('lower', $flags)) {
$value = strtolower($value);
}
if(in_array('not-empty', $flags)) {
throw new InvalidInput("$key must not be blank");
}
if(in_array('nullify', $flags)) {
if(empty($value)) $value = null;
}
$outputs[$key] = $value;
}
else {
throw new InvalidInput("Unknown validation '$validations'");
}
Expand Down
Loading

0 comments on commit 793bc36

Please sign in to comment.