mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Structure/Types
* move distributed constant values to object * move reused iterators and checks to object
This commit is contained in:
@@ -50,7 +50,7 @@ class AjaxAccount extends AjaxHandler
|
||||
$type = $this->_post['type'];
|
||||
$ids = $this->_post['id'];
|
||||
|
||||
if (!isset(Util::$typeStrings[$type]) || empty($ids))
|
||||
if (!Type::exists($type) || empty($ids))
|
||||
{
|
||||
trigger_error('AjaxAccount::handleExclude - invalid type #'.$type.(empty($ids) ? ' or id-list empty' : ''), E_USER_ERROR);
|
||||
return;
|
||||
@@ -146,16 +146,10 @@ class AjaxAccount extends AjaxHandler
|
||||
|
||||
if ($type = $this->_post['add'])
|
||||
{
|
||||
if (empty(Util::$typeClasses[$type]))
|
||||
$tc = Type::newList($type, [['id', $typeId]]);
|
||||
if (!$tc || $tc->error)
|
||||
{
|
||||
trigger_error('AjaxAccount::handleFavorites - invalid type #'.$type, E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
$tc = new Util::$typeClasses[$type]([['id', $typeId]]);
|
||||
if ($tc->error)
|
||||
{
|
||||
trigger_error('AjaxAccount::handleFavorites - invalid typeId #'.$typeId.' for type '.$tc::$brickFile, E_USER_ERROR);
|
||||
trigger_error('AjaxAccount::handleFavorites - invalid typeId #'.$typeId.' for type #'.$type, E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ class AjaxAdmin extends AjaxHandler
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdApprove = ?d WHERE id = ?d', CC_FLAG_APPROVED, User::$id, $id);
|
||||
Util::gainSiteReputation($ssEntry['userIdOwner'], SITEREP_ACTION_UPLOAD, ['id' => $id, 'what' => 1, 'date' => $ssEntry['date']]);
|
||||
// flag DB entry as having screenshots
|
||||
if (Util::$typeClasses[$ssEntry['type']] && ($tbl = get_class_vars(Util::$typeClasses[$ssEntry['type']])['dataTable']))
|
||||
if ($tbl = Type::getClassAttrib($ssEntry['type'], 'dataTable'))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_SCREENSHOT, $ssEntry['typeId']);
|
||||
}
|
||||
else
|
||||
@@ -267,7 +267,7 @@ class AjaxAdmin extends AjaxHandler
|
||||
{
|
||||
$typeIds = explode(',', $typeIds);
|
||||
$toUnflag = DB::Aowow()->selectCol('SELECT typeId AS ARRAY_KEY, IF(BIT_OR(`status`) & ?d, 1, 0) AS hasMore FROM ?_screenshots WHERE `type` = ?d AND typeId IN (?a) GROUP BY typeId HAVING hasMore = 0', CC_FLAG_APPROVED, $type, $typeIds);
|
||||
if ($toUnflag && Util::$typeClasses[$type] && ($tbl = get_class_vars(Util::$typeClasses[$type])['dataTable']))
|
||||
if ($toUnflag && ($tbl = Type::getClassAttrib($type, 'dataTable')))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id IN (?a)', CUSTOM_HAS_SCREENSHOT, array_keys($toUnflag));
|
||||
}
|
||||
}
|
||||
@@ -286,8 +286,8 @@ class AjaxAdmin extends AjaxHandler
|
||||
[$type, $oldTypeId] = array_values(DB::Aowow()->selectRow('SELECT type, typeId FROM ?_screenshots WHERE id = ?d', $id));
|
||||
$typeId = (int)$this->_get['typeid'];
|
||||
|
||||
$tc = new Util::$typeClasses[$type]([['id', $typeId]]);
|
||||
if (!$tc->error)
|
||||
$tc = Type::newList($type, [['id', $typeId]]);
|
||||
if ($tc && !$tc->error)
|
||||
{
|
||||
// move screenshot
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET typeId = ?d WHERE id = ?d', $typeId, $id);
|
||||
@@ -301,7 +301,7 @@ class AjaxAdmin extends AjaxHandler
|
||||
DB::Aowow()->query('UPDATE '.$tc::$dataTable.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_SCREENSHOT, $oldTypeId);
|
||||
}
|
||||
else
|
||||
trigger_error('AjaxAdmin::ssRelocate - invalid typeId #'.$typeId.' for type '.$tc::$brickFile, E_USER_ERROR);
|
||||
trigger_error('AjaxAdmin::ssRelocate - invalid typeId #'.$typeId.' for type #'.$type, E_USER_ERROR);
|
||||
}
|
||||
|
||||
protected function confAdd() : string
|
||||
@@ -405,7 +405,7 @@ class AjaxAdmin extends AjaxHandler
|
||||
$area = $this->_get['area'];
|
||||
$floor = $this->_get['floor'];
|
||||
|
||||
if (!in_array($type, [TYPE_NPC, TYPE_OBJECT, TYPE_SOUND, TYPE_AREATRIGGER]))
|
||||
if (!in_array($type, [Type::NPC, Type::OBJECT, Type::SOUND, Type::AREATRIGGER]))
|
||||
return '-3';
|
||||
|
||||
DB::Aowow()->query('REPLACE INTO ?_spawns_override VALUES (?d, ?d, ?d, ?d, ?d)', $type, $guid, $area, $floor, AOWOW_REVISION);
|
||||
@@ -423,7 +423,7 @@ class AjaxAdmin extends AjaxHandler
|
||||
);
|
||||
|
||||
// if creature try for waypoints
|
||||
if ($type == TYPE_NPC)
|
||||
if ($type == Type::NPC)
|
||||
{
|
||||
$jobs = array(
|
||||
'SELECT -w.id AS `entry`, w.point AS `pointId`, w.position_y AS `posX`, w.position_x AS `posY` FROM creature_addon ca JOIN waypoint_data w ON w.id = ca.path_id WHERE ca.guid = ?d AND ca.path_id <> 0',
|
||||
@@ -467,6 +467,11 @@ class AjaxAdmin extends AjaxHandler
|
||||
return '-1';
|
||||
}
|
||||
|
||||
|
||||
/***************************/
|
||||
/* additional input filter */
|
||||
/***************************/
|
||||
|
||||
protected static function checkKey(string $val) : string
|
||||
{
|
||||
// expecting string
|
||||
|
||||
@@ -39,12 +39,12 @@ class AjaxArenaTeam extends AjaxHandler
|
||||
{
|
||||
if ($teams = DB::Aowow()->select('SELECT realm, realmGUID FROM ?_profiler_arena_team WHERE id IN (?a)', $this->_get['id']))
|
||||
foreach ($teams as $t)
|
||||
Profiler::scheduleResync(TYPE_ARENA_TEAM, $t['realm'], $t['realmGUID']);
|
||||
Profiler::scheduleResync(Type::ARENA_TEAM, $t['realm'], $t['realmGUID']);
|
||||
|
||||
if ($this->_get['profile'])
|
||||
if ($chars = DB::Aowow()->select('SELECT realm, realmGUID FROM ?_profiler_profiles p JOIN ?_profiler_arena_team_member atm ON atm.profileId = p.id WHERE atm.arenaTeamId IN (?a)', $this->_get['id']))
|
||||
foreach ($chars as $c)
|
||||
Profiler::scheduleResync(TYPE_PROFILE, $c['realm'], $c['realmGUID']);
|
||||
Profiler::scheduleResync(Type::PROFILE, $c['realm'], $c['realmGUID']);
|
||||
|
||||
return '1';
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class AjaxArenaTeam extends AjaxHandler
|
||||
*/
|
||||
protected function handleStatus() : string
|
||||
{
|
||||
$response = Profiler::resyncStatus(TYPE_ARENA_TEAM, $this->_get['id']);
|
||||
$response = Profiler::resyncStatus(Type::ARENA_TEAM, $this->_get['id']);
|
||||
return Util::toJSON($response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ class AjaxComment extends AjaxHandler
|
||||
// i .. have problems believing, that everything uses nifty ajax while adding comments requires a brutal header(Loacation: <wherever>), yet, thats how it is
|
||||
protected function handleCommentAdd() : string
|
||||
{
|
||||
if (!$this->_get['typeid'] || !$this->_get['type'] || !isset(Util::$typeClasses[$this->_get['type']]))
|
||||
if (!$this->_get['typeid'] || !$this->_get['type'] || !Type::exists($this->_get['type']))
|
||||
{
|
||||
trigger_error('AjaxComment::handleCommentAdd - malforemd request received', E_USER_ERROR);
|
||||
return ''; // whatever, we cant even send him back
|
||||
}
|
||||
|
||||
// this type cannot be commented on
|
||||
if (!(get_class_vars(Util::$typeClasses[$this->_get['type']])['contribute'] & CONTRIBUTE_CO))
|
||||
if (!Type::checkClassAttrib($this->_get['type'], 'contribute', CONTRIBUTE_CO))
|
||||
{
|
||||
trigger_error('AjaxComment::handleCommentAdd - tried to comment on unsupported type #'.$this->_get['type'], E_USER_ERROR);
|
||||
return '';
|
||||
@@ -106,7 +106,7 @@ class AjaxComment extends AjaxHandler
|
||||
DB::Aowow()->query('INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, 0, 1)', $postIdx);
|
||||
|
||||
// flag target with hasComment
|
||||
if ($tbl = get_class_vars(Util::$typeClasses[$this->_get['type']])['dataTable'])
|
||||
if ($tbl = Type::getClassAttrib($this->_get['type'], 'dataTable'))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $this->_get['typeid']);
|
||||
}
|
||||
else
|
||||
@@ -122,7 +122,7 @@ class AjaxComment extends AjaxHandler
|
||||
$_SESSION['error']['co'] = Lang::main('cannotComment');
|
||||
|
||||
$this->doRedirect = true;
|
||||
return '?'.Util::$typeStrings[$this->_get['type']].'='.$this->_get['typeid'].'#comments';
|
||||
return '?'.Type::getFileString($this->_get['type']).'='.$this->_get['typeid'].'#comments';
|
||||
}
|
||||
|
||||
protected function handleCommentEdit() : void
|
||||
@@ -186,7 +186,7 @@ class AjaxComment extends AjaxHandler
|
||||
$this->_post['id']
|
||||
);
|
||||
|
||||
if (!$coInfo['hasMore'] && Util::$typeClasses[$coInfo['type']] && ($tbl = get_class_vars(Util::$typeClasses[$coInfo['type']])['dataTable']))
|
||||
if (!$coInfo['hasMore'] && ($tbl = Type::getClassAttrib($coInfo['type'], 'dataTable')))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
|
||||
}
|
||||
else
|
||||
@@ -212,7 +212,7 @@ class AjaxComment extends AjaxHandler
|
||||
if ($ok)
|
||||
{
|
||||
$coInfo = DB::Aowow()->selectRow('SELECT type, typeId FROM ?_comments WHERE id = ?d', $this->_post['id']);
|
||||
if (Util::$typeClasses[$coInfo['type']] && ($tbl = get_class_vars(Util::$typeClasses[$coInfo['type']])['dataTable']))
|
||||
if ($tbl = Type::getClassAttrib($coInfo['type'], 'dataTable'))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -27,7 +27,7 @@ class AjaxGotocomment extends AjaxHandler
|
||||
return '.'; // go home
|
||||
|
||||
if ($_ = DB::Aowow()->selectRow('SELECT IFNULL(c2.id, c1.id) AS id, IFNULL(c2.type, c1.type) AS type, IFNULL(c2.typeId, c1.typeId) AS typeId FROM ?_comments c1 LEFT JOIN ?_comments c2 ON c1.replyTo = c2.id WHERE c1.id = ?d', $this->_get['id']))
|
||||
return '?'.Util::$typeStrings[$_['type']].'='.$_['typeId'].'#comments:id='.$_['id'].($_['id'] != $this->_get['id'] ? ':reply='.$this->_get['id'] : null);
|
||||
return '?'.Type::getFileString(intVal($_['type'])).'='.$_['typeId'].'#comments:id='.$_['id'].($_['id'] != $this->_get['id'] ? ':reply='.$this->_get['id'] : null);
|
||||
else
|
||||
trigger_error('AjaxGotocomment::handleGoToComment - could not find comment #'.$this->get['id'], E_USER_ERROR);
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ class AjaxGuild extends AjaxHandler
|
||||
{
|
||||
if ($guilds = DB::Aowow()->select('SELECT realm, realmGUID FROM ?_profiler_guild WHERE id IN (?a)', $this->_get['id']))
|
||||
foreach ($guilds as $g)
|
||||
Profiler::scheduleResync(TYPE_GUILD, $g['realm'], $g['realmGUID']);
|
||||
Profiler::scheduleResync(Type::GUILD, $g['realm'], $g['realmGUID']);
|
||||
|
||||
if ($this->_get['profile'])
|
||||
if ($chars = DB::Aowow()->select('SELECT realm, realmGUID FROM ?_profiler_profiles WHERE guild IN (?a)', $this->_get['id']))
|
||||
foreach ($chars as $c)
|
||||
Profiler::scheduleResync(TYPE_PROFILE, $c['realm'], $c['realmGUID']);
|
||||
Profiler::scheduleResync(Type::PROFILE, $c['realm'], $c['realmGUID']);
|
||||
|
||||
return '1';
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class AjaxGuild extends AjaxHandler
|
||||
*/
|
||||
protected function handleStatus() : string
|
||||
{
|
||||
$response = Profiler::resyncStatus(TYPE_GUILD, $this->_get['id']);
|
||||
$response = Profiler::resyncStatus(Type::GUILD, $this->_get['id']);
|
||||
return Util::toJSON($response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ class AjaxProfile extends AjaxHandler
|
||||
if ($chars = DB::Aowow()->select('SELECT realm, realmGUID FROM ?_profiler_profiles WHERE id IN (?a)', $this->_get['id']))
|
||||
{
|
||||
foreach ($chars as $c)
|
||||
Profiler::scheduleResync(TYPE_PROFILE, $c['realm'], $c['realmGUID']);
|
||||
Profiler::scheduleResync(Type::PROFILE, $c['realm'], $c['realmGUID']);
|
||||
}
|
||||
else
|
||||
trigger_error('AjaxProfile::handleResync - profiles '.implode(', ', $this->_get['id']).' not found in db', E_USER_ERROR);
|
||||
@@ -305,7 +305,7 @@ class AjaxProfile extends AjaxHandler
|
||||
return Util::toJSON([1, [PR_QUEUE_STATUS_ERROR, 0, 0, PR_QUEUE_ERROR_CHAR]]);
|
||||
}
|
||||
|
||||
$response = Profiler::resyncStatus(TYPE_PROFILE, $ids);
|
||||
$response = Profiler::resyncStatus(Type::PROFILE, $ids);
|
||||
return Util::toJSON($response);
|
||||
}
|
||||
|
||||
@@ -603,28 +603,28 @@ class AjaxProfile extends AjaxHandler
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case TYPE_FACTION: // factionId => amount
|
||||
case Type::FACTION: // factionId => amount
|
||||
$profile['reputation'] = array_combine(array_keys($data), array_column($data, 'cur'));
|
||||
break;
|
||||
case TYPE_TITLE:
|
||||
case Type::TITLE:
|
||||
foreach ($data as &$d)
|
||||
$d = 1;
|
||||
|
||||
$profile['titles'] = $data;
|
||||
break;
|
||||
case TYPE_QUEST:
|
||||
case Type::QUEST:
|
||||
foreach ($data as &$d)
|
||||
$d = 1;
|
||||
|
||||
$profile['quests'] = $data;
|
||||
break;
|
||||
case TYPE_SPELL:
|
||||
case Type::SPELL:
|
||||
foreach ($data as &$d)
|
||||
$d = 1;
|
||||
|
||||
$profile['spells'] = $data;
|
||||
break;
|
||||
case TYPE_ACHIEVEMENT:
|
||||
case Type::ACHIEVEMENT:
|
||||
$achievements = array_filter($data, function ($x) { return $x['max'] === null; });
|
||||
$statistics = array_filter($data, function ($x) { return $x['max'] !== null; });
|
||||
|
||||
@@ -642,7 +642,7 @@ class AjaxProfile extends AjaxHandler
|
||||
$profile['statistics'] = array_combine(array_keys($statistics), array_column($statistics, 'max'));
|
||||
$profile['activity'] = $activity;
|
||||
break;
|
||||
case TYPE_SKILL:
|
||||
case Type::SKILL:
|
||||
foreach ($data as &$d)
|
||||
$d = [$d['cur'], $d['max']];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user