@@ -84,9 +84,9 @@ |
||
| 84 | 84 | <div class="description">{$descr}</div> |
| 85 | 85 | </div> |
| 86 | 86 | </div>{empty}' . __('No file details') . '{/}')])->setSource([ |
| 87 | - ['title'=> __('Name'), 'descr'=> $this->file()->name], |
|
| 88 | - ['title'=> __('Size'), 'descr'=> Utils::bytesToHuman($this->file()->content->size)], |
|
| 89 | - ]); |
|
| 87 | + ['title'=> __('Name'), 'descr'=> $this->file()->name], |
|
| 88 | + ['title'=> __('Size'), 'descr'=> Utils::bytesToHuman($this->file()->content->size)], |
|
| 89 | + ]); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | protected function addFileRemoteLinks($container = null) { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | protected function setPeriodSelection() |
| 35 | 35 | { |
| 36 | - if (! $this->periodSelection) { |
|
| 36 | + if (!$this->periodSelection) { |
|
| 37 | 37 | $this->periodSelection = []; |
| 38 | 38 | foreach ([1, 2, 3, 4] as $count) { |
| 39 | 39 | $this->periodSelection[$count . ' weeks'] = trans_choice('{1} :count week |[2,*] :count weeks', $count); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | foreach ($this->periodSelection as $key => $period) { |
| 44 | - $default = $key == $this->defaultPeriod? ' (' . __('Default') . ')': ''; |
|
| 44 | + $default = $key == $this->defaultPeriod ? ' (' . __('Default') . ')' : ''; |
|
| 45 | 45 | |
| 46 | 46 | $this->periodSelection[$key] = $period . $default; |
| 47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $this->canvas = $canvas; |
| 53 | 53 | |
| 54 | - if (! $this->file()) { |
|
| 54 | + if (!$this->file()) { |
|
| 55 | 55 | $canvas->set(__('Wrong parameters for file')); |
| 56 | 56 | return; |
| 57 | 57 | } |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | protected function file() |
| 73 | 73 | { |
| 74 | - return $this->file?: ($this->file = File::get($this->canvas->stickyGET('id'))); |
|
| 74 | + return $this->file ?: ($this->file = File::get($this->canvas->stickyGET('id'))); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | protected function addFileDetails($container = null) |
| 78 | 78 | { |
| 79 | - $container = $container?: $this->canvas; |
|
| 79 | + $container = $container ?: $this->canvas; |
|
| 80 | 80 | |
| 81 | 81 | $container->add(['Lister', 'template'=> new \atk4\ui\Template(' |
| 82 | 82 | <div class="item" style="margin: 0 15px 15px 0"> |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | protected function addFileRemoteLinks($container = null) { |
| 93 | - $container = $container?: $this->canvas; |
|
| 93 | + $container = $container ?: $this->canvas; |
|
| 94 | 94 | |
| 95 | 95 | foreach ($this->file()->links()->where('created_by', Auth::id())->get() as $link) { |
| 96 | 96 | $container->add(['View', __('Remote access link expiring :expiry', ['expiry' => $link->expires_at])]); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $container->js(true, new jsExpression('new ClipboardJS(".copy-button")')); |
| 107 | 107 | |
| 108 | 108 | $container->on('click', '.delete-link', $container->add(['jsCallback', 'postTrigger' => 'link'])->set(function($j, $linkId) { |
| 109 | - if (! $link = FileRemoteAccess::find($linkId)) return; |
|
| 109 | + if (!$link = FileRemoteAccess::find($linkId)) return; |
|
| 110 | 110 | |
| 111 | 111 | $link->delete(); |
| 112 | 112 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $dropdown->setSource($this->periodSelection); |
| 135 | 135 | |
| 136 | 136 | $dropdown->onChange(function($value) { |
| 137 | - $period = array_search($value, $this->periodSelection)?: $this->defaultPeriod; |
|
| 137 | + $period = array_search($value, $this->periodSelection) ?: $this->defaultPeriod; |
|
| 138 | 138 | |
| 139 | 139 | FileRemoteAccess::grant($this->file(), $period); |
| 140 | 140 | |
@@ -106,7 +106,9 @@ |
||
| 106 | 106 | $container->js(true, new jsExpression('new ClipboardJS(".copy-button")')); |
| 107 | 107 | |
| 108 | 108 | $container->on('click', '.delete-link', $container->add(['jsCallback', 'postTrigger' => 'link'])->set(function($j, $linkId) { |
| 109 | - if (! $link = FileRemoteAccess::find($linkId)) return; |
|
| 109 | + if (! $link = FileRemoteAccess::find($linkId)) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 110 | 112 | |
| 111 | 113 | $link->delete(); |
| 112 | 114 | |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | use Illuminate\Support\Facades\Auth; |
| 7 | 7 | |
| 8 | 8 | class FileRemoteAccess extends Model { |
| 9 | - const DEFAULT_PERIOD = '1 week'; |
|
| 9 | + const DEFAULT_PERIOD = '1 week'; |
|
| 10 | 10 | |
| 11 | - protected $table = 'filestorage_remote_access'; |
|
| 12 | - protected static $unguarded = true; |
|
| 11 | + protected $table = 'filestorage_remote_access'; |
|
| 12 | + protected static $unguarded = true; |
|
| 13 | 13 | |
| 14 | - public static function check($fileId, $token) |
|
| 15 | - { |
|
| 16 | - return (bool) self::where('file_id', $fileId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count(); |
|
| 17 | - } |
|
| 14 | + public static function check($fileId, $token) |
|
| 15 | + { |
|
| 16 | + return (bool) self::where('file_id', $fileId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count(); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public static function grant($file, $expires = self::DEFAULT_PERIOD) |
|
| 20 | - { |
|
| 19 | + public static function grant($file, $expires = self::DEFAULT_PERIOD) |
|
| 20 | + { |
|
| 21 | 21 | return self::create([ |
| 22 | 22 | 'file_id' => is_numeric($file)? $file: $file->id, |
| 23 | 23 | 'token' => md5(uniqid(rand(), true)), |
| 24 | 24 | 'created_by' => Auth::id()?: 0, |
| 25 | 25 | 'expires_at' => date('Y-m-d H:i:s', strtotime($expires)), |
| 26 | 26 | ]); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function getHrefAttribute() |
|
| 30 | - { return url('file') . '?' . http_build_query(['id' => $this->file_id, 'token' => $this->token]); |
|
| 31 | - } |
|
| 29 | + public function getHrefAttribute() |
|
| 30 | + { return url('file') . '?' . http_build_query(['id' => $this->file_id, 'token' => $this->token]); |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -19,9 +19,9 @@ |
||
| 19 | 19 | public static function grant($file, $expires = self::DEFAULT_PERIOD) |
| 20 | 20 | { |
| 21 | 21 | return self::create([ |
| 22 | - 'file_id' => is_numeric($file)? $file: $file->id, |
|
| 22 | + 'file_id' => is_numeric($file) ? $file : $file->id, |
|
| 23 | 23 | 'token' => md5(uniqid(rand(), true)), |
| 24 | - 'created_by' => Auth::id()?: 0, |
|
| 24 | + 'created_by' => Auth::id() ?: 0, |
|
| 25 | 25 | 'expires_at' => date('Y-m-d H:i:s', strtotime($expires)), |
| 26 | 26 | ]); |
| 27 | 27 | } |
@@ -14,211 +14,211 @@ |
||
| 14 | 14 | { |
| 15 | 15 | use SoftDeletes; |
| 16 | 16 | |
| 17 | - protected $table = 'filestorage_files'; |
|
| 18 | - protected static $unguarded = true; |
|
| 17 | + protected $table = 'filestorage_files'; |
|
| 18 | + protected static $unguarded = true; |
|
| 19 | 19 | |
| 20 | - public function content() |
|
| 21 | - { |
|
| 22 | - return $this->belongsTo(FileContent::class, 'content_id'); |
|
| 23 | - } |
|
| 20 | + public function content() |
|
| 21 | + { |
|
| 22 | + return $this->belongsTo(FileContent::class, 'content_id'); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function links() |
|
| 26 | - { |
|
| 27 | - return $this->hasMany(FileRemoteAccess::class, 'file_id'); |
|
| 28 | - } |
|
| 25 | + public function links() |
|
| 26 | + { |
|
| 27 | + return $this->hasMany(FileRemoteAccess::class, 'file_id'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Retrieve the file |
|
| 33 | - * |
|
| 34 | - * @param int|string $idOrLink Filestorage ID or unique link string |
|
| 35 | - * @param bool $useCache Use cache or not |
|
| 36 | - * |
|
| 37 | - * @return static |
|
| 38 | - * |
|
| 39 | - * @throws FileNotFound |
|
| 40 | - */ |
|
| 41 | - public static function get($idOrLink, $useCache = true) |
|
| 42 | - { |
|
| 43 | - static $cache = []; |
|
| 44 | - |
|
| 45 | - if (is_object($idOrLink)) return $idOrLink; |
|
| 31 | + /** |
|
| 32 | + * Retrieve the file |
|
| 33 | + * |
|
| 34 | + * @param int|string $idOrLink Filestorage ID or unique link string |
|
| 35 | + * @param bool $useCache Use cache or not |
|
| 36 | + * |
|
| 37 | + * @return static |
|
| 38 | + * |
|
| 39 | + * @throws FileNotFound |
|
| 40 | + */ |
|
| 41 | + public static function get($idOrLink, $useCache = true) |
|
| 42 | + { |
|
| 43 | + static $cache = []; |
|
| 44 | + |
|
| 45 | + if (is_object($idOrLink)) return $idOrLink; |
|
| 46 | 46 | |
| 47 | - $id = self::getIdByLink($idOrLink, true, true); |
|
| 47 | + $id = self::getIdByLink($idOrLink, true, true); |
|
| 48 | 48 | |
| 49 | - if ($useCache && isset($cache[$id])) { |
|
| 50 | - return $cache[$id]; |
|
| 51 | - } |
|
| 49 | + if ($useCache && isset($cache[$id])) { |
|
| 50 | + return $cache[$id]; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $file = self::with('content')->findOrFail($id); |
|
| 53 | + $file = self::with('content')->findOrFail($id); |
|
| 54 | 54 | |
| 55 | - if (empty($file->content['hash'])) { |
|
| 56 | - throw new FileNotFound('File object does not have corresponding content'); |
|
| 57 | - } |
|
| 55 | + if (empty($file->content['hash'])) { |
|
| 56 | + throw new FileNotFound('File object does not have corresponding content'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $cache[$id] = $file; |
|
| 60 | - } |
|
| 59 | + return $cache[$id] = $file; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get Filestorage ID by link |
|
| 64 | - * |
|
| 65 | - * @param string $link Unique link |
|
| 66 | - * @param bool $useCache Use cache or not |
|
| 67 | - * @param bool $throwException Throw exception if link is not found |
|
| 68 | - * |
|
| 69 | - * @return int Filestorage ID |
|
| 70 | - * @throws LinkNotFound |
|
| 71 | - */ |
|
| 72 | - public static function getIdByLink($link, $useCache = true, $throwException = false) |
|
| 73 | - { |
|
| 74 | - static $cache = []; |
|
| 75 | - |
|
| 76 | - if (is_numeric($link)) return $link; |
|
| 77 | - |
|
| 78 | - if (!$useCache || !isset($cache[$link])) { |
|
| 79 | - $cache[$link] = self::where('link', $link)->value('id'); |
|
| 62 | + /** |
|
| 63 | + * Get Filestorage ID by link |
|
| 64 | + * |
|
| 65 | + * @param string $link Unique link |
|
| 66 | + * @param bool $useCache Use cache or not |
|
| 67 | + * @param bool $throwException Throw exception if link is not found |
|
| 68 | + * |
|
| 69 | + * @return int Filestorage ID |
|
| 70 | + * @throws LinkNotFound |
|
| 71 | + */ |
|
| 72 | + public static function getIdByLink($link, $useCache = true, $throwException = false) |
|
| 73 | + { |
|
| 74 | + static $cache = []; |
|
| 75 | + |
|
| 76 | + if (is_numeric($link)) return $link; |
|
| 77 | + |
|
| 78 | + if (!$useCache || !isset($cache[$link])) { |
|
| 79 | + $cache[$link] = self::where('link', $link)->value('id'); |
|
| 80 | 80 | |
| 81 | - if (!$cache[$link] && $throwException) { |
|
| 82 | - throw new LinkNotFound($link); |
|
| 83 | - } |
|
| 84 | - } |
|
| 81 | + if (!$cache[$link] && $throwException) { |
|
| 82 | + throw new LinkNotFound($link); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $cache[$link]; |
|
| 87 | - } |
|
| 86 | + return $cache[$link]; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Mark file as deleted. Does not remove any content! |
|
| 91 | - * |
|
| 92 | - * @param int|string $idOrLink Filestorage ID or unique link |
|
| 93 | - */ |
|
| 94 | - public static function unlink($idOrLink) |
|
| 95 | - { |
|
| 89 | + /** |
|
| 90 | + * Mark file as deleted. Does not remove any content! |
|
| 91 | + * |
|
| 92 | + * @param int|string $idOrLink Filestorage ID or unique link |
|
| 93 | + */ |
|
| 94 | + public static function unlink($idOrLink) |
|
| 95 | + { |
|
| 96 | 96 | if ($id = self::getIdByLink($idOrLink, false)) { |
| 97 | 97 | self::find($id)->delete(); |
| 98 | - } |
|
| 99 | - } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Check if file exists |
|
| 103 | - * |
|
| 104 | - * @param int|static $idOrMeta Filestorage ID or file object |
|
| 105 | - * @param bool $throwException Throw exception on missing file or return false |
|
| 106 | - * |
|
| 107 | - * @return bool True if file exists, false otherwise |
|
| 108 | - * @throws FileNotFound May be thrown if $throwException set to true |
|
| 109 | - */ |
|
| 110 | - public static function exists($idOrMeta, $throwException = false) |
|
| 111 | - { |
|
| 112 | - try { |
|
| 113 | - $file = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta; |
|
| 101 | + /** |
|
| 102 | + * Check if file exists |
|
| 103 | + * |
|
| 104 | + * @param int|static $idOrMeta Filestorage ID or file object |
|
| 105 | + * @param bool $throwException Throw exception on missing file or return false |
|
| 106 | + * |
|
| 107 | + * @return bool True if file exists, false otherwise |
|
| 108 | + * @throws FileNotFound May be thrown if $throwException set to true |
|
| 109 | + */ |
|
| 110 | + public static function exists($idOrMeta, $throwException = false) |
|
| 111 | + { |
|
| 112 | + try { |
|
| 113 | + $file = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta; |
|
| 114 | 114 | |
| 115 | - if (! file_exists($file->content->path)) { |
|
| 116 | - throw new FileNotFound('Exception - file not found: ' . $file->content->path); |
|
| 117 | - } |
|
| 118 | - } catch (\Exception $exception) { |
|
| 119 | - if ($throwException) |
|
| 120 | - throw $exception; |
|
| 121 | - else |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return true; |
|
| 126 | - } |
|
| 115 | + if (! file_exists($file->content->path)) { |
|
| 116 | + throw new FileNotFound('Exception - file not found: ' . $file->content->path); |
|
| 117 | + } |
|
| 118 | + } catch (\Exception $exception) { |
|
| 119 | + if ($throwException) |
|
| 120 | + throw $exception; |
|
| 121 | + else |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return true; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Add multiple files, clone file if file id is provided. |
|
| 130 | - * May be used to update backref for all files. |
|
| 131 | - * |
|
| 132 | - * @param array $files array of existing filestorage ids or array with values for the new file |
|
| 133 | - * @param string|null $backref Backref for all files |
|
| 134 | - * @return array Newly created Meta Ids sorted in ascending order |
|
| 135 | - */ |
|
| 136 | - public static function putMany($files, $backref = null) |
|
| 137 | - { |
|
| 138 | - $ids = []; |
|
| 139 | - foreach ((array) $files as $filePath) { |
|
| 140 | - if (! is_numeric($filePath)) { |
|
| 141 | - $ids[] = self::put($filePath); |
|
| 128 | + /** |
|
| 129 | + * Add multiple files, clone file if file id is provided. |
|
| 130 | + * May be used to update backref for all files. |
|
| 131 | + * |
|
| 132 | + * @param array $files array of existing filestorage ids or array with values for the new file |
|
| 133 | + * @param string|null $backref Backref for all files |
|
| 134 | + * @return array Newly created Meta Ids sorted in ascending order |
|
| 135 | + */ |
|
| 136 | + public static function putMany($files, $backref = null) |
|
| 137 | + { |
|
| 138 | + $ids = []; |
|
| 139 | + foreach ((array) $files as $filePath) { |
|
| 140 | + if (! is_numeric($filePath)) { |
|
| 141 | + $ids[] = self::put($filePath); |
|
| 142 | 142 | |
| 143 | - continue; |
|
| 144 | - } |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - $file = self::get($filePath, false)->toArray(); |
|
| 146 | + $file = self::get($filePath, false)->toArray(); |
|
| 147 | 147 | |
| 148 | - if ($backref && $file['backref'] != $backref) { |
|
| 149 | - $file['backref'] = $backref; |
|
| 150 | - unset($file['link']); |
|
| 148 | + if ($backref && $file['backref'] != $backref) { |
|
| 149 | + $file['backref'] = $backref; |
|
| 150 | + unset($file['link']); |
|
| 151 | 151 | |
| 152 | - self::put($file); |
|
| 153 | - } |
|
| 152 | + self::put($file); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $ids[] = $file; |
|
| 156 | - } |
|
| 155 | + $ids[] = $file; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - sort($ids); |
|
| 158 | + sort($ids); |
|
| 159 | 159 | |
| 160 | - return $ids; |
|
| 161 | - } |
|
| 160 | + return $ids; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * @param string|array $fileOrPath |
|
| 165 | - * @param string $content Content of the file |
|
| 166 | - * |
|
| 167 | - * @return int Filestorage ID |
|
| 168 | - * @throws LinkDuplicate |
|
| 169 | - */ |
|
| 170 | - public static function put($fileOrPath, $content = null) |
|
| 171 | - { |
|
| 172 | - $file = $fileOrPath; |
|
| 173 | - if (! $content && is_string($fileOrPath)) { |
|
| 174 | - $content = file_get_contents($fileOrPath); |
|
| 163 | + /** |
|
| 164 | + * @param string|array $fileOrPath |
|
| 165 | + * @param string $content Content of the file |
|
| 166 | + * |
|
| 167 | + * @return int Filestorage ID |
|
| 168 | + * @throws LinkDuplicate |
|
| 169 | + */ |
|
| 170 | + public static function put($fileOrPath, $content = null) |
|
| 171 | + { |
|
| 172 | + $file = $fileOrPath; |
|
| 173 | + if (! $content && is_string($fileOrPath)) { |
|
| 174 | + $content = file_get_contents($fileOrPath); |
|
| 175 | 175 | |
| 176 | - $file = [ |
|
| 177 | - 'name' => basename($fileOrPath) |
|
| 178 | - ]; |
|
| 179 | - } |
|
| 176 | + $file = [ |
|
| 177 | + 'name' => basename($fileOrPath) |
|
| 178 | + ]; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - if (!empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
| 182 | - throw new LinkDuplicate($file['link']); |
|
| 183 | - } |
|
| 181 | + if (!empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
| 182 | + throw new LinkDuplicate($file['link']); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - $content = $file['content']?? $content; |
|
| 185 | + $content = $file['content']?? $content; |
|
| 186 | 186 | |
| 187 | - if (is_array($content)) { |
|
| 188 | - $path = $content['path']; |
|
| 187 | + if (is_array($content)) { |
|
| 188 | + $path = $content['path']; |
|
| 189 | 189 | |
| 190 | - $file['name'] = $file['name']?? basename($path); |
|
| 190 | + $file['name'] = $file['name']?? basename($path); |
|
| 191 | 191 | |
| 192 | - $content = file_get_contents($path); |
|
| 193 | - } |
|
| 192 | + $content = file_get_contents($path); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - unset($file['content']); |
|
| 196 | - |
|
| 197 | - return self::updateOrCreate(['id' => $file['id']?? null], array_merge([ |
|
| 198 | - 'created_at' => time(), |
|
| 199 | - 'created_by' => Auth::id(), |
|
| 200 | - 'content_id' => FileContent::put($content) |
|
| 201 | - ], $file))->id; |
|
| 202 | - } |
|
| 195 | + unset($file['content']); |
|
| 196 | + |
|
| 197 | + return self::updateOrCreate(['id' => $file['id']?? null], array_merge([ |
|
| 198 | + 'created_at' => time(), |
|
| 199 | + 'created_by' => Auth::id(), |
|
| 200 | + 'content_id' => FileContent::put($content) |
|
| 201 | + ], $file))->id; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - public function getThumbnailAttribute() |
|
| 205 | - { |
|
| 206 | - if (! $this->thumbnailPossible()) return false; |
|
| 204 | + public function getThumbnailAttribute() |
|
| 205 | + { |
|
| 206 | + if (! $this->thumbnailPossible()) return false; |
|
| 207 | 207 | |
| 208 | - $image = new \Imagick($this->content->path . '[0]'); |
|
| 208 | + $image = new \Imagick($this->content->path . '[0]'); |
|
| 209 | 209 | |
| 210 | - $image->setImageFormat('jpg'); |
|
| 210 | + $image->setImageFormat('jpg'); |
|
| 211 | 211 | |
| 212 | - $mime = 'image/jpeg'; |
|
| 212 | + $mime = 'image/jpeg'; |
|
| 213 | 213 | |
| 214 | - $name = 'preview.jpeg'; |
|
| 214 | + $name = 'preview.jpeg'; |
|
| 215 | 215 | |
| 216 | - $contents = $image . ''; |
|
| 216 | + $contents = $image . ''; |
|
| 217 | 217 | |
| 218 | - return collect(compact('mime', 'name', 'contents')); |
|
| 219 | - } |
|
| 218 | + return collect(compact('mime', 'name', 'contents')); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - protected function thumbnailPossible() { |
|
| 222 | - return $this->content->type == 'application/pdf' && class_exists('Imagick'); |
|
| 223 | - } |
|
| 221 | + protected function thumbnailPossible() { |
|
| 222 | + return $this->content->type == 'application/pdf' && class_exists('Imagick'); |
|
| 223 | + } |
|
| 224 | 224 | } |
| 225 | 225 | \ No newline at end of file |
@@ -42,7 +42,9 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | static $cache = []; |
| 44 | 44 | |
| 45 | - if (is_object($idOrLink)) return $idOrLink; |
|
| 45 | + if (is_object($idOrLink)) { |
|
| 46 | + return $idOrLink; |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | $id = self::getIdByLink($idOrLink, true, true); |
| 48 | 50 | |
@@ -73,7 +75,9 @@ discard block |
||
| 73 | 75 | { |
| 74 | 76 | static $cache = []; |
| 75 | 77 | |
| 76 | - if (is_numeric($link)) return $link; |
|
| 78 | + if (is_numeric($link)) { |
|
| 79 | + return $link; |
|
| 80 | + } |
|
| 77 | 81 | |
| 78 | 82 | if (!$useCache || !isset($cache[$link])) { |
| 79 | 83 | $cache[$link] = self::where('link', $link)->value('id'); |
@@ -116,10 +120,11 @@ discard block |
||
| 116 | 120 | throw new FileNotFound('Exception - file not found: ' . $file->content->path); |
| 117 | 121 | } |
| 118 | 122 | } catch (\Exception $exception) { |
| 119 | - if ($throwException) |
|
| 120 | - throw $exception; |
|
| 121 | - else |
|
| 122 | - return false; |
|
| 123 | + if ($throwException) { |
|
| 124 | + throw $exception; |
|
| 125 | + } else { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 123 | 128 | } |
| 124 | 129 | |
| 125 | 130 | return true; |
@@ -203,7 +208,9 @@ discard block |
||
| 203 | 208 | |
| 204 | 209 | public function getThumbnailAttribute() |
| 205 | 210 | { |
| 206 | - if (! $this->thumbnailPossible()) return false; |
|
| 211 | + if (! $this->thumbnailPossible()) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 207 | 214 | |
| 208 | 215 | $image = new \Imagick($this->content->path . '[0]'); |
| 209 | 216 | |
@@ -34,11 +34,11 @@ |
||
| 34 | 34 | $this->grid->setModel($this->getModel()); |
| 35 | 35 | |
| 36 | 36 | $this->grid->addDecorator('name', ['Multiformat', function($row, $column) { |
| 37 | - return [['Template', '<a href="#" class="file-modal" data-id="' . $row['id'] . '">' . $row[$column] . '</a>']]; |
|
| 37 | + return [['Template', '<a href="#" class="file-modal" data-id="' . $row['id'] . '">' . $row[$column] . '</a>']]; |
|
| 38 | 38 | }]); |
| 39 | 39 | |
| 40 | 40 | $this->grid->addDecorator('created_by', ['Multiformat', function($row, $column) { |
| 41 | - if (! $user = User::find($row[$column])) return ''; |
|
| 41 | + if (!$user = User::find($row[$column])) return ''; |
|
| 42 | 42 | |
| 43 | 43 | return [['Template', $user->name]]; |
| 44 | 44 | }]); |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | }]); |
| 39 | 39 | |
| 40 | 40 | $this->grid->addDecorator('created_by', ['Multiformat', function($row, $column) { |
| 41 | - if (! $user = User::find($row[$column])) return ''; |
|
| 41 | + if (! $user = User::find($row[$column])) { |
|
| 42 | + return ''; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | return [['Template', $user->name]]; |
| 44 | 46 | }]); |