public function getInput() { jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); if (!JFile::exists(JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php')) { $mainframe->enqueueMessage(JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'), 'error'); $mainframe->redirect('index.php'); } $listId = $this->form->getValue('listid', 'params'); require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php'; $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $api = new joomlamailerMCAPI($MCapi); $interests = $api->listInterestGroupings($listId); $options = array(); if ($interests) { foreach ($interests as $interest) { if ($interest['form_field'] != 'hidden') { $groups = array(); foreach ($interest['groups'] as $ig) { $groups[] = $ig['name']; } $groups = implode('####', $groups); $options[] = array('id' => $interest['id'] . ';' . $interest['form_field'] . ';' . $interest['name'] . ';' . $groups, 'name' => $interest['name']); } } } if (count($options)) { return JHtml::_('select.genericlist', $options, 'jform[params][interests][]', 'multiple="multiple"', 'id', 'name', $this->value, $this->id); } else { return JText::_('JM_NO_INTEREST_GROUPS'); } }
public function getInput() { jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); if (!JFile::exists(JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php')) { $mainframe->enqueueMessage(JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'), 'error'); $mainframe->redirect('index.php'); } jimport('joomla.plugin.plugin'); require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php'; require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/helpers/JoomlamailerMC.php'; $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $JoomlamailerMC = new JoomlamailerMC(); if (!$MCapi || !$JoomlamailerMC->pingMC()) { $mainframe->enqueueMessage(JText::_('APIKEY ERROR'), 'error'); $mainframe->redirect('index.php?option=com_joomailermailchimpintegration&view=main'); } $api = new joomlamailerMCAPI($MCapi); $lists = $api->lists(); $options = array(); $options[] = array('id' => '', 'name' => '-- ' . JText::_('JM_PLEASE_SELECT_A_LIST') . ' --'); foreach ($lists as $list) { $options[] = array('id' => $list['id'], 'name' => $list['name']); } $attribs = 'onchange="submitbutton(\'module.apply\')"'; if (count($options)) { return JHtml::_('select.genericlist', $options, 'jform[params][listid]', $attribs, 'id', 'name', $this->value, $this->id); } return ''; }
public function getInput() { jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); if (!JFile::exists(JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php')) { $mainframe->enqueueMessage(JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'), 'error'); $mainframe->redirect('index.php'); } $listId = $this->form->getValue('listid', 'params'); require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php'; $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $api = new joomlamailerMCAPI($MCapi); $fields = $api->listMergeVars($listId); $options = array(); if ($fields) { foreach ($fields as $field) { $choices = ''; if (isset($field['choices'])) { $choices = implode('##', $field['choices']); } $req = $field['req'] ? 1 : 0; $tag = $field['tag'] . ';' . $field['field_type'] . ';' . $field['name'] . ';' . $req . ';' . $choices; // force email field to be pre-selected if ($field['tag'] == 'EMAIL') { $this->value[] = $tag; } $options[] = array('tag' => $tag, 'name' => $field['name']); } } return JHtml::_('select.genericlist', $options, 'jform[params][fields][]', 'multiple="multiple"', 'tag', 'name', $this->value, $this->id); }
public function getInput() { jimport('joomla.filesystem.file'); if (!JFile::exists(JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php')) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('PLG_USER_JOOMLAMAILER_INSTALL_JOOMLAMAILER'), 'error'); $app->redirect('index.php?option=com_plugins'); } else { $listid = $this->form->getValue('listid', 'params'); require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php'; $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $api = new joomlamailerMCAPI($MCapi); $fields = $api->listMergeVars($listid); if ($fields) { $options = array(); foreach ($fields as $field) { if (!in_array($field['tag'], array('EMAIL', 'FNAME', 'LNAME', 'SIGNUPAPI'))) { $options[] = array('tag' => $field['tag'], 'name' => $field['name']); } } if (count($options)) { return JHtml::_('select.genericlist', $options, 'jform[params][fields][]', 'multiple="multiple"', 'tag', 'name', $this->value, $this->id); } } return JText::_('PLG_USER_JOOMLAMAILER_NO_MERGE_VARS'); } }
public function onUserDetailsUpdate($user) { // check if the signup plugin is enabled; if not: return. $plugin = JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); if (is_array($plugin)) { //return; } // make sure API wrapper is available (i.e. Joomlamailer is installed) jimport('joomla.filesystem.file'); if (!JFile::exists(JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php')) { return; } $app = JFactory::getApplication(); $oldEmail = $app->isSite() ? $user->emailpass : JRequest::getVar('oldEmail'); // update user if email has changed if ($user->email != $oldEmail) { // include MCAPI wrapper if (!class_exists('joomlamailerMCAPI')) { require_once JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/libraries/MCAPI.class.php'; } // create instance of api object $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $api = new joomlamailerMCAPI($MCapi); // get the ID of the mailing list $plugin = JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); $pluginParams = new JRegistry($plugin->params); $listId = $pluginParams->get('listid'); // check if the user is subscribed $userLists = $api->listsForEmail($oldEmail); if (!$userLists || !in_array($listId, $userLists)) { return; } $name = explode(' ', JRequest::getVar('name', $user->name)); $fname = $name[0]; $lname = ''; if (isset($name[1])) { for ($i = 1; $i < count($name); $i++) { $lname .= $name[$i] . ' '; } $lname = trim($lname); } $mergeVars = array('FNAME' => $fname, 'LNAME' => $lname, 'EMAIL' => $user->email, 'OPTINIP' => $this->getIpAddress()); $emailType = ''; // submit to MailChimp $api->listUpdateMember($listId, $oldEmail, $mergeVars, $emailType, true); // update local database entry $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->update('#__joomailermailchimpintegration')->set($db->qn('email') . ' = ' . $db->q($user->email))->where($db->qn('email') . ' = ' . $db->q($oldEmail))->where($db->qn('listid') . ' = ' . $db->q($listId)); $db->setQuery($query)->execute(); } }
function save() { //--Check for request forgeries if (version_compare(JVERSION, '1.6.0', 'ge')) { JRequest::checkToken() or jexit('JINVALID_TOKEN'); } else { JRequest::checkToken() or jexit('Invalid Token'); } $user =& JFactory::getUser(); //--get the model $model =& $this->getModel(); //--get data from request $post = JRequest::get('post'); $listid = JRequest::getVar('listid', '', 'post', 'array', JREQUEST_ALLOWRAW); $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $merge = array(); $names = explode(' ', $user->name); if ($names[0] && $names[1]) { $merge['FNAME'] = $names[0]; $merge['LNAME'] = $names[1]; } else { $merge['FNAME'] = $user->name; } $optin = false; foreach ($listid as $list) { $subscribe = ''; $subscribe = (bool) JRequest::getVar('subscribe_' . $list, '', 'post', 'int'); $is_sub = (bool) JRequest::getVar('is_sub_' . $list, '', 'post', 'int'); if ($subscribe && !$is_sub) { // var_dump($list, $user->email , $merge, $optin);die; $result = $MC->listSubscribe($list, $user->email, $merge, '', $optin, true, false, false); $this->db_add($user->id, $user->email, $list); } else { if (!$subscribe && $is_sub) { $result = $MC->listUnsubscribe($list, $user->email, false, false, false); $this->db_remove($user->id, $user->email, $list); } } } $msg = JText::_('JM_SUBSCRIPTIONS_UPDATED'); $itemid = JRequest::getVar('itemid', '', 'post', 'string', JREQUEST_ALLOWRAW); if ($itemid) { $itemid = '&Itemid=' . $itemid; } else { $itemid = ''; } $link = 'index.php?option=com_joomailermailchimpintegration&view=subscriptions' . $itemid; $this->setRedirect($link, $msg); }
/** * Method to save user data from admin interface */ function mcsave($ext) { $api = $this->api(); //Create the api object $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $api = new joomlamailerMCAPI($MCapi); $db =& JFactory::getDBO(); $email = JRequest::getVar('email'); $name = JRequest::getVar('name'); $name = explode(' ', $name); $fname = $name[0]; $lname = isset($name[1]) ? $name[1] : ''; //Get the ID of the mailing list $plugin =& JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); $pluginParams = new JParameter($plugin->params); $listId = $pluginParams->get('listid'); $dbext = $ext == 'com_community' ? 'JS' : 'CB'; //Get the fields associated with the extension $query = 'SELECT * FROM #__joomailermailchimpintegration_custom_fields ' . 'WHERE framework = "' . $dbext . '" ' . 'AND listID = "' . $listId . '"'; $db->setQuery($query); $fields = $db->loadObjectList(); $merge_vars = $this->getData($fields, $dbext); $others = array('FNAME' => $fname, 'LNAME' => $lname, 'INTERESTS' => ''); $merge_vars = array_merge($others, $merge_vars); $email_type = ''; $replace_interests = true; //var_dump($merge_vars);die;var_dump($_POST);die; $retval = $api->listUpdateMember($listId, $email, $merge_vars, $email_type, $replace_interests); if ($api->errorCode) { echo "Unable to update member info!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { if ($ext == 'com_community') { //echo "Returned: ".$retval."\n"; require_once JPATH_ADMINISTRATOR . '/components/com_community/controllers/controller.php'; require_once JPATH_ADMINISTRATOR . '/components/com_community/controllers/users.php'; require_once JPATH_ADMINISTRATOR . '/components/com_community/models/users.php'; $lang =& JFactory::getLanguage(); $lang->load('com_community', JPATH_ADMINISTRATOR); $userController = new CommunityControllerUsers(); $userController->execute('save'); $userController->redirect(); } elseif ($ext == 'com_comprofiler') { $GLOBALS['_JREQUEST']['option'] = array('DEFAULTCMD0' => 'com_comprofiler'); require_once JPATH_ADMINISTRATOR . '/components/com_comprofiler/admin.comprofiler.controller.php'; saveUser($ext); } } }
public function pingMC() { if (!isset($_SESSION['MCping'])) { jimport('joomla.html.parameter'); jimport('joomla.application.component.helper'); $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $MC = new joomlamailerMCAPI($MCapi); $ping = $MC->ping(); $_SESSION['MCping'] = $ping; } else { $ping = $_SESSION['MCping']; } return $ping; }
function getCampaigns() { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $menuitemid = JRequest::getInt('Itemid'); if ($menuitemid) { $menu = JSite::getMenu(); $menuparams = $menu->getParams($menuitemid); $params->merge($menuparams); } $campaigns = $MC->campaigns(array('status' => 'sent'), 0, $params->get('limit', 10)); return $campaigns; }
function resubscribe() { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $listId = JRequest::getVar('listid', 0, 'post', 'string'); $emails = JRequest::getVar('emails', array(), 'post', 'array'); $i = 0; if (isset($emails[0]) && $listId) { foreach ($emails as $email) { $email = explode(';', $email); $memberInfo = $MC->listMemberInfo($listId, $email[0]); $resubscribe = $MC->listSubscribe($listId, $email[0], $memberInfo, $memberInfo['email_type'], false, true, false, false); if (!$MC->errorCode) { $i++; } } } if ($MC->errorCode) { $msg = MCerrorHandler::getErrorMsg($MC); } else { $msg = $i . ' ' . JText::_('JM_USER_RESUBSCRIBED'); } $link = 'index.php?option=com_joomailermailchimpintegration&view=joomailermailchimpintegrations'; $this->setRedirect($link, $msg); }
function MCauth() { if (!isset($_SESSION['MCping'])) { jimport('joomla.html.parameter'); jimport('joomla.application.component.helper'); $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $ping = $MC->ping(); $_SESSION['MCping'] = $ping; } else { $ping = $_SESSION['MCping']; } return $ping; }
function fetchElement($name, $value, &$node, $control_name) { jimport( 'joomla.filesystem.file' ); $option = JRequest::getCmd('option'); $mainframe = & JFactory::getApplication(); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { $mainframe->redirect('index.php',JText::_('INSTALLJOOMAILER'),'error'); } else { $moduleParams = new JParameter( $this->_parent->_raw ); $value = $moduleParams->get('listid'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'helpers'.DS.'MCauth.php' ); $params = & JComponentHelper::getParams('com_joomailermailchimpintegration'); $apikey = $params->get('MCapi'); $MCauth = new MCauth(); if( !$apikey || !$MCauth->MCauth() ) { $mainframe->redirect('index.php?option=com_joomailermailchimpintegration&view=main',JText::_('APIKEY ERROR'),'error'); } $api = new joomlamailerMCAPI($apikey); $lists = $api->lists(); $key = 'id'; $val = 'name'; $options[] = array($key=>'',$val=>JText::_('JM_PLEASE_SELECT_A_LIST')); foreach ($lists as $list){ $options[]=array($key=>$list[$key],$val=>$list[$val]); } if( $option == 'com_joomfish' ){ $submitTask = 'translate.'; } else { $submitTask = ''; } $attribs = "onchange='submitbutton(\"".$submitTask."apply\")'"; $name = 'listid'; if($options){ $content = JHTML::_('select.genericlist',$options, $control_name.'[listid]', $attribs, $key, $val, $value, $control_name.$name); } return $content; } }
function fetchElement($name, $value, &$node, $control_name) { jimport( 'joomla.filesystem.file' ); $mainframe = & JFactory::getApplication(); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { $mainframe->redirect('index.php',JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'),'error'); } else { jimport('joomla.plugin.plugin'); $pluginParams = new JParameter( $this->_parent->_raw ); $listid = $pluginParams->get('listid'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); $params = & JComponentHelper::getParams('com_joomailermailchimpintegration'); $apikey = $params->get('MCapi'); $api = new joomlamailerMCAPI($apikey); $fields = $api->listMergeVars( $listid ); $value = $pluginParams->get('fields'); $key = 'tag'; $val = 'name'; $options = false; if($fields) { foreach ($fields as $field){ //if ($field['form_field']!='hidden') { if ($field['field_type'] != 'email') { $options[]=array($key=>$field[$key],$val=>$field[$val]); } //} } } $ctrl = $control_name .'['. $name .']'; $attribs = 'multiple="multiple"'; $control_name = 'params'; $ctrl .= '[]'; if($options){ $content = JHTML::_('select.genericlist',$options, $ctrl, $attribs, $key, $val, $value, $control_name.$name); } else { $content = JText::_('JM_NO_MERGE_VARS'); } return $content; } }
function fetchElement($name, $value, &$node, $control_name) { jimport( 'joomla.filesystem.file' ); $mainframe = & JFactory::getApplication(); $option = JRequest::getCmd('option'); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { $mainframe->redirect('index.php',JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'),'error'); } else { $moduleParams = new JParameter( $this->_parent->_raw ); $listid = $moduleParams->get('listid'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); $params = & JComponentHelper::getParams('com_joomailermailchimpintegration'); $apikey = $params->get( 'params.MCapi' ); $api = new joomlamailerMCAPI($apikey); $interests = $api->listInterestGroupings( $listid ); $value = $moduleParams->get('interests'); $key = 'id'; $val = 'name'; $options = false; if($interests) { foreach ($interests as $interest){ if ($interest['form_field']!='hidden') { $groups = ''; foreach($interest['groups'] as $ig){ $groups .= $ig['name'].'##'.$ig['name'].'####'; } $groups = substr($groups,0,-4); $options[]=array($key=>$interest[$key].';'.$interest['form_field'].';'.$interest['name'].';'.$groups,$val=>$interest[$val]); } } } $ctrl = $control_name .'['. $name .']'; $attribs = 'multiple="multiple"'; $ctrl .= '[]'; if($options){ $content = JHTML::_('select.genericlist',$options, $ctrl, $attribs, $key, $val, $value, $control_name.$name); } else { $content = JText::_('JM_NO_INTEREST_GROUPS'); } return $content; } }
public function resubscribe() { $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $MC = new joomlamailerMCAPI($MCapi); $listId = JRequest::getVar('listid', 0, 'post', 'string'); $emails = JRequest::getVar('emails', array(), 'post', 'array'); $i = 0; if (isset($emails[0]) && $listId) { foreach ($emails as $email) { $memberInfo = $MC->listMemberInfo($listId, $email); $resubscribe = $MC->listSubscribe($listId, $email, $memberInfo, $memberInfo['email_type'], false, true, false, false); if (!$MC->errorCode) { $i++; } } } if ($MC->errorCode) { $msg = MCerrorHandler::getErrorMsg($MC); } else { $msg = $i . ' ' . JText::_('JM_USER_RESUBSCRIBED'); } $this->setRedirect('index.php?option=com_joomailermailchimpintegration&view=lists', $msg); }
function ajax_sync_all() { // jimport( 'joomla.html.html.behavior' ); // JHTMLBehavior::keepalive(); $elements = JRequest::getVar('elements', '', 'request', 'string'); $elements = json_decode($elements); if ($elements->done == 0) { $_SESSION['abortAJAX'] = 0; unset($_SESSION['addedUsers']); } if ($_SESSION['abortAJAX'] != 1) { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $MCerrorHandler = new MCerrorHandler(); $list_id = $elements->listid; $step = $elements->step; $db =& JFactory::getDBO(); $model =& $this->getModel('sync'); if (isset($_SESSION['addedUsers'])) { $exclude = $_SESSION['addedUsers']; } else { $exclude = array(); } if (!$elements->failed) { $elements->failed = array(); } $exclude = array_merge($exclude, $elements->failed); $exclude = implode('","', $exclude); $exclude = '"' . $exclude . '"'; $query = 'SELECT id,email FROM #__users WHERE id NOT IN (' . $exclude . ') AND block = 0 LIMIT ' . $step; $db->setQuery($query); $data = $db->loadObjectList(); $userIds = array(); foreach ($data as $dat) { $userIds[$dat->email] = $dat->id; } // gather custom fields data $db =& JFactory::getDBO(); $query = "SELECT * FROM #__joomailermailchimpintegration_custom_fields WHERE listid = '" . $list_id . "' "; $db->setQuery($query); $custom_fields = $db->loadObjectList(); if (!isset($custom_fields[0])) { $custom_fields = false; } $addedUsers = $elements->addedUsers; $m = 0; $successCount = 0; $errorcount = $msgErrorsCount = 0; $msg = $msgErrors = false; $counter = 0; $ids = ''; $errorMsg = $elements->errorMsg; // foreach ($data as $dat){ for ($x = 0; $x < count($data); $x += $step) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } $k = 0; $batch = array(); $errorcount = $msgErrorsCount = 0; for ($y = $x; $y < $x + $step; $y++) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } if (isset($data[$y])) { $dat = $data[$y]; } else { $dat = false; } if ($dat) { $user = $model->getUser($dat->id); $addedUsers[] = $user[0]->id; $batch[$k]['EMAIL'] = $user[0]->email; // name $names = explode(' ', $user[0]->name); if (isset($names[0]) && isset($names[1])) { $batch[$k]['FNAME'] = $names[0]; $batch[$k]['LNAME'] = ''; for ($i = 1; $i < count($names); $i++) { $batch[$k]['LNAME'] .= $names[$i] . ' '; } } else { $batch[$k]['FNAME'] = $user[0]->name; } $custom = array(); if ($custom_fields) { foreach ($custom_fields as $field) { if ($field->framework == 'CB') { $query = "SELECT " . $field->dbfield . " FROM #__comprofiler WHERE user_id = '" . $user[0]->id . "' "; } else { $query = "SELECT value FROM #__community_fields_values WHERE field_id = " . $field->dbfield . " AND user_id = '" . $user[0]->id . "' "; } $db->setQuery($query); $field_value = $db->loadResult(); if ($field->framework == 'CB') { $field_value = str_replace('|*|', ',', $field_value); } if ($field->framework == 'JS') { $field_value = substr($field_value, strlen($field_value) - 1) == ',' ? $field_value = substr($field_value, 0, -1) : $field_value; if ($field_value == NULL) { $field_value = ''; } } if ($field->type == 'group') { $batch[$k]['GROUPINGS'][] = array('id' => $field->grouping_id, 'groups' => $field_value); } else { $batch[$k][$field->grouping_id] = $field_value; } // $batch[$k]['GROUPINGS'][] = array( 'id' => (int)$field->grouping_id, 'groups' => $field_value); } } $query = 'INSERT INTO #__joomailermailchimpintegration (userid,email,listid) VALUES ("' . $user[0]->id . '", "' . $user[0]->email . '", "' . $list_id . '")'; $db->setQuery($query); $db->query(); $k++; } else { break; } } if ($batch) { $optin = false; //yes, send optin emails $up_exist = true; // yes, update currently subscribed users $replace_int = true; // false = add interest, don't replace // var_dump($batch);die; $result = $MC->listBatchSubscribe($list_id, $batch, $optin, $up_exist, $replace_int); $successCount = $successCount + $result['success_count']; if ($result['error_count']) { foreach ($result['errors'] as $e) { $tmp = new stdClass(); $tmp->errorCode = $e['code']; $tmp->errorMessage = $e['message']; $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", '; $query = 'DELETE FROM #__joomailermailchimpintegration WHERE `listid` = "' . $list_id . '" AND `email` = "' . $e['row']['EMAIL'] . '" LIMIT 1'; $db->setQuery($query); $db->query(); $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']])); $elements->failed[] = $userIds[$e['row']['EMAIL']]; $errorcount++; } $msgErrorsCount += $result['error_count']; } } } if (!count($data)) { $done = $elements->total; unset($_SESSION['addedUsers']); $percent = 100; } else { $done = count($addedUsers); $_SESSION['addedUsers'] = $addedUsers; $percent = $done / $elements->total * 100; } // $response['msg'] = $done.'/'.$elements->total.' users added'; $response['msg'] = '<div id="bg"></div>' . '<div style="background:#FFFFFF none repeat scroll 0 0;border:10px solid #000000;height:100px;left:37%;position:relative;text-align:center;top:37%;width:300px; ">' . '<div style="margin: 35px auto 3px; width: 300px; text-align: center;">' . JText::_('JM_ADDING_USERS') . ' ( ' . $done . '/' . $elements->total . ' ' . JText::_('JM_DONE') . ' )</div>' . '<div style="margin: auto; background: transparent url(' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif) repeat scroll 0% 0%; width: 190px; height: 14px; display: block;">' . '<div style="width: ' . $percent . '%; overflow: hidden;">' . '<img src="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif" style="margin: 0 5px 0 0;"/>' . '</div>' . '<div style="width: 190px; text-align: center; position: relative;top:-13px; font-weight:bold;">' . round($percent, 0) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" style="text-indent:-5000px;right:-20px;top:-18px;outline:none;" href="javascript:abortAJAX();">abort</a>' . '</div>'; /* $response['msg'] = '<div style="width: 190px; text-align: center">'.JText::_( 'adding users' ).' ( '.$done.'/'.$elements->total.' '.JText::_( 'done' ).')</div>' .'<div style="background: transparent url('.JURI::root().'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif); width: 190px; height: 14px; display: block;">' .'<div style="width: '.$percent.'%; overflow: hidden; background: transparent url('.JURI::root().'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif);">' .'</div>' .'<div style="width: 190px; text-align: center; position: relative;">'.round($percent,0).' %</div>' .'</div>'; */ $response['done'] = $done; // $msg = $successCount.' '.JText::_( 'JM_RECIPIENTS_SAVED' ).$msgErrors; $response['errors'] = count($elements->failed); $response['errorMsg'] = $errorMsg; $response['addedUsers'] = array_values($addedUsers); $response['failed'] = $elements->failed; if ($done + count($elements->failed) + $elements->errors >= $elements->total) { $response['finished'] = 1; if ($errorMsg) { $errorMsg = substr($errorMsg, 0, -2); $msgErrors = ' ( ' . count($elements->failed) . ' ' . JText::_('JM_ERRORS') . ': ' . $errorMsg . ' )'; } if (!$msg) { $msg = $done . ' ' . JText::_('JM_RECIPIENTS_SAVED'); } if ($msgErrors) { $msg .= $msgErrors; } $response['finalMessage'] = $msg; } else { $response['finished'] = 0; $response['finalMessage'] = ''; } $response['abortAJAX'] = $_SESSION['abortAJAX']; echo json_encode($response); } else { unset($_SESSION['addedUsers']); $response['finished'] = 1; $response['addedUsers'] = ''; $response['abortAJAX'] = $_SESSION['abortAJAX']; echo json_encode($response); } }
function ajax_sync_hotness() { $elements = JRequest::getVar('elements', '', 'request', 'string'); $elements = json_decode($elements); if ($elements->done == 0) { $_SESSION['abortAJAX'] = 0; unset($_SESSION['addedUsers']); unset($_SESSION['HotnessExists']); } if ($_SESSION['abortAJAX'] != 1) { $db =& JFactory::getDBO(); $model =& $this->getModel('sync'); $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $MCerrorHandler = new MCerrorHandler(); $list_id = $elements->listid; $step = $elements->step; $offset = $elements->offset; // retrieve hotness rating require_once JPATH_COMPONENT_ADMINISTRATOR . DS . '/libraries/joomailer/hotActivityComposite.php'; $composite = new hotActivityComposite(); $hotnessRating = $composite->getAllUserHotnessValue($list_id); if (isset($_SESSION['addedUsers'])) { $exclude = $_SESSION['addedUsers']; } else { $exclude = array(); } if (!$elements->failed) { $elements->failed = array(); } $exclude = array_merge($exclude, $elements->failed); $exclude = implode('","', $exclude); $exclude = '"' . $exclude . '"'; if (isset($exclude[0])) { $exclude = 'AND j.userid NOT IN (' . $exclude . ') '; } else { $exclude = ''; } // $data = array(); // $run = true; // $page = 0; // while($run){ // $result = $MC->listMembers( $list_id, '', '', $page, '15000'); // $page++; // if($result){ // $run = true; // $data = array_merge($data, $result); // } else { // $run = false; // } // } $data = $MC->listMembers($list_id, '', '', $offset, $step); if (count($data) > 0) { // determine if the interest group Hotness already exists, if not: create it if (!isset($_SESSION['HotnessExists'])) { $query = "SELECT value FROM #__joomailermailchimpintegration_misc WHERE type = 'hotness' AND listid = '" . $list_id . "' "; $db->setQuery($query); $hotnessId = $db->loadResult(); if ($hotnessId == NULL) { $result = $MC->listInterestGroupingAdd($list_id, JText::_('JM_HOTNESS_RATING'), 'hidden', array(1, 2, 3, 4, 5)); if (is_int($result)) { $query = "INSERT INTO #__joomailermailchimpintegration_misc (type, listid, value) VALUES ('hotness', '" . $list_id . "', '" . $result . "') "; $db->setQuery($query); $db->query(); $_SESSION['HotnessExists'] = $result; } } else { $_SESSION['HotnessExists'] = $hotnessId; } } /* $userIds = array(); foreach($data as $dat){ $userIds[$dat->email] = $dat->id; } */ $addedUsers = $elements->addedUsers; $m = 0; $successCount = 0; $errorcount = $msgErrorsCount = 0; $msg = $msgErrors = false; $counter = 0; $ids = ''; $errorMsg = $elements->errorMsg; for ($x = 0; $x < count($data); $x += $step) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } $k = 0; $batch = array(); $errorcount = $msgErrorsCount = 0; for ($y = $x; $y < $x + $step; $y++) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } if (isset($data[$y])) { $dat = $data[$y]; } else { $dat = false; } if ($dat) { $addedUsers[] = $dat['email']; $batch[$k]['EMAIL'] = $dat['email']; if (!isset($hotnessRating[$dat['email']])) { $hotnessRating[$dat['email']] = 2; } $batch[$k]['GROUPINGS'][] = array('id' => $_SESSION['HotnessExists'], 'groups' => $hotnessRating[$dat['email']]); $k++; } else { break; } } if ($batch) { $optin = false; //yes, send optin emails $up_exist = true; // yes, update currently subscribed users $replace_int = true; // false = add interest, don't replace $result = $MC->listBatchSubscribe($list_id, $batch, $optin, $up_exist, $replace_int); $successCount = $successCount + $result['success_count']; if ($result['error_count']) { foreach ($result['errors'] as $e) { $tmp = new stdClass(); $tmp->errorCode = $e['code']; $tmp->errorMessage = $e['message']; $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", '; // $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']])); // $elements->failed[] = $userIds[$e['row']['EMAIL']]; $errorcount++; } $msgErrorsCount += $result['error_count']; } } } $addedUsers = array_unique($addedUsers); if (!count($data)) { $done = $elements->total; unset($_SESSION['addedUsers']); $percent = 100; } else { $done = count($addedUsers); $_SESSION['addedUsers'] = $addedUsers; $percent = $done / $elements->total * 100; } $response['msg'] = '<div id="bg"></div>' . '<div style="background:#FFFFFF none repeat scroll 0 0;border:10px solid #000000;height:100px;left:37%;position:relative;text-align:center;top:37%;width:300px; ">' . '<div style="margin: 35px auto 3px; width: 300px; text-align: center;">' . JText::_('adding users') . ' ( ' . $done . '/' . $elements->total . ' ' . JText::_('done') . ' )</div>' . '<div style="margin: auto; background: transparent url(' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar_grey.gif) repeat scroll 0% 0%; width: 190px; height: 14px; display: block;">' . '<div style="width: ' . $percent . '%; overflow: hidden;">' . '<img src="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/assets/images/progress_bar.gif" style="margin: 0 5px 0 0;"/>' . '</div>' . '<div style="width: 190px; text-align: center; position: relative;top:-13px; font-weight:bold;">' . round($percent, 0) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" style="text-indent:-5000px;right:-20px;top:-18px;outline:none;" href="javascript:abortAJAXnoRefresh();">abort</a>' . '</div>'; $response['done'] = $done; $response['errors'] = count($elements->failed); $response['errorMsg'] = $errorMsg; $response['addedUsers'] = array_values(array_unique($addedUsers)); // $response['failed'] = $elements->failed; if ($done + count($elements->failed) + $elements->errors >= $elements->total) { $response['finished'] = 1; if ($errorMsg) { $errorMsg = substr($errorMsg, 0, -2); $msgErrors = ' ( ' . count($elements->failed) . ' ' . JText::_('Errors') . ': ' . $errorMsg . ' )'; } if (!$msg) { $msg = $done . ' ' . JText::_('JM_USERS_SYNCHRONIZED') . '.'; } if ($msgErrors) { $msg .= $msgErrors; } $response['finalMessage'] = $msg; } else { $response['finished'] = 0; $response['finalMessage'] = ''; } $response['abortAJAX'] = $_SESSION['abortAJAX']; } else { unset($_SESSION['addedUsers']); $response['addedUsers'] = ''; $response['finalMessage'] = JText::_('JM_NO_USERS_FOUND'); $response['finished'] = 1; $response['abortAJAX'] = $_SESSION['abortAJAX']; } echo json_encode($response); } else { unset($_SESSION['addedUsers']); $response['addedUsers'] = ''; $response['finished'] = 1; $response['abortAJAX'] = $_SESSION['abortAJAX']; echo json_encode($response); } }
function refreshShareReport() { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $mc = new joomlamailerMCAPI($MCapi); $elements = JRequest::getVar('elements', '', 'request', 'string'); $elements = json_decode($elements); $cid = $elements->cid; $headerType = $elements->type; if ($headerType == 'text') { $headerData = $elements->title; } else { $headerData = $elements->logo; } // colors $colors = array(); $colors['bg_color'] = str_replace('#', '', $elements->bg_color); $colors['header_color'] = str_replace('#', '', $elements->header_color); $colors['current_tab'] = str_replace('#', '', $elements->current_tab); $colors['current_tab_text'] = str_replace('#', '', $elements->current_tab_text); $colors['normal_tab'] = str_replace('#', '', $elements->normal_tab); $colors['normal_tab_text'] = str_replace('#', '', $elements->normal_tab_text); $colors['hover_tab'] = str_replace('#', '', $elements->hover_tab); $colors['hover_tab_text'] = str_replace('#', '', $elements->hover_tab_text); $opts = array(); $opts['header_type'] = $headerType; $opts['header_data'] = $headerData; $opts['secure'] = false; $opts['password'] = ''; $opts['to_email'] = ''; $opts['theme'] = $colors; $opts['css_url'] = $elements->css; $report = $mc->campaignShareReport($cid, $opts); $response = array(); $response['iframe'] = '<iframe src="' . $report['url'] . '" width="100%" height="800"></iframe>'; $response['url'] = $report['url']; echo json_encode($response); }
function register_save() { $option = JRequest::getCmd('option'); $extension = JRequest::getVar('component'); $extension = version_compare(JVERSION, '1.6.0', 'ge') && $extension == 'com_user' ? 'com_users' : $extension; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $lang =& JFactory::getLanguage(); $task = JRequest::getVar('oldtask'); //com_user if ($extension == 'com_user' || $extension == 'com_users') { if (version_compare(JVERSION, '1.6.0', 'ge')) { $jform = JRequest::getVar('jform'); $name = $jform['name']; $email_address = $jform['email1']; } else { $name = JRequest::getVar('name'); $email_address = JRequest::getVar('email'); } $name = explode(' ', $name); $email_address = $email_address; $controller = '/controller.php'; $cname = version_compare(JVERSION, '1.6.0', 'ge') ? 'UsersController' : 'UserController'; $lang->load($extension, JPATH_BASE); //Jomsocial } elseif ($extension == 'com_community') { if ($user->email) { $email_address = $user->email; $name = explode(' ', $user->name); $_POST['view'] = 'profile'; } else { $query = 'SELECT token FROM #__community_register_auth_token WHERE auth_key="' . $_POST['authkey'] . '"'; $db->setQuery($query); $token = $db->loadResult(); $query = 'SELECT name, email FROM #__community_register WHERE token="' . $token . '"'; $db->setQuery($query); $details = $db->loadAssocList(); $name = explode(' ', $details[0]['name']); $email_address = $details[0]['email']; } $cntrllr = JRequest::getVar('cntrllr'); $controller = '/controllers/' . $cntrllr . '.php'; $cname = 'Community' . strtoupper($cntrllr[0]) . substr($cntrllr, 1) . 'Controller'; $this->_name = str_replace('com_', '', $extension); require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'controllers' . DS . 'controller.php'; require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'libraries' . DS . 'core.php'; require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'libraries' . DS . 'template.php'; require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'views' . DS . 'views.php'; require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'views' . DS . 'register' . DS . 'view.html.php'; require_once JPATH_SITE . DS . 'components' . DS . $extension . DS . 'views' . DS . 'profile' . DS . 'view.html.php'; $lang->load($extension, JPATH_BASE); $_POST['option'] = $extension; $_POST['task'] = $task; $view = JRequest::getCmd('view'); //Community Builder } elseif ($extension == 'com_comprofiler') { $name[0] = JRequest::getVar('firstname'); $name[1] = JRequest::getVar('lastname'); $name = explode(' ', JRequest::getVar('name')); $email_address = JRequest::getVar('email'); $controller = '/comprofiler.php'; $cname = 'Comprofiler'; $_POST['option'] = $extension; $GLOBALS['_JREQUEST']['option'] = array('DEFAULTCMD0' => 'com_comprofiler'); $cbtask = JRequest::getVar('oldtask'); } elseif ($extension == 'com_virtuemart') { $name[0] = JRequest::getVar('first_name'); $name[1] = JRequest::getVar('middle_name'); $name[2] = JRequest::getVar('last_name'); $email_address = JRequest::getVar('email'); } $email_address_old = JRequest::getVar('oldEmail', $email_address); $fname = $name[0]; $lname = ''; if (isset($name[1])) { for ($i = 1; $i < count($name); $i++) { $lname .= $name[$i] . ' '; } $lname = trim($lname); } //Create the api object $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $api = new joomlamailerMCAPI($MCapi); //Get the ID of the mailing list jimport('joomla.html.parameter'); $plugin =& JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); $pluginParams = new JParameter($plugin->params); $listId = $pluginParams->get('listid'); //Check if the user is already logged in and subscribed if ($user->email) { $userlists = $api->listsForEmail($email_address_old); if ($userlists && in_array($listId, $userlists)) { $sub = 1; } } //User wishes to subscribe/update interests if (isset($_POST['newsletter'])) { $double_optin = false; $update_existing = false; $replace_interests = false; $send_welcome = false; //Get merge vars from API $fields = $api->listMergeVars($listId); $fieldids = $pluginParams->get('fields'); $key = 'tag'; $val = 'name'; //Get interests from API $interests = $api->listInterestGroupings($listId); $interestids = $pluginParams->get('interests'); $groupings = array(); $merges = array(); if ($extension == 'com_user' || $extension == 'com_users') { //Default registration if ($fields) { foreach ($fields as $f) { if (isset($_POST['mf_' . $f['tag']])) { $val = $_POST['mf_' . $f['tag']]; $merges[$f['tag']] = $val; } } } if ($interests) { foreach ($interests as $i) { if ($_POST['interest_' . $i['id']]) { $groups = ''; if (is_array($_POST['interest_' . $i['id']])) { foreach ($_POST['interest_' . $i['id']] as $g) { //var_dump($i['groups']);die; foreach ($i['groups'] as $gg) { if ($g == $gg['bit']) { $groups .= $gg['name'] . ','; } } } $groups = substr($groups, 0, -1); $groupings[$i['name']] = array('name' => $i['name'], 'id' => $i['id'], 'groups' => $groups); } else { foreach ($i['groups'] as $gg) { if ($_POST['interest_' . $i['id']] == $gg['bit']) { $groups .= $gg['name']; } } $groupings[$i['name']] = array('name' => $i['name'], 'id' => $i['id'], 'groups' => $groups); } } } } } elseif ($extension == 'com_comprofiler' || $extension == 'com_community' || $extension == 'com_virtuemart') { //Get custom fields $query = 'SELECT dbfield, grouping_id as gid, type, framework FROM #__joomailermailchimpintegration_custom_fields WHERE listID="' . $listId . '"'; $db->setQuery($query); $customfields = $db->loadAssocList(); if ($customfields) { //loop over groupings if ($interests) { foreach ($interests as $i) { foreach ($customfields as $cf) { if ($cf['type'] == 'group') { if ($i['id'] == $cf['gid']) { $groups = ''; if ($extension == 'com_comprofiler' && $cf['framework'] == 'CB' || $extension == 'com_virtuemart' && $cf['framework'] == 'VM') { $field = $_POST[$cf['dbfield']]; } else { if (isset($_POST['field' . $cf['dbfield']])) { $field = $_POST['field' . $cf['dbfield']]; } } if (isset($field) && is_array($field)) { foreach ($field as $g) { foreach ($i['groups'] as $gg) { if ($g == $gg['name']) { $groups .= $gg['name'] . ','; } } } $groups = substr($groups, 0, -1); } else { foreach ($i['groups'] as $gg) { if (isset($field) && $field == $gg['name']) { $groups .= $gg['name']; } } } $groupings[$i['name']] = array('name' => $i['name'], 'id' => $i['id'], 'groups' => $groups); } } } } } } //loop over merge vars if ($fields) { foreach ($fields as $f) { foreach ($customfields as $cf) { if ($cf['type'] == 'field') { if ($f['tag'] == strtoupper($cf['gid'])) { if ($extension == 'com_comprofiler' && $cf['framework'] == 'CB' || $extension == 'com_virtuemart' && $cf['framework'] == 'VM') { if ($f['field_type'] == 'date') { if ($extension == 'com_virtuemart') { $valDay = $_POST['birthday_selector_day']; $valMonth = $_POST['birthday_selector_month']; $valYear = $_POST['birthday_selector_year']; $val = $valMonth . '/' . $valDay . '/' . $valYear; } else { $val = $_POST[$cf['dbfield']]; } $merges[$f['tag']] = substr($val, 3, 2) . '-' . substr($val, 0, 2) . '-' . substr($val, 6, 4); } else { $val = $_POST[$cf['dbfield']]; $merges[$f['tag']] = $val; } } else { if (isset($_POST['field' . $cf['dbfield']])) { $val = $_POST['field' . $cf['dbfield']]; if ($f['field_type'] == 'date') { $merges[$f['tag']] = $val[2] . '-' . $val[1] . '-' . $val[0]; } else { $merges[$f['tag']] = $val; } } } } } } } } } //If this is a new user then subscribe the user at activation if (!$user->id) { $merges_string = ''; if ($merges) { foreach ($merges as $k => $v) { $merges_string .= "name=" . $k . "\n"; if (is_array($v)) { $merges_string .= "value="; foreach ($v as $vv) { $merges_string .= $vv . "||"; } } else { $merges_string .= "value=" . $v; } $merges_string .= "\n\n"; } } $groupings_string = ''; foreach ($groupings as $g) { $groupings_string .= 'name=' . $g['name'] . "\n"; $groupings_string .= 'id=' . $g['id'] . "\n"; $groupings_string .= 'groups=' . $g['groups'] . "\n" . '||' . "\n"; } $groupings_string = substr($groupings_string, 0, -3); $merges_string = substr($merges_string, 0, -2); $query = "INSERT INTO #__joomailermailchimpsignup (fname,lname,email,groupings,merges)\r\n\t\t\t VALUES ('" . $fname . "','" . $lname . "','" . $email_address . "','" . $groupings_string . "','" . $merges_string . "')"; $db->setQuery($query); $db->query(); //Otherwise workout whether to update or subscribe the user } else { //Get the users ip address $ip = $this->get_ip_address(); $merge_vars = array('FNAME' => $fname, 'LNAME' => $lname, 'INTERESTS' => '', 'GROUPINGS' => $groupings, 'OPTINIP' => $ip); $merge_vars = array_merge($merge_vars, $merges); $email_type = ''; if (!isset($sub)) { //Subscribe the user $retval = $api->listSubscribe($listId, $email_address, $merge_vars, $email_type, $double_optin, $update_existing, $replace_interests, $send_welcome); $query = 'INSERT INTO #__joomailermailchimpintegration VALUES ("", ' . $user->id . ', "' . $email_address . '", "' . $listId . '")'; $db->setQuery($query); $db->Query(); } else { //Update the users subscription // email address changed in CB? if (($extension == 'com_comprofiler' || $extension == 'com_user' || $extension == 'com_users') && $email_address != $email_address_old) { // update local database entry $query = 'UPDATE #__joomailermailchimpintegration SET email = "' . $email_address . '" WHERE email="' . $email_address_old . '" AND listid = "' . $listId . '"'; $db->setQuery($query); $db->query(); // add new email address to merge vars array $merge_vars['EMAIL'] = $email_address; $email_address = $email_address_old; } $retval = $api->listUpdateMember($listId, $email_address, $merge_vars, $email_type, true); } } //User wishes to unsubscribe } elseif (!isset($_POST['newsletter']) && isset($sub)) { $api->listUnsubscribe($listId, $email_address, false, false, false); $query = 'DELETE FROM #__joomailermailchimpintegration WHERE email="' . $email_address . '" AND listid = "' . $listId . '"'; $db->setQuery($query); $db->query(); } if ($api->errorCode && $api->errorCode != 215 && $api->errorCode != 211) { echo "Unable to load listSubscribe()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { if ($option == 'com_user' || $option == 'com_users' || $extension == 'com_virtuemart' || $extension == 'com_community' && $task != 'edit' || $extension == 'com_comprofiler') { // we're done at this point return; } else { if ($extension != 'com_comprofiler') { if ($extension != 'com_community') { if (version_compare(JVERSION, '1.6.0', 'ge')) { JRequest::setVar('task', $task); JRequest::setVar('option', 'com_users'); $task = explode('.', $task); $controllerpath = JPATH_SITE . DS . 'components/com_users/controller.php'; require_once $controllerpath; $controllerpath = JPATH_SITE . DS . 'components/com_users/controllers/' . $task[0] . '.php'; require_once $controllerpath; $userController = JController::getInstance('Users', array('base_path' => JPATH_ROOT . DS . 'components' . DS . $extension, 'name' => str_replace('com_', '', $extension))); $task = $task[1]; } else { $controllerpath = JPATH_SITE . DS . 'components/' . $extension . $controller; require_once $controllerpath; $userController = new $cname(array('base_path' => JPATH_ROOT . DS . 'components' . DS . $extension, 'name' => $view)); $this->_name = str_replace('com_', '', $extension); } } else { $controllerpath = JPATH_SITE . DS . 'components/' . $extension . $controller; require_once $controllerpath; $userController = new $cname(array('base_path' => JPATH_ROOT . DS . 'components' . DS . $extension, 'name' => $view)); $this->_name = str_replace('com_', '', $extension); } $userController->execute($task); $userController->redirect(); } else { $controllerpath = JPATH_SITE . DS . 'components/' . $extension . $controller; require_once $controllerpath; if ($cbtask == 'saveUserEdit') { userSave($_POST['option'], $_POST['id']); } else { saveRegistration($_POST['option']); } } } } }
function fetchElement($name, $value, &$node, $control_name) { jimport( 'joomla.filesystem.file' ); $mainframe = & JFactory::getApplication(); $option = JRequest::getCmd('option'); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { $mainframe->redirect('index.php',JText::_('JM_PLEASE_INSTALL_JOOMLAMAILER'),'error'); } else { $moduleParams = new JParameter( $this->_parent->_raw ); $listid = $moduleParams->get('listid'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); $params = & JComponentHelper::getParams('com_joomailermailchimpintegration'); $apikey = $params->get('MCapi'); $api = new joomlamailerMCAPI($apikey); $fields = $api->listMergeVars( $listid ); $value = $moduleParams->get('fields'); $key = 'tag'; $val = 'name'; $options = false; if($fields) { foreach ($fields as $field){ $choices = ''; if(isset($field['choices'])){ foreach($field['choices'] as $c){ $choices .= $c.'##'; } $choices = substr($choices,0,-2); } $req = ($field['req'])?1:0; if($field[$key]=='EMAIL') { if( !is_array($value)){ $oldValue = $value; $value = array(); $value[] = $oldValue; } $value[] = $field[$key].';'.$field['field_type'].';'.$field['name'].';'.$req.';'.$choices; } $options[]=array($key=>$field[$key].';'.$field['field_type'].';'.$field['name'].';'.$req.';'.$choices,$val=>$field[$val]); } } $ctrl = $control_name .'['. $name .']'; $attribs = 'multiple="multiple"'; $ctrl .= '[]'; if($options){ $content = JHTML::_('select.genericlist',$options, $ctrl, $attribs, $key, $val, $value, $control_name.$name); $content .= '<script type="text/javascript"> window.addEvent(\'domready\',function() { $("'.$control_name.$name.'").addEvent( \'change\', function(){ $("'.$control_name.$name.'").options[0].setProperty(\'selected\', \'selected\'); }); }); </script>'; } else { $content = JText::_('JM_NO_FIELDS'); } return $content; } }
function a360_dashboard($a360_api_key, $a360_ga_token, $a360_has_key) { $notification = isset($_GET['a360_error']) ? '<span class="error" style="padding:3px;"><strong>Error</strong>: ' . esc_html(stripslashes($_GET['a360_error'])) . '</span>' : ''; $a360_list_options = array(); if (!empty($a360_api_key)) { if (!class_exists('joomlamailerMCAPI')) { require_once JPATH_COMPONENT . DS . 'libraries' . DS . 'MCAPI.class.php'; } $api = new joomlamailerMCAPI($a360_api_key); if (empty($api->errorCode)) { $lists = $api->lists(); if (is_array($lists)) { foreach ($lists as $list) { $a360_list_options[] = '<option value="' . $list['id'] . '">' . $list['name'] . '</option>'; } } else { $a360_list_options[] = '<option value="">Error: ' . $api->errorMessage . '</option>'; } } else { $a360_list_options[] = '<option value="">API Key Error: ' . $api->errorMessage . '</option>'; } } return $a360_list_options; }
function fetchElement($name, $value, &$node, $control_name) { jimport( 'joomla.filesystem.file' ); $mainframe = & JFactory::getApplication(); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { $mainframe->redirect('index.php',JText::_('JM_INSTALLJOOMAILER'),'error'); } else { jimport('joomla.plugin.plugin'); $pluginParams = new JParameter( $this->_parent->_raw ); $value = $pluginParams->get('listid'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'helpers'.DS.'MCauth.php' ); $params =& JComponentHelper::getParams( 'com_joomailermailchimpintegration' ); $paramsPrefix = (version_compare(JVERSION,'1.6.0','ge')) ? 'params.' : ''; $MCapi = $params->get( $paramsPrefix.'MCapi' ); $MCauth = new MCauth(); if( !$MCapi || !$MCauth->MCauth() ) { $mainframe->redirect('index.php?option=com_joomailermailchimpintegration&view=main',JText::_('JM_INVALID_API_KEY'),'error'); } $api = new joomlamailerMCAPI($MCapi); $lists = $api->lists(); $key = 'id'; $val = 'name'; $options[] = array($key=>'',$val=>JText::_('JM_PLEASE_SELECT_A_LIST')); foreach ($lists as $list){ $options[]=array($key=>$list[$key],$val=>$list[$val]); } $attribs = "onchange='submitbutton(\"apply\")'"; $control_name = 'params'; $name = 'listid'; if($options){ $content = JHTML::_('select.genericlist',$options, 'params[listid]', $attribs, $key, $val, $value, $control_name.$name); } return $content; } }
require_once ( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'jsonwrapper'.DS.'jsonwrapper.php' ); $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); $language = JFactory::getLanguage(); $language->load('mod_mailchimpsignup'); jimport('joomla.filesystem.file'); if(JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); } $params =& JComponentHelper::getParams( 'com_joomailermailchimpintegration' ); $paramsPrefix = (version_compare(JVERSION,'1.6.0','ge')) ? 'params.' : ''; $MCapi = $params->get( $paramsPrefix.'MCapi' ); $MC = new joomlamailerMCAPI($MCapi); $elements = JRequest::getVar( 'elements', '', 'request', 'string' ); $elements = json_decode($elements); $listId = $elements->listid; $email = $elements->EMAIL; $userId = $elements->userId; if(isset($elements->FNAME)){ $merge['FNAME'] = $elements->FNAME; } if(isset($elements->LNAME)){ $merge['LNAME'] = $elements->LNAME; } $merge['OPTINIP'] = $elements->ip;
public function ajaxSyncAll() { $done = JRequest::getVar('done', '', 'POST', 'int'); if ($done == 0) { $_SESSION['abortAJAX'] = 0; unset($_SESSION['addedUsers']); } if ($_SESSION['abortAJAX'] != 1) { $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $MCapi = $params->get('params.MCapi'); $MC = new joomlamailerMCAPI($MCapi); $MCerrorHandler = new MCerrorHandler(); $listId = JRequest::getVar('listId', '', 'POST', 'string'); $total = JRequest::getVar('total', 0, 'POST', 'int'); $errors = JRequest::getVar('errors', 0, 'POST', 'int'); $step = JRequest::getVar('step', 100, 'POST', 'int'); $failed = JRequest::getVar('failed', array(), 'POST'); $addedUsers = JRequest::getVar('addedUsers', array(), 'POST'); $errorMsg = JRequest::getVar('errorMsg', '', 'POST', 'string'); if (!$addedUsers) { $addedUsers = array(); } // create hidden signup date merge var if it doesn't exist $createSignupdateMerge = true; $mergeVars = $MC->listMergeVars($listId); foreach ($mergeVars as $mv) { if ($mv['tag'] == 'SIGNUPAPI') { $createSignupdateMerge = false; break; } } if ($createSignupdateMerge) { $MC->listMergeVarAdd($listId, 'SIGNUPAPI', 'date added (API)', array('date', false, false, true)); } if (isset($_SESSION['addedUsers'])) { $exclude = $_SESSION['addedUsers']; } else { $exclude = array(); } if (!$failed) { $failed = array(); } if (count($failed)) { $exclude = array_merge($exclude, $failed); } $query = $db->getQuery(true)->select($db->qn(array('id', 'email')))->from($db->qn('#__users'))->where($db->qn('block') . ' = ' . $db->q(0))->where($db->qn('id') . ' NOT IN ("' . implode('","', $exclude) . '")'); $db->setQuery($query, 0, $step); $users = $db->loadObjectList(); $userIds = array(); foreach ($users as $user) { $userIds[$user->email] = $user->id; } // gather custom fields data $query = $db->getQuery(true)->select('*')->from($db->qn('#__joomailermailchimpintegration_custom_fields'))->where($db->qn('listid') . ' = ' . $db->q($listId)); $db->setQuery($query); $customFields = $db->loadObjectList(); $m = $successCount = $errorcount = $msgErrorsCount = $counter = 0; $msg = $msgErrors = false; $ids = ''; for ($x = 0; $x < count($users); $x += $step) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } $k = $errorcount = $msgErrorsCount = 0; $batch = array(); for ($y = $x; $y < $x + $step; $y++) { if ($_SESSION['abortAJAX'] == 1) { unset($_SESSION['addedUsers']); break; } $dat = isset($users[$y]) ? $users[$y] : false; if ($dat) { $user = $this->getModel('sync')->getUser($dat->id); $addedUsers[] = $user[0]->id; $batch[$k]['EMAIL'] = $user[0]->email; // name $names = explode(' ', $user[0]->name); if (isset($names[0]) && isset($names[1])) { $batch[$k]['FNAME'] = $names[0]; $batch[$k]['LNAME'] = ''; for ($i = 1; $i < count($names); $i++) { $batch[$k]['LNAME'] .= $names[$i] . ' '; } } else { $batch[$k]['FNAME'] = $user[0]->name; } if (count($customFields)) { foreach ($customFields as $field) { $query = $db->getQuery(true); if ($field->framework == 'CB') { $query->select($db->qn($field->dbfield))->from($db->qn('#__comprofiler'))->where($db->qn('user_id') . ' = ' . $db->q($user[0]->id)); } else { $query->select($db->qn('value'))->from($db->qn('#__community_fields_values'))->where($db->qn('field_id') . ' = ' . $db->q($field->dbfield))->where($db->qn('user_id') . ' = ' . $db->q($user[0]->id)); } $db->setQuery($query); $fieldValue = $db->loadResult(); if ($field->framework == 'CB') { $fieldValue = str_replace('|*|', ',', $fieldValue); } if ($field->framework == 'JS') { if ($fieldValue == NULL) { $fieldValue = ''; } else { $fieldValue = substr($fieldValue, strlen($fieldValue) - 1) == ',' ? $fieldValue = substr($fieldValue, 0, -1) : $fieldValue; } } if ($field->type == 'group') { $batch[$k]['GROUPINGS'][] = array('id' => $field->grouping_id, 'groups' => $fieldValue); } else { $batch[$k][$field->grouping_id] = $fieldValue; } } } // add signup date $batch[$k]['SIGNUPAPI'] = date('Y-m-d'); $query = $db->getQuery(true); try { $query->insert($db->qn('#__joomailermailchimpintegration'))->set($db->qn('userid') . ' = ' . $db->q($user[0]->id))->set($db->qn('email') . ' = ' . $db->q($user[0]->email))->set($db->qn('listid') . ' = ' . $db->q($listId)); $db->setQuery($query); $db->execute(); } catch (Exception $e) { } $k++; } else { break; } } if ($batch) { $optin = false; // do not send optin emails $updateExisting = true; // yes, update currently subscribed users $replaceInterests = true; // false = add interest, don't replace $result = $MC->listBatchSubscribe($listId, $batch, $optin, $updateExisting, $replaceInterests); $successCount = $successCount + $result['success_count']; if ($result['error_count']) { foreach ($result['errors'] as $e) { $tmp = new stdClass(); $tmp->errorCode = $e['code']; $tmp->errorMessage = $e['message']; $errorMsg .= '"' . $MCerrorHandler->getErrorMsg($tmp) . ' => ' . $e['row']['EMAIL'] . '", '; $query->getQuery(true); $query->delete($db->qn('#__joomailermailchimpintegration'))->where($db->qn('listid') . ' = ' . $db->q($listId))->where($db->qn('email') . ' = ' . $db->q($e['row']['EMAIL'])); $db->setQuery($query, 0, 1); $db->execute(); $addedUsers = array_diff($addedUsers, array($userIds[$e['row']['EMAIL']])); $failed[] = $userIds[$e['row']['EMAIL']]; $errorcount++; } $msgErrorsCount += $result['error_count']; } } } if (!count($users)) { $done = $total; unset($_SESSION['addedUsers']); $percent = 100; } else { $done = count($addedUsers); $_SESSION['addedUsers'] = $addedUsers; $percent = $done / $total * 100; } $response['msg'] = '<div id="bg"></div>' . '<div id="progressBarContainer">' . '<div id="progressBarTitle">' . JText::_('JM_ADDING_USERS') . ' (' . $done . '/' . $total . ' ' . JText::_('JM_DONE') . ')</div>' . '<div id="progressBarBg">' . '<div id="progressBarCompleted" style="width: ' . round($percent) . '%;"></div>' . '<div id="progressBarNumber">' . round($percent) . ' %</div>' . '</div>' . '<a id="sbox-btn-close" href="javascript:joomlamailerJS.sync.abortAJAX();">abort</a>' . '</div>'; $response['done'] = $done; // $msg = $successCount.' '.JText::_('JM_RECIPIENTS_SAVED').$msgErrors; $response['errors'] = count($failed); $response['errorMsg'] = $errorMsg; $response['addedUsers'] = array_values($addedUsers); $response['failed'] = $failed; if ($done + count($failed) + $errors >= $total) { $response['finished'] = 1; if ($errorMsg) { $errorMsg = substr($errorMsg, 0, -2); $msgErrors = ' (' . count($failed) . ' ' . JText::_('JM_ERRORS') . ': ' . $errorMsg . ')'; } if (!$msg) { $msg = $done . ' ' . JText::_('JM_RECIPIENTS_SAVED'); } if ($msgErrors) { $msg .= $msgErrors; } $response['finalMessage'] = $msg; } else { $response['finished'] = 0; $response['finalMessage'] = ''; } $response['abortAJAX'] = $_SESSION['abortAJAX']; echo json_encode($response); } else { unset($_SESSION['addedUsers']); $response['finished'] = 1; $response['addedUsers'] = ''; $response['abortAJAX'] = $_SESSION['abortAJAX']; echo json_encode($response); } }
function a360_request_handler() { if (!empty($_GET['a360_action'])) { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $a360_api_key = $params->get('MCapi'); switch ($_GET['a360_action']) { case 'get_mc_data': $api = new joomlamailerMCAPI($a360_api_key); switch ($_GET['data_type']) { case 'campaigns': $results = $api->campaigns(array('sendtime_start' => $_GET['start_date'], 'end_start' => $_GET['end_date'])); if ($results) { die($this->cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false))); } else { if (empty($api->errorCode)) { die($this->cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false))); } else { die($this->cf_json_encode(array('success' => false, 'error' => $api->errorMessage))); } } break; case 'list_growth': $results = $api->listGrowthHistory($_GET['list_id']); if ($results) { die($this->cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false))); } else { die($this->cf_json_encode(array('success' => false, 'error' => $api->errorMessage))); } break; } break; case 'get_ga_data': $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $report_id = $params->get('gprofileid'); $parameters = array('start-date' => $_GET['start_date'], 'end-date' => $_GET['end_date'], 'sort' => 'date', 'ids' => 'ga:' . $report_id); // split up top referrals by filtering on each medium in turn if ($_GET['data_type'] == 'top_referrals') { $requests = array('referral' => null, 'organic' => null, 'email' => null, 'cpc' => null, '*' => null); $parameters['dimensions'] = array('medium', 'source'); $parameters['metrics'] = array('visits', 'timeOnSite', 'pageviews'); $parameters['sort'] = '-visits'; $all_results = array(); $filters = array('referral', 'organic', 'email', 'cpc', '*'); foreach ($filters as $f) { $parameters['filter'] = 'medium == ' . $f; $all_results[$f] = $this->requestReportData($report_id, $parameters['dimensions'], $parameters['metrics'], $parameters['sort'], $parameters['filter'], $parameters['start-date'], $parameters['end-date'], 1, 30); } header('Content-type: text/javascript'); die($this->cf_json_encode(array('success' => true, 'data' => $all_results, 'cached' => false))); break; } else { switch ($_GET['data_type']) { case 'visits': $parameters['dimensions'] = array('date', 'medium'); $parameters['metrics'] = array('visits', 'bounces', 'entrances', 'pageviews', 'newVisits', 'timeOnSite'); //$parameters['filters'] = 'ga:medium==referral,ga:medium==organic,ga:medium==email,ga:medium==cpc'; //$parameters['sort'] = '-ga:visits'; break; case 'geo': $parameters['dimensions'] = array('country'); $parameters['metrics'] = array('visits'); $parameters['sort'] = array('-visits'); break; case 'top_referrals': $parameters['dimensions'] = array('medium', 'source'); $parameters['metrics'] = array('visits', 'timeOnSite', 'pageviews'); $parameters['sort'] = array('-visits'); $parameters['filters'] = 'medium==referral || medium==organic || medium==email || medium==cpc'; break; case 'referral_media': $parameters['dimensions'] = array('medium'); $parameters['metrics'] = array('visits'); $parameters['sort'] = array('-visits'); break; case 'top_content': $parameters['dimensions'] = array('pagePath'); $parameters['metrics'] = array('pageviews', 'uniquePageviews', 'timeOnPage', 'exits'); $parameters['sort'] = array('-pageviews'); break; case 'keywords': $parameters['dimensions'] = array('keyword'); $parameters['metrics'] = array('pageviews', 'uniquePageviews', 'timeOnPage', 'exits'); $parameters['sort'] = array('-pageviews'); $parameters['filters'] = 'source==' . $_GET['source_name']; break; case 'referral_paths': $parameters['dimensions'] = array('source,referralPath'); $parameters['metrics'] = array('pageviews', 'uniquePageviews', 'timeOnPage', 'exits'); $parameters['sort'] = array('-pageviews'); $parameters['filters'] = 'source==' . $_GET['source_name']; break; case 'email_referrals': $parameters['dimensions'] = array('campaign'); $parameters['metrics'] = array('pageviews', 'uniquePageviews', 'timeOnPage', 'exits'); $parameters['sort'] = array('-pageviews'); $parameters['filters'] = 'medium==email'; break; default: break; } } //call the API if (isset($parameters['filters'])) { $filters = $parameters['filters']; } else { $filters = ''; } $result = $this->requestReportData($report_id, $parameters['dimensions'], $parameters['metrics'], $parameters['sort'], $filters, $parameters['start-date'], $parameters['end-date'], 1, 3000); header('Content-type: text/javascript'); die($this->cf_json_encode(array('success' => true, 'data' => $result, 'cached' => false))); break; } } }
function onUserDetailsUpdate($user) { // check if the signup plugin is enabled; if not: return. $plugin = & JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); if( is_array($plugin) ){ return; } // include MCAPI wrapper jimport('joomla.filesystem.file'); if(!JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php')) { return; } // update user if email has changed if( $user->email != $user->emailpass){ // include MCAPI wrapper if(!class_exists('joomlamailerMCAPI')) { require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomailermailchimpintegration'.DS.'libraries'.DS.'MCAPI.class.php'); } // create the api object $params =& JComponentHelper::getParams( 'com_joomailermailchimpintegration' ); $paramsPrefix = (version_compare(JVERSION,'1.6.0','ge')) ? 'params.' : ''; $MCapi = $params->get( $paramsPrefix.'MCapi' ); $api = new joomlamailerMCAPI($MCapi); // get the ID of the mailing list jimport( 'joomla.html.parameter' ); $plugin = & JPluginHelper::getPlugin('system', 'joomailermailchimpsignup'); $pluginParams = new JParameter( $plugin->params ); $listId = $pluginParams->get('listid'); // check if the user is subscribed $userlists = $api->listsForEmail($user->emailpass); if( !$userlists || !in_array($listId,$userlists)) { return; } $name = explode(' ', JRequest::getVar('name', $user->name) ); $fname = $name[0]; $lname = ''; if( isset($name[1]) ) { for( $i=1; $i < count($name); $i++ ){ $lname .= $name[$i].' '; } $lname = trim($lname); } $ip = $this->get_ip_address(); $merge_vars = array( 'FNAME' => $fname, 'LNAME' => $lname, 'EMAIL' => $user->email, 'OPTINIP' => $ip ); $email_type = ''; // submit to MailChimp $api->listUpdateMember($listId, $user->emailpass, $merge_vars, $email_type, true); // update local database entry $db =& JFactory::getDBO(); $query = 'UPDATE #__joomailermailchimpintegration SET email = "'.$user->email.'" WHERE email="'.$user->emailpass.'" AND listid = "'.$listId.'"'; $db->setQuery($query); $db->query(); return; } }
function remove() { $cid = JRequest::getVar('cid', '', 'post', 'array'); $status = JRequest::getVar('filter_status', '', 'post', 'string'); if (!$cid) { $msg = JText::_('JM_INVALID_CAMPAIGNID'); $error = 'error'; } else { $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $error = ''; if ($status == 'save') { jimport('joomla.filesystem.file'); jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $archiveDir = $params->get($paramsPrefix . 'archiveDir', '/administrator/components/com_joomailermailchimpintegration/archive'); $path = JPATH_SITE . $archiveDir . '/'; foreach ($cid as $c) { $db =& JFactory::getDBO(); $query = "SELECT name FROM #__joomailermailchimpintegration_campaigns WHERE creation_date = " . $c; $db->setQuery($query); $cName = $db->loadResult(); $cName = str_replace(' ', '_', $cName); $cName = htmlentities($cName); if (!JFile::delete($path . $cName . '.html') || !JFile::delete($path . $cName . '.txt')) { $msg = JText::_('JM_DELETE_FAILED'); $error = 'error'; } else { $query = "DELETE FROM #__joomailermailchimpintegration_campaigns WHERE creation_date = " . $c; $db->setQuery($query); $db->query(); } } } else { $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new joomlamailerMCAPI($MCapi); $MCerrorHandler = new MCerrorHandler(); foreach ($cid as $c) { $result = $MC->campaignDelete($c); if (!$result) { $msg = $MCerrorHandler->getErrorMsg($MC); $error = 'error'; break; } } } if (!$error) { if ($status == 'save') { $msg = JText::_('JM_DRAFT_DELETED'); } else { $msg = JText::_('JM_CAMPAIGNS_DELETED'); } $error = ''; } } $link = 'index.php?option=com_joomailermailchimpintegration&view=campaignlist&filter_status=' . JRequest::getVar('type', 'sent'); $this->setRedirect($link, $msg, $error); }