]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-07-12
26 use base
qw(Exporter);
28 @EXPORT = qw(check_path
37 # Check, if a virtual path is above a virtual root directory
38 # (currently no check if the path exists - check otherwise!)
40 # Params: 1. Virtual root directory
41 # 2. Virtual path to check
43 # Return: Array with the physical and the cleaned virtual path;
44 # false, if the submitted path is above the root directory
48 my ($root,$path) = @_;
52 $root = abs_path
($root);
53 $root = File
::Spec
->canonpath($root);
56 $path = $root."/".$path;
60 # The path points to a file
61 # We have to extract the directory name and create the absolute path
63 my $dir = upper_path
($path);
64 my $file = file_name
($path);
66 $dir = abs_path
($dir);
67 $path = $dir."/".$file;
71 $path = abs_path
($path);
74 $path = File
::Spec
->canonpath($path);
76 # Check if the path is above the root directory
78 return if(index($path,$root) == -1);
80 # Create short path name
82 my $short_path = substr($path,length($root));
83 $short_path =~ tr!\\!\/!;
84 $short_path = "/".$short_path if($short_path !~ m
!^/!);
85 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
87 return ($path,$short_path);
92 # Clean up a path logically and replace backslashes with
97 # Return: Cleaned path
102 $path = File
::Spec
->canonpath($path);
110 # Create a HTTP redirection header to load Dev-Editor
111 # with some other parameters
113 # Params: Hash Reference (will be merged to a query string)
115 # Return: HTTP redirection header (Scalar Reference)
117 sub devedit_reload
($)
121 # Detect the protocol (simple HTTP or SSL encrypted HTTP)
122 # and check if the server listens on the default port
129 # SSL encrypted HTTP (HTTPS)
132 $port = ($ENV{'SERVER_PORT'} == 443) ?
"" : ":".$ENV{'SERVER_PORT'};
139 $port = ($ENV{'SERVER_PORT'} == 80) ?
"" : ":".$ENV{'SERVER_PORT'};
142 # The following code is grabbed from Template::_query of
143 # Andre Malo's selfforum (http://sourceforge.net/projects/selfforum/)
144 # and modified by Patrick Canterino
146 my $query = '?'.join ('&' =>
149 ?
map{escape
($_).'='.escape
($params -> {$_})} @
{$params -> {$_}}
150 : escape
($_).'='.escape
($params -> {$_})
154 # Create the redirection header
156 my $header = redirect
($protocol."://".virtual_host
.$port.$ENV{'SCRIPT_NAME'}.$query);
163 # Create URL equal to a file or directory
165 # Params: 1. HTTP root
168 # Return: Formatted link (String)
172 my ($root,$path) = @_;
177 $url = $root."/".$path;
184 # Return the last part of a path
188 # Return: Last part of the path
197 $path = substr($path,0,-1) if($path =~ m!/$!);
198 $path = substr($path,rindex($path,"/")+1);
206 # Cut away the last part of a path
210 # Return: Truncated path
219 $path = substr($path,0,-1) if($path =~ m!/$!);
220 $path = substr($path,0,rindex($path,"/")+1);
226 # it's true, baby ;-)
patrick-canterino.de