Come avrete sicuramente notato, l' email di sistema che viene inviata all' amministratore di un sito joomla , quando un utente si registra , risulta essere effettivamente abbastanza semplice e priva di ulteriori informazioni.
In questo articolo vedremo, utilizzando la tecnica dell' override, come modificare tale email.
La tecnica dell' override permete, infatti, di effettuare agevolmente le modifiche, senza "toccare" il codice nativo joomla. Ciò, quindi, evita che, eventuali aggiornamenti di joomla, possano sovrascrivere le nostre modifiche. Ma vediamo ora come procedere. Inseriremo nella email che viene inviata all' amministratore, oltre al nome utente , nome, e sito web già presenti di default, anche l' id dell' utente che si è appena registrato e la sua email di registrazione.
Per fare ciò, sfruttiamo l' override del template e creiamo un nuovo Controller ed un nuovo Model. Il componente che modifichiamo è il com_users che gestisce gli utenti.
Il Template in esame sarà il Beez20. Spostiamoci quindi al percorso templates\beez_20\html e creiamo la cartella com_users. All' interno della com_user creiamo la cartella registration ottenendo così il percorso templates\beez_20\html\com_users\registration\
Ora copiamo il file default.php presente in components\com_users\views\registration\tmpl\ nel percorso sul template appena creato. Nel template, avremo quindi templates\beez_20\html\com_users\registration\default.php.
Già questo seplice passaggio "dice" a joomla che deve utilizzare il default.php presente sul template e non più quello del componente. Ora, apriamo il default.php copiato nel template ed apportiamo alcune piccole modifiche:
<?php
/**
* @package Joomla.Site
* @subpackage com_users
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @since 1.6
*/
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.noframes');
?>
<div class="registration<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<? echo ("questo è il nuovo registration") ?>
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration2.register'); ?>" method="post" class="form-validate">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
<fieldset>
<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.
?>
<legend><?php echo JText::_($fieldset->label);?></legend>
<?php endif;?>
<dl>
<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
<?php if ($field->hidden):// If the field is hidden, just display the input.?>
<?php echo $field->input;?>
<?php else:?>
<dt>
<?php echo $field->label; ?>
<?php if (!$field->required && $field->type!='Spacer'): ?>
<span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL'); ?></span>
<?php endif; ?>
</dt>
<dd><?php echo ($field->type!='Spacer') ? $field->input : " "; ?></dd>
<?php endif;?>
<?php endforeach;?>
</dl>
</fieldset>
<?php endif;?>
<?php endforeach;?>
<div>
<button type="submit" class="validate"><?php echo JText::_('JREGISTER');?></button>
<?php echo JText::_('COM_USERS_OR');?>
<a href="/<?php echo JRoute::_('');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration2.register" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
</div>
Ma che modifiche ho effettuato rispetto al file originale ? La prima, <? echo ("questo è il nuovo registration") ?> verso inizio file, è un debug, una echo che ho inserito per confermare che sto effettivamente utilizzando la nuova finestra di registrazione. La seconda , la riga successiva, dove ho modificato task=registration2.register al posto di registration.register e la terza modifica , in fondo al file nella imput con name=task, dove ho inserito value="registration2.register" al posto di registration.register. Ma cosa significa rigistration2.register ? Significa che, quando eseguirò l' invio dei dati di registrazione del form, richiamerò il controller registration2 del componente com_user e il suo metodo register (pattern MVC).
Creiamo quindi il controller register2. Come fare ? Semplicemente ci spostiamo su components\com_users\controllers\ , creiamo il file vuoto registration2.php e ci incolliamo dentro il medesimo contenuto del registration.php già presente nella cartella controllers. Apportiamo alcune semplici modifiche al nuovo controller registration2.php
<?php
/**
* @package Joomla.Site
* @subpackage com_users
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
require_once JPATH_COMPONENT.'/controller.php';
/**
* Registration controller class for Users.
*
* @package Joomla.Site
* @subpackage com_users
* @since 1.6
*/
class UsersControllerRegistration2 extends UsersController
{
/**
* Method to activate a user.
*
* @return boolean True on success, false on failure.
* @since 1.6
*/
public function activate()
{
$user = JFactory::getUser();
$uParams = JComponentHelper::getParams('com_users');
// If the user is logged in, return them back to the homepage.
if ($user->get('id')) {
$this->setRedirect('index.php');
return true;
}
// If user registration or account activation is disabled, throw a 403.
if ($uParams->get('useractivation') == 0 || $uParams->get('allowUserRegistration') == 0) {
JError::raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
return false;
}
$model = $this->getModel('Registration2', 'UsersModel');
$token = JRequest::getVar('token', null, 'request', 'alnum');
// Check that the token is in a valid format.
if ($token === null || strlen($token) !== 32) {
JError::raiseError(403, JText::_('JINVALID_TOKEN'));
return false;
}
// Attempt to activate the user.
$return = $model->activate($token);
// Check for errors.
if ($return === false) {
// Redirect back to the homepage.
$this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
$this->setRedirect('index.php');
return false;
}
$useractivation = $uParams->get('useractivation');
// Redirect to the login screen.
if ($useractivation == 0)
{
$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
}
elseif ($useractivation == 1)
{
$this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
}
elseif ($return->getParam('activate'))
{
$this->setMessage(JText::_('COM_USERS_REGISTRATION_VERIFY_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
}
else
{
$this->setMessage(JText::_('COM_USERS_REGISTRATION_ADMINACTIVATE_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
}
return true;
}
/**
* Method to register a user.
*
* @return boolean True on success, false on failure.
* @since 1.6
*/
public function register()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// If registration is disabled - Redirect to login page.
if(JComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0) {
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
return false;
}
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('Registration2', 'UsersModel');
// Get the user data.
$requestData = JRequest::getVar('jform', array(), 'post', 'array');
// Validate the posted data.
$form = $model->getForm();
if (!$form) {
JError::raiseError(500, $model->getError());
return false;
}
$data = $model->validate($form, $requestData);
// Check for validation errors.
if ($data === false) {
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
if ($errors[$i] instanceof Exception) {
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
} else {
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState('com_users.registration.data', $requestData);
// Redirect back to the registration screen.
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));
return false;
}
// Attempt to save the data.
$return = $model->register($data);
// Check for errors.
if ($return === false) {
// Save the data in the session.
$app->setUserState('com_users.registration.data', $data);
// Redirect back to the edit screen.
$this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));
return false;
}
// Flush the data from the session.
$app->setUserState('com_users.registration.data', null);
// Redirect to the profile screen.
if ($return === 'adminactivate'){
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
} elseif ($return === 'useractivate') {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
} else {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
}
return true;
}
}
Ora, abbiamo a che fare con il pattern MVC di programmazione adottato da joomla per cui occorre rispettare alcune semplici regole. All' inizio del file troviamo UsersControllerRegistration che diventa UsersControllerRegistration2 (l' utima parte del nome classe uguale al nome del file), poco dopo troviamo getModel('Registration', 'UsersModel') modificata in getModel('Registration2', 'UsersModel') così come un pò di righe più sotto. Queste ultime due modifiche ci fanno capire che avremo bisogno di un nuovo model , registration2, che gestirà i dati.
Nello stesso modo adottato per il controller, creiamo quindi il model registration2. Ci spostiamo su components\com_users\models\ , creiamo il file vuoto registration2.php e ci incolliamo dentro il medesimo contenuto del registration.php già presente nella cartella models. Apportiamo alcune semplici modifiche al nuovo model registration2.php , modifiche che saranno appunto quelle di inserire l' ID e la email dell' utente appena registratosi , nell' email di notifica inviata all' amministratore del sito.
<?php
/**
* @package Joomla.Site
* @subpackage com_users
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.modelform');
jimport('joomla.event.dispatcher');
/**
* Registration model class for Users.
*
* @package Joomla.Site
* @subpackage com_users
* @since 1.6
*/
class UsersModelRegistration2 extends JModelForm
{
/**
* @var object The user registration data.
* @since 1.6
*/
protected $data;
/**
* Method to activate a user account.
*
* @param string The activation token.
* @return mixed False on failure, user object on success.
* @since 1.6
*/
public function activate($token)
{
$config = JFactory::getConfig();
$userParams = JComponentHelper::getParams('com_users');
$db = $this->getDbo();
// Get the user id based on the token.
$db->setQuery(
'SELECT '.$db->quoteName('id').' FROM '.$db->quoteName('#__users') .
' WHERE '.$db->quoteName('activation').' = '.$db->Quote($token) .
' AND '.$db->quoteName('block').' = 1' .
' AND '.$db->quoteName('lastvisitDate').' = '.$db->Quote($db->getNullDate())
);
$userId = (int) $db->loadResult();
// Check for a valid user id.
if (!$userId) {
$this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND'));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Activate the user.
$user = JFactory::getUser($userId);
// Admin activation is on and user is verifying their email
if (($userParams->get('useractivation') == 2) && !$user->getParam('activate', 0))
{
$uri = JURI::getInstance();
// Compile the admin notification mail values.
$data = $user->getProperties();
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$user->set('activation', $data['activation']);
$data['siteurl'] = JUri::base();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$user->setParam('activate', 1);
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
$data['name'],
$data['sitename']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
$data['sitename'],
$data['name'],
$data['email'],
$data['username'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']
);
// get all admin users
$query = 'SELECT name, email, sendEmail, id' .
' FROM #__users' .
' WHERE sendEmail=1';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send mail to all users with users creating permissions and receiving system emails
foreach( $rows as $row )
{
$usercreator = JFactory::getUser($id = $row->id);
if ($usercreator->authorise('core.create', 'com_users'))
{
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
}
}
//Admin activation is on and admin is activating the account
elseif (($userParams->get('useractivation') == 2) && $user->getParam('activate', 0))
{
$user->set('activation', '');
$user->set('block', '0');
$uri = JURI::getInstance();
// Compile the user activated notification mail values.
$data = $user->getProperties();
$user->setParam('activate', 0);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::base();
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT',
$data['name'],
$data['sitename']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY',
$data['name'],
$data['siteurl'],
$data['username']
);
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
else
{
$user->set('activation', '');
$user->set('block', '0');
}
// Store the user object.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
return false;
}
return $user;
}
/**
* Method to get the registration form data.
*
* The base form data is loaded and then an event is fired
* for users plugins to extend the data.
*
* @return mixed Data object on success, false on failure.
* @since 1.6
*/
public function getData()
{
if ($this->data === null) {
$this->data = new stdClass();
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_users');
// Override the base user data with any data in the session.
$temp = (array)$app->getUserState('com_users.registration.data', array());
foreach ($temp as $k => $v) {
$this->data->$k = $v;
}
// Get the groups the user should be added to after registration.
$this->data->groups = array();
// Get the default new user group, Registered if not specified.
$system = $params->get('new_usertype', 2);
$this->data->groups[] = $system;
// Unset the passwords.
unset($this->data->password1);
unset($this->data->password2);
// Get the dispatcher and load the users plugins.
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('user');
// Trigger the data preparation event.
$results = $dispatcher->trigger('onContentPrepareData', array('com_users.registration', $this->data));
// Check for errors encountered while preparing the data.
if (count($results) && in_array(false, $results, true)) {
$this->setError($dispatcher->getError());
$this->data = false;
}
}
return $this->data;
}
/**
* Method to get the registration form.
*
* The base form is loaded from XML and then an event is fired
* for users plugins to extend the form with extra fields.
*
* @param array $data An optional array of data for the form to interogate.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_users.registration', 'registration', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
return $this->getData();
}
/**
* Override preprocessForm to load the user plugin group instead of content.
*
* @param object A form object.
* @param mixed The data expected for the form.
* @throws Exception if there is an error in the form event.
* @since 1.6
*/
protected function preprocessForm(JForm $form, $data, $group = 'user')
{
$userParams = JComponentHelper::getParams('com_users');
//Add the choice for site language at registration time
if ($userParams->get('site_language') == 1 && $userParams->get('frontend_userparams') == 1)
{
$form->loadFile('sitelang', false);
}
parent::preprocessForm($form, $data, $group);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
// Get the application object.
$app = JFactory::getApplication();
$params = $app->getParams('com_users');
// Load the parameters.
$this->setState('params', $params);
}
/**
* Method to save the form data.
*
* @param array The form data.
* @return mixed The user id on success, false on failure.
* @since 1.6
*/
public function register($temp)
{
$config = JFactory::getConfig();
$db = $this->getDbo();
$params = JComponentHelper::getParams('com_users');
// Initialise the table with JUser.
$user = new JUser;
$data = (array)$this->getData();
// Merge in the registration data.
foreach ($temp as $k => $v) {
$data[$k] = $v;
}
// Prepare the data for the user object.
$data['email'] = $data['email1'];
$data['password'] = $data['password1'];
$useractivation = $params->get('useractivation');
$sendpassword = $params->get('sendpassword', 1);
// Check if the user needs to activate their account.
if (($useractivation == 1) || ($useractivation == 2)) {
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$data['block'] = 1;
}
// Bind the data.
if (!$user->bind($data)) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Store the data.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
// Compile the notification mail values.
$data = $user->getProperties();
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::root();
// Handle account activation/confirmation emails.
if ($useractivation == 2)
{
// Set the link to confirm the user email.
$uri = JURI::getInstance();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
$data['name'],
$data['sitename']
);
if ($sendpassword)
{
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
$data['name'],
$data['sitename'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
$data['siteurl'],
$data['username'],
$data['password_clear']
);
}
else
{
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW',
$data['name'],
$data['sitename'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
$data['siteurl'],
$data['username']
);
}
}
elseif ($useractivation == 1)
{
// Set the link to activate the user account.
$uri = JURI::getInstance();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
$data['name'],
$data['sitename']
);
if ($sendpassword)
{
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY',
$data['name'],
$data['sitename'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
$data['siteurl'],
$data['username'],
$data['password_clear']
);
}
else
{
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW',
$data['name'],
$data['sitename'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
$data['siteurl'],
$data['username']
);
}
}
else
{
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
$data['name'],
$data['sitename']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_BODY',
$data['name'],
$data['sitename'],
$data['siteurl']
);
}
// Send the registration email.
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
//Send Notification mail to administrators
if (($params->get('useractivation') < 2) && ($params->get('mail_to_admin') == 1)) {
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
$data['name'],
$data['sitename']
);
$emailBodyAdmin = JText::sprintf(
'COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY',
$data['name'],
$data['username'],
$data['siteurl']
);
$emailBodyAdmin .= " La sua email di registrazione è ".$data['email'];
$emailBodyAdmin .= " Il suo ID è ".$data['id'];
// get all admin users
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE sendEmail=1';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send mail to all superadministrators id
foreach( $rows as $row )
{
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
}
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
// Send a system message to administrators receiving system mails
$db = JFactory::getDBO();
$q = "SELECT id
FROM #__users
WHERE block = 0
AND sendEmail = 1";
$db->setQuery($q);
$sendEmail = $db->loadColumn();
if (count($sendEmail) > 0) {
$jdate = new JDate();
// Build the query to add the messages
$q = "INSERT INTO ".$db->quoteName('#__messages')." (".$db->quoteName('user_id_from').
", ".$db->quoteName('user_id_to').", ".$db->quoteName('date_time').
", ".$db->quoteName('subject').", ".$db->quoteName('message').") VALUES ";
$messages = array();
foreach ($sendEmail as $userid) {
$messages[] = "(".$userid.", ".$userid.", '".$jdate->toSql()."', '".JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')."', '".JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])."')";
}
$q .= implode(',', $messages);
$db->setQuery($q);
$db->query();
}
return false;
}
if ($useractivation == 1)
return "useractivate";
elseif ($useractivation == 2)
return "adminactivate";
else
return $user->id;
}
}
All' inizio del file troviamo la classe UsersModelRegistration che diventa UsersModelRegistration2 , verso la fine del file , nella parte commentata //send notification mail to Administrator , troviamo 2 righe che sono la modifica che volevamo e cioè, l' aggiunta dell' ID utente ed email utente che si è appena registrato , $emailBodyAdmin .= " La sua email di registrazione è ".$data['email']; e la successiva $emailBodyAdmin .= " Il suo ID è ".$data['id'];
A questo punto, non rimane altro che fare una prova di registrazione e constatare la nuova email di notifica inviata all' amministratore. Come potete notare, le modifiche al codice sono molto semplici, abbiamo rispettato il pattern MVC e utilizzato l' override. L' unico problema è trovare il punto preciso ove intervenire nel codice. Ma questo , con un pò di esperienza, uno strumento di debug (netbeans) e conoscendo come "gira" il pattern MVC di joomla, non risulta poi così complicato da realizzare , anche per future modifiche.
Pensi che questo articolo possa essere d' aiuto anche ad altri? Allora condividilo subito nel tuo social preferito.
Lascia i tuoi commenti
Login per inviare un commento
Posta commento come visitatore