/**
* Method to return the array of client layer configuration options
*
* @param string $client Client name, currently only 'ftp' is supported
* @param boolean $force Forces re-creation of the login credentials. Set this to
* true if login credentials in the session storage have changed
*
* @return array Client layer configuration options, consisting of at least
* these fields: enabled, host, port, user, pass, root
*
* @since 1.7.0
*/
public static function getCredentials($client, $force = false)
{
static $credentials = array();
$client = strtolower($client);
if (!isset($credentials[$client]) || $force) {
$app = Factory::getApplication();
// Fetch the client layer configuration options for the specific client
switch ($client) {
case 'ftp':
$options = array('enabled' => $app->get('ftp_enable'), 'host' => $app->get('ftp_host'), 'port' => $app->get('ftp_port'), 'user' => $app->get('ftp_user'), 'pass' => $app->get('ftp_pass'), 'root' => $app->get('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 they are in the session
if ($options['enabled'] == true && ($options['user'] == '' || $options['pass'] == '')) {
$session = Factory::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];
}