* added word events to tooltips
  * added option to pass achieved criteria to achievement tooltips via rel-parameter
This commit is contained in:
Sarjuuk
2015-07-24 22:41:00 +02:00
parent 7b30c49785
commit f6e15c35fc
6 changed files with 202 additions and 80 deletions

View File

@@ -21,7 +21,7 @@ class Markup
public function parseGlobalsFromText(&$jsg = []) public function parseGlobalsFromText(&$jsg = [])
{ {
if (preg_match_all('/(?<!\\\\)\[(npc|object|item|itemset|quest|spell|zone|faction|pet|achievement|statistic|title|event|class|race|skill|currency)=(\d+)[^\]]*\]/i', $this->text, $matches, PREG_SET_ORDER)) if (preg_match_all('/(?<!\\\\)\[(npc|object|item|itemset|quest|spell|zone|faction|pet|achievement|statistic|title|event|class|race|skill|currency)=(-?\d+)[^\]]*\]/i', $this->text, $matches, PREG_SET_ORDER))
{ {
foreach ($matches as $match) foreach ($matches as $match)
{ {

View File

@@ -206,10 +206,12 @@ class AchievementList extends BaseType
break; break;
} }
$criteria .= '<!--cr'.$crt['id'].':'.$crt['type'].':'.$crt['value1'].'-->- '.Util::jsEscape($crtName);
if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER) if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER)
$criteria .= '- '.Util::jsEscape($crtName).' <span class="moneygold">'.Lang::nf($crt['value2' ] / 10000).'</span><br />'; $criteria .= '&nbsp;<span class="moneygold">'.Lang::nf($crt['value2' ] / 10000).'</span>';
else
$criteria .= '- '.Util::jsEscape($crtName).'<br />'; $criteria .= '<br />';
if (++$i == round(count($rows)/2)) if (++$i == round(count($rows)/2))
$criteria .= '</small></td><th class="q0" style="white-space: nowrap; text-align: left"><small>'; $criteria .= '</small></td><th class="q0" style="white-space: nowrap; text-align: left"><small>';

View File

@@ -9,7 +9,7 @@ class WorldEventList extends BaseType
public static $type = TYPE_WORLDEVENT; public static $type = TYPE_WORLDEVENT;
public static $brickFile = 'event'; public static $brickFile = 'event';
protected $queryBase = 'SELECT *, e.id as id, e.id AS ARRAY_KEY FROM ?_events e'; protected $queryBase = 'SELECT e.*, h.*, e.description AS nameINT, e.id AS id, e.id AS ARRAY_KEY FROM ?_events e';
protected $queryOpts = array( protected $queryOpts = array(
'e' => [['h']], 'e' => [['h']],
'h' => ['j' => ['?_holidays h ON e.holidayId = h.id', true], 'o' => '-e.id ASC'] 'h' => ['j' => ['?_holidays h ON e.holidayId = h.id', true], 'o' => '-e.id ASC']
@@ -45,14 +45,13 @@ class WorldEventList extends BaseType
{ {
$this->curTpl['name'] = $this->getField('name', true); $this->curTpl['name'] = $this->getField('name', true);
$replace[$this->id] = $this->curTpl; $replace[$this->id] = $this->curTpl;
unset($this->curTpl['description']);
} }
else // set a name if holiday is missing else // set a name if holiday is missing
{ {
// template // template
$this->curTpl['name_loc0'] = $this->curTpl['description']; $this->curTpl['name_loc0'] = $this->curTpl['nameINT'];
$this->curTpl['iconString'] = 'trade_engineering'; $this->curTpl['iconString'] = 'trade_engineering';
$this->curTpl['name'] = '(SERVERSIDE) '.$this->getField('description', true); $this->curTpl['name'] = '(SERVERSIDE) '.$this->getField('nameINT', true);
$replace[$this->id] = $this->curTpl; $replace[$this->id] = $this->curTpl;
} }
} }
@@ -66,10 +65,21 @@ class WorldEventList extends BaseType
public static function getName($id) public static function getName($id)
{ {
if ($id > 0) $row = DB::Aowow()->SelectRow('
$row = DB::Aowow()->SelectRow('SELECT * FROM ?_holidays WHERE Id = ?d', intVal($id)); SELECT
else IFNULL(h.name_loc0, e.description) AS name_loc0,
$row = DB::Aowow()->SelectRow('SELECT description as name FROM ?_events WHERE Id = ?d', intVal(-$id)); h.name_loc2,
h.name_loc3,
h.name_loc6,
h.name_loc8
FROM
?_events e
LEFT JOIN
?_holidays h ON e.holidayId = h.id
WHERE
e.id = ?d',
$id
);
return Util::localizedString($row, 'name'); return Util::localizedString($row, 'name');
} }
@@ -155,7 +165,31 @@ class WorldEventList extends BaseType
return $data; return $data;
} }
public function renderTooltip() { } public function renderTooltip()
{
if (!$this->curTpl)
return null;
$x = '<table><tr><td>';
// head v that extra % is nesecary because we are using sprintf later on
$x .= '<table width="100%%"><tr><td><b>'.Util::jsEscape($this->getField('name', true)).'</b></td><th><b class="q0">'.Lang::event('category', $this->getField('category')).'</b></th></tr></table>';
// use string-placeholder for dates
// start
$x .= Lang::event('start').Lang::main('colon').'%s<br>';
// end
$x .= Lang::event('end').Lang::main('colon').'%s';
$x .= '</td></tr></table>';
// desc
if ($this->getField('holidayId'))
if ($_ = $this->getField('description', true))
$x .= '<table><tr><td><span class="q">'.Util::jsEscape($_).'</span></td></tr></table>';
return $x;
}
} }
?> ?>

View File

@@ -230,7 +230,7 @@ class CurrencyPage extends GenericPage
} }
} }
protected function generateTooltip($asError = false) protected function generateTooltip($asError = false)
{ {
if ($asError) if ($asError)
return '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.', {});'; return '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.', {});';
@@ -268,7 +268,6 @@ class CurrencyPage extends GenericPage
echo $this->generateTooltip(true); echo $this->generateTooltip(true);
exit(); exit();
} }
} }
?> ?>

View File

@@ -4,8 +4,8 @@ if (!defined('AOWOW_REVISION'))
die('illegal access'); die('illegal access');
// menuId 11: Object g_initPath() // menuId 11: Worldevent g_initPath()
// tabId 0: Database g_initHeader() // tabId 0: Database g_initHeader()
class EventPage extends GenericPage class EventPage extends GenericPage
{ {
use DetailPage; use DetailPage;
@@ -24,16 +24,25 @@ class EventPage extends GenericPage
{ {
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);
// temp locale
if ($this->mode == CACHE_TYPE_TOOLTIP && isset($_GET['domain']))
Util::powerUseLocale($_GET['domain']);
$this->typeId = intVal($id); $this->typeId = intVal($id);
$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(Lang::game('event'), Lang::event('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;
$this->name = $this->subject->getField('name', true);
$this->name = $this->subject->getField('name', true); $this->dates = array(
'firstDate' => $this->subject->getField('startTime'),
'lastDate' => $this->subject->getField('endTime'),
'length' => $this->subject->getField('length'),
'rec' => $this->subject->getField('occurence')
);
} }
protected function generatePath() protected function generatePath()
@@ -78,17 +87,14 @@ class EventPage extends GenericPage
/* Main Content */ /* Main Content */
/****************/ /****************/
if ($this->hId)
$this->extraText = Util::jsEscape($this->subject->getField('description', true));
$this->headIcons = [$this->subject->getField('iconString')]; $this->headIcons = [$this->subject->getField('iconString')];
$this->redButtons = array( $this->redButtons = array(
BUTTON_WOWHEAD => $this->hId > 0, BUTTON_WOWHEAD => $this->hId > 0,
BUTTON_LINKS => true BUTTON_LINKS => true
); );
$this->dates = array(
'firstDate' => $this->subject->getField('startTime'),
'lastDate' => $this->subject->getField('endTime'),
'length' => $this->subject->getField('length'),
'rec' => $this->subject->getField('occurence')
);
/**************/ /**************/
/* Extra Tabs */ /* Extra Tabs */
@@ -259,53 +265,107 @@ class EventPage extends GenericPage
protected function postCache() protected function postCache()
{ {
if ($this->hId)
Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/event='.$this->hId;
/********************/
/* finalize infobox */
/********************/
// update dates to now() // update dates to now()
$updated = WorldEventList::updateDates($this->dates); $updated = WorldEventList::updateDates($this->dates);
// start if ($this->mode == CACHE_TYPE_TOOLTIP)
if ($updated['start'])
array_push($this->infobox, Lang::event('start').Lang::main('colon').date(Lang::main('dateFmtLong'), $updated['start']));
// end
if ($updated['end'])
array_push($this->infobox, Lang::event('end').Lang::main('colon').date(Lang::main('dateFmtLong'), $updated['end']));
// occurence
if ($updated['rec'] > 0)
array_push($this->infobox, Lang::event('interval').Lang::main('colon').Util::formatTime($updated['rec'] * 1000));
// in progress
if ($updated['start'] < time() && $updated['end'] > time())
array_push($this->infobox, '[span class=q2]'.Lang::event('inProgress').'[/span]');
$this->infobox = '[ul][li]'.implode('[/li][li]', $this->infobox).'[/li][/ul]';
/***************************/
/* finalize related events */
/***************************/
foreach ($this->lvTabs as &$view)
{ {
if ($view['file'] != WorldEventList::$brickFile) return array(
continue; date(Lang::main('dateFmtLong'), $updated['start']),
date(Lang::main('dateFmtLong'), $updated['end'])
foreach ($view['data'] as &$data) );
{
$updated = WorldEventList::updateDates($data['_date']);
unset($data['_date']);
$data['startDate'] = $updated['start'] ? date(Util::$dateFormatInternal, $updated['start']) : false;
$data['endDate'] = $updated['end'] ? date(Util::$dateFormatInternal, $updated['end']) : false;
$data['rec'] = $updated['rec'];
}
} }
else
{
if ($this->hId)
Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/event='.$this->hId;
/********************/
/* finalize infobox */
/********************/
// start
if ($updated['start'])
array_push($this->infobox, Lang::event('start').Lang::main('colon').date(Lang::main('dateFmtLong'), $updated['start']));
// end
if ($updated['end'])
array_push($this->infobox, Lang::event('end').Lang::main('colon').date(Lang::main('dateFmtLong'), $updated['end']));
// occurence
if ($updated['rec'] > 0)
array_push($this->infobox, Lang::event('interval').Lang::main('colon').Util::formatTime($updated['rec'] * 1000));
// in progress
if ($updated['start'] < time() && $updated['end'] > time())
array_push($this->infobox, '[span class=q2]'.Lang::event('inProgress').'[/span]');
$this->infobox = '[ul][li]'.implode('[/li][li]', $this->infobox).'[/li][/ul]';
/***************************/
/* finalize related events */
/***************************/
foreach ($this->lvTabs as &$view)
{
if ($view['file'] != WorldEventList::$brickFile)
continue;
foreach ($view['data'] as &$data)
{
$updated = WorldEventList::updateDates($data['_date']);
unset($data['_date']);
$data['startDate'] = $updated['start'] ? date(Util::$dateFormatInternal, $updated['start']) : false;
$data['endDate'] = $updated['end'] ? date(Util::$dateFormatInternal, $updated['end']) : false;
$data['rec'] = $updated['rec'];
}
}
}
}
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: '".urlencode($this->subject->getField('iconString'))."',\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);
}
list($start, $end) = $this->postCache();
header('Content-type: application/x-javascript; charset=utf-8');
die(sprintf($tt, $start, $end));
}
public function notFound()
{
if ($this->mode != CACHE_TYPE_TOOLTIP)
return parent::notFound(Lang::game('event'), Lang::event('notFound'));
header('Content-type: application/x-javascript; charset=utf-8');
echo $this->generateTooltip(true);
exit();
} }
} }

