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
This commit is contained in:
Sarjuuk
2020-05-23 13:01:10 +02:00
parent b044488308
commit 6cabfd3864
38 changed files with 418 additions and 618 deletions

View File

@@ -10,7 +10,7 @@ class AjaxHandler
protected $params = []; protected $params = [];
protected $handler; protected $handler;
protected $contentType = 'application/x-javascript; charset=utf-8'; protected $contentType = MIME_TYPE_JSON;
protected $_post = []; protected $_post = [];
protected $_get = []; protected $_get = [];

View File

@@ -282,7 +282,7 @@ class AjaxComment extends AjaxHandler
protected function handleCommentOutOfDate() : string protected function handleCommentOutOfDate() : string
{ {
$this->contentType = 'text/plain'; $this->contentType = MIME_TYPE_TEXT;
if (!$this->_post['id']) if (!$this->_post['id'])
{ {
@@ -320,7 +320,7 @@ class AjaxComment extends AjaxHandler
protected function handleReplyAdd() : string protected function handleReplyAdd() : string
{ {
$this->contentType = 'text/plain'; $this->contentType = MIME_TYPE_TEXT;
if (!User::canComment()) if (!User::canComment())
return Lang::main('cannotComment'); return Lang::main('cannotComment');
@@ -343,7 +343,7 @@ class AjaxComment extends AjaxHandler
protected function handleReplyEdit() : string protected function handleReplyEdit() : string
{ {
$this->contentType = 'text/plain'; $this->contentType = MIME_TYPE_TEXT;
if (!User::canComment()) if (!User::canComment())
return Lang::main('cannotComment'); return Lang::main('cannotComment');

View File

@@ -217,7 +217,7 @@ class AjaxProfile extends AjaxHandler
return; return;
} }
$this->contentType = 'image/'.$matches[2]; $this->contentType = $matches[2] == 'png' ? MIME_TYPE_PNG : MIME_TYPE_JPEG;
$id = $matches[1]; $id = $matches[1];
$dest = imageCreateTruecolor($sizes[$s], $sizes[$s]); $dest = imageCreateTruecolor($sizes[$s], $sizes[$s]);

View File

@@ -557,6 +557,8 @@ trait spawnHelper
private function createShortSpawns() // [zoneId, floor, [[x1, y1], [x2, y2], ..]] as tooltip2 if enabled by <a rel="map" ...> or anchor #map (one area, one floor, one creature, no survivors) private function createShortSpawns() // [zoneId, floor, [[x1, y1], [x2, y2], ..]] as tooltip2 if enabled by <a rel="map" ...> 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 // 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)) 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 @@ trait spawnHelper
foreach ($points as $p) foreach ($points as $p)
$spawns[] = [$p['posX'], $p['posY']]; $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 @@ trait spawnHelper
switch ($mode) switch ($mode)
{ {
case SPAWNINFO_SHORT: case SPAWNINFO_SHORT:
if (empty($this->spawnResult[SPAWNINFO_SHORT])) if ($this->spawnResult[SPAWNINFO_SHORT] === null)
$this->createShortSpawns(); $this->createShortSpawns();
return $this->spawnResult[SPAWNINFO_SHORT]; return $this->spawnResult[SPAWNINFO_SHORT];

View File

@@ -7,7 +7,15 @@ if (!defined('AOWOW_REVISION'))
* Page * 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 // TypeIds
define('TYPE_NPC', 1); define('TYPE_NPC', 1);

View File

@@ -177,7 +177,7 @@ set_exception_handler(function ($ex)
); );
if (!CLI) if (!CLI)
(new GenericPage(null))->error(); (new GenericPage())->error();
else else
echo 'Exception - '.$ex->getMessage()."\n ".$ex->getFile(). '('.$ex->getLine().")\n".$ex->getTraceAsString()."\n"; echo 'Exception - '.$ex->getMessage()."\n ".$ex->getFile(). '('.$ex->getLine().")\n".$ex->getTraceAsString()."\n";
}); });
@@ -244,7 +244,7 @@ if (!CLI)
$str = explode('&', mb_strtolower($_SERVER['QUERY_STRING']), 2)[0]; $str = explode('&', mb_strtolower($_SERVER['QUERY_STRING']), 2)[0];
$_ = explode('=', $str, 2); $_ = explode('=', $str, 2);
$pageCall = $_[0]; $pageCall = $_[0];
$pageParam = isset($_[1]) ? $_[1] : null; $pageParam = isset($_[1]) ? $_[1] : '';
Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/'.$str; Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/'.$str;
} }

View File

@@ -27,7 +27,7 @@ class AreaTriggerList extends BaseType
$_curTpl['name'] = 'Unnamed Areatrigger #' . $id; $_curTpl['name'] = 'Unnamed Areatrigger #' . $id;
} }
public function getListviewData() public function getListviewData() : array
{ {
$data = []; $data = [];
@@ -46,7 +46,10 @@ class AreaTriggerList extends BaseType
return $data; return $data;
} }
public function getJSGlobals($addMask = GLOBALINFO_ANY) { } public function getJSGlobals($addMask = GLOBALINFO_ANY)
{
return [];
}
public function renderTooltip() { } public function renderTooltip() { }
} }

View File

@@ -852,8 +852,9 @@ class ItemList extends BaseType
if ($dur = $this->curTpl['durability']) if ($dur = $this->curTpl['durability'])
$x .= sprintf(Lang::item('durability'), $dur, $dur).'<br />'; $x .= sprintf(Lang::item('durability'), $dur, $dur).'<br />';
$jsg = [];
// required classes // required classes
if ($classes = Lang::getClassString($this->curTpl['requiredClass'], $jsg, $__)) if ($classes = Lang::getClassString($this->curTpl['requiredClass'], $jsg))
{ {
foreach ($jsg as $js) foreach ($jsg as $js)
if (empty($this->jsGlobals[TYPE_CLASS][$js])) if (empty($this->jsGlobals[TYPE_CLASS][$js]))
@@ -863,7 +864,7 @@ class ItemList extends BaseType
} }
// required races // required races
if ($races = Lang::getRaceString($this->curTpl['requiredRace'], $jsg, $__)) if ($races = Lang::getRaceString($this->curTpl['requiredRace'], $jsg))
{ {
foreach ($jsg as $js) foreach ($jsg as $js)
if (empty($this->jsGlobals[TYPE_RACE][$js])) if (empty($this->jsGlobals[TYPE_RACE][$js]))

View File

@@ -104,7 +104,7 @@ switch ($pageCall)
header('Location: '.$out, true, 302); header('Location: '.$out, true, 302);
else else
{ {
header('Content-type: '.$ajax->getContentType()); header($ajax->getContentType());
die($out); die($out);
} }
} }

