- md5
- 21de99f52c8f413f2bf21872914bf112
- sha1
- 84367c89aad3deeb390d2a8d52d9960d098ed153
- sha256
- ed8945af38a57614f029d20504112b5a926df24e8177cce195c8014d854eaedb
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
<?php
/**
* @package Joomla.Plugin
* @subpackage User.contactcreator
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Class for Contact Creator
*
* A tool to automatically create and synchronise contacts with a user
*
* @package Joomla.Plugin
* @subpackage User.contactcreator
* @since 1.6
*/
class plgUserContactCreator extends JPlugin
{
/**
* Constructor
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.5
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
public function onUserAfterSave($user, $isnew, $success, $msg)
{
if (!$success)
{
return false; // if the user wasn't stored we don't resync
}
if (!$isnew)
{
return false; // if the user isn't new we don't sync
}
// ensure the user id is really an int
$user_id = (int) $user['id'];
if (empty($user_id))
{
die('invalid userid');
return false; // if the user id appears invalid then bail out just in case
}
$category = $this->params->get('category', 0);
if (empty($category))
{
JError::raiseWarning(41, JText::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'));
return false; // bail out if we don't have a category
}
$dbo = JFactory::getDBO();
// grab the contact ID for this user; note $user_id is cleaned above
$dbo->setQuery('SELECT id FROM #__contact_details WHERE user_id = '. $user_id);
$id = $dbo->loadResult();
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_contact/tables');
$contact = JTable::getInstance('contact', 'ContactTable');
if (!$contact)
{
return false;
}
if ($id)
{
$contact->load($id);
}
elseif ($this->params->get('autopublish', 0))
{
$contact->published = 1;
}
$contact->name = $user['name'];
$contact->user_id = $user_id;
$contact->email_to = $user['email'];
$contact->catid = $category;
$autowebpage = $this->params->get('autowebpage', '');
if (!empty($autowebpage))
{
// search terms
$search_array = array('[name]', '[username]', '[userid]', '[email]');
// replacement terms, urlencoded
$replace_array = array_map('urlencode', array($user['name'], $user['username'], $user['id'], $user['email']));
// now replace it in together
$contact->webpage = str_replace($search_array, $replace_array, $autowebpage);
}
if ($contact->check())
{
$result = $contact->store();
}
if (!(isset($result)) || !$result)
{
JError::raiseError(42, JText::sprintf('PLG_CONTACTCREATOR_ERR_FAILED_UPDATE', $contact->getError()));
}
}
}
The same content is in 2 releases, Joomla 3.0.3 to 3.0.4. See them all, or every version of this file.