/** * Processes (un)subscription requests to multiple lists * @param string $address The email address * @param array $list_ids The ids of the lists * @param bool $subscribe TRUE if addresss should be subscribed to the lists, FALSE if it should be unsubscribed * @return bool TRUE if operation was successful, else FALSE */ function gu_subscription_process($address, &$list_ids, $subscribe) { if (!check_email($address)) { return gu_error(t("Invalid email address")); } $succ_list_names = array(); $fail_list_names = array(); // For each list we need to load it with all addresses foreach ($list_ids as $list_id) { $list = gu_list::get($list_id, TRUE); // Don't allow subscriptions to private lists if ($list->is_private()) { $res = FALSE; } else { if ($subscribe) { $res = $list->add($address, TRUE); } else { $res = $list->remove($address, TRUE); } } if ($res) { $succ_list_names[] = $list->get_name(); } else { $fail_list_names[] = $list->get_name(); } } // Check if there were any successful if (count($succ_list_names) < 1) { return FALSE; } // Work out if we need to send any emails now, and if so create a sender if (gu_config::get('list_send_welcome') || gu_config::get('list_send_goodbye') || gu_config::get('list_subscribe_notify') || gu_config::get('list_unsubscribe_notify')) { $mailer = new gu_mailer(); if ($mailer->init()) { $subject_prefix = count($succ_list_names) == 1 ? $succ_list_names[0] : gu_config::get('collective_name'); // Send welcome / goodbye message if ($subscribe && gu_config::get('list_send_welcome') || !$subscribe && gu_config::get('list_send_goodbye')) { $subject = '[' . $subject_prefix . '] ' . ($subscribe ? t('Subscription') : t('Unsubscription')) . t(' confirmation'); $action = $subscribe ? t('subscribed to') : t('unsubscribed from'); $text = t("This is an automated message to confirm that you have been % the following lists:", array($action)) . "\n\n* " . implode("\n* ", $succ_list_names) . "\n\n"; $text .= t('To change your subscriptions visit: ') . absolute_url('subscribe.php') . '?addr=' . $address . "\n\n"; $text .= t('Please do not reply to this message. Thank you.'); $mailer->send_mail($address, $subject, $text); } // Send admin notifications if ($subscribe && gu_config::get('list_subscribe_notify') || !$subscribe && gu_config::get('list_unsubscribe_notify')) { $subject = '[' . $subject_prefix . '] ' . ($subscribe ? t('Subscription') : t('Unsubscription')) . t(' notification'); $action = $subscribe ? t('subscribed to') : t('unsubscribed from'); $text = t("This is an automated message to notify you that % has been % the following lists:", array($address, $action)) . "\n\n* " . implode("\n* ", $succ_list_names) . "\n\n"; $mailer->send_admin_mail($subject, $text); } } } $action = $subscribe ? t('subscribed to') : t('unsubscribed from'); return gu_success(t('You have been % lists: <i>%</i>', array($action, implode('</i>, <i>', $succ_list_names)))); }
* @file The integration page * @modifications Cyril Maguire */ /* Gutama plugin package * @version 1.6 * @date 01/10/2013 * @author Cyril MAGUIRE */ include 'inc/gutuma.php'; if ($_SESSION['profil'] != PROFIL_ADMIN) { header('Location:compose.php'); exit; } gu_init(); gu_theme_start(); $lists = gu_list::get_all(FALSE, FALSE); $script_import = '<script type="text/javascript" src="' . absolute_url('js/gadgets.js.php') . '"></script>'; $gadget_type = is_post_var('gadget_type') ? get_post_var('gadget_type') : ''; $generate = is_post_var('gadget_generate') && $gadget_type != ''; // Default to first list if one exists $example_list_id = count($lists) > 0 ? $lists[0]->get_id() : 0; if ($generate) { $gadget_list = is_post_var('gadget_list') ? get_post_var('gadget_list') : $example_list_id; switch ($gadget_type) { case 'basic_link': $gadget_text = is_post_var('gadget_text') ? get_post_var('gadget_text') : t('Subscribe to my newsletter'); $script_create = 'gu_gadgets_create_basic_link(' . $gadget_list . ', "' . $gadget_text . '")'; $script_write = '<script type="text/javascript">gu_gadgets_write_basic_link(' . $gadget_list . ', "' . $gadget_text . '")</script>'; $gadget_params = array('list', 'text'); $gadget_requires_import = FALSE; break;
<?php /************************************************************************ * @project Gutuma Newsletter Managment * @author Rowan Seymour * @copyright This source is distributed under the GPL * @file Generates a CSV version of an address list */ /* Gutama plugin package * @version 1.6 * @date 01/10/2013 * @author Cyril MAGUIRE */ include 'inc/gutuma.php'; gu_init(); // Get id of list to edit from querystring $list_id = isset($_GET['list']) ? (int) $_GET['list'] : 0; // Load list data $list = gu_list::get($list_id, TRUE); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $list->get_name() . ".csv\""); foreach ($list->get_addresses() as $address) { echo $address . "\r\n"; }
/** * Removes the specified address from the specified list * @param gu_list $list The list to modify * @param string $address The address to remove * @param int $address_id The id of the address - only used to reference a HTML element on the calling page */ function gu_ajax_remove_address($list, $address, $address_id) { if (!$list) { return gu_error(t('Invalid list')); } if ($list->remove($address, TRUE)) { gu_success(t('Address <b><i>%</i></b> removed', array($address))); gu_ajax_return('gu_ajax_on_remove_address(' . $address_id . ')'); } }
* @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'; gu_init(); gu_theme_start(); // Get the modified flag of the current newsletter $is_modified = is_post_var('is_modified') ? get_post_var('is_modified') : FALSE; // Get all available lists $lists = gu_list::get_all(); if (is_get_var('msg')) { // Load newsletter from draft if one was specified $newsletter = gu_newsletter::get((int) get_get_var('msg')); } else { // Create empty newsletter, and fill from post vars if they exist $newsletter = new gu_newsletter(); if (is_post_var('msg_id')) { $newsletter->set_id((int) get_post_var('msg_id')); } if (is_post_var('msg_recips')) { $newsletter->set_recipients(get_post_var('msg_recips')); } if (is_post_var('msg_subject')) { $newsletter->set_subject(get_post_var('msg_subject')); }
/** * Loads all of the lists * @param bool $load_addresses TRUE if lists addresses should be loaded (default is FALSE) * @param bool $inc_private TRUE if private lists should included (default is TRUE) * @return mixed Array of lists or FALSE if an error occured */ public static function get_all($load_addresses = FALSE, $inc_private = TRUE) { $lists = array(); if ($dh = @opendir(realpath(GUTUMA_LISTS_DIR))) { while (($file = readdir($dh)) !== FALSE) { if (!is_dir($file) && str_ends($file, '.php')) { $list = gu_list::get(substr($file, 0, strlen($file - 4)), $load_addresses); if ($inc_private || !$list->private) { $lists[] = $list; } } } closedir($dh); } return $lists; }
/** * Parses this newsletter's recipient list into an array of addresss and list names * @return array The array of email addresses and list names */ public function parse_recipients() { $list_names = array(); $addresses = array(); $items = explode(';', $this->recipients); foreach ($items as $r) { $recip = trim($r); if (strlen($recip) == 0) { continue; } elseif (strpos($recip, '@') === FALSE) { $list_names[] = $recip; } else { $addresses[$recip] = ''; } } // Add addresses from each list, in reverse order, so that duplicates for addresses on more than one list, come from the first occuring lists for ($l = count($list_names) - 1; $l >= 0; $l--) { if ($list = gu_list::get_by_name($list_names[$l], TRUE)) { foreach ($list->get_addresses() as $address) { $addresses[$address] = $list->get_name(); } } else { return gu_error(t('Unrecognized list name <i>%</i>', array($list_names[$l]))); } } // If admin wants a copy, add the admin address as well if (gu_config::get('msg_admin_copy')) { $addresses[gu_config::get('admin_email')] = ''; } return $addresses; }