home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / template.php < prev    next >
Encoding:
PHP Script  |  2007-09-09  |  6.6 KB  |  175 lines

  1. <?php
  2. // $Id: template.php 1029 2007-09-09 03:49:25Z phppp $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu)                                          //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31.  
  32. if (!defined('SMARTY_DIR')) {
  33.     exit();
  34. }
  35. /**
  36.  * Base class: Smarty template engine
  37.  */
  38. require_once SMARTY_DIR.'Smarty.class.php';
  39.  
  40. /**
  41.  * Template engine
  42.  *
  43.  * @package        kernel
  44.  * @subpackage    core
  45.  *
  46.  * @author        Kazumi Ono     <onokazu@xoops.org>
  47.  * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org
  48.  */
  49. class XoopsTpl extends Smarty {
  50.  
  51.     var $left_delimiter = '<{';
  52.     var $right_delimiter = '}>';
  53.  
  54.     var $template_dir = XOOPS_THEME_PATH;
  55.     var $cache_dir = XOOPS_CACHE_PATH;
  56.     var $compile_dir = XOOPS_COMPILE_PATH;
  57.  
  58.     function XoopsTpl() {
  59.         global $xoopsConfig;
  60.  
  61.         $this->compile_id = $xoopsConfig['template_set'] . '-' . $xoopsConfig['theme_set'];
  62.         $this->_compile_id = $this->compile_id;
  63.         $this->compile_check = ( $xoopsConfig['theme_fromfile'] == 1 );
  64.         $this->plugins_dir = array(
  65.             XOOPS_ROOT_PATH . '/class/smarty/xoops_plugins',
  66.             XOOPS_ROOT_PATH . '/class/smarty/plugins',
  67.         );
  68.         if ( $xoopsConfig['debug_mode'] ) {
  69.             $this->debugging_ctrl = 'URL';
  70.             if ( $xoopsConfig['debug_mode'] == 3 ) {
  71.                 $this->debugging = true;
  72.             }
  73.         }
  74.         $this->Smarty();
  75.  
  76.         $this->assign( array(
  77.             'xoops_url' => XOOPS_URL,
  78.             'xoops_rootpath' => XOOPS_ROOT_PATH,
  79.             'xoops_langcode' => _LANGCODE,
  80.             'xoops_charset' => _CHARSET,
  81.             'xoops_version' => XOOPS_VERSION,
  82.             'xoops_upload_url' => XOOPS_UPLOAD_URL
  83.         ) );
  84.     }
  85.  
  86.     /**
  87.      * Renders output from template data
  88.      *
  89.      * @param   string  $data        The template to render
  90.      * @param    bool    $display    If rendered text should be output or returned
  91.      * @return  string  Rendered output if $display was false
  92.      **/
  93.     function fetchFromData( $tplSource, $display = false, $vars = null ) {
  94.         if ( !function_exists('smarty_function_eval') ) {
  95.             require_once SMARTY_DIR . '/plugins/function.eval.php';
  96.         }
  97.         if ( isset( $vars ) ) {
  98.             $oldVars = $this->_tpl_vars;
  99.             $this->assign( $vars );
  100.             $out = smarty_function_eval( array('var' => $tplSource), $this );
  101.             $this->_tpl_vars = $oldVars;
  102.             return $out;
  103.         }
  104.         return smarty_function_eval( array('var' => $tplSource), $this );
  105.     }
  106.  
  107.     function touch( $resourceName ) {
  108.         $isForced = $this->force_compile;
  109.         $this->force_compile = true;
  110.         $this->clear_cache( $resourceName );
  111.         $result = $this->_compile_resource( $resourceName, $this->_get_compile_path( $resourceName ) );
  112.         $this->force_compile = $isForced;
  113.         return $result;
  114.     }
  115.  
  116.     /**
  117.      * @deprecated DO NOT USE THESE METHODS, ACCESS THE CORRESPONDING PROPERTIES INSTEAD
  118.      */
  119.     function xoops_setTemplateDir($dirname) {        $this->template_dir = $dirname;            }
  120.     function xoops_getTemplateDir() {                return $this->template_dir;                }
  121.     function xoops_setDebugging($flag=false) {        $this->debugging = is_bool($flag) ? $flag : false;    }
  122.     function xoops_setCaching( $num = 0 ) {            $this->caching = (int)$num;                }
  123.     function xoops_setCompileDir($dirname) {        $this->compile_dir = $dirname;            }
  124.     function xoops_setCacheDir($dirname) {            $this->cache_dir = $dirname;            }
  125.     function xoops_canUpdateFromFile() {            return $this->compile_check;            }
  126.     function xoops_fetchFromData( $data ) {            return $this->fetchFromData( $data );    }
  127.     function xoops_setCacheTime( $num = 0 ) {
  128.         if ( ( $num = (int)$num ) <= 0) {
  129.             $this->caching = 0;
  130.         } else {
  131.             $this->cache_lifetime = $num;
  132.         }
  133.     }
  134. }
  135.  
  136. /**
  137.  * function to update compiled template file in templates_c folder
  138.  *
  139.  * @param   string  $tpl_id
  140.  * @param   boolean $clear_old
  141.  * @return  boolean
  142.  **/
  143. function xoops_template_touch($tpl_id, $clear_old = true) {
  144.     $tplfile_handler =& xoops_gethandler('tplfile');
  145.     $tplfile =& $tplfile_handler->get($tpl_id);
  146.  
  147.     if ( is_object($tplfile) ) {
  148.         $file = $tplfile->getVar( 'tpl_file', 'n' );
  149.         $tpl = new XoopsTpl();
  150.         return $tpl->touch( "db:$file" );
  151.     }
  152.     return false;
  153. }
  154.  
  155. /**
  156.  * Clear the module cache
  157.  *
  158.  * @param   int $mid    Module ID
  159.  * @return
  160.  **/
  161. function xoops_template_clear_module_cache($mid)
  162. {
  163.     $block_arr = XoopsBlock::getByModule($mid);
  164.     $count = count($block_arr);
  165.     if ($count > 0) {
  166.         $xoopsTpl = new XoopsTpl();
  167.         $xoopsTpl->xoops_setCaching(2);
  168.         for ($i = 0; $i < $count; $i++) {
  169.             if ($block_arr[$i]->getVar('template') != '') {
  170.                 $xoopsTpl->clear_cache('db:'.$block_arr[$i]->getVar('template'), 'blk_'.$block_arr[$i]->getVar('bid'));
  171.             }
  172.         }
  173.     }
  174. }
  175. ?>