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 / smarty / xoops_plugins / resource.db.php < prev   
Encoding:
PHP Script  |  2007-09-09  |  2.6 KB  |  87 lines

  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.  
  69.     if ( !count( $tplobj ) ) {
  70.         return $cache[$tpl_name] = false;
  71.     }
  72.     $tplobj = $tplobj[0];
  73.     $module = $tplobj->getVar( 'tpl_module', 'n' );
  74.     $type = $tplobj->getVar( 'tpl_type', 'n' );
  75.     $blockpath = ( $type == 'block' ) ? 'blocks/' : '';
  76.     // First, check for an overloaded version within the theme folder
  77.     $filepath = XOOPS_THEME_PATH . "/$theme/modules/$module/$blockpath$tpl_name";
  78.     if ( !file_exists( $filepath ) ) {
  79.         // If no custom version exists, get the tpl from its default location
  80.         $filepath = XOOPS_ROOT_PATH . "/modules/$module/templates/$blockpath$tpl_name";
  81.     }
  82.     return $cache[$tpl_name] = $filepath;
  83. }
  84.  
  85.  
  86.  
  87. ?>