<commit_before><?php
//setlocale(LC_ALL, 'ru_RU');
// ---- center ----
unset($parsed_res);
$Page = new Page();
$Page->PagesList();
$tpl->Assign('list_menu', $Page->list);
$header = 'Результаты поиска';
$GLOBALS['IERA_LINKS'][] = array(
	'title' => $header,
	'url' => Link::Custom('search')
);
// Настройка панели действий ===============================
$list_controls = array('layout', 'sorting');
$tpl->Assign('list_controls', $list_controls);
// =========================================================

if(isset($_SERVER['HTTP_REFERER'])){
	$referer = explode('/',str_replace('http://', '', $_SERVER['HTTP_REFERER']));
	if($referer[1] != 'search'){
		unset($_SESSION['search']);
		unset($_SESSION['filters']);
	}
}else{
	unset($_SESSION['search']);
	unset($_SESSION['filters']);
}
// Получаем строку поискового запроса ======================
if(isset($_POST['query']) && !isset($_GET['query']) && $_POST['query'] != ''){
	$query = preg_replace('/[()*|,.*"^&@#$%\/]/', ' ', $_POST['query']);
	$query = trim($query);
}elseif(isset($_GET['query']) && !isset($_POST['query']) && $_GET['query'] != ''){
	$query = preg_replace('/[()*|,.*"^&@#$%]/', ' ', $_GET['query']);
	$query = trim($query);
}
G::metaTags(array('page_title' => $header.' по запросу "'.isset($query).'"'));
$tpl->Assign('header', $header.(isset($query)?' по запросу "<b>'.$query.'</b>"':null));
if(isset($_SESSION['search']['query']) && isset($query) && $query != '' && $query != $_SESSION['search']['query']){
	$_SESSION['search']['newsearch'] = 1;
	$_POST['dropfilters'] = 1;
}else{
	$_SESSION['search']['newsearch'] = 0;
}
if((isset($_SESSION['search']['query']) && $_SESSION['search']['query'] != '') && (!isset($query) || $query == '')){
	$query = $_SESSION['search']['query'];
}elseif((isset($query) && $query != '') || !isset($_SESSION['search']['query']) || $_SESSION['search']['query'] == ''){
	if(isset($query)){
		$_SESSION['search']['query'] = $query;
	}else{
		$_SESSION['search']['query'] = $query = '';
	}
}
if(isset($_POST['dropfilters'])){
	unset($_SESSION['filters']);
}
if(!_acl::isAdmin()){
	$where_arr['p.visible'] = 1;
}
// Категория для поиска ====================================
if(isset($_REQUEST['search_category']) && $_REQUEST['search_category'] != 0){
	$_SESSION['search']['search_category'] = (int) $_REQUEST['search_category'];
	$where_arr['customs']['search_category'] = 'cp.id_category IN (
		SELECT id_category
		FROM '._DB_PREFIX_.'category c
		WHERE c.id_category = '.$_SESSION['search']['search_category'].'
		OR c.pid = '.$_SESSION['search']['search_category'].'
		OR c.pid IN (
			SELECT id_category
			FROM '._DB_PREFIX_.'category c
			WHERE c.pid = '.$_SESSION['search']['search_category'].'
		)
	)';
}else{
	$_SESSION['search']['search_category'] = 0;
}

if(isset($_SESSION['member']) && $_SESSION['member']['gid'] == _ACL_TERMINAL_ && isset($_COOKIE['available_today']) && $_COOKIE['available_today'] == 1){
	$where_arr['s.available_today'] = 1;
}

// Диапазон цен ============================================
if(isset($_SESSION['member']['gid']) && $_SESSION['member']['gid'] != _ACL_ADMIN_){
	if(isset($_POST['pricefrom']) && isset($_POST['priceto'])){
		$where_arr['customs']['price_filter'] = 'price_mopt BETWEEN '.number_format(($_POST['pricefrom']), 2, ".","").' AND '.number_format(($_POST['priceto']), 2, ".","");
		$_SESSION['filters']['pricefrom'] = $_POST['pricefrom'];
		$_SESSION['filters']['priceto'] = $_POST['priceto'];
	}elseif((!isset($_POST['pricefrom']) && !isset($_POST['priceto'])) && (isset($_SESSION['filters']['pricefrom']) && isset($_SESSION['filters']['priceto']))){
		$where_arr['customs']['price_filter'] = 'price_mopt BETWEEN '.number_format(($_SESSION['filters']['pricefrom']), 2, ".","").' AND '.number_format(($_SESSION['filters']['priceto']), 2, ".","");
	}
}

