From 3cb02f22044ba528b8f90dcaf5e5c86128812c88 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 12 Mar 2022 23:59:06 +0100 Subject: [PATCH] JS/CSS * unify handling --- includes/defines.php | 5 ++++ pages/account.php | 4 +-- pages/achievement.php | 2 +- pages/achievements.php | 2 +- pages/admin.php | 38 ++++++++++++++------------ pages/areatrigger.php | 2 +- pages/areatriggers.php | 2 +- pages/arenateam.php | 6 ++-- pages/arenateams.php | 4 +-- pages/class.php | 4 +-- pages/compare.php | 14 +++++----- pages/currency.php | 2 +- pages/enchantments.php | 2 +- pages/event.php | 2 +- pages/faction.php | 2 +- pages/genericPage.class.php | 53 ++++++++++++++++++------------------ pages/guild.php | 6 ++-- pages/guilds.php | 4 +-- pages/home.php | 6 ++-- pages/icons.php | 2 +- pages/item.php | 14 ++++++---- pages/items.php | 4 +-- pages/itemset.php | 5 +--- pages/itemsets.php | 4 +-- pages/maps.php | 6 ++-- pages/more.php | 2 +- pages/npc.php | 6 ++-- pages/npcs.php | 4 +-- pages/object.php | 10 ++++--- pages/objects.php | 4 +-- pages/pet.php | 4 +-- pages/profile.php | 15 +++++++--- pages/profiler.php | 6 ++-- pages/profiles.php | 6 ++-- pages/quest.php | 6 ++-- pages/quests.php | 2 +- pages/race.php | 2 +- pages/screenshot.php | 4 +-- pages/search.php | 4 +-- pages/skill.php | 2 +- pages/sound.php | 4 +-- pages/sounds.php | 2 +- pages/spell.php | 4 +-- pages/spells.php | 2 +- pages/talent.php | 22 +++++++++------ pages/user.php | 6 ++-- pages/zone.php | 4 +-- pages/zones.php | 2 +- template/bricks/head.tpl.php | 20 +++++++------- 49 files changed, 179 insertions(+), 159 deletions(-) diff --git a/includes/defines.php b/includes/defines.php index d3545a48..263f09c0 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -64,6 +64,11 @@ define('CACHE_TYPE_XML', 4); // only used by item define('CACHE_MODE_FILECACHE', 0x1); define('CACHE_MODE_MEMCACHED', 0x2); +define ('CSS_FILE', 1); +define ('CSS_STRING', 2); +define ('JS_FILE', 3); +define ('JS_STRING', 4); + define('SEARCH_TYPE_REGULAR', 0x10000000); define('SEARCH_TYPE_OPEN', 0x20000000); define('SEARCH_TYPE_JSON', 0x40000000); diff --git a/pages/account.php b/pages/account.php index d38d2685..c6710298 100644 --- a/pages/account.php +++ b/pages/account.php @@ -8,8 +8,8 @@ if (!defined('AOWOW_REVISION')) class AccountPage extends GenericPage { protected $tpl = 'acc-dashboard'; - protected $js = ['user.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'user.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; protected $mode = CACHE_TYPE_NONE; protected $category = null; protected $validCats = array( diff --git a/pages/achievement.php b/pages/achievement.php index 80e5339d..faf6f9c5 100644 --- a/pages/achievement.php +++ b/pages/achievement.php @@ -173,7 +173,7 @@ class AchievementPage extends GenericPage ); if ($reqBook) - $this->addCss(['path' => 'Book.css']); + $this->addScript([CSS_FILE, 'Book.css']); // create rewards if ($foo = $this->subject->getField('rewards')) diff --git a/pages/achievements.php b/pages/achievements.php index 6b28239d..8579badb 100644 --- a/pages/achievements.php +++ b/pages/achievements.php @@ -15,7 +15,7 @@ class AchievementsPage extends GenericPage protected $path = [0, 9]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/admin.php b/pages/admin.php index 09a450f9..b4cb7e37 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -73,15 +73,15 @@ class AdminPage extends GenericPage private function handleConfig() { - $this->addCSS(array( - ['string' => '.grid input[type=\'text\'], .grid input[type=\'number\'] { width:250px; text-align:left; }'], - ['string' => '.grid input[type=\'button\'] { width:65px; padding:2px; }'], - ['string' => '.grid a.tip { margin:0px 5px; opacity:0.8; }'], - ['string' => '.grid a.tip:hover { opacity:1; }'], - ['string' => '.grid tr { height:30px; }'], - ['string' => '.grid .disabled { opacity:0.4 !important; }'], - ['string' => '.grid .status { position:absolute; right:5px; }'], - )); + $this->addScript( + [CSS_STRING, '.grid input[type=\'text\'], .grid input[type=\'number\'] { width:250px; text-align:left; }'], + [CSS_STRING, '.grid input[type=\'button\'] { width:65px; padding:2px; }'], + [CSS_STRING, '.grid a.tip { margin:0px 5px; opacity:0.8; }'], + [CSS_STRING, '.grid a.tip:hover { opacity:1; }'], + [CSS_STRING, '.grid tr { height:30px; }'], + [CSS_STRING, '.grid .disabled { opacity:0.4 !important; }'], + [CSS_STRING, '.grid .status { position:absolute; right:5px; }'], + ); $head = ''; $mainTab = []; @@ -123,8 +123,8 @@ class AdminPage extends GenericPage private function handlePhpInfo() { - $this->addCSS([ - 'string' => "\npre {margin: 0px; font-family: monospace;}\n" . + $this->addScript([ + CSS_STRING, "\npre {margin: 0px; font-family: monospace;}\n" . "td, th { border: 1px solid #000000; vertical-align: baseline;}\n" . ".p {text-align: left;}\n" . ".e {background-color: #ccccff; font-weight: bold; color: #000000;}\n" . @@ -187,11 +187,11 @@ class AdminPage extends GenericPage private function handleScreenshots() { - $this->addJS('screenshot.js'); - $this->addCSS(array( - ['string' => '.layout {margin: 0px 25px; max-width: inherit; min-width: 1200px; }'], - ['string' => '#highlightedRow { background-color: #322C1C; }'] - )); + $this->addScript( + [JS_FILE, 'screenshot.js'], + [CSS_STRING, '.layout {margin: 0px 25px; max-width: inherit; min-width: 1200px; }'], + [CSS_STRING, '#highlightedRow { background-color: #322C1C; }'], + ); $ssGetAll = $this->_get['all']; $ssPages = []; @@ -225,8 +225,10 @@ class AdminPage extends GenericPage private function handleWeightPresets() { - $this->addCSS(['string' => '.wt-edit {display:inline-block; vertical-align:top; width:350px;}']); - $this->addJS('filters.js'); + $this->addScript( + [JS_FILE, 'filters.js'], + [CSS_STRING, '.wt-edit {display:inline-block; vertical-align:top; width:350px;}'], + ); $head = $body = ''; diff --git a/pages/areatrigger.php b/pages/areatrigger.php index b6aff173..8071d111 100644 --- a/pages/areatrigger.php +++ b/pages/areatrigger.php @@ -45,7 +45,7 @@ class AreaTriggerPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $_type = $this->subject->getField('type'); diff --git a/pages/areatriggers.php b/pages/areatriggers.php index 0f95841b..a2906a5d 100644 --- a/pages/areatriggers.php +++ b/pages/areatriggers.php @@ -16,7 +16,7 @@ class AreaTriggersPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = [0, 1, 2, 3, 4, 5]; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $reqUGroup = U_GROUP_STAFF; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/arenateam.php b/pages/arenateam.php index 83831ebe..97f974f3 100644 --- a/pages/arenateam.php +++ b/pages/arenateam.php @@ -17,8 +17,8 @@ class ArenaTeamPage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 3]; protected $tpl = 'roster'; - protected $js = ['profile_all.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; public function __construct($pageCall, $pageParam) { @@ -97,7 +97,7 @@ class ArenaTeamPage extends GenericPage if ($this->doResync) return; - $this->addJS('?data=realms.weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=realms.weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $this->redButtons[BUTTON_RESYNC] = [$this->subjectGUID, 'arena-team']; diff --git a/pages/arenateams.php b/pages/arenateams.php index d5a81c52..bc6a3c2d 100644 --- a/pages/arenateams.php +++ b/pages/arenateams.php @@ -15,7 +15,7 @@ class ArenaTeamsPage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 3]; protected $tpl = 'arena-teams'; - protected $js = ['filters.js', 'profile_all.js', 'profile.js']; + protected $js = [[JS_FILE, 'filters.js'], [JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -57,7 +57,7 @@ class ArenaTeamsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; if (!User::isInGroup(U_GROUP_EMPLOYEE)) diff --git a/pages/class.php b/pages/class.php index 241d59af..193a0f6f 100644 --- a/pages/class.php +++ b/pages/class.php @@ -16,7 +16,7 @@ class ClassPage extends GenericPage protected $path = [0, 12]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; public function __construct($pageCall, $id) { @@ -43,7 +43,7 @@ class ClassPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); $_mask = 1 << ($this->typeId - 1); diff --git a/pages/compare.php b/pages/compare.php index a53f6c3f..ee5d6d8d 100644 --- a/pages/compare.php +++ b/pages/compare.php @@ -12,13 +12,13 @@ class ComparePage extends GenericPage protected $path = [1, 3]; protected $mode = CACHE_TYPE_NONE; protected $js = array( - 'profile.js', - 'Draggable.js', - 'filters.js', - 'Summary.js', - 'swfobject.js', + [JS_FILE, 'profile.js'], + [JS_FILE, 'Draggable.js'], + [JS_FILE, 'filters.js'], + [JS_FILE, 'Summary.js'], + [JS_FILE, 'swfobject.js'], ); - protected $css = [['path' => 'Summary.css']]; + protected $css = [[CSS_FILE, 'Summary.css']]; protected $summary = []; protected $cmpItems = []; @@ -44,7 +44,7 @@ class ComparePage extends GenericPage protected function generateContent() { // add conditional js - $this->addJS('?data=weight-presets.gems.enchants.itemsets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets.gems.enchants.itemsets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $this->summary = array( 'template' => 'compare', diff --git a/pages/currency.php b/pages/currency.php index c2dd3945..c8d9b7bb 100644 --- a/pages/currency.php +++ b/pages/currency.php @@ -50,7 +50,7 @@ class CurrencyPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $_itemId = $this->subject->getField('itemId'); diff --git a/pages/enchantments.php b/pages/enchantments.php index bd56a168..25bf598f 100644 --- a/pages/enchantments.php +++ b/pages/enchantments.php @@ -15,7 +15,7 @@ class EnchantmentsPage extends GenericPage protected $path = [0, 101]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js']; + protected $js =[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/event.php b/pages/event.php index 256e8752..31ea8755 100644 --- a/pages/event.php +++ b/pages/event.php @@ -67,7 +67,7 @@ class EventPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); /***********/ /* Infobox */ diff --git a/pages/faction.php b/pages/faction.php index 35a0e691..19e49f06 100644 --- a/pages/faction.php +++ b/pages/faction.php @@ -48,7 +48,7 @@ class FactionPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); /***********/ /* Infobox */ diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 032cf878..c981764c 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -426,35 +426,36 @@ class GenericPage $this->sumSQLStats(); } - public function addJS($name, bool $unshift = false) : void + public function addScript(array ...$structs) : void { - if (is_array($name)) + foreach ($structs as $s) // iType, sContent, bFront, sIeCnd { - foreach ($name as $n) - $this->addJS($n, $unshift); - } - else if (!in_array($name, $this->js)) - { - if ($unshift) - array_unshift($this->js, $name); - else - $this->js[] = $name; - } - } + if (empty($s[1])) + { + trigger_error('GenericPage::addScript - content empty', E_USER_WARNING); + continue; + } - public function addCSS(array $struct, bool $unshift = false) : void - { - if (is_array($struct) && empty($struct['path']) && empty($struct['string'])) - { - foreach ($struct as $s) - $this->addCSS($s, $unshift); - } - else if (!in_array($struct, $this->css)) - { - if ($unshift) - array_unshift($this->css, $struct); - else - $this->css[] = $struct; + $s = array_pad($s, 4, ''); + switch ($s[0]) + { + case JS_FILE: + case JS_STRING: + if (empty($s[2])) + $this->js[] = $s; + else + array_unshift($this->js, $s); + break; + case CSS_FILE: + case CSS_STRING: + if (empty($s[2])) + $this->css[] = $s; + else + array_unshift($this->css, $s); + break; + default: + trigger_error('GenericPage::addScript - unknown script type #'.$s[0], E_USER_WARNING); + } } } diff --git a/pages/guild.php b/pages/guild.php index 68cb836d..14bbcb6a 100644 --- a/pages/guild.php +++ b/pages/guild.php @@ -17,8 +17,8 @@ class GuildPage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 2]; protected $tpl = 'roster'; - protected $js = ['profile_all.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; public function __construct($pageCall, $pageParam) { @@ -97,7 +97,7 @@ class GuildPage extends GenericPage if ($this->doResync) return; - $this->addJS('?data=realms.weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=realms.weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $this->redButtons[BUTTON_RESYNC] = [$this->subjectGUID, 'guild']; diff --git a/pages/guilds.php b/pages/guilds.php index 2e09cd1d..d346358b 100644 --- a/pages/guilds.php +++ b/pages/guilds.php @@ -15,7 +15,7 @@ class GuildsPage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 2]; protected $tpl = 'guilds'; - protected $js = ['filters.js', 'profile_all.js', 'profile.js']; + protected $js = [[JS_FILE, 'filters.js'], [JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -57,7 +57,7 @@ class GuildsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = array( ['c.deleteInfos_Account', null], diff --git a/pages/home.php b/pages/home.php index 4eda5d31..36b0f4f7 100644 --- a/pages/home.php +++ b/pages/home.php @@ -7,8 +7,8 @@ if (!defined('AOWOW_REVISION')) class HomePage extends GenericPage { protected $tpl = 'home'; - protected $js = ['home.js']; - protected $css = [['path' => 'home.css']]; + protected $js = [[JS_FILE, 'home.js']]; + protected $css = [[CSS_FILE, 'home.css']]; protected $featuredBox = []; protected $oneliner = ''; @@ -21,7 +21,7 @@ class HomePage extends GenericPage protected function generateContent() { - $this->addCSS(['string' => '.announcement { margin: auto; max-width: 1200px; padding: 0px 15px 15px 15px }']); + $this->addScript([CSS_STRING, '.announcement { margin: auto; max-width: 1200px; padding: 0px 15px 15px 15px }']); // load oneliner if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE active = 1 LIMIT 1')) diff --git a/pages/icons.php b/pages/icons.php index 5f029672..60179f4c 100644 --- a/pages/icons.php +++ b/pages/icons.php @@ -15,7 +15,7 @@ class IconsPage extends GenericPage protected $path = [0, 31]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/item.php b/pages/item.php index 7a1f22a9..a080f566 100644 --- a/pages/item.php +++ b/pages/item.php @@ -18,9 +18,9 @@ class ItemPage extends genericPage protected $mode = CACHE_TYPE_PAGE; protected $enhancedTT = []; protected $js = array( - 'swfobject.js', // view in 3d, ok - 'profile.js', // item upgrade search, also ok - 'filters.js' // lolwut? + [JS_FILE, 'swfobject.js'], // view in 3d, ok + [JS_FILE, 'profile.js'], // item upgrade search, also ok + [JS_FILE, 'filters.js'] // lolwut? ); protected $_get = array( @@ -121,7 +121,7 @@ class ItemPage extends genericPage protected function generateContent() { - $this->addJS('?data=weight-presets.zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets.zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $_flags = $this->subject->getField('flags'); $_slot = $this->subject->getField('slot'); @@ -349,8 +349,10 @@ class ItemPage extends genericPage $pageText = []; if ($this->pageText = Game::getPageText($this->subject->getField('pageTextId'))) { - $this->addJS('Book.js'); - $this->addCSS(['path' => 'Book.css']); + $this->addScript( + [JS_FILE, 'Book.js'], + [CSS_FILE, 'Book.css'] + ); } $this->headIcons = [$this->subject->getField('iconString', true, true), $this->subject->getField('stackable')]; diff --git a/pages/items.php b/pages/items.php index 9200081b..7beb12f4 100644 --- a/pages/items.php +++ b/pages/items.php @@ -15,7 +15,7 @@ class ItemsPage extends GenericPage protected $path = [0, 0]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js', 'swfobject.js']; + protected $js = [[JS_FILE, 'filters.js'], [JS_FILE, 'swfobject.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -96,7 +96,7 @@ class ItemsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; diff --git a/pages/itemset.php b/pages/itemset.php index 9d9c9b15..5a467249 100644 --- a/pages/itemset.php +++ b/pages/itemset.php @@ -16,10 +16,7 @@ class ItemsetPage extends GenericPage protected $path = [0, 2]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = array( - 'swfobject.js', - 'Summary.js' - ); + protected $js = [[JS_FILE, 'swfobject.js'], [JS_FILE, 'Summary.js']]; protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkDomain']]; diff --git a/pages/itemsets.php b/pages/itemsets.php index db7494ee..ff2deb58 100644 --- a/pages/itemsets.php +++ b/pages/itemsets.php @@ -15,7 +15,7 @@ class ItemsetsPage extends GenericPage protected $path = [0, 2]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -31,7 +31,7 @@ class ItemsetsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; diff --git a/pages/maps.php b/pages/maps.php index e25dfb37..2ab00810 100644 --- a/pages/maps.php +++ b/pages/maps.php @@ -11,8 +11,8 @@ class MapsPage extends GenericPage protected $tabId = 1; protected $path = [1, 1]; protected $mode = CACHE_TYPE_NONE; - protected $js = ['maps.js']; - protected $css = [['string' => 'zone-picker { margin-left: 4px }']]; + protected $js = [[JS_FILE, 'maps.js']]; + protected $css = [[CSS_STRING, 'zone-picker { margin-left: 4px }']]; public function __construct($pageCall, $__) { @@ -24,7 +24,7 @@ class MapsPage extends GenericPage protected function generateContent() { // add conditional js - $this->addJS('?data=zones&locale=' . User::$localeId . '&t=' . $_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); } protected function generateTitle() diff --git a/pages/more.php b/pages/more.php index 7cad1123..ea1b8532 100644 --- a/pages/more.php +++ b/pages/more.php @@ -14,7 +14,7 @@ class MorePage extends GenericPage protected $path = []; protected $tabId = 0; protected $mode = CACHE_TYPE_NONE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; private $page = []; private $req2priv = array( diff --git a/pages/npc.php b/pages/npc.php index 8e88ed63..26b24d06 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -16,8 +16,8 @@ class NpcPage extends GenericPage protected $path = [0, 4]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'swfobject.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkDomain']]; @@ -57,7 +57,7 @@ class NpcPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $_typeFlags = $this->subject->getField('typeFlags'); $_altIds = []; diff --git a/pages/npcs.php b/pages/npcs.php index db2410e8..9a06a70a 100644 --- a/pages/npcs.php +++ b/pages/npcs.php @@ -16,7 +16,7 @@ class NpcsPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -33,7 +33,7 @@ class NpcsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; diff --git a/pages/object.php b/pages/object.php index 87b2bd09..6122828f 100644 --- a/pages/object.php +++ b/pages/object.php @@ -16,7 +16,7 @@ class ObjectPage extends GenericPage protected $path = [0, 5]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkDomain']]; @@ -51,7 +51,7 @@ class ObjectPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); /***********/ /* Infobox */ @@ -215,8 +215,10 @@ class ObjectPage extends GenericPage // pageText if ($this->pageText = Game::getPageText($next = $this->subject->getField('pageTextId'))) { - $this->addCSS(['path' => 'Book.css']); - $this->addJS('Book.js'); + $this->addScript( + [JS_FILE, 'Book.js'], + [CSS_FILE, 'Book.css'] + ); } // get spawns and path diff --git a/pages/objects.php b/pages/objects.php index 1932d977..67508336 100644 --- a/pages/objects.php +++ b/pages/objects.php @@ -16,7 +16,7 @@ class ObjectsPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = [-2, -3, -4, -5, -6, 0, 3, 9, 25]; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -33,7 +33,7 @@ class ObjectsPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; diff --git a/pages/pet.php b/pages/pet.php index 7482f062..67eda397 100644 --- a/pages/pet.php +++ b/pages/pet.php @@ -16,7 +16,7 @@ class PetPage extends GenericPage protected $path = [0, 8]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; public function __construct($pageCall, $id) { @@ -43,7 +43,7 @@ class PetPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); /***********/ /* Infobox */ diff --git a/pages/profile.php b/pages/profile.php index d71fe4ae..11d0f30c 100644 --- a/pages/profile.php +++ b/pages/profile.php @@ -18,10 +18,17 @@ class ProfilePage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 1]; protected $tpl = 'profile'; - protected $js = ['filters.js', 'TalentCalc.js', 'swfobject.js', 'profile_all.js', 'profile.js', 'Profiler.js']; + protected $js = array( + [JS_FILE, 'filters.js'], + [JS_FILE, 'TalentCalc.js'], + [JS_FILE, 'swfobject.js'], + [JS_FILE, 'profile_all.js'], + [JS_FILE, 'profile.js'], + [JS_FILE, 'Profiler.js'] + ); protected $css = array( - ['path' => 'talentcalc.css'], - ['path' => 'Profiler.css'] + [CSS_FILE, 'talentcalc.css'], + [CSS_FILE, 'Profiler.css'] ); protected $_get = array( @@ -142,7 +149,7 @@ class ProfilePage extends GenericPage return; // + .titles ? - $this->addJS('?data=enchants.gems.glyphs.itemsets.pets.pet-talents.quick-excludes.realms.statistics.weight-presets.achievements&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=enchants.gems.glyphs.itemsets.pets.pet-talents.quick-excludes.realms.statistics.weight-presets.achievements&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); // as demanded by the raid activity tracker $bossIds = array( diff --git a/pages/profiler.php b/pages/profiler.php index f0a26ddb..d6cf5288 100644 --- a/pages/profiler.php +++ b/pages/profiler.php @@ -10,8 +10,8 @@ class ProfilerPage extends GenericPage protected $tabId = 1; protected $tpl = 'profiler'; protected $gDataKey = true; - protected $js = ['profile_all.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; public function __construct($pageCall, $pageParam) { @@ -23,7 +23,7 @@ class ProfilerPage extends GenericPage protected function generateContent() { - $this->addJS('?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); } protected function generatePath() { } diff --git a/pages/profiles.php b/pages/profiles.php index cb82c6f5..d3e5dbde 100644 --- a/pages/profiles.php +++ b/pages/profiles.php @@ -17,8 +17,8 @@ class ProfilesPage extends GenericPage protected $tabId = 1; protected $path = [1, 5, 0]; protected $tpl = 'profiles'; - protected $js = ['filters.js', 'profile_all.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'filters.js'], [JS_FILE, 'profile_all.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; @@ -62,7 +62,7 @@ class ProfilesPage extends GenericPage protected function generateContent() { - $this->addJS('?data=weight-presets.realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets.realms&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $conditions = []; diff --git a/pages/quest.php b/pages/quest.php index 00dab396..0ee6f2ee 100644 --- a/pages/quest.php +++ b/pages/quest.php @@ -16,8 +16,8 @@ class QuestPage extends GenericPage protected $path = [0, 3]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $css = [['path' => 'Book.css']]; - protected $js = ['ShowOnMap.js']; + protected $js = [[JS_FILE, 'ShowOnMap.js']]; + protected $css = [[CSS_FILE, 'Book.css']]; protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkDomain']]; @@ -570,7 +570,7 @@ class QuestPage extends GenericPage /* Mapper */ /**********/ - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); // gather points of interest $mapNPCs = $mapGOs = []; // [typeId, start|end|objective, startItemId] diff --git a/pages/quests.php b/pages/quests.php index 3e6bc517..7e29f454 100644 --- a/pages/quests.php +++ b/pages/quests.php @@ -15,7 +15,7 @@ class QuestsPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = []; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/race.php b/pages/race.php index e8be0958..49c138b9 100644 --- a/pages/race.php +++ b/pages/race.php @@ -16,7 +16,7 @@ class RacePage extends GenericPage protected $path = [0, 13]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; public function __construct($pageCall, $id) { diff --git a/pages/screenshot.php b/pages/screenshot.php index ab667cbe..16cc0b86 100644 --- a/pages/screenshot.php +++ b/pages/screenshot.php @@ -12,8 +12,8 @@ class ScreenshotPage extends GenericPage const MAX_H = 325; protected $tpl = 'screenshot'; - protected $js = ['Cropper.js']; - protected $css = [['path' => 'Cropper.css']]; + protected $js = [[JS_FILE, 'Cropper.js']]; + protected $css = [[CSS_FILE, 'Cropper.css']]; protected $reqAuth = true; protected $tabId = 0; diff --git a/pages/search.php b/pages/search.php index 58b6f452..c93a365d 100644 --- a/pages/search.php +++ b/pages/search.php @@ -30,7 +30,7 @@ class SearchPage extends GenericPage protected $tpl = 'search'; protected $tabId = 0; protected $mode = CACHE_TYPE_SEARCH; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; protected $lvTabs = []; // [file, data, extraInclude, osInfo] // osInfo:[type, appendix, nMatches, param1, param2] protected $forceTabs = true; protected $search = ''; // output @@ -208,7 +208,7 @@ class SearchPage extends GenericPage if ($this->mode == CACHE_TYPE_NONE) // search is invalid return; - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $this->performSearch(); } diff --git a/pages/skill.php b/pages/skill.php index c55bc44a..4322344d 100644 --- a/pages/skill.php +++ b/pages/skill.php @@ -264,7 +264,7 @@ class SkillPage extends GenericPage $list = $spellIds ? DB::World()->selectCol('SELECT cdt.CreatureId FROM creature_default_trainer cdt JOIN trainer_spell ts ON ts.TrainerId = cdt.TrainerId WHERE ts.SpellID IN (?a)', $spellIds) : []; if ($list) { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $trainer = new CreatureList(array(CFG_SQL_LIMIT_NONE, ['ct.id', $list], ['s.guid', NULL, '!'], ['ct.npcflag', 0x10, '&'])); diff --git a/pages/sound.php b/pages/sound.php index d64d0079..5555d0e3 100644 --- a/pages/sound.php +++ b/pages/sound.php @@ -78,7 +78,7 @@ class SoundPage extends GenericPage /* Main Content */ /****************/ - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); // get spawns $map = null; @@ -331,7 +331,7 @@ class SoundPage extends GenericPage $npcs = new CreatureList($cnds); if (!$npcs->error) { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $this->extendGlobalData($npcs->getJSGlobals(GLOBALINFO_SELF)); $this->lvTabs[] = ['creature', ['data' => array_values($npcs->getListviewData())]]; diff --git a/pages/sounds.php b/pages/sounds.php index b3c59b69..3656a919 100644 --- a/pages/sounds.php +++ b/pages/sounds.php @@ -16,7 +16,7 @@ class SoundsPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = [1, 2, 3, 4, 6, 9, 10, 12, 13, 14, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 50, 52, 53]; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/spell.php b/pages/spell.php index d30c7032..e83a19af 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -16,7 +16,7 @@ class SpellPage extends GenericPage protected $path = [0, 1]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['swfobject.js']; + protected $js = [[JS_FILE, 'swfobject.js']]; protected $_get = ['domain' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkDomain']]; @@ -130,7 +130,7 @@ class SpellPage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); $_cat = $this->subject->getField('typeCat'); diff --git a/pages/spells.php b/pages/spells.php index ab4e86ec..95225ce3 100644 --- a/pages/spells.php +++ b/pages/spells.php @@ -15,7 +15,7 @@ class SpellsPage extends GenericPage protected $path = [0, 1]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $js = ['filters.js']; + protected $js = [[JS_FILE, 'filters.js']]; protected $_get = ['filter' => ['filter' => FILTER_UNSAFE_RAW]]; diff --git a/pages/talent.php b/pages/talent.php index d11ffada..555973ac 100644 --- a/pages/talent.php +++ b/pages/talent.php @@ -12,10 +12,10 @@ class TalentPage extends GenericPage protected $path = [1]; protected $mode = CACHE_TYPE_NONE; protected $gDataKey = true; - protected $js = ['TalentCalc.js']; + protected $js = [[JS_FILE, 'TalentCalc.js']]; protected $css = array( - ['path' => 'talentcalc.css'], - ['path' => 'talent.css'] + [CSS_FILE, 'talentcalc.css'], + [CSS_FILE, 'talent.css'] ); private $isPetCalc = false; @@ -31,12 +31,16 @@ class TalentPage extends GenericPage protected function generateContent() { // add conditional js & css - $this->addJS(array( - ($this->isPetCalc ? '?data=pet-talents.pets' : '?data=glyphs').'&locale='.User::$localeId.'&t='.$_SESSION['dataKey'], - $this->isPetCalc ? 'petcalc.js' : 'talent.js', - $this->isPetCalc ? 'swfobject.js' : null - )); - $this->addCSS($this->isPetCalc ? ['path' => 'petcalc.css'] : []); + $this->addScript( + [JS_FILE, ($this->isPetCalc ? '?data=pet-talents.pets' : '?data=glyphs').'&locale='.User::$localeId.'&t='.$_SESSION['dataKey']], + [JS_FILE, $this->isPetCalc ? 'petcalc.js' : 'talent.js'], + ); + + if ($this->isPetCalc) + $this->addScript( + [JS_FILE, 'swfobject.css'], + [CSS_FILE, 'petcalc.css'] + ); $this->tcType = $this->isPetCalc ? 'pc' : 'tc'; } diff --git a/pages/user.php b/pages/user.php index 8acb27e1..fbdd5303 100644 --- a/pages/user.php +++ b/pages/user.php @@ -7,8 +7,8 @@ if (!defined('AOWOW_REVISION')) class UserPage extends GenericPage { protected $tpl = 'user'; - protected $js = ['user.js', 'profile.js']; - protected $css = [['path' => 'Profiler.css']]; + protected $js = [[JS_FILE, 'user.js'], [JS_FILE, 'profile.js']]; + protected $css = [[CSS_FILE, 'Profiler.css']]; protected $mode = CACHE_TYPE_NONE; protected $typeId = 0; @@ -236,7 +236,7 @@ class UserPage extends GenericPage $profiles = new LocalProfileList($conditions); if (!$profiles->error) { - $this->addJS('?data=weight-presets&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); // Characters if ($chars = $profiles->getListviewData(PROFILEINFO_CHARACTER | PROFILEINFO_USER)) diff --git a/pages/zone.php b/pages/zone.php index 9158663f..cf4cbb60 100644 --- a/pages/zone.php +++ b/pages/zone.php @@ -14,7 +14,7 @@ class ZonePage extends GenericPage protected $tabId = 0; protected $type = TYPE_ZONE; protected $tpl = 'detail-page-generic'; - protected $js = ['ShowOnMap.js']; + protected $js = [[JS_FILE, 'ShowOnMap.js']]; protected $zoneMusic = []; @@ -33,7 +33,7 @@ class ZonePage extends GenericPage protected function generateContent() { - $this->addJS('?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']); + $this->addScript([JS_FILE, '?data=zones&locale='.User::$localeId.'&t='.$_SESSION['dataKey']]); /***********/ /* Infobox */ diff --git a/pages/zones.php b/pages/zones.php index 5d4e2cfd..e1d59aa1 100644 --- a/pages/zones.php +++ b/pages/zones.php @@ -16,7 +16,7 @@ class ZonesPage extends GenericPage protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; protected $validCats = [true, true, [0, 1, 2], [0, 1, 2], false, false, true, false, true, true, true]; - protected $js = ['ShowOnMap.js']; + protected $js = [[JS_FILE, 'ShowOnMap.js']]; public function __construct($pageCall, $pageParam) { diff --git a/template/bricks/head.tpl.php b/template/bricks/head.tpl.php index d29d88fd..35580f35 100644 --- a/template/bricks/head.tpl.php +++ b/template/bricks/head.tpl.php @@ -12,13 +12,11 @@ if (User::isInGroup(U_GROUP_STAFF | U_GROUP_SCREENSHOT | U_GROUP_VIDEO)): echo ' \n"; endif; -foreach ($this->css as $css): - if (!empty($css['string'])): - echo ' \n"; - elseif (!empty($css['path'])): - echo ' '.(!empty($css['ieCond']) ? '' : null)."\n"; +foreach ($this->css as [$type, $css]): + if ($type == CSS_FILE): + echo ' \n"; + elseif ($type == CSS_STRING): + echo ' \n"; endif; endforeach; ?> @@ -44,9 +42,11 @@ if (User::isInGroup(U_GROUP_STAFF | U_GROUP_SCREENSHOT | U_GROUP_VIDEO)): echo ' \n"; endif; -foreach ($this->js as $js): - if (!empty($js)): - echo ' \n"; +foreach ($this->js as [$type, $js]): + if ($type == JS_FILE): + echo ' \n"; + elseif ($type == JS_STRING): + echo ' \n"; endif; endforeach; ?>
KeyValueOptions