Actions

API16

JClientHelper/getCredentials

From Joomla! Documentation

< API16:JClientHelper
Revision as of 21:55, 12 May 2013 by JoomlaWikiBot (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

Method to return the array of client layer configuration options

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

getCredentials($client, $force=false)
Parameter Name Default Value Description
$client Client name, currently only 'ftp' is supported
$force false Forces re-creation of the login credentials. Set this to true if login credentials in the session storage have changed

Returns

array Client layer configuration options, consisting of at least these fields: enabled, host, port, user, pass, root

Defined in

libraries/joomla/client/helper.php

Importing

jimport( 'joomla.client.helper' );

Source Body

function getCredentials($client, $force=false)
{
        static $credentials = array();
 
        $client = strtolower($client);
 
        if (!isset($credentials[$client]) || $force)
        {
                // Initialise variables.
                $config = &JFactory::getConfig();
 
                // Fetch the client layer configuration options for the specific client
                switch ($client)
                {
                        case 'ftp':
                                $options = array(
                                        'enabled'       => $config->getValue('config.ftp_enable'),
                                        'host'          => $config->getValue('config.ftp_host'),
                                        'port'          => $config->getValue('config.ftp_port'),
                                        'user'          => $config->getValue('config.ftp_user'),
                                        'pass'          => $config->getValue('config.ftp_pass'),
                                        'root'          => $config->getValue('config.ftp_root')
                                );
                                break;
 
                        default:
                                $options = array(
                                        'enabled'       => false,
                                        'host'          => '',
                                        'port'          => '',
                                        'user'          => '',
                                        'pass'          => '',
                                        'root'          => ''
                                );
                                break;
                }
 
                // If user and pass are not set in global config lets see if its in the session
                if ($options['enabled'] == true && ($options['user'] == '' || $options['pass'] == ''))
                {
                        $session = &JFactory::getSession();
                        $options['user'] = $session->get($client.'.user', null, 'JClientHelper');
                        $options['pass'] = $session->get($client.'.pass', null, 'JClientHelper');
                }
 
                // If user or pass are missing, disable this client
                if ($options['user'] == '' || $options['pass'] == '') {
                        $options['enabled'] = false;
                }
 
                // Save the credentials for later use
                $credentials[$client] = $options;
        }
 
        return $credentials[$client];
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />