public function add_dir($path) { $this->add_empty_dir($path); foreach (IO_FS::Dir($path) as $entry) { $_path = $entry->path; $this->add($_path); } return $this; }
public function copy_value($from, $to, $name, $data) { $code = $this->temp_code(); $from_dir = $this->dir_path($from, $code, $name, $data); $to_dir = $this->dir_path($to, $code, $name, $data); IO_FS::mkdir($to_dir, null, true); IO_FS::Dir($from_dir)->copy_to($to_dir); return parent::copy_value($from, $to, $name, $data); }
public function read_dir($dir) { $out = array(); if (!is_dir($dir)) { return $out; } foreach (IO_FS::Dir($dir) as $entry) { if ($this->validate_path($entry->path)) { $out[] = $entry->path; } } return $out; }
public function get_all_keys() { $dir = IO_FS::Dir($this->path); $query = IO_FS::Query()->recursive(); $keys = array(); foreach ($query->apply_to($dir) as $name => $object) { $key = trim(str_replace($this->path, '', $name), '/'); $key = str_replace('/', ':', $key); if ($this->has($key)) { $keys[] = $key; } } return $keys; }
public static function find_all_modules() { $dir = __DIR__; Core::load('IO.FS'); $q = IO_FS::Query()->glob('*.php')->recursive(true); $result = array(); foreach ($q->apply_to(IO_FS::Dir($dir)) as $name => $file) { $real_path = realpath($file); $path_to_file = trim(str_replace($dir, '', $name), '/ '); $module = str_replace('.php', '', $path_to_file); $module = str_replace('/', '.', $module); $result[$module] = $real_path; } Core::load('Events'); Events::call('core.find_all_modules', $result); return $result; }
public function change($id, $data, $item) { if (is_object($item)) { $item->id = $id; } $file = $_FILES['value']; $name = trim($file['name']); $tmp_name = trim($file['tmp_name']); if ($tmp_name != '') { $dir = "./" . Core::option('files_name') . "/vars/{$id}"; CMS::mkdirs($dir, 0775); foreach (IO_FS::Dir($dir) as $f) { @IO_FS::rm($f->path); } $name = CMS::translit(mb_strtolower($name)); $name = preg_replace('{\\s+}', '_', $name); $name = trim(preg_replace('{[^a-z0-9_\\.\\-]}', '', $name)); if ($name == '') { $name = 'noname'; } if ($name[0] == '.') { $name = "noname.{$name}"; } move_uploaded_file($tmp_name, "{$dir}/{$name}"); chmod("{$dir}/{$name}", 0775); $rc = CMS::vars()->on_change_call($id, $value, $data); if (is_string($rc)) { $item->valuesrc = $data['valuesrc']; return $rc; } $item->value = "{$dir}/{$name}"; $item->update_value(); } }
public function action_aimages($id) { if ($this->image_list_from_gallery) { return $this->action_gimages($id); } if (!$this->attaches_dir) { die; } $id = (int) $id; $dir = "./{$this->attaches_dir}/" . $this->iddir($id); $ar = array(); if (IO_FS::exists($dir)) { foreach (IO_FS::Dir($dir) as $f) { $fp = $f->path; if ($m = Core_Regexps::match_with_results('{/([^/]+)$}', $fp)) { $fp = $m[1]; } $ar[] = '["' . $fp . '","' . $this->file_url($f->path) . '"]'; } } echo 'var tinyMCEImageList = new Array(' . implode(',', $ar) . ');'; die; }
/** * @param string $path */ public function __construct($path) { $this->path = (string) $path; $this->dir_iterator = IO_FS::Dir($this->path)->query(IO_FS::Query()->glob('*.php')->recursive(true)); $this->dir_iterator->rewind(); $this->current = Dev_Source::Module($this->module_name($this->dir_iterator->current()->path)); }
protected function hash_dir($path, $prefix = '', $item = false) { $out = array(); foreach (IO_FS::Dir($path) as $file) { $fp = $prefix == '' ? $file->name : "{$prefix}/{$file->name}"; if ($fp == 'www') { $fp = CMS::www(); } if (is_dir($file->path)) { $files = $this->hash_dir($file->path, $fp, $item); foreach ($files as $key => $value) { $out[$key] = $value; } } else { if ($item && Core_Regexps::match('{\\.(php|phtml)$}', $file)) { $version = trim($item['version']); if ($version != '') { $content = file_get_contents($file->path); $content = str_replace('%%{version}', $version, $content); file_put_contents($file->path, $content); } } $out[$fp] = array('path' => $file->path, 'hash' => md5_file($file->path)); } } return $out; }
/** * @return Service_Yandex_Direct_Manager */ private function run_all() { $this->log->debug("Running all tasks for prefix %s", $this->config->prefix); foreach (IO_FS::Dir($this->config->prefix) as $file) { Core::with(new Service_Yandex_Direct_Manager_UserTask(IO_FS::File($file), $this))->run(); $this->processed++; } $this->log->debug("All tasks complete"); }
static function run() { $_dir = getcwd(); if ($m = Core_Regexps::match_with_results('{^(.+)/index\\.php$}', $_SERVER['PHP_SELF'])) { chdir($m[1]); } $args = (array) self::parms(); $options = (array) self::options(); $action = false; if (sizeof($args) > 0) { $action = array_shift($args); } self::run_handler('CMS.CLI.Utils', $action, $args, $options); self::run_handler('App.CLI', $action, $args, $options); $cli_path = IO_FS::File(Core::loader()->file_path_for('App.CLI.Index', true))->dir_name; if (IO_FS::exists($cli_path)) { $dir = IO_FS::Dir($cli_path); foreach ($dir as $entry) { $entry = preg_replace('{\\.php$}', '', $entry->name); self::run_handler("App.CLI.{$entry}", $action, $args, $options); } } foreach (CMS::$component_original_names as $component) { $comp_cli = "Component.{$component}.CLI"; self::run_handler($comp_cli, $action, $args, $options); //$cli_path = IO_FS::File(Core::loader()->file_path_for("$comp_cli.Index", true))->dir_name; $cli_path = "../app/components/{$component}/lib/CLI"; if (IO_FS::exists($cli_path)) { $dir = IO_FS::Dir($cli_path); foreach ($dir as $entry) { $entry = preg_replace('{\\.php$}', '', $entry->name); self::run_handler("{$comp_cli}.{$entry}", $action, $args, $options); } } } chdir($_dir); }
/** * Создает каталог рекурсивно * * @param string $dir */ public function mkdirs($dirs) { return IO_FS::Dir($dirs)->create(); }
public function copy_to($dest) { $dest = IO_FS::Dir($dest); if (!$this->exists()) { return $dest; } $dest->rm()->create(); foreach ($this as $obj) { $obj->copy_to($dest->path . DIRECTORY_SEPARATOR . $obj->name); } return $dest; }
protected function branch($dir_path, $prefix = '') { $vars = array(); $dirs = array(); foreach (IO_FS::Dir($dir_path) as $entry) { $filename = $entry->name; if (Core_Regexps::match('{^[a-z0-9_-]+$}i', $filename)) { $path = $entry->path; $name = $prefix . $filename; if (is_dir($path)) { if (IO_FS::exists("{$path}/.info")) { $info = $this->load_info("{$path}/.info"); if ($info) { $var = CMS::vars()->entity('dir', $info); $var->vars = $this->branch($path, "{$name}."); $dirs[$name] = $var; } } } else { $var = $this->load($name); if ($var) { $vars[$name] = $var; } } } } ksort($vars); ksort($dirs); $out = array(); $out += $vars; $out += $dirs; return $out; }
/** * @param string $property * * @return mixed */ public function __get($property) { switch ($property) { case 'path': return $this->{$property}; case 'annotations': case 'items': return $this->items; case 'dir': return IO_FS::Dir($this->path); default: throw new Core_MissingPropertyException($property); } }
public function attaches($parms) { $id = (int) $parms['id']; $attaches = array(); if (IO_FS::exists("./" . Core::option('files_name') . "/vars/{$id}")) { foreach (IO_FS::Dir("./" . Core::option('files_name') . "/vars/{$id}") as $f) { $fp = $f->path; $attaches[$fp] = array('name' => $fp, 'path' => $f->path); } } return $this->render('attaches', array('id' => $id, 'attaches' => $attaches)); }
/** * @return IO_FS_DirIterator */ public function getIterator() { return new IO_FS_DirIterator(IO_FS::Dir($this->full_path)); }
public function action_imagelist() { $id = (int) $this->args[0]; $ar = array(); if (IO_FS::exists("./" . Core::option('files_name') . "/vars/{$id}")) { foreach (IO_FS::Dir("./" . Core::option('files_name') . "/vars/{$id}") as $f) { $fp = $f->path; if ($m = Core_Regexps::match_with_results('{/([^/]+)$}', $fp)) { $fp = $m[1]; } $ar[] = '["' . $fp . '","' . CMS::file_url($f->path) . '"]'; } } echo 'var tinyMCEImageList = new Array(' . implode(',', $ar) . ');'; die; }