/** * Export controller * * @param $type * @param $data */ public function export($type, $criteria = 'all') { switch ($type) { case 'xls': $this->exporter = new \SimpleSubscribe\ExporterExcel('browser', $this->fileName . '.xls'); $this->exporter->addRow($this->columnHeaders); foreach ($this->subscribers->getByCriteria($criteria) as $subscriber) { $this->exporter->addRow(array_values($subscriber)); } break; case 'csv': $this->exporter = new \SimpleSubscribe\ExporterCSV('browser', $this->fileName . '.csv'); $this->exporter->addRow($this->columnHeaders); foreach ($this->subscribers->getByCriteria($criteria) as $subscriber) { $this->exporter->addRow(array_values($subscriber)); } break; case 'tsv': $this->exporter = new \SimpleSubscribe\ExporterTSV('browser', $this->fileName . '.tsv'); $this->exporter->addRow($this->columnHeaders); foreach ($this->subscribers->getByCriteria($criteria) as $subscriber) { $this->exporter->addRow(array_values($subscriber)); } break; case 'xml': $this->exporter = new \SimpleSubscribe\ExporterXML($this->fileName . '.xml'); foreach ($this->subscribers->getByCriteria($criteria) as $subscriber) { $this->exporter->addRow($subscriber); } break; } }
/** * Constructor */ public function __construct() { $this->settings = new \SimpleSubscribe\Settings(SUBSCRIBE_KEY); $this->settingsAll = $this->settings->getSettings(); $this->htmlEmail = isset($this->settingsAll['emailType']['source']) ? $this->settingsAll['emailType']['source'] == 0 ? TRUE : FALSE : TRUE; $this->subscribers = \SimpleSubscribe\RepositorySubscribers::getInstance(); $this->log = \SimpleSubscribe\RepositoryLog::getInstance(); $this->mailer = new \Nette\Mail\SendmailMailer(); $this->senderName = isset($this->settingsAll['misc']['senderName']) ? $this->settingsAll['misc']['senderName'] : html_entity_decode(get_option('blogname'), ENT_QUOTES); $this->senderEmail = isset($this->settingsAll['misc']['senderEmail']) ? $this->settingsAll['misc']['senderEmail'] : get_option('admin_email'); }
/** * Unsubscription form * * @return Nette\Forms\Form */ public static function getUnsubscriptionForm() { $form = \SimpleSubscribe\Forms::unsubscriptionForm(); if ($form->isSubmitted() && $form->isValid()) { try { $subscribers = \SimpleSubscribe\RepositorySubscribers::getInstance(); $formValues = $form->getValues(); $subscribers->deleteOrDeactivateByEmail($formValues->email); $form->setValues(array(), TRUE); } catch (RepositarySubscribersException $e) { $form->addError($e->getMessage()); } } return $form; }
/** * Process actions */ public function process() { if (isset($this->queryVars['a']) && $this->queryVars['a'] == 's') { if (isset($this->queryVars['sb']) && !empty($this->queryVars['sb']) && (isset($this->queryVars['i']) && !empty($this->queryVars['i']))) { try { $subscribers = \SimpleSubscribe\RepositorySubscribers::getInstance(); $subscribers->validateApiCall($this->queryVars['i'], $this->queryVars['sb']); $subscribers->activateUser($this->queryVars['i']); $this->addMessage('success', 'Congratulations! You\'ve successfully subscribed!'); } catch (RepositarySubscribersException $e) { $this->addMessage('error', $e->getMessage()); } } } $this->display(); }
/** * On post publish * * @param $post * @return mixed */ public function onPublish($post) { if ($post) { $subcribers = $this->subscribers->getAllActiveEmails(); $postDigest = $this->getPostDigestBody($post); try { $this->sendEmail($subcribers, $postDigest->subject, $postDigest->data); // log success message $this->log->add(1, 'Digest successfully sent to ' . count($subcribers) . ' subscribers. Post ID: ' . $post->ID); } catch (EmailException $e) { // log error $this->log->add(0, $e->getMessage()); } } else { // log error $this->log->add(0, 'Digest not sent - no post included. Removed maybe?'); } }
/** * Processes bulk actions, delete, activate, deactivate */ function process_bulk_action() { $subscribersBatch = isset($_POST['subscriberId']) ? is_array($_POST['subscriberId']) ? $_POST['subscriberId'] : NULL : NULL; $subscriberId = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : NULL; try { switch ($this->current_action()) { case 'delete': if (!empty($subscribersBatch)) { $this->subscribers->deleteBatch($subscribersBatch); $this->addNotice('updated', 'Subscriber(s) successfully deleted!'); } elseif (isset($_GET['action']) && is_numeric($_GET['id'])) { $this->subscribers->deleteUser($_GET['id']); $this->addNotice('updated', 'Subscriber successfully deleted!'); } break; case 'activate': if (!empty($subscribersBatch)) { $this->subscribers->activateBatch($subscribersBatch); $this->addNotice('updated', 'Subscriber(s) successfully activated!'); } elseif (isset($_GET['action']) && is_numeric($_GET['id'])) { $this->subscribers->activateUser($_GET['id']); $this->addNotice('updated', 'Subscriber successfully activated!'); } break; case 'deactivate': if (!empty($subscribersBatch)) { $this->subscribers->deactivateBatch($subscribersBatch); $this->addNotice('updated', 'Subscriber(s) successfully deactivated!'); } elseif (isset($_GET['action']) && is_numeric($_GET['id'])) { $this->subscribers->deactivateUser($_GET['id']); $this->addNotice('updated', 'Subscriber successfully deactivated!'); } break; case 'deactivateRegistered': $this->subscribers->deactivateRegisteredUserById($_GET['id']); $this->addNotice('updated', 'Subscriber successfully deactivated!'); break; } } catch (RepositarySubscribersException $e) { $this->addNotice('error', $e->getMessage()); } }
/** * Constructor */ public function __construct() { // admin actions add_action('admin_init', array($this, 'adminInit')); add_action('admin_menu', array($this, 'adminMenu')); add_action('admin_notices', array($this, 'adminNotices')); add_action('admin_enqueue_scripts', function () { wp_enqueue_style('core', SUBSCRIBE_ASSETS . 'styleAdmin.css', null, '2.0'); wp_enqueue_script('netteForms', SUBSCRIBE_ASSETS . 'netteForms.js', array(), '1.0.0'); }); // settings & forms $this->settings = new \SimpleSubscribe\Settings(SUBSCRIBE_KEY); $this->subscribers = \SimpleSubscribe\RepositorySubscribers::getInstance(); $this->log = \SimpleSubscribe\RepositoryLog::getInstance(); $this->email = \SimpleSubscribe\Email::getInstance(); $this->formSettings = \SimpleSubscribe\Forms::settings($this->settings->getSettings()); $this->formEmailTemplate = \SimpleSubscribe\Forms::emailTemplate($this->settings->getSettings()); $this->formEmail = \SimpleSubscribe\Forms::email($_GET); $this->formSubscriber = \SimpleSubscribe\Forms::subscribeAdmin($this->settings->getTableColumns()); $this->formSubscriberWp = \SimpleSubscribe\Forms::subscribeAdminWp($this->subscribers->getAllRegisteredInactive()); $this->formEmailPreview = \SimpleSubscribe\Forms::emailPreview(); }
/** * Unsubscription form * * @param bool $widget * @param array $args * @return Nette\Templating\FileTemplate */ public static function unsubscriptionForm($widget = FALSE, $args = array()) { $widgetMessage = ''; $widgetTitle = isset($args['title']) && !empty($args['title']) ? $args['title'] : 'Unsubscribe'; $widgetId = isset($args['widget_id']) ? $args['widget_id'] : NULL; $form = \SimpleSubscribe\Forms::unsubscriptionForm($widget, $widgetId); if ($form->isSubmitted() && $form->isValid()) { try { $subscribers = \SimpleSubscribe\RepositorySubscribers::getInstance(); $formValues = $form->getValues(); $subscribers->deleteOrDeactivateByEmail($formValues->email); $widgetMessage = '<strong>You have successfully unsubscribed. We\'re sorry to see you leave!</strong>'; $form = ''; } catch (RepositarySubscribersException $e) { $form->addError($e->getMessage()); } } if ($widget) { // defaults $defaults = array('beforeWidget' => $args['before_widget'], 'beforeTitle' => $args['before_title'], 'afterTitle' => $args['after_title'], 'widgetTitle' => $widgetTitle, 'message' => $widgetMessage, 'guts' => $form, 'afterWidget' => $args['after_widget']); // template $template = new \SimpleSubscribe\Template('widget.latte'); $template->prepareTemplate($defaults); } else { // defaults $defaults = array('title' => 'Unsubscribe', 'message' => $widgetMessage, 'guts' => $form); // template $template = new \SimpleSubscribe\Template('shortcode.latte'); $template->prepareTemplate($defaults); } return $template->getTemplate(); }
/** * Do the magic */ public function processActions() { // WP_List_Table export \SimpleSubscribe\TableSubscribes::process(); // settings form if ($this->formSettings->isSubmitted() && $this->formSettings->isValid()) { $values = $this->formSettings->getValues(TRUE); // if there are cateogires selected, and ALL as well, uncheck remaining if (count(array_filter($values['cat'])) > 0 && $values['cat']['0'] == TRUE) { foreach ($values['cat'] as $key => $value) { $values['cat'][$key] = FALSE; $this->formSettings['cat'][$key]->value = FALSE; } $values['cat']['0'] = TRUE; $this->formSettings['cat']['0']->value = TRUE; // if there is other category selected, unselect ALL } elseif (count(array_filter($values['cat'])) > 1) { $values['cat']['0'] = FALSE; $this->formSettings['cat']['0']->value = FALSE; // if there's no category selected, select ALL } elseif (!in_array(TRUE, $values['cat'])) { $values['cat']['0'] = TRUE; $this->formSettings['cat']['0']->value = TRUE; } $this->settings->saveSettings($values); $this->addNotice('updated', 'Settings successfully saved.'); } elseif ($this->formSettings->hasErrors()) { foreach ($this->formSettings->getErrors() as $error) { $this->addNotice('error', $error); } } // email template (saved in settings table tho) if ($this->formEmailTemplate->isSubmitted() && $this->formEmailTemplate->isValid()) { $this->settings->saveSettings($this->formEmailTemplate->getValues(TRUE)); $this->addNotice('updated', 'Settings successfully saved.'); } elseif ($this->formEmailTemplate->hasErrors()) { foreach ($this->formEmailTemplate->getErrors() as $error) { $this->addNotice('error', $error); } } // mass email if ($this->formEmail->isSubmitted() && $this->formEmail->isValid()) { try { $this->email->sendMassEmail($this->formEmail->getValues(TRUE)); $this->addNotice('updated', 'Email successfully sent.'); } catch (EmailException $e) { $this->addNotice('error', $e->getMessage()); } } elseif ($this->formEmail->hasErrors()) { foreach ($this->formEmail->getErrors() as $error) { $this->addNotice('error', $error); } } // subscriber form if ($this->formSubscriber->isSubmitted() && $this->formSubscriber->isValid()) { try { $this->subscribers->addThruAdmin($this->formSubscriber->getValues()); $this->addNotice('updated', 'Subscriber successfully added.'); } catch (RepositarySubscribersException $e) { $this->addNotice('error', $e->getMessage()); } } elseif ($this->formSubscriber->hasErrors()) { foreach ($this->formSubscriber->getErrors() as $error) { $this->addNotice('error', $error); } } // wp subscriber form if ($this->formSubscriberWp->isSubmitted() && $this->formSubscriberWp->isValid()) { try { $users = $this->formSubscriberWp->getValues(TRUE); $this->subscribers->addWpRegistered($users['users']); $this->addNotice('updated', 'Subscriber(s) successfully added.'); } catch (RepositarySubscribersException $e) { $this->addNotice('error', $e->getMessage()); } } elseif ($this->formSubscriberWp->hasErrors()) { foreach ($this->formSubscriberWp->getErrors() as $error) { $this->addNotice('error', $error); } } // email preview form if ($this->formEmailPreview->isSubmitted() && $this->formEmailPreview->isValid()) { try { $this->email->sendEmailPreview($this->formEmailPreview->getValues(TRUE)); $this->addNotice('updated', 'Email Preview successfully sent.'); } catch (EmailException $e) { $this->addNotice('error', $e->getMessage()); } } elseif ($this->formEmailPreview->hasErrors()) { foreach ($this->formEmailPreview->getErrors() as $error) { $this->addNotice('error', $error); } } }