public function close() { $this->zip->close(); if ($this->zip_path) { IO_FS::chmod($this->zip_path); } return $this; }
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; }
/** * @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)); }
public static function load($path, Config_Tree $defaults = null) { $extension = IO_FS::Path($path)->extension; if (isset(self::$parsers[$extension])) { $class_name = 'Config_File_' . self::$parsers[$extension]; $parser = new $class_name($path); return $parser->parse($defaults); } else { throw new Config_File_UnknownFormatException($extension); } }
static function with_images_cb($m) { $src = '.' . $m[2]; if (IO_FS::exists($src)) { self::$multipart = 'related'; $id = md5($src); self::$attaches[$id] = Mail_Message::Part()->file($src)->content_id("<{$id}>")->content_disposition('inline'); return $m[1] . "=\"cid:{$id}\""; } else { return $m[0]; } }
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(); } }
protected function get_lang_file($data) { $lang_file = false; $lang_file = $data['lang_file']; $lang = $this->get_lang($data); $path = "jquery/lang/{$lang}.js"; if ($data['lang_file']) { $lang_file = $data['lang_file']; } elseif (IO_FS::exists('scripts/' . $path)) { $lang_file = $path; } elseif (IO_FS::exists(CMS::stdfile('scripts/' . $path))) { $lang_file = CMS::stdfile_url('scripts/' . $path); } return $lang_file; }
/** * @param int $page * @param int $numpages * @param string $url_template * * @return string */ static function run($page, $numpages, $tpl) { if ($numpages < 2) { return ''; } self::$url_template = $tpl; self::$current = $page; ob_start(); if (IO_FS::exists(self::$template)) { include self::$template; } else { include CMS::view('page-navigator.phtml'); } $out = ob_get_clean(); return $out; }
public function on_execute(DB_Cursor $cursor) { self::$cnt++; if ($cursor->execution_time < self::$time_filter) { return; } if (!self::check_filters()) { return; } $dir = IO_FS::Path(self::$log_file)->dirname; IO_FS::mkdir($dir); $fh = fopen(self::$log_file, 'a'); fwrite($fh, $this->create_string($cursor) . "\n"); fclose($fh); CMS::chmod_file(self::$log_file); }
public function route($request) { $uri = trim(strtolower($this->clean_url($request->uri))); if (CMS_FSPages::$with_htm_extension) { $uri = preg_replace('{\\.htm$}', '/', $uri); } $path = ''; if ($uri == '/') { $path = '/'; } elseif ($m = Core_Regexps::match_with_results('{^/(.+)/$}', $uri)) { foreach (explode('/', $m[1]) as $chunk) { if (Core_Regexps::match('{[a-z0-9_-]+}', $chunk)) { $path .= "/{$chunk}"; } } } if ($path != '') { $dirs = array(CMS::$taopath . '/views/pages', CMS::app_path('views/pages')); /** * @event cms.fspages.dirs * @arg $dirs Список каталогов * Событие генерируется механизмом статических страниц (CMS.FSPages) для уточнения списка каталогов, в которых ищутся шаблоны. При необходимости в список можно добавить свой каталог. */ Events::call('cms.fspages.dirs', $dirs); if (count($dirs) > 0) { for ($i = count($dirs) - 1; $i >= 0; $i--) { $dir = $dirs[$i]; $page = false; $page_path = "{$dir}{$path}/index.phtml"; if (IO_FS::exists($page_path)) { $page = $page_path; } else { $page_path = "{$dir}/{$path}.phtml"; if (IO_FS::exists($page_path)) { $page = $page_path; } } if ($page) { return array('controller' => 'CMS.Controller.FSPages', 'action' => 'index', $page); } } } } return false; }
public function page_navigator($view, $pagenum, $numpages, $url) { $app = CMS::app_path('views/helpers'); $lib = CMS::tao_view('helpers'); $templates = array(); if (CMS::admin()) { $templates[] = "{$app}/page-navigator-admin.phtml"; $templates[] = "{$lib}/page-navigator-admin.phtml"; } else { $templates[] = "{$app}/page-navigator-site.phtml"; $templates[] = "{$app}/page-navigator.phtml"; } $templates[] = "{$lib}/page-navigator.phtml"; foreach ($templates as $template) { if (IO_FS::exists($template)) { break; } } self::$pn_url = $url; self::$pn_current = $pagenum; return $view->partial($template, array('tpl' => $url, 'page' => $pagenum, 'numpages' => $numpages)); }
/** * Подгружает файл конфигурации в формате Config.DSL * * @param string $path * * @return CLI_Application_Base */ protected function load_config($path) { if (IO_FS::exists($path)) { $this->log->debug('Using config: %s', $path); Config_DSL::Builder($this->config)->load($path); } else { throw new CLI_ApplicationException("Missing config file: {$path}"); } return $this; }
public function exists() { return IO_FS::exists($this->get_path()); }
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; }
protected function before_render() { parent::before_render(); $path = $this->cached_path(); if (!IO_FS::exists($path)) { return ''; } if ($this->get_parm('width') === null || $this->get_parm('height') === null) { $sz = getImageSize($path); if ($this->get_parm('width') === null) { $this->set_parm('width', $sz[0]); } if ($this->get_parm('height') === null) { $this->set_parm('height', $sz[1]); } } }
/** * @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; }
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; }
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; }
protected function dir($file = '') { $dir = Templates_HTML_Assets_Join::option('dir'); $ext = pathinfo($file, PATHINFO_EXTENSION); $paths = Templates_HTML::option('paths'); if (!empty($ext) && isset($paths[$ext])) { $dir = '/' . trim($paths[$ext] . '/' . trim($dir, PATH_SEPARATOR), '/'); } if (!is_dir('.' . $dir)) { IO_FS::mkdir('.' . $dir, IO_FS::option('dir_mod'), true); } return "{$dir}/{$file}"; }
public function draw($template = 'simple', $parms = array()) { //var_dump($this); $this->links = $this->sub(); if (!$this->links) { $this->links = new ArrayObject(); } ob_start(); $filename1 = CMS_Navigation2::$tpl_path . "/{$template}.phtml"; $filename2 = CMS::view("navigation/{$template}.phtml"); if (IO_FS::exists($filename1)) { include $filename1; } else { if (IO_FS::exists($filename2)) { include $filename2; } } return ob_get_clean(); }
/** * @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; }
/** * @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 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(); } }
protected function action_delgallery($id) { $fid = (int) $_GET['file']; $item = $this->load($id); if (!$item) { return $this->page_not_found(); } $files = $item[$this->gallery_field]; if (is_string($files)) { $files = unserialize($files); } if (!is_array($files)) { $files = array(); } @IO_FS::rm($files[$fid]['file_path']); @IO_FS::rm($files[$fid]['preview_path']); unset($files[$fid]); $item[$this->gallery_field] = $files; $this->update($item); Events::call('admin.change', $item); return $this->redirect_to($this->admin_url('gallery', $id)); }
protected function create_module_file($module, $content) { list($file, $dir) = $this->module_paths($module); if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); CMS::chmod_dir($dir); } if (IO_FS::exists($file)) { //return "{$file} уже существует!"; } $content = preg_replace('{^<}', '<', $content); file_put_contents($file, $content); CMS::chmod_file($file); return false; }
/** * @param string $access * * @return string */ static function admin_menu($access = 'full') { if (!CMS::$globals[$access]) { return ''; } ob_start(); $tpl = self::$admin_menu_tpl . '.phtml'; if (IO_FS::exists("../app/views/{$tpl}")) { include "../app/views/{$tpl}"; } else { include CMS::view("{$tpl}"); } $content = ob_get_clean(); return $content; }
public function action($name, $data, $action, $item = false) { $code = $this->request('code'); $dir = $this->dir_path($item, $code, $name, $data); if ($action == 'delete') { return $this->action_delete($name, $data, $action, $item); } if ($action == 'download') { $file = $this->request('file'); $path = "{$dir}/{$file}"; if (!IO_FS::exists($path)) { return false; } Core::load('Net.HTTP'); return Net_HTTP::Download($path, false); } if ($action == 'reload') { $t = $this->create_template($name, $data, 'files'); return $t->with(array('type_object' => $this, 'c' => CMS::$current_controller, 'name' => $name, 'data' => $data, 'item' => $item))->render(); } if ($action == 'upload') { return $this->action_upload($name, $data, $action, $item); } return false; }
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)); }
/** * @param $asset * @param $dir * @param $extension * @param int $timestamp * * @return string */ protected function compute_public_path($asset, $dir, $extension, $timestamp = false) { if ($asset[0] == '/' || strstr($asset, "://")) { return $asset; } $asset .= preg_match('{(?:gif|png|jpg|js|css)$}', $asset) ? '' : $extension; return "/{$dir}/{$asset}" . ($timestamp ? '?' . IO_FS::Stat("{$dir}/{$asset}")->mtime->timestamp : ''); }
/** * @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)); }