View File

@@ -337,7 +337,7 @@ class Lang
return implode(', ', $tmp); 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.. $classMask &= CLASS_MASK_ALL; // clamp to available classes..
@@ -359,13 +359,12 @@ class Lang
$i++; $i++;
} }
$n = count($tmp);
$ids = array_keys($tmp); $ids = array_keys($tmp);
return implode(', ', $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.. $raceMask &= RACE_MASK_ALL; // clamp to available races..
@@ -396,7 +395,6 @@ class Lang
$i++; $i++;
} }
$n = count($tmp);
$ids = array_keys($tmp); $ids = array_keys($tmp);
return implode(', ', $tmp); return implode(', ', $tmp);

View File

@@ -32,6 +32,8 @@ class AchievementPage extends GenericPage
protected $tabId = 0; protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE; protected $mode = CACHE_TYPE_PAGE;
private $powerTpl = '$WowheadPower.registerAchievement(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
@@ -44,7 +46,7 @@ class AchievementPage extends GenericPage
$this->subject = new AchievementList(array(['id', $this->typeId])); $this->subject = new AchievementList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('achievement'), Lang::achievement('notFound'));
$this->extendGlobalData($this->subject->getJSGlobals(GLOBALINFO_REWARDS)); $this->extendGlobalData($this->subject->getJSGlobals(GLOBALINFO_REWARDS));
@@ -527,43 +529,17 @@ class AchievementPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerAchievement('.$this->typeId.', '.User::$localeId.', {});'; if (!$this->subject->error)
$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 = '')
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $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'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
private function createMail(&$reqCss = false) private function createMail(&$reqCss = false)

View File

@@ -29,7 +29,7 @@ class AreaTriggerPage extends GenericPage
$this->subject = new AreaTriggerList(array(['id', $this->typeId])); $this->subject = new AreaTriggerList(array(['id', $this->typeId]));
if ($this->subject->error) 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; $this->name = $this->subject->getField('name') ?: 'AT #'.$this->typeId;
} }
@@ -99,14 +99,13 @@ class AreaTriggerPage extends GenericPage
{ {
$sai = new SmartAI(SAI_SRC_TYPE_AREATRIGGER, $this->typeId, ['name' => $this->name, 'teleportA' => $this->subject->getField('teleportA')]); $sai = new SmartAI(SAI_SRC_TYPE_AREATRIGGER, $this->typeId, ['name' => $this->name, 'teleportA' => $this->subject->getField('teleportA')]);
if ($sai->prepare()) if ($sai->prepare())
foreach ($sai->getJSGlobals() as $type => $typeIds) $this->extendGlobalData($sai->getJSGlobals());
$this->extendGlobalIds($type, $typeIds);
} }
$this->map = $map; $this->map = $map;
$this->infobox = false; $this->infobox = false;
$this->extraText = $sai ? $sai->getMarkdown() : null; $this->smartAI = $sai ? $sai->getMarkdown() : null;
$this->redButtons = array( $this->redButtons = array(
BUTTON_LINKS => false, BUTTON_LINKS => false,
BUTTON_WOWHEAD => false BUTTON_WOWHEAD => false

View File

@@ -126,9 +126,9 @@ class ArenaTeamPage extends GenericPage
} }
} }
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) private function handleIncompleteData($teamGuid)

View File

@@ -17,6 +17,8 @@ class CurrencyPage extends GenericPage
protected $tabId = 0; protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE; protected $mode = CACHE_TYPE_PAGE;
private $powerTpl = '$WowheadPower.registerCurrency(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
@@ -29,7 +31,7 @@ class CurrencyPage extends GenericPage
$this->subject = new CurrencyList(array(['id', $this->typeId])); $this->subject = new CurrencyList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('currency'), Lang::currency('notFound'));
$this->name = $this->subject->getField('name', true); $this->name = $this->subject->getField('name', true);
} }
@@ -220,43 +222,17 @@ class CurrencyPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.', {});'; if (!$this->subject->error)
$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 = '')
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $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'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
} }

View File

@@ -25,7 +25,7 @@ class EmotePage extends GenericPage
$this->subject = new EmoteList(array(['id', $this->typeId])); $this->subject = new EmoteList(array(['id', $this->typeId]));
if ($this->subject->error) 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')); $this->name = Util::ucFirst($this->subject->getField('cmd'));
} }

View File

@@ -25,7 +25,7 @@ class EnchantmentPage extends GenericPage
$this->subject = new EnchantmentList(array(['id', $this->typeId])); $this->subject = new EnchantmentList(array(['id', $this->typeId]));
if ($this->subject->error) 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()); $this->extendGlobalData($this->subject->getJSGlobals());

View File

@@ -25,7 +25,7 @@ class EnchantmentsPage extends GenericPage
parent::__construct($pageCall, $pageParam); parent::__construct($pageCall, $pageParam);
$this->name = Util::ucFirst(Lang::game('enchantments')); $this->name = Util::ucFirst(Lang::game('enchantments'));
$this->subCat = $pageParam !== null ? '='.$pageParam : ''; $this->subCat = $pageParam !== '' ? '='.$pageParam : '';
} }
protected function generateContent() protected function generateContent()
@@ -100,8 +100,8 @@ class EnchantmentsPage extends GenericPage
protected function generatePath() protected function generatePath()
{ {
$form = $this->filterObj->getForm('form'); $form = $this->filterObj->getForm('form');
if (isset($form['ty']) && !is_array($form['ty'])) if (isset($form['ty']) && count($form['ty']) == 1)
$this->path[] = $form['ty']; $this->path[] = $form['ty'][0];
} }
} }

View File

@@ -17,6 +17,7 @@ class EventPage extends GenericPage
protected $tabId = 0; protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE; protected $mode = CACHE_TYPE_PAGE;
private $powerTpl = '$WowheadPower.registerHoliday(%d, %d, %s);';
private $hId = 0; private $hId = 0;
private $eId = 0; private $eId = 0;
@@ -32,7 +33,7 @@ class EventPage extends GenericPage
$this->subject = new WorldEventList(array(['id', $this->typeId])); $this->subject = new WorldEventList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('event'), Lang::event('notFound'));
$this->hId = $this->subject->getField('holidayId'); $this->hId = $this->subject->getField('holidayId');
$this->eId = $this->typeId; $this->eId = $this->typeId;
@@ -266,6 +267,22 @@ class EventPage extends GenericPage
} }
} }
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() protected function postCache()
{ {
// update dates to now() // update dates to now()
@@ -326,50 +343,6 @@ class EventPage extends GenericPage
} }
} }
} }
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();
}
} }
?> ?>

