/** * Method to get the field input markup. * * @return string */ public function getInput() { $content = ''; $api = new cmcHelperChimp(); $lists = $api->lists(); $key = 'id'; $val = 'name'; $options[] = array($key => '', $val => '-- ' . JText::_('MOD_CMC_PLEASE_SELECT_A_LIST') . ' --'); foreach ($lists['data'] as $list) { $options[] = array($key => $list[$key], $val => $list[$val]); } $option = JFactory::getApplication()->input->get('option'); $controller = in_array($option, array('com_modules', 'com_advancedmodules')) ? 'module' : 'plugin'; $attribs = "onchange='submitbutton(\"{$controller}.apply\")'"; if ($options) { $content = JHtml::_('select.genericlist', $options, 'jform[params][listid]', $attribs, $key, $val, $this->value, $this->id); } return $content; }
/** * Sends an email with information how to update the form * * @return bool */ public function update() { $appl = JFactory::getApplication(); $input = $appl->input; $listId = $input->getString('listid'); $email = $input->getString('email'); $mailer = JFactory::getMailer(); $chimp = new cmcHelperChimp(); if (!$listId && !$email) { $appl->enqueueMessage(JText::_('COM_CMC_INVALID_LIST_OR_EMAIL')); $appl->redirect($_SERVER['HTTP_REFERER']); return false; } $dc = "us1"; if (strstr($chimp->api_key, "-")) { list($key, $dc) = explode("-", $chimp->api_key, 2); if (!$dc) { $dc = "us1"; } } $account = $chimp->getAccountDetails(); $memberInfo = $chimp->listMemberInfo($listId, $email); $listInfo = $chimp->lists(array('list_id' => $listId)); $url = 'http://' . $account['username'] . '.' . $dc . '.list-manage.com/profile?u=' . $account['user_id'] . '&id=' . $listId . '&e=' . $memberInfo['data'][0]['euid']; $subject = JText::sprintf('COM_CMC_CHANGE_YOUR_SUBSCRIPTION_PREFERENCES_EMAIL_TITLE', $listInfo['data'][0]['name']); $text = JText::sprintf('COM_CMC_CHANGE_YOUR_SUBSCRIPTION_PREFERENCES_EMAIL_CONTENT', $listInfo['data'][0]['name'], $url); $config = JFactory::getConfig(); if ($mailer->sendMail($config->get('mailfrom'), $config->get('fromname'), $email, $subject, $text, true)) { $appl->enqueueMessage(JText::sprintf('COM_CMC_EMAIL_WITH_FURTHER_INSTRUCTIONS_UPDATE', $email)); $appl->redirect($_SERVER['HTTP_REFERER']); return true; } $appl->enqueueMessage(JText::_('COM_CMC_SOMETHING_WENT_WRONG')); $appl->redirect($_SERVER['HTTP_REFERER']); return false; }
/** * Loads the list values for the plugin * * @return mixed */ public function loadLists() { $api = new cmcHelperChimp(); $lists = $api->lists(); // Get the plugin (No this->params) any longer $plugin = GetCmcTab::getPlugin(); $key = 'id'; $val = 'name'; $options[] = array($key => '', $val => '-- ' . JText::_('Please select') . ' --'); foreach ($lists['data'] as $list) { $options[] = array($key => $list[$key], $val => $list[$val]); } $attribs = "onchange='submitbutton(\"act=apply\")'"; if ($options) { $content = JHtml::_('select.genericlist', $options, 'params[listid]', $attribs, $key, $val, $plugin->params->get('listid', "")); } return $content; }