Annotation of /trunk/lib/gallery.class.php
Parent Directory
|
Revision Log
Revision 2 - (view) (download)
| 1 : | andphe | 2 | <?php |
| 2 : | //zOOm Media Gallery// | ||
| 3 : | /** | ||
| 4 : | ----------------------------------------------------------------------- | ||
| 5 : | | zOOm Media Gallery! by Mike de Boer - a multi-gallery component | | ||
| 6 : | ----------------------------------------------------------------------- | ||
| 7 : | |||
| 8 : | ----------------------------------------------------------------------- | ||
| 9 : | | | | ||
| 10 : | | Author: Mike de Boer, <http://www.mikedeboer.nl> | | ||
| 11 : | | Copyright: copyright (C) 2007 by Mike de Boer | | ||
| 12 : | | Description: zOOm Media Gallery, a multi-gallery component for | | ||
| 13 : | | Joomla!. It's the most feature-rich gallery component | | ||
| 14 : | | for Joomla!! For documentation and a detailed list | | ||
| 15 : | | of features, check the zOOm homepage: | | ||
| 16 : | | http://www.zoomfactory.org | | ||
| 17 : | | License: GPL | | ||
| 18 : | | Filename: gallery.class.php | | ||
| 19 : | | | | ||
| 20 : | ----------------------------------------------------------------------- | ||
| 21 : | * @version $Id:gallery.class.php 113 2007-02-11 20:56:11Z kevinuru $ | ||
| 22 : | * @package zOOmGallery | ||
| 23 : | * @author Mike de Boer <mailme@mikedeboer.nl> | ||
| 24 : | **/ | ||
| 25 : | // MOS Intruder Alerts | ||
| 26 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 27 : | |||
| 28 : | /** | ||
| 29 : | * Gallery class; creates an instance of a gallery. | ||
| 30 : | * | ||
| 31 : | * @access public | ||
| 32 : | */ | ||
| 33 : | class gallery extends zoom { | ||
| 34 : | /** | ||
| 35 : | * @var int | ||
| 36 : | * @access private | ||
| 37 : | */ | ||
| 38 : | var $_id = null; | ||
| 39 : | /** | ||
| 40 : | * @var string | ||
| 41 : | * @access private | ||
| 42 : | */ | ||
| 43 : | var $_name = null; | ||
| 44 : | /** | ||
| 45 : | * @var string | ||
| 46 : | * @access private | ||
| 47 : | */ | ||
| 48 : | var $_descr = null; | ||
| 49 : | /** | ||
| 50 : | * @var string | ||
| 51 : | * @access private | ||
| 52 : | */ | ||
| 53 : | var $_dir = null; | ||
| 54 : | /** | ||
| 55 : | * @var int | ||
| 56 : | * @access private | ||
| 57 : | */ | ||
| 58 : | var $_cat_img = null; | ||
| 59 : | /** | ||
| 60 : | * @var string | ||
| 61 : | * @access private | ||
| 62 : | */ | ||
| 63 : | var $_password = null; | ||
| 64 : | /** | ||
| 65 : | * @var string | ||
| 66 : | * @access private | ||
| 67 : | */ | ||
| 68 : | var $_keywords = null; | ||
| 69 : | /** | ||
| 70 : | * @var int | ||
| 71 : | * @access private | ||
| 72 : | */ | ||
| 73 : | var $_subcat_id = null; | ||
| 74 : | /** | ||
| 75 : | * @var int | ||
| 76 : | * @access private | ||
| 77 : | */ | ||
| 78 : | var $_pos = null; | ||
| 79 : | /** | ||
| 80 : | * @var int | ||
| 81 : | * @access private | ||
| 82 : | */ | ||
| 83 : | var $_custom_order = null; | ||
| 84 : | /** | ||
| 85 : | * @var int | ||
| 86 : | * @access private | ||
| 87 : | */ | ||
| 88 : | var $_hideMsg = null; | ||
| 89 : | /** | ||
| 90 : | * @var int | ||
| 91 : | * @access private | ||
| 92 : | */ | ||
| 93 : | var $_shared = null; | ||
| 94 : | /** | ||
| 95 : | * @var int | ||
| 96 : | * @access private | ||
| 97 : | */ | ||
| 98 : | var $_published = null; | ||
| 99 : | /** | ||
| 100 : | * @var int | ||
| 101 : | * @access private | ||
| 102 : | */ | ||
| 103 : | var $_uid = null; | ||
| 104 : | /** | ||
| 105 : | * @var string | ||
| 106 : | * @access private | ||
| 107 : | */ | ||
| 108 : | var $_sql = null; | ||
| 109 : | /** | ||
| 110 : | * @var object | ||
| 111 : | * @access private | ||
| 112 : | */ | ||
| 113 : | var $_result = null; | ||
| 114 : | /** | ||
| 115 : | * @var array | ||
| 116 : | * @access private | ||
| 117 : | */ | ||
| 118 : | var $_subcats = array(); | ||
| 119 : | /** | ||
| 120 : | * @var array | ||
| 121 : | * @access private | ||
| 122 : | */ | ||
| 123 : | var $_images = array(); | ||
| 124 : | /** | ||
| 125 : | * @var array | ||
| 126 : | * @access private | ||
| 127 : | */ | ||
| 128 : | var $_members = array(); | ||
| 129 : | |||
| 130 : | /** | ||
| 131 : | * Gallery object contructor. | ||
| 132 : | * | ||
| 133 : | * @param int $gallery_id | ||
| 134 : | * @param boolean $galleryview | ||
| 135 : | * @return gallery | ||
| 136 : | * @access public | ||
| 137 : | */ | ||
| 138 : | function gallery($gallery_id, $galleryview = false) { | ||
| 139 : | $this->_id = intval($this->escapeString($gallery_id)); | ||
| 140 : | $this->_getInfo($galleryview); | ||
| 141 : | if (!$galleryview) { | ||
| 142 : | // getting sub-categories (sub-galleries...) | ||
| 143 : | $this->_getSubCats($galleryview); | ||
| 144 : | // getting gallery images... | ||
| 145 : | $this->_getImages($galleryview); | ||
| 146 : | } | ||
| 147 : | } | ||
| 148 : | /** | ||
| 149 : | * Retrieves data from the 'mos_zoom' table and assigns it to | ||
| 150 : | * the class variables... | ||
| 151 : | * | ||
| 152 : | * @param boolean $galleryview | ||
| 153 : | * @access private | ||
| 154 : | */ | ||
| 155 : | function _getInfo($galleryview = false) { | ||
| 156 : | global $database; | ||
| 157 : | $database->setQuery("SELECT catid, catname, catdescr, catdir, catimg, subcat_id, catpassword, catkeywords, pos, custom_order, hideMsg, shared, published, uid, catmembers FROM #__zoom WHERE catid=".$this->_id." LIMIT 1"); | ||
| 158 : | $this->_result = $database->query(); | ||
| 159 : | $rows = $database->loadObjectList(); | ||
| 160 : | if (count($rows) > 0){ | ||
| 161 : | foreach ($rows as $row) { | ||
| 162 : | $this->_name = utf8_decode($this->stripslashesSafe($row->catname)); | ||
| 163 : | $this->_descr = utf8_decode($this->stripslashesSafe($row->catdescr)); | ||
| 164 : | $this->_dir = $row->catdir; | ||
| 165 : | $this->_cat_img = $row->catimg; | ||
| 166 : | $this->_subcat_id = $row->subcat_id; | ||
| 167 : | $this->_password = $row->catpassword; | ||
| 168 : | $this->_keywords = $row->catkeywords; | ||
| 169 : | $this->_pos = $row->pos; | ||
| 170 : | $this->_custom_order = $row->custom_order; | ||
| 171 : | $this->_hideMsg = $row->hideMsg; | ||
| 172 : | $this->_shared = $row->shared; | ||
| 173 : | $this->_published = $row->published; | ||
| 174 : | $this->_uid = $row->uid; | ||
| 175 : | $members = explode(",", $row->catmembers); | ||
| 176 : | // gallery-members of type 1 are of access-level 'public' | ||
| 177 : | // and members of type 2 are 'registered'. | ||
| 178 : | if (in_array("1", $members)) { | ||
| 179 : | $this->_members[0] = 1; | ||
| 180 : | } elseif(in_array("2", $members)) { | ||
| 181 : | $this->_members[0] = 2; | ||
| 182 : | } else { | ||
| 183 : | $this->_members = $members; | ||
| 184 : | } | ||
| 185 : | } | ||
| 186 : | } else { | ||
| 187 : | die("This is not a valid gallery-id. Please return to the homepage and try again."); | ||
| 188 : | } | ||
| 189 : | } | ||
| 190 : | /** | ||
| 191 : | * Get the sub-galleries of a gallery from the 'mos_zoom' table. | ||
| 192 : | * | ||
| 193 : | * @param boolean $galleryview | ||
| 194 : | * @access private | ||
| 195 : | */ | ||
| 196 : | function _getSubCats($galleryview = false) { | ||
| 197 : | global $database, $zoom; | ||
| 198 : | $orderMethod = $zoom->getCatOrderMethod(); | ||
| 199 : | $database->setQuery("SELECT catid FROM #__zoom WHERE subcat_id=".$this->_id." ORDER BY ".$orderMethod); | ||
| 200 : | $this->_result = $database->query(); | ||
| 201 : | while ($row = mysql_fetch_object($this->_result)) { | ||
| 202 : | if ($galleryview == true) { | ||
| 203 : | $subcat = new stdClass(); | ||
| 204 : | } else { | ||
| 205 : | $subcat = new gallery($row->catid, true); | ||
| 206 : | } | ||
| 207 : | $this->_subcats[] = $subcat; | ||
| 208 : | } | ||
| 209 : | } | ||
| 210 : | /** | ||
| 211 : | * Get the images of a gallery from the 'mos_zoomfiles' table. | ||
| 212 : | * | ||
| 213 : | * @param boolean $galleryview | ||
| 214 : | * @access private | ||
| 215 : | */ | ||
| 216 : | function _getImages($galleryview = false) { | ||
| 217 : | global $database, $zoom; | ||
| 218 : | $orderMethod = $zoom->getOrderMethod(); | ||
| 219 : | if($zoom->_isAdmin) { | ||
| 220 : | $database->setQuery("SELECT imgid FROM #__zoomfiles WHERE catid = ".$this->_id." ORDER BY ".$orderMethod); | ||
| 221 : | } else { | ||
| 222 : | $database->setQuery("SELECT imgid FROM #__zoomfiles WHERE catid = ".$this->_id." AND published = 1 ORDER BY ".$orderMethod); | ||
| 223 : | } | ||
| 224 : | $this->_result = $database->query(); | ||
| 225 : | while ($row = mysql_fetch_object($this->_result)) { | ||
| 226 : | if ($galleryview == true) { | ||
| 227 : | $image = new stdClass(); | ||
| 228 : | } else { | ||
| 229 : | $image = new image($row->imgid); | ||
| 230 : | } | ||
| 231 : | $this->_images[] = $image; | ||
| 232 : | } | ||
| 233 : | } | ||
| 234 : | /** | ||
| 235 : | * Change the gallery (sample-)image to a different image. | ||
| 236 : | * | ||
| 237 : | * Quick explanation: | ||
| 238 : | * - first, the function checks if a category-image | ||
| 239 : | * has been set for this gallery. | ||
| 240 : | * If not, and the gallery is one at the FIRST level | ||
| 241 : | * (one of the main galleries), the first image present | ||
| 242 : | * in the gallery is returned... | ||
| 243 : | * - second, the function retrieves the filename and CORRECT | ||
| 244 : | * directory of the category image from the database (in | ||
| 245 : | * case the category image is from a higher level gallery) | ||
| 246 : | * and returns the complete path in the end! | ||
| 247 : | * | ||
| 248 : | * @return void | ||
| 249 : | * @access public | ||
| 250 : | */ | ||
| 251 : | function setCatImg() { | ||
| 252 : | global $database, $zoom; | ||
| 253 : | if (isset($this->_cat_img) && !empty($this->_cat_img)) { | ||
| 254 : | $this->_cat_img = new image($this->_cat_img); | ||
| 255 : | $this->_cat_img->getInfo(); | ||
| 256 : | $this->_cat_img->_thumbnail = $zoom->hotlinkImage($this->_cat_img->_catid, '2', $this->_cat_img->_id, null ); | ||
| 257 : | } else { | ||
| 258 : | $database->setQuery("SELECT pos FROM #__zoom WHERE catid = ".$this->_id." LIMIT 1"); | ||
| 259 : | $this->_result = $database->query(); | ||
| 260 : | $row = mysql_fetch_object($this->_result); | ||
| 261 : | //if ($row->pos == 0) { | ||
| 262 : | $database->setQuery("SELECT imgid FROM #__zoomfiles WHERE catid=".$this->_id." ORDER BY ".$zoom->getOrderMethod()." LIMIT 1"); | ||
| 263 : | $this->_result = $database->query(); | ||
| 264 : | $xxx = mysql_fetch_object($this->_result); | ||
| 265 : | if (isset($xxx->imgid) && !empty($xxx->imgid)) { | ||
| 266 : | $this->_cat_img = new image($xxx->imgid); | ||
| 267 : | $this->_cat_img->getInfo(); | ||
| 268 : | $this->_cat_img->_thumbnail = $zoom->hotlinkImage($this->_cat_img->_catid, '2', $this->_cat_img->_id, null ); | ||
| 269 : | } | ||
| 270 : | //} | ||
| 271 : | } | ||
| 272 : | if (empty($this->_cat_img)) { | ||
| 273 : | $this->_cat_img = new image(0); | ||
| 274 : | } | ||
| 275 : | } | ||
| 276 : | /** | ||
| 277 : | * Move this gallery up or down the hierarchial list of galleries. | ||
| 278 : | * | ||
| 279 : | * @param int $to | ||
| 280 : | * @return boolean | ||
| 281 : | * @access public | ||
| 282 : | */ | ||
| 283 : | function move($to = 0) { | ||
| 284 : | global $database, $zoom; | ||
| 285 : | $reordered = true; | ||
| 286 : | |||
| 287 : | if ($to != 0) { | ||
| 288 : | // first, check if the target gallery has any children of its own, because in that case: dhtmlXTree places | ||
| 289 : | // this gallery as a CHILD of the target inside the tree! | ||
| 290 : | $database->setQuery("SELECT catid FROM #__zoom WHERE subcat_id = $to ORDER BY custom_order, ".$zoom->getCatOrderMethod()." LIMIT 1"); | ||
| 291 : | $result1 = $database->query(); | ||
| 292 : | while($row1 = mysql_fetch_object($result1)) { | ||
| 293 : | $to = $row1->catid; | ||
| 294 : | break; | ||
| 295 : | } | ||
| 296 : | // now it's safe to create a gallery object... | ||
| 297 : | $to_gallery =& new gallery($to); | ||
| 298 : | if ($this->_subcat_id != $to_gallery->_subcat_id) { | ||
| 299 : | // the target gallery has a different parent gallery than this one, so it has been moved (apparently). | ||
| 300 : | $this->_subcat_id = $to_gallery->_subcat_id; | ||
| 301 : | $this->_pos = $to_gallery->_pos; | ||
| 302 : | $this->_custom_order = "0"; | ||
| 303 : | $database->setQuery("UPDATE #__zoom SET subcat_id='".$this->_subcat_id."', pos='".$this->_pos."', custom_order='0' WHERE catid=".$this->_id); | ||
| 304 : | //echo "\n".$database->_sql; | ||
| 305 : | if (!$database->query()) { | ||
| 306 : | $reordered = false; | ||
| 307 : | } | ||
| 308 : | } | ||
| 309 : | } else { | ||
| 310 : | $this->_subcat_id = 0; | ||
| 311 : | $this->_pos = 0; | ||
| 312 : | $this->_custom_order = "0"; | ||
| 313 : | $database->setQuery("UPDATE #__zoom SET subcat_id='".$this->_subcat_id."', pos='".$this->_pos."', custom_order='0' WHERE catid=".$this->_id); | ||
| 314 : | //echo "\n".$database->_sql; | ||
| 315 : | if (!$database->query()) { | ||
| 316 : | $reordered = false; | ||
| 317 : | } | ||
| 318 : | } | ||
| 319 : | |||
| 320 : | if ($reordered) { | ||
| 321 : | // we need to fetch all galleries that share a common 'pos' (ie. position in the hierarchy) | ||
| 322 : | // to set all their 'custom_order's | ||
| 323 : | $database->setQuery("SELECT catid, custom_order FROM #__zoom WHERE pos = $this->_pos AND subcat_id = ".$this->_subcat_id." ORDER BY custom_order, ".$zoom->getCatOrderMethod()); | ||
| 324 : | $result2 = $database->query(); | ||
| 325 : | $new_order = 1; | ||
| 326 : | while ($row2 = mysql_fetch_object($result2)) { | ||
| 327 : | if ($row2->catid != $this->_id) { | ||
| 328 : | $database->setQuery("UPDATE #__zoom SET custom_order = $new_order WHERE catid = $row2->catid"); | ||
| 329 : | if (!$database->query()) { | ||
| 330 : | $reordered = false; | ||
| 331 : | } | ||
| 332 : | $new_order++; | ||
| 333 : | if ($row2->catid == $to) { | ||
| 334 : | $this->_custom_order = $new_order; | ||
| 335 : | $database->setQuery("UPDATE #__zoom SET custom_order = $this->_custom_order WHERE catid = $this->_id"); | ||
| 336 : | if (!$database->query()) { | ||
| 337 : | $reordered = false; | ||
| 338 : | } | ||
| 339 : | $new_order++; | ||
| 340 : | } | ||
| 341 : | } | ||
| 342 : | } | ||
| 343 : | } | ||
| 344 : | |||
| 345 : | return $reordered; | ||
| 346 : | |||
| 347 : | } | ||
| 348 : | /** | ||
| 349 : | * Change a gallery state to 'published'. | ||
| 350 : | * | ||
| 351 : | * @return boolean | ||
| 352 : | * @access public | ||
| 353 : | */ | ||
| 354 : | function publish() { | ||
| 355 : | global $database; | ||
| 356 : | $database->setQuery("UPDATE #__zoom SET published = 1 WHERE catid = ".$this->_id); | ||
| 357 : | if ($database->query()) { | ||
| 358 : | return true; | ||
| 359 : | } else { | ||
| 360 : | return false; | ||
| 361 : | } | ||
| 362 : | } | ||
| 363 : | /** | ||
| 364 : | * Change a gallery state to 'not published'. | ||
| 365 : | * | ||
| 366 : | * @return boolean | ||
| 367 : | * @access public | ||
| 368 : | */ | ||
| 369 : | function unPublish(){ | ||
| 370 : | global $database; | ||
| 371 : | $database->setQuery("UPDATE #__zoom SET published = 0 WHERE catid = ".$this->_id); | ||
| 372 : | if ($database->query()) { | ||
| 373 : | return true; | ||
| 374 : | }else{ | ||
| 375 : | return false; | ||
| 376 : | } | ||
| 377 : | } | ||
| 378 : | /** | ||
| 379 : | * Change a gallery state to 'shared' | ||
| 380 : | * | ||
| 381 : | * @return boolean | ||
| 382 : | * @access public | ||
| 383 : | */ | ||
| 384 : | function share() { | ||
| 385 : | global $database; | ||
| 386 : | $database->setQuery("UPDATE #__zoom SET shared = 1 WHERE catid = ".$this->_id); | ||
| 387 : | if ($database->query()) { | ||
| 388 : | return true; | ||
| 389 : | } else { | ||
| 390 : | return false; | ||
| 391 : | } | ||
| 392 : | } | ||
| 393 : | /** | ||
| 394 : | * Change a gallery state to 'not shared'. | ||
| 395 : | * | ||
| 396 : | * @return boolean | ||
| 397 : | * @access public | ||
| 398 : | */ | ||
| 399 : | function unShare() { | ||
| 400 : | global $database; | ||
| 401 : | $database->setQuery("UPDATE #__zoom SET shared = 0 WHERE catid = ".$this->_id); | ||
| 402 : | if ($database->query()) { | ||
| 403 : | return true; | ||
| 404 : | } else { | ||
| 405 : | return false; | ||
| 406 : | } | ||
| 407 : | } | ||
| 408 : | /** | ||
| 409 : | * Get the name of a sub-gallery. | ||
| 410 : | * | ||
| 411 : | * @return void | ||
| 412 : | * @access public | ||
| 413 : | */ | ||
| 414 : | function getSubcatName() { | ||
| 415 : | global $database; | ||
| 416 : | $database->setQuery("SELECT catname FROM #__zoom WHERE catid=".$this->_subcat_id." LIMIT 1"); | ||
| 417 : | $this->_result = $database->query(); | ||
| 418 : | while ($row = mysql_fetch_object($this->_result)) { | ||
| 419 : | return $row->catname; | ||
| 420 : | } | ||
| 421 : | } | ||
| 422 : | /** | ||
| 423 : | * Get the keywords of a gallery. | ||
| 424 : | * | ||
| 425 : | * @return void | ||
| 426 : | * @access public | ||
| 427 : | */ | ||
| 428 : | function getKeywords() { | ||
| 429 : | global $database; | ||
| 430 : | $database->setQuery("SELECT catkeywords FROM #__zoom WHERE catid = ".$this->_id." LIMIT 1"); | ||
| 431 : | if ($result = $database->query()) { | ||
| 432 : | $row = mysql_fetch_object($result); | ||
| 433 : | $this->_keywords = $row->catkeywords; | ||
| 434 : | } | ||
| 435 : | } | ||
| 436 : | /** | ||
| 437 : | * Get the virtual path (eg. '>Gallery1 > Gallery2 > Gallery 3') of a gallery. | ||
| 438 : | * | ||
| 439 : | * @return string | ||
| 440 : | * @access public | ||
| 441 : | */ | ||
| 442 : | function getCatVirtPath() { | ||
| 443 : | global $database; | ||
| 444 : | // first, get the pos of this category | ||
| 445 : | $pos = $this->_pos; | ||
| 446 : | $subcat_id = $this->_subcat_id; | ||
| 447 : | if ($pos==0 && $subcat_id==0) { | ||
| 448 : | return "> ".$this->_name; | ||
| 449 : | } else { | ||
| 450 : | // second, get the different subcat-names in an array... | ||
| 451 : | $catnames = array(); | ||
| 452 : | $i = $pos; | ||
| 453 : | while ($i>=1) { | ||
| 454 : | $database->setQuery("SELECT catname, subcat_id FROM #__zoom WHERE catid = ".$subcat_id." LIMIT 1"); | ||
| 455 : | $this->_result = $database->query(); | ||
| 456 : | $row2 = mysql_fetch_object($this->_result); | ||
| 457 : | $subcat_id = $row2->subcat_id; | ||
| 458 : | $catnames[$i] = $row2->catname; | ||
| 459 : | $i--; | ||
| 460 : | } | ||
| 461 : | // third, place the array (dirs) in a single return-string | ||
| 462 : | $retname = ""; | ||
| 463 : | $i = 1; | ||
| 464 : | while ($i<=$pos) { | ||
| 465 : | if($i==1) | ||
| 466 : | $retname .= "> ".$catnames[$i]; | ||
| 467 : | else | ||
| 468 : | $retname .= " > ".$catnames[$i]; | ||
| 469 : | $i++; | ||
| 470 : | } | ||
| 471 : | return $retname." > ".$this->_name; | ||
| 472 : | } | ||
| 473 : | } | ||
| 474 : | /** | ||
| 475 : | * Get the number of images that a gallery contains. | ||
| 476 : | * | ||
| 477 : | * @return int | ||
| 478 : | * @access public | ||
| 479 : | */ | ||
| 480 : | function getNumOfImages() { | ||
| 481 : | global $database, $zoom; | ||
| 482 : | if (isset($this->_images) && !empty($this->_images)) { | ||
| 483 : | return count($this->_images); | ||
| 484 : | } else { | ||
| 485 : | // double check if there are no media in gallery AND resource saver for gallery-view! | ||
| 486 : | if($zoom->_isAdmin) { | ||
| 487 : | $database->setQuery("SELECT COUNT(imgid) AS no FROM #__zoomfiles WHERE catid = ".$this->_id." LIMIT 1"); | ||
| 488 : | } | ||
| 489 : | else { | ||
| 490 : | $database->setQuery("SELECT COUNT(imgid) AS no FROM #__zoomfiles WHERE catid = ".$this->_id." AND published=1 LIMIT 1"); | ||
| 491 : | } | ||
| 492 : | $result = $database->query(); | ||
| 493 : | while ($row = mysql_fetch_object($result)) { | ||
| 494 : | return $row->no; | ||
| 495 : | } | ||
| 496 : | } | ||
| 497 : | } | ||
| 498 : | /** | ||
| 499 : | * Get the number of images viewable by a user that a gallery contains. | ||
| 500 : | * | ||
| 501 : | * @return int | ||
| 502 : | * @access public | ||
| 503 : | */ | ||
| 504 : | function getNumOfImagesUSER() { | ||
| 505 : | global $database, $zoom, $my, $backend; | ||
| 506 : | // double check if there are no media in gallery AND resource saver for gallery-view! | ||
| 507 : | if($zoom->_isAdmin) { | ||
| 508 : | $database->setQuery("SELECT imgmembers FROM #__zoomfiles WHERE catid = ".$this->_id); | ||
| 509 : | } | ||
| 510 : | else { | ||
| 511 : | $database->setQuery("SELECT imgmembers FROM #__zoomfiles WHERE catid = ".$this->_id." AND published=1"); | ||
| 512 : | } | ||
| 513 : | $rows = $database->loadObjectList(); | ||
| 514 : | $counter = 0; | ||
| 515 : | if($rows) { | ||
| 516 : | foreach ($rows as $row) { | ||
| 517 : | $members = explode(",", $row->imgmembers); | ||
| 518 : | if ($zoom->currGID) { | ||
| 519 : | $registered = true; | ||
| 520 : | } else { | ||
| 521 : | $registered = false; | ||
| 522 : | } | ||
| 523 : | // Public / Registered User / ID of user / Admin | ||
| 524 : | //0 CANNOT read null | ||
| 525 : | if ($my->id == "0") { | ||
| 526 : | $id = "zip"; | ||
| 527 : | } else { | ||
| 528 : | $id = $my->id; | ||
| 529 : | } | ||
| 530 : | if (in_array("1", $members) || (in_array("2", $members) && $registered) | ||
| 531 : | || in_array($id, $members) || $zoom->_isAdmin) { | ||
| 532 : | $counter++; | ||
| 533 : | } else { | ||
| 534 : | foreach ($members as $member) { | ||
| 535 : | if (strstr($member, "gid-")) { | ||
| 536 : | $m_gid = intval(str_replace("gid-", "", $member)); | ||
| 537 : | if ($zoom->currGID >= $m_gid) { | ||
| 538 : | $counter++; | ||
| 539 : | break; | ||
| 540 : | } | ||
| 541 : | } | ||
| 542 : | } | ||
| 543 : | } | ||
| 544 : | } | ||
| 545 : | } | ||
| 546 : | return $counter; | ||
| 547 : | } | ||
| 548 : | /** | ||
| 549 : | * Get the number of sub-galleries a gallery contains. | ||
| 550 : | * | ||
| 551 : | * @return int | ||
| 552 : | * @access public | ||
| 553 : | */ | ||
| 554 : | function getNumOfSubCats() { | ||
| 555 : | global $database; | ||
| 556 : | if (isset($this->_subcats) && !empty($this->_subcats)) { | ||
| 557 : | return count($this->_subcats); | ||
| 558 : | } else { | ||
| 559 : | $database->setQuery("SELECT COUNT(catid) AS no FROM #__zoom WHERE subcat_id = ".$this->_id." LIMIT 1"); | ||
| 560 : | $result = $database->query(); | ||
| 561 : | while ($row = mysql_fetch_object($result)) { | ||
| 562 : | return $row->no; | ||
| 563 : | } | ||
| 564 : | } | ||
| 565 : | } | ||
| 566 : | /** | ||
| 567 : | * Get the directory on the filesystem of a gallery | ||
| 568 : | * | ||
| 569 : | * @return string | ||
| 570 : | * @access public | ||
| 571 : | */ | ||
| 572 : | function getDir() { | ||
| 573 : | return $this->_dir; | ||
| 574 : | } | ||
| 575 : | /** | ||
| 576 : | * Check if an entered password of a password-protected gallery is correct. | ||
| 577 : | * | ||
| 578 : | * @param string $pass | ||
| 579 : | * @return boolean | ||
| 580 : | * @access public | ||
| 581 : | */ | ||
| 582 : | function checkPassword($pass) { | ||
| 583 : | global $zoom; | ||
| 584 : | $pass = md5($pass); | ||
| 585 : | if ($zoom->EditMon->isEdited($this->_id, 'pass')) { | ||
| 586 : | return true; | ||
| 587 : | } elseif ($this->_password == $pass) { | ||
| 588 : | $zoom->EditMon->setEditMon($this->_id, 'pass'); | ||
| 589 : | return true; | ||
| 590 : | } else { | ||
| 591 : | return false; | ||
| 592 : | } | ||
| 593 : | } | ||
| 594 : | /** | ||
| 595 : | * Check if a gallery is shared (ie. if users may upload media to it). | ||
| 596 : | * | ||
| 597 : | * @return boolean | ||
| 598 : | * @access public | ||
| 599 : | */ | ||
| 600 : | function isShared() { | ||
| 601 : | if($this->_shared == 1) { | ||
| 602 : | return true; | ||
| 603 : | } else { | ||
| 604 : | return false; | ||
| 605 : | } | ||
| 606 : | } | ||
| 607 : | /** | ||
| 608 : | * Check is a gallery is published. | ||
| 609 : | * | ||
| 610 : | * @return boolean | ||
| 611 : | * @access public | ||
| 612 : | */ | ||
| 613 : | function isPublished() { | ||
| 614 : | if($this->_published == 1) { | ||
| 615 : | return true; | ||
| 616 : | } else { | ||
| 617 : | return false; | ||
| 618 : | } | ||
| 619 : | } | ||
| 620 : | /** | ||
| 621 : | * Check if a user may see the contents of a gallery. | ||
| 622 : | * | ||
| 623 : | * @return boolean | ||
| 624 : | * @access public | ||
| 625 : | */ | ||
| 626 : | function isMember() { | ||
| 627 : | global $zoom, $my; | ||
| 628 : | if ($zoom->currGID) { | ||
| 629 : | $registered = true; | ||
| 630 : | } else { | ||
| 631 : | $registered = false; | ||
| 632 : | } | ||
| 633 : | // Don't forget strict mode looking for $my->id. It will be 0 for unregistered! | ||
| 634 : | if (in_array("1", $this->_members) || (in_array("2", $this->_members) && $registered) || in_array($my->id, $this->_members, true) || $zoom->_isAdmin) { | ||
| 635 : | return true; | ||
| 636 : | } else { | ||
| 637 : | $res = false; | ||
| 638 : | foreach ($this->_members as $member) { | ||
| 639 : | if (strstr($member, "gid-")) { | ||
| 640 : | $m_gid = intval(str_replace("gid-", "", $member)); | ||
| 641 : | if ($zoom->currGID >= $m_gid) { | ||
| 642 : | $res = true; | ||
| 643 : | } | ||
| 644 : | } | ||
| 645 : | } | ||
| 646 : | return $res; | ||
| 647 : | } | ||
| 648 : | } | ||
| 649 : | /** | ||
| 650 : | * Get an image by it's id instead of the usual array key. | ||
| 651 : | * | ||
| 652 : | * @param int $id | ||
| 653 : | * @return image | ||
| 654 : | * @access public | ||
| 655 : | */ | ||
| 656 : | function getImage($id) { | ||
| 657 : | foreach ($this->_images as $image) { | ||
| 658 : | if ($image->_id == $id) { | ||
| 659 : | return $image; | ||
| 660 : | } | ||
| 661 : | } | ||
| 662 : | } | ||
| 663 : | /** | ||
| 664 : | * Get the array key of an image by it's id. | ||
| 665 : | * | ||
| 666 : | * @param int $id | ||
| 667 : | * @return int | ||
| 668 : | * @access public | ||
| 669 : | */ | ||
| 670 : | function getImageKey($id) { | ||
| 671 : | $count = 0; | ||
| 672 : | foreach ($this->_images as $image) { | ||
| 673 : | if ($image->_id == $id) { | ||
| 674 : | return $count; | ||
| 675 : | } else { | ||
| 676 : | $count++; | ||
| 677 : | } | ||
| 678 : | } | ||
| 679 : | } | ||
| 680 : | /** | ||
| 681 : | * Return the data of this object in an XML formatted stream | ||
| 682 : | * | ||
| 683 : | * @return string in XML format | ||
| 684 : | * @access public | ||
| 685 : | */ | ||
| 686 : | function toXML($list_subcats = false, $list_media = false) { | ||
| 687 : | global $database, $acl; | ||
| 688 : | $this->getKeywords(); | ||
| 689 : | $xml = ("<gallery id=\"".$this->_id."\" " | ||
| 690 : | . "name=\"". $this->_name."\" " | ||
| 691 : | . "dir=\"".$this->_dir."\" " | ||
| 692 : | . "cat_img=\"".$this->_cat_img."\" " | ||
| 693 : | . "password=\"".$this->_password."\" " | ||
| 694 : | . "keywords=\"".$this->_keywords."\" " | ||
| 695 : | . "subcat_id=\"".$this->_subcat_id."\" " | ||
| 696 : | . "pos=\"".$this->_pos."\" " | ||
| 697 : | . "custom_order=\"".$this->_custom_order."\" " | ||
| 698 : | . "hide_msg=\"".$this->_hideMsg."\" " | ||
| 699 : | . "shared=\"".$this->_shared."\" " | ||
| 700 : | . "published=\"".$this->_published."\" " | ||
| 701 : | . "uid=\"".$this->_uid."\">"); | ||
| 702 : | if (!empty($this->_subcats) && count($this->_subcats) > 0 && $list_subcats) { | ||
| 703 : | $xml .= ("<subcats>"); | ||
| 704 : | foreach ($this->_subcats as $subcat) { | ||
| 705 : | $xml .= $subcat->toXML()."\n"; | ||
| 706 : | } | ||
| 707 : | $xml .= ("</subcats>"); | ||
| 708 : | } | ||
| 709 : | if (!empty($this->_images) && count($this->_images) > 0 && $list_media) { | ||
| 710 : | $xml .= ("<media>"); | ||
| 711 : | foreach ($this->_images as $image) { | ||
| 712 : | $xml .= $image->toXML().""; | ||
| 713 : | } | ||
| 714 : | $xml .= ("</media>"); | ||
| 715 : | } | ||
| 716 : | $members_arr = array(); | ||
| 717 : | foreach ($this->_members as $member) { | ||
| 718 : | $type = split("-", $member); | ||
| 719 : | if ($member == 1 || $member == 2) { | ||
| 720 : | $members_arr[] = "<member id=\"".$member."\">none</member>"; | ||
| 721 : | } else if ($type[0] == "gid") { | ||
| 722 : | $members_arr[] = "<member id=\"".$member."\" username=\"".$acl->get_group_name($type[1])."\">".$acl->get_group_name($type[1])."</member>"; | ||
| 723 : | } else { | ||
| 724 : | $database->setQuery("SELECT name, username FROM #__users WHERE id=$member LIMIT 1"); | ||
| 725 : | $this->_result = $database->query(); | ||
| 726 : | $rows = $database->loadObjectList(); | ||
| 727 : | if (count($rows) == 1) { | ||
| 728 : | foreach ($rows as $row) { | ||
| 729 : | $members_arr[] = "<member id=\"".$member."\" username=\"".$row->username."\">".$row->name."</member>"; | ||
| 730 : | } | ||
| 731 : | } | ||
| 732 : | } | ||
| 733 : | } | ||
| 734 : | $xml .= ("<members>".implode("", $members_arr)."</members><![CDATA[" | ||
| 735 : | . $this->_descr . "]]></gallery>"); | ||
| 736 : | return $xml; | ||
| 737 : | } | ||
| 738 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