View File

@@ -58,7 +58,7 @@ class FactionPage extends GenericPage
// Quartermaster if any // Quartermaster if any
if ($ids = $this->subject->getField('qmNpcIds')) if ($ids = $this->subject->getField('qmNpcIds'))
{ {
$this->extendGlobalIds(TYPE_NPC, $ids); $this->extendGlobalIds(TYPE_NPC, ...$ids);
$qmStr = Lang::faction('quartermaster').Lang::main('colon'); $qmStr = Lang::faction('quartermaster').Lang::main('colon');

View File

@@ -18,7 +18,7 @@ trait TrDetailPage
protected $contribute = CONTRIBUTE_ANY; protected $contribute = CONTRIBUTE_ANY;
protected function generateCacheKey($withStaff = true) protected function generateCacheKey(bool $withStaff = true) : string
{ {
$staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE));
@@ -32,7 +32,7 @@ trait TrDetailPage
return implode('_', $key); return implode('_', $key);
} }
protected function applyCCErrors() protected function applyCCErrors() : void
{ {
if (!empty($_SESSION['error']['co'])) if (!empty($_SESSION['error']['co']))
$this->coError = $_SESSION['error']['co']; $this->coError = $_SESSION['error']['co'];
@@ -56,7 +56,7 @@ trait TrListPage
private $filterObj = null; private $filterObj = null;
protected function generateCacheKey($withStaff = true) protected function generateCacheKey(bool $withStaff = true) : string
{ {
$staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE));
@@ -73,6 +73,7 @@ trait TrListPage
} }
} }
trait TrProfiler trait TrProfiler
{ {
protected $region = ''; protected $region = '';
@@ -85,7 +86,7 @@ trait TrProfiler
protected $doResync = null; protected $doResync = null;
protected function generateCacheKey($withStaff = true) protected function generateCacheKey(bool $withStaff = true) : string
{ {
$staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE)); $staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE));
@@ -95,15 +96,15 @@ trait TrProfiler
return implode('_', $key); return implode('_', $key);
} }
protected function getSubjectFromUrl($str) protected function getSubjectFromUrl(string $pageParam) : void
{ {
if (!$str) if (!$pageParam)
return; return;
// cat[0] is always region // cat[0] is always region
// cat[1] is realm or bGroup (must be realm if cat[2] is set) // cat[1] is realm or bGroup (must be realm if cat[2] is set)
// cat[2] is arena-team, guild or player // cat[2] is arena-team, guild or player
$cat = explode('.', $str, 3); $cat = explode('.', $pageParam, 3);
$cat = array_map('urldecode', $cat); $cat = array_map('urldecode', $cat);
@@ -131,7 +132,7 @@ trait TrProfiler
} }
} }
protected function initialSync() protected function initialSync() : void
{ {
$this->prepareContent(); $this->prepareContent();
@@ -150,7 +151,7 @@ trait TrProfiler
exit(); exit();
} }
protected function generatePath() protected function generatePath() : void
{ {
if ($this->region) if ($this->region)
{ {
@@ -164,6 +165,7 @@ trait TrProfiler
} }
} }
class GenericPage class GenericPage
{ {
protected $tpl = ''; protected $tpl = '';
@@ -232,7 +234,7 @@ class GenericPage
'zone' => ['template' => 'zone', 'id' => 'zones', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_zones' ] '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); $this->time = microtime(true);
@@ -296,11 +298,13 @@ class GenericPage
$this->applyCCErrors(); $this->applyCCErrors();
} }
/**********/ /**********/
/* Checks */ /* 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))) if (preg_match('/[^\w\-]/i', str_replace('admin/', '', $file)))
return false; return false;
@@ -311,7 +315,8 @@ class GenericPage
return true; 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)) if (!isset($this->category) || empty($this->validCats))
return true; return true;
@@ -341,11 +346,13 @@ class GenericPage
return false; return false;
} }
/****************/ /****************/
/* Prepare Page */ /* Prepare Page */
/****************/ /****************/
protected function prepareContent() // get from cache ?: run generators // get from cache ?: run generators
protected function prepareContent() : void
{ {
if (!$this->loadCache()) if (!$this->loadCache())
{ {
@@ -404,7 +411,7 @@ class GenericPage
$this->sumSQLStats(); $this->sumSQLStats();
} }
public function addJS($name, $unshift = false) public function addJS($name, bool $unshift = false) : void
{ {
if (is_array($name)) if (is_array($name))
{ {
@@ -420,7 +427,7 @@ class GenericPage
} }
} }
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'])) if (is_array($struct) && empty($struct['path']) && empty($struct['string']))
{ {
@@ -436,7 +443,8 @@ class GenericPage
} }
} }
private function addArticle() // get article & static infobox (run before processing jsGlobals) // get article & static infobox (run before processing jsGlobals)
private function addArticle() :void
{ {
$article = []; $article = [];
if (!empty($this->type) && isset($this->typeId)) if (!empty($this->type) && isset($this->typeId))
@@ -492,7 +500,8 @@ class GenericPage
} }
} }
private function addAnnouncements() // get announcements and notes for user // get announcements and notes for user
private function addAnnouncements() : void
{ {
if (!isset($this->announcements)) if (!isset($this->announcements))
$this->announcements = []; $this->announcements = [];
@@ -539,9 +548,9 @@ class GenericPage
} }
} }
protected function getCategoryFromUrl($str) protected function getCategoryFromUrl(string $urlParam) : void
{ {
$arr = explode('.', $str); $arr = explode('.', $urlParam);
$params = []; $params = [];
foreach ($arr as $v) foreach ($arr as $v)
@@ -551,43 +560,61 @@ class GenericPage
$this->category = $params; $this->category = $params;
} }
protected function forwardToSignIn($next = '') protected function forwardToSignIn(string $next = '') : void
{ {
$next = $next ? '&next='.$next : ''; $next = $next ? '&next='.$next : '';
header('Location: ?account=signin'.$next, true, 302); header('Location: ?account=signin'.$next, true, 302);
} }
protected function sumSQLStats() protected function sumSQLStats() : void
{ {
Util::arraySumByKey($this->mysql, DB::Aowow()->getStatistics(), DB::World()->getStatistics()); Util::arraySumByKey($this->mysql, DB::Aowow()->getStatistics(), DB::World()->getStatistics());
} }
/*******************/ /*******************/
/* Special Display */ /* 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'));
$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 (isset($this->tabId))
$this->pageTemplate['activeTab'] = $this->tabId;
$this->sumSQLStats();
header('HTTP/1.0 404 Not Found', true, 404); header('HTTP/1.0 404 Not Found', true, 404);
$this->display('list-page-generic'); 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'));
$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 (isset($this->tabId))
$this->pageTemplate['activeTab'] = $this->tabId;
$this->sumSQLStats();
$this->display('list-page-generic');
}
exit(); exit();
} }
public function error() // unknown page // unknown page
public function error() : void
{ {
$this->path = null; $this->path = null;
$this->tabId = null; $this->tabId = null;
@@ -606,7 +633,8 @@ class GenericPage
exit(); 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('HTTP/1.0 503 Service Temporarily Unavailable', true, 503);
header('Retry-After: '.(3 * HOUR)); header('Retry-After: '.(3 * HOUR));
@@ -615,46 +643,74 @@ class GenericPage
exit(); exit();
} }
/*******************/ /*******************/
/* General Display */ /* 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 // 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. // re-requesting them from the server but load them from local cache, thus breaking menu features.
Util::sendNoCacheHeader(); Util::sendNoCacheHeader();
if (isset($this->tabId)) if ($this->mode == CACHE_TYPE_TOOLTIP && method_exists($this, 'generateTooltip'))
$this->pageTemplate['activeTab'] = $this->tabId; $this->displayExtra([$this, 'generateTooltip']);
else if ($this->mode == CACHE_TYPE_XML && method_exists($this, 'generateXML'))
if ($override) $this->displayExtra([$this, 'generateXML'], MIME_TYPE_XML);
{
$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();
include('template/pages/'.$this->tpl.'.tpl.php');
die();
}
else else
$this->error(); {
if (isset($this->tabId))
$this->pageTemplate['activeTab'] = $this->tabId;
if ($override)
{
$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();
include('template/pages/'.$this->tpl.'.tpl.php');
die();
}
else
$this->error();
}
} }
public function writeGlobalVars() // load jsGlobal // 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
die($outString);
}
// load jsGlobal
public function writeGlobalVars() : string
{ {
$buff = ''; $buff = '';
@@ -700,7 +756,8 @@ class GenericPage
return $buff; 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) foreach ($localVars as $n => $v)
$$n = $v; $$n = $v;
@@ -711,7 +768,8 @@ class GenericPage
include('template/bricks/'.$file.'.tpl.php'); 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)) if (!$this->isSaneInclude('template/listviews/', $file))
trigger_error('Nonexistant Listview addin requested: template/listviews/'.$file.'.tpl.php', E_USER_ERROR); trigger_error('Nonexistant Listview addin requested: template/listviews/'.$file.'.tpl.php', E_USER_ERROR);
@@ -719,7 +777,8 @@ class GenericPage
include('template/listviews/'.$file.'.tpl.php'); 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)) if (!$this->isSaneInclude('template/localized/', $file.'_'.$loc))
{ {
@@ -732,32 +791,27 @@ class GenericPage
include('template/localized/'.$file.'_'.$loc.'.tpl.php'); include('template/localized/'.$file.'_'.$loc.'.tpl.php');
} }
/**********************/ /**********************/
/* Prepare js-Globals */ /* Prepare js-Globals */
/**********************/ /**********************/
public function extendGlobalIds($type, $data) // add typeIds <int|array[int]> that should be displayed as jsGlobal on the page // add typeIds <int|array[int]> that should be displayed as jsGlobal on the page
public function extendGlobalIds(int $type, int ...$ids) : void
{ {
if (!$type || !$data) if (!$type || !$ids)
return false; return;
if (!isset($this->jsgBuffer[$type])) if (!isset($this->jsgBuffer[$type]))
$this->jsgBuffer[$type] = []; $this->jsgBuffer[$type] = [];
if (is_array($data)) foreach ($ids as $id)
{ $this->jsgBuffer[$type][] = $id;
foreach ($data as $id)
$this->jsgBuffer[$type][] = (int)$id;
}
else if (is_numeric($data))
$this->jsgBuffer[$type][] = (int)$data;
} }
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) foreach ($data as $type => $globals)
{ {
if (!is_array($globals) || !$globals) if (!is_array($globals) || !$globals)
@@ -781,7 +835,8 @@ class GenericPage
$this->jsGlobals[$type][2] = $extra; $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 $jsg = &$this->jsGlobals; // shortcut
@@ -815,7 +870,8 @@ class GenericPage
} }
} }
private function applyGlobals() // lookup jsGlobals from collected typeIds // lookup jsGlobals from collected typeIds
private function applyGlobals() : void
{ {
foreach ($this->jsgBuffer as $type => $ids) foreach ($this->jsgBuffer as $type => $ids)
{ {
@@ -864,14 +920,16 @@ class GenericPage
} }
} }
/*********/ /*********/
/* Cache */ /* 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) if ($this->mode == CACHE_TYPE_NONE)
return false; return;
if (!CFG_CACHE_MODE || CFG_DEBUG) if (!CFG_CACHE_MODE || CFG_DEBUG)
return; return;
@@ -894,7 +952,7 @@ class GenericPage
} }
} }
else else
$cache = (string)$saveString; $cache = $saveString;
if (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED) if (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED)
{ {
@@ -949,7 +1007,7 @@ class GenericPage
} }
} }
public function loadCache(&$saveString = null) private function loadCache(string &$saveString = '') : bool
{ {
if ($this->mode == CACHE_TYPE_NONE) if ($this->mode == CACHE_TYPE_NONE)
return false; return false;
@@ -1021,7 +1079,7 @@ class GenericPage
return false;; return false;;
} }
private function memcached() private function memcached() : Memcached
{ {
if (!$this->memcached && (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED)) if (!$this->memcached && (CFG_CACHE_MODE & CACHE_MODE_MEMCACHED))
{ {

View File

@@ -130,9 +130,9 @@ class GuildPage extends GenericPage
} }
} }
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) private function handleIncompleteData($teamGuid)

View File

@@ -25,7 +25,7 @@ class IconPage extends GenericPage
$this->subject = new IconList(array(['id', $this->typeId])); $this->subject = new IconList(array(['id', $this->typeId]));
if ($this->subject->error) 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()); $this->extendGlobalData($this->subject->getJSGlobals());

View File

@@ -23,6 +23,8 @@ class ItemPage extends genericPage
'filters.js' // lolwut? 'filters.js' // lolwut?
); );
private $powerTpl = '$WowheadPower.registerItem(%s, %d, %s);';
public function __construct($pageCall, $param) public function __construct($pageCall, $param)
{ {
parent::__construct($pageCall, $param); parent::__construct($pageCall, $param);
@@ -59,7 +61,7 @@ class ItemPage extends genericPage
$this->subject = new ItemList($conditions); $this->subject = new ItemList($conditions);
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('item'), Lang::item('notFound'));
if (!is_numeric($param)) if (!is_numeric($param))
$this->typeId = $this->subject->id; $this->typeId = $this->subject->id;
@@ -1009,30 +1011,33 @@ class ItemPage extends genericPage
// name: LANG.tab_taughtby // name: LANG.tab_taughtby
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
$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);
}
$itemString = $this->typeId; $itemString = $this->typeId;
foreach ($this->enhancedTT as $k => $val) if ($this->enhancedTT)
$itemString .= $k.(is_array($val) ? implode(',', $val) : $val); {
foreach ($this->enhancedTT as $k => $val)
$itemString .= $k.(is_array($val) ? implode(',', $val) : $val);
$itemString = "'".$itemString."'";
}
if ($asError) return sprintf($this->powerTpl, $itemString, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
return '$WowheadPower.registerItem(\''.$itemString.'\', '.User::$localeId.', {})';
$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 .= "});";
return $x;
} }
protected function generateXML($asError = false) protected function generateXML()
{ {
$root = new SimpleXML('<aowow />'); $root = new SimpleXML('<aowow />');
if ($asError) if ($this->subject->error)
$root->addChild('error', 'Item not found!'); $root->addChild('error', 'Item not found!');
else else
{ {
@@ -1173,52 +1178,6 @@ class ItemPage extends genericPage
return $root->asXML(); 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'));
}
} }
?> ?>

View File

@@ -88,7 +88,7 @@ class ItemsPage extends GenericPage
parent::__construct($pageCall, $pageParam); parent::__construct($pageCall, $pageParam);
$this->name = Util::ucFirst(Lang::game('items')); $this->name = Util::ucFirst(Lang::game('items'));
$this->subCat = $pageParam !== null ? '='.$pageParam : ''; $this->subCat = $pageParam !== '' ? '='.$pageParam : '';
} }
protected function generateContent() protected function generateContent()

View File

@@ -21,6 +21,8 @@ class ItemsetPage extends GenericPage
'Summary.js' 'Summary.js'
); );
private $powerTpl = '$WowheadPower.registerItemSet(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
@@ -33,7 +35,7 @@ class ItemsetPage extends GenericPage
$this->subject = new ItemsetList(array(['id', $this->typeId])); $this->subject = new ItemsetList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('itemset'), Lang::itemset('notFound'));
$this->name = $this->subject->getField('name', true); $this->name = $this->subject->getField('name', true);
$this->extendGlobalData($this->subject->getJSGlobals()); $this->extendGlobalData($this->subject->getJSGlobals());
@@ -92,10 +94,11 @@ class ItemsetPage extends GenericPage
} }
// class // 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); $this->extendGlobalIds(TYPE_CLASS, ...$jsg);
$t = $qty == 1 ? Lang::game('class') : Lang::game('classes'); $t = count($jsg)== 1 ? Lang::game('class') : Lang::game('classes');
$infobox[] = Util::ucFirst($t).Lang::main('colon').$cl; $infobox[] = Util::ucFirst($t).Lang::main('colon').$cl;
} }
@@ -229,42 +232,16 @@ class ItemsetPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerItemSet('.$this->typeId.', '.User::$localeId.', {});'; if (!$this->subject->error)
$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 = '')
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
} }
header('Content-type: application/x-javascript; charset=utf-8'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
} }

View File

@@ -55,10 +55,11 @@ class MailPage extends GenericPage
if ($mlr['level']) if ($mlr['level'])
$infobox[] = Lang::game('level').Lang::main('colon').$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; $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'].']'; $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$mlr['senderEntry'].']';

View File

@@ -19,6 +19,7 @@ class NpcPage extends GenericPage
protected $js = ['swfobject.js']; protected $js = ['swfobject.js'];
private $soundIds = []; private $soundIds = [];
private $powerTpl = '$WowheadPower.registerNpc(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
@@ -32,7 +33,7 @@ class NpcPage extends GenericPage
$this->subject = new CreatureList(array(['id', $this->typeId])); $this->subject = new CreatureList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('npc'), Lang::npc('notFound'));
$this->name = Util::htmlEscape($this->subject->getField('name', true)); $this->name = Util::htmlEscape($this->subject->getField('name', true));
$this->subname = $this->subject->getField('subname', true); $this->subname = $this->subject->getField('subname', true);
@@ -335,10 +336,7 @@ class NpcPage extends GenericPage
} }
if ($sai->prepare()) if ($sai->prepare())
{ $this->extendGlobalData($sai->getJSGlobals());
foreach ($sai->getJSGlobals() as $type => $typeIds)
$this->extendGlobalIds($type, $typeIds);
}
else else
trigger_error('Creature has SmartAI set in template but no SmartAI defined.'); trigger_error('Creature has SmartAI set in template but no SmartAI defined.');
} }
@@ -841,45 +839,17 @@ class NpcPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerNpc('.$this->typeId.', '.User::$localeId.', {})'; if (!$this->subject->error)
$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))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
$power->map = $this->subject->getSpawns(SPAWNINFO_SHORT);
} }
header('Content-type: application/x-javascript; charset=utf-8'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
private function getRepForId($entries, &$spillover) private function getRepForId($entries, &$spillover)

View File

@@ -18,6 +18,8 @@ class ObjectPage extends GenericPage
protected $mode = CACHE_TYPE_PAGE; protected $mode = CACHE_TYPE_PAGE;
protected $js = ['swfobject.js']; protected $js = ['swfobject.js'];
private $powerTpl = '$WowheadPower.registerObject(%d, %d, %s);'
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
@@ -30,7 +32,7 @@ class ObjectPage extends GenericPage
$this->subject = new GameObjectList(array(['id', $this->typeId])); $this->subject = new GameObjectList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('object'), Lang::gameObject('notFound'));
$this->name = $this->subject->getField('name', true); $this->name = $this->subject->getField('name', true);
} }
@@ -248,10 +250,7 @@ class ObjectPage extends GenericPage
} }
if ($sai->prepare()) if ($sai->prepare())
{ $this->extendGlobalData($sai->getJSGlobals());
foreach ($sai->getJSGlobals() as $type => $typeIds)
$this->extendGlobalIds($type, $typeIds);
}
else else
trigger_error('Gameobject has AIName set in template but no SmartAI defined.'); trigger_error('Gameobject has AIName set in template but no SmartAI defined.');
} }
@@ -481,45 +480,17 @@ class ObjectPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerObject('.$this->typeId.', '.User::$localeId.', {});'; if (!$this->subject->error)
$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 = '')
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
$power->map = $this->subject->getSpawns(SPAWNINFO_SHORT);
} }
header('Content-type: application/x-javascript; charset=utf-8'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
} }

View File

@@ -27,6 +27,7 @@ class ProfilePage extends GenericPage
private $isCustom = false; private $isCustom = false;
private $profile = null; private $profile = null;
private $rnItr = 0; private $rnItr = 0;
private $powerTpl = '$WowheadPower.registerProfile(%s, %d, %s);';
public function __construct($pageCall, $pageParam) public function __construct($pageCall, $pageParam)
{ {
@@ -50,6 +51,7 @@ class ProfilePage extends GenericPage
// redundancy much? // redundancy much?
$this->subjectGUID = intval($params[0]); $this->subjectGUID = intval($params[0]);
$this->profile = intval($params[0]); $this->profile = intval($params[0]);
$this->isCustom = true; // until proven otherwise
$this->subject = new LocalProfileList(array(['id', intval($params[0])])); $this->subject = new LocalProfileList(array(['id', intval($params[0])]));
if ($this->subject->error) if ($this->subject->error)
@@ -58,9 +60,7 @@ class ProfilePage extends GenericPage
if (!$this->subject->isVisibleToUser()) if (!$this->subject->isVisibleToUser())
$this->notFound(); $this->notFound();
if ($this->subject->isCustom()) if (!$this->subject->isCustom())
$this->isCustom = true;
else
header('Location: '.$this->subject->getProfileUrl(), true, 302); header('Location: '.$this->subject->getProfileUrl(), true, 302);
} }
else if (count($params) == 3) else if (count($params) == 3)
@@ -154,7 +154,7 @@ class ProfilePage extends GenericPage
/* Anub, Faerlina, Maexxna, Noth, Heigan, Loatheb, Razuvious, Gothik, Patchwerk, Grobbulus, Gluth, Thaddius, Sapphiron, Kel'Thuzad */ /* 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 /* 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 // dummy title from dungeon encounter
foreach (Lang::profiler('encounterNames') as $id => $name) foreach (Lang::profiler('encounterNames') as $id => $name)
@@ -171,59 +171,48 @@ class ProfilePage extends GenericPage
array_unshift($this->title, Util::ucFirst(Lang::game('profile'))); array_unshift($this->title, Util::ucFirst(Lang::game('profile')));
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
$id = $this->profile; $id = $this->profile;
if (!$this->isCustom) if (!$this->isCustom)
$id = "'".$this->profile[0].'.'.$this->profile[1].'.'.urlencode($this->profile[2])."'"; $id = "'".$this->profile[0].'.'.$this->profile[1].'.'.urlencode($this->profile[2])."'";
$x = '$WowheadPower.registerProfile('.$id.', '.User::$localeId.', {'; $power = new StdClass();
if ($asError) if ($this->subject && !$this->subject->error && $this->subject->isVisibleToUser())
return $x."});"; {
$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');
$name = $this->subject->getField('name'); if ($this->isCustom)
$guild = $this->subject->getField('guild'); $n .= Lang::profiler('customProfile');
$guildRank = $this->subject->getField('guildrank'); else if ($_ = $this->subject->getField('title'))
$lvl = $this->subject->getField('level'); if ($title = (new TitleList(array(['id', $_])))->getField($g ? 'female' : 'male', true))
$ra = $this->subject->getField('race'); $n = sprintf($title, $n);
$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) $power->{'name_'.User::$localeString} = $n;
$name .= Lang::profiler('customProfile'); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
else if ($title) $power->icon = '$$WH.g_getProfileIcon('.$r.', '.$c.', '.$g.', '.$l.', \''.$this->subject->getIcon().'\')';
$name = sprintf($title, $name); }
$x .= "\n"; return sprintf($this->powerTpl, $id, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
$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;
} }
public function display($override = '') public function display(string $override = ''): void
{ {
if ($this->mode != CACHE_TYPE_TOOLTIP) if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override); parent::display($override);
// do not cache profile tooltips // do not cache profile tooltips
header('Content-type: application/x-javascript; charset=utf-8'); header(MIME_TYPE_JSON);
die($this->generateTooltip()); die($this->generateTooltip());
} }
public function notFound($title = '', $msg = '') public function notFound(string $title = '', string $msg = '') : void
{ {
if ($this->mode != CACHE_TYPE_TOOLTIP) parent::notFound($title ?: Util::ucFirst(Lang::profiler('profiler')), $msg ?: Lang::profiler('notFound', 'profile'));
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();
} }
private function handleIncompleteData($params, $guid) private function handleIncompleteData($params, $guid)

View File

@@ -19,6 +19,8 @@ class QuestPage extends GenericPage
protected $css = [['path' => 'Book.css']]; protected $css = [['path' => 'Book.css']];
protected $js = ['ShowOnMap.js']; protected $js = ['ShowOnMap.js'];
private $powerTpl = '$WowheadPower.registerQuest(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
@@ -31,7 +33,7 @@ class QuestPage extends GenericPage
$this->subject = new QuestList(array(['id', $this->typeId])); $this->subject = new QuestList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('quest'), Lang::quest('notFound'));
// may contain htmlesque tags // may contain htmlesque tags
$this->name = Util::htmlEscape($this->subject->getField('name', true)); $this->name = Util::htmlEscape($this->subject->getField('name', true));
@@ -138,19 +140,20 @@ class QuestPage extends GenericPage
case 1: $infobox[] = $_.'[span class=icon-alliance]'.Lang::game('si', 1).'[/span]'; break; case 1: $infobox[] = $_.'[span class=icon-alliance]'.Lang::game('si', 1).'[/span]'; break;
} }
$jsg = [];
// races // 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); $this->extendGlobalIds(TYPE_RACE, ...$jsg);
$t = $n == 1 ? Lang::game('race') : Lang::game('races'); $t = count($jsg) == 1 ? Lang::game('race') : Lang::game('races');
$infobox[] = Util::ucFirst($t).Lang::main('colon').$_; $infobox[] = Util::ucFirst($t).Lang::main('colon').$_;
} }
// classes // 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); $this->extendGlobalIds(TYPE_CLASS, ...$jsg);
$t = $n == 1 ? Lang::game('class') : Lang::game('classes'); $t = count($jsg) == 1 ? Lang::game('class') : Lang::game('classes');
$infobox[] = Util::ucFirst($t).Lang::main('colon').$_; $infobox[] = Util::ucFirst($t).Lang::main('colon').$_;
} }
@@ -1015,44 +1018,18 @@ class QuestPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
return '$WowheadPower.registerQuest('.$this->typeId.', '.User::$localeId.', {});'; if (!$this->subject->error)
$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 = '')
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{ {
$tt = $this->generateTooltip(); $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
$this->saveCache($tt); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
if ($this->subject->isDaily())
$power->daily = 1;
} }
header('Content-type: application/x-javascript; charset=utf-8'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
private function createRewards($side) private function createRewards($side)

View File

@@ -206,7 +206,7 @@ class SearchPage extends GenericPage
$this->performSearch(); $this->performSearch();
} }
public function notFound($title = '', $msg = '') public function notFound(string $title = '', string $msg = '') : void
{ {
if ($this->searchMask & SEARCH_TYPE_REGULAR) if ($this->searchMask & SEARCH_TYPE_REGULAR)
{ {
@@ -220,80 +220,53 @@ class SearchPage extends GenericPage
parent::display(); // errors are handled in the search-template itself parent::display(); // errors are handled in the search-template itself
} }
else if ($this->searchMask & SEARCH_TYPE_OPEN) else if ($this->searchMask & SEARCH_TYPE_OPEN)
$result = $this->generateOpenSearch(true); $result = [$this->search, []];
else /* if ($this->searchMask & SEARCH_TYPE_JSON) */ else if ($this->searchMask & SEARCH_TYPE_JSON)
$result = $this->generateJsonSearch(true); $result = [$this->search, [], []];
header("Content-type: application/x-javascript"); header(MIME_TYPE_JSON);
exit($result); exit(Util::toJSON($result));
} }
public function display($override = '') public function display(string $override = '') : void
{ {
if ($override || ($this->searchMask & SEARCH_TYPE_REGULAR)) if ($override || ($this->searchMask & SEARCH_TYPE_REGULAR))
return parent::display($override); parent::display($override);
else if ($this->searchMask & SEARCH_TYPE_OPEN) else if ($this->searchMask & SEARCH_TYPE_OPEN)
{ $this->displayExtra([$this, 'generateOpenSearch']);
if (!$this->loadCache($open)) else if ($this->searchMask & SEARCH_TYPE_JSON)
{ $this->displayExtra([$this, 'generateJsonSearch']);
$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);
}
} }
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 = ''; $outItems = [];
$outSets = ''; $outSets = [];
if (!$asError) $this->performSearch();
// 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']))
{ {
// items foreach ($this->lvTabs[5][1]['data'] as $k => $v)
if (!empty($this->lvTabs[6][1]['data']))
{ {
$items = []; unset($v['quality']);
foreach ($this->lvTabs[6][1]['data'] as $k => $v) if (!$v['heroic'])
$items[] = Util::toJSON($v); unset($v['heroic']);
$outItems = "\t".implode(",\n\t", $items)."\n"; $outSets[] = $v;
}
// item sets
if (!empty($this->lvTabs[5][1]['data']))
{
$sets = [];
foreach ($this->lvTabs[5][1]['data'] as $k => $v)
{
unset($v['quality']);
if (!$v['heroic'])
unset($v['heroic']);
$sets[] = Util::toJSON($v);
}
$outSets = "\t".implode(",\n\t", $sets)."\n";
} }
} }
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 // this one is funny: we want 10 results, ideally equally distributed over each type
$foundTotal = 0; $foundTotal = 0;
@@ -303,11 +276,13 @@ class SearchPage extends GenericPage
[], [], [], [], [], [], [] [], [], [], [], [], [], []
); );
$this->performSearch();
foreach ($this->lvTabs as [ , , , $osInfo]) foreach ($this->lvTabs as [ , , , $osInfo])
$foundTotal += $osInfo[2]; $foundTotal += $osInfo[2];
if (!$foundTotal || $asError) if (!$foundTotal)
return '["'.Util::jsEscape($this->search).'", []]'; return Util::toJSON([$this->search, []]);
foreach ($this->lvTabs as [ , $tabData, , $osInfo]) foreach ($this->lvTabs as [ , $tabData, , $osInfo])
{ {

View File

@@ -20,6 +20,7 @@ class SpellPage extends GenericPage
private $difficulties = []; private $difficulties = [];
private $firstRank = 0; private $firstRank = 0;
private $powerTpl = '$WowheadPower.registerSpell(%d, %d, %s);';
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
@@ -33,7 +34,7 @@ class SpellPage extends GenericPage
$this->subject = new SpellList(array(['id', $this->typeId])); $this->subject = new SpellList(array(['id', $this->typeId]));
if ($this->subject->error) if ($this->subject->error)
$this->notFound(); $this->notFound(Lang::game('spell'), Lang::spell('notFound'));
$jsg = $this->subject->getJSGlobals(GLOBALINFO_ANY, $extra); $jsg = $this->subject->getJSGlobals(GLOBALINFO_ANY, $extra);
$this->extendGlobalData($jsg, $extra); $this->extendGlobalData($jsg, $extra);
@@ -158,19 +159,20 @@ class SpellPage extends GenericPage
$infobox[] = (in_array($_cat, [-2, 7, -13]) ? sprintf(Lang::game('reqLevel'), $_) : Lang::game('level').Lang::main('colon').$_); $infobox[] = (in_array($_cat, [-2, 7, -13]) ? sprintf(Lang::game('reqLevel'), $_) : Lang::game('level').Lang::main('colon').$_);
} }
$jsg = [];
// races // 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); $this->extendGlobalIds(TYPE_RACE, ...$jsg);
$t = $n == 1 ? Lang::game('race') : Lang::game('races'); $t = count($jsg) == 1 ? Lang::game('race') : Lang::game('races');
$infobox[] = Util::ucFirst($t).Lang::main('colon').$_; $infobox[] = Util::ucFirst($t).Lang::main('colon').$_;
} }
// classes // 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); $this->extendGlobalIds(TYPE_CLASS, ...$jsg);
$t = $n == 1 ? Lang::game('class') : Lang::game('classes'); $t = count($jsg) == 1 ? Lang::game('class') : Lang::game('classes');
$infobox[] = Util::ucFirst($t).Lang::main('colon').$_; $infobox[] = Util::ucFirst($t).Lang::main('colon').$_;
} }
@@ -923,7 +925,7 @@ class SpellPage extends GenericPage
if ($a['racemask'] & (1 << $i)) if ($a['racemask'] & (1 << $i))
$foo[] = $i + 1; $foo[] = $i + 1;
$this->extendGlobalIds(TYPE_RACE, $foo); $this->extendGlobalIds(TYPE_RACE, ...$foo);
$condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]]; $condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]];
} }
@@ -1193,55 +1195,23 @@ class SpellPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip()
{ {
if ($asError) $power = new StdClass();
die('$WowheadPower.registerSpell('.$this->typeId.', '.User::$localeId.', {});'); if (!$this->subject->error)
$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())
{ {
$pt[] = "\ttooltip_".User::$localeString.": '".Util::jsEscape($tt[0])."'"; [$tooltip, $ttSpells] = $this->subject->renderTooltip();
$pt[] = "\tspells_".User::$localeString.": ".Util::toJSON($tt[1]); [$buff, $bfSpells] = $this->subject->renderBuff();
}
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; $power->{'name_'.User::$localeString} = $this->subject->getField('name', true);
} $power->icon = rawurlencode($this->subject->getField('iconString', true, true));
$power->{'tooltip_'.User::$localeString} = $tooltip;
public function display($override = '') $power->{'spells_'.User::$localeString} = $ttSpells;
{ $power->{'buff_'.User::$localeString} = $buff;
if ($this->mode != CACHE_TYPE_TOOLTIP) $power->{'buffspells_'.User::$localeString} = $bfSpells;
return parent::display($override);
if (!$this->loadCache($tt))
{
$tt = $this->generateTooltip();
$this->saveCache($tt);
} }
header('Content-type: application/x-javascript; charset=utf-8'); return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER));
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();
} }
private function appendReagentItem(&$reagentResult, $_iId, $_qty, $_mult, $_level, $_path, $alreadyUsed) private function appendReagentItem(&$reagentResult, $_iId, $_qty, $_mult, $_level, $_path, $alreadyUsed)

