<?php
/*
  PHP version 5
  Copyright (c) 2002-2020 ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220
*/
use modul_application\ESPCMS_ArticleTypeDB;
use inc_application\link\ArticleLink;
class lib_type {
	public static function call_type($parameter, $filename = 'type', $outHTML = null) {
		$espcms_lib_template = espcms_web_template();
		$espcms_lib_template->libfile = true;
		$para = espcms_array_getvalue($parameter);
		if (!espcms_ismatches($para['tid']) || !$para['tid']) {
			return false;
		}
		$type_read = ESPCMS_ArticleTypeDB::get_article_type_view($para['tid']);
		if (!$type_read) {
			return false;
		}
		$type_goto_read = $type_read['gotoid'] && espcms_ismatches($type_read['gotoid']) ? ESPCMS_ArticleTypeDB::get_article_type_view($type_read['gotoid']) : $type_read;
		$type_read['link'] = ArticleLink::type_link($type_goto_read);
		$espcms_lib_template->into('para', $para);
		$espcms_lib_template->into('read', $type_read);
		if (!empty($outHTML)) {
			$output = $espcms_lib_template->fetch(null, null, $outHTML);
		} else {
			$output = $espcms_lib_template->fetch('lib/' . $filename);
		}
		return $output;
	}
	public static function find_type($tid = 0, $return_key = 'typename') {
		if (!espcms_ismatches($tid) || !$tid) {
			return false;
		}
		$type_read = ESPCMS_ArticleTypeDB::get_article_type_view($tid);
		if (!$type_read) {
			return false;
		}
		$type_goto_read = $type_read['gotoid'] && espcms_ismatches($type_read['gotoid']) ? ESPCMS_ArticleTypeDB::get_article_type_view($type_read['gotoid']) : $type_read;
		$type_read['link'] = ArticleLink::type_link($type_goto_read);
		$type_read['purview_link'] = ArticleLink::doc_js_link('typepuv', $type_read);
		return $type_read[$return_key];
	}
}
