\n"; } require("config.php"); include("lib/pack.php"); $PACK_FILE=packInit($PACK_STRUCT); packHTML(0); header("Content-type: text/html; charset=".$SITE_CHARSET); include("lib/base.php"); $URL=url(); if(preg_match("~^(((.+\.)?cdn)|(.+\..+)).".preg_quote($BASE_HOST)."$~i", $_SERVER['HTTP_HOST'])) redirect(url("base_root").url("path")); //fix https://pl.pl.pl.cdn.sz.lviv.ua/ //if($URL["base"]=="http://xn----7sbtihk8aoa4k.xn--j1amh/") $URL["base"]="http://смак-життя.укр/"; if(url("root")=="robots.txt" && !url("lang_path")) mod('main')->robots(); include("lib/db.php"); if((isset($_POST["auth_login"]) && !isset($_GET["ajax"]))||isset($_GET["auth_logout"])){ mod('access')->login(@$_POST["auth_login"], @$_POST["auth_password"]); header("Location: ".$_SERVER['HTTP_REFERER']); exit; } //mt("m"); //mod('menu')->res("panel/access/modify/", "iw"); //mt("a"); include("lib/tml6.php"); TML::$GLOBAL=array( "is_admin"=>!!auth(), "access"=>auth(), "year"=>date("Y"), "currency"=>def(mod('access')->owner("settings", "currency"), "₴"), // "грн"), "is_root_owner"=>!auth('owner'), ); TML::$GLOBAL["vars"]=mod('menu')->res("system/settings/site/", "wv"); TML::$GLOBAL["sett"]=array_map(function($item){ return !$item["hide"];}, mod('menu')->res("system/settings/crm/", array("type"=>"w*", "hidden"=>true))); if(url("error")) error_page(url("error")); //if error - return error page and exit $PRICE_ROUND=def(mod('access')->owner("settings", "price_round"), 0); $DEFAULT_COUNTRY=def(mod('access')->owner("settings", "default_country"), "ua"); $cdn_domain=mod('menu')->item("system/settings/site/cdn/", "value"); if($cdn_domain) $CDN_URL='https://'.$cdn_domain.'/'.$UPLOAD_DIR; //replace default cdn url if(($_lang=mod('access')->owner("settings", "lang"))){ $URL=set_lang($_lang, true); mod('menu')->cache_free(); } if(url("root")=="sitemap.xml" && !url("lang_suf")) mod('main')->sitemap(); $PROFILE=mod('customer')->auth(); $LANG_CONST=mod('menu')->hash("system/const/"); $LANG_CONST["const"]=mod('menu')->res("system/const/", "wn"); $GLOBALS["~"]=$LANG_CONST; //base redirect for short links if(@$URL["root"]=="pay" && is_numeric(@$URL["items"][1])) $_GET=array("ajax"=>"payment", "action"=>"pay_redirect", "type"=>"wayforpay", "order_id"=>$URL["items"][1]); //START if(@$_GET["ajax"]) ajax($_GET["ajax"]); if(isset($_GET["panel"])) include("panel.php"); ////panel if(@TML::$GLOBAL["sett"]["only_crm"]) redirect("?panel"); $is_page_auth=in_array($URL["root"], array("reg", "login")); $show_home=!$URL["root"] || in_array($URL["root"], array("order", "order_ok", "korzina", "korzina_ok", "subscribe_ok", "order".@$SITE_SUF, "order_ok".@$SITE_SUF, "subscribe_ok".@$SITE_SUF, "ref")) || $is_page_auth; if(!$show_home && !preg_match("~/$~", url("path"))) redirect(url("path")."/".($_SERVER["QUERY_STRING"]?"?".$_SERVER["QUERY_STRING"]:"")); //add last / if(preg_match("~((/{2,})|(\?))$~", $_SERVER["REQUEST_URI"])) redirect(preg_replace("~/+$~", "/", url("path"))); //rerirect from //// and /? //if(url('lang') && !@$LANGS[url('lang')]) redirect(url("route")); //rerirect from unknown lang if(!$IS_LOCAL) is_modified(time()-2); //-------------------- RENDER TML --------------------- mt("0"); $tml=array(); $tml["is_page_".($is_page_auth?@$URL["root"]:"")]=true; if(@$URL["root"]) $is_page=mod('menu')->item("page/".$URL["route"]); if(!@$is_page) $is_page=mod('menu')->item("page/more/".$URL["route"]); $tml["EXT_ID"]=!$IS_LOCAL && !@$TEST_MODE ? mod('menu')->hash("system/settings/ext_ids/"):null; if($tml["EXT_ID"] && (auth() || @$SUB_DOMAIN)) unset($tml["EXT_ID"]["jivo"], $tml["EXT_ID"]["helpCrunch"], $tml["EXT_ID"]["binotel"]); $tml["EXT_ID_"]=@$tml["EXT_ID"]?json_encode($tml["EXT_ID"]):"{}"; if(@$_GET["no_ext"]) $tml["EXT_ID_"]="{}"; $tml["SMTP"]=mod('menu')->res("system/settings/smtp/", "wn"); $tml["canonical"]=url("base").url("path"); $tml["alternate"]=array_keys($LANGS); $tml["profile_auth"]=$PROFILE; if($PROFILE){ $tml["profile_auth"]["_submenu"]["item"]=mod('menu')->res("system/profile/", array("active"=>@$URL["items"][1])); if(@$PROFILE["chb_optovik"]) $tml["profile_auth"]["_submenu"]["item"][]=mod('menu')->item("system/profile/opt/")+array("active"=>@$URL["items"][1]=="opt"); } $tml["menu"]=mod('menu')->item("system/const/ui/catalog/"); $tml["menu"]["item"]=mod('menu')->res("catalog/", array("sub"=>"item", "current"=>@$URL["path"], "active"=>@$URL["root"], "sub_active"=>@$URL["current"]));//, "counts"=>mod('catalog')->getCountList())); $tml["nav"]["item"]=mod('menu')->res("page/", array("sub"=>"item", "active"=>@$URL["current"]."/")); $tml["header_icons"]=mod('menu')->res("system/settings/site/header_icons/", "w*"); if($favorite_str=@$_COOKIE[$GLOBALS["SITE_PREF"]."favorite"]){ $fav_ids=preg_split("~,~si", $favorite_str); $tml["favorite_count"]=count($fav_ids); } //if($SITE=="sue") $tml["filters"]["item"]=mod('menu')->res("panel/product/status/"); //$tml["item_article"]=mod('menu')->item("page/article/", "*"); //$tml["block_public"]=true; $tml["phones"]["item"]=mod('menu')->res("system/const/phones/"); if($tml["phones"]["item"]) array_walk($tml["phones"]["item"], function(&$item){$item["name_"]=preg_replace("~\D~", "", $item["name"]);}); $tml["buts_soc"]["item"]=$tml["buts_soc2"]["item"]=$tml["buts_soc3"]["item"]=mod('menu')->res("system/const/soc/"); $tml["soc_links"]=mod('menu')->res("system/const/soc/", "wn"); $tml["show_lang"]=true;//@$SITE=="sue"||auth(); //$tml["telegram_bot_name"]=mod('menu')->item("system/settings/telegram/bot_name/", "name"); $CUSTOMER=@$PROFILE; if(!$CUSTOMER && @$_COOKIE[$SITE_PREF."customer_id"]) $CUSTOMER=mod('customer')->info(@$_COOKIE[$SITE_PREF."customer_id"]); //detect customer by cookie $CUSTOMER_HAS_ORDER=@$_COOKIE[$SITE_PREF."customer_id"] || @$PROFILE["order_count"]; if(preg_match("~&((utm_[^=]+)|(gclid)|(fbclid)|(price-base-to-[^=]+))=~", "&".$_SERVER["QUERY_STRING"])) $tml["nofollow"]=true; //for ads urls if($SITE=="sz" && !@$DEFAULT_OWNER){ if(@$URL["root"]=="ref") @$_GET["ref"]=@$URL["items"][1]; if(@$URL["root"]=="" && @$URL["items"][1]=="ref") @$_GET["ref"]=@$URL["items"][2]; $tml["referal_but"]=false;//true;//auth(); $tml["referal_top_banner"]=$tml["referal_but"] && !$URL["root"] && !@$_COOKIE[$SITE_PREF."referal_top_close"] && $CUSTOMER_HAS_ORDER; if(@$_GET["ref"]){// && !@$_COOKIE[$SITE_PREF."referal_done"]){ $tml["nofollow"]=true; if(!$PROFILE) $tml["show_referal_banner"]=mod('referal')->set($_GET["ref"]); else redirect(url('lang_path')."profile/referal/"); } else{ //set start referal if(!$PROFILE && !@$_COOKIE[$SITE_PREF."referal_start"] && !@$_COOKIE[$SITE_PREF."referal"] && !@$_COOKIE[$SITE_PREF."referal_done"]){ //$tml["show_start_banner"]=mod('referal')->set("0599241628502506", "start"); } //diler banner if($tml["referal_but"] && !@$_COOKIE[$SITE_PREF."referal_diler"] && $CUSTOMER_HAS_ORDER){ setcookie($SITE_PREF."referal_diler", time(), mktime(23,59,59)+60*60*24*120, url("rel")); $tml["show_diler_banner"]=true; } } //enable friend bonus if has referal_parent and no order if((!@$_COOKIE[$SITE_PREF."referal"] && !@$_COOKIE[$SITE_PREF."referal_done"]) || (@$PROFILE["referal_parent"] && !mod('order')->getOrderByCustomer(@$PROFILE["id"]))){ mod('referal')->setByParent(@$PROFILE["referal_parent"]); } if(@$_COOKIE[$SITE_PREF."referal"]){ $tml["user_discount"]=mod('menu')->item("panel/order/referal/amount/", "name"); $tml["is_mode_referal".(@$_COOKIE[$SITE_PREF."referal_start"]?"_start":"")]=true; //$tml["user_discount_expire"]=@$_COOKIE[$SITE_PREF."referal_expire"]?date("d.m.Y", @$_COOKIE[$SITE_PREF."referal_expire"]):""; } } if($SITE=="sue"){ //diler banner if(!@$_COOKIE[$SITE_PREF."banner_sue_2"]){ //setcookie($SITE_PREF."banner_sue_2", time(), mktime(23,59,59)+60*60*5, url("rel")); //$tml["show_sue_banner"]=true; } $tml["popup_consultants"]=url("lang")=="uk"; } $tml["is_site_".$SITE]=true; if($SITE=="zsu"||$SITE=="fashion") $tml["is_site_sz"]=true; $tml["is_site_".($SITE=="sz"||$SITE=="zsu"||$SITE=="fashion"?"sue":"sz")]=false; //for multi template mt(); if($show_home && !@$_GET["query"]){ $tml["is_home"]=true; $tml["block_menu"]["item"]=$tml["menu"]["item"]; $tml["block_menu"]["item"]=$tml["menu"]["item"]; //$tml["top_mess"]=$SITE=="sz"; $tml["top_cat"]=true; //$tml["but_review"]=mod('menu')->item("page/reviews/", "*"); //$tml["but_consultant"]=mod('menu')->item("page/consulting/"); $tml["home_text"]=mod('menu')->item("catalog/", "*"); $tml["banner"]=mod('menu')->item("system/banner/", array("key"=>"*", "sub"=>"item", "sub_opts"=>array("extend"=>array("limit"=>10), "skip"=>"empty_name"))); //if(@$tml["show_referal_banner"] && auth()) array_push($tml["banner"]["item"], $tml["show_referal_banner"]); $tml["banner"]["item"][0]["active"]=true; $tml["banner"]["but"]=$tml["banner"]["item"]; $banner2=mod('menu')->item("system/banner2/", array("key"=>"*", "sub"=>"item", "sub_opts"=>array("extend"=>array("limit"=>10), "skip"=>"empty_name"))); if(@$banner2["item"]){ $tml["banner2"]=$banner2; $tml["banner2"]["item"][0]["active"]=true; } /*if($SITE=="sz"){ //$tml["social"]=true; //$out1["menu"]=mod('menu')->item("catalog/fitnes_lajf/"); //$out1["item"]=mod('catalog')->res(array("root_id"=>$out1["menu"]["id"])); //$tml["catalog_2"][]=$out1; $public_block=array("slider", "news", "video", ); } if(@$SITE=="sue"){ $tml["filter_menu"]["item_p"]=mod('menu')->item("system/block_home/cons/", "*"); //$tml["filter_menu"]["item"]=mod('menu')->res("panel/product/status/"); $public_block=array("slider", "slider2", "news", ); $tml["article_list"]=mod('menu')->item("page/problems/", array("sub"=>"item")); if($URL["lang"]!="pl") $tml["top_banner"]=mod('menu')->item("system/top_banner/"); } */ mt("1"); $promo_res=mod('promo')->res(array("current"=>true, "type"=>array("hit", "action", "newest"), "for_opt_price"=>false, "sort"=>"date_start")); if($promo_res){ mt("2"); $product_res=mod('catalog')->res(array("promo_id"=>db_column($promo_res, "id"), "sort"=>"a.pos ASC", "short"=>true)); mt("3"); if($product_res){ foreach($product_res as $v){ //echo $v["name"]."-".$v["promo_id"]."
"; //if(count(@$promo_products[$v["promo_id"]])>=6) continue; //limit if slider $promo_products[$v["promo_id"]][]=$v; } foreach($promo_res as $v){ if(@$promo_products[$v["id"]]){ $tml["catalog_1"][]=array( "menu"=>$v, "url"=>@$v["url"]?url("lang_path").$v["url"]:null, "item"=>@$promo_products[$v["id"]], ); } } } } if(@$public_block){ foreach($public_block as $v){ $out=mod('menu')->item("page/".$v."/", array("key"=>"*", "sub"=>"item", "sub_opts"=>array("extend"=>array("limit"=>10, "order_by"=>"pos DESC")))); if(@$out["item"]){ $out["item"][0]["active"]=true; $out["but"]=$out["item"]; } if($v=="slider") $out["delay"]=12; $tml["slider"][]=$out; } } $banner_filter=mod('menu')->item("system/banner_filter/", array("sub"=>"item")); if(@$banner_filter["item"] && !@$banner_filter["hide"]){ foreach($banner_filter["item"] as $block){ $block=mod('catalog')->banner_filter($block); if(!$block) continue; $tml["banner_filter"]["block"][]=$block; } $tml["banner_filter"]["menu"]=$tml["banner_filter"]["block"]; } $tml["title"]=mod('menu')->item("system/const/base/meta_title_index/", "name"); if(!$tml["title"]) $tml["title"]=@$LANG_CONST["base"]["kind"]; $tml["h1_index"]=@$LANG_CONST["base"]["meta_h1_index"]; $tml["meta_description"]=@$LANG_CONST["base"]["meta_description_index"]; $tml["meta_keywords"]=@$LANG_CONST["base"]["meta_keywords_index"]; $tml["meta_img"]=mod('product')->img_url(@$tml["banner"]["item"][0]["opts"]["site_uk"], 1024, 1024); if(!@$tml["meta_keywords"]) foreach(@$tml["menu"]["item"] as $i=>$item) if($i) @$tml["meta_keywords"].=(@$tml["meta_keywords"]?", ":"").$item["name"]; if($URL["root"]=="subscribe_ok") $tml["subscribe_ok"]=true; $tml["search_term_string"]="{search_term_string}"; if(@$_GET["debug"]==1 || @$_GET["debug"]==2){//for lighthouse https://web.dev/measure/ if(@$_GET["debug"]==1) $tml["catalog_1"]=array_slice($tml["catalog_1"], 0, 2); $tml["EXT_ID"]="{}"; $tml["g_login"]=true; } } else if($URL["root"]=="cart"){ header_nocache(); $opts=mod('order')->get_cart(); $opts["is_gift"]=$_tml["has_gift"]=mod('order')->cart_gift(); $_tml["item"]=mod('order')->product_res($opts+array("ext"=>array("category_name"=>true, "extra"=>true), "owner"=>"")); $_tml["item_count"]=$_tml["item"]?count($_tml["item"]):null; $_tml["show_cart_free_sh"]=!@$PROFILE["chb_optovik"]&&!mod('menu')->item("panel/order/free_ship/", "hide")?mod('menu')->res("panel/order/free_ship/"):null; //$_tml["item2"]=mod('order')->cart_adds($_tml["item"]); $cart_pack_product_id=mod('menu')->item("system/const/cart/pack/", "value"); if($cart_pack_product_id && !in_array($cart_pack_product_id, $arr_product_id)) $tml["cart_pack"]=mod('order')->product_res(array("product_id"=>$cart_pack_product_id, "ext"=>array("category_name"=>true, "extra"=>true), "owner"=>"")); $_tml["cart_summary2"]=true; $_tml["gift"]=!!@$CUSTOMER["chb_gift"] && mod('menu')->item("panel/product/gift/", array("visible"=>true)); $tml["page_cart"]=$_tml; $tml["title"]=$LANG_CONST["const"]["cart"]; } else if($URL["root"]=="filter"){ /*if(!preg_match("~^[a-z0-9]~", $URL["current"])){ $filter_list=mod('menu')->res("panel/product/status/", array("type"=>"n*")); $filter=@$filter_list[str_replace("_", " ", urldecode(str_replace("+", "%2B", $URL["current"])))]; if($filter) redirect(url('lang_path').$URL["root"]."/".$filter["webname"]."/"); }*/ $tml["catalog"]["menu"]=$filter=mod('menu')->item("page/".$URL["root"]."/".$URL["current"]."/"); $tml["catalog"]["h1_sub"]=true; $res=mod('catalog')->res(array("status"=>$filter["webname"])); if($res){ foreach($res as $item){ $mi_res[$item["menu_id"]][]=$item; $mi=mod('menu')->item($item["menu_id"], "*"); $mpi=mod('menu')->item($mi["pid"], "*"); $pos="1".str_pad($mpi["pos"], 8, "0", STR_PAD_LEFT).str_pad($mi["pos"], 4, "0", STR_PAD_LEFT).str_pad($item["menu_id"], 4, "0", STR_PAD_LEFT); $pos_mi_arr[$pos]=$item["menu_id"]; } ksort($pos_mi_arr); foreach($pos_mi_arr as $menu_id){ $items=$mi_res[$menu_id]; $out=array(); $out["menu"]=$out["description_text"]=mod('menu')->item($menu_id, "*"); if(@$out["menu"]["hide"]) continue; $tml["catalog"]["item"]=array_merge(@(array)$tml["catalog"]["item"], $items); } } $tml["title"]=$tml["catalog"]["menu"]["name"]; $tml["meta_description"]=$tml["title"]." ".@$LANG_CONST["base"]["meta_description_page"]; } else if($URL["root"]=="favorite"){ $tml["catalog"]["menu"]=$mi=mod('menu')->item("page/".$URL["route"], "*"); $pids=@$_COOKIE[$GLOBALS["SITE_PREF"]."favorite"]; $pids=preg_replace(array("~[^0-9,]~si", "~\s*,+\s*~si"), array("", ","), stripslashes($pids)); if($pids) $tml["catalog"]["item"]=$item=mod('catalog')->res(array("product_id"=>preg_split('~,~', $pids))); if(!@$tml["catalog"]["item"]) $tml["catalog"]["description_text"]=$mi["text"]; $tml["title"]=$mi["name"]; $tml["meta_description"]=$tml["title"]." ".@$LANG_CONST["base"]["meta_description_page"]; } else if($URL["root"]=="profile"){ if(@$_GET["login"]){ if(@$_GET["pass"]){ //approve registrarion mod('customer')->approve($_GET); $_GET["auth"]=md5($_GET["login"].$_GET["pass"]); $_GET["pass"]=null; } $id=mod('customer')->login($_GET); if($id) header("Location: ".url("base").url("path").(@$_GET["pass"]?"?approve=ok":"?auto_auth=ok")); else echo "
Invalid auth url";
		exit;	
	}
	$mi=mod('menu')->item("system/profile/", "*");
	$mi_current=mod('menu')->item("system/profile/".@$URL["items"][1]."/", "*");
	
	$tml["profile"]["is_auth"]=!!$PROFILE;
	
	if($PROFILE){
		$tml["profile"]["is_approve"]=@$_GET["approve"]?mod('menu')->item("system/const/profile/is_approve/", "text"):null;
		$tml["profile"]["is_auto_reg"]=@$_GET["auto_auth"] && !$PROFILE["pass"]?mod('menu')->item("system/const/profile/is_auto_reg/", "text"):null;
		$tml["submenu"]=$mi;
		$tml["submenu"]["current"]=!@$URL["items"][1];
		$tml["submenu"]["item"]=$tml["profile_auth"]["_submenu"]["item"];
		$tml["profile_auth"]["_submenu"]["item"]=$tml["submenu"]["item"];
		
		$limit=40;
		
		if(!@$URL["items"][1] || $URL["items"][1]=="order"){
			$tml["profile"]["orders"]["bonus"]=$PROFILE["bonus"];
			$tml["profile"]["orders"]["items"]=mod('order')->res(array("customer_id"=>$PROFILE["id"], "filter"=>"with_trash", "limit"=>$limit, "page"=>@$_GET["page"], "has_pager"=>1, "owner"=>mod('access')->owner()), $RES_COUNT);
			$tml["profile"]["orders"]["pager"]["item"]=mod('main')->pager($RES_COUNT, $limit, @$_GET["page"]);
		
			$tml["profile"]["data"]=mod('customer')->res(array("id"=>$PROFILE["id"]));
			
			$card=mod('card')->active_card("*");
			$tml["profile"]["data"]["card"]=$card;;
		}
		else if($URL["items"][1]=="opt" && @$PROFILE["chb_optovik"]){
			$tml["profile"]["opt"]["has_foto"]=true;
			$tml["profile"]["opt"]["promo_type_list"]=mod('menu')->res("panel/promo/type/", array(""=>"hidden"));
			$tml["profile"]["opt"]["block"]=mod('product')->price_list(array("base", "opt"), $tml["profile"]["opt"]["price_type"]);
		}
		else if($URL["items"][1]=="referal"){
			$_tml=$mi_current;
			$_tml["description_text"]=$mi_current;
			$_tml["link"]=url("base")."ref/".mod('referal')->code($PROFILE);
			mod('referal')->res($PROFILE, $_tml);
			$tml["profile"]["referal"]=$_tml;
			$GLOBALS["~"]["referal"]=mod('menu')->res("system/profile/referal/", "wn");;
		}
		else if($URL["items"][1]=="pass"){
			$_tml["description_text"]=$mi_current;
			$_tml["email"]=@$PROFILE["email"];
			$tml["profile"]["pass"]=$_tml;
		}
		
		$tml["feedback"]=!@$URL["items"][1];

	}
	else{
		if(@$URL["items"][1]=="referal"){
			$tml["submenu"]=$mi;
			$tml["submenu"]["current"]=!@$URL["items"][1];
			$tml["submenu"]["item"]=$mi_current;
			$_tml=$mi_current;
			$tml["profile"]["referal"]=$_tml;
			$GLOBALS["~"]["referal"]=mod('menu')->res("system/profile/referal/", "wn");;
		}
		else{
			$tml["is_page_login"]=$is_page_auth=true;
		}
	}
	
	$tml["nofollow"]=true;
	$tml["name"]=@$mi_current["name"];
	$tml["title"]=(@$mi_current["name"]?@$mi_current["name"]." - ":"").@$mi["name"];
}


