From f6e15c35fc6899dd283d942fd95abcda50661a50 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 24 Jul 2015 22:41:00 +0200 Subject: [PATCH] Tooltips * added word events to tooltips * added option to pass achieved criteria to achievement tooltips via rel-parameter --- includes/markup.class.php | 2 +- includes/types/achievement.class.php | 8 +- includes/types/worldevent.class.php | 52 +++++-- pages/currency.php | 3 +- pages/event.php | 168 +++++++++++++++------- setup/tools/filegen/templates/power.js.in | 49 +++++-- 6 files changed, 202 insertions(+), 80 deletions(-) diff --git a/includes/markup.class.php b/includes/markup.class.php index 7d4df093..1400b9eb 100644 --- a/includes/markup.class.php +++ b/includes/markup.class.php @@ -21,7 +21,7 @@ class Markup public function parseGlobalsFromText(&$jsg = []) { - if (preg_match_all('/(?text, $matches, PREG_SET_ORDER)) + if (preg_match_all('/(?text, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { diff --git a/includes/types/achievement.class.php b/includes/types/achievement.class.php index 24e49d37..c8803b3d 100644 --- a/includes/types/achievement.class.php +++ b/includes/types/achievement.class.php @@ -206,10 +206,12 @@ class AchievementList extends BaseType break; } + $criteria .= '- '.Util::jsEscape($crtName); + if ($crt['completionFlags'] & ACHIEVEMENT_CRITERIA_FLAG_MONEY_COUNTER) - $criteria .= '- '.Util::jsEscape($crtName).' '.Lang::nf($crt['value2' ] / 10000).'
'; - else - $criteria .= '- '.Util::jsEscape($crtName).'
'; + $criteria .= ' '.Lang::nf($crt['value2' ] / 10000).''; + + $criteria .= '
'; if (++$i == round(count($rows)/2)) $criteria .= ''; diff --git a/includes/types/worldevent.class.php b/includes/types/worldevent.class.php index 6021cca6..ac98c68d 100644 --- a/includes/types/worldevent.class.php +++ b/includes/types/worldevent.class.php @@ -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 = '
'; + + // head v that extra % is nesecary because we are using sprintf later on + $x .= '
'.Util::jsEscape($this->getField('name', true)).''.Lang::event('category', $this->getField('category')).'
'; + + // use string-placeholder for dates + // start + $x .= Lang::event('start').Lang::main('colon').'%s
'; + // end + $x .= Lang::event('end').Lang::main('colon').'%s'; + + $x .= '
'; + + // desc + if ($this->getField('holidayId')) + if ($_ = $this->getField('description', true)) + $x .= '
'.Util::jsEscape($_).'
'; + + return $x; + } } ?> diff --git a/pages/currency.php b/pages/currency.php index fcc6706d..1b23f449 100644 --- a/pages/currency.php +++ b/pages/currency.php @@ -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(); } - } ?> diff --git a/pages/event.php b/pages/event.php index e8f68340..a904abfc 100644 --- a/pages/event.php +++ b/pages/event.php @@ -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(); } } diff --git a/setup/tools/filegen/templates/power.js.in b/setup/tools/filegen/templates/power.js.in index 34367b6b..1316162b 100644 --- a/setup/tools/filegen/templates/power.js.in +++ b/setup/tools/filegen/templates/power.js.in @@ -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("

", '

' + $WH.sprintf(_LANG.achievementcomplete, currentParams.who, currentParams.when.getMonth() + 1, currentParams.when.getDate(), currentParams.when.getFullYear()) + "

"); 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("