import torrus 1.0.9
[freeside.git] / FS / FS / CGI.pm
index 96047f6..9454784 100644 (file)
@@ -194,16 +194,24 @@ sub myexit {
   }
 }
 
-=item popurl LEVEL
+=item popurl LEVEL [URL]
 
-Returns current URL with LEVEL levels of path removed from the end (default 0).
+Returns current (or, optionally, passed) URL with LEVEL levels of path removed
+from the end (default 0).
 
 =cut
 
 sub popurl {
-  my($up)=@_;
-  my $cgi = &FS::UID::cgi;
-  my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
+  my $up = shift;
+
+  my $url_string;
+  if ( scalar(@_) ) {
+    $url_string = shift;
+  } else {
+    my $cgi = &FS::UID::cgi;
+    $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
+  }
+
   $url_string =~ s/\?.*//;
   my $url = new URI::URL ( $url_string );
   my(@path)=$url->path_components;
@@ -219,9 +227,15 @@ sub popurl {
 =cut
 
 sub rooturl {
-  # better to start with the client-provided URL
-  my $cgi = &FS::UID::cgi;
-  my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
+  my $url_string;
+  if ( scalar(@_) ) {
+    $url_string = shift;
+  } else {
+    # better to start with the client-provided URL
+    my $cgi = &FS::UID::cgi;
+    $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
+  }
+
   $url_string =~ s/\?.*//;
 
   #even though this is kludgy
@@ -233,7 +247,7 @@ sub rooturl {
        (browse|config|docs|edit|graph|misc|search|view|pref|rt|elements)
        /
        (process/)?
-       ([\w\-\.\/]+)
+       ([\w\-\.\/]*)
        $
      }
      {}x;