⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 template.inc

📁 完美的在线教育系统
💻 INC
📖 第 1 页 / 共 2 页
字号:
    $sub=$str;    while($sub=strstr($sub,'$r')){		$sub=substr($sub,2);		$pos=0;		$num='';				while(($sub[$pos]>='0')&&($sub[$pos]<='9')){			$num.=$sub[$pos++];		}				$str=ereg_replace('\$r'.$num, ''.$Randoms[$num], $str);    }        if($echo) echo $str; else return $str;}/** * Reads the template file. * @param	none	All the parameters are taken as globals, which is very bad. * @return	void	No return value everything is left in global scope */function read_template(){    global $Randoms;    global $template_file; //uri of the file to open    global $templates,$dbaddr;    global $ps, $np, $ul, $ul_arr, $o, $tag, $tag_arr, $m, $cat, $cat_arr, $wm, $wf;    global $dt, $dp, $dx, $dm, $dy, $dd, $db, $de;    global $clones,$lang,$lang_arr, $sp, $sy, $s, $resultslimit;    global $affix_file, $spell_file, $spell_host;    global $stopwordtable_arr, $stopwordfile_arr;    global $synonym_arr, $searchd_arr;    global $alias_arr,$type, $type_arr;        $affix_file=array();    $spell_file=array();    $alias_arr=array();	$dbaddr=array();    $names=array('top', 'bottom', 'restop', 'resbot', 'navigator',				 'res', 'ftpres', 'httpres', 'notfound', 'error', 'variables', 				 'clone', 'navleft_nop', 'navright_nop', 'navleft', 				 'navbar1', 'navbar0', 'navright', 'noquery', 'site_limit', 				 'storedoc_top','storedoc_bottom','storedoc','stored');    $where='';        //First check that the template file is available    if (!($fp=fopen($template_file, 'r'))){		echo "Can't open template file $template_file";		exit_local(1);    } do {    	//The template file is there, read it 		$str=fgets($fp, 1024);		$param = array();        if (preg_match('/value="(.*)"[\s\t]+selected="\$ps"/i',$str,$param)) {      		if (($param[1]) == $ps) {          		$str=preg_replace('/selected="\$ps"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$ps"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$ul"/i',$str,$param)) {  			$found_param=0;  			for($i=0; $i<count($ul_arr); $i++) {				$temp_ul=$ul_arr[$i];      			if (($param[1]) == $temp_ul) {          			$str=preg_replace('/selected="\$ul"/i',"selected",$str);          			$found_param=1;          			break;          		}      		}       		if (!$found_param) $str=preg_replace('/selected="\$ul"/i',"",$str);  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$type"/i',$str,$param)) {  			$found_param=0;  			for($i=0; $i<count($type_arr); $i++) {				$temp_type=$type_arr[$i];      			if (($param[1]) == $temp_type) {          			$str=preg_replace('/selected="\$type"/i',"selected",$str);          			$found_param=1;          			break;          		}      		}       		if (!$found_param) $str=preg_replace('/selected="\$type"/i',"",$str);        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$lang"/i',$str,$param)) {	  		$found_param=0;	  		for($i=0; $i<count($lang_arr); $i++) {				$temp_lang=$lang_arr[$i];      			if (($param[1]) == $temp_lang) {          			$str=preg_replace('/selected="\$lang"/i',"selected",$str);          			$found_param=1;          			break;          		}      		}       		if (!$found_param) $str=preg_replace('/selected="\$lang"/i',"",$str);  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$o"/i',$str,$param)) {      		if (($param[1]) == $o) {          		$str=preg_replace('/selected="\$o"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$o"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$m"/i',$str,$param)) {      		if (($param[1]) == $m) {          		$str=preg_replace('/selected="\$m"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$m"/i',"",$str);      		}        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$wm"/i',$str,$param)) {      		if (($param[1]) == $wm) {          		$str=preg_replace('/selected="\$wm"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$wm"/i',"",$str);      		}        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$s"/i',$str,$param)) {      		if ($param[1] == $s) {          		$str=preg_replace('/selected="\$s"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$s"/i',"",$str);      		}        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$sp"/i',$str,$param)) {      		if ($param[1] == $sp) {          		$str=preg_replace('/selected="\$sp"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$sp"/i',"",$str);      		}        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$sy"/i',$str,$param)) {      		if ($param[1] == $sy) {          		$str=preg_replace('/selected="\$sy"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$sy"/i',"",$str);      		}        } elseif (preg_match('/value="(.*)"[\s\t]+selected="\$wf"/i',$str,$param)) {      		if (($param[1]) == $wf) {          		$str=preg_replace('/selected="\$wf"/i',"selected",$str);      		} else {          		$str=preg_replace('/selected="\$wf"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$tag"/i',$str,$param)) {      		$found_param=0;			for($i=0; $i<count($tag_arr); $i++) {				$temp_tag=$tag_arr[$i];      			if (($param[1]) == $temp_tag) {          			$str=preg_replace('/selected="\$tag"/i',"selected",$str);          			$found_param=1;          			break;          		}      		}       		if (!$found_param) $str=preg_replace('/selected="\$tag"/i',"",$str);  			} elseif (preg_match('/type=radio[\s\t]+name="dt"[\s\t]+value="(.*)"/i',$str,$param)) {      		if (($param[1]) == $dt) {          		$str=preg_replace("/value=\"$dt\"/i","value=\"$dt\" checked",$str);      		} else {                                          		$str=preg_replace('/checked/i',"",$str);      		} 	 	} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dp"/i',$str,$param)) {      		if (($param[1]) == $dp) {          		$str=preg_replace('/selected="\$dp"/i',"selected",$str);      		} else {                                          		$str=preg_replace('/selected="\$dp"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dx"/i',$str,$param)) {      		if (($param[1]) == $dx) {          		$str=preg_replace('/selected="\$dx"/i',"selected",$str);      		} else {                                          		$str=preg_replace('/selected="\$dx"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dm"/i',$str,$param)) {      		if (($param[1]) == $dm) {          		$str=preg_replace('/selected="\$dm"/i',"selected",$str);      		} else {                                          		$str=preg_replace('/selected="\$dm"/i',"",$str);      		}  		} elseif (preg_match('/value="(.*)"[\s\t]+selected="\$dy"/i',$str,$param)) {      		if (($param[1]) == $dy) {          		$str=preg_replace('/selected="\$dy"/i',"selected",$str);      		} else {                                          		$str=preg_replace('/selected="\$dy"/i',"",$str);      		}  		}		if (preg_match('/\$g\((\d*)\)/i',$str,$param)) {	    	    		    $str=str_replace("\$g($param[1])",substr($tag,0,strlen($tag)-$param[1]),$str);		}			//Replace date attributes        $str=str_replace("\$dd",$dd,$str);        $str=str_replace("\$dy",$dy,$str);        $str=str_replace("\$dm",$dm,$str);        $str=str_replace("\$db",$db,$str);        $str=str_replace("\$de",$de,$str);		//Replace page numbering        $str=str_replace("\$ps",$ps,$str);		$str=str_replace("\$pn",$ps*$np,$str);        $str=str_replace("\$cat",$cat,$str);		        if (preg_match('/\$IF\s?\((.+)\)/i',$str,$param)) {		    $param[1]=trim($param[1]);		    $str=preg_replace('/\$IF\s?\((.+)\)/i',load_file($param[1]),$str);	            }		$comment_flag=0;				//If found comment tag, add empty field to the $templates array for the corresponding tag 		if (substr($str, 0, 4) == "<!--") {			reset($names);			while ($name=current($names)){			    if (strstr($str, "<!--$name")){					$where=$name;							$templates["$where"][] = '';										$comment_flag=1;					break;			    } elseif (strstr($str, "/$name-->")) {					$where='';					$comment_flag=1;					break;			    }			    next($names);			}		}			//if found a comment on this line, skip to the next line (do{...})		if ($comment_flag) continue;		//if the previous line was a comment and contained 'variables'		//'variables' is the section of the template where the configuration is		//Once this section is over, the HTML template really begins		if ($where=='variables') {			//if the line starts with a #, it's a comment so skip to next line		    if (ereg("^#",$str)) continue;			//look for some characters not space or tab starting a line, 			//followed by spaces or tabs, followed by any chars (basically any var..value couple)		    if (preg_match("/^([^\s\t]+)[\s\t]+(.+)/",$str,$param)) {	            $var=$param[1];			    $value=$param[2];			    $var=strtolower($var);				    $var=trim($var);			    $value=trim($value);                 			    //assign each value to the corresponding array, for reuse later			    if ($var=='affix') {			    	if ($sp=='') $sp=1;			    	$GLOBALS["ispellmode"]="text";		       		if (preg_match("/([^\s\t]+)[\s\t]+([^\s\t]+)[\s\t]+(.+)/",$value,$param)) {		          		$t_lang=trim($param[1]);                        $t_charset=trim($param[2]);		          		$file=trim($param[3]);		          		$affix_file[$t_lang]="$t_charset;$file";		          	} else {		          		print "Unsupported Affix command: Affix $value\n<br>";		          		exit;		        	}			    } elseif ($var=='spell') {                       if ($sp=='') $sp=1;                       $GLOBALS["ispellmode"]="text";       	           		if (preg_match("/([^\s\t]+)[\s\t]+([^\s\t]+)[\s\t]+(.+)/",$value,$param)) {			          		$t_lang=trim($param[1]);                            $t_charset=trim($param[2]);			          		$file=trim($param[3]);				          		$spell_file[$t_lang][]="$t_charset;$file";			       		} else {			          		print "Unsupported Spell command: Spell $value\n<br>";			          		exit;			       		}				} elseif ($var=='ispellmode') {                       if (preg_match("/^server[\s\t]+(.+)/i",$value,$param)) {				          $spell_host=trim($param[1]);                          $GLOBALS["ispellmode"]="server";		    		   } else {		   	 		   	  $GLOBALS["$var"]="$value";		   			    }		   		} elseif ($var=='alias') {                       if (preg_match("/^([^\s]+)\s+(.+)$/i",$value,$param)) {                       	  $alias_arr[trim($param[1])]=trim($param[2]);		       			} else {		       			  $GLOBALS["$var"]="$value";		       			}	            } elseif ($var=='stopwordtable') {	               $stopwordtable_arr[]=$value;	            } elseif ($var=='stopwordfile') {	               $stopwordfile_arr[]=$value;	            } elseif ($var=='synonym') {	               if ($sy=='') $sy=1;	               $synonym_arr[]=$value;	            } elseif ($var=='searchdaddr') {	                   $searchd_arr[]=$value;			    } elseif ($var=='r') {			       $rand=0+substr($var,1);			       $frand=rand();			       $frand=$frand/getrandmax()*$value;			       $Randoms[$rand]=floor($frand);			    } elseif ($var=='dbaddr') {		    		$dbaddr[]=$value;			    } else {			       $GLOBALS["$var"]="$value";			    }	    }	}	else	if ($where!=''){	    $templates["$where"][count($templates["$where"])-1] .= $str;	}	    } while (!feof($fp));//do this big loop until we reach the end of the file    fclose($fp);}/** * Calls back the udm_get_res_field_ex() function whith the second element of * the given array...!? * @param	array	Array which second element is sent to udm_get_res_field_ex() * @return	string	A string */function res_field_callback($expr) {    global $global_doc_res, $global_res_position;    return 	ParseDocText(htmlspecialchars(udm_get_res_field_ex($global_doc_res,$global_res_position,$expr[1])));}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -