Esempio n. 1
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;
 }
Esempio n. 2
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. 3
0
File: cmc.php Progetto: fracting/cmc
 /**
  * Checks if we have a subscription and then does what is necessary - either activating it
  * on the fly
  *
  * @param   array    $data    - the user data
  * @param   boolean  $isNew   - true if the user is new
  * @param   boolean  $result  - the result of the save
  * @param   object   $error   - the error if any
  *
  * @return void
  */
 public function onUserAfterSave($data, $isNew, $result, $error)
 {
     /**
      * Jomsocial is calling the onUserAfterSave function around 3 times
      * During the registration process. Because of that we end up sending 3
      * Emails telling the user to subscribe. Since this is stupid, we'll mark
      * if we've sent a mail and won't try to do it over and over again
      */
     static $mailSent = false;
     // If we have a token, let us check if we have a subscription
     // And if we do, set the correct user_id
     if (isset($data['token'])) {
         $subscription = $this->getSubscription($data['token']);
         if ($subscription) {
             $this->updateUserId($data['id'], $data['token']);
         }
     }
     // Now let us check if we have a subscription for the user id, this time using the user id
     $subscription = $this->getSubscription($data['id']);
     if ($subscription && !$mailSent) {
         if ($data["block"] == 0) {
             $json = json_decode($subscription->params, true);
             // Directly activate user
             CmcHelperRegistration::activateDirectUser(JFactory::getUser($data["id"]), $json, _CPLG_JOMSOCIAL);
             $mailSent = true;
         }
     }
 }