Rev 229 Rev 236
1 <?php 1 <?php
2   2  
3 /** 3 /**
4 * IO class. 4 * IO class.
5 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License 5 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
6 * @copyright (c)2003-2005 Tamlyn Rhodes 6 * @copyright (c)2003-2005 Tamlyn Rhodes
7 * @version $Id: io.class.php,v 1.11 2005/12/04 04:39:46 tamlyn Exp $ 7 * @version $Id: io.class.php,v 1.11 2005/12/04 04:39:46 tamlyn Exp $
8 */ 8 */
9   9  
10 /** 10 /**
11 * Abstract superclass of all IO classes. Also implements iifn code. 11 * Abstract superclass of all IO classes. Also implements iifn code.
12 * @package singapore 12 * @package singapore
13 * @abstract 13 * @abstract
14 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 14 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
15 * @copyright (c)2003, 2004 Tamlyn Rhodes 15 * @copyright (c)2003, 2004 Tamlyn Rhodes
16 */ 16 */
17 class sgIO 17 class sgIO
18 { 18 {
19 19
20 /** 20 /**
21 * Reference to a {@link sgConfig} object representing the current 21 * Reference to a {@link sgConfig} object representing the current
22 * script configuration 22 * script configuration
23 * @var sgConfig 23 * @var sgConfig
24 */ 24 */
25 var $config; 25 var $config;
26 26
27 /** 27 /**
28 * Constructor. Can be over-ridden by subclass but does not need to be. 28 * Constructor. Can be over-ridden by subclass but does not need to be.
29 * @param sgConfig pointer to current script configuration object 29 * @param sgConfig pointer to current script configuration object
30 */ 30 */
31 function sgIO() 31 function sgIO()
32 { 32 {
33 $this->config =& sgConfig::getInstance(); 33 $this->config =& sgConfig::getInstance();
34 } 34 }
35 35
36 /** 36 /**
37 * Pseudo-abstract method to be over-ridden in subclasses. 37 * Pseudo-abstract method to be over-ridden in subclasses.
38 */ 38 */
39 function getName() 39 function getName()
40 { 40 {
41 return "undefined"; 41 return "undefined";
42 } 42 }
43   43  
44 /** 44 /**
45 * Pseudo-abstract method to be over-ridden in subclasses. 45 * Pseudo-abstract method to be over-ridden in subclasses.
46 */ 46 */
47 function getVersion() 47 function getVersion()
48 { 48 {
49 return "undefined"; 49 return "undefined";
50 } 50 }
51   51  
52 /** 52 /**
53 * Pseudo-abstract method to be over-ridden in subclasses. 53 * Pseudo-abstract method to be over-ridden in subclasses.
54 */ 54 */
55 function getAuthor() 55 function getAuthor()
56 { 56 {
57 return "undefined"; 57 return "undefined";
58 } 58 }
59   59  
60 /** 60 /**
61 * Pseudo-abstract method to be over-ridden in subclasses. 61 * Pseudo-abstract method to be over-ridden in subclasses.
62 */ 62 */
63 function getDescription() 63 function getDescription()
64 { 64 {
65 return "undefined"; 65 return "undefined";
66 } 66 }
67   67  
68 /** 68 /**
69 * Fetches gallery info for the specified gallery (and immediate children). 69 * Fetches gallery info for the specified gallery (and immediate children).
70 * @param string gallery id 70 * @param string gallery id
71 * @param sgItem reference to parent gallery 71 * @param sgItem reference to parent gallery
72 * @param int number of levels of child galleries to fetch (optional) 72 * @param int number of levels of child galleries to fetch (optional)
73 * @param string language code spec for this request (optional, ignored) 73 * @param string language code spec for this request (optional, ignored)
74 */ 74 */
75 function &getGallery($galleryId, &$parent, $getChildGalleries = 1, $language = null) 75 function &getGallery($galleryId, &$parent, $getChildGalleries = 1, $language = null)
76 { 76 {
77 $gal =& new sgGallery($galleryId, $parent); 77 $gal =& new sgGallery($galleryId, $parent);
78 78
79 if(file_exists($this->config->base_path.$this->config->pathto_galleries.$galleryId)) { 79 if(file_exists($this->config->base_path.$this->config->pathto_galleries.$galleryId)) {
80 80
81 $bits = explode("/",$gal->id); 81 $bits = explode("/",$gal->id);
82 $temp = strtr($bits[count($bits)-1], "_", " "); 82 $temp = strtr($bits[count($bits)-1], "_", " ");
83 if($temp == ".") 83 if($temp == ".")
84 $gal->name = $this->config->gallery_name; 84 $gal->name = $this->config->gallery_name;
85 elseif($this->config->enable_iifn && strpos($temp, " - ")) 85 elseif($this->config->enable_iifn && strpos($temp, " - "))
86 list($gal->artist,$gal->name) = explode(" - ", $temp); 86 list($gal->artist,$gal->name) = explode(" - ", $temp);
87 else 87 else
88 $gal->name = $temp; 88 $gal->name = $temp;
89 89
90 $dir = Singapore::getListing($this->config->base_path.$this->config->pathto_galleries.$gal->id."/", $this->config->recognised_extensions); 90 $dir = Singapore::getListing($this->config->base_path.$this->config->pathto_galleries.$gal->id."/", $this->config->recognised_extensions);
91 91
92 //set gallery thumbnail to first image in gallery (if any) 92 //set gallery thumbnail to first image in gallery (if any)
93 if(isset($dir->files[0])) $gal->filename = $dir->files[0]; 93 if(isset($dir->files[0])) $gal->filename = $dir->files[0];
94 94
95 for($i=0; $i<count($dir->files); $i++) 95 for($i=0; $i<count($dir->files); $i++)
96 //always get the first image for the gallery thumbnail 96 //always get the first image for the gallery thumbnail
97 //but only get the rest if child galleries are requested 97 //but only get the rest if child galleries are requested
98 if($getChildGalleries || $i==0) { 98 if($getChildGalleries || $i==0) {
99 $gal->images[$i] =& new sgImage($dir->files[$i], $gal); 99 $gal->images[$i] =& new sgImage($dir->files[$i], $gal);
100 100
101 //trim off file extension and replace underscores with spaces 101 //trim off file extension and replace underscores with spaces
102 $temp = strtr(substr($gal->images[$i]->id, 0, strrpos($gal->images[$i]->id,".")-strlen($gal->images[$i]->id)), "_", " "); 102 $temp = strtr(substr($gal->images[$i]->id, 0, strrpos($gal->images[$i]->id,".")-strlen($gal->images[$i]->id)), "_", " ");
103 //split string in two on " - " delimiter 103 //split string in two on " - " delimiter
104 if($this->config->enable_iifn && strpos($temp, " - ")) 104 if($this->config->enable_iifn && strpos($temp, " - "))
105 list($gal->images[$i]->artist,$gal->images[$i]->name) = explode(" - ", $temp); 105 list($gal->images[$i]->artist,$gal->images[$i]->name) = explode(" - ", $temp);
106 else 106 else
107 $gal->images[$i]->name = $temp; 107 $gal->images[$i]->name = $temp;
108 108
109 //get image size and type 109 //get image size and type
110 list( 110 list(
111 $gal->images[$i]->width, 111 $gal->images[$i]->width,
112 $gal->images[$i]->height, 112 $gal->images[$i]->height,
113 $gal->images[$i]->type 113 $gal->images[$i]->type
114 ) = @GetImageSize($this->config->base_path.$this->config->pathto_galleries.$gal->id."/".$gal->images[$i]->id); 114 ) = @GetImageSize($this->config->base_path.$this->config->pathto_galleries.$gal->id."/".$gal->images[$i]->id);
115 115
116 //set parent link 116 //set parent link
117 $gal->images[$i]->parent =& $gal; 117 $gal->images[$i]->parent =& $gal;
118 } else 118 } else
119 //otherwise just create an empty array of the appropriate length 119 //otherwise just create an empty array of the appropriate length
120 $gal->images[$i] = $dir->files[$i]; 120 $gal->images[$i] = $dir->files[$i];
121 } else { 121 } else {
122 //selected gallery does not exist 122 //selected gallery does not exist
123 return null; 123 return null;
124 } 124 }
125 125
126 //discover child galleries 126 //discover child galleries
127 if($getChildGalleries) 127 if($getChildGalleries)
128 //but only fetch their info if required too 128 //but only fetch their info if required too
129 foreach($dir->dirs as $gallery) 129 foreach($dir->dirs as $gallery)
130 $gal->galleries[] =& $this->getGallery($galleryId."/".$gallery, $gal, $getChildGalleries-1, $language); 130 $gal->galleries[] =& $this->getGallery($galleryId."/".$gallery, $gal, $getChildGalleries-1, $language);
131 else 131 else
132 //otherwise just copy their names in so they can be counted 132 //otherwise just copy their names in so they can be counted
133 $gal->galleries = $dir->dirs; 133 $gal->galleries = $dir->dirs;
134 134
135 return $gal; 135 return $gal;
136 } 136 }
137 137
138 /** 138 /**
139 * Pseudo-abstract method to be over-ridden in subclasses. 139 * Pseudo-abstract method to be over-ridden in subclasses.
140 */ 140 */
141 function putGallery($gal) { 141 function putGallery($gal) {
142 return false; 142 return false;
143 } 143 }
144 144
145 /** 145 /**
146 * Pseudo-abstract method to be over-ridden in subclasses. 146 * Pseudo-abstract method to be over-ridden in subclasses.
147 */ 147 */
148 function getHits($gal) { 148 function getHits($gal) {
149 return false; 149 return false;
150 } 150 }
151 151
152 /** 152 /**
153 * Pseudo-abstract method to be over-ridden in subclasses. 153 * Pseudo-abstract method to be over-ridden in subclasses.
154 */ 154 */
155 function putHits($gal) { 155 function putHits($gal) {
156 return false; 156 return false;
157 } 157 }
158 158
159 /** 159 /**
160 * Pseudo-abstract method to be over-ridden in subclasses. 160 * Pseudo-abstract method to be over-ridden in subclasses.
161 */ 161 */
162 function getUsers() { 162 function getUsers() {
163 return array(); 163 return array();
164 } 164 }
165 165
166 /** 166 /**
167 * Pseudo-abstract method to be over-ridden in subclasses. 167 * Pseudo-abstract method to be over-ridden in subclasses.
168 */ 168 */
169 function putUsers($users) { 169 function putUsers($users) {
170 return false; 170 return false;
171 } 171 }
172 } 172 }
173   173  
174 ?> 174 ?>