dedecms修改arc.archives.class.php实现文章页支持mip v1.0

php
if(!defined('DEDEINC')) exit("Request Error!");
/**
 * 文档类
 *
 * @version        $Id: arc.archives.class.php 4 15:13 2010年7月7日Z tianya $
 * @package        DedeCMS.Libraries
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(DEDEINC."/typelink.class.php");
require_once(DEDEINC."/channelunit.class.php");
require_once(DEDEINC."/downmix.inc.php");
require_once(DEDEINC.'/ftp.class.php');

@set_time_limit(0);
/**
 * 主文档类(Archives类)
 *
 * @package          TypeLink
 * @subpackage       DedeCMS.Libraries
 * @link             http://www.dedecms.com
 */
class Archives
{
    var $TypeLink;
    var $ChannelUnit;
    var $dsql;
    var $Fields;
    var $dtp;
    var $ArcID;
    var $SplitPageField;
    var $SplitFields;
    var $NowPage;
    var $TotalPage;
    var $NameFirst;
    var $ShortName;
    var $FixedValues;
    var $TempSource;
    var $IsError;
    var $SplitTitles;
    var $PreNext;
    var $addTableRow;
    var $ftp;
    var $remoteDir;

    /**
     *  php5构造函数
     *
     * @access    public
     * @param     int  $aid  文档ID
     * @return    string
     */
    function __construct($aid)
    {
        global $dsql,$ftp;
        $this->IsError = FALSE;
        $this->ArcID = $aid;
        $this->PreNext = array();

        $this->dsql = $dsql;
        $query = "SELECT channel,typeid FROM `#@__arctiny` WHERE id='$aid' ";
        $arr = $this->dsql->GetOne($query);
        if(!is_array($arr))
        {
            $this->IsError = TRUE;
        }
        else
        {
            if($arr['channel']==0) $arr['channel']=1;
            $this->ChannelUnit = new ChannelUnit($arr['channel'], $aid);
            $this->TypeLink = new TypeLink($arr['typeid']);
            if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
            {
                // 如果当前文档不是系统模型,为单表模型
                $query = "SELECT arc.*,tp.reid,tp.typedir,ch.addtable
                FROM `#@__archives` arc
                         LEFT JOIN #@__arctype tp on tp.id=arc.typeid
                          LEFT JOIN #@__channeltype as ch on arc.channel = ch.id
                          WHERE arc.id='$aid' ";
                $this->Fields = $this->dsql->GetOne($query);
            }
            else
            {
                $this->Fields['title'] = '';
                $this->Fields['money'] = $this->Fields['arcrank'] = 0;
                $this->Fields['senddate'] = $this->Fields['pubdate'] = $this->Fields['mid'] = $this->Fields['adminid'] = 0;
                $this->Fields['ismake'] = 1;
                $this->Fields['filename'] = '';
            }

            if($this->TypeLink->TypeInfos['corank'] > 0 && $this->Fields['arcrank']==0)
            {
                $this->Fields['arcrank'] = $this->TypeLink->TypeInfos['corank'];
            }

            $this->Fields['tags'] = GetTags($aid);
            $this->dtp = new DedeTagParse();
            $this->dtp->SetRefObj($this);
            $this->SplitPageField = $this->ChannelUnit->SplitPageField;
            $this->SplitFields = '';
            $this->TotalPage = 1;
            $this->NameFirst = '';
            $this->ShortName = 'html';
            $this->FixedValues = '';
            $this->TempSource = '';
            $this->ftp = &$ftp;
            $this->remoteDir = '';
            if(empty($GLOBALS['pageno']))
            {
                $this->NowPage = 1;
            }
            else
            {
                $this->NowPage = $GLOBALS['pageno'];
            }

            //特殊的字段数据处理
            $this->Fields['aid'] = $aid;
            $this->Fields['id'] = $aid;
            $this->Fields['position'] = $this->TypeLink->GetPositionLink(TRUE);
            $this->Fields['typeid'] = $arr['typeid'];

            //设置一些全局参数的值
            foreach($GLOBALS['PubFields'] as $k=>$v)
            {
                $this->Fields[$k] = $v;
            }

            //为了减少重复查询,这里直接把附加表查询记录放在 $this->addTableRow 中,在 ParAddTable() 不再查询
            if($this->ChannelUnit->ChannelInfos['addtable']!='')
            {
                $query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}` WHERE `aid` = '$aid'";
                $this->addTableRow = $this->dsql->GetOne($query);
            }

            //issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
            if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
            {
                if(is_array($this->addTableRow))
                {
                    $this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
                    $this->Fields['templet'] = $this->addTableRow['templet'];
                    $this->Fields['userip'] = $this->addTableRow['userip'];
                }
                $this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
                $this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
                $this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
            }
            else
            {
                $this->Fields['templet'] = $this->Fields['redirecturl'] = '';
            }
        }//!error
    }

    //php4构造函数
    function Archives($aid)
    {
        $this->__construct($aid);
    }

    /**
     *  解析附加表的内容
     *
     * @access    public
     * @return    void
     */
    function ParAddTable()
    {
        //读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用 {dede:field name='fieldname' /} 标记统一调用
        if($this->ChannelUnit->ChannelInfos['addtable']!='')
        {
            $row = $this->addTableRow;
            if($this->ChannelUnit->ChannelInfos['issystem']==-1)
            {
                $this->Fields['title'] = $row['title'];
                $this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
                $this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
                $this->Fields['ismake'] = 1;
                $this->Fields['arcrank'] = 0;
                $this->Fields['money']=0;
                $this->Fields['filename'] = '';
            }

            if(is_array($row))
            {
                foreach($row as $k=>$v) $row[strtolower($k)] = $v;
            }
            if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
            {
                foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
                {
                    if(isset($row[$k]))
                    {
                        if(!empty($arr['rename']))
                        {
                            $nk = $arr['rename'];
                        }
                        else
                        {
                            $nk = $k;
                        }
                        $cobj = $this->GetCurTag($k);
                        if(is_object($cobj))
                        {
                            foreach($this->dtp->CTags as $ctag)
                            {
                                if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$k)
                                {
                                    //带标识的专题节点
                                    if($ctag->GetAtt('noteid') != '') {
                                        $this->Fields[$k.'_'.$ctag->GetAtt('noteid')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
                                    }
                                    //带类型的字段节点
                                    else if($ctag->GetAtt('type') != '') {
                                        $this->Fields[$k.'_'.$ctag->GetAtt('type')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
                                    }
                                    //其它字段
                                    else {
                                        $this->Fields[$nk] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
                                    }
                                }
                            }
                        }
                        else
                        {
                            $this->Fields[$nk] = $row[$k];
                        }
                        if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y' && !empty($this->Fields['keywords']))
                        {
                            $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'],$this->Fields[$nk]);
                        }
                    }
                }//End foreach
            }
            //设置全局环境变量
            $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
            $this->Fields['typelink'] = $this->TypeLink->GetOneTypeLink($this->TypeLink->TypeInfos);
            $this->Fields['typeurl'] = $this->TypeLink->GetOneTypeUrl($this->TypeLink->TypeInfos);
            @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
$this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']);
$this->Fields['body'] = str_replace('$', '$$', $this->Fields['body']);
      // 过滤掉样式表和脚本
   $this->Fields['body'] = preg_replace('/(style=".*")/', '', $this->Fields['body']); $this->Fields['body'] = preg_replace("/