/** * 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)))); }
<li><a href="newsletters.php?box=outbox"><?php echo t('Outbox'); ?> (<?php echo count($mailbox['outbox']); ?> )</a></li> </ul> </div> </div> <?php if (count($lists) == 0) { gu_error(t("A address list must be created before a newsletter can be sent")); } if (gu_config::get('admin_email') == '') { gu_error(t("A valid admin email must be specified before a newsletter can be sent")); } gu_theme_messages(); ?> <form enctype="multipart/form-data" id="send_form" name="send_form" method="post" action="compose.php<?php echo gu_is_debugging() ? '?DEBUG' : ''; ?> "><input type="hidden" id="msg_id" name="msg_id" value="<?php echo $newsletter->get_id(); ?> " /><input type="hidden" id="is_modified" name="is_modified" value="<?php echo $is_modified; ?> " /> <div class="menubar"> <input name="save_submit" type="submit" id="save_submit" value="<?php
/** * 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; }
/** * 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() . ')'); } }
exit; } else { $name = ''; gu_error(t('Incorrect username or password')); } } elseif (is_get_var('action') && get_get_var('action') == 'login') { $username = is_post_var('u') ? get_post_var('u') : ''; $password = is_post_var('p') ? get_post_var('p') : ''; $remember = is_post_var('login_remember'); if (gu_session_authenticate($username, $password, $remember)) { // Redirect to page that referred here - or to the home page $redirect = is_get_var('ref') ? urldecode(get_get_var('ref')) : absolute_url('index.php'); header('Location: ' . $redirect); exit; } else { gu_error(t('Incorrect username or password')); } } elseif (is_get_var('action') && get_get_var('action') == 'logout') { // Invalidate session flag gu_session_set_valid(FALSE); } gu_theme_start(); ?> <script type="text/javascript"> /* <![CDATA[ */ function loginSubmit(form) { // MD5 encrypt the password and store in hidden field form.p.value = hex_md5(form.dummy_p.value);
// Import CSV into new list if one has been uploaded if (isset($_FILES['import_file'])) { $name = remove_ext(basename($_FILES['import_file']['name'])); if ($_FILES['import_file']['type'] == 'text/csv') { $csv = $_FILES['import_file']['tmp_name']; if ($list = gu_list::import_csv($name, $csv)) { if ($list->update()) { gu_success(t('List <b><i>%</i></b> imported from CSV file', array($name))); } } // Delete file if (is_file($csv)) { unlink($csv); } } else { gu_error(t('Uploaded file is not a csv file')); } } $lists = gu_list::get_all(); ?> <script type="text/javascript"> /* <![CDATA[ */ function gu_list_menu(list_id) { return '<a href="editlist.php?list=' + list_id + '" class="imglink" title="<?php echo t('Edit'); ?> "><img src="themes/<?php echo gu_config::get('theme_name'); ?>
/** * Saves the current settings values by writing them to the config.php file * @return bool TRUE if operation was successful, else FALSE */ public static function save() { if (gu_is_demo()) { return gu_error(t('Settings cannot be changed in demo mode')); } // Data checks if (preg_match('[^A-Za-z0-9]', self::$values['admin_username'])) { return gu_error(t('Username can only contain alphanumeric characters')); } if (strlen(self::$values['admin_password']) < GUTUMA_PASSWORD_MIN_LEN) { return gu_error(t('Password must be at least % characters long', array(GUTUMA_PASSWORD_MIN_LEN))); } if (!check_email(self::$values['admin_email'])) { return gu_error(t('A valid administrator email must be at provided')); } if (!is_dir(RPATH . 'themes/' . self::$values['theme_name'])) { return gu_error(t("Theme <em>%</em> doesn't exists. You need to create it first !", array(self::$values['theme_name']))); } $lh = @fopen(GUTUMA_CONFIG_FILE, 'w'); if ($lh == FALSE) { return gu_error(t("Unable to create/open % file for writing", array(GUTUMA_CONFIG_FILE))); } fwrite($lh, "\$gu_config_version = " . GUTUMA_VERSION_NUM . ";\n"); foreach (array_keys(self::$values) as $key) { if (is_bool(self::$values[$key])) { fwrite($lh, "\$gu_config['" . $key . "'] = " . (self::$values[$key] ? 'TRUE' : 'FALSE') . ";\n"); } elseif (is_numeric(self::$values[$key])) { fwrite($lh, "\$gu_config['" . $key . "'] = " . self::$values[$key] . ";\n"); } else { fwrite($lh, "\$gu_config['" . $key . "'] = '" . str_replace(array('\\"', "'"), array('"', "\\'"), self::$values[$key]) . "';\n"); } } fclose($lh); $f = file_get_contents(GUTUMA_CONFIG_FILE); // Version encodée (voir ligne 185) file_put_contents(GUTUMA_CONFIG_FILE, "<?php /*\n" . base64_encode($f) . "\n*/ ?>"); // Version décodée (voir ligne 187) /* file_put_contents(GUTUMA_CONFIG_FILE,"<?php \n".$f."\n?>");*/ return TRUE; }
/** * Imports an address list from a CSV file * @param string $name The list name * @param string $path The path of the CSV file * @return mixed The new list if it was successfully created, else FALSE */ public static function import_csv($name, $path) { $csv = @fopen($path, 'r'); if ($csv == FALSE) { return gu_error(t("Unable to open CSV file for reading")); } // Read addresses from first cell on each line $addresses = array(); while (!feof($csv)) { $vals = explode(',', fgets($csv)); $address = trim($vals[0]); if (strlen($address) > 0 && strlen($address) <= GUTUMA_MAX_ADDRESS_LEN) { $addresses[] = $address; } } fclose($csv); // Sort addresses alphabetically natcasesort($addresses); return gu_list::create($name, FALSE, $addresses); }
function gu_sender_test() { // Get current settings, which may not have been saved $use_smtp = is_post_var('use_smtp'); $smtp_server = get_post_var('smtp_server'); $smtp_port = (int) get_post_var('smtp_port'); $smtp_encryption = get_post_var('smtp_encryption'); $smtp_username = get_post_var('smtp_username'); $smtp_password = get_post_var('smtp_password'); $use_sendmail = is_post_var('use_sendmail'); $use_phpmail = is_post_var('use_phpmail'); if (!($use_smtp || $use_sendmail || $use_phpmail)) { return gu_error(t('No method of mail transportation has been configured')); } $test_msg = t('If you have received this email then your settings clearly work!'); // Test SMTP settings first if ($use_smtp) { $mailer = new gu_mailer(); if ($mailer->init(TRUE, $smtp_server, $smtp_port, $smtp_encryption, $smtp_username, $smtp_password, FALSE, FALSE)) { if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing SMTP', $test_msg)) { return gu_error(t('Unable to send test message using SMTP')); } } else { return gu_error(t('Unable to initialize mailer with the SMTP settings')); } $mailer->disconnect(); } // Test Sendmail next if ($use_sendmail) { $mailer = new gu_mailer(); if ($mailer->init(FALSE, '', '', '', '', '', FALSE, FALSE)) { if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing Sendmail', $test_msg)) { return gu_error(t('Unable to send test message using Sendmail')); } } else { return gu_error(t('Unable to initialize mailer with Sendmail')); } $mailer->disconnect(); } // Test PHP mail next if ($use_phpmail) { $mailer = new gu_mailer(); if ($mailer->init(FALSE, '', '', '', '', '', FALSE, TRUE)) { if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing PHP mail', $test_msg)) { return gu_error(t('Unable to send test message using PHP mail')); } } else { return gu_error(t('Unable to initialize mailer with PHP mail')); } $mailer->disconnect(); } gu_success(t('Test messages sent to <br><i>%</i></b>', array(gu_config::get('admin_email')))); }
* @author Cyril MAGUIRE */ include_once 'inc/gutuma.php'; if (isset($_GET['token'])) { list($name, $username, $password, $salt, $userProfile, $id, $new_record) = explode('[::]', unserialize(base64_decode($_GET['token']))); list($user_name, $user_login, $user_password, $user_salt, $user_userProfile, $user_id) = explode('[::]', unserialize(base64_decode($new_record))); $user_salt = substr($user_salt, 1, -2); } else { header('Location:./index.php'); } gu_init(); $users = gu_config::getUsers(); if (isset($users[$user_name])) { header('location:' . str_replace('plugins/gutuma/news', 'core/admin', absolute_url('plugin.php?p=gutuma&rec=done&u=' . $users[$user_name]['id']))); } // Save settings if (is_post_var('save_settings')) { if (isset($users[$user_name])) { gu_error(t('<span style="color:red;">User already exists !</span>')); } else { gu_config::setUsers(get_post_var('id'), get_post_var('name'), get_post_var('login'), get_post_var('password'), base64_decode(get_post_var('salt')), get_post_var('userProfile')); if (gu_config::save()) { $ok = ''; } gu_success(t('New user successfully saved.')); } } gu_theme_start(); //Body include_once 'themes/' . gu_config::get('theme_name') . '/_users.php'; gu_theme_end();
/** * Gets all the newsletters * @return array The newsletters */ public static function get_all() { $newsletters = array(); if ($dh = @opendir(realpath(GUTUMA_TEMP_DIR))) { while (($file = readdir($dh)) !== FALSE) { if ($file == '.' || $file == '..' || $file[0] == '.') { continue; } if (($newsletter = self::get($file)) !== FALSE) { $newsletters[] = $newsletter; } } } else { return gu_error(t('Unable to open newsletter folder'), ERROR_EXTRA); } return $newsletters; }