diff --git a/includes/class.item.php b/includes/class.item.php
index 7c20b712..024f2044 100644
--- a/includes/class.item.php
+++ b/includes/class.item.php
@@ -17,7 +17,7 @@ class ItemList extends BaseType
protected $setupQuery = 'SELECT *, i.entry AS ARRAY_KEY FROM item_template i LEFT JOIN ?_item_template_addon iX ON i.entry = iX.id LEFT JOIN locales_item l ON i.entry = l.entry WHERE [filter] [cond] GROUP BY i.entry ORDER BY i.Quality DESC';
protected $matchQuery = 'SELECT COUNT(1) FROM item_template i LEFT JOIN ?_item_template_addon iX ON i.entry = iX.id LEFT JOIN locales_item l ON i.entry = l.entry WHERE [filter] [cond]';
- public function __construct($conditions)
+ public function __construct($conditions, $pieceToSet = null)
{
parent::__construct($conditions);
@@ -28,6 +28,10 @@ class ItemList extends BaseType
$this->initScalingStats();
$this->initJsonStats();
+
+ // readdress itemset .. is wrong for virtual sets
+ if ($pieceToSet)
+ $this->json[$this->id]['itemset'] = $pieceToSet[$this->id];
}
$this->reset(); // restore 'iterator'
@@ -90,30 +94,47 @@ class ItemList extends BaseType
if ($addInfoMask & ITEMINFO_JSON)
$this->extendJsonStats();
- $tmp = array_merge($this->json[$this->id], array(
- 'id' => $this->id,
- 'name' => $this->names[$this->id],
- 'quality' => 7 - $this->curTpl['Quality'],
- 'reqskill' => $this->curTpl['RequiredSkill'],
- 'reqskillrank' => $this->curTpl['RequiredSkillRank'],
- 'reqspell' => $this->curTpl['requiredspell'],
- 'reqfaction' => $this->curTpl['RequiredReputationFaction'],
- 'reqrep' => $this->curTpl['RequiredReputationRank'],
- 'side' => Util::sideByRaceMask($this->curTpl['AllowableRace']), // FlagsExtra zur Rate ziehen? 0:Beide; 1: Horde; 2:Allianz
- 'heroic' => (string)($this->curTpl['Flags'] & 0x8),
- 'nslots' => $this->curTpl['ContainerSlots'],
- 'buyprice' => $this->curTpl['BuyPrice'],
- 'sellprice' => $this->curTpl['SellPrice']
- ));
+ $data[$this->id] = $this->json[$this->id];
+
+ if (isset($this->itemMods[$this->id])) // due to ITEMINFO_JSON
+ foreach ($this->itemMods[$this->id] as $k => $v)
+ $data[$this->id][Util::$itemMods[$k]] = $v;
+
+ if ($addInfoMask & ITEMINFO_VENDOR)
+ {
+ if ($x = $this->curTpl['BuyPrice'])
+ $data[$this->id]['buyprice'] = $x;
+
+ if ($x = $this->curTpl['SellPrice'])
+ $data[$this->id]['sellprice'] = $x;
+ }
// complicated data
- if (!in_array($this->curTpl['AllowableRace'], [-1, 0, RACE_MASK_ALL, RACE_MASK_ALLIANCE, RACE_MASK_HORDE]))
- $tmp['reqrace'] = $this->curTpl['AllowableRace'];
+ if ($x = $this->curTpl['RequiredSkill'])
+ $data[$this->id]['reqskill'] = $x;
- if (!in_array($this->curTpl['AllowableClass'], [-1, 0, CLASS_MASK_ALL]))
- $tmp['reqclass'] = $this->curTpl['AllowableClass']; // $tmp['classes'] ??
+ if ($x = $this->curTpl['RequiredSkillRank'])
+ $data[$this->id]['reqskillrank'] = $x;
- $data[$this->id] = $tmp;
+ if ($x = $this->curTpl['requiredspell'])
+ $data[$this->id]['reqspell'] = $x;
+
+ if ($x = $this->curTpl['RequiredReputationFaction'])
+ $data[$this->id]['reqfaction'] = $x;
+
+ if ($x = $this->curTpl['RequiredReputationRank'])
+ $data[$this->id]['reqrep'] = $x;
+
+ if ($x = $this->curTpl['ContainerSlots'])
+ $data[$this->id]['nslots'] = $x;
+
+
+ if (!in_array($this->curTpl['AllowableRace'], [-1, 0]) && !$this->curTpl['AllowableRace'] & RACE_MASK_ALL == RACE_MASK_ALL &&
+ !$this->curTpl['AllowableRace'] & RACE_MASK_ALLIANCE == RACE_MASK_ALLIANCE && !$this->curTpl['AllowableRace'] & RACE_MASK_HORDE == RACE_MASK_HORDE)
+ $data[$this->id]['reqrace'] = $this->curTpl['AllowableRace'];
+
+ if (!in_array($this->curTpl['AllowableClass'], [-1, 0]) && !$this->curTpl['AllowableClass'] & CLASS_MASK_ALL == CLASS_MASK_ALL)
+ $data[$this->id]['reqclass'] = $this->curTpl['AllowableClass']; // $data[$this->id]['classes'] ??
}
/* even more complicated crap
@@ -642,7 +663,7 @@ class ItemList extends BaseType
$reagents = new ItemList(array(['i.entry', array_keys($reagentItems)]));
$reqReag = [];
- $x .= ''.Lang::$item['trigger'][0].' '.Util::localizedString($this->curTpl, 'description').'';
+ $x .= ''.Lang::$item['trigger'][0].' '.Util::localizedString($this->curTpl, 'description').'
';
$xCraft = '
'.$craftItem->renderTooltip(null, $interactive).'
';
@@ -778,7 +799,7 @@ class ItemList extends BaseType
return 0;
}
- public function extendJsonStats($pieceAssoc = NULL)
+ public function extendJsonStats()
{
// convert ItemMods
for ($h = 1; $h <= 10; $h++)
@@ -808,24 +829,14 @@ class ItemList extends BaseType
$eqpSplList = new SpellList(array(['id', $equipSpells]));
$stats = $eqpSplList->getStatGain();
foreach ($stats as $mId => $qty)
- @$this->itemMods[$this->id][$mId] += $qty;
+ if ($qty > 0)
+ @$this->itemMods[$this->id][$mId] += $qty;
}
// fetch and add socketbonusstats
if (@$this->json[$this->id]['socketbonus'] > 0)
- {
- $enh = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantment WHERE Id = ?;', $this->json[$this->id]['socketbonus']);
- $this->json[$this->id]['socketbonusstat'] = [];
- $socketbonusstat = Util::parseItemEnchantment($enh);
- foreach ($socketbonusstat as $k => $v)
- $this->json[$this->id]['socketbonusstat'][] = '"'.$k.'":'.$v;
-
- $this->json[$this->id]['socketbonusstat'] = "{".implode(',', $this->json[$this->id]['socketbonusstat'])."}";
- }
-
- // readdress itemset .. is wrong for virtual sets
- if ($pieceAssoc)
- $this->json[$this->id]['itemset'] = $pieceAssoc[$this->id];
+ if ($enh = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantment WHERE Id = ?;', $this->json[$this->id]['socketbonus']))
+ $this->json[$this->id]['socketbonusstat'] = Util::parseItemEnchantment($enh);
// gather random Enchantments
// todo: !important! extremly high sql-load
@@ -866,23 +877,12 @@ class ItemList extends BaseType
);
}
- $this->json[$this->id]['subitems'] = json_encode($this->subItems[$this->id], JSON_FORCE_OBJECT);
+ $this->json[$this->id]['subitems'] = $this->subItems[$this->id];
}
foreach ($this->json[$this->id] as $k => $v)
- {
- if (!isset($v) || $v === "false")
- {
+ if (!isset($v) || $v === "false" || (!in_array($k, ['classs', 'subclass']) && $v == "0"))
unset($this->json[$this->id][$k]);
- continue;
- }
-
- if (!in_array($k, ['classs', 'subclass', 'armor']) && $v === "0")
- {
- unset($this->json[$this->id][$k]);
- continue;
- }
- }
}
private function parseRating($type, $value, $interactive = false)
@@ -994,12 +994,14 @@ class ItemList extends BaseType
private function initJsonStats()
{
$json = array(
- 'id' => $this->id, // note to self: lowercase for js-Ids.. ALWAYS!!
+ 'id' => $this->id,
'name' => (ITEM_QUALITY_HEIRLOOM - $this->curTpl['Quality']).$this->names[$this->id],
'icon' => $this->curTpl['icon'],
'classs' => $this->curTpl['class'],
'subclass' => $this->curTpl['subclass'],
// 'subsubclass' => $this->curTpl['subsubclass'],
+ 'heroic' => (string)($this->curTpl['Flags'] & 0x8),
+ 'side' => Util::sideByRaceMask($this->curTpl['AllowableRace']), // check for FlagsExtra? 0:both; 1: Horde; 2:Alliance
'slot' => $this->curTpl['InventoryType'],
'slotbak' => $this->curTpl['InventoryType'],
'level' => $this->curTpl['ItemLevel'],
@@ -1054,7 +1056,7 @@ class ItemList extends BaseType
// clear zero-values afterwards
foreach ($json as $k => $v)
- if (!isset($v) || $v === "false" || (!in_array($k, ['classs', 'subclass', 'armor']) && $v === "0"))
+ if (!isset($v) || $v === "false" || (!in_array($k, ['classs', 'subclass']) && $v == "0"))
unset($json[$k]);
$this->json[$json['id']] = $json;
diff --git a/includes/class.itemset.php b/includes/class.itemset.php
index e4e200ed..c0780cd3 100644
--- a/includes/class.itemset.php
+++ b/includes/class.itemset.php
@@ -6,8 +6,7 @@ if (!defined('AOWOW_REVISION'))
class ItemsetList extends BaseType
{
private $classes = []; // used to build g_classes
- public $pieces = []; // used to build g_items and search
- public $pieceToSet = [];
+ public $pieceToSet = []; // used to build g_items and search
protected $setupQuery = 'SELECT *, id AS ARRAY_KEY FROM ?_itemset WHERE [filter] [cond] ORDER BY maxlevel ASC';
protected $matchQuery = 'SELECT COUNT(1) FROM ?_itemset WHERE [filter] [cond]';
@@ -35,7 +34,6 @@ class ItemsetList extends BaseType
{
if ($piece = $this->curTpl['item'.$i])
{
- $this->pieces[] = $piece;
$this->templates[$this->id]['pieces'][] = $piece;
$this->pieceToSet[$piece] = $this->id;
}
@@ -43,9 +41,7 @@ class ItemsetList extends BaseType
}
$this->reset();
- $this->classes = array_unique($this->classes);
- $this->pieces = array_unique($this->pieces);
- $this->pieceToSet = array_unique($this->pieceToSet);
+ $this->classes = array_unique($this->classes);
}
public function getListviewData()
@@ -78,8 +74,8 @@ class ItemsetList extends BaseType
if ($this->classes)
(new CharClassList(array(['id', $this->classes])))->addGlobalsToJscript($refs);
- if ($this->pieces)
- (new ItemList(array(['i.entry', $this->pieces])))->addGlobalsToJscript($refs);
+ if ($this->pieceToSet)
+ (new ItemList(array(['i.entry', array_keys($this->pieceToSet)])))->addGlobalsToJscript($refs);
}
public function addRewardsToJScript(&$ref) { }
diff --git a/pages/compare.php b/pages/compare.php
index 000829e8..f17eb1c3 100644
--- a/pages/compare.php
+++ b/pages/compare.php
@@ -30,7 +30,7 @@ if ($compareString)
while (sizeof($params) < 7)
$params[] = 0;
- $outString[] = "[".implode(',', $params)."]";
+ $outString[] = $params;
// MATCH() AGAINST() for integers would be nice...
$res = DB::Aowow()->SelectRow(
@@ -43,29 +43,23 @@ if ($compareString)
if ($res)
$piecesAssoc[(int)$params[0]] = $res['id'];
}
- $outSet[] = "[".implode(',', $outString)."]";
+ $outSet[] = $outString;
}
- $pageData['summary'] = "[".implode(',', $outSet)."]";
+ $pageData['summary'] = json_encode($outSet, JSON_NUMERIC_CHECK);
$iList = new ItemList(array(['i.entry', $items]));
- while ($iList->iterate())
+ $data = $iList->getListviewData(ITEMINFO_SUBITEMS | ITEMINFO_JSON);
+ foreach ($data as $id => $item)
{
- $iList->extendJsonStats();
- $stats = [];
-
- foreach ($iList->json[$iList->id] as $k => $v)
- $stats[] = is_numeric($v) || $v[0] == "{" ? '"'.$k.'":'.$v.'' : '"'.$k.'":"'.$v.'"';
-
- foreach ($iList->itemMods[$iList->id] as $k => $v)
- if ($v)
- $stats[] = '"'.Util::$itemMods[$k].'":'.$v;
+ while ($iList->id != $id)
+ $iList->iterate();
$pageData['items'][] = [
- $iList->id,
- Util::jsEscape($iList->names[$iList->id]),
+ $id,
+ Util::jsEscape($iList->names[$id]),
$iList->getField('Quality'),
$iList->getField('icon'),
- "{".implode(",", $stats)."}"
+ json_encode($item, JSON_NUMERIC_CHECK)
];
}
}
diff --git a/search.php b/search.php
index 4d21fa87..39e94b9d 100644
--- a/search.php
+++ b/search.php
@@ -239,7 +239,7 @@ if ($searchMask & 0x20)
'appendix' => ' (Item Set)',
'data' => $data,
'params' => ['tabs' => '$myTabs'],
- 'pieces' => $sets->pieces
+ 'pcsToSet' => $sets->pieceToSet
);
}
}
@@ -247,14 +247,17 @@ if ($searchMask & 0x20)
// 7 Items
if ($searchMask & 0x40)
{
- if (($searchMask & SEARCH_TYPE_JSON) && $type == TYPE_ITEMSET && $found['itemset']['pieces'])
- $conditions = [['i.class', [2, 4]], ['i.entry', $found['itemset']['pieces']]];
+ if (($searchMask & SEARCH_TYPE_JSON) && $type == TYPE_ITEMSET && isset($found['itemset']))
+ $conditions = [['i.entry', array_keys($found['itemset']['pcsToSet'])]];
+ else if (($searchMask & SEARCH_TYPE_JSON) && $type == TYPE_ITEM)
+ $conditions = [['i.class', [2, 4]], [User::$localeId ? 'name_loc'.User::$localeId : 'name', $query], 0];
else
$conditions = [[User::$localeId ? 'name_loc'.User::$localeId : 'name', $query], 0];
- $items = new ItemList($conditions);
+
+ $items = new ItemList($conditions, @$found['itemset']['pcsToSet']);
$items->addGlobalsToJscript($jsGlobals);
- if ($data = $items->getListviewData($searchMask & SEARCH_TYPE_JSON ? ITEMINFO_SUBITEMS : 0))
+ if ($data = $items->getListviewData($searchMask & SEARCH_TYPE_JSON ? (ITEMINFO_SUBITEMS | ITEMINFO_JSON) : 0))
{
while ($items->iterate())
{
@@ -347,12 +350,51 @@ if ($searchMask & 0x10000)
// 26 Guilds
// if ($searchMask & 0x2000000)
-
+/*
+ !note! dear reader, if you ever try to generate a string, that is to be evaled by JS, NEVER EVER terminate with a \n
+ $totalHoursWasted +=2;
+*/
if ($searchMask & SEARCH_TYPE_JSON)
{
+ $outItems = '';
+ $outSets = '';
+
+ if (isset($found['item']))
+ {
+ $items = [];
+
+ foreach ($found['item']['data'] as $k => $v)
+ {
+ unset($v['param1']);
+ unset($v['param2']);
+
+ $items[] = json_encode($v, JSON_NUMERIC_CHECK);
+ }
+
+ $outItems = "\t".implode(",\n\t", $items)."\n";
+ }
+
+ if (isset($found['itemset']))
+ {
+ $sets = [];
+
+ foreach ($found['itemset']['data'] as $k => $v)
+ {
+ $v['name'] = $v['quality'].$v['name'];
+
+ unset($v['param1']);
+ unset($v['quality']);
+ if (!$v['heroic'])
+ unset($v['heroic']);
+
+ $sets[] = json_encode($v, JSON_NUMERIC_CHECK);
+ }
+
+ $outSets = "\t".implode(",\n\t", $sets)."\n";
+ }
+
header("Content-type: text/javascript");
- echo "// not yet supported \n";
- exit ("[\"".Util::jsEscape($query)."\", [\n],[\n]]\n");
+ die ('["'.Util::jsEscape($query)."\", [\n".$outItems."],[\n".$outSets.']]');
}
else if ($searchMask & SEARCH_TYPE_OPEN)
{
@@ -421,7 +463,7 @@ else /* if ($searchMask & SEARCH_TYPE_REGULAR) */
$smarty->updatePageVars($vars);
$smarty->assign('lang', array_merge(Lang::$main, Lang::$search));
- $smarty->assign('found', $found);
+ $smarty->assign('found', $found);
$smarty->assign('data', $jsGlobals);
$smarty->assign('search', $search);
$smarty->assign('mysql', DB::Aowow()->getStatistics());