// Сортировка ==============================================
if(!isset($sorting)){
	$sorting = array('value' => 'popularity DESC');
	setcookie('sorting', json_encode(array('products' => $sorting)), time()+3600*24*30, '/');
}else{
	$_SESSION['filters']['orderby'] = $orderby = $sorting['value'];
}
if(isset($_SESSION['member']['gid']) && ($_SESSION['member']['gid'] == _ACL_SUPPLIER_ || $_SESSION['member']['gid'] == _ACL_ADMIN_)){
	$available_sorting_values = array(
		'popularity desc' => 'популярные',
		'create_date desc' => 'новые сверху',
		'price_opt asc' => 'от дешевых к дорогим',
		'price_opt desc' => 'от дорогих к дешевым',
		'name asc' => 'по названию от А до Я',
		'name desc' => 'по названию от Я до А',
	);
}else{
	$available_sorting_values = array(
		'popularity desc' => 'популярные',
		'create_date desc' => 'новые сверху',
		'price_opt asc' => 'от дешевых к дорогим',
		'price_opt desc' => 'от дорогих к дешевым',
		'name asc' => 'по названию от А до Я',
		'name desc' => 'по названию от Я до А',
	);
}
$tpl->Assign('sorting', $sorting);
$tpl->Assign('available_sorting_values', $available_sorting_values);
if((!isset($orderby) || $orderby == '') && isset($_SESSION['filters']['orderby'])){
	$orderby = $_SESSION['filters']['orderby'];
}
// =========================================================
<commit_msg>default sort + title (search page)<commit_after><?php
//setlocale(LC_ALL, 'ru_RU');
// ---- center ----
unset($parsed_res);
$Page = new Page();
$Page->PagesList();
$tpl->Assign('list_menu', $Page->list);
$header = 'Результаты поиска';
$GLOBALS['IERA_LINKS'][] = array(
	'title' => $header,
	'url' => Link::Custom('search')
);
// Настройка панели действий ===============================
$list_controls = array('layout', 'sorting');
$tpl->Assign('list_controls', $list_controls);
// =========================================================

if(isset($_SERVER['HTTP_REFERER'])){
	$referer = explode('/',str_replace('http://', '', $_SERVER['HTTP_REFERER']));
	if($referer[1] != 'search'){
		unset($_SESSION['search']);
		unset($_SESSION['filters']);
	}
}else{
	unset($_SESSION['search']);
	unset($_SESSION['filters']);
}
// Получаем строку поискового запроса ======================
if(isset($_POST['query']) && !isset($_GET['query']) && $_POST['query'] != ''){
	$query = preg_replace('/[()*|,.*"^&@#$%\/]/', ' ', $_POST['query']);
	$query = trim($query);
}elseif(isset($_GET['query']) && !isset($_POST['query']) && $_GET['query'] != ''){
	$query = preg_replace('/[()*|,.*"^&@#$%]/', ' ', $_GET['query']);
	$query = trim($query);
}
G::metaTags(array('page_title' => $header.' по запросу "'.isset($query).'"'));
$tpl->Assign('header', (isset($query)?'"<b>'.$query.'</b>"':null));
if(isset($_SESSION['search']['query']) && isset($query) && $query != '' && $query != $_SESSION['search']['query']){
	$_SESSION['search']['newsearch'] = 1;
	$_POST['dropfilters'] = 1;
}else{
	$_SESSION['search']['newsearch'] = 0;
}
if((isset($_SESSION['search']['query']) && $_SESSION['search']['query'] != '') && (!isset($query) || $query == '')){
	$query = $_SESSION['search']['query'];
}elseif((isset($query) && $query != '') || !isset($_SESSION['search']['query']) || $_SESSION['search']['query'] == ''){
	if(isset($query)){
		$_SESSION['search']['query'] = $query;
	}else{
		$_SESSION['search']['query'] = $query = '';
	}
}
if(isset($_POST['dropfilters'])){
	unset($_SESSION['filters']);
}
if(!_acl::isAdmin()){
	$where_arr['p.visible'] = 1;
}
// Категория для поиска ====================================
if(isset($_REQUEST['search_category']) && $_REQUEST['search_category'] != 0){
	$_SESSION['search']['search_category'] = (int) $_REQUEST['search_category'];
	$where_arr['customs']['search_category'] = 'cp.id_category IN (
		SELECT id_category
		FROM '._DB_PREFIX_.'category c
		WHERE c.id_category = '.$_SESSION['search']['search_category'].'
		OR c.pid = '.$_SESSION['search']['search_category'].'
		OR c.pid IN (
			SELECT id_category
			FROM '._DB_PREFIX_.'category c
			WHERE c.pid = '.$_SESSION['search']['search_category'].'
		)
	)';
}else{
	$_SESSION['search']['search_category'] = 0;
}

