/**
  * Create a folder -- and all necessary parent folders
  *
  * @param string $path A path to create from the base path
  * @param int $mode Directory permissions to set for folders created
  * @return boolean True if successful
  * @since 1.5
  */
 function createDir($path = '', $mode = 0755)
 {
     // Initialize variables
     //jimport('joomla.client.helper');
     //$FTPOptions = JClientHelper::getCredentials('ftp');
     static $nested = 0;
     // Check to make sure the path valid and clean
     $path = zmgFileHelper::cleanPath($path);
     // Check if parent dir exists
     $parent = dirname($path);
     if (!is_dir($parent)) {
         // Prevent infinite loops!
         $nested++;
         if ($nested > 20 || $parent == $path) {
             zmgError::throwError(T_('Infinite loop detected'));
             $nested--;
             return false;
         }
         // Create the parent directory
         if (zmgFileHelper::createDir($parent, $mode) !== true) {
             // zmgFileHelper::createDir throws an error
             $nested--;
             return false;
         }
         // OK, parent directory has been created
         $nested--;
     }
     // Check if dir already exists
     if (is_dir($path)) {
         return true;
     }
     // Check for safe mode
     if (zmgFactory::getConfig()->get('plugins/safemode/general/enable') == 1) {
         $ret = zmgFactory::getEvents()->fire('ondircreate', $path);
         zmgFileHelper::chmod($path);
     } else {
         // We need to get and explode the open_basedir paths
         $obd = ini_get('open_basedir');
         // If open_basedir is set we need to get the open_basedir that the path is in
         if ($obd != null) {
             if (ZMG_ISWIN) {
                 $obdSeparator = ";";
             } else {
                 $obdSeparator = ":";
             }
             // Create the array of open_basedir paths
             $obdArray = explode($obdSeparator, $obd);
             $inOBD = false;
             // Iterate through open_basedir paths looking for a match
             foreach ($obdArray as $test) {
                 $test = zmgFileHelper::cleanPath($test);
                 if (strpos($path, $test) === 0) {
                     $obdpath = $test;
                     $inOBD = true;
                     break;
                 }
             }
             if ($inOBD == false) {
                 // Return false for zmgFileHelper::createDir because the path to be created is not in open_basedir
                 zmgError::throwError(T_('Path not in open_basedir paths'));
                 return false;
             }
         }
         // First set umask
         $origmask = @umask(0);
         // Create the path
         if (!($ret = @mkdir($path, $mode))) {
             @umask($origmask);
             zmgError::throwError(T_('Could not create directory'));
             return false;
         }
         // Reset umask
         @umask($origmask);
     }
     return $ret;
 }