added a permalink and use clean urls
[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 ?>
18 <html>
19 <title><?php echo htmlspecialchars($title) ?></title>
20 <script src="<?php echo $webbase?>/d3.min.js"></script>
21 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/normalize.css" />
22 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/style.css" />
23
24 <body>
25
26 <div class="debug">test</div>
27 <h1><?php echo htmlspecialchars($title) ?></h1>
28
29 <button class="prev" disabled="disabled" onclick="left()"> prev </button>
30 <button class="next"   onclick="right()">next </button>
31
32 <div class="permalink"></div>
33
34 <div class="pics"> </div>
35
36 <footer>
37   This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
38   <div class="copyright"> code: copyright 2011 Arun Persaud arun@nubati.net, code available at nubati.net/git/f-spot-gallery</div>
39 </footer>
40
41
42 <script type="text/javascript" >
43
44
45 var pics = d3.select(".pics").append("ul");
46
47 var page=<?php echo $page ?>;
48 var N=<?php echo $N ?>;
49 var count=0;
50
51 function myreload(a) {
52   d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) {
53       count=0;
54       pics.selectAll("li").remove();
55       pics.selectAll("li").data(json)
56         .enter().append("li")
57         .append("a")
58         .attr("href",function(d) {
59             s= d.base_uri+'/'+d.filename;
60             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase; ?>/Photos-small/');
61             return s;
62           })
63         .append("img")
64         .attr("src",function(d) {
65             count++;
66             s= d.base_uri+'/'+d.filename;
67             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
68             return s;
69           });
70       checkbutton();
71     });
72
73   permalink="<?php echo $webbase ?>/page/"+page;
74   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
75   d3.select(".debug").text("P, count= "+a+" "+count);
76 }
77
78 function left() {
79   if (page>=2) page=page-1;
80   myreload(page);
81 }
82
83 function right() {
84   page=page+1;
85   myreload(page);
86 }
87
88 function checkbutton() {
89
90   if (page==1)
91     { d3.select("button.prev").attr("disabled","disabled");}
92   else
93     { d3.select("button.prev").attr("disabled", null);};
94
95   if (count<N)
96     { d3.select("button.next").attr("disabled","disabled");}
97   else
98     { d3.select("button.next").attr("disabled",null);}
99 }
100
101 myreload(page);
102
103 </script>
104
105 </body>
106 </html>