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
    • SIWECOS
    • 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:      * @param bool  $bSanityCheck
 51:      *
 52:      * @throws cException
 53:      * @throws cInvalidArgumentException if the given configurations are not an
 54:      *         array
 55:      */
 56:     public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
 57:         // check if already instanciated
 58:         if (isset(self::$bSmartyInstanciated) && self::$bSmartyInstanciated) {
 59:             throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not instanciate multiple times.");
 60:         }
 61: 
 62:         if (!is_array($aCfg)) {
 63:             throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 1 invalid.");
 64:         }
 65: 
 66:         if (!is_array($aClientCfg)) {
 67:             throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 2 invalid.");
 68:         }
 69: 
 70:         self::$oSmarty = new cSmartyWrapper();
 71:         self::$aDefaultPaths = array(
 72:             'template_dir' => $aClientCfg['module']['path'],
 73:             'cache_dir' => $aClientCfg['cache']['path'] . 'templates_c',
 74:             'compile_dir' => $aClientCfg['cache']['path'] . 'templates_c'
 75:         );
 76: 
 77:         // check the template directory and create new one if it not exists
 78:         if (!is_dir(self::$aDefaultPaths['compile_dir'])) {
 79:             mkdir(self::$aDefaultPaths['compile_dir'], cDirHandler::getDefaultPermissions());
 80:         }
 81: 
 82:         // check if folders exist and rights ok if needed
 83:         if ($bSanityCheck) {
 84:             foreach (self::$aDefaultPaths as $key => $value) {
 85:                 if (!file_exists($value)) {
 86:                     throw new cException(sprintf("Class %s Error: Folder %s does not exist. Please create.", __CLASS__, $value));
 87:                 }
 88:                 if ($key == 'cache' || $key == 'compile_dir') {
 89:                     if (!is_writable($value)) {
 90:                         throw new cException(sprintf("Class %s Error: Folder %s is not writable. Please check for sufficient rights.", __CLASS__, $value));
 91:                     }
 92:                 }
 93:             }
 94:         }
 95: 
 96:         self::resetPaths();
 97:         self::$bSmartyInstanciated = true;
 98:     }
 99: 
100:     /**
101:      * prevent users from cloning instance
102:      *
103:      * @throws cException if this function is called
104:      */
105:     public function __clone() {
106:         throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not clone.");
107:     }
108: 
109:     /**
110:      * destructor
111:      * set cSmarty::bSmartyInstanciated to false
112:      */
113:     public function __destruct() {
114:         self::$bSmartyInstanciated = false;
115:     }
116: 
117:     /**
118:      * static function to provide the smart object
119:      *
120:      * @param boolean $bResetTemplate true if the template values shall all be
121:      *        resetted
122:      * @throws cException if singleton has not been instantiated yet
123:      * @return cSmartyWrapper
124:      */
125:     public static function getInstance($bResetTemplate = false) {
126:         if (!isset(self::$oSmarty)) {
127:             // @TODO find a smart way to instanciate smarty object on demand
128:             throw new cException("Smarty singleton not instantiated yet.");
129:         }
130:         if ($bResetTemplate) {
131:             self::$oSmarty = new cSmartyWrapper();
132:             self::resetPaths();
133:         }
134:         return self::$oSmarty;
135:     }
136: 
137:     /**
138:      * sets the default paths again
139:      */
140:     public static function resetPaths() {
141:         self::$oSmarty->setTemplateDir(self::$aDefaultPaths['template_dir']);
142:         self::$oSmarty->setCacheDir(self::$aDefaultPaths['cache_dir']);
143:         self::$oSmarty->setCompileDir(self::$aDefaultPaths['compile_dir']);
144:     }
145: 
146: }
147: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0