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
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.
12
* @author Jordi Boggiano <j.boggiano@seld.be>
13
* @copyright Copyright (c) 2008, Jordi Boggiano
14
* @license http://dwoo.org/LICENSE Modified BSD License
15
* @link http://dwoo.org/
20
function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null)
26
if ($policy = $dwoo->getSecurityPolicy()) {
28
if (preg_match('{^([a-z]+?)://}i', $file)) {
29
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
32
$file = realpath($file);
33
$dirs = $policy->getAllowedDirectories();
34
foreach ($dirs as $dir=>$dummy) {
35
if (strpos($file, $dir) === 0) {
39
return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
42
$file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
44
$out = file_get_contents($file);
46
if ($assign === null) {
49
$dwoo->assignInScope($out, $assign);