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']; @SetSysEnv($this->Fields['typeid'], $this->Fields['typename'], $this->Fields['id'], $this->Fields['title'], 'archives'); } //完成附加表信息读取 unset($row); //处理要分页显示的字段 $this->SplitTitles = array(); if ($this->SplitPageField != '' && $GLOBALS['cfg_arcsptitle'] = 'Y' && isset($this->Fields[$this->SplitPageField]) ) { $this->SplitFields = explode("#p#", $this->Fields[$this->SplitPageField]); $i = 1; foreach ($this->SplitFields as $k => $v) { $tmpv = cn_substr($v, 50); $pos = strpos($tmpv, '#e#'); if ($pos > 0) { $st = trim(cn_substr($tmpv, $pos)); if ($st == "" || $st == "副标题" || $st == "分页标题") { $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v); continue; } else { $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v); $this->SplitTitles[$k] = $st; } } else { continue; } $i++; } $this->TotalPage = count($this->SplitFields); $this->Fields['totalpage'] = $this->TotalPage; } //处理默认缩略图等 if (isset($this->Fields['litpic'])) { if ($this->Fields['litpic'] == '-' || $this->Fields['litpic'] == '') { $this->Fields['litpic'] = $GLOBALS['cfg_cmspath'] . '/static/defaultpic.jpg'; } if (!preg_match("#^http:\/\/#i", $this->Fields['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') { $this->Fields['litpic'] = $GLOBALS['cfg_mainsite'] . $this->Fields['litpic']; } $this->Fields['picname'] = $this->Fields['litpic']; //模板里直接使用{dede:field name='image'/}获取缩略图 $this->Fields['image'] = (!preg_match('/jpg|gif|png/i', $this->Fields['picname']) ? '' : ""); } // 处理投票选项 if (isset($this->Fields['voteid']) && !empty($this->Fields['voteid'])) { $this->Fields['vote'] = ''; $voteid = $this->Fields['voteid']; $this->Fields['vote'] = ""; if ($GLOBALS['cfg_multi_site'] == 'Y') { $this->Fields['vote'] = ""; } } if (isset($this->Fields['goodpost']) && isset($this->Fields['badpost'])) { //digg if ($this->Fields['goodpost'] + $this->Fields['badpost'] == 0) { $this->Fields['goodper'] = $this->Fields['badper'] = 0; } else { $this->Fields['goodper'] = number_format($this->Fields['goodpost'] / ($this->Fields['goodpost'] + $this->Fields['badpost']), 3) * 100; $this->Fields['badper'] = 100 - $this->Fields['goodper']; } } } //获得当前字段参数 function GetCurTag($fieldname) { if (!isset($this->dtp->CTags)) { return ''; } foreach ($this->dtp->CTags as $ctag) { if ($ctag->GetTagName() == 'field' && $ctag->GetAtt('name') == $fieldname) { return $ctag; } else { continue; } } return ''; } /** * 生成静态HTML * * @access public * @param int $isremote 是否远程 * @return string */ function MakeHtml($isremote = 0) { global $fileFirst, $cfg_basehost; if ($this->IsError) { return ''; } $this->Fields["displaytype"] = "st"; //预编译$th $this->LoadTemplet(); $this->ParAddTable(); $this->ParseTempletsFirst(); $this->Fields['senddate'] = empty($this->Fields['senddate']) ? '' : $this->Fields['senddate']; $this->Fields['title'] = empty($this->Fields['title']) ? '' : $this->Fields['title']; $this->Fields['arcrank'] = empty($this->Fields['arcrank']) ? 0 : $this->Fields['arcrank']; $this->Fields['ismake'] = empty($this->Fields['ismake']) ? 0 : $this->Fields['ismake']; $this->Fields['money'] = empty($this->Fields['money']) ? 0 : $this->Fields['money']; $this->Fields['filename'] = empty($this->Fields['filename']) ? '' : $this->Fields['filename']; //分析要创建的文件名称 $filename = GetFileNewName( $this->ArcID, $this->Fields['typeid'], $this->Fields['senddate'], $this->Fields['title'], $this->Fields['ismake'], $this->Fields['arcrank'], $this->TypeLink->TypeInfos['namerule'], $this->TypeLink->TypeInfos['typedir'], $this->Fields['money'], $this->Fields['filename'] ); $filenames = explode(".", $filename); $this->ShortName = $filenames[count($filenames) - 1]; if ($this->ShortName == '') $this->ShortName = 'html'; $fileFirst = preg_replace("/\." . $this->ShortName . "$/i", "", $filename); $this->Fields['namehand'] = basename($fileFirst); $filenames = explode("/", $filename); $this->NameFirst = preg_replace("/\." . $this->ShortName . "$/i", "", $filenames[count($filenames) - 1]); if ($this->NameFirst == '') { $this->NameFirst = $this->arcID; } //获得当前文档的全名 $filenameFull = GetFileUrl( $this->ArcID, $this->Fields['typeid'], $this->Fields["senddate"], $this->Fields["title"], $this->Fields["ismake"], $this->Fields["arcrank"], $this->TypeLink->TypeInfos['namerule'], $this->TypeLink->TypeInfos['typedir'], $this->Fields["money"], $this->Fields['filename'], $this->TypeLink->TypeInfos['moresite'], $this->TypeLink->TypeInfos['siteurl'], $this->TypeLink->TypeInfos['sitepath'] ); $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull; //对于已设置不生成HTML的文章直接返回网址 if ( $this->Fields['ismake'] == -1 || $this->Fields['arcrank'] != 0 || $this->Fields['money'] > 0 || ($this->Fields['typeid'] == 0 && $this->Fields['channel'] != -1) ) { return $this->GetTrueUrl($filename); } //循环生成HTML文件 else { $seoUrls = array(); for ($i = 1; $i <= $this->TotalPage; $i++) { if ($this->TotalPage > 1) { $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']); if ($i > 1) $this->Fields['title'] = $this->Fields['tmptitle'] . "($i)"; } if ($i > 1) { $TRUEfilename = $this->GetTruePath() . $fileFirst . "_" . $i . "." . $this->ShortName; $URLFilename = $fileFirst . "_" . $i . "." . $this->ShortName; } else { $TRUEfilename = $this->GetTruePath() . $filename; $URLFilename = $filename; } $seoUrls = array_merge($seoUrls, array($cfg_basehost . $URLFilename)); $this->ParseDMFields($i, 1); $this->dtp->SaveTo($TRUEfilename); } } $this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='" . $this->ArcID . "'"); return $this->GetTrueUrl($filename); } /** * 获得真实连接路径 * * @access public * @param string $nurl 连接 * @return string */ function GetTrueUrl($nurl) { return GetFileUrl( $this->Fields['id'], $this->Fields['typeid'], $this->Fields['senddate'], $this->Fields['title'], $this->Fields['ismake'], $this->Fields['arcrank'], $this->TypeLink->TypeInfos['namerule'], $this->TypeLink->TypeInfos['typedir'], $this->Fields['money'], $this->Fields['filename'], $this->TypeLink->TypeInfos['moresite'], $this->TypeLink->TypeInfos['siteurl'], $this->TypeLink->TypeInfos['sitepath'] ); } /** * 获得站点的真实根路径 * * @access public * @return string */ function GetTruePath() { $TRUEpath = $GLOBALS["cfg_basedir"]; return $TRUEpath; } /** * 获得指定键值的字段 * * @access public * @param string $fname 键名称 * @param object $ctag 标记 * @return string */ function GetField($fname, $ctag) { //所有Field数组 OR 普通Field if ($fname == 'array') { return $this->Fields; } //指定了ID的节点 else if ($ctag->GetAtt('noteid') != '') { if (isset($this->Fields[$fname . '_' . $ctag->GetAtt('noteid')])) { return $this->Fields[$fname . '_' . $ctag->GetAtt('noteid')]; } } //指定了type的节点 else if ($ctag->GetAtt('type') != '') { if (isset($this->Fields[$fname . '_' . $ctag->GetAtt('type')])) { return $this->Fields[$fname . '_' . $ctag->GetAtt('type')]; } } else if (isset($this->Fields[$fname])) { return $this->Fields[$fname]; } return ''; } /** * 获得模板文件位置 * * @access public * @return string */ function GetTempletFile() { global $cfg_basedir, $cfg_templets_dir, $cfg_df_style; $cid = $this->ChannelUnit->ChannelInfos['nid']; if (!empty($this->Fields['templet'])) { $filetag = MfTemplet($this->Fields['templet']); if (!preg_match("#\/#", $filetag)) $filetag = $GLOBALS['cfg_df_style'] . '/' . $filetag; } else { $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]); } $tid = $this->Fields['typeid']; $filetag = str_replace('{cid}', $cid, $filetag); $filetag = str_replace('{tid}', $tid, $filetag); $tmpfile = $cfg_basedir . $cfg_templets_dir . '/' . $filetag; if ($cid == 'spec') { if (!empty($this->Fields['templet'])) { $tmpfile = $cfg_basedir . $cfg_templets_dir . '/' . $filetag; } else { $tmpfile = $cfg_basedir . $cfg_templets_dir . "/{$cfg_df_style}/article_spec.htm"; } } if (defined('DEDEMOB')) { $tmpfile = str_replace('.htm', '_m.htm', $tmpfile); } if (!file_exists($tmpfile)) { $tmpfile = $cfg_basedir . $cfg_templets_dir . "/{$cfg_df_style}/" . ($cid == 'spec' ? 'article_spec.htm' : 'article_default.htm'); if (defined('DEDEMOB')) { $tmpfile = str_replace('.htm', '_m.htm', $tmpfile); } } if (!preg_match("#.htm$#", $tmpfile)) return FALSE; return $tmpfile; } /** * 动态输出结果 * * @access public * @return void */ function display() { global $htmltype; if ($this->IsError) { return ''; } $this->Fields["displaytype"] = "dm"; if ($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"] . "({$this->NowPage})"; //预编译 $this->LoadTemplet(); $this->ParAddTable(); $this->ParseTempletsFirst(); //跳转网址 $this->Fields['flag'] = empty($this->Fields['flag']) ? "" : $this->Fields['flag']; if (preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '') { if ($GLOBALS['cfg_jump_once'] == 'N') { $pageHtml = "\r\n
\r\n\r\n