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:  * Smarty Internal Plugin Smarty Template  Base
  4:  * This file contains the basic shared methods for template handling
  5:  *
  6:  * @package    Smarty
  7:  * @subpackage Template
  8:  * @author     Uwe Tews
  9:  */
 10: 
 11: /**
 12:  * Class with shared template methods
 13:  *
 14:  * @package    Smarty
 15:  * @subpackage Template
 16:  */
 17: abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
 18: {
 19:     /**
 20:      * fetches a rendered Smarty template
 21:      *
 22:      * @param  string $template         the resource handle of the template file or template object
 23:      * @param  mixed  $cache_id         cache id to be used with this template
 24:      * @param  mixed  $compile_id       compile id to be used with this template
 25:      * @param  object $parent           next higher level of Smarty variables
 26:      * @param  bool   $display          true: display, false: fetch
 27:      * @param  bool   $merge_tpl_vars   if true parent template variables merged in to local scope
 28:      * @param  bool   $no_output_filter if true do not run output filter
 29:      *
 30:      * @throws Exception
 31:      * @throws SmartyException
 32:      * @return string rendered template output
 33:      */
 34:     public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
 35:     {
 36:         if ($template === null && $this instanceof $this->template_class) {
 37:             $template = $this;
 38:         }
 39:         if ($cache_id !== null && is_object($cache_id)) {
 40:             $parent = $cache_id;
 41:             $cache_id = null;
 42:         }
 43:         if ($parent === null && ($this instanceof Smarty || is_string($template))) {
 44:             $parent = $this;
 45:         }
 46:         // create template object if necessary
 47:         $_template = ($template instanceof $this->template_class)
 48:             ? $template
 49:             : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
 50:         // if called by Smarty object make sure we use current caching status
 51:         if ($this instanceof Smarty) {
 52:             $_template->caching = $this->caching;
 53:         }
 54:         // merge all variable scopes into template
 55:         if ($merge_tpl_vars) {
 56:             // save local variables
 57:             $save_tpl_vars = $_template->tpl_vars;
 58:             $save_config_vars = $_template->config_vars;
 59:             $ptr_array = array($_template);
 60:             $ptr = $_template;
 61:             while (isset($ptr->parent)) {
 62:                 $ptr_array[] = $ptr = $ptr->parent;
 63:             }
 64:             $ptr_array = array_reverse($ptr_array);
 65:             $parent_ptr = reset($ptr_array);
 66:             $tpl_vars = $parent_ptr->tpl_vars;
 67:             $config_vars = $parent_ptr->config_vars;
 68:             while ($parent_ptr = next($ptr_array)) {
 69:                 if (!empty($parent_ptr->tpl_vars)) {
 70:                     $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
 71:                 }
 72:                 if (!empty($parent_ptr->config_vars)) {
 73:                     $config_vars = array_merge($config_vars, $parent_ptr->config_vars);
 74:                 }
 75:             }
 76:             if (!empty(Smarty::$global_tpl_vars)) {
 77:                 $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
 78:             }
 79:             $_template->tpl_vars = $tpl_vars;
 80:             $_template->config_vars = $config_vars;
 81:         }
 82:         // dummy local smarty variable
 83:         if (!isset($_template->tpl_vars['smarty'])) {
 84:             $_template->tpl_vars['smarty'] = new Smarty_Variable;
 85:         }
 86:         if (isset($this->smarty->error_reporting)) {
 87:             $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);
 88:         }
 89:         // check URL debugging control
 90:         if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
 91:             if (isset($_SERVER['QUERY_STRING'])) {
 92:                 $_query_string = $_SERVER['QUERY_STRING'];
 93:             } else {
 94:                 $_query_string = '';
 95:             }
 96:             if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {
 97:                 if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) {
 98:                     // enable debugging for this browser session
 99:                     setcookie('SMARTY_DEBUG', true);
100:                     $this->smarty->debugging = true;
101:                 } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) {
102:                     // disable debugging for this browser session
103:                     setcookie('SMARTY_DEBUG', false);
104:                     $this->smarty->debugging = false;
105:                 } else {
106:                     // enable debugging for this page
107:                     $this->smarty->debugging = true;
108:                 }
109:             } else {
110:                 if (isset($_COOKIE['SMARTY_DEBUG'])) {
111:                     $this->smarty->debugging = true;
112:                 }
113:             }
114:         }
115:         // must reset merge template date
116:         $_template->smarty->merged_templates_func = array();
117:         // get rendered template
118:         // disable caching for evaluated code
119:         if ($_template->source->recompiled) {
120:             $_template->caching = false;
121:         }
122:         // checks if template exists
123:         if (!$_template->source->exists) {
124:             if ($_template->parent instanceof Smarty_Internal_Template) {
125:                 $parent_resource = " in '{$_template->parent->template_resource}'";
126:             } else {
127:                 $parent_resource = '';
128:             }
129:             throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
130:         }
131:         // read from cache or render
132:         if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {
133:             // render template (not loaded and not in cache)
134:             if (!$_template->source->uncompiled) {
135:                 /** @var Smarty_Internal_Template $_smarty_tpl
136:                  * used in evaluated code
137:                  */
138:                 $_smarty_tpl = $_template;
139:                 if ($_template->source->recompiled) {
140:                     $code = $_template->compiler->compileTemplate($_template);
141:                     if ($this->smarty->debugging) {
142:                         Smarty_Internal_Debug::start_render($_template);
143:                     }
144:                     try {
145:                         ob_start();
146:                         eval("?>" . $code);
147:                         unset($code);
148:                     }
149:                     catch (Exception $e) {
150:                         ob_get_clean();
151:                         throw $e;
152:                     }
153:                 } else {
154:                     if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) {
155:                         $_template->compileTemplateSource();
156:                         $code = file_get_contents($_template->compiled->filepath);
157:                         eval("?>" . $code);
158:                         unset($code);
159:                         $_template->compiled->loaded = true;
160:                         $_template->compiled->isCompiled = true;
161:                     }
162:                     if ($this->smarty->debugging) {
163:                         Smarty_Internal_Debug::start_render($_template);
164:                     }
165:                     if (!$_template->compiled->loaded) {
166:                         include($_template->compiled->filepath);
167:                         if ($_template->mustCompile) {
168:                             // recompile and load again
169:                             $_template->compileTemplateSource();
170:                             $code = file_get_contents($_template->compiled->filepath);
171:                             eval("?>" . $code);
172:                             unset($code);
173:                             $_template->compiled->isCompiled = true;
174:                         }
175:                         $_template->compiled->loaded = true;
176:                     } else {
177:                         $_template->decodeProperties($_template->compiled->_properties, false);
178:                     }
179:                     try {
180:                         ob_start();
181:                         if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
182:                             throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
183:                         }
184:                         array_unshift($_template->_capture_stack, array());
185:                         //
186:                         // render compiled template
187:                         //
188:                         $_template->properties['unifunc']($_template);
189:                         // any unclosed {capture} tags ?
190:                         if (isset($_template->_capture_stack[0][0])) {
191:                             $_template->capture_error();
192:                         }
193:                         array_shift($_template->_capture_stack);
194:                     }
195:                     catch (Exception $e) {
196:                         ob_get_clean();
197:                         throw $e;
198:                     }
199:                 }
200:             } else {
201:                 if ($_template->source->uncompiled) {
202:                     if ($this->smarty->debugging) {
203:                         Smarty_Internal_Debug::start_render($_template);
204:                     }
205:                     try {
206:                         ob_start();
207:                         $_template->source->renderUncompiled($_template);
208:                     }
209:                     catch (Exception $e) {
210:                         ob_get_clean();
211:                         throw $e;
212:                     }
213:                 } else {
214:                     throw new SmartyException("Resource '$_template->source->type' must have 'renderUncompiled' method");
215:                 }
216:             }
217:             $_output = ob_get_clean();
218:             if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
219:                 $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
220:             }
221:             if ($_template->parent instanceof Smarty_Internal_Template) {
222:                 $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
223:                 foreach ($_template->required_plugins as $code => $tmp1) {
224:                     foreach ($tmp1 as $name => $tmp) {
225:                         foreach ($tmp as $type => $data) {
226:                             $_template->parent->required_plugins[$code][$name][$type] = $data;
227:                         }
228:                     }
229:                 }
230:             }
231:             if ($this->smarty->debugging) {
232:                 Smarty_Internal_Debug::end_render($_template);
233:             }
234:             // write to cache when nessecary
235:             if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
236:                 if ($this->smarty->debugging) {
237:                     Smarty_Internal_Debug::start_cache($_template);
238:                 }
239:                 $_template->properties['has_nocache_code'] = false;
240:                 // get text between non-cached items
241:                 $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output);
242:                 // get non-cached items
243:                 preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts);
244:                 $output = '';
245:                 // loop over items, stitch back together
246:                 foreach ($cache_split as $curr_idx => $curr_split) {
247:                     // escape PHP tags in template content
248:                     $output .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', "<?php echo '\$1'; ?>\n", $curr_split);
249:                     if (isset($cache_parts[0][$curr_idx])) {
250:                         $_template->properties['has_nocache_code'] = true;
251:                         // remove nocache tags from cache output
252:                         $output .= preg_replace("!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]);
253:                     }
254:                 }
255:                 if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
256:                     $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
257:                 }
258:                 // rendering (must be done before writing cache file because of {function} nocache handling)
259:                 /** @var Smarty_Internal_Template $_smarty_tpl
260:                  * used in evaluated code
261:                  */
262:                 $_smarty_tpl = $_template;
263:                 try {
264:                     ob_start();
265:                     eval("?>" . $output);
266:                     $_output = ob_get_clean();
267:                 }
268:                 catch (Exception $e) {
269:                     ob_get_clean();
270:                     throw $e;
271:                 }
272:                 // write cache file content
273:                 $_template->writeCachedContent($output);
274:                 if ($this->smarty->debugging) {
275:                     Smarty_Internal_Debug::end_cache($_template);
276:                 }
277:             } else {
278:                 // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
279:                 if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
280:                     // replace nocache_hash
281:                     $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
282:                     $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
283:                 }
284:             }
285:         } else {
286:             if ($this->smarty->debugging) {
287:                 Smarty_Internal_Debug::start_cache($_template);
288:             }
289:             try {
290:                 ob_start();
291:                 array_unshift($_template->_capture_stack, array());
292:                 //
293:                 // render cached template
294:                 //
295:                 $_template->properties['unifunc']($_template);
296:                 // any unclosed {capture} tags ?
297:                 if (isset($_template->_capture_stack[0][0])) {
298:                     $_template->capture_error();
299:                 }
300:                 array_shift($_template->_capture_stack);
301:                 $_output = ob_get_clean();
302:             }
303:             catch (Exception $e) {
304:                 ob_get_clean();
305:                 throw $e;
306:             }
307:             if ($this->smarty->debugging) {
308:                 Smarty_Internal_Debug::end_cache($_template);
309:             }
310:         }
311:         if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
312:             $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template);
313:         }
314:         if (isset($this->error_reporting)) {
315:             error_reporting($_smarty_old_error_level);
316:         }
317:         // display or fetch
318:         if ($display) {
319:             if ($this->caching && $this->cache_modified_check) {
320:                 $_isCached = $_template->isCached() && !$_template->has_nocache_code;
321:                 $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
322:                 if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
323:                     switch (PHP_SAPI) {
324:                         case 'cgi': // php-cgi < 5.3
325:                         case 'cgi-fcgi': // php-cgi >= 5.3
326:                         case 'fpm-fcgi': // php-fpm >= 5.3.3
327:                             header('Status: 304 Not Modified');
328:                             break;
329: 
330:                         case 'cli':
331:                             if ( /* ^phpunit */
332:                             !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
333:                             ) {
334:                                 $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
335:                             }
336:                             break;
337: 
338:                         default:
339:                             header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
340:                             break;
341:                     }
342:                 } else {
343:                     switch (PHP_SAPI) {
344:                         case 'cli':
345:                             if ( /* ^phpunit */
346:                             !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
347:                             ) {
348:                                 $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
349:                             }
350:                             break;
351: 
352:                         default:
353:                             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
354:                             break;
355:                     }
356:                     echo $_output;
357:                 }
358:             } else {
359:                 echo $_output;
360:             }
361:             // debug output
362:             if ($this->smarty->debugging) {
363:                 Smarty_Internal_Debug::display_debug($_template);
364:             }
365:             if ($merge_tpl_vars) {
366:                 // restore local variables
367:                 $_template->tpl_vars = $save_tpl_vars;
368:                 $_template->config_vars = $save_config_vars;
369:             }
370: 
371:             return;
372:         } else {
373:             if ($merge_tpl_vars) {
374:                 // restore local variables
375:                 $_template->tpl_vars = $save_tpl_vars;
376:                 $_template->config_vars = $save_config_vars;
377:             }
378:             // return fetched content
379:             return $_output;
380:         }
381:     }
382: 
383:     /**
384:      * displays a Smarty template
385:      *
386:      * @param string $template   the resource handle of the template file or template object
387:      * @param mixed  $cache_id   cache id to be used with this template
388:      * @param mixed  $compile_id compile id to be used with this template
389:      * @param object $parent     next higher level of Smarty variables
390:      */
391:     public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
392:     {
393:         // display template
394:         $this->fetch($template, $cache_id, $compile_id, $parent, true);
395:     }
396: 
397:     /**
398:      * test if cache is valid
399:      *
400:      * @param  string|object $template   the resource handle of the template file or template object
401:      * @param  mixed         $cache_id   cache id to be used with this template
402:      * @param  mixed         $compile_id compile id to be used with this template
403:      * @param  object        $parent     next higher level of Smarty variables
404:      *
405:      * @return boolean       cache status
406:      */
407:     public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
408:     {
409:         if ($template === null && $this instanceof $this->template_class) {
410:             return $this->cached->valid;
411:         }
412:         if (!($template instanceof $this->template_class)) {
413:             if ($parent === null) {
414:                 $parent = $this;
415:             }
416:             $template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
417:         }
418:         // return cache status of template
419:         return $template->cached->valid;
420:     }
421: 
422:     /**
423:      * creates a data object
424:      *
425:      * @param object $parent next higher level of Smarty variables
426:      *
427:      * @returns Smarty_Data data object
428:      */
429:     public function createData($parent = null)
430:     {
431:         return new Smarty_Data($parent, $this);
432:     }
433: 
434:     /**
435:      * Registers plugin to be used in templates
436:      *
437:      * @param  string   $type       plugin type
438:      * @param  string   $tag        name of template tag
439:      * @param  callback $callback   PHP callback to register
440:      * @param  boolean  $cacheable  if true (default) this fuction is cachable
441:      * @param  array    $cache_attr caching attributes if any
442:      *
443:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
444:      * @throws SmartyException              when the plugin tag is invalid
445:      */
446:     public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
447:     {
448:         if (isset($this->smarty->registered_plugins[$type][$tag])) {
449:             throw new SmartyException("Plugin tag \"{$tag}\" already registered");
450:         } elseif (!is_callable($callback)) {
451:             throw new SmartyException("Plugin \"{$tag}\" not callable");
452:         } else {
453:             $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
454:         }
455: 
456:         return $this;
457:     }
458: 
459:     /**
460:      * Unregister Plugin
461:      *
462:      * @param  string $type of plugin
463:      * @param  string $tag  name of plugin
464:      *
465:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
466:      */
467:     public function unregisterPlugin($type, $tag)
468:     {
469:         if (isset($this->smarty->registered_plugins[$type][$tag])) {
470:             unset($this->smarty->registered_plugins[$type][$tag]);
471:         }
472: 
473:         return $this;
474:     }
475: 
476:     /**
477:      * Registers a resource to fetch a template
478:      *
479:      * @param  string                $type     name of resource type
480:      * @param  Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
481:      *
482:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
483:      */
484:     public function registerResource($type, $callback)
485:     {
486:         $this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
487: 
488:         return $this;
489:     }
490: 
491:     /**
492:      * Unregisters a resource
493:      *
494:      * @param  string $type name of resource type
495:      *
496:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
497:      */
498:     public function unregisterResource($type)
499:     {
500:         if (isset($this->smarty->registered_resources[$type])) {
501:             unset($this->smarty->registered_resources[$type]);
502:         }
503: 
504:         return $this;
505:     }
506: 
507:     /**
508:      * Registers a cache resource to cache a template's output
509:      *
510:      * @param  string               $type     name of cache resource type
511:      * @param  Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
512:      *
513:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
514:      */
515:     public function registerCacheResource($type, Smarty_CacheResource $callback)
516:     {
517:         $this->smarty->registered_cache_resources[$type] = $callback;
518: 
519:         return $this;
520:     }
521: 
522:     /**
523:      * Unregisters a cache resource
524:      *
525:      * @param  string $type name of cache resource type
526:      *
527:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
528:      */
529:     public function unregisterCacheResource($type)
530:     {
531:         if (isset($this->smarty->registered_cache_resources[$type])) {
532:             unset($this->smarty->registered_cache_resources[$type]);
533:         }
534: 
535:         return $this;
536:     }
537: 
538:     /**
539:      * Registers object to be used in templates
540:      *
541:      * @param          $object_name
542:      * @param  object  $object_impl   the referenced PHP object to register
543:      * @param  array   $allowed       list of allowed methods (empty = all)
544:      * @param  boolean $smarty_args   smarty argument format, else traditional
545:      * @param  array   $block_methods list of block-methods
546:      *
547:      * @throws SmartyException
548:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
549:      */
550:     public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
551:     {
552:         // test if allowed methods callable
553:         if (!empty($allowed)) {
554:             foreach ((array) $allowed as $method) {
555:                 if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
556:                     throw new SmartyException("Undefined method or property '$method' in registered object");
557:                 }
558:             }
559:         }
560:         // test if block methods callable
561:         if (!empty($block_methods)) {
562:             foreach ((array) $block_methods as $method) {
563:                 if (!is_callable(array($object_impl, $method))) {
564:                     throw new SmartyException("Undefined method '$method' in registered object");
565:                 }
566:             }
567:         }
568:         // register the object
569:         $this->smarty->registered_objects[$object_name] =
570:             array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
571: 
572:         return $this;
573:     }
574: 
575:     /**
576:      * return a reference to a registered object
577:      *
578:      * @param  string $name object name
579:      *
580:      * @return object
581:      * @throws SmartyException if no such object is found
582:      */
583:     public function getRegisteredObject($name)
584:     {
585:         if (!isset($this->smarty->registered_objects[$name])) {
586:             throw new SmartyException("'$name' is not a registered object");
587:         }
588:         if (!is_object($this->smarty->registered_objects[$name][0])) {
589:             throw new SmartyException("registered '$name' is not an object");
590:         }
591: 
592:         return $this->smarty->registered_objects[$name][0];
593:     }
594: 
595:     /**
596:      * unregister an object
597:      *
598:      * @param  string $name object name
599:      *
600:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
601:      */
602:     public function unregisterObject($name)
603:     {
604:         if (isset($this->smarty->registered_objects[$name])) {
605:             unset($this->smarty->registered_objects[$name]);
606:         }
607: 
608:         return $this;
609:     }
610: 
611:     /**
612:      * Registers static classes to be used in templates
613:      *
614:      * @param         $class_name
615:      * @param  string $class_impl the referenced PHP class to register
616:      *
617:      * @throws SmartyException
618:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
619:      */
620:     public function registerClass($class_name, $class_impl)
621:     {
622:         // test if exists
623:         if (!class_exists($class_impl)) {
624:             throw new SmartyException("Undefined class '$class_impl' in register template class");
625:         }
626:         // register the class
627:         $this->smarty->registered_classes[$class_name] = $class_impl;
628: 
629:         return $this;
630:     }
631: 
632:     /**
633:      * Registers a default plugin handler
634:      *
635:      * @param  callable $callback class/method name
636:      *
637:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
638:      * @throws SmartyException              if $callback is not callable
639:      */
640:     public function registerDefaultPluginHandler($callback)
641:     {
642:         if (is_callable($callback)) {
643:             $this->smarty->default_plugin_handler_func = $callback;
644:         } else {
645:             throw new SmartyException("Default plugin handler '$callback' not callable");
646:         }
647: 
648:         return $this;
649:     }
650: 
651:     /**
652:      * Registers a default template handler
653:      *
654:      * @param  callable $callback class/method name
655:      *
656:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
657:      * @throws SmartyException              if $callback is not callable
658:      */
659:     public function registerDefaultTemplateHandler($callback)
660:     {
661:         if (is_callable($callback)) {
662:             $this->smarty->default_template_handler_func = $callback;
663:         } else {
664:             throw new SmartyException("Default template handler '$callback' not callable");
665:         }
666: 
667:         return $this;
668:     }
669: 
670:     /**
671:      * Registers a default template handler
672:      *
673:      * @param  callable $callback class/method name
674:      *
675:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
676:      * @throws SmartyException              if $callback is not callable
677:      */
678:     public function registerDefaultConfigHandler($callback)
679:     {
680:         if (is_callable($callback)) {
681:             $this->smarty->default_config_handler_func = $callback;
682:         } else {
683:             throw new SmartyException("Default config handler '$callback' not callable");
684:         }
685: 
686:         return $this;
687:     }
688: 
689:     /**
690:      * Registers a filter function
691:      *
692:      * @param  string   $type filter type
693:      * @param  callback $callback
694:      *
695:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
696:      */
697:     public function registerFilter($type, $callback)
698:     {
699:         $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
700: 
701:         return $this;
702:     }
703: 
704:     /**
705:      * Unregisters a filter function
706:      *
707:      * @param  string   $type filter type
708:      * @param  callback $callback
709:      *
710:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
711:      */
712:     public function unregisterFilter($type, $callback)
713:     {
714:         $name = $this->_get_filter_name($callback);
715:         if (isset($this->smarty->registered_filters[$type][$name])) {
716:             unset($this->smarty->registered_filters[$type][$name]);
717:         }
718: 
719:         return $this;
720:     }
721: 
722:     /**
723:      * Return internal filter name
724:      *
725:      * @param  callback $function_name
726:      *
727:      * @return string   internal filter name
728:      */
729:     public function _get_filter_name($function_name)
730:     {
731:         if (is_array($function_name)) {
732:             $_class_name = (is_object($function_name[0]) ?
733:                 get_class($function_name[0]) : $function_name[0]);
734: 
735:             return $_class_name . '_' . $function_name[1];
736:         } else {
737:             return $function_name;
738:         }
739:     }
740: 
741:     /**
742:      * load a filter of specified type and name
743:      *
744:      * @param  string $type filter type
745:      * @param  string $name filter name
746:      *
747:      * @throws SmartyException if filter could not be loaded
748:      */
749:     public function loadFilter($type, $name)
750:     {
751:         $_plugin = "smarty_{$type}filter_{$name}";
752:         $_filter_name = $_plugin;
753:         if ($this->smarty->loadPlugin($_plugin)) {
754:             if (class_exists($_plugin, false)) {
755:                 $_plugin = array($_plugin, 'execute');
756:             }
757:             if (is_callable($_plugin)) {
758:                 $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
759: 
760:                 return true;
761:             }
762:         }
763:         throw new SmartyException("{$type}filter \"{$name}\" not callable");
764:     }
765: 
766:     /**
767:      * unload a filter of specified type and name
768:      *
769:      * @param  string $type filter type
770:      * @param  string $name filter name
771:      *
772:      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
773:      */
774:     public function unloadFilter($type, $name)
775:     {
776:         $_filter_name = "smarty_{$type}filter_{$name}";
777:         if (isset($this->smarty->registered_filters[$type][$_filter_name])) {
778:             unset ($this->smarty->registered_filters[$type][$_filter_name]);
779:         }
780: 
781:         return $this;
782:     }
783: 
784:     /**
785:      * preg_replace callback to convert camelcase getter/setter to underscore property names
786:      *
787:      * @param  string $match match string
788:      *
789:      * @return string replacemant
790:      */
791:     private function replaceCamelcase($match)
792:     {
793:         return "_" . strtolower($match[1]);
794:     }
795: 
796:     /**
797:      * Handle unknown class methods
798:      *
799:      * @param string $name unknown method-name
800:      * @param array  $args argument array
801:      *
802:      * @throws SmartyException
803:      */
804:     public function __call($name, $args)
805:     {
806:         static $_prefixes = array('set' => true, 'get' => true);
807:         static $_resolved_property_name = array();
808:         static $_resolved_property_source = array();
809: 
810:         // method of Smarty object?
811:         if (method_exists($this->smarty, $name)) {
812:             return call_user_func_array(array($this->smarty, $name), $args);
813:         }
814:         // see if this is a set/get for a property
815:         $first3 = strtolower(substr($name, 0, 3));
816:         if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') {
817:             if (isset($_resolved_property_name[$name])) {
818:                 $property_name = $_resolved_property_name[$name];
819:             } else {
820:                 // try to keep case correct for future PHP 6.0 case-sensitive class methods
821:                 // lcfirst() not available < PHP 5.3.0, so improvise
822:                 $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
823:                 // convert camel case to underscored name
824:                 $property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name);
825:                 $_resolved_property_name[$name] = $property_name;
826:             }
827:             if (isset($_resolved_property_source[$property_name])) {
828:                 $_is_this = $_resolved_property_source[$property_name];
829:             } else {
830:                 $_is_this = null;
831:                 if (property_exists($this, $property_name)) {
832:                     $_is_this = true;
833:                 } elseif (property_exists($this->smarty, $property_name)) {
834:                     $_is_this = false;
835:                 }
836:                 $_resolved_property_source[$property_name] = $_is_this;
837:             }
838:             if ($_is_this) {
839:                 if ($first3 == 'get') {
840:                     return $this->$property_name;
841:                 } else {
842:                     return $this->$property_name = $args[0];
843:                 }
844:             } elseif ($_is_this === false) {
845:                 if ($first3 == 'get') {
846:                     return $this->smarty->$property_name;
847:                 } else {
848:                     return $this->smarty->$property_name = $args[0];
849:                 }
850:             } else {
851:                 throw new SmartyException("property '$property_name' does not exist.");
852:            }
853:         }
854:         if ($name == 'Smarty') {
855:             throw new SmartyException("PHP5 requires you to call __construct() instead of Smarty()");
856:         }
857:         // must be unknown
858:         throw new SmartyException("Call of unknown method '$name'.");
859:     }
860: }
861: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen