Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file BitSmarty.php

Documentation is available at BitSmarty.php

  1. <?php
  2. /**
  3.  * Smarty Library Inteface Class
  4.  *
  5.  * @package Smarty
  6.  * @version $Header: /cvsroot/bitweaver/_bit_kernel/BitSmarty.php,v 1.15 2006/10/13 09:22:47 lsces Exp $
  7.  *
  8.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  9.  *  All Rights Reserved. See copyright.txt for details and a complete list of authors.
  10.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  11.  */
  12.  
  13. /**
  14.  * required setup
  15.  */
  16. iffile_existsUTIL_PKG_PATH.'smarty/libs/Smarty.class.php' ) ) {
  17.     // set SMARTY_DIR that we have the absolute path
  18.     define'SMARTY_DIR'UTIL_PKG_PATH.'smarty/libs/' );
  19.     // If we have smarty in our kernel, use that.
  20.     $smartyIncFile SMARTY_DIR 'Smarty.class.php';
  21. else {
  22.     // assume it is in php's global include_path
  23. // don't set SMARTY_DIR if we are not using the bw copy
  24.     
  25.     $smartyIncFile 'Smarty.class.php';
  26. }
  27.  
  28. require_once($smartyIncFile);
  29.  
  30. /**
  31.  * PermissionCheck
  32.  *
  33.  * @package kernel
  34.  */
  35. class PermissionCheck {
  36.     function check$perm {
  37.         global $gBitUser;
  38.         return $gBitUser->hasPermission$perm );
  39.     }
  40. }
  41.  
  42. /**
  43.  * BitSmarty
  44.  *
  45.  * @package kernel
  46.  */
  47. class BitSmarty extends Smarty
  48. {
  49.     function BitSmarty()
  50.     {
  51.         global $smarty_force_compile;
  52.         Smarty::Smarty();
  53.         $this->mCompileRsrc NULL;
  54.         $this->config_dir "configs/";
  55.         // $this->caching = false;
  56.         $this->force_compile $smarty_force_compile;
  57.         $this->assign('app_name''bitweaver');
  58.         $this->plugins_dir array_merge(array(KERNEL_PKG_PATH "smarty_bit")$this->plugins_dir);
  59.         $this->register_prefilter("add_link_ticket");
  60.  
  61.         global $permCheck;
  62.         $permCheck new PermissionCheck();
  63.         $this->register_object('perm'$permCheckarray()truearray('autoComplete'));
  64.         $this->assign_by_ref'perm'$permCheck );
  65.     }
  66.  
  67.     function _smarty_include ($pParams)
  68.     {
  69.         ifdefined'TEMPLATE_DEBUG' && TEMPLATE_DEBUG == TRUE {
  70.             echo "\n<!-- - - - {$pParams['smarty_include_tpl_file']} - - - -->\n";
  71.         }
  72.         $this->includeSiblingPhp$pParams['smarty_include_tpl_file');
  73.         return parent::_smarty_include ($pParams);
  74.     }
  75.  
  76.     function _compile_resource($resource_name$compile_path)
  77.     {
  78.         // this is used when auto-storing untranslated master strings
  79.         $this->mCompileRsrc $resource_name;
  80.         return parent::_compile_resource($resource_name$compile_path);
  81.     }
  82.  
  83.     function fetch($_smarty_tpl_file$_smarty_cache_id null$_smarty_compile_id null$_smarty_display false)
  84.     {
  85.         global $gBitSystem;
  86.         $this->verifyCompileDir();
  87.         $_smarty_cache_id $_smarty_cache_id;
  88.         $_smarty_compile_id $_smarty_compile_id;
  89.         ifstrpos$_smarty_tpl_file':' ) ) {
  90.             list($resource$locationsplit(':'$_smarty_tpl_file);
  91.             if ($resource == 'bitpackage'{
  92.                 list($package$templatesplit('/'$location);
  93.                 // exclude temp, as it contains nexus menus
  94.                 if!$gBitSystem->isPackageActive$package && $package != 'temp' {
  95.                     return '';
  96.                 }
  97.             }
  98.         }
  99.  
  100.         // the PHP sibling file needs to be included here, before the fetch so caching works properly
  101.         $this->includeSiblingPhp($_smarty_tpl_file);
  102.         ifdefined'TEMPLATE_DEBUG' && TEMPLATE_DEBUG == TRUE {
  103.             echo "\n<!-- - - - {$_smarty_tpl_file} - - - -->\n";
  104.         }
  105.         return parent::fetch($_smarty_tpl_file$_smarty_cache_id$_smarty_compile_id$_smarty_display);
  106.     }
  107.     // {{{ includeSiblingPhp
  108.     
  109.     /**
  110.     * THE method to invoke if you want to be sure a tpl's sibling php file gets included if it exists. This
  111.     * should not need to be invoked from anywhere except within this class
  112.     *
  113.     * @param string $pRsrc resource of the template, should be of the form "bitpackage:<packagename>/<templatename>"
  114.     * @return TRUE if a sibling php file was included
  115.     * @access private
  116.     */
  117.     function includeSiblingPhp($pRsrc)
  118.     {
  119.         $ret false;
  120.         if (strpos($pRsrc':'))
  121.         {
  122.             list($resource$locationsplit(':'$pRsrc);
  123.             if ($resource == 'bitpackage')
  124.             {
  125.                 list($package$templatesplit('/'$location);
  126.                 // print "( $resource, $location )  ( $package, $template )<br/>";
  127.                 $subdir preg_match('/mod_/'$template'modules' 'templates';
  128.                 if (preg_match('/mod_/'$template|| preg_match('/center_/'$template))
  129.                 {
  130.                     global $gBitSystem;
  131.                     $path $gBitSystem->mPackages[$package]['path'];
  132.                     $modPhpFile str_replace('.tpl''.php'"$path$subdir/$template");
  133.                     if (file_exists($modPhpFile))
  134.                     {
  135.                         global $gBitSmarty$gBitSystem$gBitUser$user$smarty$gQueryUserId$module_rows$module_params$module_column;
  136.                         // Module Params were passed in from the template, like kernel/dynamic.tpl
  137.                         if$moduleParams $this->get_template_vars('moduleParams') ) {
  138.                             ifstrpostrim$moduleParams['params')' ' ) ) {
  139.                                 $module_params parse_xml_attributes$moduleParams['params');
  140.                             else {
  141.                                 parse_str$moduleParams["params"]$module_params );
  142.                             }
  143.                             $module_title isset$moduleParams['title'tra$moduleParams['title'isset$module_params['title'$module_params['title'NULL ) );
  144.                             $module_rows $moduleParams['module_rows'];
  145.                         }
  146.                         include($modPhpFile);
  147.                         $ret true;
  148.                     }
  149.                 }
  150.             }
  151.         }
  152.     }
  153.  
  154.     function verifyCompileDir()
  155.     {
  156.         global $gBitSystem$gBitLanguage$bitdomain;
  157.         if (!defined("TEMP_PKG_PATH")) {
  158.             $temp BIT_ROOT_PATH "temp/";
  159.         else {
  160.             $temp TEMP_PKG_PATH;
  161.         }
  162.         $style $gBitSystem->getStyle();
  163.         $endPath "$bitdomain/$style/".$gBitLanguage->mLanguage;
  164.  
  165.         // Compile directory
  166.         $compDir $temp "templates_c/$endPath";
  167.         $compDir str_replace('//''/'$compDir);
  168.         $compDir clean_file_path($compDir);
  169.         mkdir_p($compDir);
  170.         $this->compile_dir $compDir;
  171.  
  172.         // Cache directory
  173.         $cacheDir $temp "cache/$endPath";
  174.         $cacheDir str_replace('//''/'$cacheDir);
  175.         $cacheDir clean_file_path($cacheDir);;
  176.         mkdir_p($cacheDir);
  177.         $this->cache_dir $cacheDir;
  178.  
  179.     }
  180. }
  181. // This will insert a ticket on all template URL's that have GET parameters.
  182. function add_link_ticket($tpl_source&$smarty{
  183.     global $gBitUser;
  184.  
  185.     if is_object$gBitUser && $gBitUser->isValid() ) {
  186.         $from '#href="(.*PKG_URL.*php)\?(.*)&(.*)"#i';
  187.         $to 'href="\\1?\\2&amp;tk={$gBitUser->mTicket}&\\3"';
  188.         $tpl_source preg_replace$from$to$tpl_source );
  189.         $from '#<form([^>]*)>#i';
  190.         $to '<form\\1><input type="hidden" name="tk" value="{$gBitUser->mTicket}" />';
  191.         $tpl_source preg_replace$from$to$tpl_source );
  192.         ifstrpos$tpl_source'{form}' ) ) {
  193.             $tpl_source str_replace'{form}''{form}<input type="hidden" name="tk" value="{$gBitUser->mTicket}" />'$tpl_source );
  194.         elseifstrpos$tpl_source'{form ' ) ) {
  195.             $from '#\{form(\}| [^\}]*)\}#i';
  196.             $to '{form\\1}<input type="hidden" name="tk" value="{$gBitUser->mTicket}" />';
  197.             $tpl_source preg_replace$from$to$tpl_source );
  198.         }
  199.     }
  200.  
  201.     return $tpl_source;
  202. }
  203.  
  204. ?>

Documentation generated on Thu, 15 Feb 2007 20:32:07 +0000 by phpDocumentor 1.3.0