Source for file contactcreator.php

Documentation is available at contactcreator.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  User.contactcreator
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Class for Contact Creator
  14.  *
  15.  * A tool to automatically create and synchronise contacts with a user
  16.  *
  17.  * @package     Joomla.Plugin
  18.  * @subpackage  User.contactcreator
  19.  * @since       1.6
  20.  */
  21. {
  22.     /**
  23.      * Load the language file on instantiation.
  24.      *
  25.      * @var    boolean 
  26.      * @since  3.1
  27.      */
  28.     protected $autoloadLanguage = true;
  29.  
  30.     public function onUserAfterSave($user$isnew$success$msg)
  31.     {
  32.         if (!$success)
  33.         {
  34.             return false// if the user wasn't stored we don't resync
  35.         }
  36.  
  37.         if (!$isnew)
  38.         {
  39.             return false// if the user isn't new we don't sync
  40.         }
  41.  
  42.         // ensure the user id is really an int
  43.         $user_id = (int) $user['id'];
  44.  
  45.         if (empty($user_id))
  46.         {
  47.             die('invalid userid');
  48.             return false// if the user id appears invalid then bail out just in case
  49.         }
  50.  
  51.         $category $this->params->get('category'0);
  52.         if (empty($category))
  53.         {
  54.             JError::raiseWarning(41JText::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'));
  55.             return false// bail out if we don't have a category
  56.         }
  57.  
  58.         $db JFactory::getDbo();
  59.         // grab the contact ID for this user; note $user_id is cleaned above
  60.         $db->setQuery('SELECT id FROM #__contact_details WHERE user_id = '$user_id);
  61.         $id $db->loadResult();
  62.  
  63.         JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_contact/tables');
  64.         $contact JTable::getInstance('contact''ContactTable');
  65.  
  66.         if (!$contact)
  67.         {
  68.             return false;
  69.         }
  70.  
  71.         if ($id)
  72.         {
  73.             $contact->load($id);
  74.         }
  75.         elseif ($this->params->get('autopublish'0))
  76.         {
  77.             $contact->published 1;
  78.         }
  79.  
  80.         $contact->name $user['name'];
  81.         $contact->user_id $user_id;
  82.         $contact->email_to $user['email'];
  83.         $contact->catid $category;
  84.         $contact->language '*';
  85.  
  86.         $autowebpage $this->params->get('autowebpage''');
  87.  
  88.         if (!empty($autowebpage))
  89.         {
  90.             // search terms
  91.             $search_array array('[name]''[username]''[userid]''[email]');
  92.             // replacement terms, urlencoded
  93.             $replace_array array_map('urlencode'array($user['name']$user['username']$user['id']$user['email']));
  94.             // now replace it in together
  95.             $contact->webpage str_replace($search_array$replace_array$autowebpage);
  96.         }
  97.  
  98.         if ($contact->check())
  99.         {
  100.             $result $contact->store();
  101.         }
  102.  
  103.         if (!(isset($result)) || !$result)
  104.         {
  105.             JError::raiseError(42JText::sprintf('PLG_CONTACTCREATOR_ERR_FAILED_UPDATE'$contact->getError()));
  106.         }
  107.     }
  108. }

Documentation generated on Tue, 19 Nov 2013 14:56:42 +0100 by phpDocumentor 1.4.3