else if($URL["root"]=="reviews"){
	$limit=70;
	$tml["mi"]=mod('menu')->item("page/".$URL["root"]."/");
	if(!$URL["current"]) redirect(str_replace("//", "/", $URL["path"])); 
	$cur=$tml["current"]=mod('menu')->item("page/".$URL["root"]."/".@$URL["items"][1]."/");
	$review_count=mod('review')->count();
	$menu=mod('menu')->res("page/".$URL["root"]."/", array("active"=>@$URL["items"][1]."", "counts"=>$review_count));
	$menu[0]["url"]=str_replace("//", "/", $menu[0]["url"]);
	$tml["review_count"]=@$review_count[$cur["webname"]];
	if(@$_GET["page"]) $tml["nofollow"]=true;
	$tml["title"]=$cur["name"].(@$_GET["page"]>1?" (".$_GET["page"].")":"");
	$tml["review_buts"]["item"]=$menu;
	$tml["review_all"]["is_product"]=$is_product=@$URL["items"][1]=="product";
	$tml["review_all"]["review"]["item"]=mod('review')->res(array("type"=>@$URL["items"][1]."", "approved"=>1, "limit"=>$limit, "page"=>@$_GET["page"]), $RES_COUNT);
	$tml["review_all"]["review_pager"]["item"]=mod('main')->pager($RES_COUNT, $limit, @$_GET["page"]);
}

