Some refactoring
Better handling of cover
This commit is contained in:
		
							parent
							
								
									984f1b2a41
								
							
						
					
					
						commit
						06430d7563
					
				
					 1 changed files with 33 additions and 28 deletions
				
			
		
							
								
								
									
										43
									
								
								book.php
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								book.php
									
										
									
									
									
								
							|  | @ -15,7 +15,7 @@ class Book extends Base { | ||||||
|     const ALL_BOOKS_UUID = "urn:uuid"; |     const ALL_BOOKS_UUID = "urn:uuid"; | ||||||
|     const ALL_BOOKS_ID = "calibre:books"; |     const ALL_BOOKS_ID = "calibre:books"; | ||||||
|     const ALL_RECENT_BOOKS_ID = "calibre:recentbooks"; |     const ALL_RECENT_BOOKS_ID = "calibre:recentbooks"; | ||||||
|     const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid"; |     const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover"; | ||||||
|      |      | ||||||
|     public $id; |     public $id; | ||||||
|     public $title; |     public $title; | ||||||
|  | @ -23,6 +23,7 @@ class Book extends Base { | ||||||
|     public $pubdate; |     public $pubdate; | ||||||
|     public $path; |     public $path; | ||||||
|     public $uuid; |     public $uuid; | ||||||
|  |     public $hasCover; | ||||||
|     public $relativePath; |     public $relativePath; | ||||||
|     public $seriesIndex; |     public $seriesIndex; | ||||||
|     public $comment; |     public $comment; | ||||||
|  | @ -47,6 +48,7 @@ class Book extends Base { | ||||||
|         $this->seriesIndex = $line->series_index; |         $this->seriesIndex = $line->series_index; | ||||||
|         $this->comment = $line->comment; |         $this->comment = $line->comment; | ||||||
|         $this->uuid = $line->uuid; |         $this->uuid = $line->uuid; | ||||||
|  |         $this->hasCover = $line->has_cover; | ||||||
|     } |     } | ||||||
|          |          | ||||||
|     public function getEntryId () { |     public function getEntryId () { | ||||||
|  | @ -156,21 +158,28 @@ class Book extends Base { | ||||||
|         return NULL; |         return NULL; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     private function getLink ($type, $mime, $rel, $filename, $title = NULL) | ||||||
|  |     { | ||||||
|  |         global $config; | ||||||
|  |          | ||||||
|  |         if (preg_match ('/^\//', $config['calibre_directory'])) | ||||||
|  |         { | ||||||
|  |             return new Link ("fetch.php?id=$this->id&type=" . $type, $mime, $rel, $title); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             return new Link (str_replace('%2F','/',rawurlencode ($this->path."/".$filename)), $mime, $rel, $title); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|     public function getLinkArray () |     public function getLinkArray () | ||||||
|     { |     { | ||||||
|         global $config; |         global $config; | ||||||
|         $linkArray = array(); |         $linkArray = array(); | ||||||
|         if ($handle = opendir($this->path)) { |          | ||||||
|             while (false !== ($file = readdir($handle))) { |         if ($this->hasCover) | ||||||
|                 if (preg_match ('/jpg$/', $file)) { |  | ||||||
|                     if (preg_match ('/^\//', $config['calibre_directory'])) |  | ||||||
|         { |         { | ||||||
|                         array_push ($linkArray, new Link ("fetch.php?id=$this->id", "image/jpeg", Link::OPDS_IMAGE_TYPE)); |             array_push ($linkArray, $this->getLink ("jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg")); | ||||||
|                     } |  | ||||||
|                     else |  | ||||||
|                     { |  | ||||||
|                         array_push ($linkArray, new Link (str_replace('%2F','/',rawurlencode ($this->path."/".$file)), "image/jpeg", Link::OPDS_IMAGE_TYPE)); |  | ||||||
|                     } |  | ||||||
|             $height = "50"; |             $height = "50"; | ||||||
|             if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |             if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { | ||||||
|                 $height = $config['cops_opds_thumbnail_height']; |                 $height = $config['cops_opds_thumbnail_height']; | ||||||
|  | @ -181,18 +190,14 @@ class Book extends Base { | ||||||
|             } |             } | ||||||
|             array_push ($linkArray, new Link ("fetch.php?id=$this->id&height=" . $height, "image/jpeg", Link::OPDS_THUMBNAIL_TYPE)); |             array_push ($linkArray, new Link ("fetch.php?id=$this->id&height=" . $height, "image/jpeg", Link::OPDS_THUMBNAIL_TYPE)); | ||||||
|         } |         } | ||||||
|  |          | ||||||
|  |         if ($handle = opendir($this->path)) { | ||||||
|  |             while (false !== ($file = readdir($handle))) { | ||||||
|                 foreach (self::$mimetypes as $ext => $mime) |                 foreach (self::$mimetypes as $ext => $mime) | ||||||
|                 { |                 { | ||||||
|                     if (preg_match ('/'. $ext .'$/', $file)) { |                     if (preg_match ('/'. $ext .'$/', $file)) { | ||||||
|                         $this->format [$ext] = $file; |                         $this->format [$ext] = $file; | ||||||
|                         if (preg_match ('/^\//', $config['calibre_directory'])) |                         array_push ($linkArray, $this->getLink ($ext, $mime, Link::OPDS_ACQUISITION_TYPE, $file, "Download")); | ||||||
|                         { |  | ||||||
|                             array_push ($linkArray, new Link ("fetch.php?id=$this->id&type=" . $ext, $mime, Link::OPDS_ACQUISITION_TYPE, "Download")); |  | ||||||
|                         } |  | ||||||
|                         else |  | ||||||
|                         { |  | ||||||
|                             array_push ($linkArray, new Link (str_replace('%2F','/',rawurlencode ($this->path."/".$file)), $mime, Link::OPDS_ACQUISITION_TYPE, "Download")); |  | ||||||
|                         } |  | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue