]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
1bc020d2b3fcdb0dc53a9888ff4259b245f8ef9f
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
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'} == 443) ?
"" : ":".$ENV{'SERVER_PORT'};
140 $port = ($ENV{'SERVER_PORT'} == 80) ?
"" : ":".$ENV{'SERVER_PORT'};
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 # Cut away the last part of a path
211 # Return: Truncated path
220 $path = substr($path,0,-1) if($path =~ m!/$!);
221 $path = substr($path,0,rindex($path,"/")+1);
227 # it's true, baby ;-)
patrick-canterino.de