<?php
if (!defined('DEDEINC')) exit ('dedebiz');
/**
 * 指定栏目信息标签
 *
 * @version        $id:type.lib.php 9:29 2010年7月6日 tianya $
 * @package        DedeBIZ.Taglib
 * @copyright      Copyright (c) 2022 DedeBIZ.COM
 * @license        GNU GPL v2 (https://www.dedebiz.com/license)
 * @link           https://www.dedebiz.com
 */
function lib_type(&$ctag, &$refObj)
{
    global $dsql, $envs;
    $attlist = "typeid|0";
    FillAttsDefault($ctag->CAttribute->Items, $attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    $innertext = trim($ctag->GetInnerText());
    if ($typeid == 0) {
        $typeid = (isset($refObj->TypeLink->TypeInfos['id']) ? $refObj->TypeLink->TypeInfos['id'] : $envs['typeid']);
    }
    if (empty($typeid)) return '';
    $row = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$typeid' ");
    if (!is_array($row)) return '';
    if (trim($innertext) == '') $innertext = GetSysTemplets("part_type_list.htm");
    $dtp = new DedeTagParse();
    $dtp->SetNameSpace('field', '[', ']');
    $dtp->LoadSource($innertext);
    if (!is_array($dtp->CTags)) {
        unset($dtp);
        return '';
    } else {
        $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
        foreach ($dtp->CTags as $tagid => $ctag) {
            if (isset($row[$ctag->GetName()])) $dtp->Assign($tagid, $row[$ctag->GetName()]);
        }
        $revalue = $dtp->GetResult();
        unset($dtp);
        return $revalue;
    }
}
?>