Actions

API16

JFactory/getStream

From Joomla! Documentation

< API16:JFactory
Revision as of 16:47, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Creates a new stream object with appropriate prefix

[Edit Descripton]

Description:JFactory/getStream

Syntax

getStream($use_prefix=true, $use_network=true, $ua=null, $uamask=false)
Parameter Name Default Value Description
$use_prefix true Prefix the connections for writing
$use_network true Use network if available for writing; use false to disable (e.g. FTP, SCP)
$ua null UA User agent to use
$uamask false User agent masking (prefix Mozilla)

Defined in

libraries/joomla/factory.php

Importing

jimport( 'joomla.factory' );

Source Body

function getStream($use_prefix=true, $use_network=true,$ua=null, $uamask=false) {
        jimport('joomla.filesystem.stream');
        // Setup the context; Joomla! UA and overwrite
        $context = Array();
        $version = new JVersion();
        // set the UA for HTTP and overwrite for FTP
        $context['http']['user_agent'] = $version->getUserAgent($ua, $uamask);
        $context['ftp']['overwrite'] = true;
        if($use_prefix) {
                jimport('joomla.client.helper');
                $FTPOptions = JClientHelper::getCredentials('ftp');
                $SCPOptions = JClientHelper::getCredentials('scp');
                if ($FTPOptions['enabled'] == 1 && $use_network) {
                        $prefix = 'ftp://'. $FTPOptions['user'] .':'. $FTPOptions['pass'] .'@'. $FTPOptions['host'];
                        $prefix .= $FTPOptions['port'] ? ':'. $FTPOptions['port'] : '';
                        $prefix .= $FTPOptions['root'];
                } else if($SCPOptions['enabled'] == 1 && $use_network) {
                        $prefix = 'ssh2.sftp://'. $SCPOptions['user'] .':'. $SCPOptions['pass'] .'@'. $SCPOptions['host'];
                        $prefix .= $SCPOptions['port'] ? ':'. $SCPOptions['port'] : '';
                        $prefix .= $SCPOptions['root'];
                } else {
                        $prefix = JPATH_ROOT.DS;
                }
                $retval = new JStream($prefix, JPATH_ROOT, $context);
        } else {
                $retval = new JStream('','',$context);
        }
        return $retval;
}

[Edit See Also] SeeAlso:JFactory/getStream

Examples

<CodeExamplesForm />