📄 template.inc
字号:
<?php/** * This is a library of functions to act on the template HTML file. * The functions declared here mainly read the template and write the * result output using this template. * Modified version - the PHP extension must be higher than 3.2.32 and PHP must be higher than 4.2 *//** * Initialise arrays */$templates=array();/** * Reads the template file given and returns a string. * Similar to the file_get_contents() function but using a loop to read by chunks * of 1024 bytes. * @param string Filename * @return string File contents */function load_file($file){ if (!($fp=fopen($file, 'r'))){ echo "Can't open template file $template_file"; exit_local(1); } while(!feof($fp)) { $str.=fgets($fp, 1024); } fclose($fp); return $str;}/** * Build the navigation bar * @param string Original query ? - not used anyway * @return string Navigation bar string */function make_nav($query_orig=''){ global $found,$np,$isnext,$ps,$tag,$ul,$ul_arr,$self,$o,$m,$cat,$cat_arr; global $dt, $dp, $dx, $dm, $dy, $dd, $db, $de, $lang, $wm, $wf, $site, $sp, $sy; global $q_local,$db_local,$de_local,$lang_arr, $tag, $tag_arr, $type, $type_arr; $temp_ul=''; for($i=0; $i<count($ul_arr); $i++) { $temp_ul.="&ul=".urlencode($ul_arr[$i]); } $temp_tag=''; for($i=0; $i<count($tag_arr); $i++) { $temp_tag.="&tag=".urlencode($tag_arr[$i]); } $temp_lang=''; for($i=0; $i<count($lang_arr); $i++) { $temp_lang.="&lang=".urlencode($lang_arr[$i]); } $temp_cat=''; for($i=0; $i<count($cat_arr); $i++) { $temp_cat.="&cat=".urlencode($cat_arr[$i]); } $temp_type=''; for($i=0; $i<count($type_arr); $i++) { $temp_type.="&type=".urlencode($type_arr[$i]); } if($np>0){ $prevp=$np-1; $prev_href="$self?q=$q_local&np=$prevp&m=$m". ($ps==20?'':"&ps=$ps"). $temp_tag. $temp_ul. $temp_cat. $temp_lang. ($site==''?'':"&site=$site"). ($wm==''?'':"&wm=$wm"). ($wf==''?'':"&wf=$wf"). (!$o?'':"&o=$o"). ($dt=='back'?'':"&dt=$dt"). (!$dp?'':"&dp=$dp"). (!$dx?'':"&dx=$dx"). ($dd=='01'?'':"&dd=$dd"). (!$dm?'':"&dm=$dm"). ($dy=='1970'?'':"&dy=$dy"). ($db=='01/01/1970'?'':"&db=$db_local"). ($de=='31/12/2020'?'':"&de=$de_local"). ($sp==''?'':"&sp=$sp"). ($sy==''?'':"&sy=$sy"); $nav_left=print_template('navleft',0); $nav_left=ereg_replace('\$NH',"$prev_href",$nav_left); } elseif ($np==0) { $nav_left=print_template('navleft_nop',0); } if($isnext==1) { $nextp=$np+1; $next_href="$self?q=$q_local&np=$nextp&m=$m". ($ps==20?'':"&ps=$ps"). $temp_tag. $temp_ul. $temp_cat. $temp_lang. ($site==''?'':"&site=$site"). ($wm==''?'':"&wm=$wm"). ($wf==''?'':"&wf=$wf"). (!$o?'':"&o=$o"). ($dt=='back'?'':"&dt=$dt"). (!$dp?'':"&dp=$dp"). (!$dx?'':"&dx=$dx"). ($dd=='01'?'':"&dd=$dd"). (!$dm?'':"&dm=$dm"). ($dy=='1970'?'':"&dy=$dy"). ($db=='01/01/1970'?'':"&db=$db_local"). ($de=='31/12/2020'?'':"&de=$de_local"). ($sp==''?'':"&sp=$sp"). ($sy==''?'':"&sy=$sy"); $nav_right=print_template('navright',0); $nav_right=ereg_replace('\$NH',"$next_href",$nav_right); } else { $nav_right=print_template('navright_nop',0); } $nav_bar0=print_template('navbar0',0); $nav_bar1=print_template('navbar1',0); $tp=ceil($found/$ps); $cp=$np+1; if ($cp>5) { $lp=$cp-5; } else { $lp=1; } $rp=$lp+10-1; if ($rp>$tp) { $rp=$tp; $lp=$rp-10+1; if ($lp<1) $lp=1; } if ($lp!=$rp) { for ($i=$lp; $i<=$rp;$i++) { $realp=$i-1; if ($i==$cp) { $nav_bar=$nav_bar.$nav_bar0; } else { $nav_bar=$nav_bar.$nav_bar1; } $href="$self?q=$q_local&np=$realp&m=$m". ($ps==20?'':"&ps=$ps"). $temp_tag. $temp_ul. $temp_cat. $temp_lang. ($site==''?'':"&site=$site"). ($wm==''?'':"&wm=$wm"). ($wf==''?'':"&wf=$wf"). (!$o?'':"&o=$o"). ($dt=='back'?'':"&dt=$dt"). (!$dp?'':"&dp=$dp"). (!$dx?'':"&dx=$dx"). ($dd=='01'?'':"&dd=$dd"). (!$dm?'':"&dm=$dm"). ($dy=='1970'?'':"&dy=$dy"). ($db=='01/01/1970'?'':"&db=$db_local"). ($de=='31/12/2020'?'':"&de=$de_local"). ($sp==''?'':"&sp=$sp"). ($sy==''?'':"&sy=$sy"); $nav_bar=ereg_replace('\$NP',"$i",$nav_bar); $nav_bar=ereg_replace('\$NH',"$href",$nav_bar); } $nav=print_template('navigator',0); $nav=ereg_replace('\$NL',"$nav_left",$nav); $nav=ereg_replace('\$NR',"$nav_right",$nav); $nav=ereg_replace('\$NB',"$nav_bar",$nav); } elseif ($found) { $nav=print_template('navigator',0); $nav=ereg_replace('\$NL',"$nav_left",$nav); $nav=ereg_replace('\$NR',"$nav_right",$nav); $nav=ereg_replace('\$NB',"",$nav); } return $nav;}/** * Prints the template on screen after substituting a lot of variables * from the global scope * @param string Index of the part of the template we want to use (storedoc_top, storedoc, ...) * @param boolean Whether to echo the results on screen or just return the string * @return mixed Nothing if $echo=1, the resulting string if $echo=false */function print_template($t,$echo=1){ global $templates, $udm_agent; global $first_doc, $last_doc, $found, $query_orig, $error, $self; global $nav, $wordinfo, $ws, $doclang, $doccharset, $storedocurl; global $url, $ue, $o, $cat, $storedstr, $stored_href; global $clonestr, $searchtime, $persite; global $title, $rating, $desc, $contype, $lastmod, $docsize, $ndoc; global $keyw, $text, $category, $pop_rank; global $crc, $Randoms, $rec_id, $DEBUG, $id; global $lang_url_translation, $phpver, $sitelimit_href, $sitelimitstr; global $global_doc_res, $global_res_position; global $last_modified, $content, $charset, $length, $document, $url; $str=$templates["$t"][$o]; if ($str == '') $str=$templates["$t"][0]; //variables as returned by the udm_search() function and defined in search.php $str=ereg_replace('\$f', "$first_doc", $str); $str=ereg_replace('\$l', "$last_doc", $str); $str=ereg_replace('\$t', "$found", $str); $str=ereg_replace('\$A', $self, $str); $str=ereg_replace('\$Q', urlencode(stripslashes($query_orig)), $str); $str=ereg_replace('\$q', urlencode($query_orig), $str); $str=eregi_replace('\$UE', $ue, $str); $str=ereg_replace('\$E', $error, $str); $str=ereg_replace('\$W', htmlspecialchars($wordinfo), $str); $str=ereg_replace('\$\(WS\)', htmlspecialchars($ws), $str); $str=ereg_replace('\$V', $nav, $str); if ($lang_url_translation == 'yes') { $nolangurl = ereg_replace("\.[a-z]{2}\.[a-z]{2,4}$", "", $url); $str=ereg_replace('\$DU', htmlspecialchars($nolangurl), $str); } else { $str=ereg_replace('\$DU', htmlspecialchars($url), $str); } $str=ereg_replace('\$\(stored_href\)', htmlspecialchars($stored_href), $str); $str=ereg_replace('\$\(sitelimit_href\)', htmlspecialchars($sitelimit_href), $str); //require_once('filter_user.functions.php'); //$title = subst_course_code(urldecode(html_entity_decode($title))); $str=ereg_replace('\$DT', htmlspecialchars($title), $str); $str=ereg_replace('\$DR', htmlspecialchars("$rating"), $str); //$text = subst_course_code(html_entity_decode($text)); //Comment out temporarily because breaking XML file (excerpt of Word document with unknown character) $str=ereg_replace('\$DX', htmlspecialchars(urlencode($text)), $str); $str=ereg_replace('\$DE', ($desc != '')?htmlspecialchars(urlencode($desc)):htmlspecialchars(urlencode($text)), $str); $str=ereg_replace('\$DC', $contype, $str); $str=ereg_replace('\$DM', $lastmod, $str); $str=ereg_replace('\$DS', "$docsize", $str); $str=ereg_replace('\$DN', "$ndoc", $str); $str=ereg_replace('\$DD', htmlspecialchars($desc), $str); $str=ereg_replace('\$DK', htmlspecialchars($keyw), $str); $str=ereg_replace('\$SearchTime', "$searchtime", $str); $str=ereg_replace('\$\(STORED\)', htmlspecialchars("$storedstr"), $str); $str=ereg_replace('\$\(SITELIMIT\)', htmlspecialchars("$sitelimitstr"), $str); $str=ereg_replace('\$\(Pop_Rank\)', "$pop_rank", $str); $str=ereg_replace('\$CL', "$clonestr", $str); $str=ereg_replace('\$\(PerSite\)', "$persite", $str); //information on each link (header for one item) if ($t == 'storedoc_top') { $str=ereg_replace('\$\(ID\)', htmlspecialchars("$id"), $str); $str=ereg_replace('\$\(Last-Modified\)', htmlspecialchars("$last_modified"), $str); $str=ereg_replace('\$\(Content-Language\)', htmlspecialchars("$content"), $str); $str=ereg_replace('\$\(Charset\)', htmlspecialchars("$charset"), $str); $str=ereg_replace('\$\(Content-Length\)', "$length", $str); $str=ereg_replace('\$\(URL\)', htmlspecialchars("$url"), $str); } //link to the document if ($t == 'storedoc') { $str=ereg_replace('\$\(document\)', htmlspecialchars("$document"), $str); } //Categories if (ereg('\$CP',$str)) { if ($temp_cp_arr=udm_cat_path($udm_agent,$cat)) { reset($temp_cp_arr); $temp_cp=''; for ($i=0; $i<count($temp_cp_arr); $i+=2) { $cp_path=$temp_cp_arr[$i]; $cp_name=$temp_cp_arr[$i+1]; $temp_cp .= " > <a href=\"$PHP_SELF?cat=$cp_path\">$cp_name</a> "; } $str=ereg_replace('\$CP', $temp_cp, $str); } else $str=ereg_replace('\$CP', '', $str); } //Categories if (ereg('\$CS',$str)) { if ($temp_cp_arr=udm_cat_list($udm_agent,$cat)) { reset($temp_cp_arr); $temp_cp=''; for ($i=0; $i<count($temp_cp_arr); $i+=2) { $cp_path=$temp_cp_arr[$i]; $cp_name=$temp_cp_arr[$i+1]; $temp_cp .= "<a href=\"$PHP_SELF?cat=$cp_path\">$cp_name</a><br>"; } $str=ereg_replace('\$CS', $temp_cp, $str); } else $str=ereg_replace('\$CS', '', $str); } //Categories if (ereg('\$DY',$str)) { if ($temp_cp_arr=udm_cat_path($udm_agent,$category)) { reset($temp_cp_arr); $temp_cp=''; for ($i=0; $i<count($temp_cp_arr); $i+=2) { $cp_path=$temp_cp_arr[$i]; $cp_name=$temp_cp_arr[$i+1]; $temp_cp .= " > <a href=\"$PHP_SELF?cat=$cp_path\">$cp_name</a> "; } $str=ereg_replace('\$DY', $temp_cp, $str); } else $str=ereg_replace('\$DY', '', $str); } //Number of documents if (eregi('\$ndocs*',$str)) { $str=preg_replace('/\$ndocs?/', get_doc_count(), $str); } //document link? if ($global_doc_res) { $str=preg_replace_callback('/\$\(([\w\.\_\-\:]+)\)/', 'res_field_callback', $str); } //Random?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -