Beispiel #1
0
 /**
  * Method to bind an associative array or object to the JTable instance.This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  * @throws  InvalidArgumentException
  */
 public function bind($src, $ignore = array())
 {
     // If we have cmc_groups or cmc_intersts, than this would mean that we are coming from the form
     if (isset($src['cmc_groups']) || isset($src['cmc_interests'])) {
         $src['merges'] = CmcHelperList::mergeVars($src);
     }
     return parent::bind($src, $ignore);
 }
Beispiel #2
0
 /**
  * Method to get the field input markup.
  *
  * @return string
  */
 public function getInput()
 {
     $listid = $this->form->getValue('listid', 'params');
     $options = CmcHelperList::getInterestsFields($listid);
     $key = 'id';
     $val = 'name';
     $attribs = 'multiple="multiple" size="8" class="chzn-none chzn-done"';
     if ($options) {
         $content = JHtml::_('select.genericlist', $options, 'jform[params][interests][]', $attribs, $key, $val, $this->value, $this->id);
     } else {
         $content = '<div style="float:left;">' . JText::_('MOD_CMC_NO_INTEREST_GROUPS') . '</div>';
     }
     return $content;
 }
Beispiel #3
0
 /**
  * Method to get the record form.
  *
  * @param   array    $data      An optional array of data for the form to interogate.
  * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  *
  * @return    JForm    A JForm object on success, false on failure
  */
 public function getForm($data = array(), $loadData = true)
 {
     // Get the form.
     $form = $this->loadForm('com_cmc.user', 'user', array('control' => 'jform', 'load_data' => $loadData));
     $userData = $this->getItem();
     // If the user data is stored in the session we are dealing with arrays, if we are loading from DB with object
     if (is_array($userData)) {
         $old = $userData;
         $userData = new JRegistry();
         $userData->set('list_id', $old['list_id']);
         $userData->set('email', $old['cmc_groups']['email']);
     } elseif (is_object($userData) && !$userData->get('id')) {
         $userData = new JRegistry();
         $userData->set('list_id', isset($data['list_id']) ? $data['list_id'] : '');
         $userData->set('email', isset($data['cmc_groups']['EMAIL']) ? $data['cmc_groups']['EMAIL'] : '');
     }
     $listId = $userData->get('list_id', JFactory::getApplication()->input->get('filter_list'));
     // Get the merge fields and create a new form
     if ($listId) {
         $params = new JRegistry();
         $params->set('listid', $listId);
         $fields = array_map(function ($value) {
             return $value['tag'];
         }, CmcHelperList::getMergeFields($listId));
         $interests = array_map(function ($value) {
             return $value['id'];
         }, CmcHelperList::getInterestsFields($listId));
         $params->set('fields', $fields);
         $params->set('interests', $interests);
         $renderer = CmcHelperXmlbuilder::getInstance($params);
         // Generate the xml for the form
         $xml = $renderer->build();
         $form->load($xml, true);
         $subscriptionData = CmcHelperUsers::getSubscription($userData->get('email'), $userData->get('list_id'));
         // Bind the data to the form
         if ($subscriptionData) {
             $form->bind(CmcHelperSubscription::convertMergesToFormData($subscriptionData->merges));
         }
     }
     if (empty($form)) {
         return false;
     }
     return $form;
 }
Beispiel #4
0
 /**
  * Checks if the current user exists in the mailchimp database
  *
  * @throws Exception
  *
  * @return void
  */
 public function exist()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $chimp = new cmcHelperChimp();
     $input = JFactory::getApplication()->input;
     $form = $input->get('jform', '', 'array');
     $mergeVars = CmcHelperList::mergeVars($form);
     $email = $mergeVars['EMAIL'];
     $listId = $form['cmc']['listid'];
     // Check if the user is in the list already
     $userlists = $chimp->listsForEmail($email);
     if ($userlists && in_array($listId, $userlists)) {
         $exist = true;
         $url = JRoute::_('index.php?option=com_cmc&task=subscription.update&email=' . $email . '&listid=' . $listId);
     } else {
         $exist = false;
         $url = '';
     }
     echo json_encode(array('exists' => $exist, 'url' => $url));
     jexit();
 }
Beispiel #5
0
 /**
  * Initialize the sync process
  *
  * @return void
  */
 public function start()
 {
     // Check for a valid token. If invalid, send a 403 with the error message.
     JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
     // Put in a buffer to silence noise.
     ob_start();
     // Initiate an empty state
     CmcSyncerState::resetState();
     $state = CmcSyncerState::getState();
     $input = JFactory::getApplication()->input;
     $lists = $input->getString('lists');
     $chimp = new CmcHelperChimp();
     $listStats = $chimp->lists(array('list_id' => $lists));
     $names = array();
     foreach ($listStats['data'] as $key => $list) {
         $state->lists[$key] = array();
         $state->lists[$key]['mc_id'] = $list['id'];
         $state->lists[$key]['name'] = $list['name'];
         $state->lists[$key]['toSync'] = $list['stats']['member_count'];
         $names[] = $list['name'];
         // Delete the old list info
         CmcHelperList::delete($list['id']);
         // Add the new list info
         $listModel = $this->getModel('List', 'cmcModel');
         $listModel->save($list);
         // Add the joomla list id
         $state->lists[$key]['id'] = $listModel->getState('list.id');
         // Delete users in that list
         CmcHelperUsers::delete($list['id']);
     }
     $state->header = JText::sprintf('COM_CMC_LISTS_TO_SYNC', count($state->lists));
     $state->message = JText::sprintf('COM_CMC_LISTS_TO_SYNC_DESC', '"' . implode('", "', $names) . '"', $state->lists[0]['name']);
     $state->offset = 0;
     CmcSyncerState::setState($state);
     $this->sendResponse($state);
 }
Beispiel #6
0
 /**
  * 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;
 }