Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cSmartyBackend
  • cSmartyFrontend
  • cSmartyWrapper
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the frontend class for smarty wrapper plugin.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage SmartyWrapper
  7:  * @author Andreas Dieter
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Wrapper class for Integration of smarty.
 17:  *
 18:  * @package Plugin
 19:  * @subpackage SmartyWrapper
 20:  */
 21: class cSmartyFrontend {
 22: 
 23:     /**
 24:      * The smarty Object
 25:      *
 26:      * @var Smarty
 27:      */
 28:     protected static $oSmarty;
 29: 
 30:     /**
 31:      * static flag to simulate singleton behaviour
 32:      *
 33:      * @var bool
 34:      */
 35:     public static $bSmartyInstanciated = false;
 36: 
 37:     /**
 38:      * static default paths
 39:      *
 40:      * @var array
 41:      */
 42:     protected static $aDefaultPaths = array();
 43: 
 44:     /**
 45:      * constructor
 46:      *
 47:      * @param array &$aCfg contenido cfg array
 48:      * @param array &$aClientCfg contenido client cfg array of the specific
 49:      *        client
 50:      * @throws cException
 51:      * @throws cInvalidArgumentException if the given configurations are not an
 52:      *         array
 53:      */
 54:     public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
 55:         // check if already instanciated
 56:         if (isset(self::$bSmartyInstanciated) && self::$bSmartyInstanciated) {
 57:             throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not instanciate multiple times.");
 58:         }
 59: 
 60:         if (!is_array($aCfg)) {
 61:             throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 1 invalid.");
 62:         }
 63: 
 64:         if (!is_array($aClientCfg)) {
 65:             throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 2 invalid.");
 66:         }
 67: 
 68:         self::$oSmarty = new cSmartyWrapper();
 69:         self::$aDefaultPaths = array(
 70:             'template_dir' => $aClientCfg['module']['path'],
 71:             'cache_dir' => $aClientCfg['cache']['path'] . 'templates_c',
 72:             'compile_dir' => $aClientCfg['cache']['path'] . 'templates_c'
 73:         );
 74: 
 75:         // check the template directory and create new one if it not exists
 76:         if (!is_dir(self::$aDefaultPaths['compile_dir'])) {
 77:             mkdir(self::$aDefaultPaths['compile_dir'], cDirHandler::getDefaultPermissions());
 78:         }
 79: 
 80:         // check if folders exist and rights ok if needed
 81:         if ($bSanityCheck) {
 82:             foreach (self::$aDefaultPaths as $key => $value) {
 83:                 if (!file_exists($value)) {
 84:                     throw new cException(sprintf("Class %s Error: Folder %s does not exist. Please create.", __CLASS__, $value));
 85:                 }
 86:                 if ($key == 'cache' || $key == 'compile_dir') {
 87:                     if (!is_writable($value)) {
 88:                         throw new cException(sprintf("Class %s Error: Folder %s is not writable. Please check for sufficient rights.", __CLASS__, $value));
 89:                     }
 90:                 }
 91:             }
 92:         }
 93: 
 94:         self::resetPaths();
 95:         self::$bSmartyInstanciated = true;
 96:     }
 97: 
 98:     /**
 99:      * prevent users from cloning instance
100:      *
101:      * @throws cException if this function is called
102:      */
103:     public function __clone() {
104:         throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not clone.");
105:     }
106: 
107:     /**
108:      * destructor
109:      * set cSmarty::bSmartyInstanciated to false
110:      */
111:     public function __destruct() {
112:         self::$bSmartyInstanciated = false;
113:     }
114: 
115:     /**
116:      * static function to provide the smart object
117:      *
118:      * @param boolean $bResetTemplate true if the template values shall all be
119:      *        resetted
120:      * @throws cException if singleton has not been instantiated yet
121:      * @return cSmartyWrapper
122:      */
123:     public static function getInstance($bResetTemplate = false) {
124:         if (!isset(self::$oSmarty)) {
125:             // @TODO find a smart way to instanciate smarty object on demand
126:             throw new cException("Smarty singleton not instantiated yet.");
127:         }
128:         if ($bResetTemplate) {
129:             self::$oSmarty = new cSmartyWrapper();
130:             self::resetPaths();
131:         }
132:         return self::$oSmarty;
133:     }
134: 
135:     /**
136:      * sets the default paths again
137:      */
138:     public static function resetPaths() {
139:         self::$oSmarty->setTemplateDir(self::$aDefaultPaths['template_dir']);
140:         self::$oSmarty->setCacheDir(self::$aDefaultPaths['cache_dir']);
141:         self::$oSmarty->setCompileDir(self::$aDefaultPaths['compile_dir']);
142:     }
143: 
144: }
145: 
146: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0