From: Arun Persaud Date: Mon, 23 Jan 2012 07:38:29 +0000 (-0800) Subject: cleanup and new features X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=commitdiff_plain;h=79761af3ff298c01b9892a3f7e6cd94a325b9005 cleanup and new features * display of single picture * "all" button to go back to display no tags * show which tags are displayed * page index works with tags and without tags --- diff --git a/getjson.php b/getjson.php index d9b0891..83360e6 100644 --- a/getjson.php +++ b/getjson.php @@ -22,9 +22,14 @@ if (isset($_REQUEST["S"])) $tag = sqlite_escape_string($_REQUEST["S"]); $result = $DB->query("SELECT name FROM tags"); - $count = $DB->query("SELECT 1"); } -else + else if (isset($_REQUEST["ID"])) + { + $id = intval($_REQUEST["ID"]); + $result = $DB->query("SELECT base_uri, filename, id FROM photos". + " WHERE id=$id"); + } + else { if (isset($_REQUEST["P"])) $OFFSET = "".(intval($_REQUEST["P"])*$N-$N); @@ -37,6 +42,7 @@ else $tags = $_REQUEST["T"]; $tags = explode(",",$tags); $nrtags = count($tags); + foreach ($tags as $key => $value) $tags[$key]=sqlite_escape_string(trim($value)); $tags = "'".implode("','",$tags)."'"; @@ -47,24 +53,32 @@ else a good explanation on different ways of doing this can be found at: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html */ - $result = $DB->query("SELECT base_uri, filename FROM photo_tags pt, photos p, tags t". - " WHERE pt.tag_id = t.id". - " AND (t.name COLLATE NOCASE IN ($tags))". - " AND p.id = pt.photo_id ". - " GROUP BY p.id HAVING COUNT( p.id )=$nrtags". - " LIMIT $OFFSET, $N"); - - $count = $DB->query("SELECT count(*) as total FROM photo_tags pt, photos p, tags t". - " WHERE pt.tag_id = t.id". - " AND (t.name COLLATE NOCASE IN ($tags))". - " AND p.id = pt.photo_id ". - " GROUP BY p.id HAVING COUNT( p.id )=$nrtags". - " LIMIT $OFFSET, $N"); + + if (isset($_REQUEST["C"])) + { + $result = $DB->query("SELECT count(*) as total from (SELECT p.id FROM photo_tags pt, photos p, tags t". + " WHERE pt.tag_id = t.id". + " AND (t.name COLLATE NOCASE IN ($tags))". + " AND p.id = pt.photo_id ". + " GROUP BY p.id HAVING COUNT( p.id )=$nrtags)"); + } + else + { + $result = $DB->query("SELECT base_uri, filename, p.id as id FROM photo_tags pt, photos p, tags t". + " WHERE pt.tag_id = t.id". + " AND (t.name COLLATE NOCASE IN ($tags))". + " AND p.id = pt.photo_id ". + " GROUP BY p.id HAVING COUNT( p.id )=$nrtags". + " LIMIT $OFFSET, $N"); + + } } else { - $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N"); - $count = $DB->query("SELECT count(*) as total FROM photos"); + if (isset($_REQUEST["C"])) + $result = $DB->query("SELECT count(*) as total FROM photos"); + else + $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N"); } } @@ -83,24 +97,7 @@ else } $result=$tmp; -/* encode count as an array */ -$tmp=array(); -if(!$usePDO) - { - /* convert results into array */ - while($res = $count->fetchArray(SQLITE3_ASSOC)) - $tmp[]=$res; - } -else - { - foreach($count as $res) - $tmp[]=$res; - } -$count=$tmp; - -$return=array($count,$result); - -echo json_encode($return); +echo json_encode($result); /* close the database */ if($usePDO) diff --git a/index.php b/index.php index 5ee661f..82378b4 100644 --- a/index.php +++ b/index.php @@ -19,7 +19,15 @@ if(isset($_REQUEST["tag"])) else $tags = ""; +if(isset($_REQUEST["pic"])) + $pic = intval(htmlentities($_REQUEST["pic"])); +else + $pic = -1; +/* end parse flags */ + +/* The basic layout */ ?> + <?php echo htmlspecialchars($title) ?> @@ -31,20 +39,24 @@ else
test

- - +
- Tags: + Add tag:
+ Current tags:
-