/** * Интеграция в карту сайта ссылок на категории. * * @param object &$treeitem Объект дерева карты сайта. * @param string $section Полный строковой идентификатор раздела. * @param integer $id=0 Идентификатор родительской категории. */ function shoplite_createMap_Categories(&$treeitem, $section, $id = 0) { A::$DB->query("SELECT * FROM {$section}_categories WHERE idker={$id} AND active='Y' ORDER BY sort"); while ($row = A::$DB->fetchRow()) { $treeitem->items[$row['id']] = new SiteMap_Box($row['name'], shoplite_createCategoryLink($row['id'], $section)); shoplite_createMap_Categories($treeitem->items[$row['id']], $section, $row['id']); } A::$DB->free(); }
/** * Формирование данных доступных в шаблоне страницы результатов поиска. */ function ResultPage() { if (!empty($_REQUEST['sort'])) { A_Session::set(SECTION . '_rsort', $_REQUEST['sort']); } if (!empty($_REQUEST['rows'])) { A_Session::set(SECTION . '_rrows', $_REQUEST['rows']); } $sort = escape_order_string(A_Session::get(SECTION . '_rsort', !empty(A::$OPTIONS['mysort']) ? A::$OPTIONS['mysort'] : A::$OPTIONS['sort'])); $rows = (int) A_Session::get(SECTION . '_rrows', A::$OPTIONS['rrows']); $this->Assign("rows", $rows); $this->Assign("sort", $sort); $_GET['filter'] = 1; $fields = array('name' => 'string', 'content' => 'string', 'tags' => 'string', 'art' => 'string', 'date' => 'int', 'price' => 'int', 'favorite' => 'bool', 'new' => 'bool'); $where = $this->frontfilter('', $fields); if (!empty($_GET['idcat'])) { if (is_array($_GET['idcat'])) { $where2 = array(); foreach ($_GET['idcat'] as $idcat) { if ($idcats = $this->childCategories((int) $idcat)) { $where2[] = "(idcat IN(" . implode(",", $idcats) . ") OR idcat1 IN(" . implode(",", $idcats) . ") OR idcat2 IN(" . implode(",", $idcats) . "))"; } } $where .= " AND (" . implode(" OR ", $where2) . ")"; } elseif (empty($this->idcat)) { if ($this->category = A::$DB->getRowById($_GET['idcat'], SECTION . "_categories")) { A::goUrl(shoplite_createCategoryLink($this->category['id'], SECTION) . 'result.html?' . getenv('QUERY_STRING')); } } } if ($this->category) { $this->category['link'] = shoplite_createCategoryLink($this->category['id'], SECTION); if (A::$OPTIONS['usetags']) { $this->category['tags'] = A_SearchEngine::getInstance()->convertTags($this->category['tags']); } $this->category = A::$OBSERVER->Modifier('fcategory_prepareValues', SECTION, $this->category); $this->Assign("category", $this->category); if ($idcats = $this->childCategories($this->idcat)) { $where .= " AND (idcat IN(" . implode(",", $idcats) . ") OR idcat1 IN(" . implode(",", $idcats) . ") OR idcat2 IN(" . implode(",", $idcats) . "))"; } } $items = array(); $pager = new A_Pager($rows); $pager->query("SELECT *,svote/cvote AS vote FROM " . SECTION . "_catalog WHERE active='Y'{$where} ORDER BY {$sort}"); while ($row = $pager->fetchRow()) { $row['link'] = shoplite_createItemLink($row['id'], SECTION); $row['tobasketlink'] = getSectionLink(SECTION) . "?action=addbasket&id=" . $row['id']; $row['tocomparelink'] = getSectionLink(SECTION) . "?action=addcompare&id=" . $row['id']; $row['category'] = getTreePath(SECTION . "_categories", $row['idcat']); $row['vote'] = round($row['vote'], 2); $row['available'] = $row['iscount'] > 0; if (A::$OPTIONS['useimages']) { $row['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $row['id'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; } if (A::$OPTIONS['usefiles']) { $row['files'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_files WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $row['id'])); foreach ($row['files'] as $i => $data) { $row['files'][$i]['link'] = (LANG == DEFAULTLANG ? "" : "/" . LANG) . "/getfile/" . $data['id'] . "/" . $data['name']; $row['files'][$i]['size'] = sizestring($data['size']); } $row['idfile'] = isset($row['files'][0]['id']) ? $row['files'][0]['id'] : 0; } if (A::$OPTIONS['modprices']) { $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array(); $row['mprices'] = array(); foreach ($mprices as $i => $mp) { $row['mprices'][] = array('id' => $i, 'name' => $mp['name'], 'price' => $mp['price']); } } if (A::$OPTIONS['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues(SECTION, $row); $row = A::$OBSERVER->Modifier('shoplite_prepareValues', SECTION, $row); $items[] = $row; } $this->Assign("items", $items); $this->Assign("items_pager", $pager); $data = $pars = array(); foreach ($_GET as $field => $value) { if (!empty($value)) { if (is_array($value)) { $p = array(); foreach ($value as $val) { $p[] = "{$field}[]=" . (int) $val; } $pars[$field] = implode("&", $p); $data[$field] = implode(",", $value); } else { $pars[$field] = "{$field}=" . urlencode($value); $data[$field] = $value; } } } prepareValues(SECTION, $data); $filters = array(); A::$DB->query("SELECT * FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' ORDER BY sort"); while ($row = A::$DB->fetchRow()) { if (!empty($data[$row['field']])) { $filters[] = array('field' => $row['field'], 'caption' => $row['name_' . A::$LANG], 'value' => $data[$row['field']], 'link' => getSectionLink(SECTION) . "result.html?" . $pars[$row['field']]); } } A::$DB->free(); $this->Assign("filters", $filters); $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); $this->AddNavCategories($this->idcat); }
/** * Формирование данных доступных в шаблоне. */ function createData() { static $useitems = array(); if ($this->params['sort'] != 5) { $this->supportCached(); } $this->params['idcat'] = (int) $this->params['idcat']; $this->params['rows'] = (int) $this->params['rows']; if ($this->params['idcat']) { $catrow = A::$DB->getRowById($this->params['idcat'], "{$this->section}_categories"); $catrow['link'] = shoplite_createCategoryLink($this->params['idcat'], $this->section); $this->Assign("category", $catrow); } if ($this->section == SECTION && A::$MAINFRAME->iditem) { $useitems[] = A::$MAINFRAME->iditem; } if (!empty($this->params['mysort'])) { $sort = $this->params['mysort']; } else { switch ($this->params['sort']) { case 1: $sort = "name"; break; case 2: $sort = "price DESC"; break; case 3: $sort = "price"; break; case 4: $sort = "sort"; break; case 5: $sort = "RAND()"; break; } } $where = array(); if ($this->params['idcat']) { $idcat = $this->params['idcat']; $childcats = array($idcat); getTreeSubItems($this->section . "_categories", $idcat, $childcats); $where[] = "(idcat IN(" . implode(",", $childcats) . ") OR idcat1 IN(" . implode(",", $childcats) . ") OR idcat2 IN(" . implode(",", $childcats) . "))"; } switch ($this->params['filter']) { case 1: $where[] = "favorite='Y'"; break; case 2: $where[] = "new='Y'"; break; } if (!empty($this->params['myfilter'])) { $where[] = $this->params['myfilter']; } if ($useitems && !empty($this->params['nodouble'])) { $where[] = "NOT id IN(" . implode(',', $useitems) . ")"; } $sql = "\r\r\n\tSELECT * FROM {$this->section}_catalog\r\r\n\tWHERE active='Y'" . (!empty($where) ? " AND " . implode(" AND ", $where) : "") . "\r\r\n\tORDER BY {$sort}"; if ($this->params['rows']) { A::$DB->queryLimit($sql, 0, $this->params['rows']); } else { A::$DB->query($sql); } $items = array(); while ($row = A::$DB->fetchRow()) { if ($this->params['idcat'] == 0) { $row['category'] = getTreePath($this->section . "_categories", $row['idcat']); } $row['link'] = shoplite_createItemLink($row['id'], $this->section); $row['tobasketlink'] = getSectionLink($this->section) . "?action=addbasket&id=" . $row['id']; $row['vote'] = $row['cvote'] > 0 ? round($row['svote'] / $row['cvote'], 2) : 0; $row['available'] = $row['iscount'] > 0; if ($this->options['useimages']) { $row['images'] = A::$DB->getAll("\r\r\n\t SELECT * FROM " . getDomain($this->section) . "_images\r\r\n\t WHERE idsec=? AND iditem=? ORDER BY sort", array($this->section_id, $row['id'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; } if ($this->options['usefiles']) { $row['files'] = A::$DB->getAll("\r\r\n\t SELECT * FROM " . getDomain($this->section) . "_files\r\r\n\t WHERE idsec=? AND iditem=? ORDER BY sort", array($this->section_id, $row['id'])); foreach ($row['files'] as $i => $data) { $row['files'][$i]['link'] = (LANG == DEFAULTLANG ? "" : "/" . LANG) . "/getfile/" . $data['id'] . "/" . $data['name']; $row['files'][$i]['size'] = sizestring($data['size']); } $row['idfile'] = isset($row['files'][0]['id']) ? $row['files'][0]['id'] : 0; } if ($this->options['modprices']) { $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array(); $row['mprices'] = array(); foreach ($mprices as $i => $mp) { $row['mprices'][] = array('id' => $i, 'name' => $mp['name'], 'price' => $mp['price']); } } if ($this->options['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues($this->section, $row); $row = A::$OBSERVER->Modifier('shoplite_prepareValues', $this->section, $row); $useitems[] = $row['id']; $items[] = $row; } A::$DB->free(); $this->Assign("items", $items); $this->Assign("items_count", count($items)); $this->Assign('valute', $this->options['valute']); }