public function update_dir($name, $attrs) { $path = $this->path($name); if (!IO_FS::exists($path)) { CMS::mkdirs($path); } $info = $this->load_dir_info($name); if (is_string($attrs)) { $attrs = array('_title' => $attrs); } foreach ($info as $field => $value) { if (!isset($attrs[$field])) { $attrs[$field] = $value; } } foreach (CMS::vars()->config_fields() as $field => $data) { if (!isset($attrs[$field])) { $attrs[$field] = isset($data['default']) ? $data['default'] : ''; if ($attrs[$field] == '{name}') { $attrs[$field] = $name; } } } $this->save_dir_info($name, $attrs); }
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(); }
protected function mkdirs($dir) { return CMS::mkdirs($dir); }
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)); }
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 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 info_path() { $dir = CMS_Stockroom::$info_dir; if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $code = $this->code(); return "{$dir}/{$code}"; }
public function homedir($private = false) { $path = $private ? '../' : './'; $path .= Core::option('files_name'); $path .= '/varfiles/' . $this->id(); CMS::mkdirs($path); return $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); }
/** * Производит рассылку по майллисту. * * @param Mail_Message $mail * @param array $list * @param string $dir * * @return string */ static function maillist($mail, $list, $dir = '../bin/maillist') { $dir = rtrim($dir, '/'); CMS::mkdirs("{$dir}/messages"); CMS::mkdirs("{$dir}/recipients"); Core::load('Mail.List'); Mail_List::option('root', $dir); $emails = array(); foreach ($list as $k => $item) { if (is_string($k) && is_string($item)) { $item = array('To' => $k, 'Unsubscribe-List' => $item, 'UNSUBSCRIBE' => $item); } else { if (is_string($item)) { $item = array('To' => $item); } } if (is_string($k) && !isset($item['To'])) { $item['To'] = $k; } $emails[] = $item; } Mail_List::Spawner($mail, $emails)->id(time() . rand(1111, 9999))->spawn(); }
public function set($value) { if (IO_FS::exists($value)) { $path = IO_FS::Path($value); $ext = $path->extension; $filename = $path->basename; $filename = $this->type->uploaded_file_name($this->name, $this->data, $this->item, $ext, $filename); $dir = $this->type->uploaded_file_dir($this->name, $this->data, $this->item); if ($dir) { if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $_dir = preg_replace('{^\\./}', '', $dir); copy($value, "{$dir}/{$filename}"); $this->remove(); $value = "{$_dir}/{$filename}"; return parent::set($value); } } return $this; }
public function set($value) { if (IO_FS::exists($value)) { $ext = ''; if ($m = Core_Regexps::match_with_results('{\\.([^\\.]+)$}', $value)) { $ext = strtolower(trim($m[1])); } $filename = $this->type->uploaded_file_name($this->name, $this->data, $this->item, $ext); $dir = $this->type->uploaded_file_dir($this->name, $this->data, $this->item); if ($dir) { if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $_dir = preg_replace('{^\\./}', '', $dir); copy($value, "{$dir}/{$filename}"); IO_FS::rm($uploaded); $value = "{$_dir}/{$filename}"; return parent::set($value); } } return $this; }