1 |
ravilov |
1.1 |
<?php |
2 |
ravilov |
1.4 |
$ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST.$PHP_SELF; |
3 |
|
|
|
4 |
ravilov |
1.1 |
function MyQuote($str) { |
5 |
|
|
global $dbh; |
6 |
|
|
if (!$dbh) return "'$str'"; |
7 |
|
|
return $dbh->quote($str); |
8 |
|
|
} |
9 |
|
|
|
10 |
|
|
function MyMove($src, $dest) { |
11 |
|
|
$cmd = "mv -f '".EscapeShellCmd($src)."' '".EscapeShellCmd($dest)."'"; |
12 |
|
|
return exec($cmd); |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
function MyDelete($src) { |
16 |
ravilov |
1.5 |
#@unlink($src); |
17 |
ravilov |
1.1 |
} |
18 |
|
|
|
19 |
ravilov |
1.2 |
function PicSize($pic, $dir = "") { |
20 |
ravilov |
1.1 |
$ret = array(0, 0); |
21 |
|
|
if ($pic) { |
22 |
ravilov |
1.2 |
if (!$dir) { |
23 |
|
|
global $syspicdir; |
24 |
|
|
$dir = $syspicdir; |
25 |
|
|
} |
26 |
ravilov |
1.3 |
@$size = GetImageSize("$dir/$pic"); |
27 |
ravilov |
1.1 |
$ret = array($size[0], $size[1]); |
28 |
|
|
} |
29 |
|
|
return $ret; |
30 |
|
|
} |
31 |
|
|
|
32 |
ravilov |
1.3 |
function PicResize($w, $h, $maxsize = 80) { |
33 |
|
|
if ($w && $h && $w > $maxsize) { |
34 |
|
|
$ratio = ($w / $h); |
35 |
|
|
$w = intval($maxsize); |
36 |
|
|
$h = intval($w / $ratio); |
37 |
|
|
} |
38 |
|
|
return array($w, $h); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
function GetLinks($read, $more, $more_title, $id, $cat, $name, $edit, $updown = false, $up = false, $down = false) { |
42 |
|
|
$t = new Smarty(); |
43 |
ravilov |
1.5 |
global $section, $section_menu, $section_menu2, $spec, $isMed; |
44 |
ravilov |
1.3 |
$t->assign("section", $section); |
45 |
|
|
$t->assign("section_menu", $section_menu); |
46 |
ravilov |
1.5 |
$t->assign("section_menu2", $section_menu2); |
47 |
ravilov |
1.3 |
$t->assign("spec", $spec); |
48 |
|
|
$t->assign("id", $id); |
49 |
|
|
$t->assign("cat", $cat); |
50 |
ravilov |
1.5 |
$t->assign("med", $isMed); |
51 |
|
|
$m = "more"; |
52 |
|
|
if ($cat == "t") $m = "tmore"; |
53 |
|
|
if ($cat == "w") $m = "wmore"; |
54 |
|
|
if ($cat == "p") $m = "pmore"; |
55 |
|
|
$t->assign("m", $m); |
56 |
ravilov |
1.3 |
$t->assign("name", $name); |
57 |
ravilov |
1.5 |
$t->assign("read", $read || ($more && !strstr($more, "?"))); |
58 |
ravilov |
1.3 |
$t->assign("more", /* $more */ strstr($more, "?") ? $more : ""); |
59 |
|
|
$t->assign("more_new", strstr($more, "://") ? true : false); |
60 |
|
|
$t->assign("more_title", $more_title); |
61 |
|
|
$t->assign("edit", $edit); |
62 |
|
|
$t->assign("updown", $updown); |
63 |
|
|
$t->assign("up", $up); |
64 |
|
|
$t->assign("down", $down); |
65 |
|
|
return $t->fetch("links.tpl"); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
function GetHighlight($hl) { |
69 |
|
|
$tp = new Smarty(); |
70 |
|
|
$tp->assign("hl", $hl); |
71 |
|
|
return $tp->fetch("highlight.tpl"); |
72 |
|
|
} |
73 |
|
|
|
74 |
ravilov |
1.4 |
function GenerateUsername($ime, $prezime) { |
75 |
|
|
global $dbh; |
76 |
|
|
$replace_from = "¹ðè澩ÐÈÆ® "; |
77 |
|
|
$replace_to = "ssdcczzSSDCCZZ_"; |
78 |
|
|
$ime = strtolower(ereg_replace('[^A-Za-z0-9]', "", |
79 |
|
|
strtr($ime, $replace_from, $replace_to))); |
80 |
|
|
$prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "", |
81 |
|
|
strtr($prezime, $replace_from, $replace_to))); |
82 |
|
|
$cnt = 1; |
83 |
|
|
while ($cnt <= strlen($ime)) { |
84 |
|
|
$username = substr($ime, 0, $cnt++).$prezime; |
85 |
|
|
$sql = "SELECT username FROM users WHERE username = '$username'"; |
86 |
|
|
$sth = $dbh->prepare($sql); |
87 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
88 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
89 |
|
|
$row = $sth->fetchrow_array(); |
90 |
|
|
$sth->finish(); |
91 |
|
|
if (!$row) break; |
92 |
|
|
} |
93 |
|
|
if ($cnt > strlen($ime)) { |
94 |
|
|
$username2 = $username; |
95 |
|
|
$cnt = 1; |
96 |
|
|
while (true) { |
97 |
|
|
$username = $username.($cnt++); |
98 |
|
|
$sql = "SELECT username FROM users WHERE username = '$username'"; |
99 |
|
|
$sth = $dbh->prepare($sql); |
100 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
101 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
102 |
|
|
$row = $sth->fetchrow_array(); |
103 |
|
|
$sth->finish(); |
104 |
|
|
if (!$row) break; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
return $username; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
function GeneratePassword($length = 8) { |
111 |
|
|
$chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); |
112 |
|
|
array_shift($chars); |
113 |
|
|
array_pop($chars); |
114 |
|
|
$password = ""; |
115 |
|
|
for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))]; |
116 |
|
|
return $password; |
117 |
|
|
} |
118 |
|
|
|
119 |
ravilov |
1.3 |
function Auth($user = "", $pwd = "") { |
120 |
ravilov |
1.4 |
global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR; |
121 |
|
|
// DEBUG: |
122 |
ravilov |
1.5 |
#if (stristr($ME, "test.plivamed.net")) return 0; |
123 |
ravilov |
1.4 |
// User-Agent: should be mnoGoSearch, but in version 3.1.19 |
124 |
|
|
// it's UdmSearch so we match just search |
125 |
|
|
if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0; |
126 |
ravilov |
1.3 |
global $PMusername, $PMpassword; |
127 |
|
|
if (!$user) $user = $PMusername; |
128 |
|
|
if (!$pwd) $pwd = $PMpassword; |
129 |
|
|
if (!$user) return 1; |
130 |
|
|
global $dbh; |
131 |
|
|
$connected = $dbh ? true : false; |
132 |
|
|
if (!$connected) include("inc/conn.php"); |
133 |
|
|
$sql = "SELECT username, password FROM users WHERE (username = '$user')"; |
134 |
|
|
$sth = $dbh->prepare($sql); |
135 |
|
|
if (!$sth) return 4; |
136 |
|
|
if (!$sth->execute()) return 5; |
137 |
|
|
$row = $sth->fetchrow_array(); |
138 |
|
|
$sth->finish(); |
139 |
|
|
if (!$connected) $dbh->disconnect(); |
140 |
|
|
list($u, $p) = $row; |
141 |
|
|
if ($u != $user) return 2; |
142 |
|
|
if ($p != $pwd) return 3; |
143 |
|
|
return 0; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
Header("Content-Type: text/html; charset=ISO-8859-2"); |
147 |
|
|
$isEdit = stristr($ME, "/edit/") ? true : false; |
148 |
|
|
$isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false; |
149 |
|
|
if ($isEdit) { |
150 |
ravilov |
1.5 |
if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") { |
151 |
ravilov |
1.3 |
Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\""); |
152 |
|
|
Header("HTTP/1.0 401 Unauthorized"); |
153 |
|
|
echo "Sorry, you are not allowed to edit the site.\n"; |
154 |
|
|
exit; |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
$isReg = $isMed ? false : true; |
158 |
|
|
if (!$isReg) $isReg = (Auth() == 0) ? true : false; |
159 |
ravilov |
1.1 |
?> |