/** * Execute the action */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (empty($id) || !BackendMailmotorModel::existsMailing($id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } else { // get the mailing and reset some fields $mailing = BackendMailmotorModel::getMailing($id); $mailing['status'] = 'concept'; $mailing['send_on'] = null; $mailing['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $mailing['edited_on'] = $mailing['created_on']; $mailing['data'] = serialize($mailing['data']); unset($mailing['recipients'], $mailing['id'], $mailing['cm_id'], $mailing['send_on_raw']); // set groups $groups = $mailing['groups']; unset($mailing['groups']); // create a new mailing based on the old one $newId = BackendMailmotorModel::insertMailing($mailing); // update groups for this mailing BackendMailmotorModel::updateGroupsForMailing($newId, $groups); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_copy_mailing', array('item' => $mailing)); } // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=mailing-copied&var=' . $mailing['name']); }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('mailing_id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // fetch the mailing $mailing = BackendMailmotorModel::getMailing($this->id); // get all data for the user we want to edit $records = (array) BackendMailmotorCMHelper::getCM()->getCampaignBounces($mailing['cm_id']); // reset some data if (!empty($records)) { // loop the records foreach ($records as $record) { // only remove the hard bounces if ($record['bounce_type'] == 'Hard') { // remove the address BackendMailmotorModel::deleteAddresses($record['email']); } } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_bounces'); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('statistics') . '&id=' . $mailing['id'] . '&report=deleted-bounces'); } else { $this->redirect(BackendModel::createURLForAction('statistics') . '&error=no-bounces'); } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $action = SpoonFilter::getGetValue('action', array('delete'), ''); // get passed group ID $id = SpoonFilter::getGetValue('group_id', null, 0, 'int'); // fetch group record $this->group = BackendMailmotorModel::getGroup($id); // set redirect URL $redirectURL = BackendModel::createURLForAction('custom_fields') . '&group_id=' . $this->group['id']; // no id's provided if (!$action) { $this->redirect($redirectURL . '&error=no-action-selected'); } if (!isset($_GET['fields'])) { $this->redirect($redirectURL . '&error=no-items-selected'); } if (empty($this->group)) { $this->redirect(BackendModel::createURLForAction('groups') . '&error=non-existing'); } else { // redefine id's $this->fields = (array) $_GET['fields']; // evaluate $action, see what action was triggered switch ($action) { case 'delete': $this->deleteCustomFields(); break; } } }
/** * Loads the datagrid with the groups * * @return void */ private function loadDataGrid() { // create datagrid $this->dataGrid = new BackendDataGridDB(BackendMailmotorModel::QRY_DATAGRID_BROWSE_GROUPS); $this->dataGrid->setColumnsHidden(array('language', 'is_default')); // sorting columns $this->dataGrid->setSortingColumns(array('name', 'created_on'), 'created_on'); $this->dataGrid->setSortParameter('desc'); // set colum URLs $this->dataGrid->setColumnURL('name', BackendModel::createURLForAction('addresses') . '&group_id=[id]'); // set the datagrid ID so we don't run into trouble with multiple datagrids that use mass actions $this->dataGrid->setAttributes(array('id' => 'dgGroups')); // add the multicheckbox column $this->dataGrid->setMassActionCheckboxes('checkbox', '[id]', BackendMailmotorModel::getDefaultGroupIds()); $this->dataGrid->setColumnsSequence('checkbox', 'name', 'created_on', 'language'); // add mass action dropdown $ddmMassAction = new SpoonFormDropdown('action', array('delete' => BL::lbl('Delete')), 'delete'); $this->dataGrid->setMassAction($ddmMassAction); // set column functions $this->dataGrid->setColumnFunction(array('BackendDataGridFunctions', 'getTimeAgo'), array('[created_on]'), 'created_on', true); // add delete column $this->dataGrid->addColumnAction('custom_fields', null, BL::lbl('CustomFields'), BackendModel::createURLForAction('custom_fields') . '&group_id=[id]', BL::lbl('CustomFields'), array('class' => 'button icon iconEdit linkButton')); $this->dataGrid->addColumnAction('export', null, BL::lbl('Export'), BackendModel::createURLForAction('export_addresses') . '&id=[id]', BL::lbl('Export'), array('class' => 'button icon iconExport linkButton')); $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_group') . '&id=[id]', BL::lbl('Edit')); // add styles $this->dataGrid->setColumnAttributes('name', array('class' => 'title')); // set paging limit $this->dataGrid->setPagingLimit(self::PAGING_LIMIT); }
/** * Fetches the campaign ID and sets its record */ private function getCampaign() { // get the active campaign $id = $this->getParameter('campaign', 'int'); // fetch the campaign record $this->campaign = BackendMailmotorModel::getCampaign($id); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $id = SpoonFilter::getPostValue('id', null, '', 'int'); $name = trim(SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($name == '') { $this->output(self::BAD_REQUEST, null, 'no name provided'); } // get existing id $existingId = BackendMailmotorModel::getCampaignId($name); // existing campaign if ($existingId !== 0 && $id !== $existingId) { $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule())); } // build array $item = array(); $item['id'] = $id; $item['name'] = $name; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // get page $rows = BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item)); // output if ($rows !== 0) { $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule())); } else { $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule())); } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $txtName = $this->frm->getField('name'); $rbtDefaultForLanguage = $this->frm->getField('default'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { // check if the group exists by name if (BackendMailmotorModel::existsGroupByName($txtName->getValue())) { $txtName->addError(BL::err('GroupAlreadyExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['language'] = $rbtDefaultForLanguage->getValue() === '0' ? null : $rbtDefaultForLanguage->getValue(); $item['is_default'] = $rbtDefaultForLanguage->getChecked() ? 'Y' : 'N'; // insert the item $item['id'] = BackendMailmotorCMHelper::insertGroup($item); // check if all default groups were set BackendMailmotorModel::checkDefaultGroups(); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int'); $sendOnDate = SpoonFilter::getPostValue('send_on_date', null, BackendModel::getUTCDate('d/m/Y')); $sendOnTime = SpoonFilter::getPostValue('send_on_time', null, BackendModel::getUTCDate('H:i')); $messageDate = $sendOnDate; // validate mailing ID if ($mailingId == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid mailing ID'); } if ($sendOnDate == '' || $sendOnTime == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided'); } // record is empty if (!BackendMailmotorModel::existsMailing($mailingId)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', 'mailmotor')); } // reverse the date and make it a proper $explodedDate = explode('/', $sendOnDate); $sendOnDate = $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0]; // calc full send timestamp $sendTimestamp = strtotime($sendOnDate . ' ' . $sendOnTime); // build data $item['id'] = $mailingId; $item['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $sendTimestamp); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update mailing BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step4', array('item' => $item)); // output $this->output(self::OK, array('mailing_id' => $mailingId, 'timestamp' => $sendTimestamp), sprintf(BL::msg('SendOn', $this->getModule()), $messageDate, $sendOnTime)); }
/** * Sets a link to the campaign statistics if it contains sent mailings * * @param int $id The ID of the campaign. * @return string */ public static function setStatisticsLink($id) { // build the link HTML $html = '<a href="' . BackendModel::createURLForAction('statistics_campaign') . '&id=' . $id . '" class="button icon iconStats linkButton"><span>' . BL::lbl('Statistics') . '</span></a>'; // check if this campaign has sent mailings $hasSentMailings = BackendMailmotorModel::existsSentMailingsByCampaignID($id) > 0 ? true : false; // return the result return $hasSentMailings ? $html : ''; }
/** * Get the data */ private function getData() { // get the record $this->record = (array) BackendMailmotorModel::getMailing($this->id); // get the template record for this mailing $this->template = BackendMailmotorModel::getTemplate($this->record['language'], $this->record['template']); // no item found, throw an exceptions, because somebody is f*****g with our URL if (empty($this->record)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Load the form */ private function loadForm() { $this->frm = new BackendForm('add'); $this->frm->addText('email'); // fetch groups $groups = BackendMailmotorModel::getGroupsForCheckboxes(); // if no groups are found, redirect to overview if (empty($groups)) { $this->redirect(BackendModel::createURLForAction('addresses') . '&error=no_groups'); } // add checkboxes for groups $this->frm->addMultiCheckbox('groups', $groups, $this->groupId); }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (!BackendMailmotorModel::existsMailing($id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } else { BackendMailmotorModel::exportStatistics($id); } // redirect $this->redirect(BackendModel::createURLForAction('groups') . '&report=export-failed'); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (!BackendMailmotorModel::existsCampaign($id)) { $this->redirect(BackendModel::createURLForAction('campaigns') . '&error=campaign-does-not-exist'); } else { BackendMailmotorModel::exportStatisticsByCampaignID($id); } // redirect $this->redirect(BackendModel::createURLForAction('groups') . '&report=export-failed'); }
/** * Gets all data needed for this page */ private function getData() { $this->id = $this->getParameter('id', 'int'); // does the item exist if (!BackendMailmotorModel::existsMailing($this->id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } // get mailing $this->mailing = BackendMailmotorModel::getMailing($this->id); // fetch the statistics $this->statistics = BackendMailmotorCMHelper::getStatistics($this->id, true); // no stats found if ($this->statistics === false) { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-statistics-loaded&var=' . str_replace('#', '', $this->mailing['name'])); } }
/** * Gets all data needed for this page */ private function getData() { // get parameters $id = $this->getParameter('mailing_id', 'int'); // does the item exist if (!BackendMailmotorModel::existsMailing($id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } // fetch the mailing $this->mailing = BackendMailmotorModel::getMailing($id); // fetch the bounces $this->bounces = BackendMailmotorCMHelper::getBounces($this->mailing['id']); // does the item exist if (empty($this->bounces)) { $this->redirect(BackendModel::createURLForAction('statistics') . '&id=' . $this->mailing['id'] . '&error=no-bounces'); } }
/** * Gets all data needed for this page * * @return void */ private function getData() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if (!BackendMailmotorModel::existsCampaign($this->id)) { $this->redirect(BackendModel::createURLForAction('campaigns') . '&error=campaign-does-not-exist'); } // store mailing $this->campaign = BackendMailmotorModel::getCampaign($this->id); // fetch the statistics $this->statistics = BackendMailmotorCMHelper::getStatisticsByCampaignID($this->id, true); // no stats found if ($this->statistics === false || empty($this->statistics)) { $this->redirect(BackendModel::createURLForAction('campaigns') . '&error=no-statistics-loaded'); } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $id = SpoonFilter::getPostValue('id', null, '', 'int'); // validate if ($id == '' || !BackendMailmotorModel::existsMailing($id)) { $this->output(self::BAD_REQUEST, null, 'No mailing found.'); } // get mailing record $mailing = BackendMailmotorModel::getMailing($id); /* mailing was already sent We use a custom status code 900 because we want to do more with JS than triggering an error */ if ($mailing['status'] == 'sent') { $this->output(900, null, BL::err('MailingAlreadySent', $this->getModule())); } // make a regular date out of the send_on timestamp $mailing['delivery_date'] = date('Y-m-d H:i:s', $mailing['send_on']); // send the mailing try { // only update the mailing if it was queued if ($mailing['status'] == 'queued') { BackendMailmotorCMHelper::updateMailing($mailing); } else { BackendMailmotorCMHelper::sendMailing($mailing); } } catch (Exception $e) { // stop the script and show our error $this->output(902, null, $e->getMessage()); } // set status to 'sent' $item['id'] = $id; $item['status'] = $mailing['send_on'] > time() ? 'queued' : 'sent'; // update the mailing record BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_mailing_status_' . $item['status'], array('item' => $item)); // we made it \o/ $this->output(self::OK, array('mailing_id' => $item['id']), BL::msg('MailingSent', $this->getModule())); }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $action = SpoonFilter::getGetValue('action', array('delete'), 'delete'); // no id's provided if (!isset($_GET['id'])) { $this->redirect(BackendModel::createURLForAction('campaigns') . '&error=no-items-selected'); } else { // redefine id's $ids = (array) $_GET['id']; // delete comment(s) if ($action == 'delete') { BackendMailmotorModel::deleteCampaigns($ids); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_campaigns', array('ids' => $ids)); } } // redirect $this->redirect(BackendModel::createURLForAction('campaigns') . '&report=delete-campaigns'); }
/** * Execute the action */ public function execute() { parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (empty($id)) { $this->redirect(BackendModel::createURLForAction('groups') . '&error=no-items-selected'); } else { // export all addresses if ($id == 'all') { // fetch records $records = BackendMailmotorModel::getAddresses(); // export records BackendMailmotorModel::exportAddresses($records); } else { BackendMailmotorModel::exportAddressesByGroupID($id); } } // redirect $this->redirect(BackendModel::createURLForAction('groups') . '&report=export-failed'); }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $txtName = $this->frm->getField('name'); // validate fields $txtName->isFilled(BL::err('NameIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // insert the item $item['id'] = BackendMailmotorModel::insertCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_campaign', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('campaigns') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $txtName = $this->frm->getField('name'); $txtFromName = $this->frm->getField('from_name'); $txtFromEmail = $this->frm->getField('from_email'); $txtReplyToEmail = $this->frm->getField('reply_to_email'); $chkGroups = $this->frm->getField('groups'); $rbtLanguages = $this->frm->getField('languages'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { if (BackendMailmotorModel::existsMailingByName($txtName->getValue())) { $txtName->addError(BL::err('MailingAlreadyExists')); } } $txtFromName->isFilled(BL::err('NameIsRequired')); $txtFromEmail->isFilled(BL::err('EmailIsRequired')); $txtReplyToEmail->isFilled(BL::err('EmailIsRequired')); // set form values $values = $this->frm->getValues(); // check if at least one recipient group is chosen if (empty($values['groups'])) { $chkGroups->addError(BL::err('ChooseAtLeastOneGroup')); } else { // fetch the recipients for these groups $recipients = BackendMailmotorModel::getAddressesByGroupID($values['groups']); // if no recipients were found, throw an error if (empty($recipients)) { $chkGroups->addError(BL::err('GroupsNoRecipients')); } } // check if at least one language is chosen if (empty($values['languages'])) { $rbtLanguages->isFilled(BL::err('FieldIsRequired')); } // no errors? if ($this->frm->isCorrect()) { // set values $item['name'] = $txtName->getValue(); $item['from_name'] = $txtFromName->getValue(); $item['from_email'] = $txtFromEmail->getValue(); $item['reply_to_email'] = $txtReplyToEmail->getValue(); $item['language'] = $rbtLanguages->getValue(); $item['status'] = 'concept'; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); if (!empty($values['campaign'])) { $item['campaign_id'] = $this->frm->getField('campaign')->getValue(); } // insert the concept $item['id'] = BackendMailmotorModel::insertMailing($item); // update the groups for this mailing BackendMailmotorModel::updateGroupsForMailing($item['id'], $values['groups']); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_mailing_step1', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id'] . '&step=2'); } } }
/** * Checks if any groups are made yet. Depending on the client that is linked to Fork, it will creates default groups if none were found in CampaignMonitor. * If they were, the user is presented with an overview to import all groups and their subscribers in Fork. * * @return void */ private function checkForGroups() { // groups are already set if (BackendModel::getModuleSetting('mailmotor', 'cm_groups_set')) { return false; } // no CM data found if (!BackendMailmotorCMHelper::checkAccount()) { return false; } // check if there are external groups present in CampaignMonitor if ($this->checkForExternalGroups()) { // external groups were found, so redirect to the import_groups action SpoonHTTP::redirect(BackendModel::createURLForAction('import_groups', 'mailmotor')); } // fetch the default groups, language abbreviation is the array key $groups = BackendMailmotorModel::getDefaultGroups(); // loop languages foreach (BL::getActiveLanguages() as $language) { // this language does not have a default group set if (!isset($groups[$language])) { // set group record $group['name'] = 'Website (' . strtoupper($language) . ')'; $group['language'] = $language; $group['is_default'] = 'Y'; $group['created_on'] = date('Y-m-d H:i:s'); try { // insert the group in CampaignMonitor BackendMailmotorCMHelper::insertGroup($group); } catch (CampaignMonitorException $e) { // ignore } } } // we have groups set, and default groups chosen BackendModel::setModuleSetting('mailmotor', 'cm_groups_set', true); BackendModel::setModuleSetting('mailmotor', 'cm_groups_defaults_set', true); }
/** * Processes the subscriber import. Returns an array with failed subscribers. * * @return array A list with failed subscribers. * @param array $csv The uploaded CSV file. * @param int $groupID The group ID for which we're importing. */ private function processImport($csv, $groupID) { // the CM list ID for the given group ID $listID = BackendMailmotorCMHelper::getCampaignMonitorID('list', $groupID); // reserve variables $subscribers = array(); /* IMPORTANT NOTE: CM only allows a maximum amount of 100 subscribers for each import. So we have to batch */ foreach ($csv as $key => $record) { // no e-mail address set means stop here if (empty($record['email'])) { continue; } // build record to insert $subscribers[$key] = $this->formatSubscriberCSVRow($record); } // divide the subscribers into batches of 100 $batches = array_chunk($subscribers, 100); $failed = array(); $feedback = array(); $failedSubscribersCSV = array(); // loop the batches foreach ($batches as $key => $batch) { // import every 100 subscribers $feedback[$key] = BackendMailmotorCMHelper::getCM()->importSubscribers($batch, $listID); // if the batch did not contain failed imports, we continue looping if (empty($feedback[$key])) { continue; } // merge the feedback results with the full failed set $failed = array_merge($failed, $feedback[$key]); } // now we have to loop all uploaded CSV rows in order to provide a .csv with all failed records. foreach ($csv as $row) { // the subscriber didn't fail the import, so we proceed to insert him in our database if (!in_array($row['email'], $failed)) { // build subscriber record $subscriber = array(); $subscriber['email'] = $row['email']; $subscriber['source'] = 'import'; $subscriber['created_on'] = BackendModel::getUTCDate(); $subscriber['groups'] = $groupID; // unset the email (for the custom fields) unset($row['email']); // save the address in our database, with the assigned custom fields BackendMailmotorModel::saveAddress($subscriber, $groupID, $row); // continue looping continue; } // subscriber failed in import, so add his record to the fail-csv $failedSubscribersCSV[] = $row; } // return the failed subscribers return $failedSubscribersCSV; }
/** * Load the datagrid for unsubscriptions * * @return void */ private function loadUnsubscriptions() { // get results $results = BackendMailmotorModel::getUnsubscribedAddressesByGroupID($this->groupId, self::PAGING_LIMIT); // there are some results if (!empty($results)) { // get the datagrid $dataGrid = new BackendDataGridArray($results); // no pagination $dataGrid->setPaging(false); // set edit link $dataGrid->setColumnURL('email', BackendModel::createURLForAction('edit_address', 'mailmotor') . '&email=[email]'); // set column functions $dataGrid->setColumnFunction(array('BackendDataGridFunctions', 'getTimeAgo'), array('[created_on]'), 'created_on', true); // parse the datagrid $this->tpl->assign('dgMailmotorUnsubscriptions', $dataGrid->getContent()); } }
/** * Sets the group record * * @return void */ private function setGroup() { // set the passed group ID $id = SpoonFilter::getGetValue('group_id', null, 0, 'int'); // group was set if (!empty($id)) { // get group record $this->group = BackendMailmotorModel::getGroup($id); // assign the group record $this->tpl->assign('group', $this->group); } }
/** * Returns the fully parsed e-mail content * * @return string * @param string $template The template to use. * @param string $contentHTML The content. * @param string $fullContentHTML The full content. */ private function getEmailContent($template, $contentHTML, $fullContentHTML) { // require the CSSToInlineStyles class require 'external/css_to_inline_styles.php'; // fetch the template contents for this mailing $template = BackendMailmotorModel::getTemplate($this->mailing['language'], $template); // template content is empty if (!isset($template['content'])) { $this->output(self::ERROR, array('mailing_id' => $this->mailing['id'], 'error' => true), BL::err('TemplateDoesNotExist', $this->getModule())); } // remove TinyMCE $fullContentHTML = preg_replace('/<!-- tinymce -->.*?<!-- \\/tinymce -->/is', $contentHTML, $fullContentHTML); // replace bracketed entities with their proper counterpart $fullContentHTML = preg_replace('/\\[ent=(.*?)]/', '&${1};', $fullContentHTML); // add Google UTM parameters to all anchors $fullContentHTML = $this->addUTMParameters($fullContentHTML); // search values $search[] = '{$siteURL}'; $search[] = '"'; $search[] = 'src="/'; // replace values $replace[] = SITE_URL; $replace[] = '"'; $replace[] = 'src="' . SITE_URL . '/'; // replace some variables $fullContentHTML = str_replace($search, $replace, $fullContentHTML); // set CSS object $css = new CSSToInlineStyles($fullContentHTML, $template['css']); $fullContentHTML = $css->convert(); // return the content return $fullContentHTML; }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $txtName = $this->frm->getField('name'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { if (in_array($txtName->getValue(), $this->group['custom_fields'])) { $txtName->addError(BL::err('CustomFieldExists')); } } // no errors? if ($this->frm->isCorrect()) { try { // add the new item to the custom fields list $this->group['custom_fields'][] = $txtName->getValue(); // set the group fields by flipping the custom fields array for this group $groupFields = array_flip($this->group['custom_fields']); // group custom fields found if (!empty($groupFields)) { // loop the group fields and empty every value foreach ($groupFields as &$field) { $field = ''; } } // addresses found and custom field delete with CM BackendMailmotorCMHelper::createCustomField($txtName->getValue(), $this->group['id']); // update custom fields for this group BackendMailmotorModel::updateCustomFields($groupFields, $this->group['id']); } catch (Exception $e) { // redirect with a custom error $this->redirect(BackendModel::createURLForAction('custom_fields') . '&group_id=' . $this->group['id'] . '&error=campaign-monitor-error&var=' . urlencode($e->getMessage())); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('custom_fields') . '&group_id=' . $this->group['id'] . '&report=added&var=' . urlencode($txtName->getValue()) . '&highlight=id-' . $this->group['id']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int'); $subject = SpoonFilter::getPostValue('subject', null, ''); $contentHTML = urldecode(SpoonFilter::getPostValue('content_html', null, '')); $contentPlain = SpoonFilter::getPostValue('content_plain', null, ''); // validate mailing ID if ($mailingId == '') { $this->output(self::BAD_REQUEST, null, 'No mailing ID provided'); } // get mailing record $this->mailing = BackendMailmotorModel::getMailing($mailingId); // record is empty if (empty($this->mailing)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', $this->getModule())); } // validate other fields if ($subject == '') { $this->output(900, array('element' => 'subject', 'element_error' => BL::err('NoSubject', $this->getModule())), BL::err('FormError')); } // set plain content $contentPlain = empty($contentPlain) ? SpoonFilter::stripHTML($contentHTML) : $contentPlain; // add unsubscribe link if (mb_strpos($contentPlain, '[unsubscribe]') === false) { $contentPlain .= PHP_EOL . '[unsubscribe]'; } // build data $item['id'] = $this->mailing['id']; $item['subject'] = $subject; $item['content_plain'] = $contentPlain; $item['content_html'] = $contentHTML; $item['edited_on'] = date('Y-m-d H:i:s'); // update mailing in our database BackendMailmotorModel::updateMailing($item); /* we should insert the draft into campaignmonitor here, so we can use sendCampaignPreview in step 4. */ $item['groups'] = $this->mailing['groups']; $item['name'] = $this->mailing['name']; $item['from_name'] = $this->mailing['from_name']; $item['from_email'] = $this->mailing['from_email']; $item['reply_to_email'] = $this->mailing['reply_to_email']; try { BackendMailmotorCMHelper::saveMailingDraft($item); } catch (Exception $e) { // CM did not receive a valid URL if (strpos($e->getMessage(), 'HTML Content URL Required')) { $message = BL::err('HTMLContentURLRequired', $this->getModule()); } elseif (strpos($e->getMessage(), 'Payment details required')) { $error = BL::err('PaymentDetailsRequired', $this->getModule()); $cmUsername = BackendModel::getModuleSetting($this->getModule(), 'cm_username'); $message = sprintf($error, $cmUsername); } elseif (strpos($e->getMessage(), 'Duplicate Campaign Name')) { $message = BL::err('DuplicateCampaignName', $this->getModule()); } else { $message = $e->getMessage(); } // stop the script and show our error $this->output(902, null, $message); } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step3', array('item' => $item)); // output $this->output(self::OK, array('mailing_id' => $mailingId), BL::msg('MailingEdited', $this->getModule())); }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // no errors? if ($this->frm->isCorrect()) { // the total amount of subscribers $subscribersTotal = 0; // loop all groups foreach ($this->externalGroups as $group) { // insert them in our database $groupID = BackendModel::getDB(true)->insert('mailmotor_groups', array('name' => $group['name'], 'custom_fields' => $group['custom_fields'], 'created_on' => BackendModel::getUTCDate())); // insert the CM ID BackendMailmotorCMHelper::insertCampaignMonitorID('list', $group['id'], $groupID); // continue looping if this group has no subscribers if (empty($group['subscribers'])) { continue; } // add this groups subscribers amount to the total $subscribersTotal += $group['subscribers_amount']; // loop the subscribers for this group, and import them foreach ($group['subscribers'] as $subscriber) { // build new subscriber record $item = array(); $item['email'] = $subscriber['email']; $item['source'] = 'import'; $item['created_on'] = $subscriber['date']; // add an additional custom field 'name', if it was set in the subscriber record if (!empty($subscriber['name'])) { $subscriber['custom_fields']['Name'] = $subscriber['name']; } // save the subscriber in our database, and subscribe it to this group BackendMailmotorModel::saveAddress($item, $groupID, !empty($subscriber['custom_fields']) ? $subscriber['custom_fields'] : null); } } // at this point, groups are set BackendModel::setModuleSetting($this->getModule(), 'cm_groups_set', true); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import_groups'); // redirect to the index $this->redirect(BackendModel::createURLForAction('index', $this->getModule()) . '&report=groups-imported&var[]=' . count($this->externalGroups) . '&var[]=' . $subscribersTotal); } } }
/** * Export addresses */ private function exportAddresses() { // export the addresses BackendMailmotorModel::exportAddresses($this->emails); }