aboutsummaryrefslogtreecommitdiff
path: root/www/inc/www.class.inc.php
blob: 27683cc9184e2df8ee5f3acbc838d56723c377f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
// www.class.inc.php
class C_www {
   var $background, $bgcolor, $link, $vlink, $alink, $hover, $language;
   var $textcol, $font, $fontsize;

   ////
   // !vykpise HTML hlavicku dokumentu
   // Ten CSS style jeste neni moc dodelanej
   function header($title) {
      global $gallery_dir,$root, $snimek, $galerie, $ThisScript, $themes;

			header("Content-Type: text/html; charset=utf-8");// make sure we send in utf8
																											 // and override Apache

																											 // For some reason text/xml is
																											 // causing trouble with stylesheets
			echo "<?xml version=\"1.0\"?>\n";
			/*
			echo "<?xml-stylesheet type=\"text/css\" media=\"screen\""; // doesn't work yet :/
			echo " href=\"inc/style/dark/dark.css\" ?>\n";
			*/
      echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
      echo "   \"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd\">\n";
      echo "<html>\n";
      echo "<head>\n";

			#IE hacks
			echo "<!-- This makes IE6 suck less (a bit) -->\n";
			echo "<!--[if lt IE 7]>\n";
			echo "<script src=\"inc/styles/ie7/ie7-standard.js\" type=\"text/javascript\">\n";
			echo "</script>\n";
			echo "<![endif]-->\n";

      echo "   <title>$title</title>\n";
			echo "<link rel=\"icon\" href=\"stock_camera-16.png\" ";
			echo "type=\"image/png\" />\n";
			echo "<link rel=\"shortcut icon\" href=\"favicon.ico\" ";
			echo "type=\"image/x-icon\" />\n";
      # mozilla style links
		if ($snimek && $galerie) {
			#Top
			echo "   <link rel=\"Top\"      href=\"$ThisScript\" />\n";
			#First
			#Prev
			$predchozi = $snimek - 1;
			$dalsi = $snimek + 1;
   		if ($snimek > 1) {
				echo "   <link rel=\"First\" ";
				echo "   href=\"$ThisScript?galerie=$galerie&amp;photo=1\" />\n";
				echo "   <link rel=\"Previous\" ";
				echo "href=\"$ThisScript?galerie=$galerie&amp;photo=$predchozi\" />\n";
			}
			#Next
			if (is_file("$gallery_dir/$galerie/lq/img-$dalsi.jpg")) {
				echo "   <link rel=\"Next\" ";
				echo "    href=\"$ThisScript?galerie=$galerie&amp;photo=$dalsi\" />\n";
			}
			#Last
			$adr = opendir("$gallery_dir/$galerie/thumbs/");
			$i = -2;
			while ($file = readdir($adr)) {
				$i++;
			}
			if ($i!=$snimek) {
				echo "   <link rel=\"Last\" ";
				echo "    href=\"$ThisScript?galerie=$galerie&amp;photo=$i\" />\n";
			}
		}
      
      /* check the theme in a cookie */
      $theme = @$_COOKIE["theme"];
      if (!$theme) { //we didn't set the cookie yet
	 // select first key of the themes array in config.inc.php as default
	 $theme_keys = array_keys($themes);
	 $theme = $theme_keys[0]; 
      }
      foreach ($themes as $skin => $url) {
         echo "<link type=\"text/css\" rel=\"";
         if ($skin==$theme) {
            echo "stylesheet";
         } else {
            echo "prefertch alternate stylesheet";
         }
         echo "\" href=\"$url\" title=\"$skin\"";
         echo " media=\"screen\" />\n";
      }
     
      //require("javascript.inc.php");
			echo "<script src=\"inc/global.js\" ";
			echo "type=\"text/javascript\"></script>\n";
      echo "</head>\n\n";
      echo "<body onload=\"checkForTheme()";
      echo "\">\n";
   }

   ////
   // !zavre html stranku
   function footer() {
      echo "</body>\n";
      echo "</html>\n";
   }

   ////
   // !vypise chybovou hlasku
   // $title - nadpis a title HTML stranky
   // $message - vlastni chybova hlaska
   function error($title, $message) {
         $this->header($title);
         echo "<h1>$title</h1>\n";
         echo $message;
         $this->footer();
         exit; //vysere se na vsechno
   }

  
     
