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

飘逸的风13年前 (2012-11-22)程序7716
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判断一个gif图片是不是动画

01 <?php 02 function IsAnimatedGif($filename) 03 { 04  &...

MemCache安装使用

Windows下的Memcache安装: 1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached 2. 在终端(也即cmd命令界面)下输入 ‘c:\me...

ECShop仿淘宝商品详细页 实现尺码颜色关联显示库存

ECShop仿淘宝商品详细页 实现尺码颜色关联显示库存

  ecshop服装商城很多都十分需要一个颜色尺码的功能,其实在淘宝,凡客上都类似的功能,客户在下单时选容易选择相应的颜色尺码,其实ecshop要实现这样的功能并不难,因为ecshop是开源免费的。...

ecshop搜索热门关键字的调用

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

可以让PHP编程事半功倍的类库

可以让PHP编程事半功倍的类库

在用php开发网站的时候,使用面向对象的方法确实可以提高代码复用率,减少代码冗余。而对初学者更友好的是,PHP开发网站所需要的大部分类库,网上都有十分优秀的类库存在了。作为一个程序猿当然不能重复制造轮...

一些需要禁用的PHP危险函数

phpinfo() 功能描述:输出 PHP 环境信息以及相关的模块、WEB 环境等信息。 危险等级:中 passthru() 功能描述:允许执行一个外部程序并回显输出,类似于 exec()。...

评论列表

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

很好,谢谢分享!

发表评论

访客

看不清,换一张

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