/** * 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; }
/** * Check for images in specified gallery directory which are * not in the metadata and add them. If no gallery is specified, * the current gallery is used. * @param string id of gallery to reindex (optional) * @return int|false the number of images added or false on error */ function reindexGallery($galleryId = null) { if ($galleryId == null) { $gal = $this->gallery; } else { $gal = $this->io->getGallery($galleryId, new stdClass()); } $imagesAdded = 0; //get list of images $dir = Singapore::getListing($this->config->pathto_galleries . $gal->id, $this->config->recognised_extensions); //cycle through the image files for ($i = 0; $i < count($dir->files); $i++) { //search for the image file in the database images for ($j = 0; $j < count($gal->images); $j++) { //if we find it if ($dir->files[$i] == $gal->images[$j]->id) { //skip the rest of this loop continue 2; } } //otherwise add the image to the database $gal->images[$j] = new sgImage($dir->files[$i], $gal, $this->config); $gal->images[$j]->name = $dir->files[$i]; list($gal->images[$j]->width, $gal->images[$j]->height, $gal->images[$j]->type) = GetImageSize($this->config->pathto_galleries . $gal->id . "/" . $gal->images[$j]->id); $imagesAdded++; } if ($this->io->putGallery($gal)) { return $imagesAdded; } return $this->pushError($this->translator->_g("Could not save gallery info")); }
/** * Generates the HTML code for the template select box * @return string select box HTML code */ function templateFlipper() { if (!$this->config->template_flipper) { return ""; } //get list of installed templates $templates = Singapore::getListing($this->config->base_path . $this->config->pathto_templates, "dirs"); $ret = '<div class="sgTemplateFlipper">'; $ret .= '<form method="get" action="' . $_SERVER["PHP_SELF"] . "\">\n"; //carry over current get vars foreach ($_GET as $var => $val) { $ret .= '<input type="hidden" name="' . $var . '" value="' . htmlspecialchars($val) . "\" />\n"; } $ret .= '<select name="' . $this->config->url_template . "\">\n"; $ret .= ' <option value="' . $this->config->default_template . '">' . $this->translator->_g("Select template...") . "</option>\n"; foreach ($templates->dirs as $name) { //do not list admin template(s) if (strpos($name, "admin_") === false) { $ret .= ' <option value="' . $name . '"'; if ($name == $this->template && $this->template != $this->config->default_template) { $ret .= 'selected="true" '; } $ret .= '>' . $name . "</option>\n"; } } $ret .= "</select>\n"; $ret .= '<input type="submit" class="button" value="' . $this->translator->_g("Go") . "\" />\n"; $ret .= "</form></div>\n"; return $ret; }