织梦DedeCMS实现火车头采集后自动生成首页、栏目页与上下篇

使用火车头采集器采集数据并发布到织梦DedeCMS后,系统默认不会自动生成首页、上下篇以及栏目页的静态文件。通过添加自定义代码,可以实现在发布文档时自动触发静态页面生成,提升网站更新效率。

实现教程

打开织梦系统文件 /dede/inc/inc_archives_functions.php,在文件最下方添加以下三个函数。

/*火车头采集自动更新主页*/
function MakeIndex()
{
global $dsql,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
    require_once(DEDEINC.'/arc.partview.class.php');
    $envs = $_sys_globals = array();
    $envs['aid'] = 0;
    $pv = new PartView();
    $row = $pv->dsql->GetOne('SELECT * FROM `dede_homepageset`');
    $templet = str_replace("{style}", $cfg_df_style, $row['templet']);
    $homeFile = dirname(__FILE__).'/../'.$row['position'];
    $homeFile = str_replace("//", "/", str_replace("\\", "/", $homeFile));
    $fp = fopen($homeFile, 'w') or die("无法更新网站主页到:$homeFile 位置");
    fclose($fp);
    $tpl = $cfg_basedir.$cfg_templets_dir.'/'.$templet;
    if(!file_exists($tpl))
    {
        $tpl = $cfg_basedir.$cfg_templets_dir.'/default/index.htm';
        if(!file_exists($tpl)) exit("无法找到主页模板:$tpl ");
    }
    $GLOBALS['_arclistEnv'] = 'index';
    $pv->SetTemplet($tpl);
    $pv->SaveToHtml($homeFile);
    $pv->Close();
}

/*火车头采集自动更新栏目*/
function MakeParentType($typeid)
{
global $dsql;
$typediarr = array();
array_push($typediarr,$typeid);
$row3 = $dsql->GetOne("Select reid,topid From `dede_arctype` where id=".$typeid);
if(!in_array($row3['reid'],$typediarr) and $row3['reid']!=0) array_push($typediarr,$row3['reid']);
if(!in_array($row3['topid'],$typediarr) and $row3['topid']!=0) array_push($typediarr,$row3['topid']);
require_once(DEDEDATA."/cache/inc_catalog_base.inc");
require_once(DEDEINC."/channelunit.func.php");
require_once(DEDEINC."/arc.listview.class.php");
foreach($typediarr as $typeid)
{
$lv = new ListView($typeid);
$lv->MakeHtml(1,$maxpagesize);
}
}

/*火车头采集自动更新上下篇*/
function MakePreNext($aid,$typeid)
{
global $dsql;
    require_once(DEDEINC.'/arc.archives.class.php');
    $aid = intval($aid);
    $preRow =  $dsql->GetOne("SELECT id FROM `dede_arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' ORDER BY id DESC");
    $nextRow = $dsql->GetOne("SELECT id FROM `dede_arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' ORDER BY id ASC");
    if(is_array($preRow))
    {
        $envs['aid'] = $preRow['id'];
        $arc = new Archives($preRow['id']);
        $arc->MakeHtml();
    }
    if(is_array($nextRow))
    {
        $envs['aid'] = $nextRow['id'];
        $arc = new Archives($nextRow['id']);
        $arc->MakeHtml();
    }
}

继续在该文件中找到以下代码:

return $revalue;

return $revalue; 的上面加入以下三行代码:

MakePreNext($arcID,$typeid);
MakeIndex();
MakeParentType($typeid);

添加完成后的效果如下图所示:

完成以上修改后,无论使用火车头免登录接口还是WEB发布模块,无论是普通文章模型、图集模型还是软件模型,都可以在发布文档时自动生成相关的静态文件,包括首页、栏目页以及上下篇页面。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。