From b50897cb0fdf0d42d306b20b8e38f19f8e2832e3 Mon Sep 17 00:00:00 2001 From: jimmacfx Date: Tue, 14 Feb 2006 20:52:54 +0000 Subject: add sqlite hooks git-svn-id: https://forgesvn1.novell.com/svn/original/trunk@9 4fa712ea-3c06-0410-9261-c11b4c06c003 --- www/inc/comment_form.inc.php | 33 ++++ www/inc/config.inc.php | 17 ++- www/inc/db.class.inc.php | 63 ++++++++ www/inc/exif.inc.php | 4 +- www/inc/funkce.inc.php | 62 -------- www/inc/global.js | 13 +- www/inc/header.inc.php | 24 +-- www/inc/photo.class.inc.php | 279 +++++++++++++++++++++++++++++++++ www/inc/www.class.inc.php | 145 +++++++++++++++++- www/index.php | 356 +++++++++++++------------------------------ www/l10n/cs/main.lang | 3 + www/l10n/it/date.lang | 79 ++++++++++ www/l10n/it/exif.lang | 21 +++ www/l10n/it/main.lang | 111 ++++++++++++++ www/l10n/no/date.lang | 79 ++++++++++ www/l10n/no/exif.lang | 21 +++ www/l10n/no/main.lang | 110 +++++++++++++ www/stats.php | 25 +++ 18 files changed, 1111 insertions(+), 334 deletions(-) create mode 100644 www/inc/comment_form.inc.php create mode 100644 www/inc/db.class.inc.php create mode 100644 www/inc/photo.class.inc.php create mode 100644 www/l10n/it/date.lang create mode 100644 www/l10n/it/exif.lang create mode 100644 www/l10n/it/main.lang create mode 100644 www/l10n/no/date.lang create mode 100644 www/l10n/no/exif.lang create mode 100644 www/l10n/no/main.lang create mode 100644 www/stats.php diff --git a/www/inc/comment_form.inc.php b/www/inc/comment_form.inc.php new file mode 100644 index 0000000..5ac8348 --- /dev/null +++ b/www/inc/comment_form.inc.php @@ -0,0 +1,33 @@ +\n"; + +?> + " . __('Post a Comment') . ":"; ?> + + [  + " . __('Show Form') . "" . __('Hide Form') . ""; ?> +  ] + + + + + diff --git a/www/inc/config.inc.php b/www/inc/config.inc.php index 1f0bbd3..c800fac 100644 --- a/www/inc/config.inc.php +++ b/www/inc/config.inc.php @@ -1,8 +1,12 @@ dbfile = $dbfile; + //if db file doesn't exist, fill with skeleton + if (file_exists($this->dbfile)) { + $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); + } else { + //fill with skeleton + $folder = dirname($this->dbfile); + if (!is_writable($folder)) { //we need write permission to create database + die("

cannot create dabase. check permissions.

\n"); + } else { + $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); + //photo table + $sql = "create table photo (id INTEGER PRIMARY KEY, caption TEXT, "; + $sql .= "counter INTEGER, number INTEGER, album TEXT, name TEXT)"; + $this->query($sql); + //comment table + $sql = "create table comment (id INTEGER PRIMARY KEY, user TEXT, "; + $sql .= "comment_body TEXT, photo_id INT, date DATETIME)"; + $this->query($sql); + } + } + } + + function query($sql) { + global $page; + + if (!$this->result = sqlite_query($this->dbres, $sql)) { + print "Query failed,
$sql
\n"; + print sqlite_error_string (sqlite_last_error($this->dbres)); + $page->footer(); + exit; + } + } + + function count() { + return sqlite_num_rows($this->result); + } + + function rewind() { //just to abstract from sqlite + sqlite_rewind($this->result); + } + +} + + +$db = new SQLiteDatabase("$dbfile"); + +?> diff --git a/www/inc/exif.inc.php b/www/inc/exif.inc.php index f78741e..7b8262d 100644 --- a/www/inc/exif.inc.php +++ b/www/inc/exif.inc.php @@ -99,7 +99,7 @@ if ($exif_prog=="php4") { } echo "\n"; echo ""; - echo "" . __("Less info"); + echo "" . __("Less info"); echo ""; echo "\n"; echo "\n"; @@ -136,7 +136,7 @@ if ($exif_prog=="php4") { } } - echo "" . __("More info"); + echo "" . __("More info"); echo "

\n"; echo "\n"; } diff --git a/www/inc/funkce.inc.php b/www/inc/funkce.inc.php index be897f7..e45d725 100644 --- a/www/inc/funkce.inc.php +++ b/www/inc/funkce.inc.php @@ -1,66 +1,4 @@ \n"; - echo "
\n"; - if ($snapshot > 1) { //previous - echo ""; - echo "< Previous\n"; - } - echo " "; - if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) { //next - echo ""; - echo "Next >\n"; - } - echo "
\n\n"; - } elseif ($image=="prev") { //previous thumbnail - if ($snapshot > 1) { //previous - echo "\n"; - } - } else { //next thumbnail - if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) { - echo "\n"; - } - } - -} function check($file) { global $gallery_dir, $page; diff --git a/www/inc/global.js b/www/inc/global.js index ff8ec21..048af85 100644 --- a/www/inc/global.js +++ b/www/inc/global.js @@ -65,15 +65,12 @@ function toggle_comment() { } } -function toggle_exif() { - var exif_table = document.getElementById('exif_table'); - var exif_line = document.getElementById('exif_line'); - if(exif_table.style.display == 'none') { - exif_table.style.display = 'block'; - exif_line.style.display = 'none'; +function toggle_div(classname) { + var div = document.getElementById(classname); + if(div.style.display == 'none') { + div.style.display = 'block'; } else { - exif_table.style.display = 'none'; - exif_line.style.display = 'block'; + div.style.display = 'none'; } } diff --git a/www/inc/header.inc.php b/www/inc/header.inc.php index 483b6ef..970c651 100644 --- a/www/inc/header.inc.php +++ b/www/inc/header.inc.php @@ -1,14 +1,20 @@
-[ style: - $url) { - echo ""; - echo "$skin \n"; -} -?> -] + +
+ Photo Gallery\n\n"; ?> diff --git a/www/inc/photo.class.inc.php b/www/inc/photo.class.inc.php new file mode 100644 index 0000000..10b507d --- /dev/null +++ b/www/inc/photo.class.inc.php @@ -0,0 +1,279 @@ +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 .= "\"" . $this->name . "\", "; + $sql .= "\"" . $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(eregi("^(.*)( - )?(.*)", $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
\n"; + print __('This image has been viewed') . " "; + print "" . $this->counter . "". " " . __('times') . "."; + print "
\n\n"; + $this->writeCounter(); //save state + + } + + function writeCounter() { + global $log_access, $root, $gallery_dir, $galerie, $page, $db; + + $this->counter++; //we add to counter + if ($GLOBALS['have_sqlite']) { + //we have SQLite + $sql = "update photo set counter=" . $this->counter; + $sql .= " where id=" . $this->id; + $db->query($sql); + return; //no need to fallback anymore + } + //fallback to filesystem + if (is_writable("$root/$gallery_dir/$galerie/comments")) { // needs perms + $log = "$root/$gallery_dir/$galerie/comments/log_". $this->number .".txt"; + if (!is_writable($log)) { + print "\n\n\n\n"; + return 0; + } + $fh = fopen($log,"w"); + if (!fwrite($fh, $this->counter . "\n")) { + $page->error( __('Could not write to') . $log . "!"); + $page->footer(); + exit; //stop everything + } + fclose($fh); + } + } + + function renderBigSize() { + + if ($this->mq || $this->hq) { + print "
"; + if ($this->mq) { + print "mq . "\">". __('MQ') . " "; + } + if ($this->hq) { + print "hq . "\">" . __('HQ') . ""; + } + print "
\n"; + } + } + + function renderPreview() { + + $divheight = $this->previewsize[1] + 10; + print "
\n"; // extra kludge + // because of tall + // images + + print "previewsize[3] . " src=\"". $this->file; + print "\" alt=\"$snimek\" />\n"; + } + + function renderCaption() { + + print "
"; + print "" . $this->name . ""; + if ($this->caption) { + print " – "; + print $this->caption; + print "
"; + } + } + + function addComment($comment_name, $comment_data) { //adds comment to file or database + global $log_access, $root, $gallery_dir, $galerie, $page; + + if ($GLOBALS['have_sqlite']) { + //sqlite + print "\n\n\n"; + } else { + //filesystem + if (is_writable("$root/$gallery_dir/$galerie/comments")) { // needs perms + $comment = "$root/$gallery_dir/$galerie/comments/user_"; + $comment .= $this->number . ".txt"; + if (file_exists($comment) && !is_writable($comment)) { + $page->error("Permission Denied", __('Could not write to') . $comment . + "!\n Check permissions.\n"); + $page->footer(); + exit; //stop everything + } + + $fh = fopen("$comment", "a"); + if (!$comment_name) { + $comment_name = __('Anonymous'); + } + if (!fwrite($fh, "
\n")) { + $page->error("Write Failed", __('Could not write to') . $comment . "!" ); + $page->footer(); + exit; //stop everything + } + fwrite($fh, "
" . __('Comment from') . "$comment_name
\n",90); + fwrite($fh, "
$comment_data
\n",280); + fwrite($fh, "
\n"); + + fclose($fh); + } + } + } +} +?> diff --git a/www/inc/www.class.inc.php b/www/inc/www.class.inc.php index 2206382..27683cc 100644 --- a/www/inc/www.class.inc.php +++ b/www/inc/www.class.inc.php @@ -188,7 +188,150 @@ class C_www { echo "
\n"; } - + + function navigation ($gallery, $snapshot, $image) { + global $gallery_dir, $root, $ThisScript, $textnav, $img, + $show_thumbs, $exif_style, $PNthumbScale; + + $next = $snapshot + 1; + $prev = $snapshot - 1; + + if (!$image) { // this will render a navigation bar - max 3 buttons + echo "\n
\n"; + echo "
\n"; + if ($snapshot > 1) { //previous + echo ""; + echo "< Previous\n"; + } + echo " "; + if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) { //next + echo ""; + echo "Next >\n"; + } + echo "
\n
\n"; + } elseif ($image=="prev") { //previous thumbnail + if ($snapshot > 1) { //previous + echo "\n"; + } + } else { //next thumbnail + if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) { + echo "\n"; + } + } + } + + function user_comments($photo) { + global $root, $gallery_dir, $galerie, $comments, $picture; + + if ($comments) { + if (is_writable("$root/$gallery_dir/$galerie/comments")) { // needs perms + require("inc/comment_form.inc.php"); + + if ($picture->comments) { + print "
"; + print $picture->comments; + print "
"; + } + } else { + print "\n"; + } + } + } + + function process_comment_form() { // processing of the user comment data + global $comments, $root, $gallery_dir, $galerie, $snimek; + + if($comments && @$_POST["commentdata"]) { + $username = @$_COOKIE["username"]; + $comment_name = @$_POST["commentname"]; + $save_comment_name = @$_POST["savecommentname"]; + $comment_data = @$_POST["commentdata"]; + $comment_kolacek = @$_POST["commentkolacek"]; + $comment_spamcheck = @$_POST["commentspamcheck"]; + + #check for HTML tags + + $comment_name = stripslashes(strip_tags($comment_name)); + $allowedTags = '