   ////
   // !zacatek fomrulare
   function form_start($action, $method, $upload) {
      echo "<form ";
      if ($upload) echo "enctype=\"multipart/form-data\" ";
      echo "action=\"";
			echo htmlentities($action,ENT_COMPAT,"UTF-8");
			echo "\" method=\"$method\">\n";
   }

   ////
   // !konec formulare
   function form_end() {
      echo "</form>\n";
   }
 
   ////
   // !vykresli polozku formulare
   // umi text, password, submit, file, hidden, textarea, select
   // u textarea je default pocet radku...
   function input($type, $name, $value, $popis, $default, $title) {
			echo "<div class=\"row\">\n";
			if (!$title) {
				echo "	<div class=\"label\">$popis</div>\n";
			} else {
				echo "	<div class=\"label\"><a title=\"$title\" ";
				echo "href=\"#\">$popis</a></div>\n";
			}
			echo "	<div class=\"control\">";
      switch ($type) {
         case "checkbox":
            echo "<input type=\"$type\" name=\"$name\" value=\"$value\"";
            if ($default) echo " checked=\"checked\"";
            echo " />";
            break;
         case "password": 
         case "text": 
            echo "<input type=\"$type\" size=\"30\" name=\"$name\" value=\"$value\" />";
            break;
         case "file": 
            echo "<input type=\"$type\" size=\"30\" name=\"$name\" />";
            break;
         case "hidden": 
            echo "<input type=\"$type\" name=\"$name\" value=\"$value\" />";
            break;
         case "textarea":
            echo "<textarea name=\"$name\" cols=\"40\"";
            if ($default) {
                echo " rows=\"$default\"";
            } else {
                echo " rows=\"10\"";
            }
            echo ">$value</textarea>";
            break;
         case "select":
            echo "<select name=\"$name\" size=\"1\">\n";
            while (list($optval, $option) = each($value)) {
                echo "<option value=\"$optval\"";
                if ($optval == $default) echo " selected";
                echo ">";
                echo $option;
                echo "</option>\n";
            }
            echo "</select>";
            break;
         case "submit":
            echo "<input type=\"$type\" name=\"$name\" value=\"$value\" />";
            break;
      }
			echo "	</div>\n";
			echo "</div>\n";
   }

	
	function navigation ($gallery, $snapshot, $image) {
   global $gallery_dir, $root, $ThisScript, $textnav, $img, 
          $show_thumbs, $exif_style, $PNthumbScale;

   $next = $snapshot + 1;
   $prev = $snapshot - 1;

   if (!$image) { // this will render a navigation bar - max 3 buttons
      echo "\n<div class=\"navbuttons\">\n";
      echo "<div class=\"navbuttonsshell\">\n";
      if ($snapshot > 1) { //previous 
         echo "<a id=\"previcon\" href=\"$ThisScript?galerie=$gallery&amp;photo=$prev";
         echo "&amp;exif_style=$exif_style&amp;show_thumbs=$show_thumbs\"";
				 echo " accesskey=\"p\">";
         echo "&lt; <span class=\"accesskey\">P</span>revious</a>\n";
      }
      echo "&nbsp;";
      if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) { //next
         echo "<a id=\"nexticon\" href=\"$ThisScript?galerie=$gallery&amp;photo=$next";
         echo "&amp;exif_style=$exif_style&amp;show_thumbs=$show_thumbs\"";
				 echo " accesskey=\"n\">";
         echo "<span class=\"accesskey\">N</span>ext &gt;</a>\n";
      }
      echo "</div>\n</div>\n";
   } elseif ($image=="prev") { //previous thumbnail
      if ($snapshot > 1) { //previous 
         echo "<div class=\"prevthumb\">";
         echo "<a href=\"$ThisScript?galerie=$gallery&amp;photo=$prev";
         echo "&amp;exif_style=$exif_style&amp;show_thumbs=$show_thumbs\">";
         if (file_exists("$gallery_dir/$gallery/thumbs/img-$prev.png")) {
            $Pthumb = "$gallery_dir/$gallery/thumbs/img-$prev.png";
         } else {
            $Pthumb = "$gallery_dir/$gallery/thumbs/img-$prev.jpg";
         }
         $v = getimagesize("$root/$Pthumb");
         echo "<img alt=\"Previous\" src=\"";
         echo $Pthumb . "\" width=\"" . round($v[0]/$PNthumbScale);
         echo "\" height=\"" . round($v[1]/$PNthumbScale) . "\" />";
         echo "<br />" . __('Previous');
         echo "</a></div>\n";
      }
   } else { //next thumbnail
      if (is_file("$gallery_dir/$gallery/lq/img-$next.jpg")) {
         echo "<div class=\"nextthumb\">";
         echo "<a href=\"$ThisScript?galerie=$gallery&amp;photo=$next";
         echo "&amp;exif_style=$exif_style&amp;show_thumbs=$show_thumbs\">";
         if (file_exists("$gallery_dir/$gallery/thumbs/img-$next.png")) {
            $Nthumb = "$gallery_dir/$gallery/thumbs/img-$next.png";
         } else {
            $Nthumb = "$gallery_dir/$gallery/thumbs/img-$next.jpg";
         }
         $v = getimagesize("$root/$Nthumb");
         echo "<img alt=\"Next\" src=\"";
         echo $Nthumb . "\" width=\"" . round($v[0]/$PNthumbScale);
         echo "\" height=\"" . round($v[1]/$PNthumbScale) . "\" />";
         //echo "<br /><span class=\"accesskey\">N</span>ext";
         echo "<br />" . __('Next') ;	 
         echo "</a></div>\n";
      }
   }
	}

	function user_comments($photo) {
		global $root, $gallery_dir, $galerie, $comments, $picture;

   if ($comments) {
		 if (is_writable("$root/$gallery_dir/$galerie/comments")) { // needs perms
			 require("inc/comment_form.inc.php");

			 if ($picture->comments) {
					print "<div class=\"user_comment\">";
					print $picture->comments;
					print "</div>";
			 }
		 } else {
			 print "<!-- WARNING: comment dir not writable -->\n";
		 }
   }
	}

	function process_comment_form() { // processing of the user comment data
		global $comments, $root, $gallery_dir, $galerie, $snimek;
		
		if($comments && @$_POST["commentdata"]) {
				$username = @$_COOKIE["username"];
				$comment_name = @$_POST["commentname"];
				$save_comment_name = @$_POST["savecommentname"];
				$comment_data = @$_POST["commentdata"];
				$comment_kolacek = @$_POST["commentkolacek"];
				$comment_spamcheck = @$_POST["commentspamcheck"];

				#check for HTML tags
				
				$comment_name = stripslashes(strip_tags($comment_name));
				$allowedTags = '<a><b><i><ul><li><blockquote><br>';
				$comment_data = stripslashes(strip_tags($comment_data,$allowedTags));
				// thanks google: 
				// http://www.google.com/googleblog/2005/01/preventing-comment-spam.html
				$comment_data = eregi_replace("<a ","<a rel=\"nofollow\" ",$comment_data);

				#further comment spam
				$comment_blacklist = array("pharmacy", "poker", "Viagra");

				foreach($comment_blacklist as $blackword) {
					$check = addslashes($blackword);
					if (eregi($check,$comment_data)) {
						#write error message
						$this->error( __('No comment spam'), __('Your comment includes blacklisted word') . __('No comment spam') );
						$this->footer();
						exit; //stop everything
					}
				}

				if ($comment_kolacek!=md5($comment_spamcheck)) {
						$this->error( __('No comment spam'), __('You ve written the check number wrong' ) );
						$this->footer();
						exit; //stop everything
				}

				if (!$comment_name) {
					$comment_name = $_COOKIE["username"];
				}
				
				// ok so we got a comment
				if ($comment_name && $save_comment_name) {
				// save out name in a cookie
					if (!setcookie("username","$comment_name", 
											mktime(0, 0, 0, 12, 30, 2030))) {
						print __('Could not set name cookie!');
						exit;
					}
				}

				// create a user_comment file if not existant or append to it
				if (!$picture) {
				  require_once("$root/inc/photo.class.inc.php");
					$path = "$gallery_dir/$galerie/lq";
					$file = "$path/img-$snimek.jpg";
					$picture = new C_photo($file, $snimek);
				}
				$picture->addcomment($comment_name, $comment_data);
		}
	}
}

# return dirs sorted
class SortDir {
   var $items;

   function SortDir($directory) {
      $handle=@opendir($directory);
			if (!$handle) return;
      while ($file = readdir($handle)) {
         if ($file != "." && $file != "..") {
            $this->items[]=$file;
         }
      }
      closedir($handle);
	    if ($this->items) {
         natsort($this->items);
	    }
   }

   function Read() {
			if ($this->items) {
				$getback= (pos($this->items));
				next($this->items);
				return $getback;
			}
   }
}

?>