]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
3a43ffcd9005a5d3a65708b63e0c39feefcade77
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-07-28
26 use base
qw(Exporter);
28 @EXPORT = qw(check_path
38 # Check, if a virtual path is above a virtual root directory
39 # (currently no check if the path exists - check otherwise!)
41 # Params: 1. Virtual root directory
42 # 2. Virtual path to check
44 # Return: Array with the physical and the cleaned virtual path;
45 # false, if the submitted path is above the root directory
49 my ($root,$path) = @_;
53 $root = abs_path
($root);
54 $root = File
::Spec
->canonpath($root);
57 $path = $root."/".$path;
61 # The path points to a file
62 # We have to extract the directory name and create the absolute path
64 my $dir = upper_path
($path);
65 my $file = file_name
($path);
67 $dir = abs_path
($dir);
68 $path = $dir."/".$file;
72 $path = abs_path
($path);
75 $path = File
::Spec
->canonpath($path);
77 # Check if the path is above the root directory
79 return if(index($path,$root) == -1);
81 # Create short path name
83 my $short_path = substr($path,length($root));
84 $short_path =~ tr!\\!\/!;
85 $short_path = "/".$short_path if($short_path !~ m
!^/!);
86 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
88 return ($path,$short_path);
93 # Clean up a path logically and replace backslashes with
98 # Return: Cleaned path
103 $path = File
::Spec
->canonpath($path);
111 # Create a HTTP redirection header to load Dev-Editor
112 # with some other parameters
114 # Params: Hash Reference (will be merged to a query string)
116 # Return: HTTP redirection header (Scalar Reference)
118 sub devedit_reload
($)
122 # Detect the protocol (simple HTTP or SSL encrypted HTTP)
123 # and check if the server listens on the default port
130 # SSL encrypted HTTP (HTTPS)
133 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 443);
140 $port = ":".$ENV{'SERVER_PORT'} if($ENV{'SERVER_PORT'} != 80);
143 # The following code is grabbed from Template::_query of
144 # Andre Malo's selfforum (http://sourceforge.net/projects/selfforum/)
145 # and modified by Patrick Canterino
147 my $query = '?'.join ('&' =>
150 ?
map{escape
($_).'='.escape
($params -> {$_})} @
{$params -> {$_}}
151 : escape
($_).'='.escape
($params -> {$_})
155 # Create the redirection header
157 my $header = redirect
($protocol."://".virtual_host
.$port.$ENV{'SCRIPT_NAME'}.$query);
164 # Create URL equal to a file or directory
166 # Params: 1. HTTP root
169 # Return: Formatted link (String)
173 my ($root,$path) = @_;
178 $url = $root."/".$path;
185 # Return the last part of a path
189 # Return: Last part of the path
198 $path = substr($path,0,-1) if($path =~ m!/$!);
199 $path = substr($path,rindex($path,"/")+1);
207 # Convert a binary file mode string into a human
208 # readable string (rwxr-x-r-x)
210 # Params: Binary file mode string
212 # Return: Humand readable mode string
221 $string .= (($mode & 0x0100) ?
'r' : '-') .
222 (($mode & 0x0080) ?
'w' : '-') .
224 (($mode & 0x0800) ?
's' : 'x' ) :
225 (($mode & 0x0800) ?
'S' : '-')
229 $string .= (($mode & 0x0020) ?
'r' : '-') .
230 (($mode & 0x0010) ?
'w' : '-') .
232 (($mode & 0x0400) ?
's' : 'x') :
233 (($mode & 0x0400) ?
'S' : '-')
237 $string .= (($mode & 0x0004) ?
'r' : '-') .
238 (($mode & 0x0002) ?
'w' : '-') .
240 (($mode & 0x0200) ?
't' : 'x' ) :
241 (($mode & 0x0200) ?
'T' : '-')
249 # Cut away the last part of a path
253 # Return: Truncated path
262 $path = substr($path,0,-1) if($path =~ m!/$!);
263 $path = substr($path,0,rindex($path,"/")+1);
269 # it's true, baby ;-)
patrick-canterino.de