From 6377a9e659016898dbdbcedce3c9fcdc22c69bdc Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 22 Apr 2017 00:59:34 +0200 Subject: [PATCH] Misc * added option to 'verbose' concatenate a list of items to class Lang * added option to strip tags from a string to class Markdown * fixed several instances of wrong categories on pages * actually display world state conditions for zone music * some typos all over the place --- includes/markup.class.php | 81 ++++++++++++++++++++++++++++++++-- includes/types/item.class.php | 2 +- includes/types/skill.class.php | 2 +- localization/lang.class.php | 23 ++++++++++ localization/locale_dede.php | 3 +- localization/locale_enus.php | 3 +- localization/locale_eses.php | 3 +- localization/locale_frfr.php | 3 +- localization/locale_ruru.php | 3 +- pages/genericPage.class.php | 18 ++++---- pages/npc.php | 2 +- pages/npcs.php | 6 ++- pages/object.php | 4 +- pages/pet.php | 2 +- pages/pets.php | 2 +- pages/sound.php | 10 ++--- pages/zone.php | 10 ++--- static/js/locale_dede.js | 2 +- template/bricks/mapper.tpl.php | 13 ++---- template/pages/npc.tpl.php | 10 +---- 20 files changed, 149 insertions(+), 53 deletions(-) diff --git a/includes/markup.class.php b/includes/markup.class.php index b6b1d568..8a4f3fc8 100644 --- a/includes/markup.class.php +++ b/includes/markup.class.php @@ -14,6 +14,8 @@ class Markup private $text = ''; private $jsGlobals = []; + private static $dbTagPattern = '/(?text = $text; @@ -21,7 +23,7 @@ class Markup public function parseGlobalsFromText(&$jsg = []) { - if (preg_match_all('/(?text, $matches, PREG_SET_ORDER)) + if (preg_match_all(self::$dbTagPattern, $this->text, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { @@ -33,7 +35,7 @@ class Markup { if (stripos($match[0], 'items')) { - if (preg_match('/items=([0-9,]+)/', $match[0], $submatch)) + if (preg_match('/items=([0-9,]+)/i', $match[0], $submatch)) { $sm = explode(',', $submatch[1]); for ($i = 0; $i < count($sm); $i+=2) @@ -43,7 +45,7 @@ class Markup if (stripos($match[0], 'currency')) { - if (preg_match('/currency=([0-9,]+)/', $match[0], $submatch)) + if (preg_match('/currency=([0-9,]+)/i', $match[0], $submatch)) { $sm = explode(',', $submatch[1]); for ($i = 0; $i < count($sm); $i+=2) @@ -61,6 +63,79 @@ class Markup return $this->jsGlobals; } + public function stripTags($globals = []) + { + // since this is an article the db-tags should already be parsed + $text = preg_replace_callback(self::$dbTagPattern, function ($match) use ($globals) { + if ($match[1] == 'statistic') + $match[1] = 'achievement'; + else if ($match[1] == 'icondb') + $match[1] = 'icon'; + else if ($match[1] == 'money') + { + $moneys = []; + if (stripos($match[0], 'items')) + { + if (preg_match('/items=([0-9,]+)/i', $match[0], $submatch)) + { + $sm = explode(',', $submatch[1]); + for ($i = 0; $i < count($sm); $i += 2) + { + if (!empty($globals[TYPE_ITEM][1][$sm[$i]])) + $moneys[] = $globals[TYPE_ITEM][1][$sm[$i]]['name']; + else + $moneys[] = Util::ucFirst(Lang::game('item')).' #'.$sm[$i]; + } + } + } + + if (stripos($match[0], 'currency')) + { + if (preg_match('/currency=([0-9,]+)/i', $match[0], $submatch)) + { + $sm = explode(',', $submatch[1]); + for ($i = 0; $i < count($sm); $i += 2) + { + if (!empty($globals[TYPE_CURRENCY][1][$sm[$i]])) + $moneys[] = $globals[TYPE_CURRENCY][1][$sm[$i]]['name']; + else + $moneys[] = Util::ucFirst(Lang::game('curency')).' #'.$sm[$i]; + } + } + } + + return Lang::concat($moneys); + } + + if ($type = array_search($match[1], Util::$typeStrings)) + { + if (!empty($globals[$type][1][$match[2]])) + return $globals[$type][1][$match[2]]['name']; + else + return Util::ucFirst(Lang::game($match[1])).' #'.$match[2]; + } + + trigger_error('Markup::stripTags() - encountered unhandled db-tag: '.var_export($match)); + return ''; + }, $this->text); + + $text = str_replace('[br]', "\n", $text); + $stripped = ''; + + $inTag = false; + for ($i = 0; $i < strlen($text); $i++) + { + if ($text[$i] == '[') + $inTag = true; + if (!$inTag) + $stripped .= $text[$i]; + if ($text[$i] == ']') + $inTag = false; + } + + return $stripped; + } + public function fromHtml() { } diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 41bfde33..ac11f00c 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -1366,7 +1366,7 @@ class ItemList extends BaseType return null; } // level independant Bonus - else if (in_array($type, Util::$lvlIndepRating)) + else if (in_array($type, Game::$lvlIndepRating)) return Lang::item('trigger', 1).str_replace('%d', ''.$value, Lang::item('statType', $type)); // rating-Bonuses else diff --git a/includes/types/skill.class.php b/includes/types/skill.class.php index 6f095a0a..2aa2dd13 100644 --- a/includes/types/skill.class.php +++ b/includes/types/skill.class.php @@ -57,7 +57,7 @@ class SkillList extends BaseType 'name' => Util::jsEscape($this->getField('name', true)), 'profession' => $this->curTpl['professionMask'], 'recipeSubclass' => $this->curTpl['recipeSubClass'], - 'specializations' => Util::toJSON($this->curTpl['specializations']), + 'specializations' => Util::toJSON($this->curTpl['specializations'], JSON_NUMERIC_CHECK), 'icon' => Util::jsEscape($this->curTpl['iconString']) ); } diff --git a/localization/lang.class.php b/localization/lang.class.php index 2e57ace4..fccc795c 100644 --- a/localization/lang.class.php +++ b/localization/lang.class.php @@ -90,6 +90,29 @@ class Lang return self::vspf($var, $vspfArgs); } + public static function concat($args, $useAnd = true, $callback = null) + { + $b = ''; + $i = 0; + $n = count($args); + foreach ($args as $k => $arg) + { + if (is_callable($callback)) + $b .= $callback($arg, $k); + else + $b .= $arg; + + if ($n > 1 && $i < ($n - 2)) + $b .= ', '; + else if ($n > 1 && $i == $n - 2) + $b .= Lang::main($useAnd ? 'and' : 'or'); + + $i++; + } + + return $b; + } + public static function sort($prop, $group, $method = SORT_NATURAL) { diff --git a/localization/locale_dede.php b/localization/locale_dede.php index d0970f0e..687d0b05 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -721,7 +721,8 @@ $lang = array( 'pet' => array( 'notFound' => "Diese Tierart existiert nicht.", 'exotic' => "Exotisch", - 'cat' => ["Wildheit", "Hartnäckigkeit", "Gerissenheit"] + 'cat' => ["Wildheit", "Hartnäckigkeit", "Gerissenheit"], + 'food' => ["Fleisch", "Fisch", "Käse", "Brot", "Fungus", "Obst", "Rohes Fleisch", "Roher Fisch"] ), 'faction' => array( 'notFound' => "Diese Fraktion existiert nicht.", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index 24baa8d5..20a99b21 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -721,7 +721,8 @@ $lang = array( 'pet' => array( 'notFound' => "This pet family doesn't exist.", 'exotic' => "Exotic", - 'cat' => ["Ferocity", "Tenacity", "Cunning"] + 'cat' => ["Ferocity", "Tenacity", "Cunning"], + 'food' => ["Meat", "Fish", "Cheese", "Bread", "Fungus", "Fruit", "Raw Meat", "Raw Fish"] // ItemPetFood.dbc ), 'faction' => array( 'notFound' => "This faction doesn't exist.", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index 9868d69f..3205a187 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -721,7 +721,8 @@ $lang = array( 'pet' => array( 'notFound' => "Esta familia de mascotas no existe.", 'exotic' => "Exótica", - 'cat' => ["Ferocidad", "Tenacidad", "Astucia"] + 'cat' => ["Ferocidad", "Tenacidad", "Astucia"], + 'food' => ["Carne", "Pescado", "Queso", "Pan", "Hongo", "Fruta", "Carne cruda", "Pescado crudo"] ), 'faction' => array( 'notFound' => "Esta facción no existe.", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 71059a76..7cc4f087 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -721,7 +721,8 @@ $lang = array( 'pet' => array( 'notFound' => "Cette famille de familiers n'existe pas.", 'exotic' => "Exotique", - 'cat' => ["Férocité", "Tenacité", "Ruse"] + 'cat' => ["Férocité", "Tenacité", "Ruse"], + 'food' => ["Viande", "Poisson", "Fromage", "Pain", "Champignon", "Fruit", "Viande crue", "Poisson cru"] ), 'faction' => array( 'notFound' => "Cette faction n'existe pas.", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 2e61445c..be73d62b 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -721,7 +721,8 @@ $lang = array( 'pet' => array( 'notFound' => "Такой породы питомцев не существует.", 'exotic' => "Экзотический", - 'cat' => ["Свирепость", "Упорство", "Хитрость"] + 'cat' => ["Свирепость", "Упорство", "Хитрость"], + 'food' => ["Мясо", "Рыба", "Сыр", "Хлеб", "Грибы", "Фрукты", "Сырое мясо", "Сырая рыба"] ), 'faction' => array( 'notFound' => "Такая фракция не существует.", diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 8cb96010..412fcdeb 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -224,24 +224,26 @@ class GenericPage if (!isset($this->category) || empty($this->validCats)) return true; - switch (count($this->category)) + $c = $this->category; // shorthand + + switch (count($c)) { case 0: // no params works always return true; - case 1: // null is valid || value in a 1-dim-array || key for a n-dim-array + case 1: // null is valid || value in a 1-dim-array || (key for a n-dim-array && ( has more subcats || no further subCats )) $filtered = array_filter($this->validCats, function ($x) { return is_int($x); }); - return $this->category[0] === null || in_array($this->category[0], $filtered) || !empty($this->validCats[$this->category[0]]); + return $c[0] === null || in_array($c[0], $filtered) || (!empty($this->validCats[$c[0]]) && (is_array($this->validCats[$c[0]]) || $this->validCats[$c[0]] === true)); case 2: // first param has to be a key. otherwise invalid - if (!isset($this->validCats[$this->category[0]])) + if (!isset($this->validCats[$c[0]])) return false; // check if the sub-array is n-imensional - if (count($this->validCats[$this->category[0]]) == count($this->validCats[$this->category[0]], COUNT_RECURSIVE)) - return in_array($this->category[1], $this->validCats[$this->category[0]]); // second param is value in second level array + if (is_array($this->validCats[$c[0]]) && count($this->validCats[$c[0]]) == count($this->validCats[$c[0]], COUNT_RECURSIVE)) + return in_array($c[1], $this->validCats[$c[0]]); // second param is value in second level array else - return isset($this->validCats[$this->category[0]][$this->category[1]]); // check if params is key of another array + return isset($this->validCats[$c[0]][$c[1]]); // check if params is key of another array case 3: // 3 params MUST point to a specific value - return isset($this->validCats[$this->category[0]][$this->category[1]]) && in_array($this->category[2], $this->validCats[$this->category[0]][$this->category[1]]); + return isset($this->validCats[$c[0]][$c[1]]) && in_array($c[2], $this->validCats[$c[0]][$c[1]]); } return false; diff --git a/pages/npc.php b/pages/npc.php index 8fbe3a76..17290433 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -139,7 +139,7 @@ class NpcPage extends GenericPage // Classification if ($_ = $this->subject->getField('rank')) // != NPC_RANK_NORMAL { - $str = $_typeFlags & 0x4 ? '[span class=icon-boss]'.Lang::npc('rank', $_).'[/span]' : Lang::npc('rank', $_); + $str = $this->subject->isBoss() ? '[span class=icon-boss]'.Lang::npc('rank', $_).'[/span]' : Lang::npc('rank', $_); $infobox[] = Lang::npc('classification').Lang::main('colon').$str; } diff --git a/pages/npcs.php b/pages/npcs.php index 3bbbb998..161cc4e6 100644 --- a/pages/npcs.php +++ b/pages/npcs.php @@ -99,6 +99,10 @@ class NpcsPage extends GenericPage array_unshift($this->title, $this->name); if ($this->category) array_unshift($this->title, Lang::npc('cat', $this->category[0])); + + $form = $this->filterObj->getForm(); + if (isset($form['fa']) && !is_array($form['fa'])) + array_unshift($this->title, Lang::game('fa', $form['fa'])); } protected function generatePath() @@ -106,7 +110,7 @@ class NpcsPage extends GenericPage if ($this->category) $this->path[] = $this->category[0]; - $form = $this->filterObj->getForm('form'); + $form = $this->filterObj->getForm(); if (isset($form['fa']) && !is_array($form['fa'])) $this->path[] = $form['fa']; } diff --git a/pages/object.php b/pages/object.php index 66925f05..86203277 100644 --- a/pages/object.php +++ b/pages/object.php @@ -350,7 +350,7 @@ class ObjectPage extends GenericPage if ($goLoot->getByContainer(LOOT_GAMEOBJECT, $_)) { $extraCols = $goLoot->extraCols; - $extraCols[] = 'Listview.extraCols.percent'; + $extraCols[] = '$Listview.extraCols.percent'; $hiddenCols = ['source', 'side', 'slot', 'reqlevel']; $this->extendGlobalData($goLoot->jsGlobals); @@ -375,7 +375,7 @@ class ObjectPage extends GenericPage 'id' => 'contains', 'name' => '$LANG.tab_contains', 'sort' => ['-percent', 'name'], - 'extraCols' => ['$Listview.extraCols.percent'] + 'extraCols' => $extraCols ); if ($hiddenCols) diff --git a/pages/pet.php b/pages/pet.php index 4f1920e5..daa5edd1 100644 --- a/pages/pet.php +++ b/pages/pet.php @@ -103,7 +103,7 @@ class PetPage extends GenericPage // tab: diet $list = []; $mask = $this->subject->getField('foodMask'); - for ($i = 1; $i < 7; $i++) + for ($i = 1; $i < 9; $i++) if ($mask & (1 << ($i - 1))) $list[] = $i; diff --git a/pages/pets.php b/pages/pets.php index 5fb9ed08..a3d1b814 100644 --- a/pages/pets.php +++ b/pages/pets.php @@ -15,7 +15,7 @@ class PetsPage extends GenericPage protected $path = [0, 8]; protected $tabId = 0; protected $mode = CACHE_TYPE_PAGE; - protected $validCats = [1, 2, 3]; + protected $validCats = [0, 1, 2]; public function __construct($pageCall, $pageParam) { diff --git a/pages/sound.php b/pages/sound.php index c125965a..fb031ab2 100644 --- a/pages/sound.php +++ b/pages/sound.php @@ -11,7 +11,6 @@ class SoundPage extends GenericPage use DetailPage; protected $type = TYPE_SOUND; - protected $typeId = 0; protected $tpl = 'sound'; protected $path = [0, 19]; protected $tabId = 0; @@ -27,10 +26,11 @@ class SoundPage extends GenericPage // special case if (!$id && isset($_GET['playlist'])) { - $this->special = true; - $this->name = Lang::sound('cat', 1000); - $this->cat = 1000; - $this->typeId = -1000; + $this->special = true; + $this->name = Lang::sound('cat', 1000); + $this->cat = 1000; + $this->articleUrl = 'sound&playlist'; + $this->hasComContent = false; } // regular case else diff --git a/pages/zone.php b/pages/zone.php index 5dac1a6d..4a8ec996 100644 --- a/pages/zone.php +++ b/pages/zone.php @@ -708,7 +708,7 @@ class ZonePage extends GenericPage $soundIds = []; $zoneMusic = DB::Aowow()->select(' SELECT - x.soundId, x.worldStateId, x.worldStateValue + x.soundId AS ARRAY_KEY, x.soundId, x.worldStateId, x.worldStateValue FROM ( SELECT ambienceDay AS soundId, worldStateId, worldStateValue FROM ?_zones_sounds WHERE id IN (?a) AND ambienceDay > 0 UNION SELECT ambienceNight AS soundId, worldStateId, worldStateValue FROM ?_zones_sounds WHERE id IN (?a) AND ambienceNight > 0 UNION @@ -734,13 +734,13 @@ class ZonePage extends GenericPage $data = $music->getListviewData(); $tabData = []; - if (array_filter(array_column($soundIds, 'worldStateId'))) + if (array_filter(array_column($zoneMusic, 'worldStateId'))) { $tabData['extraCols'] = ['$Listview.extraCols.condition']; - foreach ($soundIds as $sData) - if ($sData['worldStateId']) - $data[$sData['soundId']]['condition'][0][$this->typeId][] = [[CND_WORLD_STATE, $sData['worldStateId'], $sData['worldStateValue']]]; + foreach ($soundIds as $sId) + if (!empty($zoneMusic[$sId]['worldStateId'])) + $data[$sId]['condition'][0][$this->typeId][] = [[CND_WORLD_STATE, $zoneMusic[$sId]['worldStateId'], $zoneMusic[$sId]['worldStateValue']]]; } $tabData['data'] = array_values($data); diff --git a/static/js/locale_dede.js b/static/js/locale_dede.js index 0f9a6858..2793d0ec 100644 --- a/static/js/locale_dede.js +++ b/static/js/locale_dede.js @@ -1382,7 +1382,7 @@ var g_pet_types = { var g_pet_foods = { 1: 'Fleisch', - 2: 'Fish', + 2: 'Fisch', 4: 'Käse', 8: 'Brot', 16: 'Fungus', diff --git a/template/bricks/mapper.tpl.php b/template/bricks/mapper.tpl.php index 25096e2d..2b0a8def 100644 --- a/template/bricks/mapper.tpl.php +++ b/template/bricks/mapper.tpl.php @@ -7,15 +7,10 @@ elseif (!empty($this->map['data'])): elseif ($this->type != TYPE_ZONE): echo '
'.($this->type == TYPE_OBJECT ? Lang::gameObject('foundIn') : ($this->type == TYPE_SOUND ? Lang::sound('foundIn') : Lang::npc('foundIn'))).' '; - $n = count($this->map['mapperData']); - $i = 0; - foreach ($this->map['mapperData'] as $areaId => $areaData): - if ($n > 1 && $i++ > 0): - echo $i < $n ? ', ' : Lang::main('and'); - endif; - - echo ''.$this->map['extra'][$areaId].' ('.reset($areaData)['count'].')'; - endforeach; + $extra = $this->map['extra']; + echo Lang::concat($this->map['mapperData'], true, function ($areaData, $areaId) use ($extra) { + return ''.$extra[$areaId].' ('.reset($areaData)['count'].')'; + }); echo ".
\n"; endif; diff --git a/template/pages/npc.tpl.php b/template/pages/npc.tpl.php index fb35478c..895bf94f 100644 --- a/template/pages/npc.tpl.php +++ b/template/pages/npc.tpl.php @@ -22,15 +22,7 @@ if ($this->accessory): echo '
'.Lang::npc('accessoryFor').' '; - - $n = count($this->accessory); - foreach ($this->accessory as $i => $ac): - if ($n > 1 && $i > 0): - echo ($i == $n - 1) ? Lang::main('and') : ', '; - endif; - echo ''.$ac[1].''; - endforeach; - + echo Lang::concat($this->accessory, true, function ($v, $k) { return ''.$v[1].''; }); echo ".
\n"; endif;