* 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 = [])
{
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)
{

View file

@ -206,10 +206,12 @@ class AchievementList extends BaseType
break;
}
$criteria .= '<!--cr'.$crt['id'].':'.$crt['type'].':'.$crt['value1'].'-->- '.Util::jsEscape($crtName);
if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER)
$criteria .= '- '.Util::jsEscape($crtName).' <span class="moneygold">'.Lang::nf($crt['value2' ] / 10000).'</span><br />';
else
$criteria .= '- '.Util::jsEscape($crtName).'<br />';
$criteria .= '&nbsp;<span class="moneygold">'.Lang::nf($crt['value2' ] / 10000).'</span>';
$criteria .= '<br />';
if (++$i == round(count($rows)/2))
$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 $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(
'e' => [['h']],
'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);
$replace[$this->id] = $this->curTpl;
unset($this->curTpl['description']);
}
else // set a name if holiday is missing
{
// template
$this->curTpl['name_loc0'] = $this->curTpl['description'];
$this->curTpl['name_loc0'] = $this->curTpl['nameINT'];
$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;
}
}
@ -66,10 +65,21 @@ class WorldEventList extends BaseType
public static function getName($id)
{
if ($id > 0)
$row = DB::Aowow()->SelectRow('SELECT * FROM ?_holidays WHERE Id = ?d', intVal($id));
else
$row = DB::Aowow()->SelectRow('SELECT description as name FROM ?_events WHERE Id = ?d', intVal(-$id));
$row = DB::Aowow()->SelectRow('
SELECT
IFNULL(h.name_loc0, e.description) AS name_loc0,
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');
}
@ -155,7 +165,31 @@ class WorldEventList extends BaseType
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)
return '$WowheadPower.registerCurrency('.$this->typeId.', '.User::$localeId.', {});';
@ -268,7 +268,6 @@ class CurrencyPage extends GenericPage
echo $this->generateTooltip(true);
exit();
}
}
?>

View file

@ -4,8 +4,8 @@ if (!defined('AOWOW_REVISION'))
die('illegal access');
// menuId 11: Object g_initPath()
// tabId 0: Database g_initHeader()
// menuId 11: Worldevent g_initPath()
// tabId 0: Database g_initHeader()
class EventPage extends GenericPage
{
use DetailPage;
@ -24,16 +24,25 @@ class EventPage extends GenericPage
{
parent::__construct($pageCall, $id);
// temp locale
if ($this->mode == CACHE_TYPE_TOOLTIP && isset($_GET['domain']))
Util::powerUseLocale($_GET['domain']);
$this->typeId = intVal($id);
$this->subject = new WorldEventList(array(['id', $this->typeId]));
if ($this->subject->error)
$this->notFound(Lang::game('event'), Lang::event('notFound'));
$this->hId = $this->subject->getField('holidayId');
$this->eId = $this->typeId;
$this->name = $this->subject->getField('name', true);
$this->hId = $this->subject->getField('holidayId');
$this->eId = $this->typeId;
$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()
@ -78,17 +87,14 @@ class EventPage extends GenericPage
/* Main Content */
/****************/
if ($this->hId)
$this->extraText = Util::jsEscape($this->subject->getField('description', true));
$this->headIcons = [$this->subject->getField('iconString')];
$this->redButtons = array(
BUTTON_WOWHEAD => $this->hId > 0,
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 */
@ -259,53 +265,107 @@ class EventPage extends GenericPage
protected function postCache()
{
if ($this->hId)
Util::$wowheadLink = 'http://'.Util::$subDomains[User::$localeId].'.wowhead.com/event='.$this->hId;
/********************/
/* finalize infobox */
/********************/
// update dates to now()
$updated = WorldEventList::updateDates($this->dates);
// 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 ($this->mode == CACHE_TYPE_TOOLTIP)
{
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'];
}
return array(
date(Lang::main('dateFmtLong'), $updated['start']),
date(Lang::main('dateFmtLong'), $updated['end'])
);
}
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 = {},
spells = {},
achievements = {},
holidays = {},
itemsets = {},
currencies = {},
profiles = {},
@ -57,6 +58,7 @@ if (typeof $WowheadPower == "undefined") {
TYPE_QUEST = 5,
TYPE_SPELL = 6,
TYPE_ACHIEVEMENT = 10,
TYPE_HOLIDAY = 12,
TYPE_CURRENCY = 17,
TYPE_PROFILE = 100,
@ -76,6 +78,7 @@ if (typeof $WowheadPower == "undefined") {
5: [quests, "quest", "Quest" ],
6: [spells, "spell", "Spell" ],
10: [achievements, "achievement", "Achievement"],
12: [holidays, "event", "Holiday" ],
17: [currencies, "currency", "Currency" ],
100: [profiles, "profile", "Profile" ]
},
@ -215,11 +218,26 @@ if (typeof $WowheadPower == "undefined") {
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;
}
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;
}
@ -239,7 +257,7 @@ if (typeof $WowheadPower == "undefined") {
else if (k == "rand" || k == "ench" || k == "lvl" || k == "c") {
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(":");
}
else if (k == "who" || k == "domain") {
@ -261,8 +279,8 @@ if (typeof $WowheadPower == "undefined") {
i2 = 3;
if (t.href.indexOf("http://") == 0 || t.href.indexOf("https://") == 0) {
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?:\/\/(.*)\/?\??(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|event|npc|object|itemset|currency)=(-?[0-9]+)/);
if (url == null) {
// url = t.href.match(/^http:\/\/(.+?)?\.?wowhead\.com\/\?(profile)=([^&#]+)/)
url = t.href.match(/^https?:\/\/(.*)\/?\??(profile)=([^&#]+)/);
@ -271,7 +289,7 @@ if (typeof $WowheadPower == "undefined") {
showLogo = 0;
}
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) {
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;
i1 = 1;
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
// url = t.rel.match(/(profile).?([^&#]+)/);
// url = rel.match(/(profile).?([^&#]+)/);
// }
showLogo = 1;
}
t.href.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p);
if (t.rel) {
t.rel.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p);
if (rel) {
rel.replace(/([a-zA-Z]+)=?([a-zA-Z0-9:-]*)/g, p);
}
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(/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.registerHoliday = function (id, locale, json) {
this.register(TYPE_HOLIDAY, id, locale, json);
};
this.registerItemSet = function (id, locale, json) {
this.register(TYPE_ITEMSET, id, locale, json);
};