moved error code for wrong Ids and pageNames to Tempate-Class

throw an error if an invalid category-parameter is passed
This commit is contained in:
Sarjuuk
2013-03-13 21:33:22 +01:00
parent 06ed69c6a1
commit 5e8d1a2a39
9 changed files with 145 additions and 142 deletions

View File

@@ -73,7 +73,7 @@ class WorldEventList extends BaseType
{
// template
$this->curTpl['name_loc0'] = $this->curTpl['description'];
$this->curTpl['iconString'] = 'INV_Misc_QuestionMark';
$this->curTpl['iconString'] = 'trade_engineering';
$replace[$this->id] = $this->curTpl;
// names

View File

@@ -73,18 +73,45 @@ class Smarty_AoWoW extends Smarty
public function display($tpl)
{
// since it's the same for every page, except index..
if ($this->_tpl_vars['query'][0])
{
if (!$this->_tpl_vars['query'][0])
return;
// sanitize
if (preg_match('/[^a-z]/i', $this->_tpl_vars['query'][0]))
return;
$ann = DB::Aowow()->Select('SELECT * FROM ?_announcements WHERE flags & 0x10 AND (page = ?s OR page = "*")', $this->_tpl_vars['query'][0]);
foreach ($ann as $k => $v)
$ann[$k]['text'] = Util::localizedString($v, 'text');
$this->_tpl_vars['announcements'] = $ann;
}
parent::display($tpl);
}
public function notFound($subject)
{
$this->updatePageVars(array(
'subject' => ucfirst($subject),
'id' => intVal($this->_tpl_vars['query'][1]),
'notFound' => sprintf(Lang::$main['pageNotFound'], $subject),
));
$this->assign('lang', Lang::$main);
$this->display('404.tpl');
exit();
}
public function error()
{
$this->assign('lang', array_merge(Lang::$main, Lang::$error));
$this->assign('mysql', DB::Aowow()->getStatistics());
$this->display('error.tpl');
exit();
}
// creates the actual cache file
public function saveCache($key, $data)
{

View File

@@ -27,7 +27,7 @@ enum(array( // UserPropsLimits
*/
if (!in_array($pageParam, array('dashboard', '', 'signin', 'signup', 'signout', 'signin_do', 'signup_do', 'forgotpassword', 'forgotusername')))
require 'error.php';
$smarty->error();
function signin()
{

View File

@@ -55,16 +55,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
{
if ($acv->error)
{
$smarty->updatePageVars(array(
'subject' => ucfirst(Lang::$achievement['achievement']),
'id' => $id,
'notFound' => sprintf(Lang::$main['pageNotFound'], Lang::$achievement['achievement']),
));
$smarty->assign('lang', Lang::$main);
$smarty->display('404.tpl');
exit();
}
$smarty->notFound(Lang::$achievement['achievement']);
$pageData['path'] = [];
$pageData['title'] = [ucfirst(Lang::$achievement['achievement'])];

View File

@@ -1,12 +0,0 @@
<?php
if (!defined('AOWOW_REVISION'))
die('illegal access');
$smarty->assign('lang', array_merge(Lang::$main, Lang::$error));
$smarty->assign('mysql', DB::Aowow()->getStatistics());
$smarty->display('error.tpl');
exit();
?>

View File

@@ -3,18 +3,31 @@
if (!defined('AOWOW_REVISION'))
die('illegal access');
@list($cat) = Util::extractURLParams($pageParam);
$cat = Util::extractURLParams($pageParam)[0];
$condition = [];
$path = [0, 11];
$cacheKeyPage = implode('_', [CACHETYPE_PAGE, TYPE_WORLDEVENT, -1, $cat, User::$localeId]);
$validCats = [0, 1, 2, 3];
$title = [Lang::$game['events']];
$cacheKey = implode('_', [CACHETYPE_PAGE, TYPE_WORLDEVENT, -1, $cat, User::$localeId]);
if (!in_array($cat, $validCats))
$smarty->error();
if ($cat)
$path[] = $cat;
if (!$smarty->loadCache($cacheKeyPage, $pageData))
if (isset($cat))
array_unshift($title, Lang::$event['category'][$cat]);
if (!$smarty->loadCache($cacheKey, $pageData))
{
if ($cat !== null)
{
switch ($cat)
{
case 0:
$condition[] = ['e.holidayId', 0];
break;
case 1:
$condition[] = ['h.scheduleType', -1];
break;
@@ -25,6 +38,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
$condition[] = ['h.scheduleType', 2];
break;
}
}
$events = new WorldEventList($condition);
@@ -37,7 +51,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
$events->addGlobalsToJScript($pageData);
$smarty->saveCache($cacheKeyPage, $pageData);
$smarty->saveCache($cacheKey, $pageData);
}
// recalculate dates with now(); can't be cached, obviously
@@ -48,13 +62,13 @@ foreach ($pageData['page'] as &$data)
$data['endDate'] = date(Util::$dateFormatLong, $updated['end']);
}
$page = array(
'tab' => 0, // for g_initHeader($tab)
'title' => ($cat ? Lang::$event['category'][$cat].' - ' : null) . Lang::$game['events'],
'path' => json_encode($path, JSON_NUMERIC_CHECK),
'title' => implode(" - ", $title),
'path' => "[".implode(", ", $path)."]"
);
$smarty->updatePageVars($page);
$smarty->assign('lang', Lang::$main);
$smarty->assign('mysql', DB::Aowow()->getStatistics());

View File

@@ -594,19 +594,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
$smarty->saveCache($cacheKeyPage, $pageData);
}
else
{
$smarty->updatePageVars(array(
'subject' => ucfirst(Lang::$game['spell']),
'id' => $id,
'notFound' => sprintf(Lang::$main['pageNotFound'], Lang::$game['spell']),
));
$smarty->assign('lang', Lang::$main);
$smarty->display('404.tpl');
exit();
}
$smarty->notFound(Lang::$game['spell']);
}
$smarty->updatePageVars(array(

View File

@@ -14,18 +14,8 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
{
$title = new TitleList(array(['id', $id]));
if ($title->error)
{
$smarty->updatePageVars(array(
'subject' => ucfirst(Lang::$game['title']),
'id' => $id,
'notFound' => sprintf(Lang::$main['pageNotFound'], Lang::$game['title']),
));
$smarty->assign('lang', Lang::$main);
$smarty->display('404.tpl');
exit();
}
else
{
$smarty->notFound(Lang::$game['title']);
$title->addGlobalsToJscript($pageData);
$infobox = [];
@@ -43,6 +33,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
if ($e = $title->getField('eventId'))
$infobox[] = Lang::$game['eventShort'].$colon.'[url=?event='.$e.']'.WorldEvent::getName($e).'[/url]';
$title->reset();
$pageData = array(
'page' => array(
'name' => $title->getHtmlizedName(),
@@ -82,16 +73,15 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
'sort' => "$['reqlevel', 'name']"
);
break;
case 13:
// case 13:
// not displayed
}
}
$pageData['title'] = ucFirst(trim(str_replace('%s', '', str_replace(',', '', $title->name[0]))));
$pageData['title'] = ucFirst(trim(str_replace('%s', '', str_replace(',', '', $title->names[$title->id][0]))));
$pageData['path'] = '[0, 10, '.$title->getField('category').']';
$smarty->saveCache($cacheKeyPage, $pageData);
}
}
$smarty->updatePageVars(array(
'title' => $pageData['title']." - ".ucfirst(Lang::$game['title']),

View File

@@ -6,8 +6,12 @@ if (!defined('AOWOW_REVISION'))
$cat = Util::extractURLParams($pageParam)[0];
$path = [0, 10];
$cacheKey = implode('_', [CACHETYPE_PAGE, TYPE_TITLE, -1, isset($cat) ? $cat : -1, User::$localeId]);
$validCats = [0, 1, 2, 3, 4, 5, 6];
$title = [ucFirst(Lang::$game['titles'])];
$cacheKey = implode('_', [CACHETYPE_PAGE, TYPE_TITLE, -1, isset($cat) ? $cat : -1, User::$localeId]);
if (!in_array($cat, $validCats))
$smarty->error();
$path[] = $cat; // should be only one parameter anyway
@@ -36,10 +40,11 @@ if (!$smarty->loadCache($cacheKey, $pageData))
$smarty->saveCache($cacheKey, $pageData);
}
$page = array(
'tab' => 0, // for g_initHeader($tab)
'title' => implode(" - ", $title),
'path' => "[".implode(", ", $path)."]",
'path' => "[".implode(", ", $path)."]"
);
$smarty->updatePageVars($page);