Rev 229 Rev 236
1 <?php 1 <?php
2   2  
3 /** 3 /**
4 * Singapore gallery item class. 4 * Singapore gallery item class.
5 * 5 *
6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License 7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
8 * @copyright (c)2005-6 Tamlyn Rhodes 8 * @copyright (c)2005-6 Tamlyn Rhodes
9 * @version $Id: item.class.php,v 1.10 2006/09/08 15:29:22 tamlyn Exp $ 9 * @version $Id: item.class.php,v 1.10 2006/09/08 15:29:22 tamlyn Exp $
10 */ 10 */
11   11  
12 //permissions bit flags 12 //permissions bit flags
13 define("SG_GRP_READ", 1); 13 define("SG_GRP_READ", 1);
14 define("SG_GRP_EDIT", 2); 14 define("SG_GRP_EDIT", 2);
15 define("SG_GRP_ADD", 4); 15 define("SG_GRP_ADD", 4);
16 define("SG_GRP_DELETE", 8); 16 define("SG_GRP_DELETE", 8);
17 define("SG_WLD_READ", 16); 17 define("SG_WLD_READ", 16);
18 define("SG_WLD_EDIT", 32); 18 define("SG_WLD_EDIT", 32);
19 define("SG_WLD_ADD", 64); 19 define("SG_WLD_ADD", 64);
20 define("SG_WLD_DELETE", 128); 20 define("SG_WLD_DELETE", 128);
21 define("SG_IHR_READ", 17); 21 define("SG_IHR_READ", 17);
22 define("SG_IHR_EDIT", 34); 22 define("SG_IHR_EDIT", 34);
23 define("SG_IHR_ADD", 68); 23 define("SG_IHR_ADD", 68);
24 define("SG_IHR_DELETE", 136); 24 define("SG_IHR_DELETE", 136);
25   25  
26 /** 26 /**
27 * Abstract class from which sgImage and sgGallery are derived. 27 * Abstract class from which sgImage and sgGallery are derived.
28 * 28 *
29 * @abstract 29 * @abstract
30 * @package singapore 30 * @package singapore
31 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 31 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
32 * @copyright (c)2005-6 Tamlyn Rhodes 32 * @copyright (c)2005-6 Tamlyn Rhodes
33 */ 33 */
34 class sgItem 34 class sgItem
35 { 35 {
36 /** 36 /**
37 * The id of the item. In the case of galleries this is the path to the 37 * The id of the item. In the case of galleries this is the path to the
38 * gallery from root and must be unique. For images it is the image file 38 * gallery from root and must be unique. For images it is the image file
39 * name (or URL for remote images). 39 * name (or URL for remote images).
40 * @var string 40 * @var string
41 */ 41 */
42 var $id; 42 var $id;
43 43
44 /** 44 /**
45 * Username of the user to which the item belongs 45 * Username of the user to which the item belongs
46 * @var string 46 * @var string
47 */ 47 */
48 var $owner = "__nobody__"; 48 var $owner = "__nobody__";
49 49
50 /** 50 /**
51 * Space-separated list of groups to which the item belongs 51 * Space-separated list of groups to which the item belongs
52 * @var string 52 * @var string
53 */ 53 */
54 var $groups = ""; 54 var $groups = "";
55 55
56 /** 56 /**
57 * Bit-field of permissions 57 * Bit-field of permissions
58 * Default is to inherit everything. 58 * Default is to inherit everything.
59 * @var int 59 * @var int
60 */ 60 */
61 var $permissions = 255; 61 var $permissions = 255;
62 62
63 /** 63 /**
64 * Space-separated list of categories to which the item belongs (not used) 64 * Space-separated list of categories to which the item belongs (not used)
65 * @var string 65 * @var string
66 */ 66 */
67 var $categories = ""; 67 var $categories = "";
68 68
69 /** 69 /**
70 * The name or title of the item 70 * The name or title of the item
71 * @var string 71 * @var string
72 */ 72 */
73 var $name = ""; 73 var $name = "";
74 74
75 /** 75 /**
76 * The name of the original item creator (or anyone else) 76 * The name of the original item creator (or anyone else)
77 * @var string 77 * @var string
78 */ 78 */
79 var $artist = ""; 79 var $artist = "";
80 80
81 /** 81 /**
82 * Email of the original item creator (or anyone else) 82 * Email of the original item creator (or anyone else)
83 * @var string 83 * @var string
84 */ 84 */
85 var $email = ""; 85 var $email = "";
86 86
87 /** 87 /**
88 * Optional copyright information 88 * Optional copyright information
89 * @var string 89 * @var string
90 */ 90 */
91 var $copyright = ""; 91 var $copyright = "";
92 92
93 /** 93 /**
94 * Multiline description of the item 94 * Multiline description of the item
95 * @var string 95 * @var string
96 */ 96 */
97 var $desc = ""; 97 var $desc = "";
98 98
99 /** 99 /**
100 * Date associated with item 100 * Date associated with item
101 * @var string 101 * @var string
102 */ 102 */
103 var $date = ""; 103 var $date = "";
104 104
105 var $location = ""; 105 var $location = "";
106 106
107 /** 107 /**
108 * Number of times item has been viewed 108 * Number of times item has been viewed
109 * @var int 109 * @var int
110 */ 110 */
111 var $hits = 0; 111 var $hits = 0;
112 112
113 /** 113 /**
114 * Unix timestamp of last time item was viewed 114 * Unix timestamp of last time item was viewed
115 * @var int 115 * @var int
116 */ 116 */
117 var $lasthit = 0; 117 var $lasthit = 0;
118 118
119 /** 119 /**
120 * Pointer to the parent sgItem 120 * Pointer to the parent sgItem
121 * @var sgItem 121 * @var sgItem
122 */ 122 */
123 var $parent; 123 var $parent;
124 124
125 125
126 /** 126 /**
127 * Reference to the current config object 127 * Reference to the current config object
128 * @var sgConfig 128 * @var sgConfig
129 */ 129 */
130 var $config; 130 var $config;
131 131
132 /** 132 /**
133 * Reference to the current translator object 133 * Reference to the current translator object
134 * @var Translator 134 * @var Translator
135 */ 135 */
136 var $translator; 136 var $translator;
137 137
138 /** 138 /**
139 * Array in which the various sized thumbnails representing this item are stored 139 * Array in which the various sized thumbnails representing this item are stored
140 * @var array 140 * @var array
141 */ 141 */
142 var $thumbnails = array(); 142 var $thumbnails = array();
143 143
144 /** Accessor methods */ 144 /** Accessor methods */
145 function name() { return $this->name; } 145 function name() { return $this->name; }
146 function artist() { return $this->artist; } 146 function artist() { return $this->artist; }
147 function date() { return $this->date; } 147 function date() { return $this->date; }
148 function location() { return $this->location; } 148 function location() { return $this->location; }
149 function description() { return $this->desc; } 149 function description() { return $this->desc; }
150 150
151 function canEdit() { return false; } 151 function canEdit() { return false; }
152 152
153 function idEntities() { return htmlspecialchars($this->id); } 153 function idEntities() { return htmlspecialchars($this->id); }
154 154
155 /** 155 /**
156 * Removes script-generated HTML (BRs and URLs) but leaves any other HTML 156 * Removes script-generated HTML (BRs and URLs) but leaves any other HTML
157 * @return string the description of the item 157 * @return string the description of the item
158 */ 158 */
159 function descriptionStripped() 159 function descriptionStripped()
160 { 160 {
161 $ret = str_replace("<br />","\n",$this->description()); 161 $ret = str_replace("<br />","\n",$this->description());
162 162
163 if($this->config->enable_clickable_urls) { 163 if($this->config->enable_clickable_urls) {
164 //strip off html from autodetected URLs 164 //strip off html from autodetected URLs
165 $ret = preg_replace('{<a href="('.SG_REGEXP_PROTOCOLURL.')\">\1</a>}', '\1', $ret); 165 $ret = preg_replace('{<a href="('.SG_REGEXP_PROTOCOLURL.')\">\1</a>}', '\1', $ret);
166 $ret = preg_replace('{<a href="http://('.SG_REGEXP_WWWURL.')">\1</a>}', '\1', $ret); 166 $ret = preg_replace('{<a href="http://('.SG_REGEXP_WWWURL.')">\1</a>}', '\1', $ret);
167 $ret = preg_replace('{<a href="mailto:('.SG_REGEXP_EMAILURL.')">\1</a>}', '\1', $ret); 167 $ret = preg_replace('{<a href="mailto:('.SG_REGEXP_EMAILURL.')">\1</a>}', '\1', $ret);
168 } 168 }
169 169
170 return $ret; 170 return $ret;
171 } 171 }
172 172
173 /** 173 /**
174 * If the current item has an artist specified, returns " by " followed 174 * If the current item has an artist specified, returns " by " followed
175 * by the artist's name. Otherwise returns an empty string. 175 * by the artist's name. Otherwise returns an empty string.
176 * @return string 176 * @return string
177 */ 177 */
178 function byArtistText() 178 function byArtistText()
179 { 179 {
180 if(empty($this->artist)) 180 if(empty($this->artist))
181 return ""; 181 return "";
182 else 182 else
183 return " ".$this->translator->_g("artist name|by %s",$this->artist); 183 return " ".$this->translator->_g("artist name|by %s",$this->artist);
184 } 184 }
185 185
186 /** 186 /**
187 * Obfuscates the given email address by replacing "." with "dot" and "@" with "at" 187 * Obfuscates the given email address by replacing "." with "dot" and "@" with "at"
188 * @param boolean override the obfuscate_email config setting (optional) 188 * @param boolean override the obfuscate_email config setting (optional)
189 * @return string obfuscated email address or HTML mailto link 189 * @return string obfuscated email address or HTML mailto link
190 */ 190 */
191 function emailLink($forceObfuscate = false) 191 function emailLink($forceObfuscate = false)
192 { 192 {
193 if($this->config->obfuscate_email || $forceObfuscate) 193 if($this->config->obfuscate_email || $forceObfuscate)
194 return strtr($this->email,array("@" => ' <b>'.$this->translator->_g("email|at").'</b> ', "." => ' <b>'.$this->translator->_g("email|dot").'</b> ')); 194 return strtr($this->email,array("@" => ' <b>'.$this->translator->_g("email|at").'</b> ', "." => ' <b>'.$this->translator->_g("email|dot").'</b> '));
195 else 195 else
196 return "<a href=\"mailto:".$this->email."\">".$this->email."</a>"; 196 return "<a href=\"mailto:".$this->email."\">".$this->email."</a>";
197 } 197 }
198   198  
199 function nameLink($action = null) 199 function nameLink($action = null)
200 { 200 {
201 return '<a href="'.$this->URL(0, $action).'">'.$this->nameForce().'</a>'; 201 return '<a href="'.$this->URL(0, $action).'">'.$this->nameForce().'</a>';
202 } 202 }
203 203
204 function parentURL($action = null) 204 function parentURL($action = null)
205 { 205 {
206 $perpage = $this->parent->isAlbum() ? $this->config->thumb_number_album : $this->config->thumb_number_gallery; 206 $perpage = $this->parent->isAlbum() ? $this->config->thumb_number_album : $this->config->thumb_number_gallery;
207 return $this->parent->URL(floor($this->index() / $perpage) * $perpage, $action); 207 return $this->parent->URL(floor($this->index() / $perpage) * $perpage, $action);
208 } 208 }
209 209
210 function parentLink($action = null) 210 function parentLink($action = null)
211 { 211 {
212 return '<a href="'.$this->parentURL($action).'">'.$this->parentText().'</a>'; 212 return '<a href="'.$this->parentURL($action).'">'.$this->parentText().'</a>';
213 } 213 }
214 214
215 function parentText() 215 function parentText()
216 { 216 {
217 return $this->translator->_g("gallery|Up"); 217 return $this->translator->_g("gallery|Up");
218 } 218 }
219 219
220 /** 220 /**
221 * @return array associative array of item properties in the form "name" => "value" 221 * @return array associative array of item properties in the form "name" => "value"
222 */ 222 */
223 function detailsArray() 223 function detailsArray()
224 { 224 {
225 $ret = array(); 225 $ret = array();
226 226
227 //generic properties 227 //generic properties
228 if(!empty($this->date)) $ret[$this->translator->_g("Date")] = $this->date; 228 if(!empty($this->date)) $ret[$this->translator->_g("Date")] = $this->date;
229 if(!empty($this->location)) $ret[$this->translator->_g("Location")] = $this->location; 229 if(!empty($this->location)) $ret[$this->translator->_g("Location")] = $this->location;
230 if(!empty($this->desc)) $ret[$this->translator->_g("Description")] = $this->desc; 230 if(!empty($this->desc)) $ret[$this->translator->_g("Description")] = $this->desc;
231 if(!empty($this->email)) $ret[$this->translator->_g("Email")] = $this->emailLink(); 231 if(!empty($this->email)) $ret[$this->translator->_g("Email")] = $this->emailLink();
232 232
233 //image properties 233 //image properties
234 if(!empty($this->camera)) $ret[$this->translator->_g("Camera")] = $this->camera; 234 if(!empty($this->camera)) $ret[$this->translator->_g("Camera")] = $this->camera;
235 if(!empty($this->lens)) $ret[$this->translator->_g("Lens")] = $this->lens; 235 if(!empty($this->lens)) $ret[$this->translator->_g("Lens")] = $this->lens;
236 if(!empty($this->film)) $ret[$this->translator->_g("Film")] = $this->film; 236 if(!empty($this->film)) $ret[$this->translator->_g("Film")] = $this->film;
237 if(!empty($this->darkroom)) $ret[$this->translator->_g("Darkroom manipulation")] = $this->darkroom; 237 if(!empty($this->darkroom)) $ret[$this->translator->_g("Darkroom manipulation")] = $this->darkroom;
238 if(!empty($this->digital)) $ret[$this->translator->_g("Digital manipulation")] = $this->digital; 238 if(!empty($this->digital)) $ret[$this->translator->_g("Digital manipulation")] = $this->digital;
239 239
240 //special properties 240 //special properties
241 if(!empty($this->copyright)) $ret[$this->translator->_g("Copyright")] = $this->copyright; 241 if(!empty($this->copyright)) $ret[$this->translator->_g("Copyright")] = $this->copyright;
242 elseif(!empty($this->artist))$ret[$this->translator->_g("Copyright")] = $this->artist; 242 elseif(!empty($this->artist))$ret[$this->translator->_g("Copyright")] = $this->artist;
243 if($this->config->show_views) 243 if($this->config->show_views)
244 $ret[$this->translator->_g("Viewed")] = $this->translator->_ng("viewed|%s time", "viewed|%s times",$this->hits); 244 $ret[$this->translator->_g("Viewed")] = $this->translator->_ng("viewed|%s time", "viewed|%s times",$this->hits);
245 245
246 return $ret; 246 return $ret;
247 } 247 }
248 248
249 function isAlbum() { return false; } 249 function isAlbum() { return false; }
250 function isGallery() { return false; } 250 function isGallery() { return false; }
251 function isImage() { return false; } 251 function isImage() { return false; }
252   252  
253 /** 253 /**
254 * Returns a link to the image or gallery with the correct formatting and path 254 * Returns a link to the image or gallery with the correct formatting and path
255 * 255 *
256 * @param int page offset (optional) 256 * @param int page offset (optional)
257 * @param string action to perform (optional) 257 * @param string action to perform (optional)
258 * @return string formatted URL 258 * @return string formatted URL
259 */ 259 */
260 function URL($startat = null, $action = null) 260 function URL($startat = null, $action = null)
261 { 261 {
262 $query = array(); 262 $query = array();
263 if($this->config->use_mod_rewrite) { //format url for use with mod_rewrite 263 if($this->config->use_mod_rewrite) { //format url for use with mod_rewrite
264 $ret = $this->config->base_url; 264 $ret = $this->config->base_url;
265 $ret .= $this->isImage() ? $this->parent->idEncoded() : $this->idEncoded(); 265 $ret .= $this->isImage() ? $this->parent->idEncoded() : $this->idEncoded();
266 if($startat) $ret .= ','.$startat; 266 if($startat) $ret .= ','.$startat;
267 $ret .= '/'; 267 $ret .= '/';
268 if($this->isImage()) $ret .= $this->idEncoded(); 268 if($this->isImage()) $ret .= $this->idEncoded();
269 269
270 if($action) $query[] = $this->config->url_action."=".$action; 270 if($action) $query[] = $this->config->url_action."=".$action;
271 if($this->translator->language != $this->config->default_language) $query[] = $this->config->url_lang.'='.$this->translator->language; 271 if($this->translator->language != $this->config->default_language) $query[] = $this->config->url_lang.'='.$this->translator->language;
272 if($GLOBALS["sg"]->template != $this->config->default_template) $query[] = $this->config->url_template.'='.$GLOBALS["sg"]->template; 272 if($GLOBALS["sg"]->template != $this->config->default_template) $query[] = $this->config->url_template.'='.$GLOBALS["sg"]->template;
273 273
274 if(!empty($query)) 274 if(!empty($query))
275 $ret .= '?'.implode(ini_get('arg_separator.output'), $query); 275 $ret .= '?'.implode(ini_get('arg_separator.output'), $query);
276 276
277 } else { //format plain url 277 } else { //format plain url
278 278
279 $query[] = $this->config->url_gallery."=".($this->isImage() ? $this->parent->idEncoded() : $this->idEncoded()); 279 $query[] = $this->config->url_gallery."=".($this->isImage() ? $this->parent->idEncoded() : $this->idEncoded());
280 if($this->isImage()) $query[] = $this->config->url_image."=".$this->idEncoded(); 280 if($this->isImage()) $query[] = $this->config->url_image."=".$this->idEncoded();
281 if($startat) $query[] = $this->config->url_startat."=".$startat; 281 if($startat) $query[] = $this->config->url_startat."=".$startat;
282 if($action) $query[] = $this->config->url_action."=".$action; 282 if($action) $query[] = $this->config->url_action."=".$action;
283 if($this->translator->language != $this->config->default_language) 283 if($this->translator->language != $this->config->default_language)
284 $query[] = $this->config->url_lang.'='.$this->translator->language; 284 $query[] = $this->config->url_lang.'='.$this->translator->language;
285 if(isset($GLOBALS["sg"]->template) && $GLOBALS["sg"]->template != $this->config->default_template) 285 if(isset($GLOBALS["sg"]->template) && $GLOBALS["sg"]->template != $this->config->default_template)
286 $query[] = $this->config->url_template.'='.$GLOBALS["sg"]->template; 286 $query[] = $this->config->url_template.'='.$GLOBALS["sg"]->template;
287 287
288 $ret = $this->config->index_file_url.implode(ini_get('arg_separator.output'), $query); 288 $ret = $this->config->index_file_url.implode(ini_get('arg_separator.output'), $query);
289 } 289 }
290 290
291 return $ret; 291 return $ret;
292 } 292 }
293 293
294 } 294 }
295   295  
296   296  
297 ?> 297 ?>