Example #1
0
 public static function getStream($use_prefix = true, $use_network = true, $ua = null, $uamask = false)
 {
     mimport('framework.filesystem.stream');
     // Setup the context;
     $context = array();
     $version = new MVersion();
     // set the UA for HTTP and overwrite for FTP
     $context['http']['user_agent'] = $version->getUserAgent($ua, $uamask);
     $context['ftp']['overwrite'] = true;
     if ($use_prefix) {
         $FTPOptions = MClientHelper::getCredentials('ftp');
         $SCPOptions = MClientHelper::getCredentials('scp');
         if ($FTPOptions['enabled'] == 1 && $use_network) {
             $prefix = 'ftp://' . $FTPOptions['user'] . ':' . $FTPOptions['pass'] . '@' . $FTPOptions['host'];
             $prefix .= $FTPOptions['port'] ? ':' . $FTPOptions['port'] : '';
             $prefix .= $FTPOptions['root'];
         } elseif ($SCPOptions['enabled'] == 1 && $use_network) {
             $prefix = 'ssh2.sftp://' . $SCPOptions['user'] . ':' . $SCPOptions['pass'] . '@' . $SCPOptions['host'];
             $prefix .= $SCPOptions['port'] ? ':' . $SCPOptions['port'] : '';
             $prefix .= $SCPOptions['root'];
         } else {
             $prefix = MPATH_ROOT . '/';
         }
         $retval = new MStream($prefix, MPATH_ROOT, $context);
     } else {
         $retval = new MStream('', '', $context);
     }
     return $retval;
 }