Skip to content

Commit

Permalink
This is in continuation with @mbabker's joomla#12068.
Browse files Browse the repository at this point in the history
The implementation in the global configuration is a nice improvement. However the same effect can be achieved without introducing an new parameter 'shared_session'.
Database changes can also be avoided but it doesn't harm in any way, so I have skipped them.
  • Loading branch information
izharaazmi committed Oct 5, 2016
1 parent 1f3db97 commit eb86b91
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 44 deletions.
20 changes: 0 additions & 20 deletions administrator/components/com_config/model/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,6 @@ public function save($data)
$table->purge(-1);
}

// Set the shared session configuration
if (isset($data['shared_session']))
{
$currentShared = isset($prev['shared_session']) ? $prev['shared_session'] : '0';

// Has the user enabled shared sessions?
if ($data['shared_session'] == 1 && $currentShared == 0)
{
// Generate a random shared session name
$data['session_name'] = JUserHelper::genRandomPassword(16);
}

// Has the user disabled shared sessions?
if ($data['shared_session'] == 0 && $currentShared == 1)
{
// Remove the session name value
unset($data['session_name']);
}
}

if (empty($data['cache_handler']))
{
$data['caching'] = 0;
Expand Down
10 changes: 5 additions & 5 deletions administrator/components/com_config/model/form/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,15 @@
size="6" />

<field
name="shared_session"
name="session_name"
type="radio"
class="btn-group btn-group-yesno"
default="0"
default=""
label="COM_CONFIG_FIELD_SHARED_SESSION_LABEL"
description="COM_CONFIG_FIELD_SHARED_SESSION_DESC"
filter="integer">
<option value="1">JYES</option>
<option value="0">JNO</option>
filter="cmd">
<option value="shared">JYES</option>
<option value="">JNO</option>
</field>

<field
Expand Down
8 changes: 4 additions & 4 deletions administrator/modules/mod_logged/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
</strong>

<small class="small hasTooltip" title="<?php echo JHtml::tooltipText('JCLIENT'); ?>">
<?php if ($user->client_id === null) : ?>
<?php // Don't display a client ?>
<?php elseif ($user->client_id) : ?>
<?php if (JFactory::getApplication()->get('session_name')) : ?>
<?php // Don't display a client if we have a shared session ?>
<?php elseif ($user->client_id == 1) : ?>
<?php echo JText::_('JADMINISTRATION'); ?>
<?php else : ?>
<?php elseif ($user->client_id == 0) : ?>
<?php echo JText::_('JSITE'); ?>
<?php endif; ?>
</small>
Expand Down
6 changes: 3 additions & 3 deletions administrator/modules/mod_status/mod_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$count = 0;

// Get the number of backend logged in users if shared sessions is not enabled.
if (!$config->get('shared_session', '0'))
if ($config->get('session_name', '') == '')
{
$query->clear()
->select('COUNT(session_id)')
Expand Down Expand Up @@ -61,7 +61,7 @@
$online_num = 0;

// Get the number of frontend logged in users if shared sessions is not enabled.
if (!$config->get('shared_session', '0'))
if ($config->get('session_name', '') == '')
{
$query->clear()
->select('COUNT(session_id)')
Expand All @@ -75,7 +75,7 @@
$total_users = 0;

// Get the number of logged in users if shared sessions is enabled.
if ($config->get('shared_session', '0'))
if ($config->get('session_name', '') != '')
{
$query->clear()
->select('COUNT(session_id)')
Expand Down
2 changes: 1 addition & 1 deletion administrator/modules/mod_status/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

// Print logged in user count based on the shared session state
if (JFactory::getConfig()->get('shared_session', '0'))
if (JFactory::getConfig()->get('session_name', '') != '')
{
// Print the frontend logged in users.
if ($params->get('show_loggedin_users', 1))
Expand Down
2 changes: 1 addition & 1 deletion installation/model/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function createConfiguration($options)
// Session setting.
$registry->set('lifetime', 15);
$registry->set('session_handler', 'database');
$registry->set('shared_session', 0);
$registry->set('session_name', '');

// Generate the configuration class string buffer.
$buffer = $registry->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
Expand Down
2 changes: 1 addition & 1 deletion libraries/cms/application/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function checkSession()
$db->quote($user->username),
);

if (!$this->get('shared_session', '0'))
if ($this->get('session_name', '') == '')
{
$columns[] = $db->quoteName('client_id');
$values[] = (int) $this->getClientId();
Expand Down
24 changes: 16 additions & 8 deletions modules/mod_whosonline/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ public static function getOnlineCount()
$user_array = 0;
$guest_array = 0;

$whereCondition = JFactory::getConfig()->get('shared_session', '0') ? 'IS NULL' : '= 0';

$query = $db->getQuery(true)
->select('guest, client_id')
->from('#__session')
->where('client_id ' . $whereCondition);
->from('#__session');

// Filter by client id only if shared session not enabled
if (JFactory::getConfig()->get('session_name', '') == '')
{
$query->where('client_id = 0');
}

$db->setQuery($query);

try
Expand Down Expand Up @@ -85,15 +89,19 @@ public static function getOnlineCount()
**/
public static function getOnlineUserNames($params)
{
$whereCondition = JFactory::getConfig()->get('shared_session', '0') ? 'IS NULL' : '= 0';

$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName(array('a.username', 'a.userid', 'a.client_id')))
->from('#__session AS a')
->where($db->quoteName('a.userid') . ' != 0')
->where($db->quoteName('a.client_id') . ' ' . $whereCondition)
->group($db->quoteName(array('a.username', 'a.userid', 'a.client_id')));
->group($db->quoteName(array('a.username', 'a.userid')));

// Filter by client id only if shared session not enabled
if (JFactory::getConfig()->get('session_name', '') == '')
{
$query->where($db->quoteName('a.client_id') . ' = 0');
$query->group($db->quoteName('a.client_id'));
}

$user = JFactory::getUser();

Expand Down
2 changes: 1 addition & 1 deletion plugins/user/joomla/joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function onUserLogout($user, $options = array())
return true;
}

$sharedSessions = $this->app->get('shared_session', '0');
$sharedSessions = $this->app->get('session_name', '') != '';

// Check to see if we're deleting the current session
if ($my->id == $user['id'] && (!$sharedSessions && $options['clientid'] == $this->app->getClientId()))
Expand Down

0 comments on commit eb86b91

Please sign in to comment.