* 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
This commit is contained in:
Sarjuuk
2017-04-22 00:59:34 +02:00
parent 959d0ace0b
commit 6377a9e659
20 changed files with 149 additions and 53 deletions

View File

@@ -14,6 +14,8 @@ class Markup
private $text = ''; private $text = '';
private $jsGlobals = []; private $jsGlobals = [];
private static $dbTagPattern = '/(?<!\\\\)\[(npc|object|item|itemset|quest|spell|zone|faction|pet|achievement|statistic|title|event|class|race|skill|currency|emote|enchantment|money|sound|icondb)=(-?\d+)[^\]]*\]/i';
public function __construct($text) public function __construct($text)
{ {
$this->text = $text; $this->text = $text;
@@ -21,7 +23,7 @@ class Markup
public function parseGlobalsFromText(&$jsg = []) public function parseGlobalsFromText(&$jsg = [])
{ {
if (preg_match_all('/(?<!\\\\)\[(npc|object|item|itemset|quest|spell|zone|faction|pet|achievement|statistic|title|event|class|race|skill|currency|emote|enchantment|money|sound|icondb)=(-?\d+)[^\]]*\]/i', $this->text, $matches, PREG_SET_ORDER)) if (preg_match_all(self::$dbTagPattern, $this->text, $matches, PREG_SET_ORDER))
{ {
foreach ($matches as $match) foreach ($matches as $match)
{ {
@@ -33,7 +35,7 @@ class Markup
{ {
if (stripos($match[0], 'items')) 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]); $sm = explode(',', $submatch[1]);
for ($i = 0; $i < count($sm); $i+=2) for ($i = 0; $i < count($sm); $i+=2)
@@ -43,7 +45,7 @@ class Markup
if (stripos($match[0], 'currency')) 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]); $sm = explode(',', $submatch[1]);
for ($i = 0; $i < count($sm); $i+=2) for ($i = 0; $i < count($sm); $i+=2)
@@ -61,6 +63,79 @@ class Markup
return $this->jsGlobals; 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() public function fromHtml()
{ {
} }

View File

@@ -1366,7 +1366,7 @@ class ItemList extends BaseType
return null; return null;
} }
// level independant Bonus // 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', '<!--rtg'.$type.'-->'.$value, Lang::item('statType', $type)); return Lang::item('trigger', 1).str_replace('%d', '<!--rtg'.$type.'-->'.$value, Lang::item('statType', $type));
// rating-Bonuses // rating-Bonuses
else else

View File

@@ -57,7 +57,7 @@ class SkillList extends BaseType
'name' => Util::jsEscape($this->getField('name', true)), 'name' => Util::jsEscape($this->getField('name', true)),
'profession' => $this->curTpl['professionMask'], 'profession' => $this->curTpl['professionMask'],
'recipeSubclass' => $this->curTpl['recipeSubClass'], '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']) 'icon' => Util::jsEscape($this->curTpl['iconString'])
); );
} }

View File

