public function getSavestring(System\Entity $content = null) { $old_value = $content[$this['keyword']]; if ($old_value != $this->value) { if (!empty($old_value)) { $old_value = fx::path()->abs($old_value); if (file_exists($old_value) && is_file($old_value)) { fx::files()->rm($old_value); } } if (!empty($this->value)) { $c_val = fx::path()->abs($this->value); if (file_exists($c_val) && is_file($c_val)) { preg_match("~[^" . preg_quote(DIRECTORY_SEPARATOR) . ']+$~', $c_val, $fn); $path = fx::path()->http('@content_files/' . $content['site_id'] . '/' . $content['type'] . '/' . $this['keyword'] . '/' . $fn[0]); $try = 0; while (fx::path()->exists($path)) { $file_name = preg_replace("~(\\.[^\\.]+)\$~", "_" . $try . "\$1", $fn[0]); $try++; $path = fx::path()->http('@content_files/' . $content['type'] . '/' . $this['keyword'] . '/' . $file_name); } fx::files()->move($c_val, $path); } } } $res = isset($path) ? $path : $this->value; return $res; }
public function getSavestring(System\Entity $content = null) { $old_value = $content[$this['keyword']]; $old_path = FX_BASE_URL . $old_value; if ($old_path === $this->value) { return $this->value; } $res = ''; if (!empty($this->value)) { $c_val = fx::path()->abs($this->value); if (file_exists($c_val) && is_file($c_val)) { $file_name = fx::path()->fileName($c_val); $path = fx::path('@content_files/' . $content['site_id'] . '/' . $content['type'] . '/' . $this['keyword'] . '/' . $file_name); $path = fx::files()->getPutFilePath($path); fx::files()->move($c_val, $path); $res = fx::path()->removeBase(fx::path()->http($path)); } } if (!empty($old_value)) { $old_value = fx::path()->abs($old_value); if (file_exists($old_value) && is_file($old_value)) { fx::files()->rm($old_value); } } return $res; }
protected function beforeDelete() { parent::beforeDelete(); $files = $this->getFileParams(); foreach ($files as $f) { fx::files()->rm($f); } }
public function uploadSave($input) { $path = 'upload'; $result = fx::files()->saveFile($input['file'], $path); if (!$result) { $result = array('error_message' => 'Can not load this file'); fx::http()->status(500); } if (isset($input['format']) && !empty($input['format']) && isset($result['path'])) { $result['formatted_value'] = fx::image($result['path'], $input['format']); } return $result; }
protected function handleThumbs() { fx::listen('unlink', function ($e) { $f = $e['file']; if (fx::files()->isMetaFile($f)) { return; } if (fx::path()->isInside($f, fx::path('@thumbs'))) { return; } if (!fx::path()->isInside($f, fx::path('@content_files'))) { return; } $thumbs = \Floxim\Floxim\System\Thumb::findThumbs($f); foreach ($thumbs as $thumb) { fx::files()->rm($thumb); } }); }
protected function dumpDictionary($dict, $file) { if (!isset($this->lang)) { $this->setLang(); } $data = fx::data('lang_string')->where('dict', $dict)->all(); $res = array(); foreach ($data as $s) { $res[$s['string']] = $s['lang_' . $this->lang]; } fx::files()->writefile($file, "<?php\nreturn " . var_export($res, 1) . ";"); }
public function templateSave($input) { $info = $this->getTemplateInfo($input['template_full_id']); if (!$info) { return; } if ($info['hash'] !== $input['hash']) { die("Hash error"); } $res = mb_substr($info['full'], 0, $info['start']); $input_source = $input['source']; $spaces = $input['common_spaces']; if (!empty($spaces)) { $lines = explode("\n", $input_source); foreach ($lines as $num => &$line) { if ($num === 0) { continue; } $line = $spaces . $line; } $input_source = join("\n", $lines); } $res .= $input_source; $res .= mb_substr($info['full'], $info['start'] + $info['length']); fx::files()->writefile($info['file'], $res); return array('status' => 'ok'); }
protected function afterUpdate() { parent::afterUpdate(); // modified image fields $image_fields = $this->getFields()->find('keyword', $this->modified)->find('type', array(Field\Entity::FIELD_IMAGE, Field\Entity::FIELD_FILE)); foreach ($image_fields as $img_field) { $old_value = $this->modified_data[$img_field['keyword']]; if (fx::path()->isFile($old_value)) { fx::files()->rm($old_value); } } }
protected function removeOldFiles() { $mask = $this->getTargetMask(); $files = glob($mask); if (is_array($files)) { foreach ($files as $file) { fx::files()->rm($file); } } }
protected function deleteFiles() { $path = $this->getPath(); fx::files()->rm($path); }
protected function afterDelete() { parent::afterDelete(); $path = fx::path()->abs($this->getPath()); fx::files()->rm($path); }
protected function updateFiles($dir, $base) { $items = glob($dir . "/*"); if (!$items) { return; } foreach ($items as $item) { $item_target = fx::config('ROOT_FOLDER') . str_replace($base, '', $item); if (is_dir($item)) { $item_info = pathinfo($item); // skip specific dirs if (in_array($item_info['basename'], array('_patch_generator'))) { continue; } fx::files()->mkdir($item_target); $this->updateFiles($item, $base); } else { fx::files()->writefile($item_target, file_get_contents($item)); } } }