static function type($type) { if (is_array($type)) { $type = isset($type['type']) ? $type['type'] : 'input'; } if (!is_string($type) || $type == '') { $type = 'input'; } $type = mb_strtolower($type); if (!isset(self::$types[$type])) { if (isset(CMS::$fields_types[$type])) { $module = CMS::$fields_types[$type]; } else { if (isset(CMS::$fields_types['input'])) { $module = CMS::$fields_types['input']; } else { throw new Exception('Fields initialization error'); } } $dir = IO_FS::File(Core::loader()->file_path_for($module))->dir_name; Core::autoload($module); $object = Core::make($module); $object->dir($dir); self::$types[$type] = $object; } return self::$types[$type]; }
/** * @covers Validation_Commons_ContentTypeTest::test */ public function test_ContentTypeTest() { $content_type = 'text'; $value = IO_FS::File('memory://test.txt'); $incorrect_value = 'not file'; $object = new Validation_Commons_ContentTypeTest($this->attribute, $content_type, $this->message); $this->assertTrue($object->test((object) array($this->attribute => $value), $this->errors)); $this->assertFalse($object->test((object) array($this->attribute => $incorrect_value), $this->errors)); }
protected function compile($less_fname, $css_fname) { $cache = $this->cache->get($less_fname); if (empty($cache)) { $cache = $less_fname; } $new_cache = $this->cexecute($cache); if (!is_array($cache) || $new_cache['updated'] > $cache['updated']) { $this->cache->set($less_fname, $new_cache, 0); $f = IO_FS::File('./' . $css_fname); $f->update($new_cache['compiled']); $f->set_permission(); } }
public function to_file($file) { if (!is_object($file)) { $this->to_file = IO_FS::File((string) $file)->open('w+'); } else { $this->to_file = $file; } $this->option(CURLOPT_FILE, $this->to_file->id); return $this; }
/** * @param WS_Environment $env * * @return Net_HTTP_Response */ public function run(WS_Environment $env) { //if ($this->disabled) return $this->application->run($env); $error = null; try { $body = $this->application->run($env); $response = Net_HTTP::merge_response($body, $env->response); } catch (Exception $e) { $error = $e; if ($this->disabled) { throw $e; } $response = Net_HTTP::Response(Net_HTTP::INTERNAL_SERVER_ERROR); } if (!$response->body && ($template = $this->find_template_name_for($response->status))) { if (isset($env->not_found->static_file)) { $response->body(IO_FS::File($env->not_found->static_file)); } else { $layout = isset($env->not_found->layout) ? $env->not_found->layout : 'work'; $view = Templates::HTML($template); if ($layout) { $view->within_layout($layout); } $view->root->with(array('env' => $env, 'response' => $response, 'error' => $error)); if ($view->exists()) { $response->body($view); } else { if (IO_FS::exists($static_name = $template . '.html')) { $response->body(IO_FS::File($static_name)); } } } } Events::call('ws.status', $response); return $response; }
public function save($file, $format = false) { if (!$format) { $format = $this->loaded_format; } if (!$this->ih) { return $this; } switch ($format) { case 'gif': imagegif($this->ih, $file); break; case 'bmp': imagewbmp($this->ih, $file); break; case 'png': imagepng($this->ih, $file, CMS_Images::$png_quality, CMS_Images::$png_filters); break; default: imagejpeg($this->ih, $file, CMS_Images::$jpeg_quality); } IO_FS::File($file)->set_permission(); return $this; }
/** * @param string $path */ protected function sql($path) { $p = Proc::Pipe($this->build_command(), 'wb'); foreach (IO_FS::File($path) as $line) { $p->write($line); } $p->close(); if ($p->exit_status != 0) { throw new Core_Exception('Erro while running db_script'); } }
/** * Копирует файл * * @param string $destination * * @return IO_FS_File */ public function copy_to($destination) { if ($this->stream && $this->stream->id) { return null; } $dest = copy($this->path, $destination = $this->fix_destination($destination)) ? IO_FS::File($destination) : null; return $dest; }
public static function flush_modules_cache() { if (self::is_flush_modules_cache()) { Core::load('IO.FS'); $cache = "<?php return " . var_export((array) self::$cached_modules, true) . ";"; IO_FS::File(self::option('modules_cache_path'))->update($cache, LOCK_EX); } }
public function files_data($name, $data, $item) { $fdata = array(); if (is_object($item)) { $i_id = $item->id(); if (empty($i_id)) { return $fdata; } } $key = $name . '-' . $i_id; if (isset($this->files_data[$key])) { return $this->files_data[$key]; } $file = IO_FS::File($this->files_data_path($name, $data, $item)); if ($file->exists()) { $fdata = unserialize($file->load()); } else { $dir = $file->dir_name; if (!IO_FS::exists($dir)) { IO_FS::mkdir($dir, null, true); } $files = $this->read_dir($file->dir_name); $fdata = array(); foreach ($files as $path) { $fdata['files'][] = array('name' => pathinfo($path, PATHINFO_BASENAME)); } $file->update(serialize($fdata)); $file->set_permission(); } if (isset($fdata['files']) && !empty($fdata['files']) && !empty($this->filters)) { $fdata['files'] = array_filter($fdata['files'], array($this, 'filter_callback')); } return $this->files_data[$key] = $fdata; }
/** * @param mixed $index */ public function offsetGet($index) { return IO_FS::exists($path = $this->full_path_for($index)) ? IO_FS::File($path) : null; }
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); }
protected function compile($less_fname, $css_fname) { self::load(); $options = self::option('options'); // generate source map if (self::option('sourse_map')) { $map_file = str_replace('styles/', '', $css_fname); $map_file = trim(str_replace('.less.css', '.map', $map_file), '/.'); $map_dir = './styles/less-maps/'; $map_path = "{$map_dir}{$map_file}"; IO_FS::mkdir(dirname($map_path)); $options = array_merge($options, array('sourceMap' => true, 'sourceMapWriteTo' => $map_path, 'sourceMapURL' => trim($map_path, '.'))); // if is out of docroot if ($less_fname[0] == '/' || Core_Strings::starts_with($less_fname, '..') || Core_Strings::starts_with($less_fname, './..')) { $less_fname = "file://{$less_fname}"; $less_fname = '.' . Templates_HTML::extern_filepath($less_fname); } } $options['import_dirs'] = self::option('less_import_dirs'); $dir = dirname($css_fname); $url = 'http://' . WS::env()->request->host . '/'; $args = array(array($less_fname => $url), $options); $css_file_name = Core::invoke(self::option('less_callback'), $args); $cached_file = rtrim($options['cache_dir'], '/') . '/' . $css_file_name; if (is_file($cached_file) && !(WS::env()->request['less_compile'] && self::option('debug'))) { $less_ftime = filemtime($cached_file); $css_ftime = false; if (IO_FS::exists($css_fname)) { $css_ftime = filemtime($css_fname); } if ($css_ftime && $css_ftime >= $less_ftime) { return false; } } $css = file_get_contents($cached_file); IO_FS::File($css_fname)->update($css); }
static function check_assets_symlink($path) { if (is_link($path)) { return; } if (!function_exists('symlink')) { throw new CMS_Exception("Error creating symlink {$path} (function not exists)"); } if (is_dir($path)) { CMS::rmdir($path); } $dir = IO_FS::File($path)->dir_name; CMS::mkdirs($dir); symlink(self::$stdfiles_path, $path); }
public static function upload_resize($name, $data, $new_file) { $upload_mods = self::value($data, 'upload_mods'); if (!empty($upload_mods)) { $mods = self::parse_mods($upload_mods); if (!empty($mods)) { Core::load('CMS.Images'); $im = CMS_Images::Image($new_file); self::apply_mods($im, $mods); $im->save($new_file); IO_FS::File($new_file)->set_permission(); } } }
/** * Формирует один фаил с заголовками и параметрами * * @param $container * @param int $index */ protected function head($container, $index) { $values = array(); $headers = Mail_Message::Head(); foreach ($container as $k => $v) { if (array_search($k, Mail_List::option('headers'), true) !== false) { $headers->field($k, $v); } else { $values[] = sprintf("-%s: %s", $k, MIME::encode_qp($v, null)); } } $path = sprintf('%s/%s.%06d', Mail_List::option('root') . '/recipients', $this->id, $index); IO_FS::rm($path); $f = IO_FS::File($path); $f->open('w')->write($headers->encode() . (count($values) ? implode("\n", $values) . "\n" : ''))->close(); $f->chmod(0664); }
protected function mods_process($path) { IO_FS::mkdir($path, null, true)->set_permission(); Core::load('CMS.Images'); foreach ($this->filelist() as $f) { $name = pathinfo($f, PATHINFO_BASENAME); if (isset($this->to_remake[$name])) { $image = CMS_Images::Image($f); $image->modify($this->mods); $file = "{$path}/{$name}"; $image->save("{$path}/{$name}"); IO_FS::File($file)->set_permission(); } } $this->to_remake = array(); }
/** * @return Dev_Source_Doc_Generator */ public function write() { $xslt = new XSLTProcessor(); $xslt->registerPHPFunctions(); $xslt->importStylesheet(DOMDocument::loadXML(Dev_Source_Doc_ModuleGenerator::xslt())); $stream = IO_FS::File($this->path . ".html")->open('w+'); $stream->write($xslt->transformToXML($this->module->xml)); $stream->close(); if (isset(self::$listeners)) { self::$listeners->on_write($this); } return $this; }
public function __construct($file, $cache = false, $cache_lifetime = Net_HTTP::DEFAULT_CACHE_LIFETIME) { parent::__construct(); $this->file = IO_FS::File($file); $this->cache = $cache; $this->cache_lifetime = $cache_lifetime; $this->setup(); }
/** * @param array $argv * * @return int */ public function run(array $argv) { Core::with($this->config->output ? IO_FS::File($this->config->output)->open('w+') : IO::stdout())->write(Dev_Source::Library($argv)->xml->SaveXML()); return 0; }
/** * @param string $path * * @return boolean */ public function save_as($path) { return IO_FS::File($path)->update(Net_HTTP::Agent()->send($this->request->method(Net_HTTP::POST))->body); }
public function write($path = null) { $path = !is_null($path) ? $path : $this->___path; if (!empty($path)) { Core::load('IO.FS'); IO_FS::File($path)->update("<?php\n/**\n * @package Config\n */\n \nreturn " . var_export($this, true) . ';'); } }
/** * @param string $name */ public function __construct($name) { $this->name = $name; $this->file = IO_FS::File(Core::loader()->file_path_for($name)); }
public function copy_value($from, $to, $name, $data) { $from_value = $from[$name]; $to_value = preg_replace("!/(\\d+){$from->id()}/!", '/${1}' . $to->id() . '/', $from_value); $to[$name] = $to_value; $file = IO_FS::File($from_value); if ($file->exists()) { $file->copy_to($to_value); } return $this; }
/** * @return Log_FileHandler */ public function init() { if (!IO_FS::exists($dir = IO_FS::File($this->path)->dir_name)) { IO_FS::mkdir($dir, null, true); } $this->stream = IO_FS::FileStream($this->path, 'a'); return $this; }
/** * Извлекает из файла значение по ключу $key * * @param string $key * * @return string */ protected function get_content($key) { return IO_FS::File($this->path($key))->load(false, null, 11); }
protected function write($path, $content) { $os_path = './' . ltrim($path, '\\/.'); $os_dir = dirname($os_path); if (!IO_FS::exists($dir)) { IO_FS::mkdir($os_dir); } IO_FS::File($os_path)->update($content); //IO_FS::chmod($path, IO_FS::option('file_mod')); return $this; }
/** * Заполняет письмо из файла, т.е. получаетя attach к письму * * @param $file * @param string $name * * @return Mail_Message_Part */ public function file($file, $name = '') { if (!$file instanceof IO_FS_File) { $file = IO_FS::File((string) $file); } $this->head['Content-Type'] = array($file->content_type, 'name' => $name ? $name : $file->name); $this->head['Content-Transfer-Encoding'] = $file->mime_type->encoding; $this->head['Content-Disposition'] = 'attachment'; $this->body = $file; return $this; }
protected function cached_preview() { if (!IO_FS::exists($this->get_preview_dir())) { CMS::mkdirs($this->get_preview_dir()); } $file = IO_FS::File($this->path()); $file->update($this->get_preview_src_from_youtube()); $file->close(); }
/** * @param string $property * * @return mixed */ public function __get($property) { switch ($property) { case 'name': return $this->{$property}; case 'url': return $this->collection->path === null ? null : DB_ORM_Assets::option('root_url') . $this->collection->path . ($this->name ? '/' . $this->name : ''); case 'file': return IO_FS::File($this->collection->path_for($this->name)); case 'annotation': return $this->collection->annotation_for($this->name); } }