]> git.mjollnir.org Git - moodle.git/commitdiff
Cleaned up file argument processing a bit
authormoodler <moodler>
Sun, 12 Jan 2003 06:53:25 +0000 (06:53 +0000)
committermoodler <moodler>
Sun, 12 Jan 2003 06:53:25 +0000 (06:53 +0000)
file.php
lib/weblib.php
user/lib.php
user/pix.php

index 4ef1baf4c0d6404450889972e133cea21a9eda1e..95b86aa9adda1b4237c8668f2a2a9e30946e52ec 100644 (file)
--- a/file.php
+++ b/file.php
@@ -8,14 +8,16 @@
     $lifetime = 86400;
 
     if (isset($file)) {     // workaround for situations where / syntax doesn't work
-        $PATH_INFO = $file;
+        $pathinfo = $file;
+    } else {
+        $pathinfo = get_slash_arguments("file.php");
     }
 
-    if (!$PATH_INFO) {
-        error("This script DEPENDS on PATH_INFO being available.  Read the README.");
+    if (!$pathinfo) {
+        error("No file parameters!");
     }
 
-    if (! $args = get_slash_arguments()) {
+    if (! $args = parse_slash_arguments($pathinfo)) {
         error("No valid arguments supplied");
     }
 
index 512a1c8f04cc4196bc99ddd31e2e8f8edb5d5395..7970cdff5ef3b96f9e4e4a0f27e169427eaff164 100644 (file)
@@ -397,29 +397,44 @@ function validate_email ($address) {
                   $address));
 }
 
+function get_slash_arguments($file="file.php") {
+/// Searches the current environment variables for some slash arguments
 
-function get_slash_arguments($i=0) {
-/// Extracts arguments from "/foo/bar/something"
-/// eg http://mysite.com/script.php/foo/bar/something
-/// Might only work on Apache
-
-    global $PATH_INFO;
+    if (isset($_SERVER['PATH_INFO'])) {
+        return $_SERVER['PATH_INFO'];
+    }
 
-    if (!isset($PATH_INFO)) {
+    if (isset($_SERVER['PHP_SELF'])) {
+        $string = $_SERVER['PHP_SELF'];
+    } else if (isset($_SERVER['REQUEST_URI'])) {
+        $string = $_SERVER['REQUEST_URI'];
+    } else {
         return false;
     }
+    $pathinfo = explode($file, $string);
+    
+    if (!empty($path_info[1])) {
+        return $path_info[1];
+    } else {
+        return false;
+    }
+}
+
+function parse_slash_arguments($string, $i=0) {
+/// Extracts arguments from "/foo/bar/something"
+/// eg http://mysite.com/script.php/foo/bar/something
 
-    if (strpos($PATH_INFO, "..")) { // check for parent URLs
+    if (strpos($string, "..")) { // check for parent URLs
         return false;
     }
-    if (strpos($PATH_INFO, "|")) {  // check for pipes
+    if (strpos($string, "|")) {  // check for pipes
         return false;
     }
-    if (strpos($PATH_INFO, "`")) {  // check for backquotes
+    if (strpos($string, "`")) {  // check for backquotes
         return false;
     }
 
-    $args = explode("/", $PATH_INFO);
+    $args = explode("/", $string);
 
     if ($i) {     // return just the required argument
         return $args[$i];
index e329366499923f6517e0291b299d7818a2577d25..ceb8c6da9d6b68848d4141bc2556440227fb79f1 100644 (file)
@@ -122,7 +122,7 @@ function save_user_image($userid, $filename) {
         }
     }
     
-    if ($badpermissions) {
+    if (!empty($badpermissions)) {
         return 0;
 
     } else {
index 9feff114a01546e19e4cd7949be78f8d59934e96..fd06d3c40ac2d8df05d4ef73c7e44a13bb042bd4 100644 (file)
@@ -7,14 +7,14 @@
 
     $lifetime = 86400;
 
-    if (isset($file)) {
-        $PATH_INFO = $file;
+    if (isset($file)) {     // workaround for situations where / syntax doesn't work
+        $pathinfo = $file;
 
-    } else if (!$PATH_INFO) {
-        $PATH_INFO = "";       // Will just show default picture
+    } else {
+        $pathinfo = get_slash_arguments("pix.php");
     }
 
-    if (! $args = get_slash_arguments()) {
+    if (! $args = parse_slash_arguments($pathinfo)) {
         error("No valid arguments supplied");
     }