diff --git a/endpoints/currencies/currencies.php b/endpoints/currencies/currencies.php new file mode 100644 index 00000000..0a5aec25 --- /dev/null +++ b/endpoints/currencies/currencies.php @@ -0,0 +1,76 @@ +getCategoryFromUrl($pageParam); + + parent::__construct($pageParam); + } + + protected function generate() : void + { + $this->h1 = Util::ucFirst(Lang::game('currencies')); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1); + if ($this->category) + array_unshift($this->title, Lang::currency('cat', $this->category[0])); + + + /*************/ + /* Menu Path */ + /*************/ + + if ($this->category) + $this->breadcrumb[] = $this->category[0]; + + + /****************/ + /* Main Content */ + /****************/ + + $this->redButtons[BUTTON_WOWHEAD] = true; + + $conditions = []; + + if (!User::isInGroup(U_GROUP_EMPLOYEE)) + $conditions[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; + + if ($this->category) + $conditions[] = ['category', $this->category[0]]; + + $money = new CurrencyList($conditions); + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $this->lvTabs->addListviewTab(new Listview(['data' => $money->getListviewData()], CurrencyList::$brickFile)); + + parent::generate(); + } +} + +?> diff --git a/pages/currency.php b/endpoints/currency/currency.php similarity index 58% rename from pages/currency.php rename to endpoints/currency/currency.php index 8bb4dbb3..31bc6823 100644 --- a/pages/currency.php +++ b/endpoints/currency/currency.php @@ -6,55 +6,61 @@ if (!defined('AOWOW_REVISION')) die('illegal access'); -// menuId 15: Currency g_initPath() -// tabId 0: Database g_initHeader() -class CurrencyPage extends GenericPage +class CurrencyBaseResponse extends TemplateResponse implements ICache { - use TrDetailPage; + use TrDetailPage, TrCache; - protected $type = Type::CURRENCY; - protected $typeId = 0; - protected $tpl = 'detail-page-generic'; - protected $path = [0, 15]; - protected $tabId = 0; - protected $mode = CACHE_TYPE_PAGE; + protected int $cacheType = CACHE_TYPE_PAGE; - protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\Locale::tryFromDomain']]; + protected string $template = 'detail-page-generic'; + protected string $pageName = 'currency'; + protected ?int $activeTab = parent::TAB_DATABASE; + protected array $breadcrumb = [0, 15]; - private $powerTpl = '$WowheadPower.registerCurrency(%d, %d, %s);'; + public int $type = Type::CURRENCY; + public int $typeId = 0; - public function __construct($pageCall, $id) + private CurrencyList $subject; + + public function __construct(string $id) { - parent::__construct($pageCall, $id); + parent::__construct($id); - // temp locale - if ($this->mode == CACHE_TYPE_TOOLTIP && $this->_get['domain']) - Lang::load($this->_get['domain']); + $this->typeId = intVal($id); + $this->contribute = Type::getClassAttrib($this->type, 'contribute') ?? CONTRIBUTE_NONE; + } - $this->typeId = intVal($id); + protected function generate() : void + { $this->subject = new CurrencyList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Lang::game('currency'), Lang::currency('notFound')); + $this->generateNotFound(Lang::game('currency'), Lang::currency('notFound')); - $this->name = $this->subject->getField('name', true); - } + $this->h1 = $this->subject->getField('name', true); - protected function generatePath() - { - $this->path[] = $this->subject->getField('category'); - } + $this->gPageInfo += array( + 'type' => $this->type, + 'typeId' => $this->typeId, + 'name' => $this->h1 + ); - protected function generateTitle() - { - array_unshift($this->title, $this->subject->getField('name', true), Util::ucFirst(Lang::game('currency'))); - } + $_relItemId = $this->subject->getField('itemId'); - protected function generateContent() - { - $this->addScript([SC_JS_FILE, '?data=zones']); - $_itemId = $this->subject->getField('itemId'); + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1, Util::ucFirst(Lang::game('currency'))); + + + /*************/ + /* Menu Path */ + /*************/ + + $this->breadcrumb[] = $this->subject->getField('category'); + /***********/ /* Infobox */ @@ -64,7 +70,7 @@ class CurrencyPage extends GenericPage // cap if ($_ = $this->subject->getField('cap')) - $infobox[] = Lang::currency('cap').Lang::main('colon').Lang::nf($_); + $infobox[] = Lang::currency('cap').Lang::nf($_); // icon if ($_ = $this->subject->getField('iconId')) @@ -73,6 +79,10 @@ class CurrencyPage extends GenericPage $this->extendGlobalIds(Type::ICON, $_); } + if ($infobox) + $this->infobox = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0'); + + /****************/ /* Main Content */ /****************/ @@ -81,8 +91,6 @@ class CurrencyPage extends GenericPage if ($hi[0] == $hi[1]) unset($hi[1]); - $this->infobox = $infobox ? '[ul][li]'.implode('[/li][li]', $infobox).'[/li][/ul]' : null; - $this->name = $this->subject->getField('name', true); $this->headIcons = $hi; $this->redButtons = array( BUTTON_WOWHEAD => true, @@ -90,30 +98,38 @@ class CurrencyPage extends GenericPage ); if ($_ = $this->subject->getField('description', true)) - $this->extraText = $_; + $this->extraText = new Markup($_, ['dbpage' => true, 'allow' => Markup::CLASS_ADMIN], 'text-generic'); + /**************/ /* Extra Tabs */ /**************/ - if ($this->typeId != 103 && $this->typeId != 104) // honor && arena points are not handled as items + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true); + + if ($this->typeId != CURRENCY_HONOR_POINTS && $this->typeId != CURRENCY_ARENA_POINTS) { // tabs: this currency is contained in.. $lootTabs = new Loot(); - if ($lootTabs->getByItem($_itemId)) + if ($lootTabs->getByItem($_relItemId)) { $this->extendGlobalData($lootTabs->jsGlobals); - foreach ($lootTabs->iterate() as [$file, $tabData]) - $this->lvTabs[] = [$file, $tabData]; + foreach ($lootTabs->iterate() as [$template, $tabData]) + { + if ($template == 'npc' || $template == 'object') + $this->addDataLoader('zones'); + + $this->lvTabs->addListviewTab(new Listview($tabData, $template)); + } } // tab: sold by - $itemObj = new ItemList(array(['id', $_itemId])); - if (!empty($itemObj->getExtendedCost()[$_itemId])) + $itemObj = new ItemList(array(['id', $_relItemId])); + if (!empty($itemObj->getExtendedCost()[$_relItemId])) { - $vendors = $itemObj->getExtendedCost()[$_itemId]; + $vendors = $itemObj->getExtendedCost()[$_relItemId]; $this->extendGlobalData($itemObj->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); $soldBy = new CreatureList(array(['id', array_keys($vendors)])); @@ -145,8 +161,8 @@ class CurrencyPage extends GenericPage $row['stack'] = $itemObj->getField('buyCount'); $row['cost'] = array( $itemObj->getField('buyPrice'), - $items ? $items : null, - $tokens ? $tokens : null + $items ?: null, + $tokens ?: null ); } @@ -154,27 +170,28 @@ class CurrencyPage extends GenericPage if (!array_column($sbData, 'condition')) array_pop($extraCols); - $this->lvTabs[] = [CreatureList::$brickFile, array( - 'data' => array_values($sbData), + $this->addDataLoader('zones'); + $this->lvTabs->addListviewTab(new Listview(array( + 'data' => $sbData, 'name' => '$LANG.tab_soldby', 'id' => 'sold-by-npc', 'extraCols' => $extraCols, 'hiddenCols' => ['level', 'type'] - )]; + ), CreatureList::$brickFile)); } } } // tab: created by (spell) [for items its handled in Loot::getByContainer()] - if ($this->typeId == 104) + if ($this->typeId == CURRENCY_HONOR_POINTS) { - $createdBy = new SpellList(array(['effect1Id', 45], ['effect2Id', 45], ['effect3Id', 45], 'OR')); + $createdBy = new SpellList(array(['effect1Id', SPELL_EFFECT_ADD_HONOR], ['effect2Id', SPELL_EFFECT_ADD_HONOR], ['effect3Id', SPELL_EFFECT_ADD_HONOR], 'OR')); if (!$createdBy->error) { $this->extendGlobalData($createdBy->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); $tabData = array( - 'data' => array_values($createdBy->getListviewData()), + 'data' => $createdBy->getListviewData(), 'name' => '$LANG.tab_createdby', 'id' => 'created-by', ); @@ -182,27 +199,27 @@ class CurrencyPage extends GenericPage if ($createdBy->hasSetFields('reagent1', 'reagent2', 'reagent3', 'reagent4', 'reagent5', 'reagent6', 'reagent7', 'reagent8')) $tabData['visibleCols'] = ['reagents']; - $this->lvTabs[] = [SpellList::$brickFile, $tabData]; + $this->lvTabs->addListviewTab(new Listview($tabData, SpellList::$brickFile)); } } // tab: currency for $n = $w = null; - if ($this->typeId == 103) + if ($this->typeId == CURRENCY_ARENA_POINTS) { $n = '?items&filter=cr=145;crs=1;crv=0'; $w = '`reqArenaPoints` > 0'; } - else if ($this->typeId == 104) + else if ($this->typeId == CURRENCY_HONOR_POINTS) { $n = '?items&filter=cr=144;crs=1;crv=0'; $w = '`reqHonorPoints` > 0'; } else - $w = '`reqItemId1` = '.$_itemId.' OR `reqItemId2` = '.$_itemId.' OR `reqItemId3` = '.$_itemId.' OR `reqItemId4` = '.$_itemId.' OR `reqItemId5` = '.$_itemId; + $w = '`reqItemId1` = '.$_relItemId.' OR `reqItemId2` = '.$_relItemId.' OR `reqItemId3` = '.$_relItemId.' OR `reqItemId4` = '.$_relItemId.' OR `reqItemId5` = '.$_relItemId; - if (!$n && ItemListFilter::isCurrencyFor($_itemId)) - $n = '?items&filter=cr=158;crs='.$_itemId.';crv=0'; + if (!$n && !is_null(ItemListFilter::getCriteriaIndex(158, $_relItemId))) + $n = '?items&filter=cr=158;crs='.$_relItemId.';crv=0'; $xCosts = DB::Aowow()->selectCol('SELECT `id` FROM ?_itemextendedcost WHERE '.$w); $boughtBy = $xCosts ? DB::World()->selectCol('SELECT `item` FROM npc_vendor WHERE `extendedCost` IN (?a) UNION SELECT `item` FROM game_event_npc_vendor WHERE `extendedCost` IN (?a)', $xCosts, $xCosts) : []; @@ -212,7 +229,7 @@ class CurrencyPage extends GenericPage if (!$boughtBy->error) { $tabData = array( - 'data' => array_values($boughtBy->getListviewData(ITEMINFO_VENDOR, [Type::CURRENCY => $this->typeId])), + 'data' => $boughtBy->getListviewData(ITEMINFO_VENDOR, [Type::CURRENCY => $this->typeId]), 'name' => '$LANG.tab_currencyfor', 'id' => 'currency-for', 'extraCols' => ["\$Listview.funcBox.createSimpleCol('stack', 'stack', '10%', 'stack')", '$Listview.extraCols.cost'] @@ -221,24 +238,13 @@ class CurrencyPage extends GenericPage if ($n) $tabData['note'] = sprintf(Util::$filterResultString, $n); - $this->lvTabs[] = [ItemList::$brickFile, $tabData]; + $this->lvTabs->addListviewTab(new Listview($tabData, ItemList::$brickFile)); $this->extendGlobalData($boughtBy->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); } } - } - protected function generateTooltip() - { - $power = new \StdClass(); - if (!$this->subject->error) - { - $power->{'name_'.Lang::getLocale()->json()} = $this->subject->getField('name', true); - $power->icon = rawurlencode($this->subject->getField('iconString', true, true)); - $power->{'tooltip_'.Lang::getLocale()->json()} = $this->subject->renderTooltip(); - } - - return sprintf($this->powerTpl, $this->typeId, Lang::getLocale()->value, Util::toJSON($power, JSON_AOWOW_POWER)); + parent::generate(); } } diff --git a/endpoints/currency/currency_power.php b/endpoints/currency/currency_power.php new file mode 100644 index 00000000..57b9c076 --- /dev/null +++ b/endpoints/currency/currency_power.php @@ -0,0 +1,50 @@ + ['filter' => FILTER_CALLBACK, 'options' => [Locale::class, 'tryFromDomain']] + ); + + public function __construct(string $id) + { + parent::__construct($id); + + // temp locale + if ($this->_get['domain']) + Lang::load($this->_get['domain']); + + $this->typeId = intVal($id); + } + + protected function generate() : void + { + $currency = new CurrencyList(array(['id', $this->typeId])); + if ($currency->error) + $this->cacheType = CACHE_TYPE_NONE; + else + $opts = array( + 'name' => $currency->getField('name', true), + 'tooltip' => $currency->renderTooltip(), + 'icon' => $currency->getField('iconString') + ); + + $this->result = new Tooltip(self::POWER_TEMPLATE, $this->typeId, $opts ?? []); + } +} + +?> diff --git a/includes/dbtypes/currency.class.php b/includes/dbtypes/currency.class.php index 33bcd0fe..a5be1df9 100644 --- a/includes/dbtypes/currency.class.php +++ b/includes/dbtypes/currency.class.php @@ -77,7 +77,7 @@ class CurrencyList extends DBTypeList $x .= '
'.$_.'
'; if ($_ = $this->getField('cap')) - $x .= '
'.Lang::currency('cap').Lang::main('colon').''.Lang::nf($_).'
'; + $x .= '
'.Lang::currency('cap').''.Lang::nf($_).'
'; $x .= ''; diff --git a/includes/game/loot.class.php b/includes/game/loot.class.php index 4ba60daf..1102fd24 100644 --- a/includes/game/loot.class.php +++ b/includes/game/loot.class.php @@ -47,8 +47,9 @@ class Loot { reset($this->results); - foreach ($this->results as $k => $__) - yield $k => $this->results[$k]; + foreach ($this->results as $k => [, $tabData]) + if ($tabData['data']) // only yield tabs with content + yield $k => $this->results[$k]; } public function getResult() : array diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 09d4fd96..bb988ab3 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -1390,7 +1390,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "Diese Währung existiert nicht.", - 'cap' => "Obergrenze", + 'cap' => "Obergrenze: ", 'cat' => array( 1 => "Verschiedenes", 2 => "Spieler gegen Spieler", 4 => "Classic", 21 => "Wrath of the Lich King", 22 => "Dungeon und Schlachtzug", 23 => "Burning Crusade", 41 => "Test", 3 => "Unbenutzt" ) diff --git a/localization/locale_enus.php b/localization/locale_enus.php index b8d154ab..ce69f448 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -1390,7 +1390,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "This currency doesn't exist.", - 'cap' => "Total cap", + 'cap' => "Total cap: ", 'cat' => array( 1 => "Miscellaneous", 2 => "Player vs. Player", 4 => "Classic", 21 => "Wrath of the Lich King", 22 => "Dungeon and Raid", 23 => "Burning Crusade", 41 => "Test", 3 => "Unused" ) diff --git a/localization/locale_eses.php b/localization/locale_eses.php index a85bec4b..1666804a 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -1390,7 +1390,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "Esta moneda no existe.", - 'cap' => "Límite total", + 'cap' => "Límite total: ", 'cat' => array( 1 => "Miscelánea", 2 => "Jugador contra Jugador", 4 => "Clásico", 21 => "Wrath of the Lich King", 22 => "Mazmorra y banda", 23 => "Burning Crusade", 41 => "Prueba", 3 => "No las uso" ) diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 53815027..1e49ae31 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -1390,7 +1390,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "Cette monnaie n'existe pas.", - 'cap' => "Maximum total", + 'cap' => "Maximum total : ", 'cat' => array( 1 => "Divers", 2 => "JcJ", 4 => "Classique", 21 => "Wrath of the Lich King", 22 => "Raid", 23 => "Burning Crusade", 41 => "Test", 3 => "Inutilisées" ) diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 17fb395b..592fc8d2 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -1390,7 +1390,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "Такая валюта не существует.", - 'cap' => "Максимум всего", + 'cap' => "Максимум всего: ", 'cat' => array( 1 => "Разное", 2 => "PvP", 4 => "World of Warcraft", 21 => "Wrath of the Lich King", 22 => "Подземелья и рейды", 23 => "Burning Crusade", 41 => "Test", 3 => "Неактивно" ) diff --git a/localization/locale_zhcn.php b/localization/locale_zhcn.php index bb35a340..25d38247 100644 --- a/localization/locale_zhcn.php +++ b/localization/locale_zhcn.php @@ -1389,7 +1389,7 @@ $lang = array( ), 'currency' => array( 'notFound' => "这个货币不存在。", - 'cap' => "总共上限", + 'cap' => "总共上限:", 'cat' => array( 1 => '其它', 2 => 'PvP', 3 => '未使用', 4 => '经典旧世', 21 => '巫妖王之怒',22 => '地下城与团队', 23 => '燃烧的远征', 41 => '测试' ) diff --git a/pages/currencies.php b/pages/currencies.php deleted file mode 100644 index dbdf57ca..00000000 --- a/pages/currencies.php +++ /dev/null @@ -1,59 +0,0 @@ -getCategoryFromUrl($pageParam); - - parent::__construct($pageCall, $pageParam); - - $this->name = Util::ucFirst(Lang::game('currencies')); - } - - protected function generateContent() - { - $conditions = []; - - if (!User::isInGroup(U_GROUP_EMPLOYEE)) - $conditions[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; - - if ($this->category) - $conditions[] = ['category', (int)$this->category[0]]; - - $money = new CurrencyList($conditions); - $this->lvTabs[] = [CurrencyList::$brickFile, ['data' => array_values($money->getListviewData())]]; - } - - protected function generateTitle() - { - array_unshift($this->title, $this->name); - if ($this->category) - array_unshift($this->title, Lang::currency('cat', $this->category[0])); - } - - protected function generatePath() - { - if ($this->category) - $this->path[] = $this->category[0]; - } -} - -?>