| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | <?php namespace BookStack\Uploads; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use BookStack\Entities\Page; | 
					
						
							|  |  |  | use BookStack\Ownable; | 
					
						
							| 
									
										
										
										
											2016-10-10 01:58:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 22:12:26 +08:00
										 |  |  | class Attachment extends Ownable | 
					
						
							| 
									
										
										
										
											2016-10-10 01:58:22 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     protected $fillable = ['name', 'order']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-23 20:36:45 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the downloadable file name for this upload. | 
					
						
							|  |  |  |      * @return mixed|string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getFileName() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-09-14 06:58:40 +08:00
										 |  |  |         if (strpos($this->name, '.') !== false) { | 
					
						
							| 
									
										
										
										
											2018-01-29 00:58:52 +08:00
										 |  |  |             return $this->name; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-10-23 20:36:45 +08:00
										 |  |  |         return $this->name . '.' . $this->extension; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-10 01:58:22 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the page this file was uploaded to. | 
					
						
							| 
									
										
										
										
											2018-09-26 01:00:40 +08:00
										 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | 
					
						
							| 
									
										
										
										
											2016-10-10 01:58:22 +08:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function page() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(Page::class, 'uploaded_to'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 03:30:27 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the url of this file. | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getUrl() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-05-20 18:06:10 +08:00
										 |  |  |         if ($this->external && strpos($this->path, 'http') !== 0) { | 
					
						
							|  |  |  |             return $this->path; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-08-04 21:26:39 +08:00
										 |  |  |         return url('/attachments/' . $this->id); | 
					
						
							| 
									
										
										
										
											2016-10-11 03:30:27 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-10 01:58:22 +08:00
										 |  |  | } |