View File

@@ -33,6 +33,7 @@ if (typeof $WowheadPower == "undefined") {
quests = {}, quests = {},
spells = {}, spells = {},
achievements = {}, achievements = {},
holidays = {},
itemsets = {}, itemsets = {},
currencies = {}, currencies = {},
profiles = {}, profiles = {},
@@ -57,6 +58,7 @@ if (typeof $WowheadPower == "undefined") {
TYPE_QUEST = 5, TYPE_QUEST = 5,
TYPE_SPELL = 6, TYPE_SPELL = 6,
TYPE_ACHIEVEMENT = 10, TYPE_ACHIEVEMENT = 10,
TYPE_HOLIDAY = 12,
TYPE_CURRENCY = 17, TYPE_CURRENCY = 17,
TYPE_PROFILE = 100, TYPE_PROFILE = 100,
@@ -76,6 +78,7 @@ if (typeof $WowheadPower == "undefined") {
5: [quests, "quest", "Quest" ], 5: [quests, "quest", "Quest" ],
6: [spells, "spell", "Spell" ], 6: [spells, "spell", "Spell" ],
10: [achievements, "achievement", "Achievement"], 10: [achievements, "achievement", "Achievement"],
12: [holidays, "event", "Holiday" ],
17: [currencies, "currency", "Currency" ], 17: [currencies, "currency", "Currency" ],
100: [profiles, "profile", "Profile" ] 100: [profiles, "profile", "Profile" ]
}, },
@@ -215,11 +218,26 @@ if (typeof $WowheadPower == "undefined") {
return -2323; return -2323;
} }
if (!t.href.length && !t.rel) { var rel = t.rel;
try {
if (t.dataset && t.dataset.hasOwnProperty("wowhead")) {
rel = t.dataset.wowhead;
}
else if (t.getAttribute && t.getAttribute("data-wowhead")) {
rel = t.getAttribute("data-wowhead");
}
}
catch(e) { void(0); }
if (!t.href.length && !rel) {
return; return;
} }
if (t.rel && t.rel.indexOf("np") != -1 && t.rel.indexOf("np") != t.rel.indexOf("npc=")) { if (rel && /^np\b/.test(rel)) {
return;
}
if (t.getAttribute("data-disable-wowhead-tooltip") == "true") {
return; return;
} }
@@ -239,7 +257,7 @@ if (typeof $WowheadPower == "undefined") {
else if (k == "rand" || k == "ench" || k == "lvl" || k == "c") { else if (k == "rand" || k == "ench" || k == "lvl" || k == "c") {
params[k] = parseInt(v); params[k] = parseInt(v);
} }
else if (k == "gems" || k == "pcs" || k == "know") { else if (k == "gems" || k == "pcs" || k == "know" || k == "cri") {
params[k] = v.split(":"); params[k] = v.split(":");
} }
else if (k == "who" || k == "domain") { else if (k == "who" || k == "domain") {
@@ -261,8 +279,8 @@ if (typeof $WowheadPower == "undefined") {
i2 = 3; i2 = 3;
if (t.href.indexOf("http://") == 0 || t.href.indexOf("https://") == 0) { if (t.href.indexOf("http://") == 0 || t.href.indexOf("https://") == 0) {
i0 = 1; i0 = 1;
// url = t.href.match(/^https?:\/\/(.+?)?\.?wowhead\.com(?:\:\d+)?\/\??(item|quest|spell|achievement|npc|object|itemset|currency)=(-?[0-9]+)/); // url = t.href.match(/^https?:\/\/(.+?)?\.?wowhead\.com(?:\:\d+)?\/\??(item|quest|spell|achievement|event|npc|object|itemset|currency)=(-?[0-9]+)/);
url = t.href.match(/^https?:\/\/(.*)\/?\??(item|quest|spell|achievement|npc|object|itemset|currency)=(-?[0-9]+)/); url = t.href.match(/^https?:\/\/(.*)\/?\??(item|quest|spell|achievement|event|npc|object|itemset|currency)=(-?[0-9]+)/);
if (url == null) { if (url == null) {
// url = t.href.match(/^http:\/\/(.+?)?\.?wowhead\.com\/\?(profile)=([^&#]+)/) // url = t.href.match(/^http:\/\/(.+?)?\.?wowhead\.com\/\?(profile)=([^&#]+)/)
url = t.href.match(/^https?:\/\/(.*)\/?\??(profile)=([^&#]+)/); url = t.href.match(/^https?:\/\/(.*)\/?\??(profile)=([^&#]+)/);
@@ -271,7 +289,7 @@ if (typeof $WowheadPower == "undefined") {
showLogo = 0; showLogo = 0;
} }
else { else {
url = t.href.match(/()\?(item|quest|spell|achievement|npc|object|itemset|currency)=(-?[0-9]+)/); url = t.href.match(/()\?(item|quest|spell|achievement|event|npc|object|itemset|currency)=(-?[0-9]+)/);
if (url == null) { if (url == null) {
url = t.href.match(/()\?(profile)=([^&#]+)/); url = t.href.match(/()\?(profile)=([^&#]+)/);
} }
@@ -280,20 +298,20 @@ if (typeof $WowheadPower == "undefined") {
} }
} }
if (url == null && t.rel && (opt.applyto & 2)) { if (url == null && rel && (opt.applyto & 2)) {
i0 = 0; i0 = 0;
i1 = 1; i1 = 1;
i2 = 2; i2 = 2;
url = t.rel.match(/(item|quest|spell|achievement|npc|object|itemset|currency).?(-?[0-9]+)/); url = rel.match(/(item|quest|spell|achievement|event|npc|object|itemset|currency).?(-?[0-9]+)/);
// if (url == null) { // sarjuuk: also matches 'profiler' and 'profiles' which screws with the language-menu workaround // if (url == null) { // sarjuuk: also matches 'profiler' and 'profiles' which screws with the language-menu workaround
// url = t.rel.match(/(profile).?([^&#]+)/); // url = rel.match(/(profile).?([^&#]+)/);
// } // }
showLogo = 1; showLogo = 1;
} }
t.href.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p); t.href.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p);
if (t.rel) { if (rel) {
t.rel.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p); rel.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p);
} }
if (params.gems && params.gems.length > 0) { if (params.gems && params.gems.length > 0) {
@@ -606,6 +624,11 @@ if (typeof $WowheadPower == "undefined") {
html = html.replace("<table><tr><td><br />", '<table><tr><td><br /><span class="q2">' + $WH.sprintf(_LANG.achievementcomplete, currentParams.who, currentParams.when.getMonth() + 1, currentParams.when.getDate(), currentParams.when.getFullYear()) + "</span><br /><br />"); html = html.replace("<table><tr><td><br />", '<table><tr><td><br /><span class="q2">' + $WH.sprintf(_LANG.achievementcomplete, currentParams.who, currentParams.when.getMonth() + 1, currentParams.when.getDate(), currentParams.when.getFullYear()) + "</span><br /><br />");
html = html.replace(/class="q0"/g, 'class="r3"'); html = html.replace(/class="q0"/g, 'class="r3"');
} }
if ((currentType == TYPE_ACHIEVEMENT) && currentParams.cri) {
for (var i = 0; i < currentParams.cri.length; i++) {
html = html.replace(new RegExp("<!--cr" + parseInt(currentParams.cri[i]) + ":[^<]+", "g"), '<span class="q2">$&</span>')
}
}
} }
} }
@@ -725,6 +748,10 @@ if (typeof $WowheadPower == "undefined") {
this.register(TYPE_ITEM, id, locale, json); this.register(TYPE_ITEM, id, locale, json);
}; };
this.registerHoliday = function (id, locale, json) {
this.register(TYPE_HOLIDAY, id, locale, json);
};
this.registerItemSet = function (id, locale, json) { this.registerItemSet = function (id, locale, json) {
this.register(TYPE_ITEMSET, id, locale, json); this.register(TYPE_ITEMSET, id, locale, json);
}; };