Move code into a function, changed redirect plugin behaviour BT#13691

- Now always redirect from /index.php to the user's URL if selected.
pull/2487/head
Julio 8 years ago
parent 95cbe85d0e
commit 9b7bfbd453
  1. 9
      index.php
  2. 19
      main/inc/lib/redirect.class.php
  3. 5
      plugin/redirection/README.md
  4. 24
      plugin/redirection/RedirectionPlugin.php

@ -1,16 +1,23 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* @package chamilo.main
*/
define('CHAMILO_HOMEPAGE', true);
define('CHAMILO_LOAD_WYSIWYG', false);
/* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
// Maybe we should change this into an api function? an example: CourseManager::unset();
$cidReset = true;
require_once 'main/inc/global.inc.php';
//require_once 'main/auth/external_login/facebook.inc.php';
$allow = api_get_configuration_value('plugin_redirection_enabled');
if ($allow) {
RedirectionPlugin::redirectUser(api_get_user_id());
}
// The section (for the tabs).
$this_section = SECTION_CAMPUS;
$header_title = null;

@ -73,21 +73,9 @@ class Redirect
if (isset($user_id)) {
$allow = api_get_configuration_value('plugin_redirection_enabled');
if ($allow) {
// Check redirection plugin
$plugin = new AppPlugin();
$pluginList = $plugin->get_installed_plugins();
$redirectionInstalled = in_array('redirection', $pluginList);
if ($redirectionInstalled) {
$pluginInfo = $plugin->getPluginInfo('redirection');
if (!empty($pluginInfo) && isset($pluginInfo['obj'])) {
/** @var RedirectionPlugin $redirectionPlugin */
$redirectionPlugin = $pluginInfo['obj'];
$record = $redirectionPlugin->getUrlFromUser($user_id);
if (!empty($record) && !empty($record['url'])) {
header('Location: '.$record['url']);
exit;
}
}
$allow = api_get_configuration_value('plugin_redirection_enabled');
if ($allow) {
RedirectionPlugin::redirectUser($user_id);
}
}
@ -143,7 +131,6 @@ class Redirect
if (!empty($page_after_login)) {
self::navigate(api_get_path(WEB_PATH).$page_after_login);
}
}
}

@ -1,7 +1,8 @@
Redirection plugin
===
Chamilo plugin for the redirection of specific users after they login.
Chamilo plugin for the redirection of specific users after they login and
redirect from the index.php to the selected URL.
Requires the addition of the following in configuration.php:
@ -12,4 +13,4 @@ $_configuration['plugin_redirection_enabled'] = true;
This setting is defined in configuration.php rather than in settings_current to reduce the
load, as it is used on every login.
@TODO Check the load difference for *just* checking it in settings_current rather than building the plugin object
@TODO Check the load difference for *just* checking it in settings_current rather than building the plugin object

@ -129,4 +129,28 @@ class RedirectionPlugin extends Plugin
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
}
/**
* Redirect user if plugin is installed
* @param int $userId
*/
public static function redirectUser($userId)
{
// Check redirection plugin
$plugin = new AppPlugin();
$pluginList = $plugin->get_installed_plugins();
$redirectionInstalled = in_array('redirection', $pluginList);
if ($redirectionInstalled) {
$pluginInfo = $plugin->getPluginInfo('redirection');
if (!empty($pluginInfo) && isset($pluginInfo['obj'])) {
/** @var RedirectionPlugin $redirectionPlugin */
$redirectionPlugin = $pluginInfo['obj'];
$record = $redirectionPlugin->getUrlFromUser($userId);
if (!empty($record) && !empty($record['url'])) {
header('Location: '.$record['url']);
exit;
}
}
}
}
}

Loading…
Cancel
Save