[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/extras/ -> resource.db.php (source)

   1  <?php
   2  /*

   3   * Smarty plugin

   4   * ------------------------------------------------------------- 

   5   * File:     resource.db.php

   6   * Type:     resource

   7   * Name:     db

   8   * Purpose:  Fetches templates from a database

   9   * -------------------------------------------------------------

  10   */
  11  function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty) {
  12      if ( !$tpl = smarty_resource_db_tplinfo( $tpl_name ) ) {
  13          return false;
  14      }
  15      if ( is_object( $tpl ) ) {
  16          $tpl_source = $tpl->getVar( 'tpl_source', 'n' );
  17      } else {
  18          $fp = fopen( $tpl, 'r' );
  19          $tpl_source = fread( $fp, filesize( $tpl ) );
  20          fclose( $fp );
  21      }
  22      return true;
  23  }
  24  
  25  function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty) {
  26      if ( !$tpl = smarty_resource_db_tplinfo( $tpl_name ) ) {
  27          return false;
  28      }
  29      if ( is_object( $tpl ) ) {
  30          $tpl_timestamp = $tpl->getVar( 'tpl_lastmodified', 'n' );
  31      } else {
  32          $tpl_timestamp = filemtime( $tpl );
  33      }
  34      return true;
  35  }
  36  
  37  function smarty_resource_db_secure($tpl_name, &$smarty)
  38  {
  39      // assume all templates are secure

  40      return true;
  41  }
  42  
  43  function smarty_resource_db_trusted($tpl_name, &$smarty)
  44  {
  45      // not used for templates

  46  }
  47  
  48  function smarty_resource_db_tplinfo( $tpl_name ) {
  49      static $cache = array();
  50      global $xoopsConfig;
  51  
  52      if ( isset( $cache[$tpl_name] ) ) {
  53          return $cache[$tpl_name];
  54      }
  55      $tplset = $xoopsConfig['template_set'];
  56      $theme = isset( $xoopsConfig['theme_set'] ) ? $xoopsConfig['theme_set'] : 'default';
  57      
  58      $tplfile_handler =& xoops_gethandler('tplfile');
  59      // If we're not using the "default" template set, then get the templates from the DB

  60      if ( $tplset != "default" ) {
  61          $tplobj = $tplfile_handler->find( $tplset, null, null, null, $tpl_name, true);
  62          if ( count( $tplobj ) ) {
  63              return $cache[$tpl_name] = $tplobj[0];
  64          }
  65      }
  66      // If we'using the default tplset, get the template from the filesystem

  67      //$tplobj = $tplfile_handler->find( "default", null, null, null, $tpl_name);

  68      $tplobj = $tplfile_handler->find( "default", null, null, null, $tpl_name, true);
  69  
  70      if ( !count( $tplobj ) ) {
  71          return $cache[$tpl_name] = false;
  72      }
  73      $tplobj = $tplobj[0];
  74      $module = $tplobj->getVar( 'tpl_module', 'n' );
  75      $type = $tplobj->getVar( 'tpl_type', 'n' );
  76      $blockpath = ( $type == 'block' ) ? 'blocks/' : '';
  77      // First, check for an overloaded version within the theme folder

  78      $filepath = XOOPS_THEME_PATH . "/$theme/modules/$module/$blockpath$tpl_name";
  79      if ( !file_exists( $filepath ) ) {
  80          // If no custom version exists, get the tpl from its default location

  81          $filepath = XOOPS_ROOT_PATH . "/modules/$module/templates/$blockpath$tpl_name";
  82          if ( !file_exists( $filepath ) ) {
  83              return $cache[$tpl_name] = $tplobj ;
  84          }
  85      }
  86      return $cache[$tpl_name] = $filepath;
  87  }
  88  
  89  
  90  
  91  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics