moved check for valid url-params to Util (will be reused in spells, ect)

This commit is contained in:
Sarjuuk
2013-04-20 15:48:35 +02:00
parent b6c0fa1b89
commit f8b8ee218c
2 changed files with 21 additions and 16 deletions

View File

@@ -1497,6 +1497,26 @@ class Util
return $return;
}
public static function isValidPage($struct, $keys)
{
switch (count($keys))
{
case 0:
return true;
case 1:
return !$keys[0] || isset($struct[$keys[0]]);
case 2:
if (!isset($struct[$keys[0]]))
return false;
return in_array($keys[1], $struct[$keys[0]]) || isset($struct[$keys[0]][$keys[1]]);
case 3:
return isset($struct[$keys[0]][$keys[1]]) && in_array($keys[2], $struct[$keys[0]][$keys[1]]);
}
return false;
}
// BaseType::_construct craaap!
// todo: unify names
public static function getNameFieldName($tpl)

View File

@@ -36,22 +36,7 @@ $validCats = array(
)
);
$valid = false;
switch (count($cats))
{
case 0:
$valid = true;
case 1:
$valid = !$cats[0] || isset($validCats[$cats[0]]);
break;
case 2:
$valid = $cats[0] == 1 ? isset($validCats[$cats[0]][$cats[1]]) : isset($validCats[$cats[0]]) && in_array($cats[1], $validCats[$cats[0]]);
break;
case 3:
$valid = $cats[0] == 1 ? isset($validCats[$cats[0]][$cats[1]]) && in_array($cats[2], $validCats[$cats[0]][$cats[1]]) : false;
break;
}
if (!$valid)
if (!Util::isValidPage($validCats, $cats))
$smarty->error();
if (!$smarty->loadCache($cacheKey, $pageData))