else if(@$is_page){
		
	$path=$is_page["path"];
	
	if(count($URL["items"])==1 && ($path_owner=mod('access')->owner("pages", $URL["items"][0]))){
		$path=$path_owner;
	}
	
		
	if(count($URL["items"])>1){
		$tml["submenu"]=mod('menu')->item("page/".@$URL["root"]."/");
		if(count($URL["items"])>2) $tml["submenu"]["item"]=mod('menu')->item("page/".@$URL["root"]."/".@$URL["items"][1]."/");
	}
	
	if(isset($_GET["add"]) || isset($_GET["edit"]) || isset($_GET["copy"])){
		if(!auth()) exit();
		if(isset($_GET["edit"])) $item=mod('menu')->item($path, "*");
		else if(isset($_GET["copy"])) $item=mod('menu')->item($_GET["copy"], "*");
		if(isset($_GET["add"]) || isset($_GET["copy"])){
			if(@$item) unset($item["id"]);
			$item["pid"]=mod('menu')->item($path, "id");
		}
		if(@$_GET["add"]==2 || @$_GET["edit"]==2 || (@$_GET["edit"]!=1 && mod('page')->is_ae(@$item["text"]))) $type=2;
		if(@$type==2) $item["block"]=mod('page')->get_ae(@$item, true);
		$tml["article_edit".@$type]=$item;
		$tml["title"]=@$item["name"];
	}
	else if(isset($_GET["save"])){
		if(!auth()) exit();
		mod('page')->save($_POST);
		header("Location: ".$URL["base"].$URL["path"]);
		exit;
	}
	else if(isset($_GET["delete"])){
		if(!auth()) exit();
		mod('menu')->delete(@$_GET["delete"]);
		header("Location: ".$URL["base"].$URL["path"]);
		exit;
	}
	else{

		if(!preg_match("~/$~", @$URL["route"])){
			@$URL["route"].="/";
			$redirect=$URL["route"];
		}

		if(@$URL["items"][1] && preg_match("~^\d{8}_\d{4}$~", @$URL["items"][1])){//**TEMP** - old url format: news/20181212_2300
			$date=@$URL["items"][1];
			$time=mktime($date[9].$date[10], $date[11].$date[12], 0, $date[4].$date[5], $date[6].$date[7], $date[0].$date[1].$date[2].$date[3]); 
			$pid=mod('menu')->item("page/".@$URL["root"]."/", "id");
			$webname=db_query("SELECT webname FROM menu WHERE pid=".$pid." AND date>=".$time." AND date<".($time+60), 0, true);
			if($webname && !preg_match("~^\d{8}_\d{4}$~", $webname)){
				$URL["route"]=@$URL["root"]."/".$webname."/";
				$redirect=$URL["route"];
			}
		}
		
		$page=mod('menu')->item($path, array("sub"=>"item", "sub_opts"=>array("extend"=>array("cond"=>array("m.name".url("lang_suf")." IS NOT NULL"))), "key"=>"*"));
		if(@$page["opts"]["redirect"]) $need_redirect=$page["opts"]["redirect"];
		if(@$page["redirect"]) $redirect=$page["redirect"];
		
		if(@$redirect) redirect(url('lang_path').$redirect); 
		
		if(@$page["item"]){
			$tml["article_list"]=$page;
			$tml["article_list"]["item"]=array_reverse($tml["article_list"]["item"]);
		}else{
			if(!$page) error_page(404);
			if(count($URL["items"])>1){
				$tml["share_buts"]=true;
				if(@$page["updated"]){
					$page["updated_date_"]=date("Y-m-d", $page["updated"]);
					$page["updated_date_format"]=date("d.m.Y", $page["updated"]);
				}
				if(@$page["date"]){
					$page["created_date_"]=date("Y-m-d", $page["date"]);
					$page["created_date_format"]=date("d.m.Y", $page["date"]);
				}
				if(@$page["created_date_format"]==@$page["updated_date_format"]) $page["updated_date_format"]=null;
			}
			if(mod('page')->is_ae(@$page["text"])){
				$page["block"]=mod('page')->get_ae(@$page);
				$tml["article_view2"]=$page;
			}
			else{
				$tml["article_view"]=$page;
			}
		}
		//$tml["back_but"]=true;
		$tml["title"]=$page["name"];
		$tml["meta_img"]=@$page["img"];
		$tml["meta_description"]=@$page["description"]?$page["description"]:$page["name"]." ".@$LANG_CONST["base"]["meta_description_page"];
	}
	
}

