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

Source for file function.moduleinc.php

Documentation is available at function.moduleinc.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * moduleinc
  10.  * 
  11.  * Usage: add to the body of any .tpl file
  12.  * Example: {inlinemodule file="_custom:custom/my_custom_module" cache_time=600}
  13.  *
  14.  * Note: currently only supports custom modules generated in themes package,
  15.  * could support any module with more work
  16.  *
  17.  * @param array $pParams 
  18.  * @param string $pParams['module_rsrc'] the full name of the template, example: _custom:custom/my_custom_module
  19.  * @param integer $pParams['cache_time'] seconds the template will be cached
  20.  */
  21. function smarty_function_moduleinc($pParams&$gBitSmarty{
  22.     global $gBitSystem$gBitThemes;
  23.  
  24.     // go through some hassle here in consideration of a future day when this handles any module
  25.     list$package$template split(  '/'$pParams['module_rsrc');
  26.  
  27.     if$package == '_custom:custom' {
  28.         global $gBitLanguage;
  29.  
  30.         // We're gonna run our own cache mechanism for user_modules
  31.         // the cache is here to avoid calls to consumming queries,
  32.         // each module is different for each language because of the strings
  33.         $cacheDir TEMP_PKG_PATH.'modules/cache/';
  34.         if!is_dir$cacheDir )) {
  35.             mkdir_p$cacheDir );
  36.         }
  37.         $cachefile $cacheDir.'_custom.'.$gBitLanguage->mLanguage.'.'.$template.'.tpl.cache';
  38.  
  39.         if!empty$pParams["cache_time"&& file_exists$cachefile && !(( $gBitSystem->getUTCTime(filemtime$cachefile )) $pParams["cache_time")) {
  40.             $fp fopen$cachefile"r" );
  41.             $data fread$fpfilesize$cachefile ));
  42.             fclose$fp );
  43.             print$data );
  44.         else {
  45.             if$moduleParams $gBitThemes->getCustomModule$template )) {
  46.                 $moduleParams array_merge$pParams$moduleParams );
  47.                 $gBitSmarty->assign_by_ref'moduleParams'$moduleParams );
  48.                 $data $gBitSmarty->fetch'bitpackage:themes/custom_module.tpl' );
  49.  
  50.                 if!empty$pParams["cache_time") ) {
  51.                     // write to chache file
  52.                     $fp fopen$cachefile"w+" );
  53.                     fwrite$fp$datastrlen$data ));
  54.                     fclose$fp );
  55.                 }
  56.                 print$data );
  57.             }
  58.         }
  59.         unset$data );
  60.     
  61. }

Documentation generated on Wed, 29 Jul 2015 13:56:39 +0000 by phpDocumentor 1.5.0-lsces