Source code for file /joomla/client/helper.php
Documentation is available at helper.php
* @version $Id: helper.php 6474 2007-02-03 21:01:56Z friesengeist $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* @package Joomla.Framework
* Method to return the array of client layer configuration options
* @param string Client name, currently only 'ftp' is supported
* @param boolean 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
static $credentials =
array();
$client =
strtolower($client);
if (!isset
($credentials[$client]) ||
$force)
$config =
& JFactory::getConfig();
// Fetch the client layer configuration options for the specific client
'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')
// 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];
* Method to set client login credentials
* @param string Client name, currently only 'ftp' is supported
* @return boolean True if the given login credentials have been set and are valid
// Test if the given credentials are valid
'enabled' =>
$config->getValue('config.ftp_enable'),
'host' =>
$config->getValue('config.ftp_host'),
'port' =>
$config->getValue('config.ftp_port'),
// Test the conection and try to log in
if ($ftp->login($user, $pass)) {
// Save valid credentials to the session
$session->set($client.
'.user', $user, 'JClientHelper');
$session->set($client.
'.pass', $pass, 'JClientHelper');
// Force re-creation of the data saved within JClientHelper::getCredentials()
* Method to determine if client login credentials are present
* @param string Client name, currently only 'ftp' is supported
* @return boolean True if login credentials are available
// Get (unmodified) credentials for this client
'enabled' =>
$config->getValue('config.ftp_enable'),
'user' =>
$config->getValue('config.ftp_user'),
'pass' =>
$config->getValue('config.ftp_pass')
if ($options['enabled'] ==
false)
// The client is disabled in global config, so let's pretend we are OK
else if ($options['user'] !=
'' &&
$options['pass'] !=
'')
// Login credentials are available in global config
// Check if login credentials are available in the session
$user =
$session->get($client.
'.user', null, 'JClientHelper');
$pass =
$session->get($client.
'.pass', null, 'JClientHelper');
if ($user !=
'' &&
$pass !=
'') {
* Determine wether input fields for client settings need to be shown
* If valid credentials were passed along with the request, they are saved to the session.
* This functions returns an exeption if invalid credentials have been given or if the
* connection to the server failed for some other reason.
* @return boolean|JExeption True, if FTP settings should be shown, or an exeption
// Determine wether FTP credentials have been passed along with the current request
if ($user !=
'' &&
$pass !=
'')
// Add credentials to the session
$return =
& JError::raiseWarning('SOME_ERROR_CODE', 'JClientHelper::setCredentialsFromRequest failed');
// Just determine if the FTP input fields need to be shown