Esempio n. 1
0
File: cmc.php Progetto: fracting/cmc
 /**
  * Prepares the form
  *
  * @param   array    $data    - the users data
  * @param   boolean  $isNew   - is the user new
  * @param   object   $result  - the db result
  * @param   string   $error   - the error message
  *
  * @return   boolean
  */
 public function onUserAfterSave($data, $isNew, $result, $error)
 {
     $userId = ArrayHelper::getValue($data, 'id', 0, 'int');
     $input = JFactory::getApplication()->input;
     $task = $input->get('task');
     if (in_array($task, array('register', 'activate'))) {
         if ($userId && $result && isset($data['cmc']) && count($data['cmc'])) {
             if ($data["cmc"]["newsletter"] != "1" && $isNew != false) {
                 // Abort if Newsletter is not checked
                 return true;
             }
             $mappedData = $this->getMapping($this->params->get('mapfields'), $data);
             if (count($mappedData)) {
                 $mergedGroups = array_merge($mappedData, $data['cmc_groups']);
                 $data = array_merge($data, array('cmc_groups' => $mergedGroups));
             }
             $user = JFactory::getUser($data["id"]);
             if ($data["block"] == 1) {
                 // Temporary save user
                 CmcHelperRegistration::saveTempUser($user, $data, _CPLG_JOOMLA);
             } else {
                 if (!$isNew) {
                     // Activate User to Mailchimp
                     CmcHelperRegistration::activateTempUser($user);
                 } else {
                     // Directly activate user
                     $activated = CmcHelperRegistration::activateDirectUser($user, $data["cmc"], _CPLG_JOOMLA);
                     if ($activated) {
                         JFactory::getApplication()->enqueueMessage(JText::_('COM_CMC_YOU_VE_BEEN_SUBSCRIBED_BUT_CONFIRMATION_IS_NEEDED'));
                     }
                 }
             }
         } else {
             // We only do something if the user is unblocked
             if ($data["block"] == 0) {
                 // Checking if user exists etc. is taken place in activate function
                 CmcHelperRegistration::activateTempUser(JFactory::getUser($data["id"]));
             }
         }
     }
     if (in_array($task, array('apply', 'save'))) {
         if ($userId && $result && isset($data['cmc']) && count($data['cmc'])) {
             if ($data["cmc"]["newsletter"] != "1") {
                 // Abort if Newsletter is not checked
                 return true;
             }
             $mappedData = $this->getMapping($this->params->get('mapfields'), $data);
             if (count($mappedData)) {
                 $mergedGroups = array_merge($mappedData, $data['cmc_groups']);
                 $data = array_merge($data, array('cmc_groups' => $mergedGroups));
             }
         }
         $subscription = CmcHelperUsers::getSubscription($data['email'], $data['cmc']['listid']);
         // Updating it to mailchimp
         $update = $subscription ? true : false;
         CmcHelperList::subscribe($data['cmc']['listid'], $data['email'], $data['cmc_groups']['FNAME'], $data['cmc_groups']['LNAME'], CmcHelperList::mergeVars($data), 'html', $update, true);
     }
     return true;
 }
Esempio n. 2
0
File: cmc.php Progetto: fracting/cmc
 /**
  * Activates the CMC Subcription, triggered on user activation
  *
  * @param   JUser   $user     - The JUser Obj
  * @param   string  $success  - Success string
  *
  * @return  void
  */
 public function userActivated($user, $success)
 {
     if (!$success) {
         return;
     }
     // Activates the user (after checking if he exists etc)
     CmcHelperRegistration::activateTempUser($user);
     return;
 }