Example #1
0
 /**
  * Creates a Swift message from a Gutuma newsletter
  * @param gu_newsletter $newsletter The newsletter
  * @param string $recipient The recipient address
  * @param string $list_name The name of the list holding the recipient
  * @return mixed The Swift message if successful, else FALSE
  */
 private function create_message(gu_newsletter $newsletter, $address, $list_name)
 {
     if (!gu_config::get('msg_prefix_subject')) {
         $subject = $newsletter->get_subject();
     } elseif ($list_name != '') {
         $subject = '[' . $list_name . '] ' . $newsletter->get_subject();
     } else {
         $subject = '[' . gu_config::get('collective_name') . '] ' . $newsletter->get_subject();
     }
     if ($list_name != '' && gu_config::get('msg_append_signature')) {
         $text = $newsletter->get_text() . "\n-------------------------------------------------\n" . t('Unsubscribe') . ": " . absolute_url('subscribe.php') . "?addr=" . $address . "\n" . t('Powered by Gutuma') . " (" . GUTUMA_URL . ")\n";
         $html = $newsletter->get_html() . '<hr /><p><a href="' . absolute_url('subscribe.php') . '?addr=' . $address . '">' . t('Unsubscribe') . '</a> ' . t('from this newsletter.') . t(' Powered by') . ' <a href="' . GUTUMA_URL . '">' . t('Gutuma') . '</a></p>';
     } else {
         $text =& $newsletter->get_text();
         $html =& $newsletter->get_html();
     }
     // Add text and html as separate MIME parts
     $message = new Swift_Message($subject);
     $message->attach(new Swift_Message_Part($text));
     $message->attach(new Swift_Message_Part($html, "text/html"));
     // Add message attachments
     foreach ($newsletter->get_attachments() as $attachment) {
         if (!$message->attach(new Swift_Message_Attachment(new Swift_File($attachment['path']), $attachment['name']))) {
             return gu_error(t("Unable to attach '") . $attachment['name'] . "'");
         }
     }
     return $message;
 }
Example #2
0
 * @copyright This source is distributed under the GPL
 * @file The CRON interface to Gutuma
 * @modifications Cyril Maguire
 */
/* Gutama plugin package
 * @version 1.6
 * @date	01/10/2013
 * @author	Cyril MAGUIRE
*/
include_once 'inc/gutuma.php';
include_once 'inc/newsletter.php';
include_once 'inc/mailer.php';
// Initialize Gutuma without validation or redirection
gu_init(FALSE, FALSE);
// Get all newsletters in the outbox
$mailbox = gu_newsletter::get_mailbox();
if ($mailbox == FALSE || !isset($mailbox['outbox'])) {
    die(utf8_decode(t('Unable to access mailbox')));
}
// Create mailer
$mailer = new gu_mailer();
if (!$mailer->init()) {
    die(utf8_decode(t('Unable to initialize mailer')));
}
// Start timer
$start_time = time();
// Process outbox
foreach ($mailbox['outbox'] as $newsletter) {
    $newsletter->send_batch($mailer, $start_time);
    // Check batch time limit
    if (time() - $start_time > (int) gu_config::get('batch_time_limit')) {
Example #3
0
/**
 * Deletes the specified newsletter
 * @param gu_newsletter $newsletter The newsletter to delete
 */
function gu_ajax_newsletter_delete($newsletter)
{
    if (!$newsletter) {
        return gu_error(t('Invalid newsletter'));
    }
    if ($newsletter->delete()) {
        gu_success(t('Newsletter deleted'));
        gu_ajax_return('gu_ajax_on_newsletter_delete(' . $newsletter->get_id() . ')');
    }
}
Example #4
0
$preview_mode = is_post_var('preview_submit');
// Send the newsletter
if (is_post_var('send_submit')) {
    // Saves newsletter to outbox
    if ($newsletter->send_prepare()) {
        $mailer = new gu_mailer();
        if ($mailer->init()) {
            if ($newsletter->send_batch($mailer)) {
                if ($newsletter->is_sending()) {
                    gu_success(t('Newsletter sent to first batch of recipients'));
                } else {
                    gu_success(t('Newsletter sent to all recipients'));
                }
            }
        }
        $newsletter = new gu_newsletter();
        $is_modified = FALSE;
    }
} elseif (is_post_var('attach_submit') && $_FILES['attach_file']['name'] != '') {
    if ($newsletter->store_attachment($_FILES['attach_file']['tmp_name'], $_FILES['attach_file']['name'])) {
        gu_success(t('Attachment <b><i>%</i></b> added', array($_FILES['attach_file']['name'])));
    }
} elseif (is_post_var('remove_submit')) {
    $attachment = get_post_var('msg_attachments');
    if ($newsletter->delete_attachment($attachment)) {
        gu_success(t('Attachment <i>%</i> removed', array($attachment)));
    }
} elseif (is_post_var('save_submit')) {
    if ($newsletter->save()) {
        $is_modified = FALSE;
        gu_success(t('Newsletter saved as draft'));