From e943e27b5bdb2721e9c791d5e8e85368c45abe2d Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 5 Aug 2025 21:50:15 +0200 Subject: [PATCH] Template/Update (Part 1) * update TrinityCore components to return new Frontend objects - SmartAI => Markup - Conditions => Data Listview * update template files to accept the new Frontend objects --- .../Conditions/Conditions.class.php | 2 +- includes/components/SmartAI/SmartAI.class.php | 19 ++- .../components/SmartAI/SmartAction.class.php | 8 +- includes/components/locstring.class.php | 3 +- includes/game/misc.php | 54 ++++----- localization/locale_dede.php | 1 + localization/locale_enus.php | 1 + localization/locale_eses.php | 1 + localization/locale_frfr.php | 1 + localization/locale_ruru.php | 1 + localization/locale_zhcn.php | 1 + pages/areatrigger.php | 2 +- pages/item.php | 3 +- pages/npc.php | 2 +- pages/object.php | 4 +- template/bricks/announcement.tpl.php | 15 +-- template/bricks/article.tpl.php | 13 -- template/bricks/book.tpl.php | 15 ++- template/bricks/infobox.tpl.php | 26 ++-- template/bricks/lvTabs.tpl.php | 111 ++++++------------ template/bricks/mail.tpl.php | 21 ++-- template/bricks/markup.tpl.php | 8 ++ template/bricks/reagentList.tpl.php | 63 +++++----- template/bricks/rewards.tpl.php | 19 ++- template/bricks/series.tpl.php | 27 +---- 25 files changed, 186 insertions(+), 235 deletions(-) delete mode 100644 template/bricks/article.tpl.php create mode 100644 template/bricks/markup.tpl.php diff --git a/includes/components/Conditions/Conditions.class.php b/includes/components/Conditions/Conditions.class.php index 1289477c..6168ca1f 100644 --- a/includes/components/Conditions/Conditions.class.php +++ b/includes/components/Conditions/Conditions.class.php @@ -345,7 +345,7 @@ class Conditions 'name' => ($name ?: '$LANG.tab_conditions') . '+" ('.$nCnd.')"' ); - return [null, $tab]; + return $tab; } // $keyX params are string(ref to lv column) or int(fixed value) diff --git a/includes/components/SmartAI/SmartAI.class.php b/includes/components/SmartAI/SmartAI.class.php index 3fb2f569..1518e426 100644 --- a/includes/components/SmartAI/SmartAI.class.php +++ b/includes/components/SmartAI/SmartAI.class.php @@ -651,32 +651,31 @@ class SmartAI return true; } - public function getMarkdown() : string + public function getMarkup() : ?Markup { # id | event (footer phase) | chance | action + target if (!$this->rawData) - return ''; + return null; - $return = '[style]#text-generic .grid { clear:left; } #text-generic .tabbed-contents { padding:0px; clear:left; }[/style][pad][h3][toggler id=sai]SmartAI'.$this->title.'[/toggler][/h3][div id=sai clear=left]%s[/div]'; + $wrapper = '[table class=grid width=940px]%s[/table]'; + $return = '[style]#smartai-generic .grid { clear:left; } #smartai-generic .tabbed-contents { padding:0px; clear:left; }[/style][pad][h3][toggler id=sai]SmartAI'.$this->title.'[/toggler][/h3][div id=sai clear=left]%s[/div]'; + $tabs = ''; if (count($this->tabs) > 1) { $wrapper = '[tabs name=sai width=942px]%s[/tabs]'; - $return = '[script]function TalTabClick(id) { $(\'#dsf67g4d-sai\').find(\\\'[href=\\\\\'#sai-actionlist-\' + id + \'\\\\\']\\\').click(); }[/script]' . $return; - $tabs = ''; + $return = "[script]function TalTabClick(id) { $('#dsf67g4d-sai').find('[href=\'#sai-actionlist-' + id + '\']').click(); }[/script]" . $return; foreach ($this->tabs as $guid => $data) { - $buff = '[tab name=\"'.($guid ? 'ActionList #'.$guid : 'Main').'\"][table class=grid width=940px]'.$data.'[/table][/tab]'; + $buff = '[tab name="'.($guid ? 'ActionList #'.$guid : 'Main').'"][table class=grid width=940px]'.$data.'[/table][/tab]'; if ($guid) $tabs .= $buff; else $tabs = $buff . $tabs; } - - return sprintf($return, sprintf($wrapper, $tabs)); } - else - return sprintf($return, '[table class=grid width=940px]'.$this->tabs[0].'[/table]'); + + return new Markup(sprintf($return, sprintf($wrapper, $tabs ?: $this->tabs[0])), ['allow' => Markup::CLASS_ADMIN], 'smartai-generic'); } public function addJsGlobals(array $jsg) : void diff --git a/includes/components/SmartAI/SmartAction.class.php b/includes/components/SmartAI/SmartAction.class.php index 0f23f409..c80c8b7f 100644 --- a/includes/components/SmartAI/SmartAction.class.php +++ b/includes/components/SmartAI/SmartAction.class.php @@ -713,12 +713,12 @@ class SmartAction break; case self::ACTION_TALK: // 1 -> any target case self::ACTION_SIMPLE_TALK: // 84 -> any target - $noSrc = false; - if ($npcId = $this->smartAI->getTarget()->getTalkSource($noSrc)) + $playerSrc = false; + if ($npcId = $this->smartAI->getTarget()->getTalkSource($playerSrc)) { if ($quotes = $this->smartAI->getQuote($npcId, $this->param[0], $npcSrc)) - foreach ($quotes as ['text' => $text, 'prefix' => $prefix]) - $this->param[10] .= sprintf($text, $noSrc ? '' : sprintf($prefix, $npcSrc), $npcSrc); + foreach ($quotes as ['text' => $text]) + $this->param[10] .= sprintf($text, $playerSrc ? Lang::main('thePlayer') : $npcSrc); } else trigger_error('SmartAI::action - could not determine talk source for action #'.$this->type); diff --git a/includes/components/locstring.class.php b/includes/components/locstring.class.php index 646c1fd4..53da1fc9 100644 --- a/includes/components/locstring.class.php +++ b/includes/components/locstring.class.php @@ -20,7 +20,8 @@ class LocString trigger_error('LocString - is entrirely empty', E_USER_WARNING); foreach (Locale::cases() as $l) - $this->store[$l] = (string)$callback($data[$key.'_loc'.$l->value] ?? ''); + if ($l->validate()) + $this->store[$l] = (string)$callback($data[$key.'_loc'.$l->value] ?? ''); } public function __toString() : string diff --git a/includes/game/misc.php b/includes/game/misc.php index 069b0369..12199e20 100644 --- a/includes/game/misc.php +++ b/includes/game/misc.php @@ -191,24 +191,23 @@ class Game return $data; } - public static function getPageText($ptId) + public static function getBook(int $ptId, ?int $startPage = null) : ?Book { $pages = []; while ($ptId) { - if ($row = DB::World()->selectRow('SELECT ptl.Text AS Text_loc?d, pt.* FROM page_text pt LEFT JOIN page_text_locale ptl ON pt.ID = ptl.ID AND locale = ? WHERE pt.ID = ?d', Lang::getLocale()->value, Lang::getLocale()->json(), $ptId)) + if ($row = DB::World()->selectRow('SELECT ptl.`Text` AS Text_loc?d, pt.* FROM page_text pt LEFT JOIN page_text_locale ptl ON pt.`ID` = ptl.`ID` AND locale = ? WHERE pt.`ID` = ?d', Lang::getLocale()->value, Lang::getLocale()->json(), $ptId)) { $ptId = $row['NextPageID']; - $pages[] = Util::parseHtmlText(Util::localizedString($row, 'Text')); - } - else - { - trigger_error('Referenced PageTextId #'.$ptId.' is not in DB', E_USER_WARNING); - break; + $pages[] = Util::localizedString($row, 'Text'); + continue; } + + trigger_error('Referenced PageTextId #'.$ptId.' is not in DB', E_USER_WARNING); + break; } - return $pages; + return $pages ? new Book($pages, page: $startPage) : null; } public static function getQuotesForCreature(int $creatureId, bool $asHTML = false, string $talkSource = '') : array @@ -256,40 +255,33 @@ class Game if ($talkSource) $msg = sprintf($msg, $talkSource); - // make type css compatible - switch ($t['talkType']) + // convert [old, new] talkType to css compatible + $t['talkType'] = match ((int)$t['talkType']) { - case 1: // yell: - case 14: $t['talkType'] = 1; break; // - dark red - case 2: // emote: - case 16: // " - case 3: // boss emote: - case 41: $t['talkType'] = 4; break; // - orange - case 4: // whisper: - case 15: // " - case 5: // boss whisper: - case 42: $t['talkType'] = 3; break; // - pink-ish - default: $t['talkType'] = 2; // [type: 0, 12] say: yellow-ish - - } + 0, 12 => 2, // say - yellow-ish + 1, 14 => 1, // yell - dark red + 2, 16, // emote + 3, 41 => 4, // boss emote - orange + 4, 15, // whisper + 5, 42 => 3, // boss whisper - pink-ish + default => 2 + }; // prefix - $pre = ''; + $prefix = '%s '; if ($t['talkType'] != 4) - $pre = ($talkSource ?: '%s').' '.Lang::npc('textTypes', $t['talkType']).Lang::main('colon').($t['lang'] ? '['.Lang::game('languages', $t['lang']).'] ' : null); + $prefix = ($talkSource ?: '%s').' '.Lang::npc('textTypes', $t['talkType']).Lang::main('colon').($t['lang'] ? '['.Lang::game('languages', $t['lang']).'] ' : ' '); if ($asHTML) - $msg = '
%s'.($t['range'] ? sprintf(Util::$dfnString, Lang::npc('textRanges', $t['range']), $msg) : $msg).'
'; + $msg = '
'.$prefix.($t['range'] ? sprintf(Util::$dfnString, Lang::npc('textRanges', $t['range']), $msg) : $msg).'
'; else - $msg = '[div][span class=s'.$t['talkType'].']%s'.html_entity_decode($msg).'[/span][/div]'; + $msg = '[div][span class=s'.$t['talkType'].']'.$prefix.html_entity_decode($msg).'[/span][/div]'; $line = array( 'range' => $t['range'], - 'text' => $msg, - 'prefix' => $pre + 'text' => $msg ); - $nQuotes++; $group[] = $line; } diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 75114e9a..9bc36a18 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -33,6 +33,7 @@ $lang = array( 'gender' => "Geschlecht", 'sex' => [null, "Mann", "Frau"], 'players' => "Spieler", + 'thePlayer' => "Der Spieler", 'quickFacts' => "Kurzübersicht", 'screenshots' => "Screenshots", 'videos' => "Videos", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index 4143113f..b83cbbf8 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -33,6 +33,7 @@ $lang = array( 'gender' => "Gender", 'sex' => [null, "Male", "Female"], 'players' => "Players", + 'thePlayer' => "The Player", 'quickFacts' => "Quick Facts", 'screenshots' => "Screenshots", 'videos' => "Videos", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index f7fca369..66dc8e76 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -33,6 +33,7 @@ $lang = array( 'gender' => "Género", 'sex' => [null, "Hombre", "Mujer"], 'players' => "Jugadores", + 'thePlayer' => "El Jugador", 'quickFacts' => "Notas rápidas", 'screenshots' => "Capturas de pantalla", 'videos' => "Videos", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 96cf5cac..406062a9 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -33,6 +33,7 @@ $lang = array( 'gender' => "Genre", 'sex' => [null, "Homme", "Femme"], 'players' => "Joueurs", + 'thePlayer' => "Le joueur", 'quickFacts' => "En bref", 'screenshots' => "Captures d'écran", 'videos' => "Vidéos", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 51f94bf5..f7e80ba0 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -33,6 +33,7 @@ $lang = array( 'gender' => "Пол", 'sex' => [null, "Мужчина", "Женщина"], 'players' => "Игрокам", + 'thePlayer' => "Игрок", 'quickFacts' => "Краткая информация", 'screenshots' => "Изображения", 'videos' => "Видео", diff --git a/localization/locale_zhcn.php b/localization/locale_zhcn.php index ca3df816..7a20fbd9 100644 --- a/localization/locale_zhcn.php +++ b/localization/locale_zhcn.php @@ -34,6 +34,7 @@ $lang = array( 'gender' => "性别", 'sex' => [null, "男性", "女性"], 'players' => "玩家", + 'thePlayer' => "玩家", 'quickFacts' => "相关信息", 'screenshots' => "屏幕截图", 'videos' => "视频", diff --git a/pages/areatrigger.php b/pages/areatrigger.php index 8bf4d3e2..ecae884d 100644 --- a/pages/areatrigger.php +++ b/pages/areatrigger.php @@ -74,7 +74,7 @@ class AreaTriggerPage extends GenericPage $this->map = $map; $this->infobox = false; - $this->smartAI = $sai?->getMarkdown(); + $this->smartAI = $sai?->getMarkup(); $this->redButtons = array( BUTTON_LINKS => false, BUTTON_WOWHEAD => false diff --git a/pages/item.php b/pages/item.php index a85a52ba..ad21cc58 100644 --- a/pages/item.php +++ b/pages/item.php @@ -382,8 +382,7 @@ class ItemPage extends genericPage $_cu = in_array($_class, [ITEM_CLASS_WEAPON, ITEM_CLASS_ARMOR]) || $this->subject->getField('gemEnchantmentId'); // pageText - $pageText = []; - if ($this->pageText = Game::getPageText($this->subject->getField('pageTextId'))) + if ($this->pageText = Game::getBook($this->subject->getField('pageTextId'))) $this->addScript( [SC_JS_FILE, 'js/Book.js'], [SC_CSS_FILE, 'css/Book.css'] diff --git a/pages/npc.php b/pages/npc.php index 703f19f4..da173275 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -406,7 +406,7 @@ class NpcPage extends GenericPage $this->accessory = $accessory; $this->quotes = $this->getQuotes(); $this->reputation = $this->getOnKillRep($_altIds, $mapType); - $this->smartAI = $sai ? $sai->getMarkdown() : null; + $this->smartAI = $sai ? $sai->getMarkup() : null; $this->redButtons = array( BUTTON_WOWHEAD => true, BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId], diff --git a/pages/object.php b/pages/object.php index 8abc3f31..762a47aa 100644 --- a/pages/object.php +++ b/pages/object.php @@ -212,7 +212,7 @@ class ObjectPage extends GenericPage /****************/ // pageText - if ($this->pageText = Game::getPageText($this->subject->getField('pageTextId'))) + if ($this->pageText = Game::getBook($this->subject->getField('pageTextId'))) $this->addScript( [SC_JS_FILE, 'js/Book.js'], [SC_CSS_FILE, 'css/Book.css'] @@ -271,7 +271,7 @@ class ObjectPage extends GenericPage $this->map = $map; $this->infobox = $infobox ? '[ul][li]'.implode('[/li][li]', $infobox).'[/li][/ul]' : null; $this->relBoss = $relBoss; - $this->smartAI = $sai ? $sai->getMarkdown() : null; + $this->smartAI = $sai ? $sai->getMarkup() : null; $this->redButtons = array( BUTTON_WOWHEAD => true, BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId], diff --git a/template/bricks/announcement.tpl.php b/template/bricks/announcement.tpl.php index c3628d5e..4f674a06 100644 --- a/template/bricks/announcement.tpl.php +++ b/template/bricks/announcement.tpl.php @@ -1,12 +1,9 @@ - +announcements as $id => $data): -?> -
+foreach ($this->announcements as $a): ?> +
- + diff --git a/template/bricks/article.tpl.php b/template/bricks/article.tpl.php deleted file mode 100644 index 9df83fbf..00000000 --- a/template/bricks/article.tpl.php +++ /dev/null @@ -1,13 +0,0 @@ - - -article)): -?> -
- -
- diff --git a/template/bricks/book.tpl.php b/template/bricks/book.tpl.php index 2116874e..2ef56dc4 100644 --- a/template/bricks/book.tpl.php +++ b/template/bricks/book.tpl.php @@ -1,15 +1,14 @@ - - pageText)): -?> + namespace Aowow\Template; + + use \Aowow\Lang; + +if ($this->book): ?>

- + diff --git a/template/bricks/infobox.tpl.php b/template/bricks/infobox.tpl.php index 672e0055..d9ca62ed 100644 --- a/template/bricks/infobox.tpl.php +++ b/template/bricks/infobox.tpl.php @@ -1,38 +1,42 @@ - + infobox) || !empty($this->contributions) || !empty($this->series) || $this->contribute & (CONTRIBUTE_SS | CONTRIBUTE_VI)): +if ($this->infobox || $this->contributions || $this->series || $this->contribute & (CONTRIBUTE_SS | CONTRIBUTE_VI)): echo " \n"; - if (!empty($this->infobox)): + if ($this->infobox): ?> contributions)): + if ($this->contributions): ?> series)): - foreach ($this->series as $s): - $this->brick('series', ['list' => $s[0], 'listTitle' => $s[1]]); + if ($this->series): + foreach ($this->series as [$list, $title]): + $this->brick('series', ['list' => $list, 'listTitle' => $title]); endforeach; endif; @@ -43,7 +47,7 @@ echo "
\n"; contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): + if ($this->contribute & CONTRIBUTE_VI && ($this->user::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): ?> @@ -56,7 +60,7 @@ echo "
\n"; contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): + if ($this->contribute & CONTRIBUTE_VI && ($this->user::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): ?> +lvTabs) || !empty($this->user['characterData']) || !empty($this->user['profileData']) || $this->contribute): - $relTabs = !empty($relTabs); - $tabVar = $relTabs || !empty($this->user) ? 'tabsRelated' : 'myTabs'; - $isTabbed = !empty($this->forceTabs) || $relTabs || count($this->lvTabs) > 1; - - // lvTab: [file, data, extraInclude] - - if ($isTabbed): +if (($this->lvTabs && count($this->lvTabs)) || $this->charactersLvData || $this->profilesLvData || $this->contribute): + if ($this->lvTabs?->isTabbed()): ?>
-
lvTabs as [$tplName, $tabData]): - if ($tplName): - continue; - endif; - - echo ''; +
+lvTabs?->getDataContainer() ?? [] as $container): + echo ' '.$container."\n"; endforeach; - ?>
+?> +
diff --git a/template/bricks/mail.tpl.php b/template/bricks/mail.tpl.php index ed922c35..643c2922 100644 --- a/template/bricks/mail.tpl.php +++ b/template/bricks/mail.tpl.php @@ -1,11 +1,12 @@ - - mail): - if (!isset($offset)) // in case we have multiple icons on the page (prominently quest-rewards) - $offset = 0; + namespace Aowow\Template; - echo '

'.sprintf(Lang::mail('mailDelivery'), $m['id'], $m['sender'], $m['delay'])."

\n"; + use \Aowow\Lang; + +if ($m = $this->mail): + $offset ??= 0; // in case we have multiple icons on the page (prominently quest-rewards) + + echo '

'.Lang::mail('mailDelivery', $m['header'])."

\n"; if ($m['subject']): echo '
'.$m['subject']."
\n"; @@ -19,16 +20,16 @@ if ($m = $this->mail): ?>
$i): - echo '\n"; + foreach ($m['attachments'] as $icon): + echo $icon->renderContainer(20, $offset, true); endforeach; ?>
'.$i['name']."
diff --git a/template/bricks/markup.tpl.php b/template/bricks/markup.tpl.php new file mode 100644 index 00000000..69801b13 --- /dev/null +++ b/template/bricks/markup.tpl.php @@ -0,0 +1,8 @@ + + +
+ +
+ diff --git a/template/bricks/reagentList.tpl.php b/template/bricks/reagentList.tpl.php index 0392d992..b512ee44 100644 --- a/template/bricks/reagentList.tpl.php +++ b/template/bricks/reagentList.tpl.php @@ -1,4 +1,8 @@ - +

@@ -6,18 +10,20 @@ if ($enhanced): ?> diff --git a/template/bricks/rewards.tpl.php b/template/bricks/rewards.tpl.php index b97c60fd..12e70c5e 100644 --- a/template/bricks/rewards.tpl.php +++ b/template/bricks/rewards.tpl.php @@ -1,12 +1,10 @@ - - $i): - echo ''.$i['name']."\n"; - echo $k % 2 ? '' : null; + $last = array_key_last($rewards); + foreach ($rewards as $k => $icon): + echo $icon->renderContainer(24, $offset); + echo $k % 2 && $k != $last ? str_repeat(' ', 24) . "" : ''; endforeach; if (count($rewards) % 2): @@ -29,8 +28,8 @@ if ($rewards): diff --git a/template/bricks/series.tpl.php b/template/bricks/series.tpl.php index bd561b6a..8a1ec0ba 100644 --- a/template/bricks/series.tpl.php +++ b/template/bricks/series.tpl.php @@ -1,4 +1,8 @@ - + @@ -6,26 +10,7 @@ $itr): - echo ' \n"; + echo $this->renderSeriesItem($idx, $itr, 12); endforeach; ?>
'.($idx + 1).'
'; - - $_ = array_keys($itr); - $end = array_pop($_); - foreach ($itr as $k => $i): // itemItr - switch ($i['side']): - case 1: $wrap = '%s'; break; - case 2: $wrap = '%s'; break; - default: $wrap = '%s'; break; - endswitch; - - if ($i['typeId'] == $this->typeId): - echo sprintf($wrap, ''.$i['name'].''); - else: - echo sprintf($wrap, ''.$i['name'].''); - endif; - - echo $end == $k ? null : '
'; - endforeach; - echo "