Source for file include.php

Documentation is available at include.php

  1. <?php
  2.  
  3. /**
  4.  * Inserts another template into the current one
  5.  * <pre>
  6.  *  * file : the resource name of the template
  7.  *  * cache_time : cache length in seconds
  8.  *  * cache_id : cache identifier for the included template
  9.  *  * compile_id : compilation identifier for the included template
  10.  *  * data : data to feed into the included template, it can be any array and will default to $_root (the current data)
  11.  *  * assign : if set, the output of the included template will be saved in this variable instead of being output
  12.  *  * rest : any additional parameter/value provided will be added to the data array
  13.  * </pre>
  14.  * This software is provided 'as-is', without any express or implied warranty.
  15.  * In no event will the authors be held liable for any damages arising from the use of this software.
  16.  *
  17.  * This file is released under the LGPL
  18.  * "GNU Lesser General Public License"
  19.  * More information can be found here:
  20.  * {@link http://www.gnu.org/copyleft/lesser.html}
  21.  *
  22.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  23.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  24.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  25.  * @link       http://dwoo.org/
  26.  * @version    0.9.1
  27.  * @date       2008-05-30
  28.  * @package    Dwoo
  29.  */
  30. function Dwoo_Plugin_include(Dwoo $dwoo$file$cache_time null$cache_id null$compile_id null$data '_root'$assign nullarray $rest array())
  31. {
  32.     if ($file === ''{
  33.         return;
  34.     }
  35.  
  36.     if (preg_match('#^([a-z]{2,}):(.*)#i'$file$m)) {
  37.         $resource $m[1];
  38.         $identifier $m[2];
  39.     else {
  40.         // get the current template's resource
  41.         $resource $dwoo->getTemplate()->getResourceName();
  42.         $identifier $file;
  43.     }
  44.  
  45.     if ($resource === 'file' && $policy $dwoo->getSecurityPolicy()) {
  46.         while (true{
  47.             if (preg_match('{^([a-z]+?)://}i'$identifier)) {
  48.                 throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$identifier.'</em>.');
  49.             }
  50.  
  51.             $identifier realpath($identifier);
  52.             $dirs $policy->getAllowedDirectories();
  53.             foreach ($dirs as $dir=>$dummy{
  54.                 if (strpos($identifier$dir=== 0{
  55.                     break 2;
  56.                 }
  57.             }
  58.             throw new Dwoo_Security_Exception('The security policy prevents you to read <em>'.$identifier.'</em>');
  59.         }
  60.     }
  61.  
  62.     try {
  63.         $include $dwoo->templateFactory($resource$identifier$cache_time$cache_id$compile_id);
  64.     catch (Dwoo_Exception $e{
  65.         $dwoo->triggerError('Include : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>'E_USER_WARNING);
  66.     }
  67.  
  68.     if ($include === null{
  69.         return;
  70.     elseif ($include === false{
  71.         $dwoo->triggerError('Include : Including "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.'E_USER_WARNING);
  72.     }
  73.  
  74.     if ($dwoo->isArray($data)) {
  75.         $vars $data;
  76.     elseif ($dwoo->isArray($cache_time)) {
  77.         $vars $cache_time;
  78.     else {
  79.         $vars $dwoo->readVar($data);
  80.     }
  81.  
  82.     if (count($rest)) {
  83.         $vars $rest $vars;
  84.     }
  85.  
  86.     $out $dwoo->get($include$vars);
  87.  
  88.     if ($assign !== null{
  89.         $dwoo->assignInScope($out$assign);
  90.     else {
  91.         return $out;
  92.     }
  93. }

Documentation generated on Sat, 28 Jun 2008 01:38:28 +0200 by phpDocumentor 1.4.0