/** * Получение полных данных записи каталога. * * @param integer $id Идентификатор материала. * @param string $section Полный строковой идентификатор раздела. * @param integer $idsec=0 Числовой идентификатор раздела. * @return array */ function catalog_getItem($id, $section, $idsec = 0) { static $cache = array(); if (isset($cache[$section][$id])) { return $cache[$section][$id]; } if ($row = A::$DB->getRow("SELECT * FROM {$section}_catalog WHERE id=?i AND active='Y'", $id)) { if (!$idsec) { $idsec = getSectionId($section); } $row['link'] = catalog_createItemLink($row['id'], $section); $row['vote'] = round($row['vote'], 2); if ($row['idcat'] > 0) { $row['category'] = getTreePath("{$section}_categories", $row['idcat']); } $row['images'] = A::$DB->getAll("SELECT * FROM " . A::$DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array($idsec, $row['id'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); prepareValues($section, $row); $row = A::$OBSERVER->Modifier('catalog_prepareValues', $section, $row); return $cache[$section][$id] = $row; } else { return $cache[$section][$id] = false; } }
A::$DB->queryLimit("\r\r\n SELECT a.*,c.name AS category\r\r\n FROM {$section}_catalog AS a\r\r\n LEFT JOIN {$section}_categories AS c ON c.id=a.idcat\r\r\n WHERE a.active='Y' " . ($idcat > 0 ? " AND a.idcat={$idcat}" : "") . "\r\r\n ORDER BY date DESC", 0, $rssrow['rows']); while ($row = A::$DB->fetchRow()) { $item = array('title' => $row['name'], 'link' => "http://" . DOMAINNAME . catalog_createItemLink($row['id'], $section), 'pubDate' => date("r", $row['date']), 'description' => strip_tags($row['description'])); if (!empty($row['category'])) { $item['category'] = $row['category']; } $data['channel'][] = $item; } A::$DB->free(); } else { $items = array(); $sections = getSectionsByModule('catalog'); foreach ($sections as $section) { A::$DB->queryLimit("\r\r\n SELECT a.*,c.name AS category\r\r\n FROM {$section}_catalog AS a\r\r\n LEFT JOIN {$section}_categories AS c ON c.id=a.idcat\r\r\n WHERE a.active='Y'\r\r\n ORDER BY date DESC", 0, $rssrow['rows']); while ($row = A::$DB->fetchRow()) { $row['link'] = catalog_createItemLink($row['id'], $section); $items[] = $row; } A::$DB->free(); } $items = array_multisort_key($items, 'date', SORT_DESC); $items = array_slice($items, 0, $rssrow['rows']); foreach ($items as $row) { $item = array('title' => $row['name'], 'link' => "http://" . DOMAINNAME . $row['link'], 'pubDate' => date("r", $row['date']), 'description' => strip_tags($row['description'])); if (!empty($row['category'])) { $item['category'] = $row['category']; } $data['channel'][] = $item; } } $serializer->serialize($data);
/** * Формирование данных доступных в шаблоне. */ function createData() { $this->supportCached(); $this->addCacheParam_Get('page'); if ($this->month == 0) { $this->month = date('m'); } if ($this->year == 0) { $this->year = date('Y'); } $checkeds = !empty(A::$OPTIONS['sections']) ? unserialize(A::$OPTIONS['sections']) : array(); $srows = $sections = array(); foreach ($checkeds as $idsec) { if ($srow = A::$DB->getRowById($idsec, DOMAIN . "_sections")) { $section = DOMAIN . "_" . $srow['lang'] . "_" . $srow['name']; $sections[$section] = $srow['module']; $srows[$section] = $srow; } } $calendar = new A_Calendar($sections); $this->Assign("calendar", $calendar->getMonthHTML($this->day, $this->month, $this->year)); if ($this->day > 0) { $date1 = mktime(0, 0, 0, $this->month, $this->day, $this->year); $date2 = mktime(23, 59, 59, $this->month, $this->day, $this->year); $this->Assign("date", $date1); } else { $date1 = mktime(0, 0, 0, $this->month, 1, $this->year); $date2 = mktime(0, 0, 0, $this->month + 1 > 12 ? 1 : $this->month + 1, 1, $this->month + 1 > 12 ? $this->year + 1 : $this->year) - 1; $this->Assign("date1", $date1); $this->Assign("date2", $date2); } $items = array(); foreach ($sections as $section => $module) { $srows[$section]['caption'] = $srows[$section]['caption_' . LANG]; $srows[$section]['link'] = getSectionLink($section); A::$DB->query("SELECT *,svote/cvote AS vote FROM {$section}_catalog WHERE date>={$date1} AND date<={$date2} AND active='Y' ORDER BY date"); while ($row = A::$DB->fetchRow()) { $row['section'] = $section; $items[] = $row; } A::$DB->free(); } $items = array_multisort_key($items, 'date'); $pager = new A_Pager(A::$OPTIONS['rows']); $items = $pager->setItems($items); foreach ($items as $i => $row) { $section = $row['section']; $row['section'] = $srows[$section]; $row['section_name'] = $srows[$section]['caption']; $row['section_link'] = $srows[$section]['link']; $row['link'] = catalog_createItemLink($row['id'], $section); $row['vote'] = round($row['vote'], 2); $row['category'] = getTreePath("{$section}_categories", $row['idcat']); $row['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array($srows[$section]['id'], $row['id'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; $row['files'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_files WHERE idsec=? AND iditem=? ORDER BY sort", array($srows[$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 (!empty($row['tags'])) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues($section, $row); $items[$i] = $row; } $this->Assign("items", $items); $this->Assign("items_pager", $pager); $this->AddNavigation(SECTION_NAME); }
/** * Формирование данных доступных в шаблоне страницы категории. */ function CategoryPage() { if (empty($_GET['filter'])) { $this->supportCached(); $this->addCacheParam_Get('filter'); $this->addCacheParam_Get('page'); } 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); $categories = array(); A::$DB->query("SELECT * FROM " . SECTION . "_categories WHERE idker={$this->idcat} AND active='Y' ORDER BY sort"); while ($row = A::$DB->fetchRow()) { $row['link'] = catalog_createCategoryLink($row['id'], SECTION); $row['subcategories'] = array(); A::$DB->query("SELECT * FROM " . SECTION . "_categories WHERE idker={$row['id']} AND active='Y' ORDER BY sort"); while ($subrow = A::$DB->fetchRow()) { $subrow['link'] = catalog_createCategoryLink($subrow['id'], SECTION); $row['subcategories'][] = $subrow; } A::$DB->free(); $categories[] = $row; } A::$DB->free(); $this->Assign("categories", $categories); if (!empty($_REQUEST['sort'])) { A_Session::set(SECTION . '_csort', $_REQUEST['sort']); } if (!empty($_REQUEST['rows'])) { A_Session::set(SECTION . '_crows', $_REQUEST['rows']); } $sort = escape_order_string(A_Session::get(SECTION . '_csort', !empty(A::$OPTIONS['mysort']) ? A::$OPTIONS['mysort'] : A::$OPTIONS['sort'])); $rows = (int) A_Session::get(SECTION . '_crows', A::$OPTIONS['crows']); $this->Assign("rows", $rows); $this->Assign("sort", $sort); $where = $this->frontfilter(); $items = array(); $pager = new A_Pager($rows); $pager->query("SELECT *,svote/cvote AS vote FROM " . SECTION . "_catalog WHERE idcat={$this->idcat} AND active='Y'{$where} ORDER BY {$sort}"); while ($row = $pager->fetchRow()) { $row['link'] = catalog_createItemLink($row['id'], SECTION); $row['category'] = getTreePath(SECTION . "_categories", $row['idcat']); $row['vote'] = round($row['vote'], 2); 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['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues(SECTION, $row); $row = A::$OBSERVER->Modifier('catalog_prepareValues', SECTION, $row); $items[] = $row; } $pager->free(); $this->Assign("items", $items); $this->Assign("items_pager", $pager); $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); $this->AddNavCategories($this->category['idker']); $this->AddNavigation($this->category['name']); $this->title = $this->category['name'] . (!empty($this->title) ? " - " . $this->title : ""); $this->description = $this->category['description']; }
/** * Формирование данных доступных в шаблоне. */ function createData() { if (!A_Session::is_set(SECTION . "_filter")) { $this->unFilter(); } $categories = A::$DB->getAll("SELECT id,idker,name FROM " . SECTION . "_categories ORDER BY level,sort"); $this->Assign("categories", $categories); if (!empty($_GET['idcat'])) { $this->Assign("category", A::$DB->getRowById($_GET['idcat'], SECTION . "_categories")); $idcat = (int) $_GET['idcat']; $childcats = array($idcat); getTreeSubItems(SECTION . "_categories", $idcat, $childcats); $where = "c.idcat IN(" . implode(",", $childcats) . ")"; $this->Assign("childcats", $childcats = count($childcats)); } else { $where = ""; } if ($filter = $this->getFilter()) { $where = !empty($where) ? "{$where} AND {$filter}" : $filter; } $rows = (int) A_Session::get(SECTION . "_rows", isset($_COOKIE[SECTION . '_rows']) ? $_COOKIE[SECTION . '_rows'] : 10); $sort = escape_order_string(A_Session::get(SECTION . "_sort", isset($_COOKIE[SECTION . '_sort']) ? $_COOKIE[SECTION . '_sort'] : A::$OPTIONS['sort'])); $items = array(); $pager = new A_Pager($rows); $pager->tab = "items"; $pager->query("\r\r\n\tSELECT c.*,c.svote/c.cvote AS vote,cc.name AS category\r\r\n\tFROM " . SECTION . "_catalog AS c\r\r\n\tLEFT JOIN " . SECTION . "_categories AS cc ON cc.id=c.idcat\r\r\n\t" . (!empty($where) ? " WHERE {$where}" : "") . "\r\r\n\tORDER BY {$sort}"); while ($row = $pager->fetchRow()) { $row['link'] = catalog_createItemLink($row['id'], SECTION); $row['vote'] = round($row['vote'], 2); 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'])); $row['idfile'] = isset($row['files'][0]['id']) ? $row['files'][0]['id'] : 0; } $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); if (empty($_GET['idcat']) || $childcats > 1) { $row['catpath'] = getTreePath(SECTION . "_categories", $row['idcat']); } $items[] = $row; } $pager->free(); $this->Assign("items", $items); $this->Assign("items_pager", $pager); $this->Assign("treebox", new A_CategoriesTree("items")); if (A::$OPTIONS['usecomments']) { $this->Assign("commbox", new A_CommentsEditor(SECTION . "_catalog")); } $this->Assign("optbox1", new A_OptionsBox("Внешний вид на сайте:", array('idgroup' => 1))); $this->Assign("optbox2", new A_OptionsBox("Файлы:", array('idgroup' => 2))); $this->Assign("optbox3", new A_OptionsBox("Комментирование и голосование:", array('idgroup' => 3))); $this->Assign("optbox4", new A_OptionsBox("Дополнительно:", array('idgroup' => 4))); $this->Assign("fieldsbox", new A_FieldsEditor(SECTION . "_catalog", array('tab' => 'opt', 'tab_opt' => 'fields'), false, true)); $this->Assign("rows", $rows); $this->Assign("sort", $sort); $this->Assign("filter", !empty($filter)); }
/** * Формирование данных доступных в шаблоне. */ 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'] = catalog_createCategoryLink($this->params['idcat'], $this->section); $this->Assign("category", $catrow); } if ($this->section == SECTION && A::$MAINFRAME->iditem) { $useitems[$this->section][] = A::$MAINFRAME->iditem; } switch ($this->params['sort']) { default: case 1: $sort = "date DESC"; break; case 2: $sort = "date"; break; case 3: $sort = "name"; 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) . ")"; } if (!empty($this->params['filter'])) { $where[] = $this->params['filter']; } if (!empty($useitems[$this->section]) && !empty($this->params['nodouble'])) { $where[] = "NOT id IN(" . implode(',', $useitems[$this->section]) . ")"; } $sql = "\r\r\n\tSELECT *,svote/cvote AS vote 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()) { $row['category'] = getTreePath($this->section . "_categories", $row['idcat']); $row['link'] = catalog_createItemLink($row['id'], $this->section); $row['vote'] = round($row['vote'], 2); 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['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues($this->section, $row); $row = A::$OBSERVER->Modifier('catalog_prepareValues', $this->section, $row); $useitems[$this->section][] = $row['id']; $items[] = $row; } A::$DB->free(); $this->Assign("items", $items); $this->Assign("items_count", count($items)); }