ryxeo-webphotoalbum-git / data / www / inc / funkce.inc.php @ 278d2613
Historique | Voir | Annoter | Télécharger (4,09 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
function check($file) { |
4 |
global $gallery_dir, $page; |
5 |
|
6 |
// if (eregi("[^0-9a-z\_\-\ ]",$file) || !file_exists("$gallery_dir/$file")) {
|
7 |
// if (eregi("CVS",$file) || !file_exists("$gallery_dir/$file")) {
|
8 |
if (!file_exists("$gallery_dir/$file")) { |
9 |
echo "funkce.inc.php/check(): Bad input"; |
10 |
$page->footer();
|
11 |
exit;
|
12 |
} |
13 |
} |
14 |
|
15 |
function browserCheck() { |
16 |
global $HTTP_USER_AGENT; |
17 |
|
18 |
$HTTP_USER_AGENT=$_SERVER["HTTP_USER_AGENT"]; |
19 |
if (eregi("(MSIE.[456789]).*Mac.*",$HTTP_USER_AGENT)) { |
20 |
return("macie4+"); |
21 |
} elseif (eregi("(MSIE.[678])",$HTTP_USER_AGENT)) { |
22 |
return("ie6+"); |
23 |
} elseif (eregi("(MSIE.[45])",$HTTP_USER_AGENT)) { |
24 |
return("ie4+"); |
25 |
} elseif (eregi("Opera",$HTTP_USER_AGENT)) { |
26 |
return("opera"); |
27 |
} elseif (eregi("(Mozilla.4)",$HTTP_USER_AGENT)) { |
28 |
return("netscape4"); |
29 |
} elseif (eregi("(Mozilla.[5-9])",$HTTP_USER_AGENT)) { |
30 |
return("mozilla"); |
31 |
} elseif (eregi("KMeleon",$HTTP_USER_AGENT)) { |
32 |
return("mozilla"); |
33 |
} else {
|
34 |
return("Netscape3"); |
35 |
} |
36 |
} |
37 |
|
38 |
function infoParse ($infofile) { |
39 |
|
40 |
$info_array = file($infofile); |
41 |
foreach ($info_array as $line) { |
42 |
list($key,$value) = split("\|",$line); |
43 |
$result[$key]=$value; |
44 |
} |
45 |
return $result; |
46 |
} |
47 |
|
48 |
function readInfo ($infofile, $file) { |
49 |
global $galerieyear, $galeriemonth, $galerieday, $galeriedesc, $galerieauthor, |
50 |
$galeriename, $galerielogin, $galeriepw, $gallery_dir, $galerievideo; |
51 |
|
52 |
if (file_exists($infofile)) { |
53 |
//read from info.txt
|
54 |
$info_array = infoParse($infofile); |
55 |
|
56 |
//video ?
|
57 |
if(trim($info_array["video"]) == "true") { |
58 |
//print_r($info_array);
|
59 |
$galerievideo = 1; |
60 |
} |
61 |
else {
|
62 |
$galerievideo = 0; |
63 |
} |
64 |
|
65 |
if ($info_array["date"]) { |
66 |
// try to be a little smarter about format
|
67 |
if (ereg("([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})", |
68 |
$info_array["date"])) { |
69 |
// remain compatible - DD.MM.YYYY
|
70 |
list($day,$month,$year) = split("\.", $info_array["date"]); |
71 |
$year = rtrim($year); |
72 |
$month = rtrim($month); |
73 |
$day = rtrim($day); |
74 |
$info_array["date"] = "$year-$month-$day"; //make it US date |
75 |
} |
76 |
// US date format at this point
|
77 |
$tstamp = strtotime($info_array["date"]); |
78 |
} else {
|
79 |
$tstamp = filemtime("$gallery_dir/$file");// Get from filesystem |
80 |
} |
81 |
$galerieyear["$file"] = date("Y", $tstamp); |
82 |
$galeriemonth["$file"] = date("m", $tstamp); |
83 |
$galerieday["$file"] = date("d", $tstamp); |
84 |
|
85 |
if (@$info_array["description"]) { |
86 |
$galeriedesc["$file"] = rtrim($info_array["description"]); |
87 |
} |
88 |
|
89 |
if (@$info_array["author"]) { |
90 |
$galerieauthor["$file"] = rtrim($info_array["author"]); |
91 |
} |
92 |
|
93 |
if (@$info_array["name"]) { |
94 |
$galeriename["$file"] = rtrim($info_array["name"]); |
95 |
} |
96 |
|
97 |
if (@$info_array["restricted_user"]) { |
98 |
$galerielogin["$file"] = rtrim($info_array["restricted_user"]); |
99 |
$galeriepw["$file"] = rtrim($info_array["restricted_password"]); |
100 |
} |
101 |
} else { // Get Dates from modification stamp |
102 |
$mtime = filemtime("$gallery_dir/$file"); |
103 |
$galerieyear["$file"] = date("Y", $mtime); |
104 |
$galeriemonth["$file"] = date("m", $mtime); //F |
105 |
$galerieday["$file"] = date("d", $mtime); |
106 |
} |
107 |
} |
108 |
|
109 |
function access_check($login, $password,$realm) { |
110 |
if (!($_SERVER['PHP_AUTH_USER']=="$login" && $_SERVER['PHP_AUTH_PW']=="$password")) { |
111 |
header("WWW-authenticate: Basic Realm=$realm"); |
112 |
Header("HTTP/1.0 401 Unauthorized"); |
113 |
$err = new C_www; |
114 |
$err->header("Access Denied"); |
115 |
echo "<div class=\"error\">\n"; |
116 |
echo "<h1>Access Denied</h1>\n"; |
117 |
echo "<p>Sorry, this gallery is restricted</p>\n"; |
118 |
echo "<p><a href=\"index.php\">Return to index</a></p>\n"; |
119 |
echo "</div>\n"; |
120 |
$err->footer();
|
121 |
exit;
|
122 |
} |
123 |
|
124 |
} |
125 |
|
126 |
function random_digits($times) { |
127 |
$random=""; |
128 |
for ($i=0;$i<$times;$i++) { |
129 |
$random .= rand(0,9); |
130 |
} |
131 |
return $random; |
132 |
} |
133 |
|
134 |
function get_photo_title($galerie, $id) { |
135 |
global $gallery_dir; |
136 |
if ($title = @file_get_contents("$gallery_dir/$galerie/comments/${id}.txt")) { |
137 |
$title = trim(preg_replace('/[\s\n\r]+/', ' ', strip_tags($title))); |
138 |
if (strlen($title) > 80) |
139 |
$title = trim(substr($title, 0, 77)) . "..."; |
140 |
} else
|
141 |
$title = "Photo ${id}"; |
142 |
return $title; |
143 |
} |
144 |
|
145 |
?>
|