source: branches/0.4/web/addons/job_monarch/dwoo/plugins/builtin/functions/fetch.php @ 755

Last change on this file since 755 was 755, checked in by ramonb, 11 years ago
  • add Dwoo
File size: 1.5 KB
Line 
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 * @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/
16 * @version    1.1.0
17 * @date       2009-07-18
18 * @package    Dwoo
19 */
20function Dwoo_Plugin_fetch(Dwoo_Core $dwoo, $file, $assign = null)
21{
22        if ($file === '') {
23                return;
24        }
25
26        if ($policy = $dwoo->getSecurityPolicy()) {
27                while (true) {
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);
30                        }
31
32                        $file = realpath($file);
33                        $dirs = $policy->getAllowedDirectories();
34                        foreach ($dirs as $dir=>$dummy) {
35                                if (strpos($file, $dir) === 0) {
36                                        break 2;
37                                }
38                        }
39                        return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
40                }
41        }
42        $file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
43
44        $out = file_get_contents($file);
45
46        if ($assign === null) {
47                return $out;
48        }
49        $dwoo->assignInScope($out, $assign);
50}
Note: See TracBrowser for help on using the repository browser.