API16

Difference between revisions of "JFactory/getStream"

From Joomla! Documentation

< API16:JFactory
(New page: ===Description=== Creates a new stream object with appropriate prefix <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JFactory/getStream|Edit Descri...)
(No difference)

Revision as of 17:47, 22 March 2010

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Creates a new stream object with appropriate prefix

[Edit Descripton]

Template:Description:JFactory/getStream

Syntax[edit]

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[edit]

libraries/joomla/factory.php

Importing[edit]

jimport( 'joomla.factory' );

Source Body[edit]

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] Template:SeeAlso:JFactory/getStream

Examples[edit]

<CodeExamplesForm />