mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
removing smarty - part XIV (only one more..)
- added some forgotten account-srings - fixed an error handling ItemFilter /w upgradeItems + markdown appearing in tooltips - relaxed session-regeneration (only regenerates on status changes (signin/-out)), fixes losing the session, when opening multiple tabs at once - striped smarty from profiler (only cleanups remaining) - moved profiler-ajax to AjaxHandler - created a (dummy, for now) ProfileClass to handle Chars and Profiles
This commit is contained in:
@@ -33,21 +33,6 @@ class AjaxHandler
|
||||
return $this->$f();
|
||||
}
|
||||
|
||||
private function isLoadOnDemand()
|
||||
{
|
||||
return substr(@$this->get['callback'], 0, 29) == '$WowheadProfiler.loadOnDemand';
|
||||
}
|
||||
|
||||
private function loadProfilerData($file, $catg = 'null')
|
||||
{
|
||||
$result = '';
|
||||
if ($this->isLoadOnDemand())
|
||||
if (Util::loadStaticFile('p-'.$file, $result, true))
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('".$file."', ".$catg.");\n";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* responses
|
||||
<string>
|
||||
*/
|
||||
@@ -74,13 +59,13 @@ class AjaxHandler
|
||||
loading the data triggers the generation of the catg-tree
|
||||
*/
|
||||
case 'factions':
|
||||
$result .= $this->loadProfilerData($set);
|
||||
$result .= $this->data_loadProfilerData($set);
|
||||
break;
|
||||
case 'companions':
|
||||
$result .= $this->loadProfilerData($set, '778');
|
||||
$result .= $this->data_loadProfilerData($set, '778');
|
||||
break;
|
||||
case 'mounts':
|
||||
$result .= $this->loadProfilerData($set, '777');
|
||||
$result .= $this->data_loadProfilerData($set, '777');
|
||||
break;
|
||||
case 'quests':
|
||||
// &partial: im not doing this right
|
||||
@@ -88,13 +73,13 @@ class AjaxHandler
|
||||
// for now omiting the detail clicks with empty results and just set catg update
|
||||
$catg = isset($this->get['catg']) ? $this->get['catg'] : 'null';
|
||||
if ($catg == 'null')
|
||||
$result .= $this->loadProfilerData($set);
|
||||
else if ($this->isLoadOnDemand())
|
||||
$result .= $this->data_loadProfilerData($set);
|
||||
else if ($this->data_isLoadOnDemand())
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('quests', ".$catg.");\n";
|
||||
|
||||
break;
|
||||
case 'recipes':
|
||||
if (!$this->isLoadOnDemand() || empty($this->get['skill']))
|
||||
if (!$this->data_isLoadOnDemand() || empty($this->get['skill']))
|
||||
break;
|
||||
|
||||
$skills = array_intersect(explode(',', $this->get['skill']), [171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356]);
|
||||
@@ -143,6 +128,46 @@ class AjaxHandler
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function handleProfile()
|
||||
{
|
||||
if (!$this->params)
|
||||
return null;
|
||||
|
||||
switch ($this->params[0])
|
||||
{
|
||||
case 'link':
|
||||
case 'unlink':
|
||||
$this->profile_handleLink(); // always returns null
|
||||
return '';
|
||||
case 'pin':
|
||||
case 'unpin':
|
||||
$this->profile_handlePin(); // always returns null
|
||||
return '';
|
||||
case 'public':
|
||||
case 'private':
|
||||
$this->profile_handlePrivacy(); // always returns null
|
||||
return '';
|
||||
case 'avatar':
|
||||
if ($this->profile_handleAvatar()) // sets an image header
|
||||
die(); // so it has to die here or another header will be set
|
||||
case 'resync':
|
||||
case 'status':
|
||||
return $this->profile_handleResync($this->params[0] == 'resync');
|
||||
case 'save':
|
||||
return $this->profile_handleSave();
|
||||
case 'delete':
|
||||
return $this->profile_handleDelete();
|
||||
case 'purge':
|
||||
return $this->profile_handlePurge();
|
||||
case 'summary': // page is generated by jScript
|
||||
return ''; // just be empty
|
||||
case 'load':
|
||||
return $this->profile_handleLoad();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* responses
|
||||
0: success
|
||||
$: silent error
|
||||
@@ -297,6 +322,369 @@ class AjaxHandler
|
||||
return null;
|
||||
}
|
||||
|
||||
/**********/
|
||||
/* Helper */
|
||||
/**********/
|
||||
|
||||
private function data_isLoadOnDemand()
|
||||
{
|
||||
return substr(@$this->get['callback'], 0, 29) == '$WowheadProfiler.loadOnDemand';
|
||||
}
|
||||
|
||||
private function data_loadProfilerData($file, $catg = 'null')
|
||||
{
|
||||
$result = '';
|
||||
if ($this->data_isLoadOnDemand())
|
||||
if (Util::loadStaticFile('p-'.$file, $result, true))
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('".$file."', ".$catg.");\n";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function profile_handleAvatar() // image
|
||||
{
|
||||
// something happened in the last years: those textures do not include tiny icons
|
||||
$s = [/* 'tiny' => 15, */'small' => 18, 'medium' => 36, 'large' => 56];
|
||||
$size = empty($this->get['size']) ? 'medium' : $this->get['size'];
|
||||
|
||||
if (empty($this->get['id']) || !preg_match('/^([0-9]+)\.(jpg|gif)$/', $this->get['id'], $matches) || !in_array($size, array_keys($s)))
|
||||
return false;
|
||||
|
||||
$id = $matches[1];
|
||||
|
||||
if (file_exists(CWD.'/uploads/avatars/'.$id.'.jpg'))
|
||||
{
|
||||
$offsetX = $offsetY = 0;
|
||||
|
||||
switch ($size)
|
||||
{
|
||||
case 'tiny':
|
||||
$offsetX += $s['small'];
|
||||
case 'small':
|
||||
$offsetY += $s['medium'];
|
||||
case 'medium':
|
||||
$offsetX += $s['large'];
|
||||
}
|
||||
|
||||
$src = imageCreateFromJpeg('uploads/avatars/'.$id.'.jpg');
|
||||
$dest = imageCreateTruecolor($s[$size], $s[$size]);
|
||||
|
||||
imagecopymerge($dest, $src, 0, 0, $offsetX, $offsetY, $s[$size], $s[$size], 100);
|
||||
|
||||
header('Content-Type: image/'.$matches[2]);
|
||||
|
||||
if ($matches[2] == 'gif')
|
||||
imageGif($dest);
|
||||
else
|
||||
imageJpeg($dest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function profile_handlePin($id, $mode) // (un)favorite
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
private function profile_handleLink($id, $mode) // links char with account
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
private function profile_handlePrivacy($id, $mode) // public visibility
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
private function profile_handleResync($initNew = true) // resync init and status requests
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return
|
||||
null [onOK]
|
||||
int or str [onError]
|
||||
*/
|
||||
|
||||
if ($initNew)
|
||||
return '1';
|
||||
else
|
||||
{
|
||||
/*
|
||||
not all fields are required, if zero they are omitted
|
||||
statusCode:
|
||||
0: end the request
|
||||
1: waiting
|
||||
2: working...
|
||||
3: ready; click to view
|
||||
4: error / retry
|
||||
errorCode:
|
||||
0: unk error
|
||||
1: char does not exist
|
||||
2: armory gone
|
||||
|
||||
[
|
||||
processId,
|
||||
[StatusCode, timeToRefresh, iCount, errorCode, iNResyncs],
|
||||
[<anotherStatus>]...
|
||||
]
|
||||
*/
|
||||
return '[0, [4, 10000, 1, 2]]';
|
||||
}
|
||||
}
|
||||
|
||||
private function profile_handleSave() // unKill a profile
|
||||
{
|
||||
/* params GET
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
params POST
|
||||
name, level, class, race, gender, nomodel, talenttree1, talenttree2, talenttree3, activespec, talentbuild1, glyphs1, talentbuild2, glyphs2, gearscore, icon, public [always]
|
||||
description, source, copy, inv { inventory: array containing itemLinks } [optional]
|
||||
}
|
||||
return
|
||||
int > 0 [profileId, if we came from an armoryProfile create a new one]
|
||||
int < 0 [onError]
|
||||
str [onError]
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
private function profile_handleDelete() // kill a profile
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
return
|
||||
null
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
private function profile_handlePurge() // removes certain saved information but not the entire character
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
data: <mode> [string, tabName?]
|
||||
return
|
||||
null
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
private function profile_handleLoad()
|
||||
{
|
||||
/* params
|
||||
id: profileId
|
||||
items: string [itemIds.join(':')]
|
||||
unnamed: unixtime [only to force the browser to reload instead of cache]
|
||||
return
|
||||
lots...
|
||||
*/
|
||||
|
||||
// titles, achievements, characterData, talents (, pets)
|
||||
// and some onLoad-hook to .. load it registerProfile($data)
|
||||
// everything else goes through data.php .. strangely enough
|
||||
|
||||
$char = new ProfileList(array(['id', $this->get['id']])); // or string or whatever
|
||||
|
||||
// modify model from auras with profile_getModelForForm
|
||||
|
||||
$buff = '';
|
||||
|
||||
if ($it = array_column($char->getField('inventory'), 0))
|
||||
{
|
||||
$itemz = new ItemList(array(['id', $it, CFG_SQL_LIMIT_NONE]));
|
||||
$data = $itemz->getListviewData(ITEMINFO_JSON | ITEMINFO_SUBITEMS);
|
||||
|
||||
// get and apply inventory
|
||||
foreach ($itemz->iterate() as $iId => $__)
|
||||
$buff .= 'g_items.add('.$iId.', {name_'.User::$localeString.":'".Util::jsEscape($itemz->getField('name', true))."', quality:".$itemz->getField('quality').", icon:'".$itemz->getField('iconString')."', jsonequip:".json_encode($data[$iId], JSON_NUMERIC_CHECK)."});\n";
|
||||
|
||||
$buff .= "\n";
|
||||
}
|
||||
|
||||
if ($au = $char->getField('auras'))
|
||||
{
|
||||
$auraz = new SpellList(array(['id', $char->getField('auras')], CFG_SQL_LIMIT_NONE));
|
||||
$dataz = $auraz->getListviewData();
|
||||
$modz = $auraz->getProfilerMods();
|
||||
|
||||
// get and apply aura-mods
|
||||
foreach ($dataz as $id => $data)
|
||||
{
|
||||
$mods = [];
|
||||
if (!empty($modz[$id]))
|
||||
{
|
||||
foreach ($modz[$id] as $k => $v)
|
||||
{
|
||||
if (is_array($v))
|
||||
$mods[] = $v;
|
||||
else if ($str = @Util::$itemMods[$k])
|
||||
$mods[$str] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$buff .= 'g_spells.add('.$id.", {id:".$id.", name:'".Util::jsEscape(substr($data['name'], 1))."', icon:'".$data['icon']."', modifier:".json_encode($mods, JSON_NUMERIC_CHECK)."});\n";
|
||||
}
|
||||
$buff .= "\n";
|
||||
}
|
||||
|
||||
/* depending on progress-achievements
|
||||
// required by progress in JScript move to handleLoad()?
|
||||
Util::$pageTemplate->extendGlobalIds(TYPE_NPC, [29120, 31134, 29306, 29311, 23980, 27656, 26861, 26723, 28923, 15991]);
|
||||
*/
|
||||
|
||||
// load available titles
|
||||
Util::loadStaticFile('p-titles-'.$char->getField('gender'), $buff, true);
|
||||
|
||||
// load available achievements
|
||||
if (!Util::loadStaticFile('p-achievements', $buff, true))
|
||||
{
|
||||
$buff .= "\n\ng_achievement_catorder = [];";
|
||||
$buff .= "\n\ng_achievement_points = [0];";
|
||||
}
|
||||
|
||||
// excludes; structure UNK type => [maskBit => [typeIds]] ?
|
||||
/*
|
||||
g_user.excludes = [type:[typeIds]]
|
||||
g_user.includes = [type:[typeIds]]
|
||||
g_user.excludegroups = groupMask // requires g_user.settings != null
|
||||
|
||||
maskBit are matched against fieldId from excludeGroups
|
||||
id: 1, label: LANG.dialog_notavail
|
||||
id: 2, label: LANG.dialog_tcg
|
||||
id: 4, label: LANG.dialog_collector
|
||||
id: 8, label: LANG.dialog_promo
|
||||
id: 16, label: LANG.dialog_nonus
|
||||
id: 96, label: LANG.dialog_faction
|
||||
id: 896, label: LANG.dialog_profession
|
||||
id: 1024, label: LANG.dialog_noexalted
|
||||
*/
|
||||
// $buff .= "\n\ng_excludes = {};";
|
||||
|
||||
// add profile to buffer
|
||||
$buff .= "\n\n\$WowheadProfiler.registerProfile(".json_encode($char->getEntry(2)).");"; // can't use JSON_NUMERIC_CHECK or the talent-string becomes a float
|
||||
|
||||
return $buff."\n";
|
||||
}
|
||||
|
||||
private function profile_getModelForForm($form, $char)
|
||||
{
|
||||
switch ($form)
|
||||
{
|
||||
case 1: // FORM_CAT
|
||||
if ($char['race'] == 4) // RACE_NIGHTELF
|
||||
{
|
||||
if ($char['hairColor'] >= 0 && $char['hairColor'] <= 2)
|
||||
return 29407;
|
||||
else if ($char['hairColor'] == 3)
|
||||
return 29406;
|
||||
else if ($char['hairColor'] == 4)
|
||||
return 29408;
|
||||
else if ($char['hairColor'] == 7 || $char['hairColor'] == 8)
|
||||
return 29405;
|
||||
else
|
||||
return 892;
|
||||
}
|
||||
|
||||
if ($char['race'] == 6) // RACE_TAUREN
|
||||
{
|
||||
if ($char['gender'] == GENDER_MALE)
|
||||
{
|
||||
if ($char['skinColor'] >= 0 && $char['skinColor'] <= 5)
|
||||
return 29412;
|
||||
else if ($char['skinColor'] >= 0 && $char['skinColor'] <= 8)
|
||||
return 29411;
|
||||
else if ($char['skinColor'] >= 0 && $char['skinColor'] <= 11)
|
||||
return 29410;
|
||||
else if (in_array($char['skinColor'], [12, 13, 14, 18]))
|
||||
return 29410;
|
||||
else
|
||||
return 8571;
|
||||
}
|
||||
else // if gender == GENDER_FEMALE
|
||||
{
|
||||
if ($char['skinColor'] >= 0 && $char['skinColor'] <= 3)
|
||||
return 29412;
|
||||
else if ($char['skinColor'] >= 0 && $char['skinColor'] <= 5)
|
||||
return 29411;
|
||||
else if ($char['skinColor'] >= 0 && $char['skinColor'] <= 7)
|
||||
return 29410;
|
||||
else if ($char['skinColor'] == 10)
|
||||
return 29410;
|
||||
else
|
||||
return 8571;
|
||||
}
|
||||
}
|
||||
case 5: // FORM_DIREBEAR
|
||||
case 8: // FORM_BEAR
|
||||
if ($char['race'] == 4) // RACE_NIGHTELF
|
||||
{
|
||||
if ($char['hairColor'] >= 0 && $char['hairColor'] <= 2)
|
||||
return 29413;
|
||||
else if ($char['hairColor'] == 3)
|
||||
return 29417;
|
||||
else if ($char['hairColor'] == 4)
|
||||
return 29416;
|
||||
else if ($char['hairColor'] == 6)
|
||||
return 29414;
|
||||
else
|
||||
return 2281;
|
||||
}
|
||||
|
||||
if ($char['race'] == 6) // RACE_TAUREN
|
||||
{
|
||||
if ($char['gender'] == GENDER_MALE)
|
||||
{
|
||||
if ($char['skinColor'] >= 0 && $char['skinColor'] <= 2)
|
||||
return 29415;
|
||||
else if (in_array($char['skinColor'], [3, 4, 5, 12, 13, 14]))
|
||||
return 29419;
|
||||
else if (in_array($char['skinColor'], [9, 10, 11, 15, 16, 17]))
|
||||
return 29420;
|
||||
else if ($char['skinColor'] == 18)
|
||||
return 29421;
|
||||
else
|
||||
return 2289;
|
||||
}
|
||||
else // if gender == GENDER_FEMALE
|
||||
{
|
||||
if ($char['skinColor'] == 0 && $char['skinColor'] == 1)
|
||||
return 29418;
|
||||
else if ($char['skinColor'] == 2 && $char['skinColor'] == 3)
|
||||
return 29419;
|
||||
else if ($char['skinColor'] >= 6 && $char['skinColor'] <= 9)
|
||||
return 29420;
|
||||
else if ($char['skinColor'] == 10)
|
||||
return 29421;
|
||||
else
|
||||
return 2289;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hey, still here? you're not a Tauren/Nelf as bear or cat, are you?
|
||||
return DB::Aowow()->selectCell('SELECT IF(?d == 1, IFNULL(displayIdA, displayIdH), IFNULL(displayIdH, displayIdA)) FROM ?_shapeshiftForm WHERE id = ?d', Util::sideByRaceMask(1 << ($char['race'] - 1)), $form);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user