diff --git a/endpoints/compare/compare.php b/endpoints/compare/compare.php new file mode 100644 index 00000000..f2cffbe0 --- /dev/null +++ b/endpoints/compare/compare.php @@ -0,0 +1,117 @@ + ['filter' => FILTER_CALLBACK, 'options' => [self::class, 'checkCompareString']] + ); + protected array $expectedCOOKIE = array( + 'compare_groups' => ['filter' => FILTER_CALLBACK, 'options' => [self::class, 'checkCompareString']] + ); + + public Summary $summary; + public array $cmpItems = []; + + private string $compareString = ''; + + public function __construct($pageParam) + { + parent::__construct($pageParam); + + // prefer GET over COOKIE + if ($this->_get['compare']) + $this->compareString = $this->_get['compare']; + else if ($this->_cookie['compare_groups']) + $this->compareString = $this->_cookie['compare_groups']; + } + + protected function generate() : void + { + $this->h1 = Lang::main('compareTool'); + + + array_unshift($this->title, $this->h1); + + + $this->summary = new Summary(array( + 'template' => 'compare', + 'id' => 'compare', + 'parent' => 'compare-generic' + )); + + if ($this->compareString) + { + $items = []; + foreach (explode(';', $this->compareString) as $itemsString) + { + $suGroup = []; + foreach (explode(':', $itemsString) as $itemDef) + { + // [itemId, subItem, permEnch, tempEnch, gem1, gem2, gem3, gem4] + $params = array_pad(array_map('intVal', explode('.', $itemDef)), 8, 0); + $items[] = $params[0]; + $suGroup[] = $params; + } + + $this->summary->addGroup($suGroup); + } + + $iList = new ItemList(array(['i.id', $items])); + $data = $iList->getListviewData(ITEMINFO_SUBITEMS | ITEMINFO_JSON); + + foreach ($iList->iterate() as $itemId => $__) + { + if (empty($data[$itemId])) + continue; + + if (!empty($data[$itemId]['subitems'])) + foreach ($data[$itemId]['subitems'] as &$si) + { + $si['enchantment'] = implode(', ', $si['enchantment']); + unset($si['chance']); + } + + $this->cmpItems[$itemId] = [ + 'name_'.Lang::getLocale()->json() => $iList->getField('name', true), + 'quality' => $iList->getField('quality'), + 'icon' => $iList->getField('iconString'), + 'jsonequip' => $data[$itemId] + ]; + } + } + + parent::generate(); + } + + protected static function checkCompareString(string $val) : string + { + $val = urldecode($val); + if (preg_match('/[^\d\.:;]/', $val)) + return ''; + + return $val; + } +} + +?> diff --git a/pages/compare.php b/pages/compare.php deleted file mode 100644 index c1d8beb2..00000000 --- a/pages/compare.php +++ /dev/null @@ -1,120 +0,0 @@ - ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\ComparePage::checkCompareString']]; - protected $_cookie = ['compare_groups' => ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\ComparePage::checkCompareString']]; - - private $compareString = ''; - - public function __construct($pageCall, $__) - { - parent::__construct($pageCall, $__); - - // prefer GET over COOKIE - if ($this->_get['compare']) - $this->compareString = $this->_get['compare']; - else if ($this->_cookie['compare_groups']) - $this->compareString = $this->_cookie['compare_groups']; - - $this->name = Lang::main('compareTool'); - } - - protected function generateContent() - { - // add conditional js - $this->addScript([SC_JS_FILE, '?data=weight-presets.gems.enchants.itemsets']); - - $this->summary = array( - 'template' => 'compare', - 'id' => 'compare', - 'parent' => 'compare-generic' - ); - - if (!$this->compareString) - return; - - $sets = explode(';', $this->compareString); - $items = $outSet = []; - foreach ($sets as $set) - { - $itemString = explode(':', $set); - $outString = []; - foreach ($itemString as $is) - { - $params = array_pad(explode('.', $is), 7, 0); - $items[] = (int)$params[0]; - - $outString[] = $params; - } - - $outSet[] = $outString; - } - - $this->summary['groups'] = $outSet; - - $iList = new ItemList(array(['i.id', $items])); - $data = $iList->getListviewData(ITEMINFO_SUBITEMS | ITEMINFO_JSON); - - foreach ($iList->iterate() as $itemId => $__) - { - if (empty($data[$itemId])) - continue; - - if (!empty($data[$itemId]['subitems'])) - foreach ($data[$itemId]['subitems'] as &$si) - { - $si['enchantment'] = implode(', ', $si['enchantment']); - unset($si['chance']); - } - - $this->cmpItems[$itemId] = [ - 'name_'.Lang::getLocale()->json() => $iList->getField('name', true), - 'quality' => $iList->getField('quality'), - 'icon' => $iList->getField('iconString'), - 'jsonequip' => $data[$itemId] - ]; - } - } - - protected function generateTitle() - { - array_unshift($this->title, $this->name); - } - - protected function generatePath() {} - - protected static function checkCompareString(string $val) : string - { - $val = urldecode($val); - if (preg_match('/[^\d\.:;]/', $val)) - return ''; - - return $val; - } -} - -?> diff --git a/template/pages/compare.tpl.php b/template/pages/compare.tpl.php index 4ff79208..6f98f7fb 100644 --- a/template/pages/compare.tpl.php +++ b/template/pages/compare.tpl.php @@ -1,7 +1,8 @@ - - -brick('header'); ?> +brick('header'); +?>
@@ -17,10 +18,10 @@