function getCacheFile() { $cache_file = VAR_DIR . '/resolvers/' . get_class($this->_resolver) . '.php'; Fs :: mkdir(VAR_DIR . '/resolvers/'); return $cache_file; }
function writeTemplateFile($file, $data) { if(!is_dir(dirname($file))) Fs :: mkdir(dirname($file), 0777, true); $fp = fopen($file, "wb"); if (fwrite($fp, $data, strlen($data))) fclose($fp); }
/** * Class constructor * * @param array $options Specific options: array('file'=>file_path) or array(file_path) */ public function __construct($options = array()) { if (isset($options[0])) { $options['file'] = Fs::file($options[0]); } elseif (isset($options['file']) && !$options['file'] instanceof Fs_Node) { $options['file'] = Fs::file($options['file']); } parent::__construct($options); }
/** * Class constructor * * @param array $options */ public function __construct($options = array()) { if (isset($options[0])) { $options['template'] = Fs::file($options[0]); } elseif (isset($options['file'])) { $options['template'] = Fs::file($options['file']); } unset($options[0], $options['file']); parent::__construct($options); }
/** * Class constructor. * * @param string $path */ public function __construct($path) { parent::__construct($path); if (file_exists($path) && !is_file($path)) { throw new Fs_Exception("File '{$path}' is not a regular file, but a " . Fs::typeOfNode($path, Fs::DESCRIPTION)); } if (is_link($path) xor $this instanceof Fs_Symlink) { throw new Fs_Exception("File '{$path}' is " . ($this instanceof Fs_Symlink ? 'not ' : '') . "a symlink"); } }
private function get_models () { if (!isset($this->models)) { // Each model must have its own php-file named by its Model-extended class $this->models = Fs::dir($this->models_path, '(.+)\.php$', '\1'); } return $this->models; }
/** * Class constructor. * * @param string $path */ public function __construct($path) { parent::__construct($path); if (file_exists($path) && filetype(realpath($path)) != 'unknown') { throw new Fs_Exception("File '{$path}' is not a file with an unknown type, but a " . Fs::typeOfNode($path, Fs::DESCRIPTION)); } if (is_link($path) xor $this instanceof Fs_Symlink) { throw new Fs_Exception("File '{$path}' is " . ($this instanceof Fs_Symlink ? 'not ' : '') . "a symlink."); } }
public function getCache() { if ($this->cache) { return $this->cache; } include_once 'Cache/Lite.php'; include_once LIMB_DIR . '/class/lib/system/Fs.class.php'; Fs::mkdir(VAR_DIR . '/shipping_options'); $options = array('cacheDir' => VAR_DIR . '/shipping_options/', 'lifeTime' => $this->cache_life_time); $this->cache = new CacheLite($options); return $this->cache; }
function _removeFileCache($group = false, $key = false) { if($key) { @unlink($this->_getCacheFilePath($group, $key)); } else { $files = Fs :: find($this->cache_dir, 'f', '~^' . preg_quote($this->_getCacheFilePrefix($group)) . '~'); foreach($files as $file) @unlink($file); } }
public function store($disk_file_path) { if (!file_exists($disk_file_path)) { throw new FileNotFoundException('file not found', $disk_file_path); } srand(time()); $media_id = md5(uniqid(rand())); Fs::mkdir(MEDIA_DIR); $media_file = $this->getMediaFilePath($media_id); if (!copy($disk_file_path, $media_file)) { throw new IOException('copy failed', array('dst' => $media_file, 'src' => $disk_file_path)); } return $media_id; }
function write($log_file_data, $string) { $log_dir = $log_file_data[0]; $log_name = $log_file_data[1]; $file_name = $log_dir . $log_name; if (!is_dir($log_dir)) Fs :: mkdir($log_dir, 0775, true); $oldumask = umask(0); $file_existed = file_exists($file_name); $log_file = fopen($file_name, 'a'); if ($log_file) { $time = gmstrftime("%b %d %Y %H:%M:%S", time()); $notice = '[ ' . $time . " ]\n"; $toolkit =& Limb :: toolkit(); $user =& $toolkit->getUser(); if(($user_id = $user->getId()) != DEFAULT_USER_ID) $notice .= '[ ' . $user_id . ' ] [ ' . $user->getLogin() . ' ] [ ' . $user->get('email', '') . ' ] '; $notice .= '[' . Sys::clientIp() . '] [' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n"; fwrite($log_file, $notice); fclose($log_file ); if (!$file_existed) chmod($file_name, 0664); umask($oldumask); $result = true; } else { umask($oldumask); return throw_error(new IOException("Cannot open log file '$file_name' for writing\n" . "The web server must be allowed to modify the file.\n" . "File logging for '$file_name' is disabled.")); } return $result; }
function testCachedDiskFiles() { $cache = new CacheFilePersister('whatever'); $cache_dir = $cache->getCacheDir(); $items = Fs :: ls($cache_dir); $this->assertEqual(sizeof($items), 0); $cache->put(1, $cache_value = 'value'); $items = Fs :: ls($cache_dir); $this->assertEqual(sizeof($items), 1); $this->assertEqual($cache->get(1), $cache_value); $cache->flushAll(); rmdir($cache_dir); }
function getClassesList() { $contents = array_merge( Fs :: ls(LIMB_DIR . '/class/core/site_objects/'), Fs :: ls(LIMB_APP_DIR . '/class/core/site_objects/') ); $classes_list = array(); foreach($contents as $file_name) { if (substr($file_name, -10, 10) == '.class.php') { $classes_list[] = substr($file_name, 0, strpos($file_name, '.')); } } return $classes_list; }
/** * Returns Fs_Node of canonicalized absolute pathname, resolving symlinks. * Unlike the realpath() PHP function, this returns a best-effort for non-existent files. * * Use Fs::NO_DEREFERENCE to not dereference. * * @param int $flags Fs::% options * @return Fs_Node * @throws Fs_Exception if Fs::ALWAYS_FOLLOW is not set */ public function realpath($flags = 0) { if ($flags & Fs::NO_DEREFERENCE) { $target = Fs::canonicalize($this->target(), dirname($this->_path)); if (is_link($target)) { return new static($target); } if (~$flags & Fs::ALWAYS_FOLLOW) { throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': File is a broken symlink."); } return Fs::unknown($target); } else { $file = $this->realpathBestEffort($flags); if (!$file) { throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': Too many levels of symbolic links."); } return $file; } }
/** * Class constructor * * @param string $path OPTIONAL * @param array $options */ public function __construct($path, $options = array()) { if (is_array($path)) { $options = $path + $options; $path = null; if (isset($options['driver'])) { if (isset($options[0])) { if (!isset($options['path'])) { $options['path'] = $options[0]; } if (!isset($options['ext'])) { $options['ext'] = $options['driver']; } unset($options[0]); } else { $options[0] = $options['driver']; } } } if (isset($options[0])) { if (strpos($options[0], ':') !== false) { list($options['ext'], $options['path']) = explode(':', $options[0], 2); } else { $key = !isset($options['ext']) && strpos($options[0], '.') === false && strpos($options[0], '/') === false ? 'ext' : 'path'; if (!isset($options[$key])) { $options[$key] = $options[0]; } } } $this->_path = isset($path) ? Fs::file($path) : (isset($options['path']) ? Fs::file($options['path']) : null); $ext = isset($options['ext']) ? $options['ext'] : (isset($this->_path) ? $this->_path->extension() : null); if (isset($options['transformer'])) { $this->_transformer = $options['transformer'] instanceof Transformer ? $options['transformer'] : Transform::with($options['transformer']); } elseif (!empty($ext)) { $this->_transformer = Transform::from($ext); } $values = isset($this->_path) && isset($this->_transformer) ? $this->_transformer->process($this->_path) : array(); \ArrayObject::__construct(&$values, \ArrayObject::ARRAY_AS_PROPS); }
function testRecursiveFind() { $this->_createFileSystem(); $res = Fs :: recursiveFind(TEST_DIR_ABSOLUTE_PATH . '/tmp/', 'test\d_1'); sort($res); $this->assertEqual( $res, array( Fs :: cleanPath(TEST_DIR_ABSOLUTE_PATH . '/tmp/test1_1'), Fs :: cleanPath(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey/test3_1'), Fs :: cleanPath(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/test2_1'), ) ); $this->_removeFileSystem(); }
/** * Create a symlink and return the Fs interface. * * @param string $target * @param string $link * @param int $flags Fs::% options as binary set * @param string $default Type for $target if file does not exist. * @return Fs_Node */ public static function symlink($target, $link, $flags = 0, $default = null) { if (is_link($link) && $flags & self::OVERWRITE) { unlink($link); } if (!@symlink($target, $link)) { throw new Fs_Exception("Failed to create symlink '{$link}' to '{$target}'", error_get_last()); } return Fs::get($link, $default); }
function _createTmpMedia($media_id) { Fs::mkdir(MEDIA_DIR); touch(MEDIA_DIR . $media_id . '.media'); }
function _loadCache() { $this->reset(); $cache_dir = $this->cache_dir; Fs :: mkdir($cache_dir); if(catch_error('IOException', $e)) { Debug :: writeWarning('could not create cache directory for ini', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('cache_dir' => $cache_dir)); $this->_parse(); return; } if($override_file = $this->getOverrideFile()) $this->cache_file = $this->cache_dir . md5($override_file) . '.php'; else $this->cache_file = $this->cache_dir . md5($this->file_path) . '.php'; if ($this->_isCacheValid()) { $charset = null; $group_values = array(); include($this->cache_file); $this->charset = $charset; $this->group_values = $group_values; unset($group_values); } else { $this->_parse(); $this->_saveCache(); } }
protected function _generateDebugEditorLinkHtml($code, $file_path) { if(!defined('WS_SCRIPT_WRITTEN')) { $code->writeHtml(' <SCRIPT LANGUAGE="JScript"> function run_template_editor(path) { WS = new ActiveXObject("WScript.shell"); WS.exec("uedit32.exe " + path); } </SCRIPT>'); define('WS_SCRIPT_WRITTEN', true); } if(Fs :: isPathRelative($file_path)) { $items = Fs :: explodePath($_SERVER['PATH_TRANSLATED']); array_pop($items); $file_path = Fs :: path($items) . Fs :: separator() . $file_path; } $file_path = addslashes(Fs :: cleanPath($file_path)); $code->writeHtml("<a href='#'><img onclick='runTemplateEditor(\"{$file_path}\");' src='/shared/images/i.gif' alt='{$file_path}' title='{$file_path}' border='0'></a>"); }
function _doWalkDir($item, $separator, $function_def, &$return_params, $params, $include_first, $level=0) { if($level > 0 || ($level == 0 && $include_first)) call_user_func_array($function_def, array('dir' => dirname($item), 'file' => basename($item), 'path' => $item, 'params' => $params, 'return_params' => &$return_params)); if(!is_dir($item)) return; $handle = opendir($item); while(($file = readdir($handle)) !== false) { if (($file == '.') || ($file == '..')) continue; Fs :: _doWalkDir($item . $separator . $file, $separator, $function_def, $return_params, $params, $level + 1); } closedir($handle); }
public function getCacheSize() { Fs :: mkdir(PAGE_CACHE_DIR); $files = Fs :: findSubitems(PAGE_CACHE_DIR, 'f', '~^[^p]~'); $size = 0; foreach($files as $file) { $size += (filesize($file)); } return $size; }
/** * Execute file and return content of stdout. * * @param Parameters will be escaped and passed as arguments. * @return string * @throws Fs_Exception if execution is not possible. * @throws ExecException if execution fails. */ public function exec() { throw new Fs_Exception("Unable to execute '{$this->_path}': This is not a regular file, but a " . Fs::typeOfNode($this, Fs::DESCRIPTION)); }
static public function isPathRelative($file_path, $os_type = null) { return !Fs :: isPathAbsolute($file_path, $os_type); }
function files_list ($root, $path = '') { $fb_root = url(self::$root, $root); self::$context['filebrowser'] = true; $this->context_breadcrumbs('Filebrowser', $fb_root); $files = array(); // Fix empty path $path = preg_replace('#(^/)|(/$)#', '', $path); $real_path = join_path(Frix::config('MEDIA_ROOT'), $this->file_manager_path, $path); if ($path) { $current_path = $fb_root; $parts = explode('/', $path); foreach ($parts as $part) { $current_path = url($current_path, $part); $this->context_breadcrumbs($part, $current_path); } // Remove current dir array_pop($parts); $files[] = array( 'name' => '.. (' . end($parts) . ')', 'class' => 'up', 'size' => ' ', 'is_dir' => true, 'is_empty' => false, 'link' => url($fb_root, dirname($path)), ); } if (!is_dir($real_path)) { throw new Http404Exception; } if ($_POST['new_dir']) { return $this->files_new_dir($real_path); } elseif ($_POST['new_file']) { return $this->files_new($real_path); } elseif ($_GET['del']) { return $this->files_delete($real_path); } if ($_GET['err']) { self::$context['msg_type'] = 'err'; if ($_GET['err'] == 'bad_upload') { load('Upload'); self::$context['msg'] = Upload::$errors[$_GET['code']]; } else { $msg = array( 'err_upload' => 'Couldn\'t save file, check your permissions.', 'bad_dir' => 'Invalid or forbidden folder name!', 'file_exists' => 'File or folder already exists, try a different name.', 'del_dir' => 'Couldn\'t remove folder, check if it is empty.', 'del_file' => 'Couldn\'t remove folder, check your permissions.', 'not_found' => 'Object not found!', ); self::$context['msg'] = $msg[$_GET['err']]; } } elseif ($_GET['msg']) { $msg = array( 'new_dir' => 'Folder created sucessfully!', 'del_dir' => 'Folder removed sucessfully!', 'del_file' => 'File removed sucessfully!', 'new_file' => 'File uploaded sucessfully!', ); self::$context['msg'] = $msg[$_GET['msg']]; self::$context['msg_type'] = 'ok'; } // Load a list of files not starting with a dot $file_list = Fs::dir($real_path, '^[^.].*'); $base_link = url(Frix::config('MEDIA_URL'), $this->file_manager_path, $path); foreach ($file_list as $file) { $full_path = join_path($real_path, $file); $file_obj = array( 'name' => $file, ); if (is_dir($full_path)) { $file_obj['size'] = ' '; $file_obj['link'] = url($fb_root, $path, $file); $file_obj['is_dir'] = true; $file_obj['is_empty'] = Fs::is_empty_dir($full_path); $file_obj['class'] = 'dir'; } else { $file_obj['size'] = Fs::format_size(Fs::file_size($full_path), 1); $file_obj['link'] = url($base_link, $file); $file_obj['target'] = '_blank'; $file_obj['class'] = Fs::extension($file); } $files[] = $file_obj; } self::$context['files'] = $files; $t = new Template('frix/admin/filebrowser/list'); echo $t->render(self::$context); }
function _cleanUp() { Fs :: rm(IMAGE_CACHE_DIR); Fs :: rm(MEDIA_DIR); }
function _cleanUp() { Fs::rm(MEDIA_DIR); }
function _writeSimpleCache($file_id, $contents) { Fs :: mkdir(PAGE_CACHE_DIR); $f = fopen(PAGE_CACHE_DIR . $file_id, 'w'); fwrite($f, $contents); fclose($f); }
} /** * Transform data and save the result into a file. * * @param string $filename File name * @param mixed $data * @param int $flags Fs::RECURSIVE and/or FILE_% flags as binary set. */ function save($filename, $data = null, $flags = 0) { $out = $this->process($data); if (!is_scalar($out) && !(is_object($out) && method_exists($out, '__toString'))) { throw new Exception("Unable to save data to '{$filename}': Transformation returned a non-scalar value of type '" . gettype($out) . "'."); } if (!Fs::file($filename)->putContents((string) $out, $flags)) { throw new Exception("Failed to create file {$filename}."); }
function &_getRecursiveFileList($directory, $file_test_function) { if(!is_dir($directory)) return array(); $dh = opendir($directory); $file_list = array(); while ($file = readdir($dh)) { $file_path = $directory . '/' . $file; if (0 === strpos($file, '.')) continue; if (is_dir($file_path)) { $file_list = array_merge($file_list, $this->_getRecursiveFileList( $file_path, $file_test_function)); } if ($file_test_function[0]->$file_test_function[1]($file)) { $file_list[] = Fs :: normalizePath($file_path); } } closedir($dh); sort($file_list); return $file_list; }