/** * Checks for external groups, and parses a message to import them. * * @return mixed Returns false if the user already made groups. */ private function checkForExternalGroups() { // get all CM groups $externalGroups = BackendMailmotorCMHelper::getCM()->getListsByClientId(); // return the result return !empty($externalGroups); }
/** * 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 */ public function execute() { parent::execute(); $this->cm = BackendMailmotorCMHelper::getCM(); $this->loadForm(); $this->validateForm(); $this->parse(); $this->display(); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $clientId = SpoonFilter::getPostValue('client_id', null, ''); // check input if (empty($clientId)) { $this->output(self::BAD_REQUEST); } // get basic details for this client $client = BackendMailmotorCMHelper::getCM()->getClient($clientId); // CM was successfully initialized $this->output(self::OK, $client); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // store CM object $this->cm = BackendMailmotorCMHelper::getCM(); // load the form $this->loadForm(); // validate the form $this->validateForm(); // parse $this->parse(); // display the page $this->display(); }
/** * 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 $clientId = SpoonFilter::getPostValue('client_id', null, ''); // check input if (empty($clientId)) { $this->output(self::BAD_REQUEST); } // get basic details for this client $client = BackendMailmotorCMHelper::getCM()->getClient($clientId); // CM was successfully initialized $this->output(self::OK, $client); }
/** * 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; }
/** * 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'); // 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) { // fetch campaign ID in CM $cmId = BackendMailmotorCMHelper::getCampaignMonitorID('campaign', $id); // check if the CM ID isn't false if ($cmId !== false) { // delete the mailing in CM BackendMailmotorCMHelper::getCM()->deleteCampaign($cmId); // delete the reference BackendModel::getDB(true)->delete('mailmotor_campaignmonitor_ids', 'cm_id = ?', $cmId); } // check what error we have switch ($e->getMessage()) { case 'HTML Content URL Required': $message = BL::err('HTMLContentURLRequired', $this->getModule()); break; case 'Payment details required': $message = sprintf(BL::err('PaymentDetailsRequired', $this->getModule()), BackendModel::getModuleSetting($this->getModule(), 'cm_username')); break; case 'Duplicate Campaign Name': $message = BL::err('DuplicateCampaignName', $this->getModule()); break; default: $message = $e->getMessage(); break; } // stop the script and show our error $this->output(902, null, $message); } // 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())); }
/** * Returns all bounces * * @param int $id The id of the campaign. * @return array */ public static function getBounces($id) { // get campaignmonitor ID $cmId = self::getCampaignMonitorID('campaign', $id); // get all bounces from CM $bounces = BackendMailmotorCMHelper::getCM()->getCampaignBounces($cmId); // get all addresses $addresses = BackendMailmotorModel::getAddressesAsPairs(); // no bounces found if (empty($bounces)) { return array(); } // loop the bounces, check what bounces are still in our database foreach ($bounces as $key => $bounce) { // check if the bounced address is in the full list of addresses if (!in_array($bounce['email'], $addresses)) { unset($bounces[$key]); } } // return the bounces return (array) $bounces; }