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 */
12 if(isset($_REQUEST["page"]))
13 $page = intval($_REQUEST["page"]);
17 if(isset($_REQUEST["tag"]))
18 $tags = htmlentities($_REQUEST["tag"]);
22 if(isset($_REQUEST["pic"]))
23 $pic = intval(htmlentities($_REQUEST["pic"]));
28 /* The basic layout */
32 <title><?php echo htmlspecialchars($title) ?></title>
33 <script src="<?php echo $webbase?>/d3.min.js"></script>
34 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/normalize.css" />
35 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/style.css" />
39 <div class="debug"></div>
40 <h1><?php echo htmlspecialchars($title) ?></h1>
43 <span class="index"></span>
44 <button class="prev" type="button" disabled="disabled" onclick="left()"> prev </button>
45 <button class="next" type="button" onclick="right()">next </button>
46 <button class="all" type="submit" onclick="document.location.href='<?php echo $webbase?>'">all</button>
49 <div class="permalink"></div>
51 <div class="tagsearch">
52 <form method="get" action="">
53 Add tag: <input list="MyTags" id="MyTagsInput" type="text" value="" />
54 <datalist id="MyTags">
57 Current tags:<span id="currenttags"></span>
58 <button class="next" type="button" onclick="cloud()">tag cloud</button>
61 <div class="nextprev"> <ul></ul></div>
63 <div class="pics"><ul></ul> </div>
66 This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
67 <div class="copyright"> photo-tags: copyright 2011 Arun Persaud arun@nubati.net, code available at <a href="http://source.nubati.net/projects/photo-tags">source.nubati.net/projects/photo-tags</a></div>
71 <script type="text/javascript" >
73 var pics = d3.select(".pics").select("ul");
75 var page=<?php echo $page ?>;
76 var N=<?php echo $N ?>;
77 var T="<?php echo $tags ?>";
78 var ID=<?php echo $pic ?>;
81 /* populate data list with tags*/
82 d3.json("<?php echo $webbase?>/getjson.php?S", function(json) {
83 d3.select("#MyTags").selectAll("option").data(json)
84 .enter().append("option").attr("value",function(d) {return d.name});
87 /* update form to point to new link */
88 d3.select("input").on("keyup", function(d) {
89 d3.select('form').attr("action","<?php echo $webbase?>/tag/"+document.getElementById('MyTagsInput').value.replace(" ","+"));
94 var mycurrenttags = T.split(",");
96 d3.select("#currenttags").select("button").remove();
97 d3.select("#currenttags").selectAll("button")
98 .data(mycurrenttags).enter()
99 .append("button").attr("type","button").text( function(d) {return d;} );
103 d3.select("#currenttags").select("button").remove();
104 d3.select("#currenttags").append("span").text( ' none');
107 function load_content(a) {
108 // d3.select(".debug").text("T,P,N = *"+T+"* *"+a+"* *"+N+"*");
110 update_page_index(a);
113 url = "<?php echo $webbase?>/getjson.php?ID="+ID;
115 url = "<?php echo $webbase?>/getjson.php?T="+T+"&P="+a;
117 url = "<?php echo $webbase?>/getjson.php?P="+a;
120 d3.json(url, function(json) {
122 pics.selectAll("li").remove();
125 /* if ID is set, just show one pictures, else create an array of pictures */
128 pics.selectAll("li").data(picdata)
129 .enter().append("li")
131 .attr("class","large")
132 .attr("src",function(d) {
133 s= d.base_uri+'/'+d.filename;
134 s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-small/');
138 /* update thumbnails */
140 url2 = "<?php echo $webbase?>/getjson.php?NP=1&T="+T+"&ID="+ID;
142 url2 = "<?php echo $webbase?>/getjson.php?NP=1&ID="+ID;
144 d3.json(url2, function(json2) {
145 var thumbs= d3.select(".nextprev").select("ul").selectAll("li").data(json2);
146 thumbs.enter().append("li")
148 .attr("href",function(d) {
149 s = '<?php echo $webbase; ?>';
152 s = s + '/pic/' + d.id;
156 .attr("src",function(d) {
157 s= d.base_uri+'/'+d.filename;
158 s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
162 thumbs.exit().remove();
169 d3.select(".nextprev").select("ul").selectAll("li").remove();
170 pics.selectAll("li").data(picdata)
171 .enter().append("li")
173 .attr("href",function(d) {
174 s = '<?php echo $webbase; ?>';
178 s = s + '/page/' + a;
179 s = s + '/pic/' + d.id;
183 .attr("src",function(d) {
185 s= d.base_uri+'/'+d.filename;
186 s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
194 /* update permalink */
196 permalink="<?php echo $webbase ?>";
198 permalink += '/tag/' + T;
200 permalink += '/page/' + a;
203 d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
207 if (page>=2) page=page-1;
218 url = "<?php echo $webbase?>/getjson.php?CLOUD=1";
220 pics.selectAll("li").remove();
222 var svgelement=pics.append("li")
223 .append("svg").attr("width",400).attr("height",400);
226 d3.json(url, function(json) {
227 svgelement.selectAll("text").data(json).enter().append("text")
228 .style("font-size", function(d){return (Math.log(d.count+1)/2.0)+"em"})
229 .text(function(d) { return d.name+" "; })
230 .on("mouseover", function(d){ d3.select(this).style("color","red")} )
231 .on("mouseout", function(d){ d3.select(this).style("color","white")} )
232 .on("click", function(d) { document.location.href='<?php echo $webbase?>/tag/'+d.name })
236 function checkbutton()
240 { d3.select("button.prev").attr("disabled","disabled");}
242 { d3.select("button.prev").attr("disabled", null);};
245 { d3.select("button.next").attr("disabled","disabled");}
247 { d3.select("button.next").attr("disabled",null);}
250 function update_page_index(mypage)
252 /* load number of pictures */
255 url = "<?php echo $webbase?>/getjson.php?C=1&T="+T;
257 url = "<?php echo $webbase?>/getjson.php?C=1";
259 d3.json(url, function(json) {
260 /* update index, show only page +-5 pages max */
261 n = Math.floor(json[0].total/N);
270 s+=" <a href=\"<?php echo $webbase?>";
273 s+="/page/1\">1</a>...";
279 for(i=start;i<=Math.min(n+1,mypage+5);i++)
285 s+=" <a href=\"<?php echo $webbase?>";
288 s+="/page/"+i+"\">"+i+"</a>";
294 s+="... <a href=\"<?php echo $webbase?>";
297 s+="/page/"+(n+1)+"\">"+(n+1)+"</a>";
301 s+=" <a href=\"<?php echo $webbase?>";
304 s+="/page/"+(n+1)+"\">"+(n+1)+"</a>";
307 d3.select(".index").html(s);