if(isset($_SESSION['member']) && $_SESSION['member']['gid'] == _ACL_TERMINAL_ && isset($_COOKIE['available_today']) && $_COOKIE['available_today'] == 1){
	$where_arr['s.available_today'] = 1;
}

// Диапазон цен ============================================
if(isset($_SESSION['member']['gid']) && $_SESSION['member']['gid'] != _ACL_ADMIN_){
	if(isset($_POST['pricefrom']) && isset($_POST['priceto'])){
		$where_arr['customs']['price_filter'] = 'price_mopt BETWEEN '.number_format(($_POST['pricefrom']), 2, ".","").' AND '.number_format(($_POST['priceto']), 2, ".","");
		$_SESSION['filters']['pricefrom'] = $_POST['pricefrom'];
		$_SESSION['filters']['priceto'] = $_POST['priceto'];
	}elseif((!isset($_POST['pricefrom']) && !isset($_POST['priceto'])) && (isset($_SESSION['filters']['pricefrom']) && isset($_SESSION['filters']['priceto']))){
		$where_arr['customs']['price_filter'] = 'price_mopt BETWEEN '.number_format(($_SESSION['filters']['pricefrom']), 2, ".","").' AND '.number_format(($_SESSION['filters']['priceto']), 2, ".","");
	}
}

// Сортировка ==============================================
if(!isset($sorting)){
	$sorting = array('value' => 'name ASC');
	setcookie('sorting', json_encode(array('products' => $sorting)), time()+3600*24*30, '/');
}else{
	$_SESSION['filters']['orderby'] = $orderby = $sorting['value'];
}
if(isset($_SESSION['member']['gid']) && ($_SESSION['member']['gid'] == _ACL_SUPPLIER_ || $_SESSION['member']['gid'] == _ACL_ADMIN_)){
	$available_sorting_values = array(
		'popularity desc' => 'популярные',
		'create_date desc' => 'новые сверху',
		'price_opt asc' => 'от дешевых к дорогим',
		'price_opt desc' => 'от дорогих к дешевым',
		'name asc' => 'по названию от А до Я',
		'name desc' => 'по названию от Я до А',
	);
}else{
	$available_sorting_values = array(
		'popularity desc' => 'популярные',
		'create_date desc' => 'новые сверху',
		'price_opt asc' => 'от дешевых к дорогим',
		'price_opt desc' => 'от дорогих к дешевым',
		'name asc' => 'по названию от А до Я',
		'name desc' => 'по названию от Я до А',
	);
}
$tpl->Assign('sorting', $sorting);
$tpl->Assign('available_sorting_values', $available_sorting_values);
if((!isset($orderby) || $orderby == '') && isset($_SESSION['filters']['orderby'])){
	$orderby = $_SESSION['filters']['orderby'];
}
// =========================================================

{'fraction_non_alphanumeric': 0.31603038566419944, 'fraction_numerical': 0.004090377873003506, 'mean_word_length': 7.376019575856444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1966386', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3603, 'n_words': 563}