false, 'user_id' => false, 'sha1' => false, 'format' => false, 'mimetype' => false, 'size' => true, 'width' => true, 'height' => true, 'added' => true, 'props' => true, ]; public static $joins = [ 'user' => 'User', ]; protected function get_disk_path() { return FileHandler::getPath(false, $this->data); } protected function get_raw_url() { return FileHandler::getPath(true, $this->data); } protected function get_fsize_ru() { return FileUtils::sizeString($this->data['size'], 'ru'); } protected function get_fsize_en() { return FileUtils::sizeString($this->data['size'], 'en'); } protected function get_url() { return App::url('api', [ 'action' => 'Files.thumb', 'sha1' => $this->data['sha1'] ]); } protected function get_gps() { return FileHandler::getGPS($this->data); } public function getThumb($width, $height, $force = false, $crop = false, $alignY = 0.5) { return FileHandler::getThumb($this->data, $width, $height, $force, $crop, $alignY); } public function cropThumb($width, $height, $alignY = 0.5) { return FileHandler::getThumb($this->data, $width, $height, false, self::CROP_XY, $alignY); } public function cropYThumb($width, $max_height, $alignY = 0.5) { return FileHandler::getThumb($this->data, $width, $max_height, false, self::CROP_Y, $alignY); } public function cropXThumb($max_width, $height) { return FileHandler::getThumb($this->data, $max_width, $height, false, self::CROP_X); } public static function upload(LocalFile $localFile, $allowedFormats = File::ANYTHING) { $file = new File(); $file->data = FileHandler::upload($localFile, $allowedFormats); return $file->data ? $file : NULL; } public static function uploadUrl($url, $allowedFormats = File::ONLY_IMAGES, $curl_options = []) { $file = new File(); $file->data = FileHandler::uploadUrl($url, $allowedFormats, $curl_options); return $file->data ? $file : NULL; } public function delete() { return FileHandler::deleteFiles([ 'id' => $this->data['id'] ]); } public static function newFromRow($row) { $obj = parent::newFromRow($row); if ($obj) { $obj->data['props'] = json_decode($obj->data['props'], true); } return $obj; } public function saveMe() { throw new Exception('File objects are immutable'); } }