78f77e18f6bdd5608d40a97dc23dffce4ca14284
[photo-tags.git] / index.php
1 <?php
2 /* parse ini -file */
3 $iniarray=parse_ini_file("config.ini");
4 $webbase=$iniarray["webbase"];
5 $dbprefix=$iniarray["dbprefix"];
6 $admin=$iniarray["admin"];
7 $title=$iniarray["title"];
8 $N=$iniarray["pics_per_page"];
9 /* end parse ini-file */
10
11 /* parse flags */
12 if(isset($_REQUEST["page"]))
13   $page = intval($_REQUEST["page"]);
14 else
15   $page = 1;
16
17 if(isset($_REQUEST["tag"]))
18   $tags = $_REQUEST["tag"];
19 else
20   $tags = "";
21
22 ?>
23 <html>
24 <title><?php echo htmlspecialchars($title) ?></title>
25 <script src="<?php echo $webbase?>/d3.min.js"></script>
26 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/normalize.css" />
27 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/style.css" />
28
29 <body>
30
31 <div class="debug">test</div>
32 <h1><?php echo htmlspecialchars($title) ?></h1>
33
34 <button class="prev" disabled="disabled" onclick="left()"> prev </button>
35 <button class="next"   onclick="right()">next </button>
36
37 <div class="permalink"></div>
38
39 <div class="tagsearch">
40 <form method="get" action="">
41  Tags: <input list="MyTags" id="MyTagsInput" type="text" value="" />
42   <datalist id="MyTags">
43   </datalist>
44 </form>
45 </div>
46
47 <div class="index"></div>
48 <div class="pics"> </div>
49
50 <footer>
51   This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
52   <div class="copyright"> code: copyright 2011 Arun Persaud arun@nubati.net, code available at nubati.net/git/f-spot-gallery</div>
53 </footer>
54
55
56 <script type="text/javascript" >
57
58 var pics = d3.select(".pics").append("ul");
59
60 var page=<?php echo $page ?>;
61 var N=<?php echo $N ?>;
62 var T="<?php echo $tags ?>";
63 var count=0;
64
65 /* populate data list with tags*/
66 d3.json("<?php echo $webbase?>/getjson.php?S", function(json) {
67     d3.select("#MyTags").selectAll("option").data(json)
68       .enter().append("option").attr("value",function(d) {return d.name});
69   });
70
71 /* update form to point to new link */
72 d3.select("input").on("keyup", function(d) {
73     d3.select('form').attr("action","<?php echo $webbase?>/tag/"+document.getElementById('MyTagsInput').value);
74 });
75
76 function myreload(a) {
77   d3.select(".debug").text("T,P,N ="+T+" "+a+" "+N);
78
79   if(T!="")
80     url = "<?php echo $webbase?>/getjson.php?T="+T+"&P="+a;
81   else
82     url = "<?php echo $webbase?>/getjson.php?P="+a;
83
84   d3.json(url, function(json) {
85
86       /* update index */
87       s="page ";
88       n = json[0][0].total/N;
89       for(i=1;i<=n+1;i++)
90         {
91           s+=" <a href=\"<?php echo $webbase?>";
92           if(T!="")
93             s+="/tag/"+T;
94           s+="/page/"+i+"\">"+i+"</a>";
95         }
96       d3.select(".index").html(s);
97
98       /* update pics */
99       count=0;
100       pics.selectAll("li").remove();
101       picdata=json[1];
102       pics.selectAll("li").data(picdata)
103         .enter().append("li")
104         .append("a")
105         .attr("href",function(d) {
106             s= d.base_uri+'/'+d.filename;
107             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase; ?>/Photos-small/');
108             return s;
109           })
110         .append("img")
111         .attr("src",function(d) {
112             count++;
113             s= d.base_uri+'/'+d.filename;
114             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
115             return s;
116           });
117       checkbutton();
118     });
119
120   permalink="<?php echo $webbase ?>/page/"+page;
121   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
122 }
123
124 function left() {
125   if (page>=2) page=page-1;
126   myreload(page);
127 }
128
129 function right() {
130   page=page+1;
131   myreload(page);
132 }
133
134 function checkbutton() {
135
136   if (page==1)
137     { d3.select("button.prev").attr("disabled","disabled");}
138   else
139     { d3.select("button.prev").attr("disabled", null);};
140
141   if (count<N)
142     { d3.select("button.next").attr("disabled","disabled");}
143   else
144     { d3.select("button.next").attr("disabled",null);}
145 }
146
147 myreload(page);
148
149 </script>
150
151 </body>
152 </html>