path = $path; $this->size = $size; $this->lastModified = $lastModified; $this->type = $type; $this->publicUrl = $publicUrl; } /** * @return bool */ public function isFile() { return $this->type == self::TYPE_FILE; } /** * Returns the file type by its name. * The known file types are: image, video, audio, document * @return string Returns the file type or NULL if the item is a folder. */ public function getFileType() { if (!$this->isFile()) { return null; } if (!self::$imageExtensions) { self::$imageExtensions = array_map('strtolower', Config::get('cms.storage.media.imageExtensions', FileDefinitions::get('imageExtensions'))); self::$videoExtensions = array_map('strtolower', Config::get('cms.storage.media.videoExtensions', FileDefinitions::get('videoExtensions'))); self::$audioExtensions = array_map('strtolower', Config::get('cms.storage.media.audioExtensions', FileDefinitions::get('audioExtensions'))); } $extension = strtolower(pathinfo($this->path, PATHINFO_EXTENSION)); if (!strlen($extension)) { return self::FILE_TYPE_DOCUMENT; } if (in_array($extension, self::$imageExtensions)) { return self::FILE_TYPE_IMAGE; } if (in_array($extension, self::$videoExtensions)) { return self::FILE_TYPE_VIDEO; } if (in_array($extension, self::$audioExtensions)) { return self::FILE_TYPE_AUDIO; } return self::FILE_TYPE_DOCUMENT; } /** * Returns the item size as string. * For file-type items the size is the number of bytes. For folder-type items * the size is the number of items contained by the item. * @return string Returns the size as string. */ public function sizeToString() { return $this->type == self::TYPE_FILE ? File::sizeToString($this->size) : $this->size.' '.trans('system::lang.media.folder_size_items'); } /** * Returns the item last modification date as string. * @return string Returns the item's last modification date as string. */ public function lastModifiedAsString() { if (!($date = $this->lastModified)) { return null; } return Carbon::createFromTimestamp($date)->toFormattedDateString(); } }