View File

@@ -91,7 +91,7 @@ class SpellsPage extends GenericPage
parent::__construct($pageCall, $pageParam); parent::__construct($pageCall, $pageParam);
$this->name = Util::ucFirst(Lang::game('spells')); $this->name = Util::ucFirst(Lang::game('spells'));
$this->subCat = $pageParam !== null ? '='.$pageParam : ''; $this->subCat = $pageParam !== '' ? '='.$pageParam : '';
$this->classPanel = false; $this->classPanel = false;
$this->glyphPanel = false; $this->glyphPanel = false;

View File

@@ -36,7 +36,7 @@ class TalentPage extends GenericPage
$this->isPetCalc ? 'petcalc.js' : 'talent.js', $this->isPetCalc ? 'petcalc.js' : 'talent.js',
$this->isPetCalc ? 'swfobject.js' : null $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'; $this->tcType = $this->isPetCalc ? 'pc' : 'tc';
} }

View File

@@ -44,15 +44,15 @@ class UtilityPage extends GenericPage
$this->lvTabs = []; $this->lvTabs = [];
} }
public function display($override = '') public function display(string $override = '') : void
{ {
if ($this->rss) // this should not be cached if ($this->rss) // this should not be cached
{ {
header('Content-Type: application/rss+xml; charset=UTF-8'); header(MIME_TYPE_RSS);
die($this->generateRSS()); die($this->generateRSS());
} }
else else
return parent::display($override); parent::display($override);
} }
protected function generateContent() protected function generateContent()

