From 66ecc6db41cd4b7e06f0c953f3b5c88506765b06 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 8 Jun 2012 22:47:00 +0200 Subject: Section::test_name implemented. --- ratatoeskr/sys/models.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'ratatoeskr/sys') diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index 4c18ffd..2dd48e5 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -1471,6 +1471,21 @@ class Section extends BySQLRowEnabled $this->template = $sqlrow["template"]; } + /* + * Function: test_name + * Tests, if a name is a valid section name. + * + * Parameters: + * $name - The name to test. + * + * Returns: + * True, if the name is a valid section name, False otherwise. + */ + public static function test_name($name) + { + return preg_match("/^[a-zA-Z0-9\\-_]+$/", $name) != 0; + } + /* * Function: get_id */ @@ -1484,10 +1499,13 @@ class Section extends BySQLRowEnabled * $name - The name of the new section. * * Throws: - * + * , */ public static function create($name) { + if(!self::test_name($name)) + throw new InvalidDataError("invalid_section_name"); + try { $obj = self::by_name($name); @@ -1619,10 +1637,13 @@ class Section extends BySQLRowEnabled * Function: save * * Throws: - * + * , */ public function save() { + if(!self::test_name($name)) + throw new InvalidDataError("invalid_section_name"); + $result = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_sections` WHERE `name` = '%s' AND `id` != %d", $this->name, $this->id); $sqlrow = mysql_fetch_assoc($result); if($sqlrow["n"] > 0) @@ -1712,7 +1733,7 @@ class Tag extends BySQLRowEnabled * $name - The name * * Throws: - * + * , */ public static function create($name) { @@ -1832,7 +1853,7 @@ WHERE `b`.`tag` = '%d'" , $this->id); * Function: save * * Throws: - * + * , */ public function save() { -- cgit v1.2.3-70-g09d2