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

Source for file resource.bitpackage.php

Documentation is available at resource.bitpackage.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * -------------------------------------------------------------
  5.  * File:     resource.bitpackage.php
  6.  * Type:     resource
  7.  * Name:     bitpackage
  8.  * Purpose:  Fetches templates from the correct package
  9.  * -------------------------------------------------------------
  10.  * @package Smarty
  11.  * @subpackage plugins
  12.  */
  13.  
  14. /**
  15.  * Smarty Bitpackage class
  16.  */
  17. class Smarty_Resource_Bitpackage extends Smarty_Resource_Custom {
  18.  
  19.     protected function fetch $pTplName&$pTplSource&$pTplTime {
  20.         $resources $this->getTplLocations$pTplName );
  21.         foreach$resources as $location => $resource {
  22.             iffile_exists$resource )) {
  23.                 $pTplSource file_get_contents$resource );
  24.                 $pTplTime filemtime$resource );
  25.                 return;
  26.             }
  27.         }
  28.     }
  29.  
  30.     /**
  31.      * THE method to invoke if you want to be sure a tpl's sibling php file gets included if it exists. This
  32.      * should not need to be invoked from anywhere except within this class
  33.      *
  34.      * @param string $pFile file to be included, should be of the form "bitpackage:<packagename>/<templatename>"
  35.      * @return TRUE if a sibling php file was included
  36.      * @access private
  37.      */
  38.     public function populate(Smarty_Template_Source $sourceSmarty_Internal_Template $_template=null{
  39.         global $gBitThemes;
  40.         $ret FALSE;
  41.  
  42.         if$siblingPhpFile static::getSiblingPhpFile$source->name ) ) {
  43.             global $gBitSmarty$gBitSystem$gBitUser$gQueryUserId$moduleParams;
  44.             $moduleParams array();
  45.             if!empty$_template->tpl_vars['module_params') ) {
  46.                 // module_params were passed through via the {include},
  47.                 // e.g. {include file="bitpackage:foobar/mod_list_foo.tpl" module_params="user_id=`$gBitUser->mUserId`&sort_mode=created_desc"}
  48.                 $moduleParams['module_params'$gBitThemes->parseString$_template->tpl_vars['module_params']->value );
  49.             elseif!empty$_template->tpl_vars['moduleParams') ) {
  50.                 // Module Params were passed in from the template, like kernel/dynamic.tpl
  51.                 $moduleParams $_template->tpl_vars['moduleParams']->value;
  52.             }
  53.             include$siblingPhpFile );
  54.         }
  55.  
  56.         parent::populate$source$_template );
  57.     }
  58.  
  59.     public static function getSiblingPhpFile$pTplName {
  60.         $ret NULL;
  61.         ifpreg_match('/mod_/'$pTplName || preg_match'/center_/'$pTplName ) ) {
  62.             ifstrpos$pTplName'/' )) {
  63.                 list$package$modFile explode'/'$pTplName );
  64.                 $subdir preg_match'/mod_/'$modFile 'modules' 'templates';
  65.                 global $gBitSmarty$gBitSystem$gBitUser$gQueryUserId$moduleParams;
  66.                 // the PHP sibling file needs to be included here, before the fetch so caching works properly
  67.                 $modFile str_replace'.tpl''.php'$modFile );
  68.  
  69.                 $path constantstrtoupper$package )."_PKG_PATH" );
  70.                 $includeFile "$path$subdir/$modFile";
  71.  
  72.                 iffile_exists$includeFile )) {
  73.                     $ret $includeFile;
  74.                 }
  75.             }
  76.         }
  77.         return $ret;
  78.     }
  79.  
  80.  
  81.     protected function fetchTimestamp$pTplName {
  82.         $ret FALSE;
  83.         $locations $this->getTplLocations$pTplName );
  84.         foreach$locations as $resource {
  85.             iffile_exists$resource )) {
  86.                 $ret filemtime$resource );
  87.             }
  88.         }
  89.  
  90.         return $ret;
  91.     }
  92.  
  93.     private function getTplLocations$pTplName {
  94.         global $gBitThemes$gNoForceStyle;
  95.  
  96.         $path explode'/'$pTplName );
  97.         $package array_shift$path );
  98.         $template array_pop$path );
  99.         $subdir '';
  100.         foreach$path as $p {
  101.             $subdir .= $p.'/';
  102.         }
  103.  
  104.         // files found in temp are special - these are stored in temp/<pkg>/(templates|modules)/<template.tpl>
  105.         if$package == 'temp' {
  106.             // if it's a module, we need to look in the correct place
  107.             $subdir .= preg_match'/\b(help_)?mod_/'$template 'modules' 'templates' );
  108.             // we can't override these templates - they only exist in temp
  109.             $ret['package_template'constantstrtoupper$package ).'_PKG_PATH' )."$subdir/$template";
  110.         else {
  111.             ifempty$gNoForceStyle )) {
  112.                 // look in config/themes/force/
  113.                 $ret['force']        CONFIG_PKG_PATH."themes/force/$package/$subdir$template";
  114.                 $ret['force_simple'CONFIG_PKG_PATH."themes/force/$subdir$template";
  115.             }
  116.  
  117.             // look in themes/style/<stylename>/
  118.             $ret['override']        $gBitThemes->getStylePath()."$package/$subdir$template";
  119.             $ret['override_simple'$gBitThemes->getStylePath().$subdir.$template;
  120.  
  121.             // if it's a module, we need to look in the correct place
  122.             $subdir preg_match'/\b(help_)?mod_/'$template 'modules' 'templates' )."/".$subdir;
  123.  
  124.             // look for default package template
  125.             $ret['package_template'constantstrtoupper$package ).'_PKG_PATH' )."$subdir$template";
  126.         }
  127.  
  128.         return $ret;
  129.     }
  130. }

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