publicfunctionfetch($tpl = null) { // make sure we have a template source to work with if (is_null($tpl)) { $tpl = $this->__config['template']; }
// get a path to the compiled template script $result = $this->template($tpl);
// did we get a path? if (! $result || $this->isError($result)) { // no. return the error result. return $result; } else { // yes. execute the template script. move the script-path // out of the local scope, then clean up the local scope to // avoid variable name conflicts. $this->__config['fetch'] = $result; unset($result); unset($tpl); // are we doing extraction? if ($this->__config['extract']) { // pull variables into the local scope. extract(get_object_vars($this), EXTR_REFS); } // buffer output so we can return it instead of displaying. ob_start(); // are we using filters? if ($this->__config['filters']) { // use a second buffer to apply filters. we used to set // the ob_start() filter callback, but that would // silence errors in the filters. Hendy Irawan provided // the next three lines as a "verbose" fix. ob_start(); include$this->__config['fetch']; echo$this->applyFilters(ob_get_clean()); } else { // no filters being used. include$this->__config['fetch']; } // reset the fetch script value, get the buffer, and return. $this->__config['fetch'] = null; return ob_get_clean(); } }
protectedfunctionfindFile($type, $file) { // get the set of paths $set = $this->__config[$type . '_path'];
// start looping through the path set foreach ($set as $path) { // get the path to the file $fullname = $path . $file;
// is the path based on a stream? if (strpos($path, '://') === false) { // not a stream, so do a realpath() to avoid // directory traversal attempts on the local file // system. Suggested by Ian Eure, initially // rejected, but then adopted when the secure // compiler was added. $path = realpath($path); // needed for substr() later
$fullname = realpath($fullname);
} // the substr() check added by Ian Eure to make sure // that the realpath() results in a directory registered // with Savant so that non-registered directores are not // accessible via directory traversal attempts. if (file_exists($fullname) && is_readable($fullname) && substr($fullname, 0, strlen($path)) == $path) { return $fullname; } } // could not find the file in the set of paths returnfalse;