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