Ejemplo n.º 1
0
 /**
  * Delete the user subscription
  *
  * @return void
  */
 public function delete()
 {
     JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     $user = JFactory::getUser();
     $appl = JFactory::getApplication();
     $input = $appl->input;
     $listId = $input->getString('listid');
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     if ($user->guest) {
         $appl->enqueueMessage(JText::_('COM_CMC_YOU_NEED_TO_BE_LOGGED_IN_TO_UNSUBSCRIBE'));
     }
     $query->select('*')->from('#__cmc_users')->where('(' . $db->qn('user_id') . '=' . $db->q($user->get('id')) . ' OR email = ' . $db->q($user->email) . ')')->where($db->qn('list_id') . '=' . $db->q($listId));
     $db->setQuery($query);
     $subscription = $db->loadObject();
     if ($subscription) {
         $chimp = new cmcHelperChimp();
         if ($chimp->listUnsubscribe($listId, $subscription->email)) {
             $appl->enqueueMessage(JText::_('COM_CMC_YOU_WERE_SUCCESSFULLY_UNSUBSCRIBED'));
         }
         $query->clear('select');
         $query->clear('from');
         $query->delete('#__cmc_users');
         $db->setQuery($query);
         $db->execute();
     }
     $appl->redirect($_SERVER['HTTP_REFERER']);
 }
Ejemplo n.º 2
0
 /**
  * Unsubscribes a user from the mailchimp list
  *
  * @param   object  $user  - the user object
  *
  * @throws Exception
  *
  * @return bool|string
  */
 public static function unsubscribeList($user)
 {
     $api = new cmcHelperChimp();
     $api->listUnsubscribe($user->list_id, $user->email, true);
     if ($api->errorCode) {
         throw new Exception(JTEXT::_("COM_CMC_UNSUBSCRIBE_FAILED") . ": " . $api->errorMessage, $api->errorCode);
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Deletes users subscription, does check if the table exists before
  *
  * @param   object  $user  - The Joomla user object
  *
  * @return  boolean
  */
 public static function deleteUser($user)
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     // Check for email, more valid then id
     $query->select("*")->from("#__cmc_users")->where("email = " . $db->quote($user->email));
     $db->setQuery($query);
     $res = $db->loadObject();
     if ($res == null) {
         // Nothing to delete
         return null;
     }
     $chimp = new cmcHelperChimp();
     $userlists = $chimp->listsForEmail($user->email);
     if ($userlists && in_array($res->list_id, $userlists)) {
         $chimp->listUnsubscribe($res->list_id, $user->email, false, false, true);
     }
     return true;
 }