else{ //is catalog
	
	$catalog_item=mod('menu')->item("catalog/".url("route"));
	
	
	if($catalog_item || @$_GET["query"]){
		
		if(url("filter")){
			foreach(preg_split("~;~", url("filter")) as $vv){
				$pp=preg_split("~=~", $vv);
				if(!@$pp[0] || !@$pp[1]) continue;
				$_GET["params"][$pp[0]]=$pp[1];
			}
		}
		
		$sort="IF(a.sale_per, a.date_start, NULL) DESC, IF(m2.pid<0, m.pos, m2.pos), m.pos";
		if(@$_GET["sort"]=="price" || @$_GET["sort"]=="priced") $sort="MIN(p.`price[base]`)".(@$_GET["sort"]=="priced"?" DESC":"");
		
		
		if(@$_GET["query"]){
			$tml["search_show"]=true;
			
			$opts["menu_id"]=null;
			$opts["mode"]="front";
			$opts["search"]=stripslashes(db_normalize(@$_GET["query"], "text"));
			$filters_opts["search"]=$opts["search"];
			//$opts["sorting"]=isset($_GET["sorting"])?$_GET["sorting"]:@$_COOKIE[$SITE_PREF."sorting"];
			$opts["limit"]=mod('catalog')->PRODUCT_LIMIT;
			$opts["params"]=@$_GET["params"];
			$opts["sort"]=$sort;
			$opts["status"]=@$_GET["status"];
			$opts["show_hidden_cat"]=true;
			
			$tml["catalog"]["item"]=mod('catalog')->res($opts, $_count);
			$tml["nofollow"]=true;
			$tml["submenu"]=array("name"=>"Результати пошуку", "current"=>true);
			$tml["skip_h2"]=true;
			$tml["h1"]="Пошук по «".$opts["search"]."»"." (".($_count?$_count:0).")";
			$tml["title"]=$tml["h1"];
		}
		
		else if(@$catalog_item){ //catalog output
			$mi=mod('menu')->item($catalog_item["id"], "*");
			$mi_sub=mod('menu')->res($mi["id"]);
			$is_main_category=$mi["pid"]<0 && !!$mi_sub;
			$root_mi=mod('menu')->item($mi["pid"]);
			if(!$mi) error_page(404);
			
			
			$tml["submenu"]=$root_mi;
			$tml["submenu"]["active_sub_item"]=$mi;
			$tml["submenu"]["current"]=$is_main_category;
			$tml["submenu"]["has_sub"]=true;
			$tml["submenu"]["path_item"]=$mi["pid"]>0?mod('menu')->breadcrumb($mi["pid"]):false;
			$tml["submenu"]["item"]=mod('menu')->res($tml["submenu"]["id"], array("active"=>$mi["id"], "by"=>"id"));
			/*if(count($tml["submenu"]["item"])==1){
				$tml["submenu"]["item"]=false;
				if(count($URL["items"])==2){
					$need_redirect=true;
					$mi=mod('menu')->item("catalog/".$URL["root"]."/");
				}
			}*/
			if(@$mi["opts"]["redirect"]) $need_redirect=url("lang_path").@$mi["opts"]["redirect"];
			
			if(@$need_redirect){
				if($need_redirect===true) $need_redirect=$mi["url"];
				if($need_redirect!=url("path")) redirect($need_redirect); 
			}
			
			if(@$root_mi["hide"]) error_page(404);
			$tml["menu_id"]=$mi["id"];
			
			//$menu_id_arr=$is_main_category?mod('menu')->childs_id($mi["id"]):array($mi["id"]);
			$menu_id_arr=array($mi["id"]);
			if($menu_id_arr){
				foreach($menu_id_arr as $menu_id){
					//$out["menu"]=$out["description_text"]=mod('menu')->item($menu_id, "*");
					//if(count($URL["items"])==2) $out["description_text2"]=$out["description_text"];
					if(@$out["menu"]["hide"] && count($URL["items"])==1) continue;
					$opts=array("menu_id"=>$menu_id, "params"=>@$_GET["params"], "status"=>@$_GET["status"], "sort"=>$sort, "show_hidden_cat"=>true);
					$out["item"]=$item=mod('catalog')->res($opts);
					//if(!$item)  continue;
					$product_ids=array_merge(@$product_ids?$product_ids:array(), db_column($item, "id"));
					$tml["catalog"][]=$out;
					array_add($tml["catalog_ld"]["item"], $out["item"]);
				};
				
				if(@TML::$GLOBAL["sett"]["show_sub_category"]){
					 if($mi_sub) $tml["block_menu_in"]["item"]=$mi_sub;
				}
				else{
					if(!$mi_sub) $mi_sub=mod('menu')->res($mi["pid"], array("active"=>@$mi["webname"]));
					if($mi_sub) $tml["filters"]["sub_cat"]["item"]=$mi_sub;
				}
				
				if(@$product_ids) $tml["product_ids"]=implode(',', $product_ids);
				
				/*if(@$_GET["params"] || @$_GET["status"]){
					$out["menu"]["name"]="Знайдено в інших категоріях";
					$out["description_text"]=null;
					$out["skip_h2"]=null;
					$out["item"]=$item=mod('catalog')->res(array("not_product_id"=>@$product_ids, "params"=>@$_GET["params"], "status"=>@$_GET["status"], "sort"=>$sort, "show_hidden_cat"=>true));	
					$tml["catalog"][]=$out;
				}*/
			}
			if(@$tml["catalog_ld"]["item"]){
				$tml["catalog_ld"]["count"]=count($tml["catalog_ld"]["item"]);
				array_walk($tml["catalog_ld"]["item"], function(&$v,$i){$v["num"]=$i+1;});
			}
			
			
			$tml["can_sort"]=auth();
			//if($is_main_category) 
			$mi["description"]=preg_replace("~^(\r?\n?
\r?\n?)$~", "", $mi["description"]); //clear single
$tml["description_text0"]=$mi["description"]?$mi:null; $tml["description_text3"]=$mi; $tag_h1=@$mi["opts"]["h1".url("lang_suf")]; $tml["h1"]["name"]=$tag_h1?$tag_h1:$mi["name"]; $tml["h1"]["active_sub_item"]=$tml["submenu"]["active_sub_item"]; $tml["h1"]["sub_item"]=$tml["submenu"]["item"]; $tml["skip_h2"]=true; //$tml["skip_h2"]=!$is_main_category||!@$tml["submenu"]["item"]; $meta_title=@$mi["opts"]["meta_title".url("lang_suf")]; $tml["title"]=$meta_title?$meta_title:$mi["name"]." - ".@$LANG_CONST["base"]["meta_title_pattern"]; $meta_keywords=@$mi["opts"]["meta_keywords".url("lang_suf")]; $tml["meta_keywords"]=$meta_keywords?$meta_keywords:$mi["name"]; $meta_description=@$mi["opts"]["meta_description".url("lang_suf")]; if($meta_description && substr_count($meta_description, " ")>3) $tml["meta_description"]=$meta_description; else $tml["meta_description"]=mail_vars(@$LANG_CONST["base"]["meta_description_pattern"], array("name"=>$meta_description?$meta_description:$mi["name"])); $tml["meta_img"]=@$mi["img"]; if(@$mi["opts"]["canonical"]) $tml["canonical"]=url("base_root").url("lang_path").$mi["opts"]["canonical"]; $filter_menu_ids=mod('menu')->childs_id(@$mi["id"], true); $filters_opts["menu_id"]=$filter_menu_ids?array_merge($filter_menu_ids, array(@$mi["id"])):@$mi["id"]; } //sorting $sort_list=mod('menu')->res("panel/product/sort_list/"); if($sort_list){ $tml["sort_list"]=array("item"=>$sort_list, "value"=>@$_GET["sort"]); if(@$_GET["sort"]) $tml["nofollow"]=true; } //filters $filters=mod('product')->params_in_category(@$filters_opts, @$_GET["params"], $filters_active); if($filters) $tml["filters"]["block"]=$filters; $tml["has_filters"]=!!@$tml["filters"]; if($filters_active){ if($filters_active) $tml["filter_line"]["item"]=$filters_active; $tml["nofollow"]=true; //seo control instructions if(@$mi && count($filters_active)==1){ $meta_data=array( "name"=>$mi["name"], "filter"=>$filters_active[0]["name"], "company"=>$GLOBALS["~"]["base"]["name"], ); $tml["page_id"]=@$filters_active[0]["param_id"]; $tml["h1"]["name"]=mail_vars(@$filters_active[0]["opts"]["h1"], $meta_data)?:$tml["h1"]["name"]." ".$filters_active[0]["name"]; $tml["title"]=mail_vars(def(@$filters_active[0]["opts"]["meta_title"], @$LANG_CONST["base"]["meta_title_filters"]), $meta_data); $tml["meta_description"]=mail_vars(def(@$filters_active[0]["opts"]["meta_description"], @$LANG_CONST["base"]["meta_description_filters"]), $meta_data); $mi_filter=mod('menu')->item(@$filters_active[0]["param_id"], "*"); $mi_filter["description"]=mail_vars($mi_filter["description"], $meta_data); $mi_filter["text"]=mail_vars($mi_filter["text"], $meta_data); $tml["description_text0"]=$tml["description_text3"]=$mi_filter; if(@$filters_active[0]["in_seo"]){ $tml["canonical"]=url("base_root").url("path_abs"); $tml["nofollow"]=false; } } } } else{ //product output if(preg_match("~^[a-z0-9_\-]+$~", $URL["current"])){ $opts=array("webname"=>$URL["current"]); $opts["show_hidden_cat"]=true; if(!preg_match("~.*/$~", url("route"))) $need_redirect=true; } else{ error_page(404); } $item=mod('catalog')->res($opts); if(!@$item["name"] && @$item[0]) $item=$item[0]; if(!$item) error_page(404); /*if($SITE=="sue" && url("lang")=="pl"){ //auto translate in google $extra=mod('product')->translate($item["product_id"]); if($extra) $item["extra"]=$extra; }*/ if(@$item["redirect"]) $need_redirect=$item["redirect"]; //if(@$item["url"] && $URL["path"]!=$item["url"] && !@$need_redirect) $need_redirect=true; if(@$need_redirect) redirect(($need_redirect===true?$item["url"]:$need_redirect).($_SERVER["QUERY_STRING"]?"?".$_SERVER["QUERY_STRING"]:"")); $mi=mod('menu')->item($item["menu_id"]); $root_mi=mod('menu')->item($mi["pid"]); if(@$root_mi["hide"] && !@$item["has_active"]) error_page(404); //hide inactive product with inactive category $tml["product"]=$item; $tml["product"]["can_add_to_cart"]=true; $tml["product"]["fb_link"]=urlencode(url('base').mod('product')->url($item)); //$tml["product"]["but_translate"]=auth() && $URL["lang"]=="pl"; $tml["submenu"]=mod('menu')->item($mi["pid"], array("sub"=>"subitem")); $tml["submenu"]["path_item"]=mod('menu')->breadcrumb($mi["id"]); $tml["category_name"]=$tml["submenu"]["name"].(@$tml["submenu"]["item"]?" > ".$tml["submenu"]["item"]["name"]:""); //var_dump($tml["product"]); if(@$item["rel_id"]){ $tml["product"]["rel_prod"]["rel_prod_title"]=@$LANG_CONST["ui"]["product_rel"]; $tml["product"]["rel_prod"]["items"]=mod('catalog')->res(array("id"=>_split($item["rel_id"]))); } if(@$item["adds_id"]){ $tml["product"]["rel_prod_adds"]["rel_prod_title"]=@$LANG_CONST["ui"]["product_rel2"]; $tml["product"]["rel_prod_adds"]["items"]=mod('catalog')->res(array("id"=>_split($item["adds_id"]))); } if(@TML::$GLOBAL["sett"]["rel_prod_auto"]){ $tml["product"]["rel_prod_auto"]["rel_prod_title"]=mod('menu')->item("system/settings/crm/rel_prod_auto/", "name"); $tml["product"]["rel_prod_auto"]["items"]=$rel_items=mod('catalog')->res(array("menu_id"=>$item["menu_id"], "not_product_id"=>$item["id"], "limit"=>24)); if(!$rel_items) $rel_items=array(); if(count($rel_items)<5){ $rel_items=mod('catalog')->res(array("menu_id"=>$item["menu_pid"], "not_product_id"=>array_merge(array($item["id"]), db_column($rel_items, "id")), "limit"=>24-count($rel_items))); if($rel_items) $tml["product"]["rel_prod_auto"]["items"]=array_merge(($tml["product"]["rel_prod_auto"]["items"]?$tml["product"]["rel_prod_auto"]["items"]:array()), $rel_items); } } /*$promo_res=mod('promo')->res(array("current"=>true, "type"=>array("hit", "action", "newest"), "for_opt_price"=>false, "sort"=>"date_start")); if($promo_res){ $promo=end($promo_res); $rel_prod_items=mod('catalog')->res(array("promo_id"=>$promo["id"], "sort"=>"a.pos ASC", "short"=>true)); if($rel_prod_items){ $tml["product"]["rel_prod"]["rel_prod_title"]=$promo["name"]; $tml["product"]["rel_prod"]["items"]=mod('catalog')->res(array("promo_id"=>$promo["id"], "sort"=>"a.pos ASC", "short"=>true)); } }*/ $tml["params_list"]=mod('product')->params_list(@$item["id"], true); $tml["has_review"]=$tml["review_count_block"]=!mod('menu')->item("panel/review/", "hide"); $product_ids=db_query("SELECT id FROM product WHERE gid=".$item["gid"], null, true); if($product_ids){ $tml["product"]["review_count"]=$tml["product"]["review_rating"]=0; $tml["review"]["item"]=mod('review')->res(array("product_id"=>$product_ids, "no_product"=>true, "approved"=>1), $tml["product"]["review_count"], $tml["product"]["review_rating"]); if($tml["review"]["item"]){ $tml["product"]["review_author"]=$tml["review"]["item"][0]["author"]?str_replace('"', '"', $tml["review"]["item"][0]["author"]):"Anonymous"; $tml["product"]["review_description"]=preg_replace("~\r?\n~si", '\n', str_replace('"', '"', $tml["review"]["item"][0]["text"])); $tml["product"]["review_datePublished"]=date("Y-m-d", $tml["review"]["item"][0]["date"]); } } if(!@$tml["product"]["follow"]) $tml["nofollow"]=true; $tml["canonical"]=url("base_root").url("lang_path").(@$tml["product"]["canonical"]?$tml["product"]["canonical"]:@$item["g_url"]); $tml["title"]=@$item["extra"]["title"]?$item["extra"]["title"]:$item["name_quot"]." ".$item["gname"]." - ".@$LANG_CONST["base"]["meta_title_pattern"];//.$menu_current["name"]; $tml["og_title"]=@$item["extra"]["title"]?$item["extra"]["title"]:$item["name_quot"]." ".$item["gname"]; $tml["meta_img"]=@$item["imgs"][0]; $tml["meta_description"]=mail_vars(@$LANG_CONST["base"]["meta_description_pattern"], array("name"=>$item["name"])); $tml["block_pay_delivery"]=array( "name"=>mod('menu')->item("panel/product/delivery/", "name"), "pay"=>mod('menu')->item("panel/product/delivery/pay/", "text"), "delivery_name"=>mod('menu')->item("panel/product/delivery/delivery/", "name"), "delivery"=>mod('menu')->res("panel/product/delivery/delivery/", array("extend"=>true)), ); //$tml["meta_description"]="Ціна: ".@$item["price"]." грн. / ".$item["gname"]." (".$item["avail_name"]."). Склад продукту: ".@$item["extra"]["desc"].(@$item["expire"]?". Рекомендований термін придатності: ".$item["expire"]:""); } } //promo in cart $promo_res=mod('promo')->res(array("current"=>true, "type"=>array("cart"))); if($promo_res){ $product_res=mod('catalog')->res(array("promo_id"=>db_column($promo_res, "id"), "sort"=>"a.pos ASC", "short"=>true)); if($product_res){ $cart=mod('order')->get_cart(); foreach($product_res as $v){ if(@$cart["product_id"] && in_array($v["id"], $cart["product_id"])) continue; $promo_products[$v["promo_id"]][]=$v; } foreach($promo_res as $v){ $tml["promo_to_cart"][]=array( "name"=>$v["name"], "items"=>@$promo_products[$v["id"]], ); } if(@$tml["page_cart"]) $tml["page_cart"]["promo_to_cart2"]=$tml["promo_to_cart"]; } } mt(); /*if($URL["root"]=="order_ok"){ $tml["order_ok"]=array("card_link"=>mod('privatbank')->pay_link(@$_COOKIE["last_order_sum"])); $tml["order_ok_autoclick"]=true; }*/ $tml["is_article_view"]=@$tml["article_view"]||@$tml["article_view2"]; if($URL["root"]=="contact"){ $tml["is_page_contact"]["streets"]=mod('menu')->res("panel/order/trans/2/"); array_walk($tml["is_page_contact"]["streets"], function(&$item){$item["name"]=preg_replace("~^[^,]*, ?~", "", $item["name"]);}); $tml["is_article_view"]=false; if(@$tml["article_view"]){ $tml["article_view"]=mail_vars($tml["article_view"], array( "customer_id"=>@$_COOKIE[$GLOBALS["SITE_PREF"]."customer_id"], "bot_name"=>mod('menu')->item("system/settings/telegram/bot_name/", "name"), )); } } if($URL["root"]=="oferta"){ if(@$tml["article_view"]){ $page_tml=mod('menu')->res("system/const/legal/", "wn"); $page_tml["domain"]=$_SERVER['HTTP_HOST']; $tml["article_view"]=mail_vars($tml["article_view"], $page_tml); } } if($SITE=="sue" && $URL["root"]=="private-label"){ $_tml["title"]="Заявка на Private Label"; $_tml["h1"]=false; $_tml["type"]=$URL["root"]; $_tml["country_list"]=mod('menu')->res("panel/customer/country/"); $tml["article_view2"]["block"][]=TML(TML::$FILE.":customer_request", $_tml); } if($SITE=="sue" && url('lang')=="ru" && !@$_COOKIE[$SITE_PREF."go_to_uk_banner"]){ setcookie($SITE_PREF."go_to_uk_banner", time(), mktime(23,59,59), url("rel")); $tml["go_to_uk_banner"]=mod('menu')->item("system/const/ui/go_to_uk_banner/", "*"); } //$tml["show_cart_charity"]=$SITE=="sz" && !@$SUB_DOMAIN; $tml["show_cart_free_sh"]=!@$PROFILE["chb_optovik"]&&!mod('menu')->item("panel/order/free_ship/", "hide")?mod('menu')->res("panel/order/free_ship/"):null; $tml["show_cart_charity_per"]=mod('menu')->item("panel/order/cart_charity_per/", array("key"=>"*", "visible"=>true)); $tml["address_list"]["item"]=mod('menu')->res(mod('order')->delivery_type_link."2/"); $tml["menu_info"]=$tml["menu_mob"]=mod('menu')->item("page/info/", array("sub"=>"item", "sub_opts"=>array("active"=>@$URL["current"]."/"))); $tml["menu_popular"]["item"]=array_slice($tml["menu"]["item"], 0, 8); $tml["menu_work_time"]=mod('menu')->item("system/const/work_time/", array("sub"=>"item")); if(!@$meta_title && !preg_match("~".@$LANG_CONST["base"]["name"]."~i", @$tml["title"])) @$tml["title"].=" - ".@$LANG_CONST["base"]["name"]; if(@$tml["meta_description"]) $tml["meta_description"]=preg_replace("~\r?\n~si", '\n', str_replace('"', '"', $tml["meta_description"])); if(@$tml["meta_img"]) $tml["meta_img"]=mod('product')->img_url($tml["meta_img"], 1024, 1024); $tml["google_site_verification"]=mod('menu')->res("system/settings/integration/google-site-verification/"); mt(); //echo mod('privatbank')->pay_link(100)."-"; //utm_source=facebook&utm_medium=social&utm_campaign=enzymo if(@$_GET["utm_source"]) setcookie($SITE_PREF."utm", "utm_source=".@$_GET["utm_source"]."&utm_medium=".@$_GET["utm_medium"]."&utm_campaign=".@$_GET["utm_campaign"]."", mktime(23,59,59)+60*60*24*30, url("rel")); /*$mychatbot=mod('menu')->res("system/settings/integration/mychatbot/", "wn"); if(@$mychatbot["account_id"]) $tml["mychatbot"]=$mychatbot; if(@$_GET["no_ext"]) $tml["mychatbot"]=null;*/ echo TML(TML::$FILE.":", $tml); mt();