/** * Fetches gallery info for the specified gallery and immediate children. * @param string gallery id * @param string language code spec for this request (optional) * @param int number of levels of child galleries to fetch (optional) * @return sgGallery the gallery object created */ function &getGallery($galleryId, &$parent, $getChildGalleries = 1, $language = null) { $gal = new sgGallery($galleryId, $parent); if ($language == null) { $translator = Translator::getInstance(); $language = $translator->language; } //try to open language specific metadata $fp = @fopen($this->config->base_path . $this->config->pathto_galleries . $galleryId . "/metadata.{$language}.csv", "r"); //if fail then try to open generic metadata if (!$fp) { $fp = @fopen($this->config->base_path . $this->config->pathto_galleries . $galleryId . "/metadata.csv", "r"); } if ($fp) { while ($temp[] = fgetcsv($fp, 2048)) { } fclose($fp); list($gal->filename, $gal->thumbnail, $gal->owner, $gal->groups, $gal->permissions, $gal->categories, $gal->name, $gal->artist, $gal->email, $gal->copyright, $gal->desc, $gal->summary, $gal->date) = $temp[1]; //only fetch individual images if child galleries are required if ($getChildGalleries) { for ($i = 0; $i < count($temp) - 3; $i++) { $gal->images[$i] = new sgImage($temp[$i + 2][0], $gal, $this->config); list(, $gal->images[$i]->thumbnail, $gal->images[$i]->owner, $gal->images[$i]->groups, $gal->images[$i]->permissions, $gal->images[$i]->categories, $gal->images[$i]->name, $gal->images[$i]->artist, $gal->images[$i]->email, $gal->images[$i]->copyright, $gal->images[$i]->desc, $gal->images[$i]->location, $gal->images[$i]->date, $gal->images[$i]->camera, $gal->images[$i]->lens, $gal->images[$i]->film, $gal->images[$i]->darkroom, $gal->images[$i]->digital) = $temp[$i + 2]; //get image size and type list($gal->images[$i]->width, $gal->images[$i]->height, $gal->images[$i]->type) = @GetImageSize($gal->images[$i]->realPath()); } //otherwise just fill in empty images } else { if (count($temp) > 3) { for ($i = 0; $i < count($temp) - 3; $i++) { $gal->images[$i] = new sgImage($temp[$i + 2][0], $gal); } } } } else { //no metadata found so use iifn method implemented in superclass return parent::getGallery($galleryId, $parent, $getChildGalleries, $language); } //discover child galleries $dir = Singapore::getListing($this->config->base_path . $this->config->pathto_galleries . $galleryId . "/"); if ($getChildGalleries) { //but only fetch their info if required too foreach ($dir->dirs as $gallery) { $gal->galleries[] = $this->getGallery($galleryId . "/" . $gallery, $gal, $getChildGalleries - 1, $language); } } else { //otherwise just copy their names in so they can be counted $gal->galleries = $dir->dirs; } return $gal; }
/** * Fetches gallery info for the specified gallery and immediate children. * @param string gallery id * @param string language code spec for this request (optional) * @param int number of levels of child galleries to fetch (optional) */ function &getGallery($galleryId, &$parent, $getChildGalleries = 1, $language = null) { $gal = new sgGallery($galleryId, $parent); if ($language == null) { $language = $this->config->default_language; } //try to open language specific gallery info $res = $this->query("SELECT * FROM " . $this->config->sql_prefix . "galleries " . "WHERE id='" . $this->escape_string($galleryId) . "' " . "AND lang='" . $this->escape_string($language) . "'"); //if fail then try to open generic gallery info if (!$res || !$this->num_rows($res)) { $res = $this->query("SELECT * FROM " . $this->config->sql_prefix . "galleries " . "WHERE id='" . $this->escape_string($galleryId) . "' and lang=''"); } //if that succeeds then get galleries from db if ($res && $this->num_rows($res)) { $galinfo = $this->fetch_array($res); $gal->filename = $galinfo['filename']; $gal->owner = $galinfo['owner']; $gal->groups = $galinfo['groups']; $gal->permissions = $galinfo['permissions']; $gal->categories = $galinfo['categories']; $gal->name = $galinfo['name']; $gal->artist = $galinfo['artist']; $gal->email = $galinfo['email']; $gal->copyright = $galinfo['copyright']; $gal->desc = $galinfo['description']; $gal->summary = $galinfo['summary']; $gal->date = $galinfo['date']; $gal->hits = $galinfo['hits']; $gal->lasthit = $galinfo['lasthit']; //try to open language specific image info $res = $this->query("SELECT * FROM " . $this->config->sql_prefix . "images " . "WHERE galleryid='" . $this->escape_string($galleryId) . "' " . "AND lang='" . $this->escape_string($language) . "'"); //if fail then try to open generic image info if (!$res || !$this->num_rows($res)) { $res = $this->query("SELECT * FROM " . $this->config->sql_prefix . "images " . "WHERE galleryid='" . $this->escape_string($galleryId) . "' and lang=''"); } for ($i = 0; $i < $this->num_rows($res); $i++) { $imginfo = $this->fetch_array($res); $gal->images[$i] = new sgImage($imginfo['filename'], $gal); $gal->images[$i]->thumbnail = $imginfo['thumbnail']; $gal->images[$i]->owner = $imginfo['owner']; $gal->images[$i]->groups = $imginfo['groups']; $gal->images[$i]->permissions = $imginfo['permissions']; $gal->images[$i]->categories = $imginfo['categories']; $gal->images[$i]->name = $imginfo['name']; $gal->images[$i]->artist = $imginfo['artist']; $gal->images[$i]->email = $imginfo['email']; $gal->images[$i]->copyright = $imginfo['copyright']; $gal->images[$i]->desc = $imginfo['description']; $gal->images[$i]->location = $imginfo['location']; $gal->images[$i]->date = $imginfo['date']; $gal->images[$i]->camera = $imginfo['camera']; $gal->images[$i]->lens = $imginfo['lens']; $gal->images[$i]->film = $imginfo['film']; $gal->images[$i]->darkroom = $imginfo['darkroom']; $gal->images[$i]->digital = $imginfo['digital']; $gal->images[$i]->width = $imginfo['width']; $gal->images[$i]->height = $imginfo['height']; $gal->images[$i]->type = $imginfo['type']; $gal->images[$i]->hits = $imginfo['hits']; $gal->images[$i]->lasthit = $imginfo['lasthit']; } } else { //no record found so use iifn method implemented in parent class return parent::getGallery($galleryId, $parent, $getChildGalleries, $language); } //discover child galleries $dir = Singapore::getListing($this->config->base_path . $this->config->pathto_galleries . $galleryId . "/"); if ($getChildGalleries) { //but only fetch their info if required too foreach ($dir->dirs as $gallery) { $gal->galleries[] = $this->getGallery($galleryId . "/" . $gallery, $gal, $getChildGalleries - 1, $language); } } else { //otherwise just copy their names in so they can be counted $gal->galleries = $dir->dirs; } return $gal; }