1 |
<?php |
2 |
|
3 |
//----------------------------------------- |
4 |
// Custom made by Dobrica Pavlinusic <dpavlin@rot13.org> |
5 |
|
6 |
// helper function to make full path of relative dir |
7 |
function dir2path($dir) { |
8 |
if (substr($dir,0,1) != "/") { |
9 |
return dirname($GLOBALS[SCRIPT_FILENAME])."/$dir"; |
10 |
} else { |
11 |
return $dir; |
12 |
} |
13 |
} |
14 |
|
15 |
function smarty_func_img() { |
16 |
extract(func_get_arg(0)); |
17 |
|
18 |
$f=Array(); |
19 |
|
20 |
global $img_time; |
21 |
if (!isset($img_time)) { |
22 |
$img_time=time(); |
23 |
} |
24 |
|
25 |
|
26 |
if (isset($dir)) { |
27 |
$tdir=dir2path($dir); |
28 |
$h=opendir($dir); |
29 |
$pics=0; |
30 |
while ($tmp = readdir($h)) { |
31 |
if (is_file("$tdir/$tmp") && substr($tmp,0,1)!=".") { |
32 |
// print "$tdir/$tmp<br>\n"; |
33 |
$f[]=$tmp; |
34 |
$pics++; |
35 |
} |
36 |
} |
37 |
closedir($h); |
38 |
// $f=shuffle($f); |
39 |
$ord=($img_time+$nr) % $pics; |
40 |
$src="$dir/$f[$ord]"; |
41 |
} |
42 |
|
43 |
$add=""; |
44 |
if (isset($border)) { |
45 |
$add.=" border=\"$border\""; |
46 |
} |
47 |
if (isset($alt)) { |
48 |
$add.=" alt=\"$alt\""; |
49 |
} |
50 |
if (isset($align)) { |
51 |
$add.=" align=\"$align\""; |
52 |
} |
53 |
if (isset($hspace)) { |
54 |
$add.=" hspace=\"$hspace\""; |
55 |
} |
56 |
if (isset($vspace)) { |
57 |
$add.=" vspace=\"$vspace\""; |
58 |
} |
59 |
|
60 |
$out=""; |
61 |
$product_link = array ( |
62 |
"andol.gif"=>"http://www.pliva.hr/human_health.php?search=andol&show_description=on#results", |
63 |
"andol_c.jpg"=>"http://www.pliva.hr/human_health.php?search=andol%25c&show_description=on#results", |
64 |
"bisolex.jpg"=>"http://www.pliva.hr/human_health.php?search=bisolex&show_description=on#results", |
65 |
"plibex.gif"=>"http://www.pliva.hr/human_health.php?search=plibex&show_description=on#results", |
66 |
"plivit_b.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25b&show_description=on#results", |
67 |
"plivit_b6.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25b6&show_description=on#results", |
68 |
"plivit_c.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25c&show_description=on#results", |
69 |
"plivazdravlje.gif"=>"http://www.plivazdravlje.hr/", |
70 |
"plivamed.gif"=>"http://www.plivamed.net/", |
71 |
); |
72 |
|
73 |
$pic=basename($src); |
74 |
if ($product_link[$pic]) { |
75 |
$out.="<a href=\"$product_link[$pic]\">"; |
76 |
$add.=" border=\"0\""; |
77 |
} |
78 |
|
79 |
$size = GetImageSize(dir2path($src)); |
80 |
$out.="<img src=\"$src\" $size[3]$add>"; |
81 |
if ($product_link[$pic]) { |
82 |
$out.="</a>"; |
83 |
} |
84 |
print $out; |
85 |
} |
86 |
|
87 |
// checkboxes |
88 |
|
89 |
function smarty_func_html_checkboxes() |
90 |
{ |
91 |
$print_result = true; |
92 |
|
93 |
extract(func_get_arg(0)); |
94 |
|
95 |
settype($output, 'array'); |
96 |
settype($values, 'array'); |
97 |
|
98 |
$html_result = ""; |
99 |
|
100 |
for ($i = 0; $i < count($output); $i++) { |
101 |
/* By default, check value against $selected */ |
102 |
$sel_check = $values[$i]; |
103 |
if (isset($before)) $html_result.=$before; |
104 |
$html_result .= "<input type=checkbox name=\"".$values[$i]."\""; |
105 |
if (isset($GLOBALS[$values[$i]])) { |
106 |
$html_result .= " checked"; |
107 |
} |
108 |
$html_result .= ">".$output[$i]."\n"; |
109 |
if (isset($after)) $html_result.=$after; |
110 |
} |
111 |
|
112 |
if ($print_result) |
113 |
print $html_result; |
114 |
else |
115 |
return $html_result; |
116 |
} |
117 |
|
118 |
// $filename|filesize:"dir":"unit" |
119 |
// |
120 |
// dir -- path to file (or "") |
121 |
// unit -- Mb|Kb|auto |
122 |
|
123 |
function smarty_mod_filesize($file,$dir,$unit="") |
124 |
{ |
125 |
$path=dir2path("$dir/$file"); |
126 |
$ext=explode(".",$file); |
127 |
$ext=strtoupper(array_pop($ext)); |
128 |
|
129 |
if ($size=filesize($path)) { |
130 |
switch ($unit) { |
131 |
case 'Mb': |
132 |
case 'mb': |
133 |
return sprintf("%s, %2.1f Mb",$ext,$size/(1024*1024)); |
134 |
case 'Kb': |
135 |
case 'kb': |
136 |
return sprintf("%s, %2.1f Mb",$ext,$size/1024); |
137 |
case 'auto': |
138 |
$size=$size/1024; # Kb |
139 |
if ($size > 1024) { |
140 |
return sprintf("%s, %2.1f Mb",$ext,$size/1024); |
141 |
} else { |
142 |
return sprintf("%s, %2.1f Kb",$ext,$size); |
143 |
} |
144 |
|
145 |
} |
146 |
return $size; |
147 |
} |
148 |
} |
149 |
|
150 |
// input functions (input, rinput) |
151 |
|
152 |
function smarty_func_input() { |
153 |
extract(func_get_arg(0)); |
154 |
if (strtolower($type) == "radio") { |
155 |
print "<input name=\"$name\" type=\"radio\" value=\"$value\""; |
156 |
if ($GLOBALS[$name] == $value) print " checked"; |
157 |
print ">"; |
158 |
} else { |
159 |
print "<input name=\"$name\" size=\"$size\" value=\"".$GLOBALS[$name]."\">"; |
160 |
} |
161 |
if ($type) print "<input type=\"hidden\" name=\"inputs_required_type[$name]\" value=\"$type\">"; |
162 |
} |
163 |
|
164 |
function smarty_func_textarea() { |
165 |
extract(func_get_arg(0)); |
166 |
print "<textarea name=\"$name\" cols=\"$cols\" rows=\"$rows\">".$GLOBALS[$name]."</textarea>"; |
167 |
} |
168 |
|
169 |
function smarty_func_rinput() { |
170 |
extract(func_get_arg(0)); |
171 |
global $inputs_required_type; |
172 |
$ok=1; |
173 |
if (! isset($GLOBALS[$name]) || $GLOBALS[$name] == "") { |
174 |
$ok=0; |
175 |
} else { |
176 |
switch($inputs_required_type[$name]) { |
177 |
case 'email': |
178 |
if (!strstr($GLOBALS[$name],'@')) $ok=0; |
179 |
} |
180 |
} |
181 |
if ($ok) { |
182 |
print "$desc"; |
183 |
} else { |
184 |
print "<b>$desc</b>"; |
185 |
} |
186 |
print "<input type=\"hidden\" name=\"inputs_required[]\" value=\"$name\">"; |
187 |
} |
188 |
|
189 |
// not strictly smarty, but it should be here and not in common.inc |
190 |
|
191 |
function check_required() { |
192 |
global $inputs_required; |
193 |
global $inputs_required_type; |
194 |
$ok=1; |
195 |
if (isset($inputs_required)) { |
196 |
foreach ($inputs_required as $i) { |
197 |
if (! isset($GLOBALS[$i]) || $GLOBALS[$i] == "") $ok=0; |
198 |
switch (strtolower($inputs_required_type[$i])) { |
199 |
case 'email': |
200 |
if (!strstr($GLOBALS[$i],'@')) $ok=0; |
201 |
} |
202 |
// print "$i: $GLOBALS[$i] type: $inputs_required_type[$i] $ok -- "; |
203 |
|
204 |
} |
205 |
} else { |
206 |
print "<!-- no inputs required -->"; |
207 |
} |
208 |
return $ok; |
209 |
} |
210 |
|
211 |
?> |