/[health_html]/inc/util.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /inc/util.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Tue Oct 16 13:07:03 2001 UTC (22 years, 5 months ago) by ravilov
Branch: MAIN
Changes since 1.8: +2 -1 lines
Added a favicon for IE. Added a new Smarty modifier (js_popup). Fixed the news editor. Other bugfixes.

1 <?php
2 $ME = "http".($HTTPS?"s":"")."://".$HTTP_HOST.$PHP_SELF;
3
4 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 #@unlink($src);
17 }
18
19 function PicSize($pic, $dir = "") {
20 $ret = array(0, 0);
21 if ($pic) {
22 if (!$dir) {
23 global $syspicdir;
24 $dir = $syspicdir;
25 }
26 @$size = GetImageSize("$dir/$pic");
27 $ret = array($size[0], $size[1]);
28 }
29 return $ret;
30 }
31
32 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, $updown = false, $up = false, $down = false, $prikazi = true) {
42 $t = new Smarty();
43 global $section, $section_menu, $section_menu2, $spec, $isMed, $isEdit, $offset;
44 $t->assign("section", $section);
45 $t->assign("section_menu", $section_menu);
46 $t->assign("section_menu2", $section_menu2);
47 $t->assign("spec", $spec);
48 $t->assign("offset", $offset);
49 $t->assign("id", $id);
50 $t->assign("cat", $cat);
51 $t->assign("med", $isMed);
52 $m = "more";
53 if ($cat == "t") $m = "tmore";
54 if ($cat == "w") $m = "wmore";
55 if ($cat == "p") $m = "pmore";
56 $t->assign("m", $m);
57 $t->assign("name", $name);
58 $pos = strpos($more, "?");
59 $t->assign("read", $read && (!$more || ($more && ($pos === false || $pos != 0))) ? $read : "");
60 $t->assign("more", /* $more */ strstr($more, "?") ? $more : "");
61 $t->assign("more_new", strstr($more, "://") ? true : false);
62 $t->assign("more_title", $more_title);
63 $t->assign("edit", $isEdit);
64 $t->assign("updown", $updown);
65 $t->assign("up", $up);
66 $t->assign("down", $down);
67 $t->assign("prikazi", $prikazi);
68 return $t->fetch("links.tpl");
69 }
70
71 function GetRead($id, $ct = "") {
72 global $section, $section_menu, $section_menu2, $spec, $offset, $cat, $acat, $acat2;
73 $tmp = array();
74 if ($section) array_push($tmp, "section=$section");
75 if ($section_menu) array_push($tmp, "section_menu=$section_menu");
76 if ($section_menu2) array_push($tmp, "section_menu=$section_menu2");
77 if ($spec) array_push($tmp, "spec=$spec");
78 if ($offset) array_push($tmp, "offset=$offset");
79 if ($acat) array_push($tmp, "acat=$acat");
80 if ($acat2) array_push($tmp, "acat2=$acat2");
81 if (!$ct) $ct = $cat;
82 if ($ct) array_push($tmp, "cat=$ct");
83 array_push($tmp, "id=$id");
84 array_push($tmp, "show=1");
85 return "?".HTMLSpecialChars(implode("&", $tmp));
86 }
87
88 function GetHighlight($hl) {
89 $tp = new Smarty();
90 $tp->assign("hl", $hl);
91 return $tp->fetch("highlight.tpl");
92 }
93
94 function GetAuthor($pic = "", $alt = "", $info = "", $width = 0, $height = 0) {
95 $t = new Smarty();
96 global $aupicdir;
97 $t->assign("aupicdir", "$aupicdir/");
98 $t->assign("url", $pic);
99 $t->assign("alt", $alt);
100 $t->assign("info", nl2br($info));
101 $t->assign("width", $width);
102 $t->assign("height", $hight);
103 return $t->fetch("author.tpl");
104 }
105
106 function GetSemafor() {
107 global $dbh;
108 $conn = $dbh ? true : false;
109 if (!$conn) include("inc/conn.php");
110 $sql = "SELECT stanje, trave, korov, stabla, date FROM semafor ORDER BY date DESC LIMIT 1";
111 $sth = $dbh->prepare($sql);
112 if (!$sth) error("Cannot prepare query: \"$sql\"");
113 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
114 $row = $sth->fetchrow_array();
115 $sth->finish();
116 if (!$conn) $dbh->disconnect();
117 $t = new Smarty();
118 if ($row) {
119 list($stanje, $trave, $korov, $stabla, $date) = $row;
120 $t->assign("stabla", $stabla);
121 $t->assign("trave", $trave);
122 $t->assign("korov", $korov);
123 $t->assign("msg", $stanje);
124 $t->assign("date", $date ? strftime("%d.%m.%y.", strtotime($date)) : "");
125 }
126 return $t->fetch("semafor-table.tpl");
127 }
128
129 function GenerateUsername($ime, $prezime) {
130 global $dbh;
131 $replace_from = "¹šðè澞©ŠÐÈÆ®Ž ";
132 $replace_to = "ssdcczzSSDCCZZ_";
133 $ime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
134 strtr($ime, $replace_from, $replace_to)));
135 $prezime = strtolower(ereg_replace('[^A-Za-z0-9]', "",
136 strtr($prezime, $replace_from, $replace_to)));
137 $cnt = 1;
138 while ($cnt <= strlen($ime)) {
139 $username = substr($ime, 0, $cnt++).$prezime;
140 $sql = "SELECT username FROM users WHERE username = '$username'";
141 $sth = $dbh->prepare($sql);
142 if (!$sth) error("Cannot prepare query: \"$sql\"");
143 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
144 $row = $sth->fetchrow_array();
145 $sth->finish();
146 if (!$row) break;
147 }
148 if ($cnt > strlen($ime)) {
149 $username2 = $username;
150 $cnt = 1;
151 while (true) {
152 $username = $username.($cnt++);
153 $sql = "SELECT username FROM users WHERE username = '$username'";
154 $sth = $dbh->prepare($sql);
155 if (!$sth) error("Cannot prepare query: \"$sql\"");
156 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
157 $row = $sth->fetchrow_array();
158 $sth->finish();
159 if (!$row) break;
160 }
161 }
162 return $username;
163 }
164
165 function GeneratePassword($length = 8) {
166 $chars = preg_split('//', "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
167 array_shift($chars);
168 array_pop($chars);
169 $password = "";
170 for ($i = 0; $i < $length; $i++) $password .= $chars[rand(0, count($chars))];
171 return $password;
172 }
173
174 $isEdit = stristr($ME, "/edit/") ? true : false;
175 $isMed = stristr($ME, "med") || stristr($ME, "pm") ? true : false;
176
177 function Auth($user = "", $pwd = "") {
178 global $ME,$HTTP_USER_AGENT,$REMOTE_ADDR;
179 global $isEdit;
180 if ($isEdit) return 0;
181 // DEBUG:
182 #if (stristr($ME, "test.plivamed.net")) return 0;
183 // User-Agent: should be mnoGoSearch, but in version 3.1.19
184 // it's UdmSearch so we match just search
185 if (strstr($HTTP_USER_AGENT, "Search") && strstr($REMOTE_ADDR, "10.254.1.")) return 0;
186 global $PMusername, $PMpassword;
187 if (!$user) $user = $PMusername;
188 if (!$pwd) $pwd = $PMpassword;
189 if (!$user) return 1;
190 global $dbh;
191 $connected = $dbh ? true : false;
192 if (!$connected) include("inc/conn.php");
193 $sql = "SELECT username, password FROM users WHERE (username = '$user')";
194 $sth = $dbh->prepare($sql);
195 if (!$sth) return 4;
196 if (!$sth->execute()) return 5;
197 $row = $sth->fetchrow_array();
198 $sth->finish();
199 if (!$connected) $dbh->disconnect();
200 list($u, $p) = $row;
201 if ($u != $user) return 2;
202 if ($p != $pwd) return 3;
203 return 0;
204 }
205
206 Header("Content-Type: text/html; charset=ISO-8859-2");
207 /*
208 if ($isEdit) {
209 if ($PHP_AUTH_USER != "editor" && $PHP_AUTH_PW != "jokkvpr") {
210 Header("WWW-Authenticate: Basic realm=\"PLIVA".($isMed?"med.net":"zdravlje.hr")."\"");
211 Header("HTTP/1.0 401 Unauthorized");
212 echo "Sorry, you are not allowed to edit the site.\n";
213 exit;
214 }
215 }
216 */
217 $isReg = $isMed ? false : true;
218 if (!$isReg) $isReg = (Auth() == 0) ? true : false;
219 ?>

  ViewVC Help
Powered by ViewVC 1.1.26