Move sqm_baseuri() to strings.php. A file for functions that manipulate strings...
[squirrelmail.git] / functions / strings.php
index df511b32f36e5fec1cdf682a8fa134e62f1f8f9c..f4e765541117f9e015ab568316dda9ad67f61faf 100644 (file)
@@ -477,6 +477,29 @@ function readShortMailboxName($haystack, $needle) {
     return( $elem );
 }
 
+/**
+ * Find out where SquirrelMail lives and try to be smart about it.
+ * The only problem would be when SquirrelMail lives in directories
+ * called "src", "functions", or "plugins", but people who do that need
+ * to be beaten with a steel pipe anyway.
+ *
+ * @return string the base uri of SquirrelMail installation.
+ * @since 1.2.6
+ */
+function sqm_baseuri(){
+    global $base_uri, $PHP_SELF;
+    /**
+     * If it is in the session, just return it.
+     */
+    if (isset($base_uri)){
+        return $base_uri;
+    }
+    $dirs = array('|src/.*|', '|plugins/.*|', '|functions/.*|');
+    $repl = array('', '', '');
+    $base_uri = preg_replace($dirs, $repl, $PHP_SELF);
+    return $base_uri;
+}
+
 /**
  * get_location
  *
@@ -1298,4 +1321,4 @@ function sq_count8bit($string) {
     return $count;
 }
 
-?>
\ No newline at end of file
+?>