From 6cabfd3864c03b731b7d7bbe4acb2d65d6b47319 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 23 May 2020 13:01:10 +0200 Subject: [PATCH] Misc/Cleanup * moving commonly used strings to defines * moving commonly reused/similar page generation functions to the parent * generally using consistent return types, more type hints and less strings * prevent browser context menu when right clicking on UI elements with their own context menus * fixed menu path for icons --- includes/ajaxHandler.class.php | 2 +- includes/ajaxHandler/comment.class.php | 6 +- includes/ajaxHandler/profile.class.php | 2 +- includes/basetype.class.php | 7 +- includes/defines.php | 10 +- includes/kernel.php | 4 +- includes/types/areatrigger.class.php | 7 +- includes/types/item.class.php | 5 +- index.php | 2 +- localization/lang.class.php | 6 +- pages/achievement.php | 44 +---- pages/areatrigger.php | 7 +- pages/arenateam.php | 4 +- pages/currency.php | 44 +---- pages/emote.php | 2 +- pages/enchantment.php | 2 +- pages/enchantments.php | 6 +- pages/event.php | 63 ++---- pages/faction.php | 2 +- pages/genericPage.class.php | 218 +++++++++++++-------- pages/guild.php | 4 +- pages/icon.php | 2 +- pages/item.php | 85 +++----- pages/items.php | 2 +- pages/itemset.php | 49 ++--- pages/mail.php | 5 +- pages/npc.php | 50 +---- pages/object.php | 51 ++--- pages/profile.php | 73 +++---- pages/quest.php | 59 ++---- pages/search.php | 91 ++++----- pages/spell.php | 76 +++---- pages/spells.php | 2 +- pages/talent.php | 2 +- pages/utility.php | 6 +- pages/zone.php | 6 +- static/js/global.js | 2 + template/pages/detail-page-generic.tpl.php | 14 ++ 38 files changed, 411 insertions(+), 611 deletions(-) diff --git a/includes/ajaxHandler.class.php b/includes/ajaxHandler.class.php index 1e5bd4b7f..37c8426d7 100644 --- a/includes/ajaxHandler.class.php +++ b/includes/ajaxHandler.class.php @@ -10,7 +10,7 @@ class AjaxHandler protected $params = []; protected $handler; - protected $contentType = 'application/x-javascript; charset=utf-8'; + protected $contentType = MIME_TYPE_JSON; protected $_post = []; protected $_get = []; diff --git a/includes/ajaxHandler/comment.class.php b/includes/ajaxHandler/comment.class.php index 6b5e153e5..4c73cd650 100644 --- a/includes/ajaxHandler/comment.class.php +++ b/includes/ajaxHandler/comment.class.php @@ -282,7 +282,7 @@ protected function handleCommentSticky() : void protected function handleCommentOutOfDate() : string { - $this->contentType = 'text/plain'; + $this->contentType = MIME_TYPE_TEXT; if (!$this->_post['id']) { @@ -320,7 +320,7 @@ protected function handleCommentShowReplies() : string protected function handleReplyAdd() : string { - $this->contentType = 'text/plain'; + $this->contentType = MIME_TYPE_TEXT; if (!User::canComment()) return Lang::main('cannotComment'); @@ -343,7 +343,7 @@ protected function handleReplyAdd() : string protected function handleReplyEdit() : string { - $this->contentType = 'text/plain'; + $this->contentType = MIME_TYPE_TEXT; if (!User::canComment()) return Lang::main('cannotComment'); diff --git a/includes/ajaxHandler/profile.class.php b/includes/ajaxHandler/profile.class.php index 8369b7636..ba7eb65c9 100644 --- a/includes/ajaxHandler/profile.class.php +++ b/includes/ajaxHandler/profile.class.php @@ -217,7 +217,7 @@ protected function handleAvatar() : void // image return; } - $this->contentType = 'image/'.$matches[2]; + $this->contentType = $matches[2] == 'png' ? MIME_TYPE_PNG : MIME_TYPE_JPEG; $id = $matches[1]; $dest = imageCreateTruecolor($sizes[$s], $sizes[$s]); diff --git a/includes/basetype.class.php b/includes/basetype.class.php index 62c1729da..becdc4610 100644 --- a/includes/basetype.class.php +++ b/includes/basetype.class.php @@ -557,6 +557,8 @@ trait spawnHelper private function createShortSpawns() // [zoneId, floor, [[x1, y1], [x2, y2], ..]] as tooltip2 if enabled by or anchor #map (one area, one floor, one creature, no survivors) { + $this->spawnResult[SPAWNINFO_SHORT] = new StdClass; + // first get zone/floor with the most spawns if ($res = DB::Aowow()->selectRow('SELECT areaId, floor FROM ?_spawns WHERE type = ?d && typeId = ?d GROUP BY areaId, floor ORDER BY count(1) DESC LIMIT 1', self::$type, $this->id)) { @@ -566,7 +568,8 @@ private function createShortSpawns() // [zoneId, floor, [[x1, foreach ($points as $p) $spawns[] = [$p['posX'], $p['posY']]; - $this->spawnResult[SPAWNINFO_SHORT] = [$res['areaId'], $res['floor'], $spawns]; + $this->spawnResult[SPAWNINFO_SHORT]->zone = $res['areaId']; + $this->spawnResult[SPAWNINFO_SHORT]->coords = [$res['floor'] => $spawns]; } } @@ -736,7 +739,7 @@ public function getSpawns($mode) switch ($mode) { case SPAWNINFO_SHORT: - if (empty($this->spawnResult[SPAWNINFO_SHORT])) + if ($this->spawnResult[SPAWNINFO_SHORT] === null) $this->createShortSpawns(); return $this->spawnResult[SPAWNINFO_SHORT]; diff --git a/includes/defines.php b/includes/defines.php index dfd6c3645..128b46d8e 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -7,7 +7,15 @@ * Page */ -define('E_AOWOW', E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)); +define('E_AOWOW', E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)); +define('JSON_AOWOW_POWER', JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + +define('MIME_TYPE_TEXT', 'Content-Type: text/plain; charset=utf-8'); +define('MIME_TYPE_XML', 'Content-Type: text/xml; charset=utf-8'); +define('MIME_TYPE_JSON', 'Content-Type: application/x-javascript; charset=utf-8'); +define('MIME_TYPE_RSS', 'Content-Type: application/rss+xml; charset=utf-8'); +define('MIME_TYPE_JPEG', 'Content-Type: image/jpeg'); +define('MIME_TYPE_PNG', 'Content-Type: image/png'); // TypeIds define('TYPE_NPC', 1); diff --git a/includes/kernel.php b/includes/kernel.php index e39fc2914..22d73a373 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -177,7 +177,7 @@ ); if (!CLI) - (new GenericPage(null))->error(); + (new GenericPage())->error(); else echo 'Exception - '.$ex->getMessage()."\n ".$ex->getFile(). '('.$ex->getLine().")\n".$ex->getTraceAsString()."\n"; }); @@ -244,7 +244,7 @@ $str = explode('&', mb_strtolower($_SERVER['QUERY_STRING']), 2)[0]; $_ = explode('=', $str, 2); $pageCall = $_[0]; - $pageParam = isset($_[1]) ? $_[1] : null; + $pageParam = isset($_[1]) ? $_[1] : ''; Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/'.$str; } diff --git a/includes/types/areatrigger.class.php b/includes/types/areatrigger.class.php index c4c9e369b..1eca832ee 100644 --- a/includes/types/areatrigger.class.php +++ b/includes/types/areatrigger.class.php @@ -27,7 +27,7 @@ public function __construct($conditions) $_curTpl['name'] = 'Unnamed Areatrigger #' . $id; } - public function getListviewData() + public function getListviewData() : array { $data = []; @@ -46,7 +46,10 @@ public function getListviewData() return $data; } - public function getJSGlobals($addMask = GLOBALINFO_ANY) { } + public function getJSGlobals($addMask = GLOBALINFO_ANY) + { + return []; + } public function renderTooltip() { } } diff --git a/includes/types/item.class.php b/includes/types/item.class.php index d19f6e351..80b4c46fc 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -852,8 +852,9 @@ public function renderTooltip($interactive = false, $subOf = 0, $enhance = []) if ($dur = $this->curTpl['durability']) $x .= sprintf(Lang::item('durability'), $dur, $dur).'
'; + $jsg = []; // required classes - if ($classes = Lang::getClassString($this->curTpl['requiredClass'], $jsg, $__)) + if ($classes = Lang::getClassString($this->curTpl['requiredClass'], $jsg)) { foreach ($jsg as $js) if (empty($this->jsGlobals[TYPE_CLASS][$js])) @@ -863,7 +864,7 @@ public function renderTooltip($interactive = false, $subOf = 0, $enhance = []) } // required races - if ($races = Lang::getRaceString($this->curTpl['requiredRace'], $jsg, $__)) + if ($races = Lang::getRaceString($this->curTpl['requiredRace'], $jsg)) { foreach ($jsg as $js) if (empty($this->jsGlobals[TYPE_RACE][$js])) diff --git a/index.php b/index.php index f02c93a82..c5ce8a199 100644 --- a/index.php +++ b/index.php @@ -104,7 +104,7 @@ header('Location: '.$out, true, 302); else { - header('Content-type: '.$ajax->getContentType()); + header($ajax->getContentType()); die($out); } } diff --git a/localization/lang.class.php b/localization/lang.class.php index 422c7aaed..1857cbde8 100644 --- a/localization/lang.class.php +++ b/localization/lang.class.php @@ -337,7 +337,7 @@ public static function getMagicSchools($schoolMask) return implode(', ', $tmp); } - public static function getClassString($classMask, &$ids = [], &$n = 0, $asHTML = true) + public static function getClassString(int $classMask, array &$ids = [], bool $asHTML = true) : string { $classMask &= CLASS_MASK_ALL; // clamp to available classes.. @@ -359,13 +359,12 @@ public static function getClassString($classMask, &$ids = [], &$n = 0, $asHTML = $i++; } - $n = count($tmp); $ids = array_keys($tmp); return implode(', ', $tmp); } - public static function getRaceString($raceMask, &$ids = [], &$n = 0, $asHTML = true) + public static function getRaceString(int $raceMask, array &$ids = [], bool $asHTML = true) : string { $raceMask &= RACE_MASK_ALL; // clamp to available races.. @@ -396,7 +395,6 @@ public static function getRaceString($raceMask, &$ids = [], &$n = 0, $asHTML = t $i++; } - $n = count($tmp); $ids = array_keys($tmp); return implode(', ', $tmp); diff --git a/pages/achievement.php b/pages/achievement.php index 6c2b9b1c7..d08e2838a 100644 --- a/pages/achievement.php +++ b/pages/achievement.php @@ -32,6 +32,8 @@ class AchievementPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; + private $powerTpl = '$WowheadPower.registerAchievement(%d, %d, %s);'; + public function __construct($pageCall, $id) { parent::__construct($pageCall, $id); @@ -44,7 +46,7 @@ public function __construct($pageCall, $id) $this->subject = new AchievementList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('achievement'), Lang::achievement('notFound')); $this->extendGlobalData($this->subject->getJSGlobals(GLOBALINFO_REWARDS)); @@ -527,43 +529,17 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerAchievement('.$this->typeId.', '.User::$localeId.', {});'; - - $x = '$WowheadPower.registerAchievement('.$this->typeId.', '.User::$localeId.",{\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ticon: '".rawurlencode($this->subject->getField('iconString', true, true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".$this->subject->renderTooltip()."'\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') + protected function generateTooltip() { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('achievement'), $msg ?: Lang::achievement('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } private function createMail(&$reqCss = false) diff --git a/pages/areatrigger.php b/pages/areatrigger.php index bc9b9c224..ec9721a03 100644 --- a/pages/areatrigger.php +++ b/pages/areatrigger.php @@ -29,7 +29,7 @@ public function __construct($pageCall, $id) $this->subject = new AreaTriggerList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Util::ucFirst(Lang::game('areatrigger')), Lang::areatrigger('notFound')); + $this->notFound(Lang::game('areatrigger'), Lang::areatrigger('notFound')); $this->name = $this->subject->getField('name') ?: 'AT #'.$this->typeId; } @@ -99,14 +99,13 @@ protected function generateContent() { $sai = new SmartAI(SAI_SRC_TYPE_AREATRIGGER, $this->typeId, ['name' => $this->name, 'teleportA' => $this->subject->getField('teleportA')]); if ($sai->prepare()) - foreach ($sai->getJSGlobals() as $type => $typeIds) - $this->extendGlobalIds($type, $typeIds); + $this->extendGlobalData($sai->getJSGlobals()); } $this->map = $map; $this->infobox = false; - $this->extraText = $sai ? $sai->getMarkdown() : null; + $this->smartAI = $sai ? $sai->getMarkdown() : null; $this->redButtons = array( BUTTON_LINKS => false, BUTTON_WOWHEAD => false diff --git a/pages/arenateam.php b/pages/arenateam.php index 298330519..83831ebe3 100644 --- a/pages/arenateam.php +++ b/pages/arenateam.php @@ -126,9 +126,9 @@ protected function generateContent() } } - public function notFound($title = '', $msg = '') + public function notFound(string $title = '', string $msg = '') : void { - return parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'arenateam')); + parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'arenateam')); } private function handleIncompleteData($teamGuid) diff --git a/pages/currency.php b/pages/currency.php index c68a2a307..8a64bd2a0 100644 --- a/pages/currency.php +++ b/pages/currency.php @@ -17,6 +17,8 @@ class CurrencyPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; + private $powerTpl = '$WowheadPower.registerCurrency(%d, %d, %s);'; + public function __construct($pageCall, $id) { parent::__construct($pageCall, $id); @@ -29,7 +31,7 @@ public function __construct($pageCall, $id) $this->subject = new CurrencyList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('currency'), Lang::currency('notFound')); $this->name = $this->subject->getField('name', true); } @@ -220,43 +222,17 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.', {});'; - - $x = '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ticon: '".rawurlencode($this->subject->getField('iconString', true, true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".$this->subject->renderTooltip()."'\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') + protected function generateTooltip() { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('currency'), $msg ?: Lang::currency('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } } diff --git a/pages/emote.php b/pages/emote.php index 26d3bbb3f..18e83ef94 100644 --- a/pages/emote.php +++ b/pages/emote.php @@ -25,7 +25,7 @@ public function __construct($pageCall, $id) $this->subject = new EmoteList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Util::ucFirst(Lang::game('emote')), Lang::emote('notFound')); + $this->notFound(Lang::game('emote'), Lang::emote('notFound')); $this->name = Util::ucFirst($this->subject->getField('cmd')); } diff --git a/pages/enchantment.php b/pages/enchantment.php index e437969c5..f1b5d6596 100644 --- a/pages/enchantment.php +++ b/pages/enchantment.php @@ -25,7 +25,7 @@ public function __construct($pageCall, $id) $this->subject = new EnchantmentList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Util::ucFirst(Lang::game('enchantment')), Lang::enchantment('notFound')); + $this->notFound(Lang::game('enchantment'), Lang::enchantment('notFound')); $this->extendGlobalData($this->subject->getJSGlobals()); diff --git a/pages/enchantments.php b/pages/enchantments.php index a35cb3544..6d70a6b89 100644 --- a/pages/enchantments.php +++ b/pages/enchantments.php @@ -25,7 +25,7 @@ public function __construct($pageCall, $pageParam) parent::__construct($pageCall, $pageParam); $this->name = Util::ucFirst(Lang::game('enchantments')); - $this->subCat = $pageParam !== null ? '='.$pageParam : ''; + $this->subCat = $pageParam !== '' ? '='.$pageParam : ''; } protected function generateContent() @@ -100,8 +100,8 @@ protected function generateTitle() protected function generatePath() { $form = $this->filterObj->getForm('form'); - if (isset($form['ty']) && !is_array($form['ty'])) - $this->path[] = $form['ty']; + if (isset($form['ty']) && count($form['ty']) == 1) + $this->path[] = $form['ty'][0]; } } diff --git a/pages/event.php b/pages/event.php index e387c3e26..a0ca31813 100644 --- a/pages/event.php +++ b/pages/event.php @@ -17,6 +17,7 @@ class EventPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; + private $powerTpl = '$WowheadPower.registerHoliday(%d, %d, %s);'; private $hId = 0; private $eId = 0; @@ -32,7 +33,7 @@ public function __construct($pageCall, $id) $this->subject = new WorldEventList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('event'), Lang::event('notFound')); $this->hId = $this->subject->getField('holidayId'); $this->eId = $this->typeId; @@ -266,6 +267,22 @@ protected function generateContent() } } + protected function generateTooltip() : string + { + $power = new StdClass(); + if (!$this->subject->error) + { + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + + if ($this->subject->getField('iconString') != 'trade_engineering') + $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); + + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); + } + + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); + } + protected function postCache() { // update dates to now() @@ -326,50 +343,6 @@ protected function postCache() } } } - - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerHoliday('.$this->typeId.', '.User::$localeId.', {});'; - - $x = '$WowheadPower.registerHoliday('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - - if ($this->subject->getField('iconString') != 'trade_engineering') - $x .= "\ticon: '".rawurlencode($this->subject->getField('iconString', true, true))."',\n"; - - $x .= "\ttooltip_".User::$localeString.": '".$this->subject->renderTooltip()."'\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) - { - $tt = $this->generateTooltip(); - $this->saveCache($tt); - } - - [$start, $end] = $this->postCache(); - - header('Content-type: application/x-javascript; charset=utf-8'); - die(sprintf($tt, $start, $end)); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('event'), $msg ?: Lang::event('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); - } } ?> diff --git a/pages/faction.php b/pages/faction.php index 292f73229..22f8789be 100644 --- a/pages/faction.php +++ b/pages/faction.php @@ -58,7 +58,7 @@ protected function generateContent() // Quartermaster if any if ($ids = $this->subject->getField('qmNpcIds')) { - $this->extendGlobalIds(TYPE_NPC, $ids); + $this->extendGlobalIds(TYPE_NPC, ...$ids); $qmStr = Lang::faction('quartermaster').Lang::main('colon'); diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index d09243d12..17159f1ec 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -18,7 +18,7 @@ trait TrDetailPage protected $contribute = CONTRIBUTE_ANY; - protected function generateCacheKey($withStaff = true) + protected function generateCacheKey(bool $withStaff = true) : string { $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); @@ -32,7 +32,7 @@ protected function generateCacheKey($withStaff = true) return implode('_', $key); } - protected function applyCCErrors() + protected function applyCCErrors() : void { if (!empty($_SESSION['error']['co'])) $this->coError = $_SESSION['error']['co']; @@ -56,7 +56,7 @@ trait TrListPage private $filterObj = null; - protected function generateCacheKey($withStaff = true) + protected function generateCacheKey(bool $withStaff = true) : string { $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); @@ -73,6 +73,7 @@ protected function generateCacheKey($withStaff = true) } } + trait TrProfiler { protected $region = ''; @@ -85,7 +86,7 @@ trait TrProfiler protected $doResync = null; - protected function generateCacheKey($withStaff = true) + protected function generateCacheKey(bool $withStaff = true) : string { $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); @@ -95,15 +96,15 @@ protected function generateCacheKey($withStaff = true) return implode('_', $key); } - protected function getSubjectFromUrl($str) + protected function getSubjectFromUrl(string $pageParam) : void { - if (!$str) + if (!$pageParam) return; // cat[0] is always region // cat[1] is realm or bGroup (must be realm if cat[2] is set) // cat[2] is arena-team, guild or player - $cat = explode('.', $str, 3); + $cat = explode('.', $pageParam, 3); $cat = array_map('urldecode', $cat); @@ -131,7 +132,7 @@ protected function getSubjectFromUrl($str) } } - protected function initialSync() + protected function initialSync() : void { $this->prepareContent(); @@ -150,7 +151,7 @@ protected function initialSync() exit(); } - protected function generatePath() + protected function generatePath() : void { if ($this->region) { @@ -164,6 +165,7 @@ protected function generatePath() } } + class GenericPage { protected $tpl = ''; @@ -232,7 +234,7 @@ class GenericPage 'zone' => ['template' => 'zone', 'id' => 'zones', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_zones' ] ); - public function __construct($pageCall, $pageParam = null) + public function __construct(string $pageCall = '', string $pageParam = '') { $this->time = microtime(true); @@ -296,11 +298,13 @@ public function __construct($pageCall, $pageParam = null) $this->applyCCErrors(); } + /**********/ /* Checks */ /**********/ - private function isSaneInclude($path, $file) // "template_exists" + // "template_exists" + private function isSaneInclude(string $path, string $file) : bool { if (preg_match('/[^\w\-]/i', str_replace('admin/', '', $file))) return false; @@ -311,7 +315,8 @@ private function isSaneInclude($path, $file) // "template_exists" return true; } - private function isValidPage() // has a valid combination of categories + // has a valid combination of categories + private function isValidPage() : bool { if (!isset($this->category) || empty($this->validCats)) return true; @@ -341,11 +346,13 @@ private function isValidPage() // has a valid combinati return false; } + /****************/ /* Prepare Page */ /****************/ - protected function prepareContent() // get from cache ?: run generators + // get from cache ?: run generators + protected function prepareContent() : void { if (!$this->loadCache()) { @@ -404,7 +411,7 @@ protected function prepareContent() // get from cache ?: run $this->sumSQLStats(); } - public function addJS($name, $unshift = false) + public function addJS($name, bool $unshift = false) : void { if (is_array($name)) { @@ -420,7 +427,7 @@ public function addJS($name, $unshift = false) } } - public function addCSS($struct, $unshift = false) + public function addCSS(array $struct, bool $unshift = false) : void { if (is_array($struct) && empty($struct['path']) && empty($struct['string'])) { @@ -436,7 +443,8 @@ public function addCSS($struct, $unshift = false) } } - private function addArticle() // get article & static infobox (run before processing jsGlobals) + // get article & static infobox (run before processing jsGlobals) + private function addArticle() :void { $article = []; if (!empty($this->type) && isset($this->typeId)) @@ -492,7 +500,8 @@ private function addArticle() // get article & static } } - private function addAnnouncements() // get announcements and notes for user + // get announcements and notes for user + private function addAnnouncements() : void { if (!isset($this->announcements)) $this->announcements = []; @@ -539,9 +548,9 @@ private function addAnnouncements() // get announcements and } } - protected function getCategoryFromUrl($str) + protected function getCategoryFromUrl(string $urlParam) : void { - $arr = explode('.', $str); + $arr = explode('.', $urlParam); $params = []; foreach ($arr as $v) @@ -551,43 +560,61 @@ protected function getCategoryFromUrl($str) $this->category = $params; } - protected function forwardToSignIn($next = '') + protected function forwardToSignIn(string $next = '') : void { $next = $next ? '&next='.$next : ''; header('Location: ?account=signin'.$next, true, 302); } - protected function sumSQLStats() + protected function sumSQLStats() : void { Util::arraySumByKey($this->mysql, DB::Aowow()->getStatistics(), DB::World()->getStatistics()); } + /*******************/ /* Special Display */ /*******************/ - public function notFound($title, $msg = '') // unknown entry + // unknown entry + public function notFound(string $title = '', string $msg = '') : void { - array_unshift($this->title, Lang::main('nfPageTitle')); + header('HTTP/1.0 404 Not Found', true, 404); - $this->hasComContent = false; - $this->notFound = array( - 'title' => isset($this->typeId) ? Util::ucFirst($title).' #'.$this->typeId : $title, - 'msg' => !$msg && isset($this->typeId) ? sprintf(Lang::main('pageNotFound'), $title) : $msg - ); + if ($this->mode == CACHE_TYPE_TOOLTIP && method_exists($this, 'generateTooltip')) + { + header(MIME_TYPE_JSON); + echo $this->generateTooltip(); + } + else if ($this->mode == CACHE_TYPE_XML && method_exists($this, 'generateXML')) + { + header(MIME_TYPE_XML); + echo $this->generateXML(); + } + else + { + array_unshift($this->title, Lang::main('nfPageTitle')); - if (isset($this->tabId)) - $this->pageTemplate['activeTab'] = $this->tabId; + $this->hasComContent = false; + $this->notFound = array( + 'title' => isset($this->typeId) ? Util::ucFirst($title).' #'.$this->typeId : $title, + 'msg' => !$msg && isset($this->typeId) ? sprintf(Lang::main('pageNotFound'), $title) : $msg + ); - $this->sumSQLStats(); + if (isset($this->tabId)) + $this->pageTemplate['activeTab'] = $this->tabId; - header('HTTP/1.0 404 Not Found', true, 404); + $this->sumSQLStats(); + + + $this->display('list-page-generic'); + } - $this->display('list-page-generic'); exit(); } - public function error() // unknown page + // unknown page + public function error() : void { $this->path = null; $this->tabId = null; @@ -606,7 +633,8 @@ public function error() // unknown page exit(); } - public function maintenance() // display brb gnomes + // display brb gnomes + public function maintenance() : void { header('HTTP/1.0 503 Service Temporarily Unavailable', true, 503); header('Retry-After: '.(3 * HOUR)); @@ -615,46 +643,74 @@ public function maintenance() // display brb gnomes exit(); } + /*******************/ /* General Display */ /*******************/ - public function display($override = '') // load given template string or GenericPage::$tpl + // load given template string or GenericPage::$tpl + public function display(string $override = '') : void { // Heisenbug: IE11 and FF32 will sometimes (under unknown circumstances) cache 302 redirects and stop // re-requesting them from the server but load them from local cache, thus breaking menu features. Util::sendNoCacheHeader(); - if (isset($this->tabId)) - $this->pageTemplate['activeTab'] = $this->tabId; - - if ($override) - { - $this->addAnnouncements(); - - include('template/pages/'.$override.'.tpl.php'); - die(); - } - else if ($this->tpl) + if ($this->mode == CACHE_TYPE_TOOLTIP && method_exists($this, 'generateTooltip')) + $this->displayExtra([$this, 'generateTooltip']); + else if ($this->mode == CACHE_TYPE_XML && method_exists($this, 'generateXML')) + $this->displayExtra([$this, 'generateXML'], MIME_TYPE_XML); + else { - $this->prepareContent(); + if (isset($this->tabId)) + $this->pageTemplate['activeTab'] = $this->tabId; - if (!$this->isSaneInclude('template/pages/', $this->tpl)) + if ($override) { - trigger_error('Error: nonexistant template requested: template/pages/'.$this->tpl.'.tpl.php', E_USER_ERROR); - $this->error(); + $this->addAnnouncements(); + + include('template/pages/'.$override.'.tpl.php'); + die(); } + else if ($this->tpl) + { + $this->prepareContent(); + + if (!$this->isSaneInclude('template/pages/', $this->tpl)) + { + trigger_error('Error: nonexistant template requested: template/pages/'.$this->tpl.'.tpl.php', E_USER_ERROR); + $this->error(); + } - $this->addAnnouncements(); + $this->addAnnouncements(); + + include('template/pages/'.$this->tpl.'.tpl.php'); + die(); + } + else + $this->error(); + } + } - include('template/pages/'.$this->tpl.'.tpl.php'); - die(); + // generate and cache + public function displayExtra(callable $generator, string $mime = MIME_TYPE_JSON) : void + { + $outString = ''; + if (!$this->loadCache($outString)) + { + $outString = $generator(); + $this->saveCache($outString); } + + header($mime); + + if (method_exists($this, 'postCache') && ($pc = $this->postCache())) + die(sprintf($outString, ...$pc)); else - $this->error(); + die($outString); } - public function writeGlobalVars() // load jsGlobal + // load jsGlobal + public function writeGlobalVars() : string { $buff = ''; @@ -700,7 +756,8 @@ public function writeGlobalVars() // load jsGlobal return $buff; } - public function brick($file, array $localVars = []) // load brick + // load brick + public function brick(string $file, array $localVars = []) : void { foreach ($localVars as $n => $v) $$n = $v; @@ -711,7 +768,8 @@ public function brick($file, array $localVars = []) // load brick include('template/bricks/'.$file.'.tpl.php'); } - public function lvBrick($file) // load listview addIns + // load listview addIns + public function lvBrick(string $file) : void { if (!$this->isSaneInclude('template/listviews/', $file)) trigger_error('Nonexistant Listview addin requested: template/listviews/'.$file.'.tpl.php', E_USER_ERROR); @@ -719,7 +777,8 @@ public function lvBrick($file) // load listview addIns include('template/listviews/'.$file.'.tpl.php'); } - public function localizedBrick($file, $loc = LOCALE_EN) // load brick with more text then vars + // load brick with more text then vars + public function localizedBrick(string $file, int $loc = LOCALE_EN) : void { if (!$this->isSaneInclude('template/localized/', $file.'_'.$loc)) { @@ -732,32 +791,27 @@ public function localizedBrick($file, $loc = LOCALE_EN) // load brick with more include('template/localized/'.$file.'_'.$loc.'.tpl.php'); } + /**********************/ /* Prepare js-Globals */ /**********************/ - public function extendGlobalIds($type, $data) // add typeIds that should be displayed as jsGlobal on the page + // add typeIds that should be displayed as jsGlobal on the page + public function extendGlobalIds(int $type, int ...$ids) : void { - if (!$type || !$data) - return false; + if (!$type || !$ids) + return; if (!isset($this->jsgBuffer[$type])) $this->jsgBuffer[$type] = []; - if (is_array($data)) - { - foreach ($data as $id) - $this->jsgBuffer[$type][] = (int)$id; - } - else if (is_numeric($data)) - $this->jsgBuffer[$type][] = (int)$data; + foreach ($ids as $id) + $this->jsgBuffer[$type][] = $id; } - public function extendGlobalData($data, $extra = null) // add jsGlobals or typeIds (can be mixed in one array: TYPE => [mixeddata]) to display on the page + // add jsGlobals or typeIds (can be mixed in one array: TYPE => [mixeddata]) to display on the page + public function extendGlobalData(array $data, ?array $extra = null) : void { - if ($data === null) - throw new ErrorException('ffffuuuu.....!'); - foreach ($data as $type => $globals) { if (!is_array($globals) || !$globals) @@ -781,7 +835,8 @@ public function extendGlobalData($data, $extra = null) // add jsGlobals or type $this->jsGlobals[$type][2] = $extra; } - private function initJSGlobal($type) // init store for type + // init store for type + private function initJSGlobal(int $type) : void { $jsg = &$this->jsGlobals; // shortcut @@ -815,7 +870,8 @@ private function initJSGlobal($type) // init store for type } } - private function applyGlobals() // lookup jsGlobals from collected typeIds + // lookup jsGlobals from collected typeIds + private function applyGlobals() : void { foreach ($this->jsgBuffer as $type => $ids) { @@ -864,14 +920,16 @@ private function applyGlobals() // lookup jsGlobals from } } + /*********/ /* Cache */ /*********/ - public function saveCache($saveString = null) // visible properties or given strings are cached + // visible properties or given strings are cached + private function saveCache(string $saveString = '') : void { if ($this->mode == CACHE_TYPE_NONE) - return false; + return; if (!CFG_CACHE_MODE || CFG_DEBUG) return; @@ -894,7 +952,7 @@ public function saveCache($saveString = null) // visible properties or } } else - $cache = (string)$saveString; + $cache = $saveString; if (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED) { @@ -949,7 +1007,7 @@ public function saveCache($saveString = null) // visible properties or } } - public function loadCache(&$saveString = null) + private function loadCache(string &$saveString = '') : bool { if ($this->mode == CACHE_TYPE_NONE) return false; @@ -1021,7 +1079,7 @@ public function loadCache(&$saveString = null) return false;; } - private function memcached() + private function memcached() : Memcached { if (!$this->memcached && (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED)) { diff --git a/pages/guild.php b/pages/guild.php index 9c9f7d2f4..8051eb116 100644 --- a/pages/guild.php +++ b/pages/guild.php @@ -130,9 +130,9 @@ protected function generateContent() } } - public function notFound($title = '', $msg = '') + public function notFound(string $title = '', string $msg = '') : void { - return parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'guild')); + parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'guild')); } private function handleIncompleteData($teamGuid) diff --git a/pages/icon.php b/pages/icon.php index c3872fe94..0eae19d9b 100644 --- a/pages/icon.php +++ b/pages/icon.php @@ -25,7 +25,7 @@ public function __construct($pageCall, $id) $this->subject = new IconList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Util::ucFirst(Lang::game('icon')), Lang::icon('notFound')); + $this->notFound(Lang::game('icon'), Lang::icon('notFound')); $this->extendGlobalData($this->subject->getJSGlobals()); diff --git a/pages/item.php b/pages/item.php index 819d2db3c..1a8daab0e 100644 --- a/pages/item.php +++ b/pages/item.php @@ -23,6 +23,8 @@ class ItemPage extends genericPage 'filters.js' // lolwut? ); + private $powerTpl = '$WowheadPower.registerItem(%s, %d, %s);'; + public function __construct($pageCall, $param) { parent::__construct($pageCall, $param); @@ -59,7 +61,7 @@ public function __construct($pageCall, $param) $this->subject = new ItemList($conditions); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('item'), Lang::item('notFound')); if (!is_numeric($param)) $this->typeId = $this->subject->id; @@ -1009,30 +1011,33 @@ protected function generateContent() // name: LANG.tab_taughtby } - protected function generateTooltip($asError = false) + protected function generateTooltip() { - $itemString = $this->typeId; - foreach ($this->enhancedTT as $k => $val) - $itemString .= $k.(is_array($val) ? implode(',', $val) : $val); - - if ($asError) - return '$WowheadPower.registerItem(\''.$itemString.'\', '.User::$localeId.', {})'; + $power = new StdClass(); + if (!$this->subject->error) + { + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true, false, $this->enhancedTT); + $power->quality = $this->subject->getField('quality'); + $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(false, 0, $this->enhancedTT); + } - $x = '$WowheadPower.registerItem(\''.$itemString.'\', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true, false, $this->enhancedTT))."',\n"; - $x .= "\tquality: ".$this->subject->getField('quality').",\n"; - $x .= "\ticon: '".rawurlencode($this->subject->getField('iconString', true, true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".Util::jsEscape($this->subject->renderTooltip(false, 0, $this->enhancedTT))."'\n"; - $x .= "});"; + $itemString = $this->typeId; + if ($this->enhancedTT) + { + foreach ($this->enhancedTT as $k => $val) + $itemString .= $k.(is_array($val) ? implode(',', $val) : $val); + $itemString = "'".$itemString."'"; + } - return $x; + return sprintf($this->powerTpl, $itemString, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } - protected function generateXML($asError = false) + protected function generateXML() { $root = new SimpleXML(''); - if ($asError) + if ($this->subject->error) $root->addChild('error', 'Item not found!'); else { @@ -1173,52 +1178,6 @@ protected function generateXML($asError = false) return $root->asXML(); } - - public function display($override = '') - { - if ($this->mode == CACHE_TYPE_TOOLTIP) - { - if (!$this->loadCache($tt)) - { - $tt = $this->generateTooltip(); - $this->saveCache($tt); - } - - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - else if ($this->mode == CACHE_TYPE_XML) - { - if (!$this->loadCache($xml)) - { - $xml = $this->generateXML(); - $this->saveCache($xml); - } - - header('Content-type: text/xml; charset=utf-8'); - die($xml); - } - else - return parent::display($override); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode == CACHE_TYPE_TOOLTIP) - { - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); - } - else if ($this->mode == CACHE_TYPE_XML) - { - header('Content-type: text/xml; charset=utf-8'); - echo $this->generateXML(true); - exit(); - } - else - return parent::notFound($title ?: Lang::game('item'), $msg ?: Lang::item('notFound')); - } } ?> diff --git a/pages/items.php b/pages/items.php index 12e58d1d3..f4cfaa200 100644 --- a/pages/items.php +++ b/pages/items.php @@ -88,7 +88,7 @@ public function __construct($pageCall, $pageParam) parent::__construct($pageCall, $pageParam); $this->name = Util::ucFirst(Lang::game('items')); - $this->subCat = $pageParam !== null ? '='.$pageParam : ''; + $this->subCat = $pageParam !== '' ? '='.$pageParam : ''; } protected function generateContent() diff --git a/pages/itemset.php b/pages/itemset.php index 263e4c028..3667d3695 100644 --- a/pages/itemset.php +++ b/pages/itemset.php @@ -21,6 +21,8 @@ class ItemsetPage extends GenericPage 'Summary.js' ); + private $powerTpl = '$WowheadPower.registerItemSet(%d, %d, %s);'; + public function __construct($pageCall, $id) { parent::__construct($pageCall, $id); @@ -33,7 +35,7 @@ public function __construct($pageCall, $id) $this->subject = new ItemsetList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('itemset'), Lang::itemset('notFound')); $this->name = $this->subject->getField('name', true); $this->extendGlobalData($this->subject->getJSGlobals()); @@ -92,10 +94,11 @@ protected function generateContent() } // class - if ($cl = Lang::getClassString($this->subject->getField('classMask'), $jsg, $qty, false)) + $jsg = []; + if ($cl = Lang::getClassString($this->subject->getField('classMask'), $jsg, false)) { - $this->extendGlobalIds(TYPE_CLASS, $jsg); - $t = $qty == 1 ? Lang::game('class') : Lang::game('classes'); + $this->extendGlobalIds(TYPE_CLASS, ...$jsg); + $t = count($jsg)== 1 ? Lang::game('class') : Lang::game('classes'); $infobox[] = Util::ucFirst($t).Lang::main('colon').$cl; } @@ -229,42 +232,16 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerItemSet('.$this->typeId.', '.User::$localeId.', {});'; - - $x = '$WowheadPower.registerItemSet('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".$this->subject->renderTooltip()."'\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') + protected function generateTooltip() { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('itemset'), $msg ?: Lang::itemset('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } } diff --git a/pages/mail.php b/pages/mail.php index ab1929575..24c07f37b 100644 --- a/pages/mail.php +++ b/pages/mail.php @@ -55,10 +55,11 @@ protected function generateContent() if ($mlr['level']) $infobox[] = Lang::game('level').Lang::main('colon').$mlr['level']; - if ($r = Lang::getRaceString($mlr['raceMask'], $rId, $_, false)) + $rIds = []; + if ($r = Lang::getRaceString($mlr['raceMask'], $rIds, false)) { $infobox[] = Lang::game('races').Lang::main('colon').$r; - $this->extendGlobalIds(TYPE_RACE, $rId); + $this->extendGlobalIds(TYPE_RACE, ...$rIds); } $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$mlr['senderEntry'].']'; diff --git a/pages/npc.php b/pages/npc.php index 610904085..f5324dd9d 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -19,6 +19,7 @@ class NpcPage extends GenericPage protected $js = ['swfobject.js']; private $soundIds = []; + private $powerTpl = '$WowheadPower.registerNpc(%d, %d, %s);'; public function __construct($pageCall, $id) { @@ -32,7 +33,7 @@ public function __construct($pageCall, $id) $this->subject = new CreatureList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('npc'), Lang::npc('notFound')); $this->name = Util::htmlEscape($this->subject->getField('name', true)); $this->subname = $this->subject->getField('subname', true); @@ -335,10 +336,7 @@ protected function generateContent() } if ($sai->prepare()) - { - foreach ($sai->getJSGlobals() as $type => $typeIds) - $this->extendGlobalIds($type, $typeIds); - } + $this->extendGlobalData($sai->getJSGlobals()); else trigger_error('Creature has SmartAI set in template but no SmartAI defined.'); } @@ -841,45 +839,17 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) + protected function generateTooltip() { - if ($asError) - return '$WowheadPower.registerNpc('.$this->typeId.', '.User::$localeId.', {})'; - - $s = $this->subject->getSpawns(SPAWNINFO_SHORT); - - $x = '$WowheadPower.registerNpc('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".Util::jsEscape($this->subject->renderTooltip())."',\n"; - $x .= "\tmap: ".($s ? "{zone: ".$s[0].", coords: {".$s[1].":".Util::toJSON($s[2])."}}" : '{}')."\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); + $power->map = $this->subject->getSpawns(SPAWNINFO_SHORT); } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('npc'), $msg ?: Lang::npc('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } private function getRepForId($entries, &$spillover) diff --git a/pages/object.php b/pages/object.php index 75223c724..a483528a9 100644 --- a/pages/object.php +++ b/pages/object.php @@ -18,6 +18,8 @@ class ObjectPage extends GenericPage protected $mode = CACHE_TYPE_PAGE; protected $js = ['swfobject.js']; + private $powerTpl = '$WowheadPower.registerObject(%d, %d, %s);' + public function __construct($pageCall, $id) { parent::__construct($pageCall, $id); @@ -30,7 +32,7 @@ public function __construct($pageCall, $id) $this->subject = new GameObjectList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('object'), Lang::gameObject('notFound')); $this->name = $this->subject->getField('name', true); } @@ -248,10 +250,7 @@ protected function generateContent() } if ($sai->prepare()) - { - foreach ($sai->getJSGlobals() as $type => $typeIds) - $this->extendGlobalIds($type, $typeIds); - } + $this->extendGlobalData($sai->getJSGlobals()); else trigger_error('Gameobject has AIName set in template but no SmartAI defined.'); } @@ -481,45 +480,17 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerObject('.$this->typeId.', '.User::$localeId.', {});'; - - $s = $this->subject->getSpawns(SPAWNINFO_SHORT); - - $x = '$WowheadPower.registerObject('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".Util::jsEscape($this->subject->renderTooltip())."',\n"; - $x .= "\tmap: ".($s ? "{zone: ".$s[0].", coords: {".$s[1].":".Util::toJSON($s[2])."}}" : '{}')."\n"; - $x .= "});"; - - return $x; - } - - public function display($override = '') + protected function generateTooltip() { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); + $power->map = $this->subject->getSpawns(SPAWNINFO_SHORT); } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('object'), $msg ?: Lang::gameObject('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } } diff --git a/pages/profile.php b/pages/profile.php index 10c6f36e0..cf2f6dc07 100644 --- a/pages/profile.php +++ b/pages/profile.php @@ -27,6 +27,7 @@ class ProfilePage extends GenericPage private $isCustom = false; private $profile = null; private $rnItr = 0; + private $powerTpl = '$WowheadPower.registerProfile(%s, %d, %s);'; public function __construct($pageCall, $pageParam) { @@ -50,6 +51,7 @@ public function __construct($pageCall, $pageParam) // redundancy much? $this->subjectGUID = intval($params[0]); $this->profile = intval($params[0]); + $this->isCustom = true; // until proven otherwise $this->subject = new LocalProfileList(array(['id', intval($params[0])])); if ($this->subject->error) @@ -58,9 +60,7 @@ public function __construct($pageCall, $pageParam) if (!$this->subject->isVisibleToUser()) $this->notFound(); - if ($this->subject->isCustom()) - $this->isCustom = true; - else + if (!$this->subject->isCustom()) header('Location: '.$this->subject->getProfileUrl(), true, 302); } else if (count($params) == 3) @@ -154,7 +154,7 @@ protected function generateContent() /* Anub, Faerlina, Maexxna, Noth, Heigan, Loatheb, Razuvious, Gothik, Patchwerk, Grobbulus, Gluth, Thaddius, Sapphiron, Kel'Thuzad */ /* nax */ 15956, 15953, 15952, 15954, 15936, 16011, 16061, 16060, 16028, 15931, 15932, 15928, 15989, 15990 ); - $this->extendGlobalIds(TYPE_NPC, $bossIds); + $this->extendGlobalIds(TYPE_NPC, ...$bossIds); // dummy title from dungeon encounter foreach (Lang::profiler('encounterNames') as $id => $name) @@ -171,59 +171,48 @@ protected function generateTitle() array_unshift($this->title, Util::ucFirst(Lang::game('profile'))); } - protected function generateTooltip($asError = false) + protected function generateTooltip() { $id = $this->profile; if (!$this->isCustom) $id = "'".$this->profile[0].'.'.$this->profile[1].'.'.urlencode($this->profile[2])."'"; - $x = '$WowheadPower.registerProfile('.$id.', '.User::$localeId.', {'; - if ($asError) - return $x."});"; - - $name = $this->subject->getField('name'); - $guild = $this->subject->getField('guild'); - $guildRank = $this->subject->getField('guildrank'); - $lvl = $this->subject->getField('level'); - $ra = $this->subject->getField('race'); - $cl = $this->subject->getField('class'); - $gender = $this->subject->getField('gender'); - $title = ''; - if ($_ = $this->subject->getField('title')) - $title = (new TitleList(array(['id', $_])))->getField($gender ? 'female' : 'male', true); - - if ($this->isCustom) - $name .= Lang::profiler('customProfile'); - else if ($title) - $name = sprintf($title, $name); - - $x .= "\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($name)."',\n"; - $x .= "\ttooltip_".User::$localeString.": '".$this->subject->renderTooltip()."',\n"; - $x .= "\ticon: \$WH.g_getProfileIcon(".$ra.", ".$cl.", ".$gender.", ".$lvl.", '".$this->subject->getIcon()."'),\n"; // (race, class, gender, level, iconOrId, 'medium') - $x .= "});"; - - return $x; + $power = new StdClass(); + if ($this->subject && !$this->subject->error && $this->subject->isVisibleToUser()) + { + $n = $this->subject->getField('name'); + $l = $this->subject->getField('level'); + $r = $this->subject->getField('race'); + $c = $this->subject->getField('class'); + $g = $this->subject->getField('gender'); + + if ($this->isCustom) + $n .= Lang::profiler('customProfile'); + else if ($_ = $this->subject->getField('title')) + if ($title = (new TitleList(array(['id', $_])))->getField($g ? 'female' : 'male', true)) + $n = sprintf($title, $n); + + $power->{'name_'.User::$localeString} = $n; + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); + $power->icon = '$$WH.g_getProfileIcon('.$r.', '.$c.', '.$g.', '.$l.', \''.$this->subject->getIcon().'\')'; + } + + return sprintf($this->powerTpl, $id, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } - public function display($override = '') + public function display(string $override = ''): void { if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); + parent::display($override); // do not cache profile tooltips - header('Content-type: application/x-javascript; charset=utf-8'); + header(MIME_TYPE_JSON); die($this->generateTooltip()); } - public function notFound($title = '', $msg = '') + public function notFound(string $title = '', string $msg = '') : void { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'profile')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'profile')); } private function handleIncompleteData($params, $guid) diff --git a/pages/quest.php b/pages/quest.php index 3b32cac21..af83529b0 100644 --- a/pages/quest.php +++ b/pages/quest.php @@ -19,6 +19,8 @@ class QuestPage extends GenericPage protected $css = [['path' => 'Book.css']]; protected $js = ['ShowOnMap.js']; + private $powerTpl = '$WowheadPower.registerQuest(%d, %d, %s);'; + public function __construct($pageCall, $id) { parent::__construct($pageCall, $id); @@ -31,7 +33,7 @@ public function __construct($pageCall, $id) $this->subject = new QuestList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('quest'), Lang::quest('notFound')); // may contain htmlesque tags $this->name = Util::htmlEscape($this->subject->getField('name', true)); @@ -138,19 +140,20 @@ protected function generateContent() case 1: $infobox[] = $_.'[span class=icon-alliance]'.Lang::game('si', 1).'[/span]'; break; } + $jsg = []; // races - if ($_ = Lang::getRaceString($this->subject->getField('reqRaceMask'), $jsg, $n, false)) + if ($_ = Lang::getRaceString($this->subject->getField('reqRaceMask'), $jsg, false)) { - $this->extendGlobalIds(TYPE_RACE, $jsg); - $t = $n == 1 ? Lang::game('race') : Lang::game('races'); + $this->extendGlobalIds(TYPE_RACE, ...$jsg); + $t = count($jsg) == 1 ? Lang::game('race') : Lang::game('races'); $infobox[] = Util::ucFirst($t).Lang::main('colon').$_; } // classes - if ($_ = Lang::getClassString($this->subject->getField('reqClassMask'), $jsg, $n, false)) + if ($_ = Lang::getClassString($this->subject->getField('reqClassMask'), $jsg, false)) { - $this->extendGlobalIds(TYPE_CLASS, $jsg); - $t = $n == 1 ? Lang::game('class') : Lang::game('classes'); + $this->extendGlobalIds(TYPE_CLASS, ...$jsg); + $t = count($jsg) == 1 ? Lang::game('class') : Lang::game('classes'); $infobox[] = Util::ucFirst($t).Lang::main('colon').$_; } @@ -1015,44 +1018,18 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) - { - if ($asError) - return '$WowheadPower.registerQuest('.$this->typeId.', '.User::$localeId.', {});'; - - $x = '$WowheadPower.registerQuest('.$this->typeId.', '.User::$localeId.", {\n"; - $x .= "\tname_".User::$localeString.": '".Util::jsEscape($this->subject->getField('name', true))."',\n"; - $x .= "\ttooltip_".User::$localeString.': \''.$this->subject->renderTooltip()."'"; - if ($this->subject->isDaily()) - $x .= ",\n\tdaily: 1"; - $x .= "\n});"; - - return $x; - } - - public function display($override = '') + protected function generateTooltip() { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) + $power = new StdClass(); + if (!$this->subject->error) { - $tt = $this->generateTooltip(); - $this->saveCache($tt); + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); + if ($this->subject->isDaily()) + $power->daily = 1; } - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('quest'), $msg ?: Lang::quest('notFound')); - - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } private function createRewards($side) diff --git a/pages/search.php b/pages/search.php index 5c30f4b3a..bf3d1105e 100644 --- a/pages/search.php +++ b/pages/search.php @@ -206,7 +206,7 @@ protected function generateContent() // just wrap it, so Gene $this->performSearch(); } - public function notFound($title = '', $msg = '') + public function notFound(string $title = '', string $msg = '') : void { if ($this->searchMask & SEARCH_TYPE_REGULAR) { @@ -220,80 +220,53 @@ public function notFound($title = '', $msg = '') parent::display(); // errors are handled in the search-template itself } else if ($this->searchMask & SEARCH_TYPE_OPEN) - $result = $this->generateOpenSearch(true); - else /* if ($this->searchMask & SEARCH_TYPE_JSON) */ - $result = $this->generateJsonSearch(true); + $result = [$this->search, []]; + else if ($this->searchMask & SEARCH_TYPE_JSON) + $result = [$this->search, [], []]; - header("Content-type: application/x-javascript"); - exit($result); + header(MIME_TYPE_JSON); + exit(Util::toJSON($result)); } - public function display($override = '') + public function display(string $override = '') : void { if ($override || ($this->searchMask & SEARCH_TYPE_REGULAR)) - return parent::display($override); + parent::display($override); else if ($this->searchMask & SEARCH_TYPE_OPEN) - { - if (!$this->loadCache($open)) - { - $this->performSearch(); - $open = $this->generateOpenSearch(); - $this->saveCache($open); - } - header('Content-type: application/x-javascript; charset=utf-8'); - die($open); - } - else /* if ($this->searchMask & SEARCH_TYPE_JSON) */ - { - if (!$this->loadCache($json)) - { - $this->performSearch(); - $json = $this->generateJsonSearch(); - $this->saveCache($json); - } - header('Content-type: application/x-javascript; charset=utf-8'); - die($json); - } + $this->displayExtra([$this, 'generateOpenSearch']); + else if ($this->searchMask & SEARCH_TYPE_JSON) + $this->displayExtra([$this, 'generateJsonSearch']); } - private function generateJsonSearch($asError = false) // !note! dear reader, if you ever try to generate a string, that is to be evaled by JS, NEVER EVER terminate with a \n ..... $totalHoursWasted +=2; + // !note! dear reader, if you ever try to generate a string, that is to be evaled by JS, NEVER EVER terminate with a \n ..... $totalHoursWasted +=2; + protected function generateJsonSearch() { - $outItems = ''; - $outSets = ''; + $outItems = []; + $outSets = []; - if (!$asError) - { - // items - if (!empty($this->lvTabs[6][1]['data'])) - { - $items = []; - foreach ($this->lvTabs[6][1]['data'] as $k => $v) - $items[] = Util::toJSON($v); + $this->performSearch(); - $outItems = "\t".implode(",\n\t", $items)."\n"; - } + // items + if (!empty($this->lvTabs[6][1]['data'])) + $outItems = array_values($this->lvTabs[6][1]['data']); - // item sets - if (!empty($this->lvTabs[5][1]['data'])) + // item sets + if (!empty($this->lvTabs[5][1]['data'])) + { + foreach ($this->lvTabs[5][1]['data'] as $k => $v) { - $sets = []; - foreach ($this->lvTabs[5][1]['data'] as $k => $v) - { - unset($v['quality']); - if (!$v['heroic']) - unset($v['heroic']); + unset($v['quality']); + if (!$v['heroic']) + unset($v['heroic']); - $sets[] = Util::toJSON($v); - } - - $outSets = "\t".implode(",\n\t", $sets)."\n"; + $outSets[] = $v; } } - return '["'.Util::jsEscape($this->search)."\", [\n".$outItems."],[\n".$outSets.']]'; + return Util::toJSON([$this->search, $outItems, $outSets]); } - private function generateOpenSearch($asError = false) + protected function generateOpenSearch() { // this one is funny: we want 10 results, ideally equally distributed over each type $foundTotal = 0; @@ -303,11 +276,13 @@ private function generateOpenSearch($asError = false) [], [], [], [], [], [], [] ); + $this->performSearch(); + foreach ($this->lvTabs as [ , , , $osInfo]) $foundTotal += $osInfo[2]; - if (!$foundTotal || $asError) - return '["'.Util::jsEscape($this->search).'", []]'; + if (!$foundTotal) + return Util::toJSON([$this->search, []]); foreach ($this->lvTabs as [ , $tabData, , $osInfo]) { diff --git a/pages/spell.php b/pages/spell.php index 7e09bd111..323cf94c6 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -20,6 +20,7 @@ class SpellPage extends GenericPage private $difficulties = []; private $firstRank = 0; + private $powerTpl = '$WowheadPower.registerSpell(%d, %d, %s);'; public function __construct($pageCall, $id) { @@ -33,7 +34,7 @@ public function __construct($pageCall, $id) $this->subject = new SpellList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(); + $this->notFound(Lang::game('spell'), Lang::spell('notFound')); $jsg = $this->subject->getJSGlobals(GLOBALINFO_ANY, $extra); $this->extendGlobalData($jsg, $extra); @@ -158,19 +159,20 @@ protected function generateContent() $infobox[] = (in_array($_cat, [-2, 7, -13]) ? sprintf(Lang::game('reqLevel'), $_) : Lang::game('level').Lang::main('colon').$_); } + $jsg = []; // races - if ($_ = Lang::getRaceString($this->subject->getField('reqRaceMask'), $jsg, $n, false)) + if ($_ = Lang::getRaceString($this->subject->getField('reqRaceMask'), $jsg, false)) { - $this->extendGlobalIds(TYPE_RACE, $jsg); - $t = $n == 1 ? Lang::game('race') : Lang::game('races'); + $this->extendGlobalIds(TYPE_RACE, ...$jsg); + $t = count($jsg) == 1 ? Lang::game('race') : Lang::game('races'); $infobox[] = Util::ucFirst($t).Lang::main('colon').$_; } // classes - if ($_ = Lang::getClassString($this->subject->getField('reqClassMask'), $jsg, $n, false)) + if ($_ = Lang::getClassString($this->subject->getField('reqClassMask'), $jsg, false)) { - $this->extendGlobalIds(TYPE_CLASS, $jsg); - $t = $n == 1 ? Lang::game('class') : Lang::game('classes'); + $this->extendGlobalIds(TYPE_CLASS, ...$jsg); + $t = count($jsg) == 1 ? Lang::game('class') : Lang::game('classes'); $infobox[] = Util::ucFirst($t).Lang::main('colon').$_; } @@ -923,7 +925,7 @@ protected function generateContent() if ($a['racemask'] & (1 << $i)) $foo[] = $i + 1; - $this->extendGlobalIds(TYPE_RACE, $foo); + $this->extendGlobalIds(TYPE_RACE, ...$foo); $condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]]; } @@ -1193,55 +1195,23 @@ protected function generateContent() } } - protected function generateTooltip($asError = false) + protected function generateTooltip() { - if ($asError) - die('$WowheadPower.registerSpell('.$this->typeId.', '.User::$localeId.', {});'); - - $x = '$WowheadPower.registerSpell('.$this->typeId.', '.User::$localeId.", {\n"; - $pt = []; - if ($n = $this->subject->getField('name', true)) - $pt[] = "\tname_".User::$localeString.": '".Util::jsEscape($n)."'"; - if ($i = $this->subject->getField('iconString', true, true)) - $pt[] = "\ticon: '".rawurlencode($i)."'"; - if ($tt = $this->subject->renderTooltip()) + $power = new StdClass(); + if (!$this->subject->error) { - $pt[] = "\ttooltip_".User::$localeString.": '".Util::jsEscape($tt[0])."'"; - $pt[] = "\tspells_".User::$localeString.": ".Util::toJSON($tt[1]); + [$tooltip, $ttSpells] = $this->subject->renderTooltip(); + [$buff, $bfSpells] = $this->subject->renderBuff(); + + $power->{'name_'.User::$localeString} = $this->subject->getField('name', true); + $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); + $power->{'tooltip_'.User::$localeString} = $tooltip; + $power->{'spells_'.User::$localeString} = $ttSpells; + $power->{'buff_'.User::$localeString} = $buff; + $power->{'buffspells_'.User::$localeString} = $bfSpells; } - if ($btt = $this->subject->renderBuff()) - { - $pt[] = "\tbuff_".User::$localeString.": '".Util::jsEscape($btt[0])."'"; - $pt[] = "\tbuffspells_".User::$localeString.": ".Util::toJSON($btt[1]);; - } - $x .= implode(",\n", $pt)."\n});"; - - return $x; - } - - public function display($override = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::display($override); - - if (!$this->loadCache($tt)) - { - $tt = $this->generateTooltip(); - $this->saveCache($tt); - } - - header('Content-type: application/x-javascript; charset=utf-8'); - die($tt); - } - - public function notFound($title = '', $msg = '') - { - if ($this->mode != CACHE_TYPE_TOOLTIP) - return parent::notFound($title ?: Lang::game('spell'), $msg ?: Lang::spell('notFound')); - header('Content-type: application/x-javascript; charset=utf-8'); - echo $this->generateTooltip(true); - exit(); + return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } private function appendReagentItem(&$reagentResult, $_iId, $_qty, $_mult, $_level, $_path, $alreadyUsed) diff --git a/pages/spells.php b/pages/spells.php index 9aa86dac3..e20bdba82 100644 --- a/pages/spells.php +++ b/pages/spells.php @@ -91,7 +91,7 @@ public function __construct($pageCall, $pageParam) parent::__construct($pageCall, $pageParam); $this->name = Util::ucFirst(Lang::game('spells')); - $this->subCat = $pageParam !== null ? '='.$pageParam : ''; + $this->subCat = $pageParam !== '' ? '='.$pageParam : ''; $this->classPanel = false; $this->glyphPanel = false; diff --git a/pages/talent.php b/pages/talent.php index 4db7a2b76..d11ffadaf 100644 --- a/pages/talent.php +++ b/pages/talent.php @@ -36,7 +36,7 @@ protected function generateContent() $this->isPetCalc ? 'petcalc.js' : 'talent.js', $this->isPetCalc ? 'swfobject.js' : null )); - $this->addCSS($this->isPetCalc ? ['path' => 'petcalc.css'] : null); + $this->addCSS($this->isPetCalc ? ['path' => 'petcalc.css'] : []); $this->tcType = $this->isPetCalc ? 'pc' : 'tc'; } diff --git a/pages/utility.php b/pages/utility.php index 5ce8d84f3..68719b931 100644 --- a/pages/utility.php +++ b/pages/utility.php @@ -44,15 +44,15 @@ public function __construct($pageCall, $pageParam) $this->lvTabs = []; } - public function display($override = '') + public function display(string $override = '') : void { if ($this->rss) // this should not be cached { - header('Content-Type: application/rss+xml; charset=UTF-8'); + header(MIME_TYPE_RSS); die($this->generateRSS()); } else - return parent::display($override); + parent::display($override); } protected function generateContent() diff --git a/pages/zone.php b/pages/zone.php index aed61db83..633f79a94 100644 --- a/pages/zone.php +++ b/pages/zone.php @@ -97,7 +97,7 @@ protected function generateContent() { foreach ($attmnt as $type => $ids) { - $this->extendGlobalIds($type, array_map('abs', $ids)); + $this->extendGlobalIds($type, ...array_map('abs', $ids)); foreach ($ids as $id) { if ($type == TYPE_ITEM) @@ -111,7 +111,7 @@ protected function generateContent() // Instances if ($_ = DB::Aowow()->selectCol('SELECT id FROM ?_zones WHERE parentAreaId = ?d AND (flags & ?d) = 0', $this->typeId, CUSTOM_EXCLUDE_FOR_LISTVIEW)) { - $this->extendGlobalIds(TYPE_ZONE, $_); + $this->extendGlobalIds(TYPE_ZONE, ...$_); $infobox[] = Lang::maps('Instances').Lang::main('colon')."\n[zone=".implode("], \n[zone=", $_).']'; } @@ -678,7 +678,7 @@ protected function generateContent() if ($a['racemask'] & (1 << $i)) $foo[] = $i + 1; - $this->extendGlobalIds(TYPE_RACE, $foo); + $this->extendGlobalIds(TYPE_RACE, ...$foo); $condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]]; } diff --git a/static/js/global.js b/static/js/global.js index 7af78310a..29f6c2bcc 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -17142,6 +17142,8 @@ var Menu = new function() $menuItems.each(function () { $innerDiv.append(this) }); $outerDiv.append($innerDiv); + $outerDiv.contextmenu($WH.rf); // aowow custom: prevent browser context menu when right clicking to get our context menu as it placed under the mouse cursor + return $outerDiv; } diff --git a/template/pages/detail-page-generic.tpl.php b/template/pages/detail-page-generic.tpl.php index 6d470d86e..c385b5c3c 100644 --- a/template/pages/detail-page-generic.tpl.php +++ b/template/pages/detail-page-generic.tpl.php @@ -44,6 +44,20 @@ echo "
\n ".$this->transfer."\n"; endif; +if (isset($this->smartAI)): +?> +
+ + +
+zoneMusic)): ?>