Source for file fetch.php

Documentation is available at fetch.php

  1. <?php
  2.  
  3. /**
  4.  * Reads a file
  5.  * <pre>
  6.  *  * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons)
  7.  *  * assign : if set, the file will be saved in this variable instead of being output
  8.  * </pre>
  9.  * This software is provided 'as-is', without any express or implied warranty.
  10.  * In no event will the authors be held liable for any damages arising from the use of this software.
  11.  *
  12.  * This file is released under the LGPL
  13.  * "GNU Lesser General Public License"
  14.  * More information can be found here:
  15.  * {@link http://www.gnu.org/copyleft/lesser.html}
  16.  *
  17.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  18.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  19.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  20.  * @link       http://dwoo.org/
  21.  * @version    0.9.1
  22.  * @date       2008-05-30
  23.  * @package    Dwoo
  24.  */
  25. function Dwoo_Plugin_fetch(Dwoo $dwoo$file$assign null)
  26. {
  27.     if ($file === ''{
  28.         return;
  29.     }
  30.  
  31.     if ($policy $dwoo->getSecurityPolicy()) {
  32.         while (true{
  33.             if (preg_match('{^([a-z]+?)://}i'$file)) {
  34.                 return $dwoo->triggerError('The security policy prevents you to read files from external sources.'E_USER_WARNING);
  35.             }
  36.  
  37.             $file realpath($file);
  38.             $dirs $policy->getAllowedDirectories();
  39.             foreach ($dirs as $dir=>$dummy{
  40.                 if (strpos($file$dir=== 0{
  41.                     break 2;
  42.                 }
  43.             }
  44.             return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>'E_USER_WARNING);
  45.         }
  46.     }
  47.     $file str_replace(array("\t""\n""\r")array('\\t''\\n''\\r')$file);
  48.  
  49.     $out file_get_contents($file);
  50.  
  51.     if ($assign !== null{
  52.         $dwoo->assignInScope($out$assign);
  53.     else {
  54.         return $out;
  55.     }
  56. }

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