@@ -90,6 +90,29 @@ class Lang
return self::vspf($var, $vspfArgs); 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) public static function sort($prop, $group, $method = SORT_NATURAL)
{ {

View File

@@ -721,7 +721,8 @@ $lang = array(
'pet' => array( 'pet' => array(
'notFound' => "Diese Tierart existiert nicht.", 'notFound' => "Diese Tierart existiert nicht.",
'exotic' => "Exotisch", '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( 'faction' => array(
'notFound' => "Diese Fraktion existiert nicht.", 'notFound' => "Diese Fraktion existiert nicht.",

View File

@@ -721,7 +721,8 @@ $lang = array(
'pet' => array( 'pet' => array(
'notFound' => "This pet family doesn't exist.", 'notFound' => "This pet family doesn't exist.",
'exotic' => "Exotic", '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( 'faction' => array(
'notFound' => "This faction doesn't exist.", 'notFound' => "This faction doesn't exist.",

View File

@@ -721,7 +721,8 @@ $lang = array(
'pet' => array( 'pet' => array(
'notFound' => "Esta familia de mascotas no existe.", 'notFound' => "Esta familia de mascotas no existe.",
'exotic' => "Exótica", 'exotic' => "Exótica",
'cat' => ["Ferocidad", "Tenacidad", "Astucia"] 'cat' => ["Ferocidad", "Tenacidad", "Astucia"],
'food' => ["Carne", "Pescado", "Queso", "Pan", "Hongo", "Fruta", "Carne cruda", "Pescado crudo"]
), ),
'faction' => array( 'faction' => array(
'notFound' => "Esta facción no existe.", 'notFound' => "Esta facción no existe.",

View File

@@ -721,7 +721,8 @@ $lang = array(
'pet' => array( 'pet' => array(
'notFound' => "Cette famille de familiers n'existe pas.", 'notFound' => "Cette famille de familiers n'existe pas.",
'exotic' => "Exotique", '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( 'faction' => array(
'notFound' => "Cette faction n'existe pas.", 'notFound' => "Cette faction n'existe pas.",

View File

@@ -721,7 +721,8 @@ $lang = array(
'pet' => array( 'pet' => array(
'notFound' => "Такой породы питомцев не существует.", 'notFound' => "Такой породы питомцев не существует.",
'exotic' => "Экзотический", 'exotic' => "Экзотический",
'cat' => ["Свирепость", "Упорство", "Хитрость"] 'cat' => ["Свирепость", "Упорство", "Хитрость"],
'food' => ["Мясо", "Рыба", "Сыр", "Хлеб", "Грибы", "Фрукты", "Сырое мясо", "Сырая рыба"]
), ),
'faction' => array( 'faction' => array(
'notFound' => "Такая фракция не существует.", 'notFound' => "Такая фракция не существует.",

View File

@@ -224,24 +224,26 @@ class GenericPage
if (!isset($this->category) || empty($this->validCats)) if (!isset($this->category) || empty($this->validCats))
return true; return true;
switch (count($this->category)) $c = $this->category; // shorthand
switch (count($c))
{ {
case 0: // no params works always case 0: // no params works always
return true; 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); }); $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 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; return false;
// check if the sub-array is n-imensional // check if the sub-array is n-imensional
if (count($this->validCats[$this->category[0]]) == count($this->validCats[$this->category[0]], COUNT_RECURSIVE)) if (is_array($this->validCats[$c[0]]) && count($this->validCats[$c[0]]) == count($this->validCats[$c[0]], COUNT_RECURSIVE))
return in_array($this->category[1], $this->validCats[$this->category[0]]); // second param is value in second level array return in_array($c[1], $this->validCats[$c[0]]); // second param is value in second level array
else 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 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; return false;

View File

@@ -139,7 +139,7 @@ class NpcPage extends GenericPage
// Classification // Classification
if ($_ = $this->subject->getField('rank')) // != NPC_RANK_NORMAL 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; $infobox[] = Lang::npc('classification').Lang::main('colon').$str;
} }

View File

@@ -99,6 +99,10 @@ class NpcsPage extends GenericPage
array_unshift($this->title, $this->name); array_unshift($this->title, $this->name);
if ($this->category) if ($this->category)
array_unshift($this->title, Lang::npc('cat', $this->category[0])); 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() protected function generatePath()
@@ -106,7 +110,7 @@ class NpcsPage extends GenericPage
if ($this->category) if ($this->category)
$this->path[] = $this->category[0]; $this->path[] = $this->category[0];
$form = $this->filterObj->getForm('form'); $form = $this->filterObj->getForm();
if (isset($form['fa']) && !is_array($form['fa'])) if (isset($form['fa']) && !is_array($form['fa']))
$this->path[] = $form['fa']; $this->path[] = $form['fa'];
} }

View File

@@ -350,7 +350,7 @@ class ObjectPage extends GenericPage
if ($goLoot->getByContainer(LOOT_GAMEOBJECT, $_)) if ($goLoot->getByContainer(LOOT_GAMEOBJECT, $_))
{ {
$extraCols = $goLoot->extraCols; $extraCols = $goLoot->extraCols;
$extraCols[] = 'Listview.extraCols.percent'; $extraCols[] = '$Listview.extraCols.percent';
$hiddenCols = ['source', 'side', 'slot', 'reqlevel']; $hiddenCols = ['source', 'side', 'slot', 'reqlevel'];
$this->extendGlobalData($goLoot->jsGlobals); $this->extendGlobalData($goLoot->jsGlobals);
@@ -375,7 +375,7 @@ class ObjectPage extends GenericPage
'id' => 'contains', 'id' => 'contains',
'name' => '$LANG.tab_contains', 'name' => '$LANG.tab_contains',
'sort' => ['-percent', 'name'], 'sort' => ['-percent', 'name'],
'extraCols' => ['$Listview.extraCols.percent'] 'extraCols' => $extraCols
); );
if ($hiddenCols) if ($hiddenCols)

View File

@@ -103,7 +103,7 @@ class PetPage extends GenericPage
// tab: diet // tab: diet
$list = []; $list = [];
$mask = $this->subject->getField('foodMask'); $mask = $this->subject->getField('foodMask');
for ($i = 1; $i < 7; $i++) for ($i = 1; $i < 9; $i++)
if ($mask & (1 << ($i - 1))) if ($mask & (1 << ($i - 1)))
$list[] = $i; $list[] = $i;

View File

@@ -15,7 +15,7 @@ class PetsPage extends GenericPage
protected $path = [0, 8]; protected $path = [0, 8];
protected $tabId = 0; protected $tabId = 0;
protected $mode = CACHE_TYPE_PAGE; protected $mode = CACHE_TYPE_PAGE;
protected $validCats = [1, 2, 3]; protected $validCats = [0, 1, 2];
public function __construct($pageCall, $pageParam) public function __construct($pageCall, $pageParam)
{ {

View File

@@ -11,7 +11,6 @@ class SoundPage extends GenericPage
use DetailPage; use DetailPage;
protected $type = TYPE_SOUND; protected $type = TYPE_SOUND;
protected $typeId = 0;
protected $tpl = 'sound'; protected $tpl = 'sound';
protected $path = [0, 19]; protected $path = [0, 19];
protected $tabId = 0; protected $tabId = 0;
@@ -30,7 +29,8 @@ class SoundPage extends GenericPage
$this->special = true; $this->special = true;
$this->name = Lang::sound('cat', 1000); $this->name = Lang::sound('cat', 1000);
$this->cat = 1000; $this->cat = 1000;
$this->typeId = -1000; $this->articleUrl = 'sound&playlist';
$this->hasComContent = false;
} }
// regular case // regular case
else else

View File

@@ -708,7 +708,7 @@ class ZonePage extends GenericPage
$soundIds = []; $soundIds = [];
$zoneMusic = DB::Aowow()->select(' $zoneMusic = DB::Aowow()->select('
SELECT SELECT
x.soundId, x.worldStateId, x.worldStateValue x.soundId AS ARRAY_KEY, x.soundId, x.worldStateId, x.worldStateValue
FROM ( FROM (
SELECT ambienceDay AS soundId, worldStateId, worldStateValue FROM ?_zones_sounds WHERE id IN (?a) AND ambienceDay > 0 UNION 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 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(); $data = $music->getListviewData();
$tabData = []; $tabData = [];
if (array_filter(array_column($soundIds, 'worldStateId'))) if (array_filter(array_column($zoneMusic, 'worldStateId')))
{ {
$tabData['extraCols'] = ['$Listview.extraCols.condition']; $tabData['extraCols'] = ['$Listview.extraCols.condition'];
foreach ($soundIds as $sData) foreach ($soundIds as $sId)
if ($sData['worldStateId']) if (!empty($zoneMusic[$sId]['worldStateId']))
$data[$sData['soundId']]['condition'][0][$this->typeId][] = [[CND_WORLD_STATE, $sData['worldStateId'], $sData['worldStateValue']]]; $data[$sId]['condition'][0][$this->typeId][] = [[CND_WORLD_STATE, $zoneMusic[$sId]['worldStateId'], $zoneMusic[$sId]['worldStateValue']]];
} }
$tabData['data'] = array_values($data); $tabData['data'] = array_values($data);

View File

@@ -1382,7 +1382,7 @@ var g_pet_types = {
var g_pet_foods = { var g_pet_foods = {
1: 'Fleisch', 1: 'Fleisch',
2: 'Fish', 2: 'Fisch',
4: 'Käse', 4: 'Käse',
8: 'Brot', 8: 'Brot',
16: 'Fungus', 16: 'Fungus',

View File

@@ -7,15 +7,10 @@ elseif (!empty($this->map['data'])):
elseif ($this->type != TYPE_ZONE): elseif ($this->type != TYPE_ZONE):
echo ' <div>'.($this->type == TYPE_OBJECT ? Lang::gameObject('foundIn') : ($this->type == TYPE_SOUND ? Lang::sound('foundIn') : Lang::npc('foundIn'))).' <span id="mapper-zone-generic">'; echo ' <div>'.($this->type == TYPE_OBJECT ? Lang::gameObject('foundIn') : ($this->type == TYPE_SOUND ? Lang::sound('foundIn') : Lang::npc('foundIn'))).' <span id="mapper-zone-generic">';
$n = count($this->map['mapperData']); $extra = $this->map['extra'];
$i = 0; echo Lang::concat($this->map['mapperData'], true, function ($areaData, $areaId) use ($extra) {
foreach ($this->map['mapperData'] as $areaId => $areaData): return '<a href="javascript:;" onclick="myMapper.update({zone: '.$areaId.'}); g_setSelectedLink(this, \'mapper\'); return false" onmousedown="return false">'.$extra[$areaId].'</a>&nbsp;('.reset($areaData)['count'].')';
if ($n > 1 && $i++ > 0): });
echo $i < $n ? ', ' : Lang::main('and');
endif;
echo '<a href="javascript:;" onclick="myMapper.update({zone: '.$areaId.'}); g_setSelectedLink(this, \'mapper\'); return false" onmousedown="return false">'.$this->map['extra'][$areaId].'</a>&nbsp;('.reset($areaData)['count'].')';
endforeach;
echo ".</span></div>\n"; echo ".</span></div>\n";
endif; endif;

View File

@@ -22,15 +22,7 @@
if ($this->accessory): if ($this->accessory):
echo ' <div>'.Lang::npc('accessoryFor').' '; echo ' <div>'.Lang::npc('accessoryFor').' ';
echo Lang::concat($this->accessory, true, function ($v, $k) { return '<a href="?npc='.$v[0].'">'.$v[1].'</a>'; });
$n = count($this->accessory);
foreach ($this->accessory as $i => $ac):
if ($n > 1 && $i > 0):
echo ($i == $n - 1) ? Lang::main('and') : ', ';
endif;
echo '<a href="?npc='.$ac[0].'">'.$ac[1].'</a>';
endforeach;
echo ".</div>\n"; echo ".</div>\n";
endif; endif;