用户名 密码 记住我 还未注册?

xoops smarty探索 [技术论坛 - 主题综合]

XOOPS China 讨论区 > XOOPS Theme (主题) > 主题综合 > xoops smarty探索

正在浏览:   1 名游客



 到底部   前一个主题   下一个主题  [无发表权] 请登录或者注册



xoops smarty探索
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
网站管理员
帖子: 513 | 精华: 3
等级: 20; EXP: 90
HP: 0 / 497
MP: 171 / 8097
离线
  xoops2.3装了有段时间了,但一直没有时间去用,xoops2.3感觉最大的改进,就是第一次见D.J的时候,D.J对我强调的"xoops将对smarty进行较深的改动"。可惜当时听起来迷迷糊糊的,只好似懂非懂的恩啊着。去年五月正是xoops2.3的开发的活跃期,相信当时大家都翘首以待,准备大干一场。不过世事难料,一载已过,xoops终于又重新步入了正规。
  废话少说,首先得从xoops繁体社区的一个帖子在说起。brent兄提出如何在缓存情况及时更新某些页面,俺们心想“独乐乐?与众乐”,霹雳啪啦的贴了些代码。可是我的那些代码是与绿野的manage模组精密结合的,估计很难看懂。而偶本人则在繁体字的夹击下头晕脑胀,很不负责任的拍拍屁股跑走了。
  现在得开始说些正经的。大家看下xoops2.016 根目录/class/smarty/xoops_plugins 目录下,对应xoops23的XOOPS/System/Frameworks/OutputRendering/Opal.xofrm/Smarty.xoobj/plugins目录中,对比下以resource开头的。 在xoops2.016中,只有1个resource.db.php,而xoops23包括resource.db.php resource.xotpl.php。所以xoops23处理的theme不仅仅只包括数据库里面,还包括以.xotpl的文件的theme.再看以compiler开始的文件在http://xoops.org.cn/modules/newbb/vie ... t_id=46638#forumpost46638 
D.J老大提出直接在theme里面

<a href="<{xoAppUrl /}>"> <img src="<{xoImgUrl img/}>logo_<{$xoops_langcode|@strtolower}>.gif" alt="" border="0" /> </a>
可以直接运用

<{xoAppUrl /}><{xoImgUrl img/}>
。那么它们是如何编译的呢?答案就在compiler.xoAppUrl.php,compiler.xoImgUrl.php里面,再看下compiler 剩下的。compiler.foreachq.php,compiler.includeq.php,于是我们就可以用<{foreachq}>代替<{foreach}>用<{includeq}>代替<{include}>。function.xoInboxCount.php,<{xoInboxCount}>代表了我们的短消息数。那么,xoops是如何编译这些标志的呢?看下xoops2.016中的。根目录/class/smarty/Smarty_Compiler.class.php中755行,xoops23中的 XOOPS/System/Frameworks/OutputRendering/Opal.xofrm/Smarty.xoobj/compiler.php中218行,_compile_compiler_tag函数。
_compile_compiler_tag就是编译这些标志的。

if (isset($this->_plugins['function'][$tag_command])) {//这是通过smarty的register_function注册的函数
            
$found true;
            
$plugin_func $this->_plugins['function'][$tag_command][0];
            if (!
is_callable($plugin_func)) {
                
$message "custom function '$tag_command' is not implemented";
                
$have_function false;
            }
        }
   else if (
$plugin_file $this->_get_plugin_filepath('function'$tag_command)) {//这是刚才提到的放在plugins 目录下smarty自动编译的函数
            
$found true;
            include_once 
$plugin_file;
            
$plugin_func 'smarty_function_' $tag_command;
            if (!
function_exists($plugin_func)) {
                
$message "plugin function $plugin_func() not found in $plugin_filen";
                
$have_function false;
            } else {
                
$this->_plugins['function'][$tag_command] = array($plugin_funcnullnullnulltrue);//因为要求$this->_plugins['function'][$tag_command][4]为false smarty才对这部分不做缓存所以放在plugins 目录下是不能实现部分缓存的。
            
}
        }

但是如果我想在把某一个页面大部分都做cache了,但只有某一部分不做cache,比如文章的点击数,其他都做缓存,这样smarty可以实现吗?回答是肯定的。我们还看上述的_compile_compiler_tag函数中的。
$_cacheable_state = $this->_push_cacheable_state('function', $tag_command);对应找到

function _push_cacheable_state($type$name) {
        
$_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
        if (
$_cacheable
            
|| 0<$this->_cacheable_state++) return '';
        if (!isset(
$this->_cache_serial)) $this->_cache_serial md5(uniqid('Smarty'));
        
$_ret 'if ($this->caching && !$this->_cache_including) { echo '{nocache:'
            . $this->_cache_serial . '
#' . $this->_nocache_count
            
'}'; };';
        return $_ret;
    }

看上述代码要求_cacheable为false,反推$this->_plugins[$type][$name][4]为false。通过plugins 目录下是不能对某部分做缓存的。所以我们必须通过register_function例如 $xTheme->tplEngine ->register_function("userkarma","encashi_userkarma",false);
"userkarma"是_plugins['function']['userkarma'],encashi_userkarma是具体某个已定义的函数。后面如果想针对此部分进行非cache,必须为false。

  我们在来看下xoops2.3的部分内容吧。首先看下根目录/modules/sysutils/sitemanager/templates/panel-list.xotpl(截取部分内容)

