* @package Mammut\IO */ /* $Id$ */ (defined('MAMMUT') && (basename(__FILE__) != basename($_SERVER['PHP_SELF']))) or die('ACCESS DENIED'); /** * Extended file_exists. * * This function works exactly like native file_exists(), but takes the include path into * account * * @see file_exists() * @since 1.0.0 * @param string $filename * to the file or directory. * @return boolean true if file or directory exists, false otherwise */ function include_exists($filename) { if(@file_exists($filename)) return true; $incpath = explode(PATH_SEPARATOR, get_include_path()); $allowedPath = ini_get('open_basedir'); if(!empty($allowedPath)) $allowedPath = explode(PATH_SEPARATOR, $allowedPath); if(!empty($allowedPath)) { // remove not allowed paths from include path foreach($incpath as $key=>$path) { if($path[0] == '.' || $path[0] != DIRECTORY_SEPARATOR) continue; $found = false; foreach($allowedPath as $basedir) { if(strpos($path, $basedir) === 0) $found = true; } if(!$found) unset($incpath[$key]); } } foreach($incpath as $path) { if(file_exists($path . DIRECTORY_SEPARATOR . $filename)) return true; } return false; } /** * Runs a scriptfile and returns the output. * Only a specific set of variables is avaible in the script. THIS IS NOT FOR SECURITY, * only to prevent coding errors (global $var is still possible) * * @param string $filename * the script to run * @param array $localvars * a list of local variables */ function get_script_output($filename, array $localvars = array()) { if(count($localvars) > 0) extract($localvars); unset($localvars); ob_start(); include ($filename); return ob_get_clean(); } /** * Recrusively deletes a directory. * * @param string $path * the directory to delete */ function rmdir_deep($path) { if($handle = opendir($path)) { while(false !== ($file = readdir($handle))) { if(!in_array($file, array('.','..'))) { if(is_file($path . DIRECTORY_SEPARATOR . $file)) @unlink($path . DIRECTORY_SEPARATOR . $file); if(is_dir($path . DIRECTORY_SEPARATOR . $file)) { rmdir_deep($path . DIRECTORY_SEPARATOR . $file); @rmdir($path . DIRECTORY_SEPARATOR . $file); } } } } }