| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/dansnotreville-fr/plugins/system/jomsocialredirect/ |
Upload File : |
<?php
/**
* @copyright (C) 2013 iJoomla, Inc. - All rights reserved.
* @license GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html)
* @author iJoomla.com <webmaster@ijoomla.com>
* @url https://www.jomsocial.com/license-agreement
* The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0
* More info at https://www.jomsocial.com/license-agreement
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
* Class exists checking
*/
if (!class_exists('plgSystemjomsocialredirect')) {
/**
* Plugin entrypoint
* @link http://docs.joomla.org/Plugin/Events/System
*/
class plgSystemjomsocialredirect extends JPlugin {
/**
* Construct method
* @param type $subject
* @param type $config
*/
function __construct($subject, $config) {
parent::__construct($subject, $config);
$this->loadLanguage();
if (JFactory::getApplication()->isClient('site')) {
include_once( JPATH_ROOT . '/components/com_community/libraries/core.php' );
}
}
/**
* This event is triggered after the framework has loaded and the application initialise method has been called.
*/
public function onAfterRoute() {
$jinput = JFactory::getApplication()->input;
if (JFactory::getApplication()->isClient('site')) {
$option = $jinput->get('option');
if ($option == 'com_user' || $option == 'com_users') {
$this->overrideComUserRegistration();
$this->overrideRedirectLoginLogout();
}
}
}
/**
* New event to be triged when FB user login
* @return string
*/
public function onAfterFBUserLogin() {
$mainframe = JFactory::getApplication();
$jinput = $mainframe->input;
/* override redirect after login / logout */
$task = $jinput->get('task');
$link = $this->getMenuLink($this->params->get('redirect_login', 1));
if ($this->params->get('redirect_previous') == 1) {
$session = JFactory::getSession();
$session->set('redirect_previous_url', $_SERVER['HTTP_REFERER']);
$link = $session->get('redirect_previous_url', $link);
}
return $link;
}
/**
* Method to override Login / Logout redirect
*/
private function overrideRedirectLoginLogout() {
$mainframe = JFactory::getApplication();
$jinput = $mainframe->input;
/* override redirect after login / logout */
$task = $jinput->get('task');
$return = $jinput->get('return', '');
if ($this->params->get('redirect_previous') == 1) {
/* in com_user we need to save reference url for these tasks to know previous page */
if ($task === 'user.login' || $task === 'login' || $task === 'user.logout' || $task === 'logout') {
$session = JFactory::getSession();
$session->set('redirect_previous_url', $_SERVER['HTTP_REFERER']);
}
}
switch ($task) {
case 'user.login' : //Joomla 1.6 and later
case 'login' : /* on logging */
if ($this->login()) { /* we do login by self */
/* redirect if login success */
$link = $this->getMenuLink($this->params->get('redirect_login', 1));
if (preg_match("/index.php\?Itemid=1/", $link)) {
$link = CRoute::_('index.php?option=com_community&view=frontpage', false);
}
$app = JFactory::getApplication();
$returnUrl = base64_decode($app->input->getBase64('return'));
if(strpos($returnUrl, 'ajaxlogin') !== false) {
$link = $returnUrl;
} else {
if ($this->params->get('redirect_previous') == 1) {
$session = JFactory::getSession();
$link = $session->get('redirect_previous_url', $link);
}
}
if(count($mainframe->getMessageQueue()) == 0){
if ($this->params->get('redirect_login_message_show', 1)) {
$mainframe->enqueueMessage(JText::_($this->params->get('redirect_login_msg', 'LOGIN_SUCCESSFUL')), 'message');
$mainframe->redirect($link);
} else {
$mainframe->redirect($link);
}
}
} else {
/* redirect if login failed */
$link = $this->getMenuLink($this->params->get('redirect_login_failed', 1));
if (preg_match("/index.php\?Itemid=1/", $link)) {
$link = CRoute::_('index.php?option=com_community&view=frontpage', false);
}
if ($this->params->get('redirect_previous') == 1) {
$session = JFactory::getSession();
$link = $session->get('redirect_previous_url', $link);
}
if ($this->params->get('redirect_login_failed_message_show', 1)) {
$mainframe->enqueueMessage(JText::_($this->params->get('redirect_login_failed_msg', 'LOGIN_FAILED')), 'notice');
$mainframe->redirect($link);
} else {
$mainframe->redirect($link);
}
}
break;
case 'user.logout' : //Joomla 1.6 and later
case 'logout' :
$link = $this->getMenuLink($this->params->get('redirect_logout', 1));
if (preg_match("/index.php\?Itemid=1/", $link)) {
$link = CRoute::_('index.php?option=com_community&view=frontpage', false);
}
if ($this->params->get('redirect_previous') == 1) {
$session = JFactory::getSession();
$link = $session->get('redirect_previous_url', $link);
}
JFactory::getApplication()->logout();
// deprecated
// if ($this->params->get('redirect_logout_message_show', 1)) {
// $mainframe->redirect($link, JText::_($this->params->get('redirect_logout_msg', 'YOU_HAVE_LOGGED_OUT')), 'message');
// } else {
// $mainframe->redirect($link);
// }
$mainframe->redirect($link);
break;
default :
break;
}
}
/**
* Method to redirect com_user registration to JomSocial registration
*/
private function overrideComUserRegistration() {
$mainframe = JFactory::getApplication();
$jinput = $mainframe->input;
$view = $jinput->get('view');
/* override Joomla com_user registration by JomSocial registration */
if ($view == 'register' || $view == 'registration') {
/* index.php?option=com_user&view=register */
if ($this->params->get('override_com_user_registration', 1) == 1) {
$jsRegistrationLink = 'index.php?option=com_community&view=register';
$jsRegistrationLink = CRoute::_($jsRegistrationLink);
//JFactory::getApplication ()->enqueueMessage ( $jsRegistrationLink );
if ($this->params->get('redirect_register_message_show', 1)) {
$mainframe->enqueueMessage(JText::_($this->params->get('redirect_registration_msg', 'REDIRECTED_TO_COMMUNITY_REGISTRATION')), 'message');
$mainframe->redirect($jsRegistrationLink);
} else {
$mainframe->redirect($jsRegistrationLink);
}
}
}
}
/**
* Method to login
* This method will call Application login and force to return true / false
* We will show message override authentication event
* @return boolean
*/
private function login() {
/**
* @param array $credentials Array('username' => string, 'password' => string)
* @param array $options Array('remember' => boolean)
*/
$jinput = JFactory::getApplication()->input;
$credentials ['username'] = $jinput->get('username',null,'username');
$credentials ['password'] = $jinput->get('passwd',null,'string');
$credentials ['secretkey'] = $jinput->get('secretkey',null,'string');
if ($credentials ['password'] == '') {
//try to detect for joomla 1.6, 17
$credentials ['password'] = $jinput->get('password',null,'string');
}
$options ['silent'] = true; /* force turn true / false of login function instead error msg */
$options ['remember'] = $jinput->get('remember');
return JFactory::getApplication()->login($credentials, $options);
}
/**
* Private method to get JomSocial itemId
* If have no itemId will return itemId of current page
* @return int
*/
private function getItemId() {
$jsFrontpageLink = 'index.php?option=com_community&view=frontpage';
$jinput = JFactory::getApplication()->input;
$db = JFactory::getDBO();
$query = ' SELECT id FROM #__menu WHERE link = ' . $db->quote($jsFrontpageLink) . ' AND published = 1 ';
$db->setQuery($query);
$itemId = $db->loadResult();
if (!$itemId) {
$itemId = $jinput->get('Itemid');
}
return $itemId;
}
/**
*
* @param int $Itemid
* @return string
*/
private function getMenuLink($Itemid) {
if ($Itemid == 1) {
return JUri::root();
}
$db = JFactory::getDBO();
$query = ' SELECT menutype,link FROM #__menu WHERE id = ' . $db->quote($Itemid) . ' AND published = 1 ';
$db->setQuery($query);
$menu = $db->loadObject();
if (!empty($menu)) {
if ($menu->menutype == 'jomsocial') {
//for toolbar menu item
$url = CRoute::_($menu->link, false);
} else {
$url = JRoute::_($menu->link . "&Itemid=" . $Itemid, false); // use JRoute to make link from object
}
} else {
$url = JRoute::_(JURI::root(), false);
}
return $url;
}
}
}