View File

@@ -97,7 +97,7 @@ class ZonePage extends GenericPage
{ {
foreach ($attmnt as $type => $ids) foreach ($attmnt as $type => $ids)
{ {
$this->extendGlobalIds($type, array_map('abs', $ids)); $this->extendGlobalIds($type, ...array_map('abs', $ids));
foreach ($ids as $id) foreach ($ids as $id)
{ {
if ($type == TYPE_ITEM) if ($type == TYPE_ITEM)
@@ -111,7 +111,7 @@ class ZonePage extends GenericPage
// Instances // Instances
if ($_ = DB::Aowow()->selectCol('SELECT id FROM ?_zones WHERE parentAreaId = ?d AND (flags & ?d) = 0', $this->typeId, CUSTOM_EXCLUDE_FOR_LISTVIEW)) 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=", $_).']'; $infobox[] = Lang::maps('Instances').Lang::main('colon')."\n[zone=".implode("], \n[zone=", $_).']';
} }
@@ -678,7 +678,7 @@ class ZonePage extends GenericPage
if ($a['racemask'] & (1 << $i)) if ($a['racemask'] & (1 << $i))
$foo[] = $i + 1; $foo[] = $i + 1;
$this->extendGlobalIds(TYPE_RACE, $foo); $this->extendGlobalIds(TYPE_RACE, ...$foo);
$condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]]; $condition[0][$this->typeId][] = [[CND_RACE, $a['racemask']]];
} }

View File

@@ -17142,6 +17142,8 @@ var Menu = new function()
$menuItems.each(function () { $innerDiv.append(this) }); $menuItems.each(function () { $innerDiv.append(this) });
$outerDiv.append($innerDiv); $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; return $outerDiv;
} }

View File

@@ -44,6 +44,20 @@ if (!empty($this->transfer)):
echo " <div class=\"pad\"></div>\n ".$this->transfer."\n"; echo " <div class=\"pad\"></div>\n ".$this->transfer."\n";
endif; endif;
if (isset($this->smartAI)):
?>
<div id="text-generic" class="left"></div>
<script type="text/javascript">//<![CDATA[
Markup.printHtml("<?=$this->smartAI; ?>", "text-generic", {
allow: Markup.CLASS_ADMIN,
dbpage: true
});
//]]></script>
<div class="pad2"></div>
<?php
endif;
if (!empty($this->zoneMusic)): if (!empty($this->zoneMusic)):
?> ?>
<div class="clear"> <div class="clear">