([xoLoadExtension xos_pyro])
([
xoWidget bundleId='xos_pyro_TreeWidget' elementId='panels-tree' treeData=$mgr_panelsTree.children])

<
div id="manager_panel-view">
([if 
$mgr_path])
    ([
xoWidget bundleId='xos_pyro_Breadcrumbs' 
        
sourceData=$mgr_panelsTree
        sourceType
='tree'
        
nameKey='name'
        
childrenKey='children'
        
linkKey='link'
        
currentPath=$mgr_path
    
])
([/if])

xoops23主要支持的是([])格式,但是也支持<{}>。这点我们可以看下XOOPS/System/Frameworks/OutputRendering/Opal.xofrm/Smarty.xoobj/smarty.php
中的163行filterOldTemplates找到答案。xoLoadExtension我们在79行$this->register_compiler_function( 'xoLoadExtension', array( &$this, 'loadExtension' ) );也可以找到答案。
xoWidget我们在plugins 目录下找到答案。其实例如会出现([xoForm $form])xoForm之类的,这些定义的话应该在XOOPS/System/Frameworks/UserExperience/Pyro.xofrm/pyro.php 50行extendCompiler函数中定义

function extendCompiler( &$tplEngine, &$compiler ) {
$tplEngine->register_compiler_function'xoPyroFieldsTemplate', array( &$this'setFieldsTemplate' ) );
        
$tplEngine->register_compiler_function'xoForm', array( &$this'compileForm' ) );
        
$tplEngine->register_compiler_function'/xoForm', array( &$this'compileForm' ) );
        foreach ( 
$this->plugins as $extName => $bundleId ) {
            
$tplEngine->register_compiler_function$extName, array( &$this'compilerPlugin' ) );
        }
        
$code '$this->loadRuntimeExtension( "xos_pyro" );';
    }

呵呵,我目前也只了解这么多了。


2007-6-19

2007/6/19 22:54
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
网站管理员
注册日期:
2005/2/24 15:17
所属群组:
网站管理员
注册会员
技术文档组
帖子: 723 | 精华: 32
等级: 24; EXP: 37
HP: 0 / 584
MP: 241 / 9807
离线
分析得不错,看来是下了不少功夫呢。

2007/6/20 0:20
_________________
nightcat 小站
不同时刻的访问,有不同的惊喜 小站已经改版,欢迎有事没事来踩踩,内容丰富不少,希望你有喜欢的,

Gtalk:[email protected]
MSN:[email protected]
QQ:1043931
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2006/11/30 20:48
来自 beijing
所属群组:
网站管理员
注册会员
Dev+Hack
资料整理组
帖子: 1106 | 精华: 16
等级: 29; EXP: 19
HP: 140 / 704
MP: 368 / 8200
离线
哪下载的2.3?

2007/6/21 9:56
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
网站管理员
帖子: 513 | 精华: 3
等级: 20; EXP: 90
HP: 0 / 497
MP: 171 / 8097
离线

2007/6/21 9:58
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2006/11/30 20:48
来自 beijing
所属群组:
网站管理员
注册会员
Dev+Hack
资料整理组
帖子: 1106 | 精华: 16
等级: 29; EXP: 19
HP: 140 / 704
MP: 368 / 8200
离线
安装失败!

2007/7/3 7:25
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
网站管理员
帖子: 513 | 精华: 3
等级: 20; EXP: 90
HP: 0 / 497
MP: 171 / 8097
离线
因为不是正式版,安装还是有些问题,需要调试解决.
在mainfile.dist.php里面先定义下
define('XOOPS_PATH' --xoops目录
define('XOOPS_VAR_PATH'--XOOPS-data目录

执行下upgrade 目录下的sql语句

2007/7/3 8:17
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2004/7/8 9:57
所属群组:
注册会员
ComSupp
帖子: 165 | 精华: 4
等级: 11; EXP: 90
HP: 0 / 272
MP: 55 / 5081
离线
2.3,好遥远啊

2007/7/4 14:37
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2006/11/30 20:48
来自 beijing
所属群组:
网站管理员
注册会员
Dev+Hack
资料整理组
帖子: 1106 | 精华: 16
等级: 29; EXP: 19
HP: 140 / 704
MP: 368 / 8200
离线
看了一下2.3的themes,都快晕菜了。
zetareticuli还有这个主题,乱死。
真想不到2.3发布的时候themes的代码是什么样子。

2007/7/4 23:05
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: xoops smarty探索
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
网站管理员
帖子: 513 | 精华: 3
等级: 20; EXP: 90
HP: 0 / 497
MP: 171 / 8097
离线
2.3设计好是优秀,就是现在应该还是很先进的。对2.3的themes方式的理解,写的这些应该还有些许作用。

2007/7/27 9:40
工具箱 短消息 Email PDF 书签 打印 举报 回顶部



  [无发表权] 请登录或者注册


不可查看帖子。
不可发帖。
不可回复。
不可编辑自己的帖子。
不可删除自己的帖子。
不可发起投票调查。
不可在投票调查中投票。
不可上传附件。
不可不经审核直接发帖。
不可使用主题类别。
不可使用HTML语法。
不可使用签名档。

[高级搜索]