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); }
static function modified_image($path, $mods) { if (is_string($mods)) { $mods = self::parse_modifiers($mods); } $ext = false; $name = false; if ($m = Core_Regexps::match_with_results('{(.+)\\.(jpe?g|gif|png|bmp)$}i', $path)) { $name = $m[1]; $ext = strtolower($m[2]); } if (!$ext || !IO_FS::exists($path)) { $path = '../tao/files/images/admin.gif'; $ext = 'gif'; $name = 'error'; } $name = preg_replace('{^\\.\\./}', 'up/', $name); $name = ltrim($name, '.'); $name = ltrim($name, '/'); $stat = IO_FS::Stat($path); $mtime = $stat->mtime->timestamp; $name .= "-{$stat->size}-{$mtime}-"; $name .= md5(serialize($mods)); $cache = self::$cache_dir . "/{$name}.{$ext}"; if (IO_FS::exists('./' . $cache)) { return '/' . $cache; } $dir = preg_replace('{/([^/]+)$}', '', $cache); if (!IO_FS::exists($dir)) { IO_FS::mkdir($dir); } $image = self::Image($path); $image->modify($mods); $image->save('./' . $cache); CMS::chmod_file('./' . $cache); return '/' . $cache; }
protected function chmod_file($name) { CMS::chmod_file($name); }
public function addfile($parms) { $id = (int) $parms['id']; $file = $_FILES['up']; $name = trim($file['name']); $tmp_name = trim($file['tmp_name']); if ($tmp_name != '') { $dir = "./" . Core::option('files_name') . "/vars/{$id}"; CMS::mkdirs($dir); $name = strtolower($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}"); CMS::chmod_file("{$dir}/{$name}"); Events::call('admin.change'); } return $this->redirect_to($this->make_uri('attaches', $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; }
protected function upload_file($fobject, $name, $data, $action, $item) { $file = $fobject->file_array; $filename = $this->real_uploaded_filename($name, $data, $file); $code = $this->request('code'); $dir = $this->dir_path($item, $code, $name, $data); if (!empty($file['error'])) { return $this->upload_error_message($file['error']); } else { if (!isset($file['tmp_name']) || empty($file['tmp_name']) || $file['tmp_name'] == 'none') { throw new Exception(CMS::lang()->_common->no_file_uploaded); //TODO: Exception class } else { $old = $file['tmp_name']; $new = "{$dir}/{$filename}"; $valid = $this->upload_validate($name, $data, $file, $new); if ($valid !== true) { throw new Exception($valid); } $eres = Events::call('cms.fields.upload', $name, $data, $file, $new); if (!is_null($eres) && $eres !== true) { return $eres; } $eres = Events::call("cms.fields.{$name}.upload", $data, $file, $new); if (!is_null($eres) && $eres !== true) { return $eres; } if (!is_dir($dir)) { CMS::mkdirs($dir); } CMS::copy($old, $new); CMS::chmod_file($new); return $this->upload_return($name, $data, $new, $dir, $filename); } } }
public function save_info_file() { $title = $this['title']; $version = $this['version']; $content = "component {$title}\nversion {$version}\n"; foreach ($this->hashes as $file => $hash) { $content .= "hash {$hash} {$file}\n"; } file_put_contents($this->info_path(), $content); CMS::chmod_file($this->info_path()); }
public function set($file) { if (!IO_FS::exists($file)) { return $this; } $private = isset($this->data['private']) && $this->data['private']; $dir = $this->type->uploaded_file_dir($this->data, $this->item, $private); $filename = $this->type->uploaded_file_name($this->get_file_info($file), $this->data, $this->item, $this->name); if (!$dir) { return $this; } if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $_dir = preg_replace('{^\\./}', '', $dir); copy($file, "{$dir}/{$filename}"); CMS::chmod_file("{$dir}/{$filename}"); $this->remove($file); $file = "{$_dir}/{$filename}"; return parent::set($file); }
protected function process_uploads($item) { if (!isset($_FILES[$this->form->name])) { return; } $dir = CMS::temp_dir(); $files = $_FILES[$this->form->name]; foreach ($files['tmp_name'] as $field => $path) { $t = time(); $path = trim($path); if ($path == '') { continue; } $original_name = $files['name'][$field]; $original_name_we = $original_name; $ext = ''; $dotext = ''; if ($m = Core_Regexps::match_with_results('{^(.*)\\.([a-z0-9_]+)$}i', $original_name)) { $original_name_we = strtolower($m[1]); $ext = $m[2]; $dotext = ".{$ext}"; } $uplname = "uploaded-{$field}-{$t}{$dotext}"; $uplpath = "{$dir}/{$uplname}"; move_uploaded_file($path, $uplpath); CMS::chmod_file($uplpath); $this->uploaded_files[$field] = array('original_name' => $original_name, 'original_name_we' => $original_name_we, 'ext' => $ext, 'dotext' => $dotext, 'uplname' => $uplname, 'uplpath' => $uplpath, 'size' => $files['size'][$field], 'type' => $files['type'][$field]); } $uploads_extra = array('old_item' => $this->item_before_assign, 'id' => $this->item_id($item), 'homedir' => $this->item_homedir($item), 'private_homedir' => $this->item_homedir($item, true), 'controller' => $this, 'form' => $this->form, 'form_fields' => $this->filtered_form_fields); foreach ($this->filtered_form_fields as $field => $parms) { $type = CMS_Fields::type($parms); $type->process_uploads($field, $parms, $this->uploaded_files, $item, $uploads_extra); } foreach ($this->uploaded_files as $fdata) { IO_FS::rm($fdata['uplpath']); } }
/** * @param string $name * @param string $text */ static function log($name, $text) { if (!IO_FS::exists(self::$logs_path)) { self::mkdirs(self::$logs_path); self::chmod_dir(self::$logs_path); } $filename = self::$logs_path . '/' . $name . '.log'; $text = trim($text); $f = fopen($filename, "a"); $t = date('Y-m-d G:i:s'); $ip = self::ip(); fputs($f, "{$t} [{$ip}] {$text}\n"); fclose($f); CMS::chmod_file($filename); }
public function process_inserted($name, $data, $item) { $item_id = $item->id(); $value = trim($item[$name]); if ($value != '') { if ($value[0] == '#') { $uploaded = trim(substr($value, 1)); $value = ''; if ($uploaded != '') { $uploaded = str_replace('..', '', $uploaded); $filename = $uploaded; $uploaded = CMS::temp_dir() . '/' . $uploaded; if (IO_FS::exists($uploaded)) { $ext = ''; if ($m = Core_Regexps::match_with_results('{\\.([^\\.]+)$}', $uploaded)) { $ext = trim($m[1]); } $filename = $this->uploaded_file_name($name, $data, $item, $ext, $filename); $dir = $this->uploaded_file_dir($name, $data, $item); if ($dir) { if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $_dir = preg_replace('{^\\./}', '', $dir); copy($uploaded, "{$dir}/{$filename}"); CMS::chmod_file("{$dir}/{$filename}"); IO_FS::rm($uploaded); $value = "{$_dir}/{$filename}"; } } } } } $item[$name] = $value; if (!empty($value) && method_exists($item, 'clear_cache')) { $item->clear_cache(false); } $this->preset->preset_on_upload($this->container($name, $data, $item)); return true; }
public function save_info($file, $info) { $s = ''; foreach ($info as $field => $value) { if (is_array($value)) { $value = serialize($value); } if ($value == trim($value) && Core_Regexps::match('{^[a-zа-я0-9\\. ]*$}i', $value)) { $s .= "{$field}={$value}\n"; } else { $v = base64_encode($value); $s .= "{$field}: {$v}\n"; } } file_put_contents($file, $s); CMS::chmod_file($file); }