]>
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-02-03
22 use base
qw(Exporter);
24 @EXPORT = qw(check_path
33 # Check, if a virtual path is above a virtual root directory
34 # (currently no check if the path exists - check otherwise!)
36 # Params: 1. Virtual root directory
37 # 2. Virtual path to check
39 # Return: Array with the physical and the cleaned virtual path;
40 # false, if the submitted path is above the root directory
44 my ($root,$path) = @_;
48 $root = abs_path
($root);
49 $root = File
::Spec
->canonpath($root);
52 $path = $root."/".$path;
56 # The path points to a file
57 # We have to extract the directory name and create the absolute path
59 my $dir = upper_path
($path);
60 my $file = file_name
($path);
62 $dir = abs_path
($dir);
63 $path = $dir."/".$file;
67 $path = abs_path
($path);
70 $path = File
::Spec
->canonpath($path);
72 # Check if the path is above the root directory
74 return if(index($path,$root) == -1);
76 # Create short path name
78 my $short_path = substr($path,length($root));
79 $short_path =~ tr!\\!\/!;
80 $short_path = "/".$short_path if($short_path !~ m
!^/!);
81 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
83 return ($path,$short_path);
88 # Clean up a path logically and replace backslashes with
93 # Return: Cleaned path
98 $path = File
::Spec
->canonpath($path);
106 # Create a HTTP redirection header to load Dev-Editor
107 # with some other parameters
109 # Params: Hash Reference (will be merged to a query string)
111 # Return: HTTP redirection header (Scalar Reference)
113 sub devedit_reload
($)
118 while(my ($param,$value) = each(%$params))
120 push(@list,$param."=".$value);
123 my $query = join("&",@list);
124 my $header = redirect
("http://$ENV{'HTTP_HOST'}$ENV{'SCRIPT_NAME'}?$query");
131 # Create URL equal to a file or directory
133 # Params: 1. HTTP root
136 # Return: Formatted link (String)
140 my ($root,$path) = @_;
145 $url = $root."/".$path;
146 #$url = encode_entities($url);
153 # Returns the last path of a path
157 # Return: Last part of the path
166 $path = substr($path,0,-1) if($path =~ m!/$!);
167 $path = substr($path,rindex($path,"/")+1);
175 # Cut the last part of a path away
179 # Return: Truncated path
188 $path = substr($path,0,-1) if($path =~ m!/$!);
189 $path = substr($path,0,rindex($path,"/")+1);
195 # it's true, baby ;-)
patrick-canterino.de