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

📄 iltemp.pm

📁 支持全流程的Perl+MySQL电子商务系统。完全公开代码。
💻 PM
字号:
package iltemp;require 5.000;require Exporter;@ISA = qw(Exporter);@EXPORT = qw(new Parse);use strict;use vars qw($parse_end $text $self %dbs);my $VERSION='1.4a';############################################################################	iLcat Template Tool############################################################################	Current Version : 1.4a#	History Change:#	1.4			Change [% element %] to <!-- element -->(not in b version)#	1.3			remodel object module、perfect INCLUDE、Support Mulit-FOREACH#	1.2			Support multi-INCLUDEs#	1.1			Recover Bugs#	1.0			Support for Basetag、INCLUDE、FOREACH############################################################################	Function:base_tag、INCLUDE、FOREACH############################################################################	author:hoowa#	Email:hoowa@263.net#	Web:http://hoowa.tab.net.cn############################################################################===================#Here is new object#===================sub new{my $class=shift;my %hash=@_;my $self={};$self->{ttmlpath}	=	$hash{ttmlpath} || 0;bless $self,$class;return $self;}#==================#Parse from source#==================sub Parse{my (@source_code,@foreach_line);my ($file,$source_line,$continue_foreach);($self,$file,$text,%dbs)=@_;	#Open Source file	open(SOURCE_FILE,"$self->{ttmlpath}/$file") || die &error("Can't Open File: $self->{ttmlpath}/$file");		@source_code=<SOURCE_FILE>;	close(SOURCE_FILE);######代码解析$parse_end=undef;foreach $source_line (@source_code) {#INCLUDE处理部分_______________________________________________________________				$parse_end .= &_include("$source_line") if ($source_line =~ /\<\!\-\-TP INCLUDE (.*?) \-\-\>/);#______________________________________________________________________________#循环处理部分__________________________________________________________________				if ($source_line =~ /\<\!\-\-TP FOREACH (.*?) \-\-\>/) {$continue_foreach=1;}		#循环模式代码存储开关		elsif ($source_line =~ /\<\!\-\-TP END \-\-\>/) {				$continue_foreach=0;				$parse_end .= &_foreach(@foreach_line);				#处理循环模式代码				@foreach_line=();		}		else {			#普通标记的记录________________________________________________________________					$parse_end .= &_styles("$source_line") if ($continue_foreach ne 1);			#______________________________________________________________________________		}		push(@foreach_line,"$source_line") if ($continue_foreach eq "1");		#循环模式代码存储#______________________________________________________________________________}return("Content-type: text/html\n\n$parse_end");}#-----------------#CODE Styles#-----------------sub _styles{my $code_line=$_[0];my (@element,$a_tag);if ($code_line =~ m/\<\!\-\-TP (.*?) \-\-\>/) {	@element=$code_line	=~ m/\<\!\-\-TP (.*?) \-\-\>/g;	foreach $a_tag (@element) {			$code_line	=~	s/\<\!\-\-TP $a_tag \-\-\>/$text->{$a_tag}/i;	}}return($code_line);}#-------------------#INCLUDE other file#-------------------sub _include{my $code_line=$_[0];my (@element,$include_source_file,@file_code,$include_end);#判断是否包含INCLUDE元素if ($code_line =~ /\<\!\-\-TP INCLUDE (.*?) \-\-\>/)	{	#将所有INCLUDE元素名称解析到@element数组中来	@element=$code_line=~ m/\<\!\-\-TP INCLUDE (.*?) \-\-\>/g;	#逐个读入元素文件	foreach $include_source_file (@element) {			#打开并存储元素到@file_code数组中			open(INCLUDE_SOURCE,"$self->{ttmlpath}/$include_source_file") || die &error("Can't Open INCLUDE file $self->{ttmlpath}/$include_source_file");			@file_code=<INCLUDE_SOURCE>;			close(INCLUDE_SOURCE);			#解析@file_code数组中的标准元素并且存储元素到目标变量$include_end中			$include_end=undef;			foreach  (@file_code) {				$include_end.=&_styles("$_");			}			$code_line	=~	s/\<\!\-\-TP INCLUDE $include_source_file \-\-\>/$include_end/i;	}}return($code_line);}#-------------------#FOREACH CODES#-------------------sub _foreach{my (@foreach_code)=@_;my (@foreach_code2,@element,$a_tag,$foreach_end,$headname,$i,$foreach_line);#得到循环体名称	$headname=shift(@foreach_code);	$headname =~ m/\<\!\-\-TP FOREACH (.*?) \-\-\>/g;	$headname = $1;#开始解析循环代码___________for ($i=0;$i<=$text->{"loop_$headname"};$i++) {	@foreach_code2=@foreach_code;	foreach $foreach_line (@foreach_code2) {			@element=$foreach_line =~ m/\<\!\-\-TP (.*?) \-\-\>/g;			foreach $a_tag (@element) {				$foreach_line =~ s/\<\!\-\-TP $a_tag \-\-\>/$dbs{$headname}{"$i"}->{$a_tag}/i;			}	$foreach_end .= $foreach_line;	}}#___________________________return($foreach_end);}#===================#Error Report#===================sub error{print "Content-type: text/html\n\n";print qq~<html><head><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>ErrorPage</title></head><body><p><font size="2">iLcat Template Error Report to http://hoowa.tab.net.cn</font></p><p><font size="2">@_</font></p></body></html>~;exit;}1;

⌨️ 快捷键说明

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