<?php

/*
  PHP version 5
  Copyright (c) 2002-2018 ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030
  ESPCMS官网介绍：http://www.ecisp.cn	企业建站：http://www.earclink.cn

 */

use modul_application\ESPCMS_ArticleTypeDB;
use inc_application\link\ArticleLink;

class lib_typelist {

    public static function call_typelist($parameter, $filename = 'typelist', $outHTML = null) {
        $espcms_lib_template = espcms_web_template();
        $espcms_lib_template->libfile = true;
        $para = espcms_array_getvalue($parameter);
        $mid = $para['mid'] && espcms_ismatches($para['mid']) ? $para['mid'] : 0;
        $utid = $para['utid'] && espcms_ismatches($para['utid']) ? $para['utid'] : 0;
        $tid = $para['tid'] && espcms_ismatches($para['tid']) ? $para['tid'] : 0;
        if (!$utid && $tid) {
            $utid = $tid;
        }
        $lng = espcms_lancode();
        if (defined('ESPCMS_WEB_TYPE') && ESPCMS_WEB_TYPE == 'WAP') {
            $typelist = ESPCMS_ArticleTypeDB::get_article_type_list($tid, $utid, $mid, $lng, false, false, true, 1);
        } else {
            $typelist = ESPCMS_ArticleTypeDB::get_article_type_list($tid, $utid, $mid, $lng, false, false, true);
        }

        $espcms_lib_template->into('para', $para);
        $espcms_lib_template->into('array', $typelist);

        if ($utid) {
            $type_read = ESPCMS_ArticleTypeDB::get_article_type_view($utid);
            $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('uptypeview', $type_read);
        }
        if (!empty($outHTML)) {
            $output = $espcms_lib_template->fetch(null, null, $outHTML);
        } else {
            $output = $espcms_lib_template->fetch('lib/' . $filename);
        }
        return $output;
    }

}
