/[corp_html]/mnogo/template.inc
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 /mnogo/template.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Mar 27 16:00:18 2002 UTC (17 years, 6 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
*** empty log message ***

1 <?
2
3 $templates=array();
4
5 // -----------------------------------------------
6 // load_file()
7 // -----------------------------------------------
8 function load_file($file){
9 if (!($fp=fopen($file, 'r'))){
10 echo "Can't open template file $template_file";
11 exit_local(1);
12 }
13
14 while(!feof($fp)) {
15 $str.=fgets($fp, 1024);
16 }
17
18 fclose($fp);
19
20 return $str;
21 }
22
23 // -----------------------------------------------
24 // read_template()
25 // -----------------------------------------------
26 function read_template(){
27 global $Randoms;
28 global $template_file;
29 global $templates;
30 global $ps, $np, $ul, $ue, $o, $tag, $m, $cat;
31 global $dt, $dp, $dx, $dm, $dy, $dd, $db, $de;
32 global $clones,$lang;
33 global $affix_file;
34 global $spell_file;
35
36 $affix_file=array();
37 $spell_file=array();
38
39 $names=array('top', 'bottom', 'restop', 'resbot', 'navigator',
40 'res', 'ftpres', 'httpres', 'notfound', 'error', 'variables', 'clone',
41 'navleft_nop', 'navright_nop',
42 'navleft', 'navbar1', 'navbar0', 'navright', 'noquery' );
43
44 $where='';
45
46 if (!($fp=fopen($template_file, 'r'))){
47 echo "Can't open template file $template_file";
48 exit_local(1);
49 } do {
50 $str=fgets($fp, 1024);
51
52 if (preg_match('/value="(.*)"[\s\t]+selected="\$ps"/i',$str,$param)) {
53 if (($param[1]) == $ps) {
54 $str=preg_replace('/selected="\$ps"/i',"selected",$str);
55 } else {
56 $str=preg_replace('/selected="\$ps"/i',"",$str);
57 }
58 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$ul"/i',$str,$param)) {
59 if (($param[1]) == $ul) {
60 $str=preg_replace('/selected="\$ul"/i',"selected",$str);
61 } else {
62 $str=preg_replace('/selected="\$ul"/i',"",$str);
63 }
64 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$ue"/i',$str,$param)) {
65 if (($param[1]) == $ue) {
66 $str=preg_replace('/selected="\$ue"/i',"selected",$str);
67 } else {
68 $str=preg_replace('/selected="\$ue"/i',"",$str);
69 }
70 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$lang"/i',$str,$param)) {
71 if (($param[1]) == $lang) {
72 $str=preg_replace('/selected="\$lang"/i',"selected",$str);
73 } else {
74 $str=preg_replace('/selected="\$lang"/i',"",$str);
75 }
76 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$o"/i',$str,$param)) {
77 if (($param[1]) == $o) {
78 $str=preg_replace('/selected="\$o"/i',"selected",$str);
79 } else {
80 $str=preg_replace('/selected="\$o"/i',"",$str);
81 }
82 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$m"/i',$str,$param)) {
83 if (($param[1]) == $m) {
84 $str=preg_replace('/selected="\$m"/i',"selected",$str);
85 } else {
86 $str=preg_replace('/selected="\$m"/i',"",$str);
87 }
88 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$g"/i',$str,$param)) {
89 if (($param[1]) == $tag) {
90 $str=preg_replace('/selected="\$g"/i',"selected",$str);
91 } else {
92 $str=preg_replace('/selected="\$g"/i',"",$str);
93 }
94 } elseif (preg_match('/type=radio[\s\t]+name="dt"[\s\t]+value="(.*)"/i',$str,$param)) {
95 if (($param[1]) == $dt) {
96 $str=preg_replace("/value=\"$dt\"/i","value=\"$dt\" checked",$str);
97 } else {
98 $str=preg_replace('/checked/i',"",$str);
99 }
100 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dp"/i',$str,$param)) {
101 if (($param[1]) == $dp) {
102 $str=preg_replace('/selected="\$dp"/i',"selected",$str);
103 } else {
104 $str=preg_replace('/selected="\$dp"/i',"",$str);
105 }
106 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dx"/i',$str,$param)) {
107 if (($param[1]) == $dx) {
108 $str=preg_replace('/selected="\$dx"/i',"selected",$str);
109 } else {
110 $str=preg_replace('/selected="\$dx"/i',"",$str);
111 }
112 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dm"/i',$str,$param)) {
113 if (($param[1]) == $dm) {
114 $str=preg_replace('/selected="\$dm"/i',"selected",$str);
115 } else {
116 $str=preg_replace('/selected="\$dm"/i',"",$str);
117 }
118 } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dy"/i',$str,$param)) {
119 if (($param[1]) == $dy) {
120 $str=preg_replace('/selected="\$dy"/i',"selected",$str);
121 } else {
122 $str=preg_replace('/selected="\$dy"/i',"",$str);
123 }
124 }
125
126 if (preg_match('/\$g\((\d*)\)/i',$str,$param)) {
127 $str=str_replace("\$g($param[1])",substr($tag,0,strlen($tag)-$param[1]),$str);
128 }
129
130 $str=str_replace("\$g",$tag,$str);
131 $str=str_replace("\$ul",$ul,$str);
132 $str=str_replace("\$ue",$ue,$str);
133 $str=str_replace("\$lang",$lang,$str);
134 $str=str_replace("\$ps",$ps,$str);
135 $str=str_replace("\$o",$o,$str);
136 $str=str_replace("\$m",$m,$str);
137 $str=str_replace("\$s",$s,$str);
138 $str=str_replace("\$pn",$ps*$np,$str);
139 $str=str_replace("\$dd",$dd,$str);
140 $str=str_replace("\$dy",$dy,$str);
141 $str=str_replace("\$dm",$dm,$str);
142 $str=str_replace("\$db",$db,$str);
143 $str=str_replace("\$de",$de,$str);
144 $str=str_replace("\$cat",$cat,$str);
145
146 if (preg_match('/\$IF\s?\((.+)\)/i',$str,$param)) {
147 $param[1]=trim($param[1]);
148 $str=preg_replace('/\$IF\s?\((.+)\)/i',load_file($param[1]),$str);
149 }
150
151 $comment_flag=0;
152
153 if (substr($str, 0, 4) == "<!--") {
154 reset($names);
155 while ($name=current($names)){
156 if (strstr($str, "<!--$name")){
157 $where=$name;
158
159 $templates["$where"][] = '';
160
161 $comment_flag=1;
162 break;
163 } elseif (strstr($str, "/$name-->")) {
164 $where='';
165 $comment_flag=1;
166 break;
167 }
168 next($names);
169 }
170 }
171
172 if ($comment_flag) continue;
173
174 if ($where=='variables') {
175 if (ereg("^#",$str)) continue;
176
177 if (preg_match("/^([^\s\t]+)[\s\t]+(.+)/",$str,$param)) {
178 $var=$param[1];
179 $value=$param[2];
180 $var=strtolower($var);
181
182 $var=trim($var);
183 $value=trim($value);
184
185 if ($var=='affix') {
186 if (preg_match("/([^\s\t]+)[\s\t]+(.+)/",$value,$param)) {
187 $lang=trim($param[1]);
188 $file=trim($param[2]);
189
190 $affix_file[$lang]=$file;
191 }
192 } elseif ($var=='spell') {
193 if (preg_match("/([^\s\t]+)[\s\t]+(.+)/",$value,$param)) {
194 $lang=trim($param[1]);
195 $file=trim($param[2]);
196
197 $spell_file[$lang][]=$file;
198 }
199 } elseif ($var=='r') {
200 $rand=0+substr($var,1);
201 $frand=rand();
202 $frand=$frand/getrandmax()*$value;
203 $Randoms[$rand]=floor($frand);
204 } else {
205 $GLOBALS["$var"]="$value";
206 }
207 }
208 }
209 else
210 if ($where!=''){
211 $templates["$where"][count($templates["$where"])-1] .= $str;
212 }
213
214 } while (!feof($fp));
215
216 fclose($fp);
217 }
218
219 // -----------------------------------------------
220 // print_template($t,$echo=1)
221 // -----------------------------------------------
222 function print_template($t,$echo=1){
223 global $templates;
224 global $from, $to, $found, $query_orig, $error, $self;
225 global $nav, $wordsinfo;
226 global $url, $ue, $o, $cs, $cp;
227 global $clones;
228 global $title, $rating, $desc, $contype, $lastmod, $docsize, $ndoc;
229 global $keyw, $text, $category;
230 global $crc, $Randoms, $rec_id, $DEBUG;
231 global $soundex_suggestions, $lang_url_translation;
232
233 global $last_mod_field;
234 global $crc_field;
235 global $db_format;
236 global $micro_start;
237
238 $from1=$from+1;
239
240 $str=$templates["$t"][$o];
241 if ($str == '') $str=$templates["$t"][0];
242
243 $str=ereg_replace('\$f', "$from1", $str);
244 $str=ereg_replace('\$l', "$to", $str);
245 $str=ereg_replace('\$t', "$found", $str);
246 $str=ereg_replace('\$A', $self, $str);
247
248 $str=ereg_replace('\$Q', HtmlSpecialChars(StripSlashes($query_orig)), $str);
249 $str=ereg_replace('\$q', urlencode($query_orig), $str);
250 $str=eregi_replace('\$UE', $ue, $str);
251
252 $str=ereg_replace('\$E', $error, $str);
253 $str=ereg_replace('\$W', $wordsinfo, $str);
254
255 $str=ereg_replace('\$V', $nav, $str);
256
257 if ($lang_url_translation == 'yes') {
258 $nolangurl = ereg_replace("\.[a-z]{2}\.[a-z]{2,4}$", "", $url);
259 $str=ereg_replace('\$DU', $nolangurl, $str);
260 } else {
261 $str=ereg_replace('\$DU', $url, $str);
262 }
263
264 $str=ereg_replace('\$DT', $title, $str);
265 $str=ereg_replace('\$DR', "$rating", $str);
266 $str=ereg_replace('\$DX', $text, $str);
267 $str=ereg_replace('\$DE', ($desc != '')?$desc:$text, $str);
268 $str=ereg_replace('\$DC', $contype, $str);
269 $str=ereg_replace('\$DM', $lastmod, $str);
270 $str=ereg_replace('\$DS', "$docsize", $str);
271 $str=ereg_replace('\$DN', "$ndoc", $str);
272 $str=ereg_replace('\$DD', $desc, $str);
273 $str=ereg_replace('\$DK', $keyw, $str);
274 $str=ereg_replace('\$CS', $cs, $str);
275 $str=ereg_replace('\$CP', $cp, $str);
276 $str=ereg_replace('\$SearchTime', (round(((get_micro_time()-$micro_start)*100))/100).'s', $str);
277 $str=ereg_replace('\$SDX', $soundex_suggestions, $str);
278
279 if ($db_format == '3.1') {
280 if (ereg('\$DY',$str)) $temp_cp=load_cp($category);
281 } else {
282 $temp_cp='';
283 }
284
285 $str=ereg_replace('\$DY', $temp_cp, $str);
286
287 if (eregi('\$ndocs*',$str)) {
288 $str=eregi_replace('\$ndocs*', get_doc_count(), $str);
289 }
290
291 $sub=$str;
292 while($sub=strstr($sub,'$r')){
293 $sub=substr($sub,2);
294 $pos=0;
295 $num='';
296
297 while(($sub[$pos]>='0')&&($sub[$pos]<='9')){
298 $num.=$sub[$pos++];
299 }
300
301 $str=ereg_replace('\$r'.$num, ''.$Randoms[$num], $str);
302 }
303
304 if (strstr($str,'$CL')&&($t=='res')) {
305 if (strtolower($clones) == 'no') {
306 $str=ereg_replace('\$CL', '', $str);
307 } elseif ($crc<>'') {
308 $myurl=$url;
309 $myct=$contype;
310 $mylm=$lastmod;
311
312 $query="SELECT url,
313 content_type,
314 $last_mod_field
315 FROM url
316 WHERE $crc_field='$crc'
317 AND status=200
318 AND rec_id<>'$rec_id'";
319
320 if($DEBUG) echo "print_template(): ",$query,"<BR><HR>";
321
322 if(!($res=db_query($query))) print_error_local('Query error:'.$query."\n<BR>".db_error());
323
324 while($row=db_fetchrow($res)){
325 $url=$row[0];
326 $contype=$row[1];
327 $lastmod=format_lastmod($row[2]);
328
329 $clon.=print_template('clone',0);
330 }
331
332 db_freeresult($res);
333 $url=$myurl;$contype=$myct;$lastmod=$mylm;
334 }
335 $str=ereg_replace('\$CL', $clon, $str);
336 }
337
338 // if($echo) echo $str; else return $str;
339 global $mnogo_output;
340 if ($echo) $mnogo_output.=$str; else return $str;
341 }
342
343 // -----------------------------------------------
344 // make_nav($query_orig)
345 // -----------------------------------------------
346 function make_nav($query_orig){
347 global $found,$np,$isnext,$ps,$tag,$ul,$ue,$self,$o,$m,$cat;
348 global $dt, $dp, $dx, $dm, $dy, $dd, $db, $de, $lang;
349 global $q_local,$ul_local,$ue_local,$t_local,$db_local,$de_local,$lang_local;
350
351 if($np>0){
352 $prevp=$np-1;
353 $prev_href="$self?q=$q_local&np=$prevp&m=$m".
354 ($ps==20?'':"&ps=$ps").
355 ($tag==''?'':"&t=$t_local").
356 ($ul==''?'':"&ul=$ul_local").
357 ($ue==''?'':"&ue=$ue_local").
358 (!$o?'':"&o=$o").
359 ($dt=='back'?'':"&dt=$dt").
360 (!$dp?'':"&dp=$dp").
361 (!$dx?'':"&dx=$dx").
362 ($dd=='01'?'':"&dd=$dd").
363 (!$dm?'':"&dm=$dm").
364 ($dy=='1970'?'':"&dy=$dy").
365 ($db=='01/01/1970'?'':"&db=$db_local").
366 ($de=='31/12/2020'?'':"&de=$de_local").
367 ($cat==''?'':"&cat=$cat").
368 ($lang==''?'':"&lang=$lang_local");
369
370 $nav_left=print_template('navleft',0);
371 $nav_left=ereg_replace('\$NH',"$prev_href",$nav_left);
372 } elseif ($np==0) {
373 $nav_left=print_template('navleft_nop',0);
374 }
375
376 if($isnext==1) {
377 $nextp=$np+1;
378 $next_href="$self?q=$q_local&np=$nextp&m=$m".
379 ($ps==20?'':"&ps=$ps").
380 ($tag==''?'':"&t=$t_local").
381 ($ul==''?'':"&ul=$ul_local").
382 ($ue==''?'':"&ue=$ue_local").
383 (!$o?'':"&o=$o").
384 ($dt=='back'?'':"&dt=$dt").
385 (!$dp?'':"&dp=$dp").
386 (!$dx?'':"&dx=$dx").
387 ($dd=='01'?'':"&dd=$dd").
388 (!$dm?'':"&dm=$dm").
389 ($dy=='1970'?'':"&dy=$dy").
390 ($db=='01/01/1970'?'':"&db=$db_local").
391 ($de=='31/12/2020'?'':"&de=$de_local").
392 ($cat==''?'':"&cat=$cat").
393 ($lang==''?'':"&lang=$lang_local");
394
395 $nav_right=print_template('navright',0);
396 $nav_right=ereg_replace('\$NH',"$next_href",$nav_right);
397 } else {
398 $nav_right=print_template('navright_nop',0);
399 }
400
401 $nav_bar0=print_template('navbar0',0);
402 $nav_bar1=print_template('navbar1',0);
403
404 $tp=ceil($found/$ps);
405
406 $cp=$np+1;
407
408 if ($cp>5) {
409 $lp=$cp-5;
410 } else {
411 $lp=1;
412 }
413
414 $rp=$lp+10-1;
415 if ($rp>$tp) {
416 $rp=$tp;
417 $lp=$rp-10+1;
418 if ($lp<1) $lp=1;
419 }
420
421
422 if ($lp!=$rp) {
423 for ($i=$lp; $i<=$rp;$i++) {
424 $realp=$i-1;
425
426 if ($i==$cp) {
427 $nav_bar=$nav_bar.$nav_bar0;
428 } else {
429 $nav_bar=$nav_bar.$nav_bar1;
430 }
431
432 $href="$self?q=$q_local&np=$realp&m=$m".
433 ($ps==20?'':"&ps=$ps").
434 ($tag==''?'':"&t=$t_local").
435 ($ul==''?'':"&ul=$ul_local").
436 ($ue==''?'':"&ue=$ue_local").
437 (!$o?'':"&o=$o").
438 ($dt=='back'?'':"&dt=$dt").
439 (!$dp?'':"&dp=$dp").
440 (!$dx?'':"&dx=$dx").
441 ($dd=='01'?'':"&dd=$dd").
442 (!$dm?'':"&dm=$dm").
443 ($dy=='1970'?'':"&dy=$dy").
444 ($db=='01/01/1970'?'':"&db=$db_local").
445 ($de=='31/12/2020'?'':"&de=$de_local").
446 ($cat==''?'':"&cat=$cat").
447 ($lang==''?'':"&lang=$lang_local");
448
449 $nav_bar=ereg_replace('\$NP',"$i",$nav_bar);
450 $nav_bar=ereg_replace('\$NH',"$href",$nav_bar);
451 }
452
453 $nav=print_template('navigator',0);
454 $nav=ereg_replace('\$NL',"$nav_left",$nav);
455 $nav=ereg_replace('\$NR',"$nav_right",$nav);
456 $nav=ereg_replace('\$NB',"$nav_bar",$nav);
457
458 } elseif ($found) {
459 $nav=print_template('navigator',0);
460 $nav=ereg_replace('\$NL',"$nav_left",$nav);
461 $nav=ereg_replace('\$NR',"$nav_right",$nav);
462 $nav=ereg_replace('\$NB',"",$nav);
463 }
464
465 return $nav;
466 }
467
468 ?>

  ViewVC Help
Powered by ViewVC 1.1.26