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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the former template class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage GUI
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Jan Lengowski, Stefan Jelner
 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: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * class Template
 20:  * Light template mechanism
 21:  *
 22:  * @package Core
 23:  * @subpackage GUI
 24:  */
 25: class cTemplate {
 26: 
 27:     /**
 28:      * Needles (static)
 29:      *
 30:      * @var array
 31:      */
 32:     public $needles = array();
 33: 
 34:     /**
 35:      * Replacements (static)
 36:      *
 37:      * @var array
 38:      */
 39:     public $replacements = array();
 40: 
 41:     /**
 42:      * Dyn_Needles (dynamic)
 43:      *
 44:      * @var array
 45:      */
 46:     public $Dyn_needles = array();
 47: 
 48:     /**
 49:      * Dyn_Replacements (dynamic)
 50:      *
 51:      * @var array
 52:      */
 53:     public $Dyn_replacements = array();
 54: 
 55: 
 56:     /**
 57:      * Dynamic counter
 58:      *
 59:      * @var int
 60:      */
 61:     public $dyn_cnt = 0;
 62: 
 63:     /**
 64:      * Tags array (for dynamic blocks);
 65:      *
 66:      * @var array
 67:      */
 68:     public $tags = array(
 69:         'static' => '{%s}',
 70:         'start' => '<!-- BEGIN:BLOCK -->',
 71:         'end' => '<!-- END:BLOCK -->'
 72:     );
 73: 
 74:     /**
 75:      * gettext domain (default: contenido)
 76:      *
 77:      * @var string
 78:      */
 79:     protected $_sDomain = 'contenido';
 80: 
 81:     /**
 82:      * Constructor function
 83:      * @param array|bool $tags
 84:      */
 85:     public function __construct($tags = false) {
 86:         if (is_array($tags)) {
 87:             $this->tags = $tags;
 88:         }
 89: 
 90:         $this->setEncoding("");
 91:     }
 92: 
 93:     /**
 94:      * Sets the gettext domain to use for translations in a template
 95:      *
 96:      * @param string $sDomain Sets the domain to use for template translations
 97:      */
 98:     public function setDomain($sDomain) {
 99:         $this->_sDomain = $sDomain;
100:     }
101: 
102:     /**
103:      * Set Templates placeholders and values
104:      *
105:      * With this method you can replace the placeholders
106:      * in the static templates with dynamic data.
107:      *
108:      * @param string $which 's' for Static or else dynamic
109:      * @param string $needle Placeholder
110:      * @param string $replacement Replacement String
111:      */
112:     public function set($which, $needle, $replacement) {
113:         if ($which == 's') {
114:             // static
115:             $this->needles[] = sprintf($this->tags['static'], $needle);
116:             $this->replacements[] = $replacement;
117:         } else {
118:             // dynamic
119:             $this->Dyn_needles[$this->dyn_cnt][] = sprintf($this->tags['static'], $needle);
120:             $this->Dyn_replacements[$this->dyn_cnt][] = $replacement;
121:         }
122:     }
123: 
124:     /**
125:      * Sets an encoding for the template's head block.
126:      *
127:      * @param string $encoding Encoding to set
128:      */
129:     public function setEncoding($encoding) {
130:         $this->_encoding = $encoding;
131:     }
132: 
133:     /**
134:      * Iterate internal counter by one
135:      */
136:     public function next() {
137:         $this->dyn_cnt++;
138:     }
139: 
140:     /**
141:      * Reset template data
142:      */
143:     public function reset() {
144:         $this->dyn_cnt = 0;
145:         $this->needles = array();
146:         $this->replacements = array();
147:         $this->Dyn_needles = array();
148:         $this->Dyn_replacements = array();
149:     }
150: 
151:     /**
152:      * Generate the template and print/return it.
153:      * (do translations sequentially to save memory!!!)
154:      *
155:      * @param string $template Either template string or template file path
156:      * @param bool $return Return or print template
157:      * @param bool $note Echo "Generated by ... " Comment
158:      * @return string|void  Complete template string or nothing
159:      */
160:     public function generate($template, $return = false, $note = false) {
161:         global $cCurrentModule, $cfg, $frontend_debug;
162: 
163:         $moduleHandler = NULL;
164:         if (!is_null($cCurrentModule)) {
165:             $moduleHandler = new cModuleHandler($cCurrentModule);
166:         }
167: 
168:         // Check if the template is a file or a string
169:         if (!@is_file($template)) {
170:             if (is_object($moduleHandler) && is_file($moduleHandler->getTemplatePath($template))) {
171:                 // Module directory has higher priority
172:                 $content = $moduleHandler->getFilesContent('template', '', $template);
173:                 if ($frontend_debug['template_display']) {
174:                     echo('<!-- CTEMPLATE ' . $template . ' -->');
175:                 }
176:             } else {
177:                 // Template is a string (it is a reference to save memory!!!)
178:                 $content = &$template;
179:             }
180:         } else {
181:             if (is_object($moduleHandler) && is_file($moduleHandler->getTemplatePath($template))) {
182:                 // Module directory has higher priority
183:                 $content = $moduleHandler->getFilesContent('template', '', $template);
184:             } else {
185:                 // Template is a file in template directory
186:                 $content = implode('', file($template));
187:             }
188:         }
189: 
190:         $content = (($note) ? "<!-- Generated by CONTENIDO " . CON_VERSION . "-->\n" : "") . $content;
191: 
192:         // CEC for template pre processing
193:         $content = cApiCecHook::executeAndReturn('Contenido.Template.BeforeParse', $content, $this);
194: 
195:         $pieces = array();
196: 
197:         // Replace i18n strings before replacing other placeholders
198:         $this->replacei18n($content, 'i18n');
199:         $this->replacei18n($content, 'trans');
200: 
201:         // If content has dynamic blocks
202:         $startQ = preg_quote($this->tags['start'], '/');
203:         $endQ = preg_quote($this->tags['end'], '/');
204:         if (preg_match('/^.*' . $startQ . '.*?' . $endQ . '.*$/s', $content)) {
205:             // Split everything into an array
206:             preg_match_all('/^(.*)' . $startQ . '(.*?)' . $endQ . '(.*)$/s', $content, $pieces);
207:             // Safe memory
208:             array_shift($pieces);
209:             $content = '';
210:             // Now combine pieces together
211:             // Start block
212:             $content .= str_replace($this->needles, $this->replacements, $pieces[0][0]);
213:             unset($pieces[0][0]);
214: 
215:             // Generate dynamic blocks
216:             for ($a = 0; $a < $this->dyn_cnt; $a++) {
217:                 $content .= str_replace($this->Dyn_needles[$a], $this->Dyn_replacements[$a], $pieces[1][0]);
218:             }
219:             unset($pieces[1][0]);
220: 
221:             // End block
222:             $content .= str_replace($this->needles, $this->replacements, $pieces[2][0]);
223:             unset($pieces[2][0]);
224:         } else {
225:             $content = str_replace($this->needles, $this->replacements, $content);
226:         }
227: 
228:         if ($this->_encoding != '') {
229: //            $content = str_replace("</head>", '<meta http-equiv="Content-Type" content="text/html; charset=' . $this->_encoding . '">' . "\n" . '</head>', $content);
230:         }
231: 
232:         if ($return) {
233:             return $content;
234:         } else {
235:             echo $content;
236:         }
237:     }
238: 
239:     /**
240:      * Replaces a named function with the translated variant
241:      *
242:      * @param string $template Contents of the template to translate (it is
243:      *        reference to save memory!!!)
244:      * @param string $functionName Name of the translation function (e.g. i18n)
245:      */
246:     public function replacei18n(&$template, $functionName) {
247:         $container = array();
248: 
249:         // Be sure that php code stays unchanged
250:         $php_matches = array();
251:         /*
252:          * if (preg_match_all('/<\?(php)?((.)|(\s))*?\?>/i', $template,
253:          * $php_matches)) { $x = 0; foreach ($php_matches[0] as $php_match) {
254:          * $x++; $template = str_replace($php_match , '{PHP#' . $x . '#PHP}',
255:          * $template); $container[$x] = $php_match; } }
256:          */
257: 
258:         $functionNameQ = preg_quote($functionName, '/');
259: 
260:         // If template contains functionName + parameter store all matches
261:         $matches = array();
262:         preg_match_all('/' . $functionNameQ . "\\(([\\\"\\'])(.*?)\\1\\)/s", $template, $matches);
263: 
264:         $matches = array_values(array_unique($matches[2]));
265:         for ($a = 0; $a < count($matches); $a++) {
266:             $template = preg_replace('/' . $functionNameQ . "\\([\\\"\\']" . preg_quote($matches[$a], '/') . "[\\\"\\']\\)/s", i18n($matches[$a], $this->_sDomain), $template);
267:         }
268: 
269:         // Change back php placeholder
270:         if (is_array($container)) {
271:             foreach ($container as $x => $php_match) {
272:                 $template = str_replace('{PHP#' . $x . '#PHP}', $php_match, $template);
273:             }
274:         }
275:     }
276: 
277: }
278: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen