Exemple #1
0
     // check every recipient
     foreach ($recipients as $address => $label) {
         // check that the address is valid
         if (!preg_match(VALID_RECIPIENT, $address)) {
             $recipients_skipped++;
             $context['text'] .= str_replace(array('<', '>'), array('&lt;', '&gt;'), $address) . ' ' . i18n::s('Error: Invalid address skipped') . BR . "\n";
             continue;
         }
         // no recipient string
         if (!$label) {
             $to[] = $address;
         } else {
             if (preg_match('/,/', $label)) {
                 $label = implode(' ', array_reverse(preg_split("/[\\s,]+/", $label)));
             }
             $to[] = Mailer::encode_recipient($address, $label);
         }
     }
 }
 // subject
 $subject = $_REQUEST['letter_title'];
 // enable yacs codes in messages
 $text = Codes::beautify($_REQUEST['letter_body']);
 // preserve tagging as much as possible
 $message = Mailer::build_multipart($text);
 // reply-to: from the letters configuration file
 if (isset($context['letter_reply_to']) && $context['letter_reply_to']) {
     $headers[] = 'Reply-To: ' . $context['letter_reply_to'];
 }
 // list and count recipients
 $recipients_errors = $recipients_processed = $recipients_ok = 0;
Exemple #2
0
 }
 // always add the item to the watch list
 Members::assign('section:' . $item['id'], 'user:'******'id']);
 // propagate the invitation to the overlay, if applicable
 if (is_callable(array($overlay, 'invite'))) {
     $overlay->invite($user['id']);
 }
 // this person has no valid email address
 if (!$user['email'] || !preg_match(VALID_RECIPIENT, $user['email'])) {
     continue;
 }
 // use this email address
 if ($user['full_name']) {
     $recipient = Mailer::encode_recipient($user['email'], $user['full_name']);
 } else {
     $recipient = Mailer::encode_recipient($user['email'], $user['nick_name']);
 }
 // headline
 $headline = sprintf(i18n::c('%s has invited you to %s'), Surfer::get_link(), '<a href="' . Sections::get_permalink($item) . '">' . $item['title'] . '</a>');
 // build the full message
 if (isset($_REQUEST['message'])) {
     $message = '<div>' . $_REQUEST['message'] . '</div>';
 } else {
     $message = '<p>' . i18n::c('I would like to invite you to the following page.') . '</p>' . '<p><a href="' . Sections::get_permalink($item) . '">' . $item['title'] . '</a></p>';
 }
 // change content for message poster
 if (strpos(Surfer::from(), $user['email']) !== FALSE) {
     $message = '<hr /><p>' . i18n::c('This is a copy of the message you have sent, for your own record.') . '</p><p>' . join(', ', $actual_names) . '</p><hr />' . $message;
 }
 // allow the overlay to filter message content
 if (is_callable(array($overlay, 'filter_invite_message'))) {
Exemple #3
0
 /**
  * remember an action once it's done
  *
  * To be overloaded into derived class
  *
  * @param string the action 'insert', 'update' or 'delete'
  * @param array the hosting record
  * @param string reference of the hosting record (e.g., 'article:123')
  * @return FALSE on error, TRUE otherwise
  */
 function remember($action, $host, $reference)
 {
     global $context;
     // remember the id of the master record
     $id = $host['id'];
     // set default values for this editor
     Surfer::check_default_editor($this->attributes);
     // we use the existing back-end for dates
     include_once $context['path_to_root'] . 'dates/dates.php';
     // build the update query
     switch ($action) {
         case 'delete':
             // no need to notify participants after the date planned for the event, nor if the event has been initiated
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp'] > gmstrftime('%Y-%m-%d %H:%M') && isset($this->attributes['status']) && $this->attributes['status'] != 'started' && $this->attributes['status'] != 'stopped') {
                 // send a cancellation message to participants
                 $query = "SELECT user_email FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "') AND (approved LIKE 'Y')";
                 $result = SQL::query($query);
                 while ($item = SQL::fetch($result)) {
                     // sanity check
                     if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                         continue;
                     }
                     // message title
                     $subject = sprintf('%s: %s', i18n::c('Cancellation'), strip_tags($this->anchor->get_title()));
                     // headline
                     $headline = sprintf(i18n::c('%s has cancelled %s'), Surfer::get_link(), $this->anchor->get_title());
                     // message to reader
                     $message = $this->get_invite_default_message('CANCEL');
                     // assemble main content of this message
                     $message = Skin::build_mail_content($headline, $message);
                     // threads messages
                     $headers = Mailer::set_thread($this->anchor->get_reference());
                     // get attachment from the overlay
                     $attachments = $this->get_invite_attachments('CANCEL');
                     // post it
                     Mailer::notify(Surfer::from(), $item['user_email'], $subject, $message, $headers, $attachments);
                 }
             }
             // delete dates for this anchor
             Dates::delete_for_anchor($reference);
             // also delete related enrolment records
             $query = "DELETE FROM " . SQL::table_name('enrolments') . " WHERE anchor LIKE '" . $reference . "'";
             SQL::query($query);
             break;
         case 'insert':
             // bind one date to this record
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp']) {
                 $fields = array();
                 $fields['anchor'] = $reference;
                 $fields['date_stamp'] = $this->attributes['date_stamp'];
                 // update the database
                 if (!($fields['id'] = Dates::post($fields))) {
                     Logger::error(i18n::s('Impossible to add an item.'));
                     return FALSE;
                 }
             }
             // enroll page creator
             include_once $context['path_to_root'] . 'shared/enrolments.php';
             enrolments::confirm($reference);
             // reload the anchor through the cache to reflect the update
             if ($reference) {
                 $this->anchor = Anchors::get($reference, TRUE);
             }
             // send a confirmation message to event creator
             $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "')";
             $result = SQL::query($query);
             while ($item = SQL::fetch($result)) {
                 // a user registered on this server
                 if ($item['user_id'] && ($watcher = Users::get($item['user_id']))) {
                     // sanity check
                     if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                         continue;
                     }
                     // use this email address
                     if ($watcher['full_name']) {
                         $recipient = Mailer::encode_recipient($watcher['email'], $watcher['full_name']);
                     } else {
                         $recipient = Mailer::encode_recipient($watcher['email'], $watcher['nick_name']);
                     }
                     // message title
                     $subject = sprintf(i18n::c('Meeting: %s'), strip_tags($this->anchor->get_title()));
                     // headline
                     $headline = sprintf(i18n::c('you have arranged %s'), '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url() . '">' . $this->anchor->get_title() . '</a>');
                     // message to reader
                     $message = $this->get_invite_default_message('PUBLISH');
                     // assemble main content of this message
                     $message = Skin::build_mail_content($headline, $message);
                     // a set of links
                     $menu = array();
                     // call for action
                     $link = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
                     $menu[] = Skin::build_mail_button($link, i18n::c('View event details'), TRUE);
                     // finalize links
                     $message .= Skin::build_mail_menu($menu);
                     // threads messages
                     $headers = Mailer::set_thread($this->anchor->get_reference());
                     // get attachment from the overlay
                     $attachments = $this->get_invite_attachments('PUBLISH');
                     // post it
                     Mailer::notify(Surfer::from(), $recipient, $subject, $message, $headers, $attachments);
                 }
             }
             break;
         case 'update':
             // reload the anchor through the cache to reflect the update
             if ($reference) {
                 $this->anchor = Anchors::get($reference, TRUE);
             }
             // no need to notify watchers after the date planned for the event, nor if the event has been initiated
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp'] > gmstrftime('%Y-%m-%d %H:%M') && isset($this->attributes['status']) && $this->attributes['status'] != 'started' && $this->attributes['status'] != 'stopped' && isset($_REQUEST['notify_watchers']) && $_REQUEST['notify_watchers'] == 'Y') {
                 // send a confirmation message to participants
                 $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "')";
                 $result = SQL::query($query);
                 while ($item = SQL::fetch($result)) {
                     // skip current surfer
                     if (Surfer::get_id() && Surfer::get_id() == $item['user_id']) {
                         continue;
                     }
                     // a user registered on this server
                     if ($item['user_id'] && ($watcher = Users::get($item['user_id']))) {
                         // skip banned users
                         if ($watcher['capability'] == '?') {
                             continue;
                         }
                         // ensure this surfer wants to be alerted
                         if ($watcher['without_alerts'] == 'Y') {
                             continue;
                         }
                         // sanity check
                         if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                             continue;
                         }
                         // use this email address
                         if ($watcher['full_name']) {
                             $recipient = Mailer::encode_recipient($watcher['email'], $watcher['full_name']);
                         } else {
                             $recipient = Mailer::encode_recipient($watcher['email'], $watcher['nick_name']);
                         }
                         // message title
                         $subject = sprintf(i18n::c('Updated: %s'), strip_tags($this->anchor->get_title()));
                         // headline
                         $headline = sprintf(i18n::c('%s has updated %s'), Surfer::get_link(), '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url() . '">' . $this->anchor->get_title() . '</a>');
                         // message to reader
                         $message = $this->get_invite_default_message('PUBLISH');
                         // assemble main content of this message
                         $message = Skin::build_mail_content($headline, $message);
                         // a set of links
                         $menu = array();
                         // call for action
                         $link = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
                         $menu[] = Skin::build_mail_button($link, i18n::c('View event details'), TRUE);
                         // finalize links
                         $message .= Skin::build_mail_menu($menu);
                         // threads messages
                         $headers = Mailer::set_thread($this->anchor->get_reference());
                         // get attachment from the overlay
                         $attachments = $this->get_invite_attachments('PUBLISH');
                         // post it
                         Mailer::notify(Surfer::from(), $recipient, $subject, $message, $headers, $attachments);
                     }
                 }
             }
             // bind one date to this record
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp']) {
                 $fields = array();
                 $fields['anchor'] = $reference;
                 $fields['date_stamp'] = $this->attributes['date_stamp'];
                 // there is an existing record
                 if ($date =& Dates::get_for_anchor($reference)) {
                     // update the record
                     $fields['id'] = $date['id'];
                     if (!($id = Dates::post($fields))) {
                         Logger::error(sprintf(i18n::s('Impossible to update date %s'), $this->attributes['date_stamp']));
                         return FALSE;
                     }
                     // create a record instead of raising an error, we are smart y'a'know
                 } else {
                     if (!($fields['id'] = Dates::post($fields))) {
                         Logger::error(i18n::s('Impossible to add an item.'));
                         return FALSE;
                     }
                 }
             }
             break;
     }
     // job done
     return TRUE;
 }
Exemple #4
0
}
// page canonical link
$context['page_link'] = Articles::get_permalink($item);
// not found -- help web crawlers
if (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!$permitted) {
    // make it clear to crawlers
    if (Surfer::is_crawler()) {
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
    } elseif (!Surfer::is_logged()) {
        Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Articles::get_permalink($item)));
    } elseif (isset($_REQUEST['requested']) && ($requested = Users::get($_REQUEST['requested'])) && $requested['email']) {
        // prepare the mail message
        $to = Mailer::encode_recipient($requested['email'], $requested['full_name']);
        $subject = sprintf(i18n::c('%s: %s'), i18n::c('Request'), strip_tags($item['title']));
        $message = Articles::build_notification('apply', $item, $overlay);
        $headers = Mailer::set_thread('article:' . $item['id']);
        // allow for skinnable template
        $message = Skin::build_mail_message($message);
        // build multiple parts, for HTML rendering
        $message = Mailer::build_multipart($message);
        // send the message to requested user
        if (Mailer::post(Surfer::from(), $to, $subject, $message, NULL, $headers)) {
            $text = sprintf(i18n::s('Your request has been transmitted to %s. Check your mailbox for feed-back.'), Skin::build_link(Users::get_permalink($requested), Codes::beautify_title($requested['full_name']), 'user'));
            $context['text'] .= Skin::build_block($text, 'note');
        }
        // follow-up navigation
        $context['text'] .= '<div>' . i18n::s('Where do you want to go now?') . '</div>';
        $menu = array();
Exemple #5
0
 /**
  * alert one user
  *
  * This function sends messages only to users ready to receive alerts and notifications.
  *
  * It ensures that only one alert is send to a user,
  * by maintaining an internal list of ids that have been processed.
  *
  * @param mixed an array of attributes, or only an id of the user profile
  * @param array components of a mail message to be submitted to Mailer::notify()
  * @return TRUE on success, FALSE otherwise
  */
 public static function alert($user, $mail)
 {
     global $context;
     // sanity check
     if (!isset($mail['subject']) || !$mail['subject'] || !isset($mail['message']) || !$mail['message']) {
         return FALSE;
     }
     // retrieve user attributes
     if (!isset($user['id']) && !($user = Users::get($user))) {
         return FALSE;
     }
     // skip banned users
     if (isset($user['capability']) && $user['capability'] == '?') {
         return FALSE;
     }
     // a valid address is required for e-mail...
     if (!isset($user['email']) || !$user['email'] || !preg_match(VALID_RECIPIENT, $user['email'])) {
         return FALSE;
     }
     // ensure poster wants alerts
     if (isset($user['without_alerts']) && $user['without_alerts'] == 'Y') {
         return FALSE;
     }
     // the list of users notified during overall script execution
     static $already_processed;
     if (!isset($already_processed)) {
         $already_processed = array();
     }
     // this user has already been notified
     if (in_array($user['id'], $already_processed)) {
         return FALSE;
     }
     // remember this recipient
     $already_processed[] = $user['id'];
     // use this email address
     if ($user['full_name']) {
         $recipient = Mailer::encode_recipient($user['email'], $user['full_name']);
     } else {
         $recipient = Mailer::encode_recipient($user['email'], $user['nick_name']);
     }
     // post a message to this particular user
     return Mailer::notify(Surfer::from(), $recipient, $mail['subject'], $mail['message'], isset($mail['headers']) ? $mail['headers'] : '', isset($mail['attachement']) ? $mail['attachement'] : null);
 }