file = $file; $this->number = $number; $this->album = $galerie; //init from filesystem //preview $this->preview = "$gallery_dir/$galerie/lq/img-" . $this->number . ".jpg"; $this->previewsize = getimagesize($this->preview); //MQ if (file_exists("$root/$gallery_dir/$galerie/mq/img-" . $this->number . ".jpg")) { $this->mq = "$gallery_dir/$galerie/mq/img-" . $this->number . ".jpg"; } //HQ if (file_exists("$root/$gallery_dir/$galerie/hq/img-" . $this->number . ".jpg")) { $this->hq = "$gallery_dir/$galerie/hq/img-" . $this->number . ".jpg"; } if ($GLOBALS['have_sqlite']) { //query just once require_once("$root/inc/db.class.inc.php"); $sql = "select * from photo where "; $sql .= "number=" . $this->number . " and "; $sql .= "album='" . $this->album . "'"; $db->query($sql); } $this->readCaption(); $this->readCounter(); //reads access log number if ($GLOBALS['have_sqlite']) { //need to get photo id first if (!$db->count()) {//no record for this photo, let's update the record //FIXME - if no photo data in db, create a unique index for it //and add number, album, caption and views. $sql = "insert into photo (name, caption, counter, number, album)"; $sql .= " values ("; $sql .= "\"" . sqlite_escape_string($this->name) . "\", "; $sql .= "\"" . sqlite_escape_string(strtr($this->caption,"\"","'")) . "\", "; $sql .= $this->counter . ", "; $sql .= $this->number . ", "; $sql .= "\"" . $this->album . "\""; $sql .= ")"; $db->query($sql); print "\n\n"; //now we still need to query for the id $sql = "select id from photo where "; $sql .= "number=" . $this->number . " and "; $sql .= "album='" . $this->album . "'"; $db->query($sql); } $db->rewind(); $resultarray = sqlite_fetch_array($db->result); $this->id = $resultarray["id"]; print "\n\n\n"; } $this->readComments(); } function readCaption() { global $have_sqlite, $root, $gallery_dir, $galerie, $db; /* reads name and caption of a photo - either from sqlite database or filesystem */ if ($have_sqlite) { //try reading from sqlite if ($db->count()) { $result = sqlite_fetch_array($db->result); $this->name = $result["name"]; $this->caption = $result["caption"]; return; //no need to fallback anymore } } //we falback to filesystem $buffer = ""; $captionfile = "$root/$gallery_dir/$galerie/comments/" . $this->number . ".txt"; $fh = @fopen($captionfile, "r"); if ($fh) { while (!feof($fh)) { $buffer .= fgets($fh, 4096); } fclose($fh); } else { // no caption file $this->name = __("Photo ") . $this->number; return; } //parse buffer if(preg_match("|^(.*)( - )?(.*)|i", $buffer, $x)) { $this->name = $x[1]; //mostly "Photo" $this->caption = chop($x[3]); } else { $this->caption = $buffer; } } function readCounter() { global $log_access, $root, $gallery_dir, $galerie, $db; if ($GLOBALS['have_sqlite']) { //try reading from sqlite if ($db->count()) { $db->rewind(); $result = sqlite_fetch_array($db->result); $this->counter = $result["counter"]; return; //no need to fallback anymore } } //we fallback to filesystem :/ if (is_writable("$root/$gallery_dir/$galerie/comments")) { // needs perms $log = "$root/$gallery_dir/$galerie/comments/log_" . $this->number . ".txt"; if (file_exists($log)){ $fh = @fopen($log, "r"); $this->counter = rtrim(fgets($fh)); fclose($fh); } else { $this->counter = 0; } } else { //doesn't do anything if no perms print "\n"; return 0; //failure } return 1; //success } function readComments() { global $root, $gallery_dir, $galerie, $db; if ($GLOBALS['have_sqlite']) { //we have and will use SQLite //FIXME print "\n\n\n"; return 1; } else { //filesystem $comments = "$root/$gallery_dir/$galerie/comments/user_" . $this->number . ".txt"; if (file_exists($comments)){ $buffer = ""; $fh = @fopen($comments, "r"); if ($fh) { while (!feof($fh)) { $buffer .= fgets($fh, 4096); } $this->comments = $buffer; fclose($fh); } } } } function renderCounter() { print "\n