fix displaying of tags that include a whitespace (use + instead)
[photo-tags.git] / index.php
index 78f77e18f6bdd5608d40a97dc23dffce4ca14284..4a7bdf48720a6b629bb03ca0b29d027bf0112ea3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -15,7 +15,7 @@ else
   $page = 1;
 
 if(isset($_REQUEST["tag"]))
-  $tags = $_REQUEST["tag"];
+  $tags = htmlentities($_REQUEST["tag"]);
 else
   $tags = "";
 
@@ -64,13 +64,13 @@ var count=0;
 
 /* populate data list with tags*/
 d3.json("<?php echo $webbase?>/getjson.php?S", function(json) {
-    d3.select("#MyTags").selectAll("option").data(json)
+    d3.select("#MyTags").selectAll("option").data(json[1])
       .enter().append("option").attr("value",function(d) {return d.name});
   });
 
 /* update form to point to new link */
 d3.select("input").on("keyup", function(d) {
-    d3.select('form').attr("action","<?php echo $webbase?>/tag/"+document.getElementById('MyTagsInput').value);
+    d3.select('form').attr("action","<?php echo $webbase?>/tag/"+document.getElementById('MyTagsInput').value.replace(" ","+"));
 });
 
 function myreload(a) {
@@ -83,16 +83,50 @@ function myreload(a) {
 
   d3.json(url, function(json) {
 
-      /* update index */
+      /* update index, show only page +-5 pages max */
       s="page ";
-      n = json[0][0].total/N;
-      for(i=1;i<=n+1;i++)
+      n = Math.floor(json[0][0].total/N);
+
+      if(a>7)
        {
          s+=" <a href=\"<?php echo $webbase?>";
          if(T!="")
            s+="/tag/"+T;
-         s+="/page/"+i+"\">"+i+"</a>";
+         s+="/page/1\">1</a>...";
+         start = a-5;
+       }
+      else
+       start=1;
+
+      for(i=start;i<=Math.min(n+1,a+5);i++)
+       {
+         if(i==a)
+           s+= " "+i+" ";
+         else
+           {
+             s+=" <a href=\"<?php echo $webbase?>";
+             if(T!="")
+               s+="/tag/"+T;
+             s+="/page/"+i+"\">"+i+"</a>";
+           }
        }
+
+      if(a+5<n)
+       {
+         s+="... <a href=\"<?php echo $webbase?>";
+         if(T!="")
+           s+="/tag/"+T;
+         s+="/page/"+(n+1)+"\">"+(n+1)+"</a>";
+       }
+      else if(a+5==n)
+       {
+         s+=" <a href=\"<?php echo $webbase?>";
+         if(T!="")
+           s+="/tag/"+T;
+         s+="/page/"+(n+1)+"\">"+(n+1)+"</a>";
+       };
+
+
       d3.select(".index").html(s);
 
       /* update pics */