[ Indice ]

Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4

Servizio fornito da VMItalia
Classe:   Funzione:   Variabile:   Costante:  
Storico Ricerche +

titolo

Corpo

[chiudi]

/administrator/components/com_virtuemart/classes/ -> template.class.php (sorgente)

   1  <?php
   2  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
   3  /**

   4  *

   5  * @version $Id: template.class.php 1948 2009-09-30 14:32:48Z soeren_nb $

   6  * @package VirtueMart

   7  * @subpackage core

   8  * @copyright Copyright (c) 2003 Brian E. Lozier (brian@massassi.net)

   9  * @copyright Copyright (C) 2007 soeren - All rights reserved.

  10  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php

  11  * VirtueMart is free software. This version may have been modified pursuant

  12  * to the GNU General Public License, and as distributed it includes or

  13  * is derivative of works licensed under the GNU General Public License or

  14  * other free or open source software licenses.

  15  * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.

  16  *

  17  * http://virtuemart.net

  18  *

  19  * set_vars() method contributed by Ricardo Garcia (Thanks!)

  20  *

  21  * Permission is hereby granted, free of charge, to any person obtaining a copy

  22  * of this software and associated documentation files (the "Software"), to

  23  * deal in the Software without restriction, including without limitation the

  24  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or

  25  * sell copies of the Software, and to permit persons to whom the Software is

  26  * furnished to do so, subject to the following conditions:

  27  *

  28  * The above copyright notice and this permission notice shall be included in

  29  * all copies or substantial portions of the Software.

  30  */
  31  require_once ( CLASSPATH . 'parameters.class.php');
  32  
  33  class vm_vmTemplate {
  34      var $vars; /// Holds all the template variables

  35      var $path; /// Path to the templates

  36      /**

  37       * Stores the theme configuration

  38       *

  39       * @var $config

  40       */
  41      var $config;
  42      var $cache_filename;
  43      var $expire;
  44      var $cached = false;
  45      
  46      /**

  47      * Constructor.

  48      *

  49      * @param string $path path to template files

  50      * @param string $cache_id unique cache identifier

  51      * @param int $expire number of seconds the cache will live

  52      *

  53      * @return void

  54      */
  55  	function vm_vmTemplate($path='', $expire = 0 ) {
  56          global $mosConfig_absolute_path, $mosConfig_cachepath, $mosConfig_cachetime;
  57              
  58          $this->path = empty($path) ?  VM_THEMEPATH.'templates/' : $path;
  59          $this->default_path = $mosConfig_absolute_path.'/components/'.VM_COMPONENT_NAME.'/themes/default/templates/';
  60          
  61          $globalsArray = vmGetGlobalsArray();
  62          foreach( $globalsArray as $global ) {
  63              global $$global;
  64              $this->vars[$global] = $GLOBALS[$global];
  65          }
  66          $this->cache_filename = $mosConfig_cachepath.'/' . $GLOBALS['cache_id'];
  67          $this->expire   = $expire == 0 ? $mosConfig_cachetime : $expire;
  68          
  69          // the theme configuration needs to be available to the templates! (so you can use $this->get_cfg('showManufacturerLink') for example )

  70          if( empty( $GLOBALS['vmThemeConfig'] ) || !empty( $_REQUEST['vmThemeConfig'])) {
  71              $GLOBALS['vmThemeConfig'] = new vmParameters( @file_get_contents(VM_THEMEPATH.'theme.config.php'), VM_THEMEPATH.'theme.xml', 'theme');
  72  
  73          }
  74          $this->config =& $GLOBALS['vmThemeConfig'];
  75          
  76      }
  77      /**

  78       * Returns a unique Cache ID

  79       * @static 

  80       * @return string

  81       */
  82  	function getCacheId() {
  83          global $modulename, $pagename, $product_id, $category_id, $manufacturer_id, $auth, $limitstart, $limit;
  84          return 'vm_' . @md5( 'vm_' . @md5( $modulename. $pagename. $product_id. $category_id .$manufacturer_id. $auth["shopper_group_id"]. $limitstart. $limit. @$_REQUEST['orderby']. @$_REQUEST['DescOrderBy'] ). @$_REQUEST['orderby']. @$_REQUEST['DescOrderBy'] );
  85      }
  86      /**

  87       * @static 

  88       *

  89       * @return vmTheme

  90       */
  91  	function getInstance() {
  92          return new $GLOBALS['VM_THEMECLASS']();
  93      }
  94      /**

  95      * Test to see whether the currently loaded cache_id has a valid

  96      * corresponding cache file.

  97      * @param string the name of the template file (relative path to the theme dir)

  98      * @return array

  99      */
 100  	function get_cached( $templateFile ) {
 101          global $mosConfig_cachepath;
 102          
 103          // Passed a cache_id?

 104          if(!$GLOBALS['cache_id']) {
 105              $GLOBALS['cache_id'] = $this->getCacheId();
 106          }
 107          
 108          $returnArr['cache_file_id'] = md5($templateFile . $GLOBALS['cache_id']);
 109          $returnArr['cache_file_name'] = $mosConfig_cachepath.'/'.$returnArr['cache_file_id'];
 110          // Cache file exists?

 111          if(!@file_exists($returnArr['cache_file_name'])) {
 112              $returnArr['isCached'] = false;
 113              return $returnArr;
 114          }
 115          if( @filesize($returnArr['cache_file_name']) == 0) {
 116              $returnArr['isCached'] = false;
 117              return $returnArr;
 118          }
 119  
 120          // Can get the time of the file?

 121          if(!($mtime = filemtime($returnArr['cache_file_name']))) {
 122              $returnArr['isCached'] = false;
 123              return $returnArr;
 124          }
 125  
 126          // Cache expired?

 127          if(($mtime + $this->expire) < time()) {
 128              @unlink($returnArr['cache_file_name']);
 129              $returnArr['isCached'] = false;
 130              return $returnArr;
 131          }
 132          $returnArr['isCached'] = true;
 133          return $returnArr;
 134          
 135      }
 136      
 137      /**

 138      * Set the path to the template files.

 139      *

 140      * @param string $path path to template files

 141      *

 142      * @return void

 143      */
 144  	function set_path($path) {
 145          $this->path = $path;
 146      }
 147  
 148      /**

 149      * Set a template variable.

 150      *

 151      * @param string $name name of the variable to set

 152      * @param mixed $value the value of the variable

 153      *

 154      * @return void

 155      */
 156  	function set($name, $value) {
 157          $this->vars[$name] = $value;
 158      }
 159  
 160      /**

 161      * Set a bunch of variables at once using an associative array.

 162      *

 163      * @param array $vars array of vars to set

 164      * @param bool $clear whether to completely overwrite the existing vars

 165      *

 166      * @return void

 167      */
 168  	function set_vars($vars, $clear = false) {
 169          if($clear) {
 170              $this->vars = $vars;
 171          }
 172          else {
 173              if(is_array($vars)) {
 174                  $this->vars = array_merge($this->vars, $vars);
 175              }
 176          }
 177      }
 178      /**

 179       * Returns the value of a configuration parameter of this theme

 180       *

 181       * @param string $var

 182       * @param mixed $default

 183       * @return mixed

 184       */
 185  	function get_cfg( $var, $default='' ) {
 186  
 187          return $this->config->get( $var, $default );
 188      }
 189      
 190      /**

 191       * Sets the configuration parameter of this theme

 192       *

 193       * @param string $var

 194       * @param mixed $value

 195       */
 196  	function set_cfg( $var, $value ) {
 197          if( is_a( $this->config, 'vmParameters' )) {
 198              $this->config->set( $var, $value );
 199          }
 200      }
 201      
 202      /**

 203      * Open, parse, and return the template file.

 204      *

 205      * @param string string the template file name

 206      *

 207      * @return string

 208      */
 209  	function fetch($file) {
 210          extract($this->vars);          // Extract the vars to local namespace

 211          ob_start();                    // Start output buffering

 212          if( is_file( $this->path . $file ) ) {
 213              include($this->path . $file);  // Include the file

 214          } elseif( is_file( $this->default_path . $file ) ) {
 215              include( $this->default_path . $file );
 216          }
 217          $contents = ob_get_contents(); // Get the contents of the buffer

 218          ob_end_clean();                // End buffering and discard

 219          return $contents;              // Return the contents

 220      }
 221  
 222      /**

 223      * This function returns a cached copy of a template (if it exists),

 224      * otherwise, it parses it as normal and caches the content.

 225      *

 226      * @param $file string the template file

 227      *

 228      * @return string

 229      */
 230  	function fetch_cache($file) {
 231          global $mosConfig_caching;
 232          
 233          $cacheFileArr = $this->get_cached( $file );
 234          
 235          if( $cacheFileArr['isCached'] !== false ) {
 236              
 237              $contents = file_get_contents($cacheFileArr['cache_file_name']);
 238              return $contents;
 239          }
 240          else {
 241              $contents = $this->fetch($file);
 242              if( $mosConfig_caching ) {
 243                  // Write the cache

 244                  if( !file_put_contents($cacheFileArr['cache_file_name'], $contents ) ) {
 245                      $vmLogger->crit('Failed to write to Cache!');
 246                  }                
 247              }
 248              return $contents;
 249          }
 250      }
 251  }
 252  
 253  // Check if there is an extended class in the Themes and if it is allowed to use them

 254  // If the class is called outside Virtuemart, we have to make sure to load the settings

 255  // Thomas Kahl - Feb. 2009

 256  if (!defined('VM_ALLOW_EXTENDED_CLASSES') && file_exists(dirname(__FILE__).'/../virtuemart.cfg.php')) {
 257      include_once(dirname(__FILE__).'/../virtuemart.cfg.php');
 258  }
 259  // If settings are loaded, extended Classes are allowed and the class exisits...

 260  if (defined('VM_ALLOW_EXTENDED_CLASSES') && defined('VM_THEMEPATH') && VM_ALLOW_EXTENDED_CLASSES && file_exists(VM_THEMEPATH.'user_class/'.basename(__FILE__))) {
 261      // Load the theme-user_class as extended

 262      include_once(VM_THEMEPATH.'user_class/'.basename(__FILE__));
 263  } else {
 264      // Otherwise we have to use the original classname to extend the core-class

 265      class vmTemplate extends vm_vmTemplate {
 266  		function vmTemplate() {
 267              parent::vm_vmTemplate();
 268          }
 269      }
 270  }
 271  ?>


Generato il: Mon Oct 19 20:29:27 2009 Generato con PHPXref 0.7