<?php
/**
 * @link         http://www.openzc.cn/
 * @author       hexipeng | e-mail:2017412656@qq.com
 * @copyright    Copyright (c) 2020, Openzc, Inc.
 * @license      http://www.openzc.cn/license.txt
 */
class cTag{
    function tag_field($GET,$field){
        global $currencies,$blog_class,$product_class;
				
		
        switch ($field) {
			case "securityToken":
				return $_SESSION['securityToken'];
			break;
			case 'hidden':
				foreach($GET as $k => $v){
					if($v){$str.="<input type='hidden' name='".$k."' value='".$v."'/>\r\n";}
                }
				return $str;
			break;
			case 'position':
				$position=$this->get_breadcrumb();
				
				return $position;
			break;
			case 'template':
				$str=DIR_WS_CATALOG.DIR_WS_TEMPLATE;
				return $str;
			break;
			
        }
        
    }
    private function tag_meta($GET,$field){
        switch($field){
            case "global_title":return TITLE;break;
            case "global_site_tagline":return SITE_TAGLINE;break;
            case "global_custom_keywords":return CUSTOM_KEYWORDS;break;
            case "home_title":return HOME_PAGE_TITLE;break;
            case "home_keywords":return HOME_PAGE_META_KEYWORDS;break;
            case "home_description":return HOME_PAGE_META_DESCRIPTION;break;
            case "title":return ;break;
            case "keywords":return ;break;
            case "description":return ;break;
        }
    }
    private function get_breadcrumb($data=[]){
		global $predata_class,$blog_class,$breadcrumb;
		$categories=$predata_class->getPredata(TABLE_BLOG_CATEGORIES);
		if($_GET['main_page']==FILENAME_BLOG || $_GET['main_page']==FILENAME_BLOG_ARCHIVES || $_GET['main_page']==FILENAME_BLOG_REVIEWS){
			$home=$breadcrumb->_trail[0];
			$breadcrumb->_trail=array();
			$breadcrumb->_trail[]=$home;
		}
		if($_GET['main_page']==FILENAME_BLOG || $_GET['main_page']==FILENAME_BLOG_ARCHIVES){
			$breadcrumb->_trail[]=array("link"=>zen_href_link(FILENAME_BLOG),"title"=>FILENAME_BLOG_TEXT);
			if(isset($_GET['cPath'])){
				$cpath=array_filter(explode("_",$_GET['cPath']));
				foreach($cpath as $k => $v){
					$link=$categories[$v]['categories_link'];
					$title=$categories[$v]['categories_name'];
					$breadcrumb->_trail[]=array("link"=>$link,"title"=>$title);
				}
			}
			if(isset($_GET['archives_id'])){
				$archives=$blog_class->get_archives_list($_GET,["aid"=>$_GET['archives_id']]);
				$archives=$archives['datalist'][0];
				$breadcrumb->_trail[]=array("link"=>$archives['archives_link'],"title"=>$archives['archives_name']);
			}
		}
		if($_GET['main_page']==FILENAME_BLOG_REVIEWS){
			$breadcrumb->_trail[]=array("link"=>zen_href_link(FILENAME_BLOG_REVIEWS),"title"=>FILENAME_BLOG_REVIEWS_TEXT);
			if(isset($_GET['archives_id'])){
				$archives=$blog_class->get_archives_list($_GET,["aid"=>$_GET['archives_id']]);
				$archives=$archives['datalist'][0];
				$breadcrumb->_trail[]=array("link"=>$archives['archives_link'],"title"=>$archives['archives_name']);
			}
		}
		if($_GET['main_page']==FILENAME_ADVANCED_SEARCH_RESULT){
			$breadcrumb->_trail[]=array("link"=>"javascript:void(0);","title"=>HEADING_TITLE);
			if(isset($_GET['cid']) && $_GET['cid']!=0){
				$categories=$predata_class->getPredata(TABLE_CATEGORIES);
				$breadcrumb->_trail[]=array("link"=>$categories[$_GET['cid']]['categories_link'],"title"=>$_GET['cid']['categories_name']);
			}
			if(isset($_GET['keyword'])){
				$breadcrumb->_trail[]=array("link"=>"javascript:void(0);","title"=>$_GET['keyword']);
			}
			
		}
		if(!defined("TPL_MODULES_RESET")){
			define("TPL_MODULES_RESET",TPL_MODULES);
		}
		if(is_file(TPL_MODULES_RESET."tpl/position.tpl")){
			$html=file_get_contents(TPL_MODULES_RESET."tpl/position.tpl");
		}else{
			$html="";
			return "Error:Your breadcrumb template file does not exist!";
		}
		foreach($breadcrumb->_trail as $k => $v){
			$k=$k+1;
			if($k==1){
				$name="home";
			}else if($k<count($breadcrumb->_trail)){
				$name="center";
			}else{
				$name="last";
			}
			$content=$this->get_breadcrumb_tpl($html,$name);
			$str=str_replace("[field:link/]",$v['link'],$content);
			$str=str_replace("[field:title/]",$v['title'],$str);
			@$result.=$str;
		}
		
		return $result;
	}
	private function get_breadcrumb_tpl($html,$name){
		$start=strpos($html,"{type:".$name."}")+strlen("{type:".$name."}");
		$end=strpos($html,"{/type:".$name."}");
		$length=$end-$start;
		if($length<0){
			return false;
		}
		$content=substr($html,$start,$length);
		return $content;
    }
	
}
?>