ECShop设置模板的原理以及一些模板设置函数说明(个人观点)

飘逸的风14年前 (2012-11-22)程序7997
ECShop设置模板的原理以及一些模板设置函数说明(个人观点)

admin/includes/lib_template.php 一些函数及变量说明

$template_files 可以设置内容的模板。

$page_libs 每个模板允许设置的库项目。

get_template_region() 获得模版文件中的编辑区域及其内容,即TemplateBeginEditable和此标签里面的内容件数组。第三个

参数$lib=true时,同时也获取该编辑区域内所有库项目。

get_editable_libs() 从相应模板xml文件中获得指定模板文件中的可编辑区信息,返回可编辑的库文件数组。此XML文件在模板

目录下,名为libs.xml。

设置模板的页面:admin/template.php

模板语言包:languages/语言/admin/template.php

设置模板的原理:
如果某个模板文件存在region(区域),选择region提交后,库项目会自动移至所选择的区域。

处理代码:

/* 修改模板文件 */
$template_file    = '../themes/' . $curr_template . '/' . $_POST['template_file'] . '.dwt';
$template_content = file_get_contents($template_file);
$template_content = str_replace("\xEF\xBB\xBF", '', $template_content);
$org_regions      = get_template_region($curr_template, $_POST['template_file'].'.dwt', false);

$region_content   = '';
$pattern          = '/(<!--\\s*TemplateBeginEditable\\sname="%s"\\s*-->)(.*?)(<!--\\s*TemplateEndEditable\\s*--

>)/s';
$replacement      = "\\1\n%s\\3";
$lib_template     = "<!-- #BeginLibraryItem \"%s\" -->\n%s\n <!-- #EndLibraryItem -->\n";

foreach ($org_regions AS $region)
{
    $region_content = ''; // 获取当前区域内容
    foreach ($post_regions AS $lib)
    {
        if ($lib['region'] == $region)
        {
            if (!file_exists('../themes/' . $curr_template . $lib['library']))
            {
                continue;
            }
            $lib_content     = file_get_contents('../themes/' . $curr_template . $lib['library']);
            $lib_content     = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']

text\/html;\\scharset=.*["|\']>/i', '', $lib_content);
            $lib_content     = str_replace("\xEF\xBB\xBF", '', $lib_content);
            $region_content .= sprintf($lib_template, $lib['library'], $lib_content);
        }
    }

    /* 替换原来区域内容 */
    $template_content = preg_replace(sprintf($pattern, $region), sprintf($replacement , $region_content), 

$template_content);
}

相关文章

PHP制作安装程序的原理与步骤详细讲解

本文讲解PHP制作安装程序的原理与步骤 1、制作PHP安装程序的原理         PHP程序的安装原理就是将数据库结构和内容导入到相...

文章内链的实现方法

在很多的时候,我在浏览其他的网站发现文章中一写关键词都被加上了链接链向对应的页面,我就在想他们是怎么实现这个功能的?为什么这么做,这么做有什么好处?   当然有什么好处一看便知,无论是从...

php日历的高效写法

标题写的吸引人了些,不过我就觉得是挺高效的,我相信 之前看到过 irlvirus 写的 《php练习代码-日历》,我觉得效率都不是很好。 date()函数结合mktime() 可以得到一切东西...

ecshop搜索热门关键字的调用

码关键字的设定在:后台-商店设置-显示设置--首页搜索的关键词 {if $searchkeywords} {$lang.hot_search} :  {foreach from...

PHP如何设置页面最大执行过期时间

一般在上传较大的附件时,超过30秒会出现网页过期的错误页面,如何处理这个问题呢?以下是处理方法: 1、如果是自己的服务器,可以全局配置:在php.ini 中设置,默认为30秒 max_execut...

10个你可能从未用过的PHP函数

1. sys_getloadavg() sys_getloadavt()可以获得系统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。...

评论列表

李明博客
14年前 (2013-01-17)

很好,谢谢分享!

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。