<?php   if(!defined('DEDEINC')) exit('Request Error!');
/**
 * 自定義宏標記調用標籤
 *
 * @version        $Id: mytag.lib.php 1 9:29 2010年7月6日Z tianya $
 * @package        DedeCMS.Taglib
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
 
/*>>dede>>
<name>自定義宏標記</name>
<type>全局標記</type>
<for>V55,V56,V57</for>
<description>用於獲取自定義宏標記的內容</description>
<demo>
{dede:mytag typeid='0' name=''/}
</demo>
<attributes>
    <iterm>name:標記名稱，該項是必須的屬性，以下 2、3是可選屬性</iterm> 
    <iterm>ismake:默認是 no 表示設定的純HTML代碼， yes 表示含板塊標記的代碼</iterm>
    <iterm>typeid:表示所屬欄目的ID，默認為 0 ，表示所有欄目通用的顯示內容，在列表和文檔模板中，typeid默認是這個列表或文檔本身的欄目ＩＤ</iterm>
</attributes> 
>>dede>>*/
 
function lib_mytag(&$ctag, &$refObj)
{
    $attlist = "typeid|0,name|,ismake|no";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);

    if(trim($ismake)=='') $ismake = 'no';
    $body = lib_GetMyTagT($refObj, $typeid, $name, '#@__mytag');
    //編譯
    if($ismake=='yes')
    {
        require_once(DEDEINC.'/arc.partview.class.php');
        $pvCopy = new PartView($typeid);
        $pvCopy->SetTemplet($body,"string");
        $body = $pvCopy->GetResult();
    }
    return $body;
}

function lib_GetMyTagT(&$refObj, $typeid,$tagname,$tablename)
{
    global $dsql;
    if($tagname=='') return '';
    if(trim($typeid)=='') $typeid=0;
    if( !empty($refObj->Fields['typeid']) && $typeid==0) $typeid = $refObj->Fields['typeid'];
    
    $typesql = $row = '';
    if($typeid > 0) $typesql = " And typeid IN(0,".GetTopids($typeid).") ";
    
    $row = $dsql->GetOne(" SELECT * FROM $tablename WHERE tagname LIKE '$tagname' $typesql ORDER BY typeid DESC ");
    if(!is_array($row)) return '';

    $nowtime = time();
    if($row['timeset']==1 
      && ($nowtime<$row['starttime'] || $nowtime>$row['endtime']) )
    {
        $body = $row['expbody'];
    }
    else
    {
        $body = $row['normbody'];
    }
    
    return $body;
}