/** * Обработчик действия: Сохранение текста страницы. */ function SavePage() { setTextOption(SECTION, 'content', $_REQUEST['content']); $name = A::$DB->getOne("SELECT caption_" . A::$LANG . " FROM " . DOMAIN . "_sections WHERE id=" . SECTION_ID); A_SearchEngine::getInstance()->updateIndex(SECTION_ID, 0, $name, $_REQUEST['content']); return true; }
/** * Формирование данных доступных в шаблоне. */ function createData() { $this->supportCached(); $count = isset($this->params['count']) ? (int) $this->params['count'] : 50; $idsec = !empty($this->params['idsearch']) ? (int) $this->params['idsearch'] : 0; $this->Assign('tags', A_SearchEngine::getInstance()->getCloudTags($count, 10, $idsec)); }
/** * Обработчик события "Удаление раздела". * * @param string $section Полный строковой идентификатор раздела. * @param array $params Параметры события. */ function search_deleteSection($section, $params) { if ($params['module'] == 'search') { A_SearchEngine::getInstance()->resetSection(); } else { A_SearchEngine::getInstance()->deleteSection($params['id']); } }
/** * Формирование данных доступных в шаблоне. */ function createData() { 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'] = gallery_createCategoryLink($this->params['idcat'], $this->section); $this->Assign("category", $catrow); } 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; } $sql = "\r\r\n\tSELECT *,svote/cvote AS vote FROM {$this->section}_albums\r\r\n\tWHERE active='Y'" . ($this->params['idcat'] ? " AND idcat={$this->params['idcat']}" : "") . (!empty($this->params['filter']) ? " AND {$this->params['filter']}" : "") . "\r\r\n\tORDER BY {$sort}"; if ($this->params['rows']) { A::$DB->queryLimit($sql, 0, $this->params['rows']); } else { A::$DB->query($sql); } $albums = array(); while ($row = A::$DB->fetchRow()) { $row['category'] = getTreePath($this->section . "_categories", $row['idcat']); $row['link'] = gallery_createItemLink($row['id'], $this->section); $row['vote'] = round($row['vote'], 2); $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'])); if ($this->options['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues($this->section, $row); $row = A::$OBSERVER->Modifier('gallery_prepareValues', $this->section, $row); $albums[] = $row; } A::$DB->free(); $this->Assign("albums", $albums); }
/** * Обработчик действия: Отдает форму редактирования. */ function Edit() { $form = new A_Form("block_cloud_edit.tpl"); $block = A::$DB->getRowById($_POST['id'], DOMAIN . "_blocks"); $form->data = !empty($block['params']) ? unserialize($block['params']) : array(); if (!isset($form->data['count'])) { $form->data['count'] = 50; } $form->data['sections'] = A_SearchEngine::getInstance()->getSections(); foreach ($form->data['sections'] as $idsec => $caption) { if (!getOption(getSectionById($idsec), 'usetags')) { unset($form->data['sections'][$idsec]); } } $this->RESULT['html'] = $form->getContent(); }
/** * Формирование данных доступных в шаблоне. */ function createData() { $this->supportCached(true); $this->params['idcat'] = (int) $this->params['idcat']; if (isset($this->params['curcheck']) && $this->section == SECTION && A::$MAINFRAME->id > 0) { $this->params['idcat'] = A::$MAINFRAME->idker; } $links = array(); A::$DB->query("SELECT * FROM {$this->section} WHERE idker={$this->params['idcat']} AND active='Y' ORDER BY sort"); while ($row = A::$DB->fetchRow()) { if ($row['urlname'] == 'index') { continue; } $row['link'] = pages_createItemLink($row['id'], $this->section); $row['selected'] = $this->section == SECTION && ($row['id'] == A::$MAINFRAME->id || $row['type'] == 'dir' && $row['id'] == A::$MAINFRAME->idker); $row['subindex'] = false; if ($row['type'] == 'dir') { $row['sublinks'] = array(); A::$DB->query("SELECT id,name,urlname,type,level,content FROM {$this->section} WHERE idker={$row['id']} AND active='Y' ORDER BY sort"); while ($subrow = A::$DB->fetchRow()) { if ($subrow['urlname'] == 'index') { $row['subindex'] = true; continue; } $subrow['link'] = pages_createItemLink($subrow['id'], $this->section); $subrow['selected'] = $this->section == SECTION && $subrow['id'] == A::$MAINFRAME->id; $row['sublinks'][] = $subrow; } A::$DB->free(); } elseif ($this->options['usetags']) { $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); } prepareValues($this->section, $row); $links[] = $row; } A::$DB->free(); $this->Assign("links", $links); }
/** * Получение полных данных страницы. * * @param integer $id Идентификатор страницы. * @param string $section Полный строковой идентификатор раздела. * @param integer $idsec=0 Числовой идентификатор раздела. * @return array */ function pages_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} WHERE id=?i AND active='Y'", $id)) { $row['link'] = pages_createItemLink($row['id'], $section); $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']); prepareValues($section, $row); return $cache[$section][$id] = $row; } else { return $cache[$section][$id] = false; } }
/** * Обработчик действия: Импорт каталога. */ function Import() { @set_time_limit(0); require_once "Structures/DataGrid.php"; require_once "Structures/DataGrid/DataSource/Excel.php"; require_once "Structures/DataGrid/DataSource/CSV.php"; require_once 'Image/Transform.php'; mk_dir("files/" . DOMAIN . "/tmp"); clearDir("files/" . DOMAIN . "/tmp"); if (isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name'])) { $path_parts = pathinfo($_FILES['file']['name']); $ext = preg_replace("/[^a-z0-9]+/i", "", mb_strtolower($path_parts['extension'])); if ($ext == 'xls' || $ext == 'csv' || $ext == 'gz') { if ($ext == 'gz') { if (extractArchive($_FILES['file']['tmp_name'], "files/" . DOMAIN . "/tmp")) { $sourcefile1 = preg_replace("/tar\\.gz\$/i", "xls", $_FILES['file']['name']); $sourcefile2 = preg_replace("/tar\\.gz\$/i", "csv", $_FILES['file']['name']); if (is_file("files/" . DOMAIN . "/tmp/{$sourcefile1}")) { $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile1}"; $ext = "xls"; } elseif (is_file("files/" . DOMAIN . "/tmp/{$sourcefile2}")) { $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile2}"; $content = @file_get_contents($sourcefile); if ($content && !mb_check_encoding($content, 'UTF-8')) { file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251')); } $ext = "csv"; } else { return false; } } else { return false; } } elseif ($ext == 'csv') { $sourcefile = $_FILES['file']['tmp_name']; $content = @file_get_contents($sourcefile); if ($content && !mb_check_encoding($content, 'UTF-8')) { file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251')); } } else { $sourcefile = $_FILES['file']['tmp_name']; } if (!empty($_REQUEST['clear'])) { switch ($_REQUEST['clear']) { case 1: A::$DB->execute("TRUNCATE " . SECTION . "_categories"); case 2: A::$DB->execute("TRUNCATE " . SECTION . "_catalog"); A::$DB->execute("DELETE FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem>0"); A::$DB->execute("DELETE FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem>0"); A::$DB->execute("DELETE FROM " . DOMAIN . "_comments WHERE idsec=" . SECTION_ID); A_SearchEngine::getInstance()->deleteSection(SECTION_ID); break; } } A::$OPTIONS['imgpath'] = !empty(A::$OPTIONS['imgpath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['imgpath']) : "ifiles"; A::$OPTIONS['filepath'] = !empty(A::$OPTIONS['filepath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['filepath']) : "ifiles"; $categories = array(); $fields = array(); $cfiles = array(); A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort"); $i = 0; while ($row = A::$DB->fetchRow()) { if ($row['type'] == 'select' || $row['type'] == 'mselect') { if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field='{$row['field']}'")) { if (isset($vars[$row['idvar']])) { $row['vars'] =& $vars[$row['idvar']]; } else { $row['vars'] = array(); $_vars = loadList($row['idvar']); foreach ($_vars as $key => $name) { $row['vars'][$key] = is_array($name) ? $name['name'] : $name; } $vars[$row['idvar']] =& $row['vars']; } } } $row['id'] = $i++; if (preg_match("/^category[0-9]{1}\$/i", $row['field'])) { $categories[$row['field']] = $row; } elseif ($row['type'] == 'image' || $row['type'] == 'file') { $cfiles[$row['field']] = $row; } else { $fields[$row['field']] = $row; } } A::$DB->free(); if ($ext == 'xls') { $datasource = new Structures_DataGrid_DataSource_Excel(); $datasource->bind($sourcefile); } elseif ($ext == 'csv') { $datasource = new Structures_DataGrid_DataSource_CSV(); $datasource->bind($sourcefile, array('delimiter' => ';', 'enclosure' => '"')); } else { return false; } $datagrid = new Structures_DataGrid(); $datagrid->bindDataSource($datasource); A::$DB->caching = false; $prevgoods = A::$DB->getCount(SECTION . "_catalog", "active='Y'"); $curgoods = 0; $arts = array(); $catn = array(); $catr = array(); $cats = array(); $i = 0; $gsort = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_catalog") + 1; foreach ($datagrid->recordSet as $row) { $i++; if ($i == 1) { continue; } if (empty($row)) { continue; } if ($ext == 'xls') { $trow = array(); foreach ($row as $j => $value) { if (!empty($value)) { $trow[$j - 1] = $value; } } $row = $trow; } $idcat = 0; for ($j = 0; $j < 3; $j++) { if (isset($categories['category' . $j]) && !empty($row[$categories['category' . $j]['id']])) { if ($cname = strip_tags(trim($row[$categories['category' . $j]['id']]))) { $ch = md5($idcat . '|' . $cname); if (isset($catn[$ch])) { $idcat = $catn[$ch]; } elseif ($_idcat = A::$DB->getOne("SELECT id FROM " . SECTION . "_categories WHERE idker={$idcat} AND name=?", $cname)) { $idcat = $catn[$ch] = $_idcat; } else { if (!isset($catr[$idcat])) { $catr[$idcat] = A::$DB->getRowById($idcat, SECTION . "_categories"); } $category = array(); $category['name'] = $cname; $category['urlname'] = getURLName($cname); $category['idker'] = $idcat; $category['level'] = isset($catr[$idcat]['level']) ? $catr[$idcat]['level'] + 1 : 0; $category['sort'] = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_categories WHERE idker={$idcat}") + 1; $idcat = $catn[$ch] = A::$DB->Insert(SECTION . "_categories", $category); } } } } if ($idcat == 0 && empty($row[$fields['art']['id']])) { continue; } $data = array(); $data['date'] = time(); if ($idcat > 0) { $data['idcat'] = $idcat; if (!isset($cats[$idcat])) { $cats[$idcat] = 1; } else { $cats[$idcat]++; } } $data['idcat1'] = 0; $data['idcat2'] = 0; foreach ($fields as $field => $frow) { if (!isset($_REQUEST['iempty']) || !empty($row[$frow['id']])) { switch ($frow['type']) { default: $data[$field] = !empty($row[$frow['id']]) ? trim($row[$frow['id']]) : ""; break; case 'int': $data[$field] = !empty($row[$frow['id']]) ? (int) $row[$frow['id']] : 0; break; case 'float': $data[$field] = !empty($row[$frow['id']]) ? (double) str_replace(',', '.', $row[$frow['id']]) : 0; break; case 'select': if (!empty($row[$frow['id']])) { if (isset($frow['vars'])) { $row[$frow['id']] = trim($row[$frow['id']]); $key = array_search($row[$frow['id']], $frow['vars']); if (empty($key) && !empty($row[$frow['id']])) { $key = addToList($frow['idvar'], $row[$frow['id']]); $fields[$field]['vars'][$key] = $frow['vars'][$key] = $row[$frow['id']]; } if (!empty($key)) { $data[$field] = $key; } } } break; case 'mselect': if (!empty($row[$frow['id']])) { if (isset($frow['vars'])) { $row[$frow['id']] = explode(',', $row[$frow['id']]); $data[$field] = array(); foreach ($row[$frow['id']] as $value) { $value = trim($value); $key = array_search($value, $frow['vars']); if (empty($key) && !empty($value)) { $key = addToList($frow['idvar'], $value); $fields[$field]['vars'][$key] = $frow['vars'][$key] = $value; } if (!empty($key)) { $data[$field][] = sprintf("%04d", $key); } } $data[$field] = implode(",", $data[$field]); } } break; case 'bool': $data[$field] = !empty($row[$frow['id']]) && $row[$frow['id']] != 'N' ? "Y" : "N"; break; } } } if (isset($data['name'])) { $data['name'] = strip_tags(trim($data['name'])); } if (!empty(A::$OPTIONS['idrule'])) { $_data = $data; prepareValues(SECTION, $_data); $litems = array(); $idrule = A::$OPTIONS['idrule']; $idrule = explode("+", $idrule); foreach ($idrule as $fname) { if (!empty($_data[$fname])) { $litems[] = getURLName($_data[$fname]); } } $data['urlname'] = implode(!empty($GLOBALS['A_URL_SEPARATOR']) ? $GLOBALS['A_URL_SEPARATOR'] : "_", $litems); } elseif (!empty($data['art'])) { $data['urlname'] = getURLName($data['art']); } if (empty($data['urlname'])) { $data['urlname'] = getURLName($data['name']); } if (!empty($data['content']) && empty($data['description'])) { $data['description'] = truncate($data['content'], A::$OPTIONS['anonslen']); } if (!empty($data['art'])) { $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE art=? LIMIT 0,1", $data['art']); if (A::$OPTIONS['usecats']) { if (!empty($arts[$data['art']]) && !empty($data['idcat'])) { if ($arts[$data['art']] < 3) { $data['idcat' . $arts[$data['art']]] = $data['idcat']; unset($data['idcat']); } $arts[$data['art']]++; } else { $arts[$data['art']] = 1; } } } else { $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE idcat=? AND name=? LIMIT 0,1", array($data['idcat'], $data['name'])); } if ($grow) { $id = $grow['id']; $mprices = !empty($grow['mprices']) ? unserialize($grow['mprices']) : array(); } else { $id = 0; } if ($id) { if (isset($fields['mprice']) && !empty($data['mprice'])) { $inm = false; foreach ($mprices as $mp) { if ($mp['name'] == trim($data['mprice'])) { $inm = true; break; } } if (!$inm) { $mprices[] = array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : ''); } $data['mprices'] = serialize($mprices); unset($data['price']); $cats[$idcat]--; $curgoods--; } if (isset($data['mprice'])) { unset($data['mprice']); } A::$DB->Update(SECTION . "_catalog", $data, "id={$id}"); $images = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_images\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}"); $images = array_values($images); $files = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_files\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}"); $files = array_values($files); $curgoods++; } elseif (!empty($data['idcat'])) { if (isset($fields['mprice']) && !empty($data['mprice'])) { $mprices = array(array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : '')); $data['mprices'] = serialize($mprices); } if (isset($data['mprice'])) { unset($data['mprice']); } if (empty($data['name'])) { continue; } $data['sort'] = $gsort++; $id = A::$DB->Insert(SECTION . "_catalog", $data); $images = array(); $files = array(); $curgoods++; } else { continue; } foreach ($cfiles as $field => $frow) { if (!empty($row[$frow['id']])) { switch ($frow['type']) { case 'image': $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]); $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : ""; $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['imgpath'] . "/" . $row[$frow['id']]; $path2 = "files/" . DOMAIN . "/reg_images/" . $row[$frow['id']]; $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : "")); if ($path) { preg_match("/^idimg([0-9]+)\$/i", $field, $mathes); $sort = $mathes[1]; if (!isset($images[$sort]) || $images[$sort]['path'] != $path) { $image = array(); $image['path'] = $path; $image['name'] = basename($row[$frow['id']]); $image['mime'] = getMimeByFile($row[$frow['id']]); $image['caption'] = !empty($data['name']) ? $data['name'] : ""; $it = Image_Transform::factory('GD'); $it->load($path); $image['width'] = $it->img_x; $image['height'] = $it->img_y; $image['idsec'] = SECTION_ID; $image['iditem'] = $id; $image['sort'] = $sort; if (isset($images[$sort])) { A::$DB->Update(DOMAIN . "_images", $image, "id=" . $images[$sort]['id']); } else { A::$DB->Insert(DOMAIN . "_images", $image); } } } break; case 'file': $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]); $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : ""; $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['filepath'] . "/" . $row[$frow['id']]; $path2 = "files/" . DOMAIN . "/reg_files/" . $row[$frow['id']]; $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : "")); if ($path) { preg_match("/^idfile([0-9]+)\$/i", $field, $mathes); $sort = $mathes[1]; if (!isset($files[$sort]) || $files[$sort]['path'] != $path) { $file = array(); $file['path'] = $path; $file['name'] = basename($row[$frow['id']]); $file['mime'] = getMimeByFile($row[$frow['id']]); $file['caption'] = !empty($data['name']) ? $data['name'] : ""; $file['idsec'] = SECTION_ID; $file['iditem'] = $id; $file['sort'] = $sort; $file['size'] = filesize($path); $file['dwnl'] = 0; if (isset($files[$sort])) { A::$DB->Update(DOMAIN . "_files", $file, "id=" . $files[$sort]['id']); } else { A::$DB->Insert(DOMAIN . "_files", $file); } } } break; } } } } if ($prevgoods > 0 && $prevgoods != $curgoods) { $this->updateCItems(); } else { A::$DB->Update(SECTION . "_categories", array('citems' => 0)); foreach ($cats as $id => $count) { A::$DB->Update(SECTION . "_categories", array('citems' => $count), "id={$id}"); } $this->updateCItems(0, true); } A::$CACHE->resetSection(SECTION); delDir("files/" . DOMAIN . "/tmp"); return true; } } return false; }
/** * Индексация страницы в базу поиска по сайту. * * @param string $section Полный строковой идентификатор раздела. */ function feedback_searchIndexAll($section) { $idsec = getSectionId($section); $name = A::$DB->getOne("SELECT caption_" . A::$LANG . " FROM " . DOMAIN . "_sections WHERE id=" . $idsec); A_SearchEngine::getInstance()->updateIndex($idsec, 0, $name, getTextOption($section, 'content')); }
/** * Получение полных данных записи каталога. * * @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; } }
/** * Формирование данных доступных в шаблоне детальной страницы материала. */ function ItemPage() { $this->supportCached(); if ($this->idcat > 0) { $this->category['link'] = catalog_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); } $itemdata = $this->itemdata; $itemdata['vote'] = $itemdata['cvote'] > 0 ? round($itemdata['svote'] / $itemdata['cvote'], 2) : 0; if (A::$OPTIONS['useimages']) { $itemdata['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $itemdata['id'])); $itemdata['idimg'] = isset($itemdata['images'][0]['id']) ? $itemdata['images'][0]['id'] : 0; } if (A::$OPTIONS['usefiles']) { $itemdata['files'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_files WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $this->iditem)); foreach ($itemdata['files'] as $i => $data) { $itemdata['files'][$i]['link'] = (LANG == DEFAULTLANG ? "" : "/" . LANG) . "/getfile/" . $data['id'] . "/" . $data['name']; $itemdata['files'][$i]['size'] = sizestring($data['size']); } $itemdata['idfile'] = isset($itemdata['files'][0]['id']) ? $itemdata['files'][0]['id'] : 0; } if (A::$OPTIONS['usetags']) { $itemdata['tags'] = A_SearchEngine::getInstance()->convertTags($itemdata['tags']); } prepareValues(SECTION, $itemdata); $itemdata = A::$OBSERVER->Modifier('catalog_prepareValues', SECTION, $itemdata); $this->Assign("item", $itemdata); if (A::$OPTIONS['usecomments']) { $comments = array(); A::$DB->query("SELECT * FROM " . DOMAIN . "_comments WHERE idsec=" . SECTION_ID . " AND iditem={$this->iditem} AND active='Y' ORDER BY date"); while ($row = A::$DB->fetchRow()) { if ($row['iduser'] > 0 && A::$AUTH->section) { if ($row['user'] = A::$DB->getRowById($row['iduser'], A::$AUTH->section)) { prepareValues(A::$AUTH->section, $row['user']); } } $comments[] = $row; } A::$DB->free(); $this->Assign("comments", $comments); $form = array(); $form['name'] = !empty($_REQUEST['name']) ? $_REQUEST['name'] : (A::$AUTH->isLogin() ? A::$AUTH->data['name'] : ""); $form['message'] = !empty($_REQUEST['message']) ? $_REQUEST['message'] : ""; $this->Assign("form", $form); $this->Assign("captcha", $captcha = substr(time(), rand(0, 6), 4)); A_Session::set("captcha", md5($captcha)); } if (A::$OPTIONS['usevote']) { $this->Assign("isvote", A_Session::get(SECTION . "_vote_" . $this->iditem, false)); $this->addCacheParam_Session(SECTION . "_vote_" . $this->iditem); } $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); if (isset($this->category)) { $this->AddNavCategories($this->category['id']); } $this->title = $this->itemdata['name'] . (!empty($this->title) ? " - " . $this->title : ""); if (!empty($this->itemdata['keywords'])) { $this->keywords = $this->itemdata['keywords']; } $this->description = $this->itemdata['description']; }
/** * Формирование данных доступных в шаблоне активного типа. */ function createData() { $this->supportCached(); prepareValues(SECTION, $this->pagedata); $this->pagedata['latname'] = $this->pagedata['urlname']; if (A::$OPTIONS['usetags']) { $this->pagedata['tags'] = A_SearchEngine::getInstance()->convertTags($this->pagedata['tags']); } $this->Assign_by_ref("page", $this->pagedata); $this->Assign_by_ref("content", $this->pagedata['content']); $this->Assign_by_ref("fullpath", $this->fullpath); if ($this->pagedata['level']) { if (SNAME != A::$OPTIONS['mainsection']) { $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); } if ($this->pagedata['idker']) { $this->AddNavPages($this->pagedata['idker'], $this->pagedata['urlname'] != "index"); } } elseif (SNAME != A::$OPTIONS['mainsection']) { if ($this->pagedata['urlname'] != 'index') { $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); } else { $this->AddNavigation(SECTION_NAME); } } if (!empty($this->pagedata['title'])) { $this->title = $this->pagedata['title']; } if (!(A::$OPTIONS['mainsection'] && count(A::$URIPARAMS) == 0)) { $this->title = $this->pagedata['name'] . (!empty($this->title) ? ' - ' . $this->title : ''); } $this->keywords = $this->pagedata['keywords']; $this->description = $this->pagedata['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() { $this->Assign("query", !empty($_GET['query']) ? htmlspecialchars($_GET['query']) : ""); $this->Assign("sections", A_SearchEngine::getInstance()->getSections()); }
/** * Формирование данных доступных в шаблоне. */ 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)); }
/** * Формирование данных доступных в шаблоне страницы альбома. */ function AlbumPage() { $this->supportCached(); $this->addCacheParam_Get('page'); if ($this->idcat > 0) { $this->category['link'] = gallery_createCategoryLink($this->category['id'], SECTION); if (A::$OPTIONS['usetags']) { $this->category['tags'] = A_SearchEngine::getInstance()->convertTags($this->category['tags']); } $this->Assign("category", $this->category); } $album = $this->album; $album['vote'] = $album['cvote'] > 0 ? round($album['svote'] / $album['cvote'], 2) : 0; $album['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $album['id'])); if (A::$OPTIONS['usetags']) { $album['tags'] = A_SearchEngine::getInstance()->convertTags($album['tags']); } prepareValues(SECTION, $album); $album = A::$OBSERVER->Modifier('gallery_prepareValues', SECTION, $album); $this->Assign("album", $album); $irows = (int) (!empty($_GET['irows'])) ? (int) $_GET['irows'] : A::$OPTIONS['irows']; $this->Assign("irows", $irows); $pager = new A_Pager($irows); $images = $pager->setItems($album['images']); $this->Assign("images", $images); $this->Assign("images_pager", $pager); $sort = escape_order_string(!empty(A::$OPTIONS['mysort']) ? A::$OPTIONS['mysort'] : A::$OPTIONS['sort']); $albums = A::$DB->getCol("\r\r\n\tSELECT id FROM " . SECTION . "_albums\r\r\n\tWHERE active='Y' AND idcat={$album['idcat']} ORDER BY {$sort}"); $i = array_search($album['id'], $albums); if ($i !== false) { $previd = isset($albums[$i - 1]) ? $albums[$i - 1] : 0; $nextid = isset($albums[$i + 1]) ? $albums[$i + 1] : 0; if ($previd) { $this->Assign("prevalbum", gallery_createItemLink($previd, SECTION)); } if ($nextid) { $this->Assign("nextalbum", gallery_createItemLink($nextid, SECTION)); } } if (A::$OPTIONS['usecomments']) { $comments = array(); A::$DB->query("SELECT * FROM " . DOMAIN . "_comments WHERE idsec=" . SECTION_ID . " AND iditem={$this->idalb} AND active='Y' ORDER BY date"); while ($row = A::$DB->fetchRow()) { if ($row['iduser'] > 0 && A::$AUTH->section) { if ($row['user'] = A::$DB->getRowById($row['iduser'], A::$AUTH->section)) { prepareValues(A::$AUTH->section, $row['user']); } } $comments[] = $row; } A::$DB->free(); $this->Assign("comments", $comments); $form = array(); $form['name'] = !empty($_REQUEST['name']) ? $_REQUEST['name'] : (A::$AUTH->isLogin() ? A::$AUTH->data['name'] : ""); $form['message'] = !empty($_REQUEST['message']) ? $_REQUEST['message'] : ""; $this->Assign("form", $form); $this->Assign("captcha", $captcha = substr(time(), rand(0, 6), 4)); A_Session::set("captcha", md5($captcha)); } if (A::$OPTIONS['usevote']) { $this->Assign("isvote", A_Session::get(SECTION . "_vote_" . $this->idalb, false)); $this->addCacheParam_Session(SECTION . "_vote_" . $this->idalb); } $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION)); if (isset($this->category)) { $this->AddNavCategories($this->category['id']); } $this->title = $this->album['name'] . (!empty($this->title) ? " - " . $this->title : ""); $this->description = $this->album['description']; }
/** * Формирование данных доступных в шаблоне страницы результатов поиска. */ 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() { $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 createData() { $items = array(); $pager = new A_Pager(A::$OPTIONS['rows']); if (!empty($_GET['idsec'])) { if (is_array($_GET['idsec'])) { foreach ($_GET['idsec'] as $i => $id) { $idsec[$i] = (int) $id; } } else { $idsec = array((int) $_GET['idsec']); } } $imodules = array('feedback'); if (!empty($_GET['query'])) { $_GET['query'] = mb_substr($_GET['query'], 0, 50); $stems = $_stems = array(); $words = $_words = array(); $query = explode(" ", $_GET['query']); foreach ($query as $word) { if (mb_strlen($word) > 2) { $word = mb_strtolower($word); $words[] = $word; $_words[] = empty($_words) ? "+>{$word}" : ">{$word}"; if ($stem = A_SearchEngine::getInstance()->getStem($word)) { if (mb_strlen($stem) > 3) { $stems[] = $stem; $_stems[] = empty($_stems) ? "+<{$stem}" : "<{$stem}"; } } } } $_words = A::$DB->real_escape_string(implode(" ", $_words)); $_stems = A::$DB->real_escape_string(implode(" ", $_stems)); if (!empty($_words)) { $pager->query("\r\r\n\t SELECT `date`,`idsec`,`iditem`,`name`,`content`,`idtags`,\r\r\n\t MATCH(`name`) AGAINST('{$_words}')+MATCH(`content`) AGAINST('{$_words}')+MATCH(`stems`) AGAINST('{$_stems}') AS relevant\r\r\n\t FROM " . SECTION . "\r\r\n\t WHERE " . (!empty($idsec) ? "idsec IN(" . implode(",", $idsec) . ") AND " : "") . "\r\r\n\t ( MATCH(`name`) AGAINST ('{$_words}' IN BOOLEAN MODE)\r\r\n\t OR\r\r\n\t\t MATCH(`content`) AGAINST ('{$_words}' IN BOOLEAN MODE)\r\r\n\t\t OR\r\r\n\t\t MATCH(`stems`) AGAINST ('{$_stems}' IN BOOLEAN MODE)\r\r\n\t )\r\r\n\t ORDER BY `relevant` DESC, `date` DESC"); while ($row = $pager->fetchRow()) { $row['num'] = $pager->begin + count($items); $row['description'] = A_SearchEngine::getInstance()->getFindedText($words, $stems, $row['content']); if ($srow = A::$DB->getRowById($row['idsec'], DOMAIN . "_sections")) { $section = DOMAIN . '_' . $srow['lang'] . '_' . $srow['name']; if (!empty($row['name']) && !in_array($srow['module'], $imodules)) { if (!empty($srow['caption_' . LANG])) { $row['name'] = $srow['caption_' . LANG] . " - " . $row['name']; } } else { $row['name'] = $srow['caption_' . LANG]; } if ($row['iditem'] > 0) { $row['link'] = function_exists($srow['module'] . '_createItemLink') ? call_user_func($srow['module'] . '_createItemLink', $row['iditem'], $section) : getSectionLink($section); } else { $row['link'] = function_exists($srow['module'] . '_createCategoryLink') ? call_user_func($srow['module'] . '_createCategoryLink', -$row['iditem'], $section) : getSectionLink($section); } $row['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array($row['idsec'], $row['iditem'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; $row['tags'] = A_SearchEngine::getInstance()->getTags($row['idtags']); $items[] = $row; } } $pager->free(); } } elseif (!empty($_GET['tag'])) { if ($_GET['tag'] = mb_substr(mb_strtolower(trim($_GET['tag'])), 0, 50)) { if ($idtag = A::$DB->getOne("SELECT id FROM " . SECTION . "_tags WHERE tag=?", $_GET['tag'])) { $idtag = sprintf("%04d", $idtag); $pager->query("\r\r\n\t SELECT `date`,`idsec`,`iditem`,`name`,`content`,`idtags`\r\r\n\t FROM " . SECTION . "\r\r\n\t WHERE " . (!empty($idsec) ? "idsec IN(" . implode(",", $idsec) . ") AND " : "") . "\r\r\n\t MATCH(`idtags`) AGAINST ('{$idtag}' IN BOOLEAN MODE)\r\r\n\t ORDER BY `date` DESC"); while ($row = $pager->fetchRow()) { $row['num'] = $pager->begin + count($items); $row['description'] = truncate($row['content'], 350); if ($srow = A::$DB->getRowById($row['idsec'], DOMAIN . "_sections")) { $section = DOMAIN . '_' . $srow['lang'] . '_' . $srow['name']; if (!empty($row['name']) && !in_array($srow['module'], $imodules)) { if (!empty($srow['caption_' . LANG])) { $row['name'] = $srow['caption_' . LANG] . " - " . $row['name']; } } else { $row['name'] = $srow['caption_' . LANG]; } if ($row['iditem'] > 0) { $row['link'] = function_exists($srow['module'] . '_createItemLink') ? call_user_func($srow['module'] . '_createItemLink', $row['iditem'], $section) : getSectionLink($section); } else { $row['link'] = function_exists($srow['module'] . '_createCategoryLink') ? call_user_func($srow['module'] . '_createCategoryLink', -$row['iditem'], $section) : getSectionLink($section); } $row['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array($row['idsec'], $row['iditem'])); $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0; $row['tags'] = A_SearchEngine::getInstance()->getTags($row['idtags']); $items[] = $row; } } $pager->free(); } } } $this->Assign("items", $items); $this->Assign("items_pager", $pager); $this->Assign("sections", A_SearchEngine::getInstance()->getSections()); $this->AddNavigation(SECTION_NAME); }
/** * Формирование данных доступных в шаблоне. */ 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']); }