/** * 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)))); }
<?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"; }
case 'unsubscribe': $list = is_post_var('list') ? gu_list::get((int) get_post_var('list'), TRUE) : NULL; $address = is_post_var('address') ? get_post_var('address') : ''; gu_ajax_subscribe($list, $address, FALSE); break; case 'list_add': $name = is_post_var('name') ? trim(get_post_var('name')) : ''; $private = is_post_var('private') ? (bool) get_post_var('private') : false; gu_ajax_list_add($name, $private); break; case 'list_delete': $list = is_post_var('list') ? gu_list::get((int) get_post_var('list'), TRUE) : NULL; gu_ajax_list_delete($list); break; case 'remove_address': $list = is_post_var('list') ? gu_list::get((int) get_post_var('list'), TRUE) : NULL; $address = is_post_var('address') ? get_post_var('address') : ''; $address_id = is_post_var('address_id') ? (int) get_post_var('address_id') : 0; gu_ajax_remove_address($list, $address, $address_id); break; case 'newsletter_delete': $newsletter = is_post_var('newsletter') ? gu_newsletter::get((int) get_post_var('newsletter')) : NULL; gu_ajax_newsletter_delete($newsletter); break; } // If action function hasn't already returned due to error, return now gu_ajax_return(); /** * Called when an error has occured. * @param string $msg The error message to send to the client */
} // Get querystring variables $list_id = is_get_var('list') ? (int) get_get_var('list') : 0; $address = is_get_var('addr') ? get_get_var('addr') : ''; $action = is_get_var('action') ? get_get_var('action') : ''; // Check if we've got what we need to do a querystring (un)subscription if ($list_id > 0 && $address != '' && $action != '') { $list_ids = array($list_id); gu_subscription_process($address, $list_ids, $subscribe == 'subscribe'); } // Check to see if a single valid list was specified if ($list_id > 0 || count($posted_lists) == 1) { if ($list_id == 0) { $list_id = $posted_lists[0]; } $list = gu_list::get($list_id, FALSE); } else { // Load all non-private lists $lists = gu_list::get_all(FALSE, FALSE); } if ($address == '' && $posted_address != '') { $address = $posted_address; } ?> <script type="text/javascript"> /* <![CDATA[ */ function checkSubmit(form) { if (form.subscribe_address.value == "" || !gu_check_email(form.subscribe_address.value)) { alert("<?php
/** * 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; }