Overview

Packages

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

Classes

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