]>
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: 2003-12-02
22 use base
qw(Exporter);
24 @EXPORT = qw(check_path
32 # Check, if a virtual path is above a virtual root directory
33 # (currently no check if the path exists - check otherwise!)
35 # Params: 1. Virtual root directory
36 # 2. Virtual path to check
38 # Return: Array with the physical and the cleaned virtual path;
39 # false, if the submitted path is above the root directory
43 my ($root,$path) = @_;
47 $root = abs_path
($root);
48 $root = File
::Spec
->canonpath($root);
51 $path = $root."/".$path;
55 # The path points to a file
56 # We have to extract the directory name and create the absolute path
58 my $dir = upper_path
($path);
59 my $file = file_name
($path);
61 $dir = abs_path
($dir);
62 $path = $dir."/".$file;
66 $path = abs_path
($path);
69 $path = File
::Spec
->canonpath($path);
71 # Check if the path is above the root directory
73 return if(index($path,$root) == -1);
75 # Create short path name
77 my $short_path = substr($path,length($root));
78 $short_path =~ tr!\\!\/!;
79 $short_path = "/".$short_path if($short_path !~ m
!^/!);
80 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
82 return ($path,$short_path);
87 # Clean up a path logically and replace backslashes with
92 # Return: Cleaned path
97 $path = File
::Spec
->canonpath($path);
105 # Create a HTTP redirection header to load Dev-Editor
106 # with some other parameters
108 # Params: Hash Reference (will be merged to a query string)
110 # Return: HTTP redirection header (Scalar Reference)
112 sub devedit_reload
($)
117 while(my ($param,$value) = each(%$params))
119 push(@list,$param."=".$value);
122 my $query = join("&",@list);
123 my $header = redirect
("http://$ENV{'HTTP_HOST'}$ENV{'SCRIPT_NAME'}?$query");
130 # Returns the last path of a path
134 # Return: Last part of the path
143 $path = substr($path,0,-1) if($path =~ m!/$!);
144 $path = substr($path,rindex($path,"/")+1);
152 # Cut the last part of a path away
156 # Return: Truncated path
165 $path = substr($path,0,-1) if($path =~ m!/$!);
166 $path = substr($path,0,rindex($path,"/")+1);
172 # it's true, baby ;-)
patrick-canterino.de