Update header - remove Tech section and add Projects.
[www.vanrenterghem.biz.git] / phppages / photoblog.php
1 <?php 
2 $title = "MOBLOG";
4 // // Based on code taken from Teri Solow - http://terisolow.com/source.php?url=/photoblog.php
6 // // include('comments.php'); 
8 // the code for printing/adding comments is 
9 // basically straight from my picture script:
10 // http://www.terisolow.com/programs.php#PHP-pics
12 // cookie_setup();
13  
14 $serverroot = "/www";
15 $home = "/Pictures/";
16 $path = "";
18 include $serverroot."/header.shtml";
19 // connect to database and get picture information
20 // //db_connect();
21  $table = 'photoblog';
22  $picsperpage = 20;
24 function show_image($imagename, $imagearray) {
25         global $home, $serverroot, $PHP_SELF, $HTTP_POST_VARS, $HTTP_SERVER_VARS, $banned, $table;
26         $img_data = $imagearray[$imagename];
27         $img_size = getimagesize($serverroot.$home."camblog/".$img_data['file']);
28         $width = $img_size[0];
29         $height = $img_size[1];
30         $width_scale = 600;
31                 if ($width>$width_scale) {
32                         $ratio = $width/$width_scale;
33                         $width = $width_scale;
34                         $height = round($height/$ratio);
35                         }
36         $images = array_keys($imagearray);
38 foreach ($images as $image) {
39         if (!isset($last)) {
40                 $first = $image;
41                 }
42         if ($now) {
43                 $next = $image;
44                 $now = false;
45                 }
46         if ($image == $imagename) {
47                 $prev = $last;
48                 $now = true;
49                 }
50         $last = $image;
51         }
53 if (!isset($prev)){
54         $prev = $last;
55         }
56 if (!isset($next)){
57         $next = $first;
58         }
59 print "<hr align=\"center\" size=\"2\" width=\"95%\" noshade=\"noshade\" />
60 <center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"90%\"><tr><td align=\"left\" width=\"33%\">
61 <a class=\"inflate\" href=\"$HTTP_SERVER_VARS[PHP_SELF]?image=$prev\">&lt;-- previous</a>
62 </td>
63 <td align=\"center\" width=\"34%\"><a href=\"$HTTP_SERVER_VARS[PHP_SELF]\">back</a></td>
64 <td align=\"right\" width=\"33%\">
65 <a class=\"inflate\" href=\"$HTTP_SERVER_VARS[PHP_SELF]?image=$next\">next --&gt;</a>
66 </td></tr></table></center>
67 <br />
68 <center>
69 <img src=\"$home./camblog/".$img_data['file']."\" border=\"0\" width=\"$width\" height=\"$height\"  alt=\"".$img_data['file']."\" />
70 <br /><em class=\"date\">".$img_data['date']."</em><br />
71 <strong>".$img_data['subject']."</strong>
72 </center>
73 <p style=\"margin: 10px 40px 10px 40px\">\n";
74 print $img_data['description'];
75 print "</p><br />\n\n";
77 // $notify = show_comments($img_data['file'], $table);
78 // comment_form($img_data['file'], $table, $notify);
79 }
81 function show_all($imagearray, $page) {
82 global $HTTP_SERVER_VARS, $home, $serverroot, $table, $picsperpage;
84 // given page number and number of pics per page, find starting and
85 // ending indexes
86 $start = 0;
87 if ($page == 0) {
88 $end = $start+$picsperpage;
89 }
90 else {
91 $start = $page*$picsperpage;
92 if ($start > count($imagearray)) {
93 $start = 0;
94 $end = $start+$picsperpage;
95 }
96 else {
97 $end = $start+$picsperpage;
98 }
99 }
100 // find out how many pages there are
101 $numpages = ceil(count($imagearray)/$picsperpage);
102 print "<hr align=\"center\" size=\"2\" width=\"95%\" noshade=\"noshade\" />
104 <div class=\"body\">
106 <p>These pictures were taken with my mobile phone.</p>
109 </div>\n\n";
111 print "<div class=\"hr\">
112 <p class=\"leftside\">photo tekniklog</p>
113 <p class=\"rightside\">".count($imagearray)." images; $picsperpage images/page; page ";
114 print $page+1;
115 print "/".$numpages."</p>
116 <div style=\"clear: both;\"></div></div>\n\n";
118 print "<div style=\"float: left; align: left;\">";
119 if ($page>0) {
120 $last = $page-1;
121 print "<a href=\"$HTTP_SERVER_VARS[PHP_SELF]?page=$last\">&lt;&lt;</a>";
123 print "</div>\n<div style=\"float: right; align: right;\">";
124 if ($page<$numpages-1) {
125 $next = $page+1;
126 print "<a href=\"$HTTP_SERVER_VARS[PHP_SELF]?page=$next\">&gt;&gt;</a>";
128 print "</div>\n<div style=\"clear: both;\"></div>";
130 print "<div style=\"text-align: center; margin: 0px 50px 0px 50px;\">
131 <br clear=\"all\" />\n\n";
133 $curr = 0;
134 foreach ($imagearray as $image) {
135 if (($curr>=$start)&&($curr<$end)) {
136 $thumbname = "/Pictures/camblog/tiny".$image['file'];
138 // $comments = num_comments($image['file'], $table);
139 //if ($comments==0) {
140 //$nocomments = "No comments";
141 //}
142 //else if ($comments==1) {
143 //$nocomments = "One comment";                  
144 //}
145 //else {
146 //$nocomments = "$comments comments";
147 //}
149 print "<div class=\"thumbnail\" style=\"height: 140px\">
150 <a class=\"art\" href=\"$HTTP_SERVER_VARS[PHP_SELF]?image=".$image['file']."\"><img class=\"art\" src=\"$thumbname\" border=\"0\" width=\"125\" height=\"93\" alt=\"".$image['date']."\" title=\"".$image['date']."  - $nocomments\" /></a><br />\n";
151 if ($comments>0) {
152 print "<span class=\"comment_notify\">$nocomments</span><br />";
153 } else {
154 print "$nocomments<br />";
156 print $image['date']."<br />";
157 print $image['subject'];
158 print "</div>\n";
160 $curr++;
163 print "</div>\n\n";
164 print "<br clear=\"all\" />\n";
166 if ($numpages>1) {
167 print "<div style=\"font-size: x-small; text-align: center; font-family: lucidatypewriter, clean, courier, monospace;\">";
168 print "<strong>~ Page ~</strong><br />\n";
169 for ($i = 0; $i < $numpages; $i++) {
170 if ($page==$i) {
171 print " <s>$i</s> ";
173 else {
174 print " <a href=\"$HTTP_SERVER_VARS[PHP_SELF]?page=$i\">$i</a> ";
177 print "</div>\n\n";
181 function sanitize($input) {
182 $output = str_replace("<br />", "[br]", $input);
183 $output = htmlspecialchars($output, ENT_QUOTES);
184 $output = str_replace("[br]", " <br />\n", $input);
185 return $output;
188 $workincludefile = $serverroot.$home."/camblog/index.txt";
189 $worklinearray = file($workincludefile);
190 $worklines =  array_keys($worklinearray);
191 foreach ($worklines as $line) {
192 $element = explode("::", $worklinearray[$line]);
193 $thisfile = $element[0];
194 $thissubject = sanitize($element[1]);
195 $thisdesc = sanitize($element[2]);
196 $thisdate = date("M j Y H:i", substr($thisfile, 0, -4));
197 $images[$thisfile] = array("file"=>$thisfile, "subject"=>$thissubject, "description"=>$thisdesc, "date"=>$thisdate);
199 $images = array_reverse($images, TRUE);
200 $image = $HTTP_GET_VARS['image'];
201 $page = $HTTP_GET_VARS['page'];
202 if (empty($page)) { $page = 0; }
203 if (array_key_exists($image, $images)) {
204 show_image($image, $images);
205 } else {
206 show_all($images, $page);
209 include('../footer.php');
211 ?>