Example #1
0
 function T_($string, $req_locale = '')
 {
     global $current_locale, $locales, $evo_charset;
     if (empty($req_locale)) {
         if (empty($current_locale)) {
             // don't translate if we have no locale
             return $string;
         }
         $req_locale = $current_locale;
     }
     if ($req_locale == $current_locale) {
         // We have not asked for a different locale than the currently active one:
         $r = _($string);
         $messages_charset = $locales[$req_locale]['charset'];
     } else {
         // We have asked for another locale...
         if (locale_temp_switch($req_locale)) {
             global $current_charset;
             $r = _($string);
             $messages_charset = $current_charset;
             locale_restore_previous();
         } else {
             // Locale could not be activated:
             $r = $string;
             $messages_charset = 'iso-8859-1';
             // charset of our .php files
         }
     }
     if (!empty($evo_charset)) {
         $r = convert_charset($r, $evo_charset, $messages_charset);
     }
     return $r;
 }
Example #2
0
/**
 * Send newsletter emails
 */
function newsletter_send()
{
    global $DB, $Session;
    load_class('users/model/_userlist.class.php', 'UserList');
    // Initialize users list from session cache in order to get users IDs for newsletter
    $UserList = new UserList('admin');
    $UserList->memorize = false;
    $UserList->load_from_Request();
    $users_IDs = $UserList->filters['users'];
    // Get all active users which accept newsletter email
    $SQL = get_newsletter_users_sql($users_IDs);
    $users = $DB->get_col($SQL->get());
    echo sprintf(T_('Newsletter is sending for %s users...'), count($users)) . '<br /><br />';
    evo_flush();
    $email_newsletter_params = array('message' => $Session->get('newsletter_message'));
    foreach ($users as $user_ID) {
        $UserCache =& get_UserCache();
        $User = $UserCache->get_by_ID($user_ID);
        echo sprintf(T_('Email is sending for %s (%s)...'), $User->get_identity_link(), $User->get('email')) . ' ';
        // Send a newsletter in user's locale
        locale_temp_switch($User->get('locale'));
        $email_result = send_mail_to_User($user_ID, $Session->get('newsletter_title'), 'newsletter', $email_newsletter_params);
        locale_restore_previous();
        if ($email_result) {
            // Success sending
            echo T_('OK');
        } else {
            // Failed sending
            echo '<span class="red">' . T_('Failed') . '</span>';
        }
        echo '<br />';
        evo_flush();
    }
}
Example #3
0
 /**
  * Send an email to the user with a link to validate/confirm his email address.
  *
  * If the email could get sent, it saves the used "request_id" into the user's Session.
  *
  * @param string URL, where to redirect the user after he clicked the validation link (gets saved in Session).
  * @return boolean True, if the email could get sent; false if not
  */
 function send_validate_email($redirect_to_after, $blog = NULL, $email_changed = false)
 {
     global $app_name, $Session, $secure_htsrv_url, $baseurl, $servertimenow;
     global $Settings, $UserSettings;
     // Display messages depending on user email status
     display_user_email_status_message($this->ID);
     if ($Settings->get('validation_process') == 'easy') {
         // validation process is set to easy, send and easy activation email
         return send_easy_validate_emails(array($this->ID), false, $email_changed);
     }
     if (mail_is_blocked($this->email)) {
         // prevent trying to send an email to a blocked email address ( Note this is checked in the send_easy_validate_emails too )
         return false;
     }
     if (empty($redirect_to_after)) {
         // redirect to was not set
         $redirect_to_after = param('redirect_to', 'url', '');
         if (empty($redirect_to_after)) {
             if (is_admin_page()) {
                 $redirect_to_after = regenerate_url('action');
             } else {
                 $redirect_to_after = $this->get_userpage_url();
             }
         }
     }
     $request_id = generate_random_key(22);
     $blog_param = empty($blog) ? '' : '&inskin=1&blog=' . $blog;
     // Change locale here to localize the email subject and content
     locale_temp_switch($this->get('locale'));
     $email_template_params = array('status' => $this->status, 'blog_param' => $blog_param, 'request_id' => $request_id);
     $r = send_mail_to_User($this->ID, T_('Activate your account: $login$'), 'account_activate', $email_template_params, true);
     locale_restore_previous();
     if ($r) {
         // save request_id into Session
         $request_ids = $Session->get('core.validatemail.request_ids');
         if (!is_array($request_ids) || $email_changed) {
             // create new request ids array if it doesn't exist yet, or if user email changed ( this way the old request into the old email address won't be valid )
             $request_ids = array();
         }
         $request_ids[] = $request_id;
         $Session->set('core.validatemail.request_ids', $request_ids, 86400 * 2);
         // expires in two days (or when clicked)
         // set a redirect_to session variable because this way after the account will be activated we will know where to redirect
         $Session->set('core.validatemail.redirect_to', $redirect_to_after);
         $Session->dbsave();
         // save immediately
         // update last activation email timestamp
         $UserSettings->set('last_activation_email', date2mysql($servertimenow), $this->ID);
         $UserSettings->dbupdate();
     }
     return $r;
 }
Example #4
0
    /**
     * Send email notifications to subscribed users:
     *
     * @todo fp> SEPARATE MODERATION notifications from SUBSCRIPTION notifications
     * @todo shall we notify suscribers of blog were this is in extra-cat?
     * @todo cache message by locale like {@link Item::send_email_notifications()}
     * @todo dh> Indicator in url to see where the user came from (&from=subnote ["subscription notification"]) - Problem: too long urls.
     * @todo dh> "Beautify" like {@link Item::send_email_notifications()} ? fp > sure
     * @todo Should include "visibility status" in the mail to the Item's Author
     */
    function send_email_notifications()
    {
        global $DB, $admin_url, $debug, $Debuglog;
        $edited_Item =& $this->get_Item();
        $edited_Blog =& $edited_Item->get_Blog();
        $notify_array = array();
        if ($edited_Blog->get_setting('allow_subscriptions')) {
            // Get list of users who want to be notfied:
            // TODO: also use extra cats/blogs??
            // So far you get notifications for everything. We'll need a setting to decide if you want to received unmoderated (aka unpublished) comments or not.
            // Note: users receive comments on their own posts. This is done on purpose. Otherwise they think it's broken when they test the app.
            $sql = 'SELECT DISTINCT user_email, user_locale
								FROM T_subscriptions INNER JOIN T_users ON sub_user_ID = user_ID
							 WHERE sub_coll_ID = ' . $this->Item->blog_ID . '
							   AND sub_comments <> 0
							   AND LENGTH(TRIM(user_email)) > 0';
            $notify_list = $DB->get_results($sql);
            // Preprocess list:
            foreach ($notify_list as $notification) {
                $notify_array[$notification->user_email] = $notification->user_locale;
            }
        }
        // Check if we need to include the author:
        $item_author_User =& $edited_Item->get_creator_User();
        if ($item_author_User->notify && !empty($item_author_User->email)) {
            // Author wants to be notified...
            if (!($this->get_author_User() && $item_author_User->login == $this->author_User->login)) {
                // Author is not commenting on his own post...
                $notify_array[$item_author_User->email] = $item_author_User->locale;
            }
        }
        if (!count($notify_array)) {
            // No-one to notify:
            return false;
        }
        /*
         * We have a list of email addresses to notify:
         */
        // TODO: dh> this reveals the comments author's email address to all subscribers!!
        //           $notify_from should get used by default, unless the user has opted in to be the sender!
        // fp>If the subscriber has permission to moderate the comments, he SHOULD receive the email address.
        if ($this->get_author_User()) {
            // Comment from a registered user:
            $mail_from = '"' . $this->author_User->get('preferredname') . '" <' . $this->author_User->get('email') . '>';
        } elseif (!empty($this->author_email)) {
            // non-member, but with email address:
            $mail_from = "\"{$this->author}\" <{$this->author_email}>";
        } else {
            // Fallback (we have no email address):  fp>TODO: or the subscriber is not allowed to view it.
            global $notify_from;
            $mail_from = $notify_from;
        }
        // Send emails:
        foreach ($notify_array as $notify_email => $notify_locale) {
            locale_temp_switch($notify_locale);
            switch ($this->type) {
                case 'trackback':
                    /* TRANS: Subject of the mail to send on new trackbacks. First %s is the blog's shortname, the second %s is the item's title. */
                    $subject = T_('[%s] New trackback on "%s"');
                    break;
                default:
                    /* TRANS: Subject of the mail to send on new comments. First %s is the blog's shortname, the second %s is the item's title. */
                    $subject = T_('[%s] New comment on "%s"');
            }
            $subject = sprintf($subject, $edited_Blog->get('shortname'), $edited_Item->get('title'));
            $notify_message = T_('Blog') . ': ' . $edited_Blog->get('shortname') . "\n" . T_('Post') . ': ' . $edited_Item->get('title') . "\n";
            // Mail bloat: .' ( '.str_replace('&amp;', '&', $edited_Item->get_permanent_url())." )\n";
            // TODO: fp> We MAY want to force short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
            switch ($this->type) {
                case 'trackback':
                    $user_domain = gethostbyaddr($this->author_IP);
                    $notify_message .= T_('Website') . ": {$this->author} (IP: {$this->author_IP}, {$user_domain})\n";
                    $notify_message .= T_('Url') . ": {$this->author_url}\n";
                    break;
                default:
                    if ($this->get_author_User()) {
                        // Comment from a registered user:
                        $notify_message .= T_('Author') . ': ' . $this->author_User->get('preferredname') . ' (' . $this->author_User->get('login') . ")\n";
                    } else {
                        // Comment from visitor:
                        $user_domain = gethostbyaddr($this->author_IP);
                        $notify_message .= T_('Author') . ": {$this->author} (IP: {$this->author_IP}, {$user_domain})\n";
                        $notify_message .= T_('Email') . ": {$this->author_email}\n";
                        $notify_message .= T_('Url') . ": {$this->author_url}\n";
                    }
            }
            $notify_message .= T_('Comment') . ': ' . str_replace('&amp;', '&', $this->get_permanent_url()) . "\n" . $this->get('content') . "\n\n" . T_('Edit/Delete') . ': ' . $admin_url . '?ctrl=items&blog=' . $edited_Blog->ID . '&p=' . $edited_Item->ID . '&c=1#c' . $this->ID . "\n\n" . T_('Edit your subscriptions/notifications') . ': ' . str_replace('&amp;', '&', url_add_param($edited_Blog->gen_blogurl(), 'disp=subs')) . "\n";
            if ($debug) {
                $mail_dump = "Sending notification to {$notify_email}:<pre>Subject: {$subject}\n{$notify_message}</pre>";
                if ($debug >= 2) {
                    // output mail content - NOTE: this will kill sending of headers.
                    echo "<p>{$mail_dump}</p>";
                }
                $Debuglog->add($mail_dump, 'notification');
            }
            send_mail($notify_email, $subject, $notify_message, $mail_from);
            locale_restore_previous();
        }
    }
				'prev_start'  => '<td>',
				'prev_end'    => '</td>',
				'next_start'  => '<td class="right">',
				'next_end'    => '</td>',
				'block_end'   => '</tr></table>' ) );
	}*/
?>

<!-- =================================== START OF MAIN AREA =================================== -->

<?php 
// ------------------------------------ START OF POSTS ----------------------------------------
// Display message if no post:
display_if_empty();
while ($Item =& $MainList->get_item()) {
    locale_temp_switch($Item->locale);
    // Temporarily switch to post locale
    ?>

	<div class="bTitle"><h3 class="bTitle"><?php 
    $Item->title();
    ?>
</h3></div>

		<div class="bPost" lang="<?php 
    $Item->lang();
    ?>
">
			<?php 
    $Item->anchor();
    // Anchor for permalinks to refer to
Example #6
0
         /* exited */
     }
     break;
 case 'updatepwd':
     // Update password(The submit action of the change password form)
     param('reqID', 'string', '');
     if (!is_logged_in()) {
         // Don't allow not logged in user here, because it must be logged in on the action 'changepwd' above
         $Messages->add(T_('Invalid password change request! Please try again...'), 'error');
         $action = 'lostpassword';
         $login_required = true;
         // Do not display "Without login.." link on the form
         break;
     }
     $forgetful_User =& $current_User;
     locale_temp_switch($forgetful_User->locale);
     if (!$forgetful_User || empty($reqID)) {
         // This was not requested
         $Messages->add(T_('Invalid password change request! Please try again...'), 'error');
         $action = 'lostpassword';
         $login_required = true;
         // Do not display "Without login.." link on the form
         break;
     }
     // Validate provided reqID against the one stored in the user's session
     if ($Session->get('core.changepwd.request_id') != $reqID) {
         $Messages->add(T_('Invalid password change request! Please try again...'), 'error');
         $action = 'lostpassword';
         $login_required = true;
         // Do not display "Without login.." link on the form
         break;
Example #7
0
/**
 * Get a mail message text by template name
 *
 * @param string Template name
 * @param string Email format ( auto | html | text )
 * @param array Params
 * @param object User
 * @return string Mail message
 */
function mail_template($template_name, $format = 'auto', $params = array(), $User = NULL)
{
    global $current_charset, $is_admin_page;
    if (!empty($params['locale'])) {
        // Switch to locale for current email template
        locale_temp_switch($params['locale']);
    }
    $value_is_admin_page = $is_admin_page;
    // Set TRUE to use gender settings from back office
    $is_admin_page = true;
    // Set extension of template
    $template_exts = array();
    switch ($format) {
        case 'auto':
            // $template_exts['non-mime'] = '.txt.php'; // The area that is ignored by MIME-compliant clients
            $template_exts['text'] = '.txt.php';
            $template_exts['html'] = '.html.php';
            $boundary = $params['boundary'];
            $boundary_alt = 'b2evo-alt-' . md5(rand());
            $template_headers = array('text' => 'Content-Type: text/plain; charset=' . $current_charset, 'html' => 'Content-Type: text/html; charset=' . $current_charset);
            break;
        case 'html':
            $template_exts['html'] = '.html.php';
            break;
        case 'text':
            $template_exts['text'] = '.txt.php';
            break;
    }
    $template_message = '';
    if (isset($boundary, $boundary_alt)) {
        // Start new boundary content
        $template_message .= "\n" . '--' . $boundary . "\n";
        $template_message .= 'Content-Type: multipart/alternative; boundary="' . $boundary_alt . '"' . "\n\n";
    }
    foreach ($template_exts as $format => $ext) {
        if (isset($boundary, $boundary_alt) && $format != 'non-mime') {
            // Start new boundary alt content
            $template_message .= "\n" . '--' . $boundary_alt . "\n";
        }
        if (isset($template_headers[$format])) {
            // Header data for each content
            $template_message .= $template_headers[$format] . "\n\n";
        }
        // Get mail template
        ob_start();
        emailskin_include($template_name . $ext, $params);
        $template_message .= ob_get_clean();
        if (!empty($User)) {
            // Replace $login$ with gender colored link + icon in HTML format,
            //   and with simple login text in PLAIN TEXT format
            $user_login = $format == 'html' ? $User->get_colored_login(array('mask' => '$avatar$ $login$')) : $User->login;
            $template_message = str_replace('$login$', $user_login, $template_message);
        }
    }
    if (isset($boundary, $boundary_alt)) {
        // End all boundary contents
        $template_message .= "\n" . '--' . $boundary_alt . '--' . "\n";
        $template_message .= "\n" . '--' . $boundary . '--' . "\n";
    }
    // Return back the value
    $is_admin_page = $value_is_admin_page;
    if (!empty($params['locale'])) {
        // Restore previous locale
        locale_restore_previous();
    }
    return $template_message;
}
                        }
                        if ($allowed) {
                            // User has permission to edit comments with this author level
                            $cmt_count += $count;
                        }
                    }
                }
            }
            if ($cmt_count > 0) {
                // There are comments awaiting moderation on this blog and user has permission to moderate
                $blog_comments[$blog_ID] = $cmt_count;
            }
        }
    }
    if (empty($blog_comments)) {
        // There are no comments awaiting moderation that this user could moderate
        continue;
    }
    $params['blogs'] = array_keys($blog_comments);
    // This can be remvoved if this solution will remain
    $params['comments'] = $blog_comments;
    // Change locale here to localize the email subject and content
    locale_temp_switch($moderator_User->get('locale'));
    if (send_mail_to_User($moderator_ID, T_('Comment moderation reminder'), 'comments_unmoderated_reminder', $params, false)) {
        $mail_sent++;
    }
    locale_restore_previous();
}
$result_message = sprintf(T_('%d moderator have been notified!'), $mail_sent);
return 1;
/*OK*/
if (empty($users_to_remind_ids)) {
    // There is no user to remind after we have filtered out those ussers who haven't logged in since a long time
    $result_message = T_('It was not necessary to send any reminder!');
    return 1;
}
// Set TRUE to use gender settings from back office
global $is_admin_page;
$is_admin_page = true;
// Get all those user threads and their recipients where the corresponding users have unread messages
$unread_threads = get_users_unread_threads($users_to_remind_ids, NULL, 'array', 'html');
// Get unread thread urls
list($threads_link) = get_messages_link_to();
$reminder_sent = 0;
foreach ($users_to_remind_ids as $user_ID) {
    // send reminder email
    $email_template_params = array('unread_threads' => $unread_threads[$user_ID], 'threads_link' => $threads_link);
    $notify_User = $UserCache->get_by_ID($user_ID);
    // Change locale here to localize the email subject and content
    locale_temp_switch($notify_User->get('locale'));
    if (send_mail_to_User($user_ID, T_('You have unread messages!'), 'private_messages_unread_reminder', $email_template_params)) {
        // Update users last unread message reminder timestamp
        $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $user_ID);
        // save UserSettings after each email, because the cron task mail fail and users won't be updated!
        $UserSettings->dbupdate();
        $reminder_sent++;
    }
    locale_restore_previous();
}
$result_message = sprintf(T_('%d reminder emails were sent!'), $reminder_sent);
return 1;
/* ok */
Example #10
0
    /**
     * Send email notifications to subscribed users
     *
     * @todo fp>> shall we notify suscribers of blog were this is in extra-cat? blueyed>> IMHO yes.
     */
    function send_email_notifications($display = true)
    {
        global $DB, $admin_url, $debug, $Debuglog;
        $edited_Blog =& $this->get_Blog();
        if (!$edited_Blog->get_setting('allow_subscriptions')) {
            // Subscriptions not enabled!
            return;
        }
        if ($display) {
            echo "<div class=\"panelinfo\">\n";
            echo '<h3>', T_('Notifying subscribed users...'), "</h3>\n";
        }
        // Get list of users who want to be notfied:
        // TODO: also use extra cats/blogs??
        $sql = 'SELECT DISTINCT user_email, user_locale
							FROM T_subscriptions INNER JOIN T_users ON sub_user_ID = user_ID
						WHERE sub_coll_ID = ' . $this->blog_ID . '
							AND sub_items <> 0
							AND LENGTH(TRIM(user_email)) > 0';
        $notify_list = $DB->get_results($sql);
        // Preprocess list: (this comes form Comment::send_email_notifications() )
        $notify_array = array();
        foreach ($notify_list as $notification) {
            $notify_array[$notification->user_email] = $notification->user_locale;
        }
        if (empty($notify_array)) {
            // No-one to notify:
            if ($display) {
                echo '<p>', T_('No-one to notify.'), "</p>\n</div>\n";
            }
            return false;
        }
        /*
         * We have a list of email addresses to notify:
         */
        $this->get_creator_User();
        $mail_from = '"' . $this->creator_User->get('preferredname') . '" <' . $this->creator_User->get('email') . '>';
        // Send emails:
        $cache_by_locale = array();
        foreach ($notify_array as $notify_email => $notify_locale) {
            if (!isset($cache_by_locale[$notify_locale])) {
                // No message for this locale generated yet:
                locale_temp_switch($notify_locale);
                // Calculate length for str_pad to align labels:
                $pad_len = max(strlen(T_('Blog')), strlen(T_('Author')), strlen(T_('Title')), strlen(T_('Url')), strlen(T_('Content')));
                $cache_by_locale[$notify_locale]['subject'] = sprintf(T_('[%s] New post: "%s"'), $edited_Blog->get('shortname'), $this->get('title'));
                $cache_by_locale[$notify_locale]['message'] = str_pad(T_('Blog'), $pad_len) . ': ' . $edited_Blog->get('shortname') . ' ( ' . str_replace('&amp;', '&', $edited_Blog->gen_blogurl()) . " )\n" . str_pad(T_('Author'), $pad_len) . ': ' . $this->creator_User->get('preferredname') . ' (' . $this->creator_User->get('login') . ")\n" . str_pad(T_('Title'), $pad_len) . ': ' . $this->get('title') . "\n" . str_pad(T_('Url'), $pad_len) . ': ' . (empty($this->url) ? '-' : str_replace('&amp;', '&', $this->get('url'))) . "\n" . str_pad(T_('Content'), $pad_len) . ': ' . str_replace('&amp;', '&', $this->get_permanent_url()) . "\n\n" . $this->get('content') . "\n" . "\n-- \n" . T_('Edit/Delete') . ': ' . $admin_url . '?ctrl=items&blog=' . $this->blog_ID . '&p=' . $this->ID . "\n\n" . T_('Edit your subscriptions/notifications') . ': ' . str_replace('&amp;', '&', url_add_param($edited_Blog->gen_blogurl(), 'disp=subs')) . "\n";
                locale_restore_previous();
            }
            if ($display) {
                echo T_('Notifying:') . $notify_email . "<br />\n";
            }
            if ($debug >= 2) {
                echo "<p>Sending notification to {$notify_email}:<pre>{$cache_by_locale[$notify_locale]}['message']</pre>";
            }
            send_mail($notify_email, $cache_by_locale[$notify_locale]['subject'], $cache_by_locale[$notify_locale]['message'], $mail_from);
        }
        if ($display) {
            echo '<p>', T_('Done.'), "</p>\n</div>\n";
        }
    }
Example #11
0
global $locale_from_get, $disp_handler, $disp_handler_custom, $disp_handler_custom_found;
global $Session;
load_class('_core/ui/_menu.class.php', 'Menu');
/**
 * @global Menu Evobar menu on the top left (should be useed for content & system management features)
 */
global $topleft_Menu;
$topleft_Menu = new Menu();
/**
 * @global Menu Evobar menu on the top right (should be used for current user's session, profile & prefs features)
 */
global $topright_Menu;
$topright_Menu = new Menu();
// Switch to users locale (if not overridden via REQUEST):
if (!$locale_from_get) {
    locale_temp_switch($current_User->locale);
}
// Let the modules construct the menu:
modules_call_method('build_evobar_menu');
// Call AdminAfterToolbarInit to notify Plugins that the toolbar menus are initialized. Plugins can add entries.
$Plugins->trigger_event('AdminAfterEvobarInit');
?>

<div id="evo_toolbar" class="evo_toolbar_<?php 
echo $Hit->get_agent_name();
?>
">
	<div class="actions_right">
		<?php 
// Display evobar menu:
echo $topright_Menu->get_html_menu(NULL, 'evobar-menu-right');
Example #12
0
/**
 * Get a mail message text by template name
 *
 * @param string Template name
 * @param string Email format ( auto | html | text )
 * @param array Params
 * @param object User
 * @return string|array Mail message OR Array of the email contents when message is multipart content
 */
function mail_template($template_name, $format = 'auto', $params = array(), $User = NULL)
{
    global $current_charset;
    if (!empty($params['locale'])) {
        // Switch to locale for current email template
        locale_temp_switch($params['locale']);
    }
    // Set extension of template
    $template_exts = array();
    switch ($format) {
        case 'auto':
            // $template_exts['non-mime'] = '.txt.php'; // The area that is ignored by MIME-compliant clients
            $template_exts['text'] = '.txt.php';
            $template_exts['html'] = '.html.php';
            $boundary = $params['boundary'];
            $boundary_alt = 'b2evo-alt-' . md5(rand());
            $template_headers = array('text' => 'Content-Type: text/plain; charset=' . $current_charset, 'html' => 'Content-Type: text/html; charset=' . $current_charset);
            // Store all contents in this array for multipart message
            $template_contents = array('charset' => $current_charset, 'full' => '', 'html' => '', 'text' => '');
            break;
        case 'html':
            $template_exts['html'] = '.html.php';
            break;
        case 'text':
            $template_exts['text'] = '.txt.php';
            break;
    }
    $template_message = '';
    if (isset($boundary, $boundary_alt)) {
        // Start new boundary content
        $template_message .= "\n" . '--' . $boundary . "\n";
        $template_message .= 'Content-Type: multipart/alternative; boundary="' . $boundary_alt . '"' . "\n\n";
    }
    foreach ($template_exts as $format => $ext) {
        $formated_message = '';
        if (isset($boundary, $boundary_alt) && $format != 'non-mime') {
            // Start new boundary alt content
            $template_message .= "\n" . '--' . $boundary_alt . "\n";
        }
        if (isset($template_headers[$format])) {
            // Header data for each content
            $template_message .= $template_headers[$format] . "\n\n";
        }
        // Get mail template
        ob_start();
        emailskin_include($template_name . $ext, $params);
        $formated_message .= ob_get_clean();
        if (!empty($User)) {
            // Replace $login$ with gender colored link + icon in HTML format,
            //   and with simple login text in PLAIN TEXT format
            $user_login = $format == 'html' ? $User->get_colored_login(array('mask' => '$avatar$ $login$', 'use_style' => true)) : $User->login;
            $formated_message = str_replace('$login$', $user_login, $formated_message);
        }
        if ($format == 'html') {
            // Use "http://" for protocol-relative urls because email browsers cannot load such urls:
            $formated_message = preg_replace('~(src|href)="//~', '$1="http://', $formated_message);
        }
        $template_message .= $formated_message;
        if (isset($template_contents)) {
            // Multipart content
            $template_contents[$format] = $formated_message;
        }
    }
    if (isset($boundary, $boundary_alt)) {
        // End all boundary contents
        $template_message .= "\n" . '--' . $boundary_alt . '--' . "\n";
        $template_message .= "\n" . '--' . $boundary . '--' . "\n";
    }
    if (!empty($params['locale'])) {
        // Restore previous locale
        locale_restore_previous();
    }
    if (isset($template_contents)) {
        // Return array for multipart content
        $template_contents['full'] = $template_message;
        return $template_contents;
    } else {
        // Return string if email message contains one content (html or text)
        return $template_message;
    }
}
Example #13
0
 /**
  * Template function: Temporarily switch to this post's locale or to current blog's locale depending on setting
  */
 function locale_temp_switch()
 {
     global $Blog;
     if (!empty($Blog) && $Blog->get_setting('post_locale_source') == 'blog') {
         // Use locale what current blog is using now
         return;
     } else {
         // Use locale of this post
         $locale = $this->locale;
     }
     locale_temp_switch($locale);
 }
Example #14
0
 /**
  * We want to preview a single post, we are going to fake a lot of things...
  */
 function preview_from_request()
 {
     global $current_User;
     if (empty($current_User)) {
         // dh> only logged in user's can preview. Alternatively we need those checks where $current_User gets used below.
         return;
     }
     global $DB, $localtimenow, $Messages, $BlogCache;
     global $Plugins;
     $preview_userid = param('preview_userid', 'integer', true);
     $post_status = param('post_status', 'string', true);
     $post_locale = param('post_locale', 'string', $current_User->locale);
     $content = param('content', 'html', true);
     $post_title = param('post_title', 'html', true);
     $post_excerpt = param('post_excerpt', 'string', true);
     $post_url = param('post_url', 'string', '');
     $post_category = param('post_category', 'integer', true);
     $post_views = param('post_views', 'integer', 0);
     $renderers = param('renderers', 'array', array('default'));
     if (!is_array($renderers)) {
         // dh> workaround for param() bug. See rev 1.93 of /inc/_misc/_misc.funcs.php
         $renderers = array('default');
     }
     $comment_Blog =& $BlogCache->get_by_ID(get_catblog($post_category));
     if ($comment_Blog->allowcomments == 'post_by_post') {
         // param is required
         $post_comment_status = param('post_comment_status', 'string', true);
     } else {
         $post_comment_status = $comment_Blog->allowcomments;
     }
     // Get issue date, using the user's locale (because it's entered like this in the form):
     locale_temp_switch($current_User->locale);
     param_date('item_issue_date', T_('Please enter a valid issue date.'), false);
     // TODO: dh> get_param() is always true here, also on invalid dates:
     if (strlen(get_param('item_issue_date'))) {
         // only set it, if a date was given:
         param_time('item_issue_time');
         $item_issue_date = form_date(get_param('item_issue_date'), get_param('item_issue_time'));
         // TODO: cleanup...
     } else {
         $item_issue_date = date('Y-m-d H:i:s', $localtimenow);
     }
     locale_restore_previous();
     if (!($item_typ_ID = param('item_typ_ID', 'integer', NULL))) {
         $item_typ_ID = NULL;
     }
     if (!($item_st_ID = param('item_st_ID', 'integer', NULL))) {
         $item_st_ID = NULL;
     }
     if (!($item_assigned_user_ID = param('item_assigned_user_ID', 'integer', NULL))) {
         $item_assigned_user_ID = NULL;
     }
     if (!($item_deadline = param('item_deadline', 'string', NULL))) {
         $item_deadline = NULL;
     }
     $item_priority = param('item_priority', 'integer', NULL);
     // QUESTION: can this be also empty/NULL?
     // Do some optional filtering on the content
     // Typically stuff that will help the content to validate
     // Useful for code display.
     // Will probably be used for validation also.
     $Plugins_admin =& get_Cache('Plugins_admin');
     $Plugins_admin->filter_contents($post_title, $content, $renderers);
     $post_title = format_to_post($post_title);
     $content = format_to_post($content);
     $this->sql = "SELECT\r\n\t\t\t0 AS post_ID,\r\n\t\t\t{$preview_userid} AS post_creator_user_ID,\r\n\t\t\t{$preview_userid} AS post_lastedit_user_ID,\r\n\t\t\t'{$item_issue_date}' AS post_datestart,\r\n\t\t\t'{$item_issue_date}' AS post_datecreated,\r\n\t\t\t'{$item_issue_date}' AS post_datemodified,\r\n\t\t\t'" . $DB->escape($post_status) . "' AS post_status,\r\n\t\t\t'" . $DB->escape($post_locale) . "' AS post_locale,\r\n\t\t\t'" . $DB->escape($content) . "' AS post_content,\r\n\t\t\t'" . $DB->escape($post_title) . "' AS post_title,\r\n\t\t\t'" . $DB->escape($post_excerpt) . "' AS post_excerpt,\r\n\t\t\tNULL AS post_urltitle,\r\n\t\t\t'" . $DB->escape($post_url) . "' AS post_url,\r\n\t\t\t{$post_category} AS post_main_cat_ID,\r\n\t\t\t{$post_views} AS post_views,\r\n\t\t\t'' AS post_flags,\r\n\t\t\t'noreq' AS post_notifications_status,\r\n\t\t\tNULL AS post_notifications_ctsk_ID,\r\n\t\t\t" . bpost_count_words($content) . " AS post_wordcount,\r\n\t\t\t" . $DB->quote($post_comment_status) . " AS post_comment_status,\r\n\t\t\t'" . $DB->escape(implode('.', $renderers)) . "' AS post_renderers,\r\n\t\t\t" . $DB->quote($item_assigned_user_ID) . " AS post_assigned_user_ID,\r\n\t\t\t" . $DB->quote($item_typ_ID) . " AS post_ptyp_ID,\r\n\t\t\t" . $DB->quote($item_st_ID) . " AS post_pst_ID,\r\n\t\t\t" . $DB->quote($item_deadline) . " AS post_datedeadline,\r\n\t\t\t" . $DB->quote($item_priority) . " AS post_priority";
     $this->total_rows = 1;
     $this->total_pages = 1;
     $this->page = 1;
     // ATTENTION: we skip the parent on purpose here!! fp> refactor
     DataObjectList2::query(false, false, false, 'PREVIEW QUERY');
     $Item =& $this->Cache->instantiate($this->rows[0]);
     // Trigger plugin event, allowing to manipulate or validate the item before it gets previewed
     $Plugins->trigger_event('AppendItemPreviewTransact', array('Item' => &$Item));
     if ($errcontent = $Messages->display(T_('Invalid post, please correct these errors:'), '', false, 'error')) {
         $Item->content = $errcontent . "\n<hr />\n" . $content;
     }
     // little funky fix for IEwin, rawk on that code
     global $Hit;
     if ($Hit->is_winIE && !isset($IEWin_bookmarklet_fix)) {
         // QUESTION: Is this still needed? What about $IEWin_bookmarklet_fix? (blueyed)
         $Item->content = preg_replace('/\\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10). ';'", $Item->content);
     }
 }
Example #15
0
			<?php 
        if ($current_User->check_perm('options', 'edit') && $allow_po_extraction) {
            echo '<th class="lastcol">' . T_('Extract') . '</th>';
        }
    }
    ?>
	</tr>


	<?php 
    $i = 0;
    // counter to distinguish POSTed locales later
    foreach ($locales as $lkey => $lval) {
        $i++;
        // Generate preview of date/time-format:
        locale_temp_switch($lkey);
        $datefmt_preview = date_i18n($locales[$lkey]['datefmt'], $localtimenow);
        $timefmt_preview = date_i18n($locales[$lkey]['timefmt'], $localtimenow);
        locale_restore_previous();
        ?>
		<tr class="<?php 
        echo $i % 2 == 1 ? 'odd' : 'even';
        ?>
">
		<td class="firstcol left" title="<?php 
        echo T_('Priority') . ': ' . $locales[$lkey]['priority'] . ', ' . T_('Charset') . ': ' . $locales[$lkey]['charset'] . ', ' . T_('Lang file') . ': ' . $locales[$lkey]['messages'];
        ?>
">
			<?php 
        echo '<input type="hidden" name="loc_' . $i . '_locale" value="' . $lkey . '" />';
        locale_flag($lkey);
Example #16
0
 /**
  * We want to preview a single post, we are going to fake a lot of things...
  */
 function preview_from_request()
 {
     global $current_User;
     if (empty($current_User)) {
         // dh> only logged in user's can preview. Alternatively we need those checks where $current_User gets used below.
         return;
     }
     global $DB, $localtimenow, $Messages, $BlogCache;
     global $Plugins;
     if ($this->Blog->get_setting('allow_html_post')) {
         // HTML is allowed for this post
         $text_format = 'html';
     } else {
         // HTML is disallowed for this post
         $text_format = 'htmlspecialchars';
     }
     $preview_userid = param('preview_userid', 'integer', true);
     $post_status = param('post_status', 'string', true);
     $post_locale = param('post_locale', 'string', $current_User->locale);
     $content = param('content', $text_format, true);
     $post_title = param('post_title', $text_format, true);
     $post_titletag = param('titletag', 'string', true);
     $post_excerpt = param('post_excerpt', 'string', true);
     $post_url = param('post_url', 'string', '');
     check_categories_nosave($post_category, $post_extracats);
     $post_views = param('post_views', 'integer', 0);
     $renderers = param('renderers', 'array/string', array('default'));
     if (!is_array($renderers)) {
         // dh> workaround for param() bug. See rev 1.93 of /inc/_misc/_misc.funcs.php
         $renderers = array('default');
     }
     if ($post_category == 0) {
         $post_category = $this->Blog->get_default_cat_ID();
     }
     $comment_Blog =& $BlogCache->get_by_ID(get_catblog($post_category));
     if ($comment_Blog->get_setting('allow_comments') != 'never' && $comment_Blog->get_setting('disable_comments_bypost')) {
         // param is required
         $post_comment_status = param('post_comment_status', 'string', true);
     } else {
         $post_comment_status = $comment_Blog->get_setting('allow_comments');
     }
     // Get issue date, using the user's locale (because it's entered like this in the form):
     locale_temp_switch($current_User->locale);
     param_date('item_issue_date', T_('Please enter a valid issue date.'), false);
     // TODO: dh> get_param() is always true here, also on invalid dates:
     if (strlen(get_param('item_issue_date'))) {
         // only set it, if a date was given:
         param_time('item_issue_time');
         $item_issue_date = form_date(get_param('item_issue_date'), get_param('item_issue_time'));
         // TODO: cleanup...
     } else {
         $item_issue_date = date('Y-m-d H:i:s', $localtimenow);
     }
     locale_restore_previous();
     $item_typ_ID = param('item_typ_ID', 'integer', NULL);
     $item_st_ID = param('item_st_ID', 'integer', NULL);
     $item_assigned_user_ID = param('item_assigned_user_ID', 'integer', NULL);
     $item_deadline = param('item_deadline', 'string', NULL);
     $item_priority = param('item_priority', 'integer', NULL);
     // QUESTION: can this be also empty/NULL?
     // Do some optional filtering on the content
     // Typically stuff that will help the content to validate
     // Useful for code display.
     // Will probably be used for validation also.
     $Plugins_admin =& get_Plugins_admin();
     $params = array('object_type' => 'Item', 'object_Blog' => &$comment_Blog);
     $Plugins_admin->filter_contents($post_title, $content, $renderers, $params);
     $post_title = format_to_post($post_title);
     $content = format_to_post($content);
     $post_ID = param('post_ID', 'integer', 0);
     $this->sql = "SELECT\n\t\t\t{$post_ID} AS post_ID,\n\t\t\t{$preview_userid} AS post_creator_user_ID,\n\t\t\t{$preview_userid} AS post_lastedit_user_ID,\n\t\t\t'{$item_issue_date}' AS post_datestart,\n\t\t\t'{$item_issue_date}' AS post_datecreated,\n\t\t\t'{$item_issue_date}' AS post_datemodified,\n\t\t\t'{$item_issue_date}' AS post_last_touched_ts,\n\t\t\t0 AS post_dateset,\n\t\t\t'" . $DB->escape($post_status) . "' AS post_status,\n\t\t\t'" . $DB->escape($post_locale) . "' AS post_locale,\n\t\t\t'" . $DB->escape($content) . "' AS post_content,\n\t\t\t'" . $DB->escape($post_title) . "' AS post_title,\n\t\t\t'" . $DB->escape($post_titletag) . "' AS post_titletag,\n\t\t\t'" . $DB->escape($post_excerpt) . "' AS post_excerpt,\n\t\t\tNULL AS post_excerpt_autogenerated,\n\t\t\tNULL AS post_urltitle,\n\t\t\tNULL AS post_canonical_slug_ID,\n\t\t\tNULL AS post_tiny_slug_ID,\n\t\t\t'" . $DB->escape($post_url) . "' AS post_url,\n\t\t\t{$post_category} AS post_main_cat_ID,\n\t\t\t{$post_views} AS post_views,\n\t\t\t'' AS post_flags,\n\t\t\t'noreq' AS post_notifications_status,\n\t\t\tNULL AS post_notifications_ctsk_ID,\n\t\t\t" . bpost_count_words($content) . " AS post_wordcount,\n\t\t\t" . $DB->quote($post_comment_status) . " AS post_comment_status,\n\t\t\t'" . $DB->escape(implode('.', $renderers)) . "' AS post_renderers,\n\t\t\t" . $DB->quote($item_assigned_user_ID) . " AS post_assigned_user_ID,\n\t\t\t" . $DB->quote($item_typ_ID) . " AS post_ptyp_ID,\n\t\t\t" . $DB->quote($item_st_ID) . " AS post_pst_ID,\n\t\t\t" . $DB->quote($item_deadline) . " AS post_datedeadline,\n\t\t\t" . $DB->quote($item_priority) . " AS post_priority,";
     $this->sql .= $DB->quote(param('item_order', 'double', NULL)) . ' AS post_order' . ",\n" . $DB->quote(param('item_featured', 'integer', NULL)) . ' AS post_featured' . "\n";
     $this->total_rows = 1;
     $this->total_pages = 1;
     $this->page = 1;
     // ATTENTION: we skip the parent on purpose here!! fp> refactor
     DataObjectList2::query(false, false, false, 'PREVIEW QUERY');
     $Item =& $this->Cache->instantiate($this->rows[0]);
     // set Item settings
     $Item->set_setting('hide_teaser', param('item_hideteaser', 'integer', 0));
     $Item->set_setting('post_metadesc', param('metadesc', 'string', true));
     $Item->set_setting('post_custom_headers', param('custom_headers', 'string', true));
     // set custom Item settings
     foreach (array('double', 'varchar') as $type) {
         $count_custom_field = $comment_Blog->get_setting('count_custom_' . $type);
         $param_type = $type == 'varchar' ? 'string' : $type;
         for ($i = 1; $i <= $count_custom_field; $i++) {
             // For each custom double field:
             $field_guid = $comment_Blog->get_setting('custom_' . $type . $i);
             $Item->set_setting('custom_' . $type . '_' . $field_guid, param('item_' . $type . '_' . $field_guid, $param_type, NULL));
         }
     }
     // Trigger plugin event, allowing to manipulate or validate the item before it gets previewed
     $Plugins->trigger_event('AppendItemPreviewTransact', array('Item' => &$Item));
     if ($Messages->has_errors()) {
         $errcontent = $Messages->display(T_('Invalid post, please correct these errors:'), '', false);
         $Item->content = $errcontent . "\n<hr />\n" . $content;
     }
     // little funky fix for IEwin, rawk on that code
     global $Hit;
     if ($Hit->is_winIE() && !isset($IEWin_bookmarklet_fix)) {
         // QUESTION: Is this still needed? What about $IEWin_bookmarklet_fix? (blueyed)
         $Item->content = preg_replace('/\\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10). ';'", $Item->content);
     }
 }
Example #17
0
/**
 * Send account validation email with a permanent validation link
 *
 * @param array user ids to send validation email
 * @param boolean true if this email is an account activation reminder, false if the account status was changed right now
 * @return integer the number of successfully sent emails
 */
function send_easy_validate_emails($user_ids, $is_reminder = true, $email_changed = false)
{
    global $UserSettings, $servertimenow, $secure_htsrv_url;
    $UserCache =& get_UserCache();
    if (isset($GLOBALS['messaging_Module'])) {
        // Get already received messages for each recepient user
        $already_received_messages = get_users_unread_threads($user_ids);
    }
    $cache_by_locale = array();
    $email_sent = 0;
    foreach ($user_ids as $user_ID) {
        // Iterate through user ids and send account activation reminder to all user
        $User = $UserCache->get_by_ID($user_ID, false);
        if (!$User) {
            // user not exists
            continue;
        }
        if (!$User->check_status('can_be_validated')) {
            // User is validated or it is not allowed to be validated
            continue;
        }
        if ($is_reminder && !$UserSettings->get('send_activation_reminder')) {
            // This is an activation reminder, but user wouldn't like to receive this kind of emails
            continue;
        }
        if (mail_is_blocked($User->get('email'))) {
            // prevent trying to send an email to a blocked email address
            continue;
        }
        $notify_locale = $User->get('locale');
        $reminder_key = $UserSettings->get('last_activation_reminder_key', $User->ID);
        if (empty($reminder_key) || $email_changed) {
            // reminder key was not generated yet, or the user email address was changed and we need a new one, to invalidate old requests
            $reminder_key = generate_random_key(32);
            $UserSettings->set('last_activation_reminder_key', $reminder_key, $User->ID);
        }
        if (!isset($cache_by_locale[$notify_locale])) {
            // No subject for this locale generated yet:
            locale_temp_switch($notify_locale);
            $cache_by_locale[$notify_locale]['subject'] = T_('Activate your account: $login$');
            locale_restore_previous();
        }
        $email_template_params = array('locale' => $notify_locale, 'status' => $User->get('status'), 'reminder_key' => $reminder_key, 'is_reminder' => $is_reminder);
        if (!empty($already_received_messages[$User->ID])) {
            // add already received message list to email body
            $email_template_params['already_received_messages'] = $already_received_messages[$User->ID];
        }
        // Update notification sender's info from General settings
        $User->update_sender(true);
        if (send_mail_to_User($User->ID, $cache_by_locale[$notify_locale]['subject'], 'account_activate', $email_template_params, true)) {
            // save corresponding user settings right after the email was sent, to prevent not saving if an eroor occurs
            $email_sent++;
            // Set last remind activation email date and increase sent reminder emails number in UserSettings
            $UserSettings->set('last_activation_email', date2mysql($servertimenow), $User->ID);
            if ($is_reminder) {
                $reminder_sent_to_user = $UserSettings->get('activation_reminder_count', $User->ID);
                $UserSettings->set('activation_reminder_count', $reminder_sent_to_user + 1, $User->ID);
            }
            $UserSettings->dbupdate();
        }
    }
    return $email_sent;
}
Example #18
0
} elseif (!is_email($sender_address) || antispam_check($sender_address)) {
    $Messages->add(T_('Supplied email address is invalid.'), 'error');
}
if (empty($recipient_User) && empty($recipient_address)) {
    // should be prevented by UI
    debug_die('No recipient specified!');
}
// opt-out links:
if ($recipient_User) {
    // Member:
    // Change the locale so the email is in the recipients language
    locale_temp_switch($recipient_User->locale);
} else {
    // Visitor:
    // We don't know the recipient's language - Change the locale so the email is in the blog's language:
    locale_temp_switch($Blog->locale);
}
// Trigger event: a Plugin could add a $category="error" message here..
$Plugins->trigger_event('MessageFormSent', array('recipient_ID' => $recipient_id, 'item_ID' => $post_id, 'comment_ID' => $comment_id, 'subject' => &$subject, 'message' => &$message, 'Blog' => &$Blog, 'sender_name' => &$sender_name, 'sender_email' => &$sender_address));
$success_message = !$Messages->has_errors();
if ($success_message) {
    // no errors, try to send the message
    $email_template_params = array('sender_name' => $sender_name, 'sender_address' => $sender_address, 'Blog' => $Blog, 'message' => $message, 'comment_id' => $comment_id, 'post_id' => $post_id, 'recipient_User' => $recipient_User, 'Comment' => $Comment);
    if (empty($recipient_User)) {
        // Send mail to visitor
        // Get a message text from template file
        $message = mail_template('contact_message_new', 'text', $email_template_params);
        $success_message = send_mail($recipient_address, $recipient_name, $subject, $message, NULL, NULL, array('Reply-To' => $sender_address));
    } else {
        // Send mail to registered user
        $success_message = send_mail_to_User($recipient_User->ID, $subject, 'contact_message_new', $email_template_params, false, array('Reply-To' => $sender_address));
Example #19
0
File: login.php Project: LFSF/oras
 $ForgetfulUser =& $UserCache->get_by_login($login);
 if (!$ForgetfulUser) {
     // User does not exist
     // pretend that the email is sent for avoiding guessing user_login
     $Messages->add(T_('If you correctly typed in your login, a link to change your password has been sent to your registered email address.'), 'success');
     $action = 'req_login';
     break;
 }
 // echo 'email: ', $ForgetfulUser->email;
 // echo 'locale: '.$ForgetfulUser->locale;
 if ($demo_mode && ($ForgetfulUser->login == 'demouser' || $ForgetfulUser->ID == 1)) {
     $Messages->add(T_('You cannot reset this account in demo mode.'), 'error');
     $action = 'req_login';
     break;
 }
 locale_temp_switch($ForgetfulUser->locale);
 // DEBUG!
 // echo $message.' (password not set yet, only when sending email does not fail);
 if (empty($ForgetfulUser->email)) {
     $Messages->add(T_('You have no email address with your profile, therefore we cannot reset your password.') . ' ' . T_('Please try contacting the admin.'), 'error');
 } else {
     $request_id = generate_random_key(22);
     // 22 to make it not too long for URL but unique/safe enough
     $message = T_('Somebody (presumably you) has requested a password change for your account.') . "\n\n" . T_('Login:'******'Link to change your password:'******'login.php?action=changepwd' . '&login='******'&reqID=' . $request_id . '&sessID=' . $Session->ID . "\n\n" . T_('Please note:') . ' ' . T_('For security reasons the link is only valid for your current session (by means of your session cookie).') . "\n\n" . T_('If it was not you that requested this password change, simply ignore this mail.');
     if (!send_mail($ForgetfulUser->email, sprintf(T_('Password change request for %s'), $ForgetfulUser->login), $message, $notify_from)) {
         $Messages->add(T_('Sorry, the email with the link to reset your password could not be sent.') . '<br />' . T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error');
     } else {
         $Session->set('core.changepwd.request_id', $request_id, 86400 * 2);
         // expires in two days (or when clicked)
         $Session->dbsave();
         // save immediately
Example #20
0
    /**
     * Send email notifications to subscribed users:
     *
     * efy-asimo> moderatation and subscription notifications have been separated
     *
     * @param boolean true if send only moderation email, false otherwise
     * @param boolean true if send for everyone else but not for moterators, because a moderation email was sent for them
     * @param integer the user ID who executed the action which will be notified, or NULL if it was executed by an anonymous user
     */
    function send_email_notifications($only_moderators = false, $except_moderators = false, $executed_by_userid = NULL)
    {
        global $DB, $admin_url, $baseurl, $debug, $Debuglog, $htsrv_url;
        global $Settings, $UserSettings;
        if ($only_moderators && $except_moderators) {
            // at least one of them must be false
            return;
        }
        $edited_Item =& $this->get_Item();
        $edited_Blog =& $edited_Item->get_Blog();
        $owner_User = $edited_Blog->get_owner_User();
        $notify_users = array();
        $moderators = array();
        if ($only_moderators || $except_moderators) {
            // we need the list of moderators:
            $sql = 'SELECT DISTINCT user_email, user_ID, uset_value as notify_moderation
						FROM T_users
							LEFT JOIN T_coll_user_perms ON bloguser_user_ID = user_ID
							LEFT JOIN T_coll_group_perms ON bloggroup_group_ID = user_grp_ID
							LEFT JOIN T_users__usersettings ON uset_user_ID = user_ID AND uset_name = "notify_comment_moderation"
							LEFT JOIN T_groups ON grp_ID = user_grp_ID
						WHERE ( ( bloguser_blog_ID = ' . $edited_Blog->ID . ' AND bloguser_perm_edit_cmt IN ( "anon", "lt", "le", "all" ) )
								OR ( bloggroup_blog_ID = ' . $edited_Blog->ID . ' AND bloggroup_perm_edit_cmt IN ( "anon", "lt", "le", "all" ) )
								OR ( grp_perm_blogs = "editall" ) )
							AND LENGTH(TRIM(user_email)) > 0';
            $moderators_to_notify = $DB->get_results($sql);
            foreach ($moderators_to_notify as $moderator) {
                $notify_moderator = is_null($moderator->notify_moderation) ? $Settings->get('def_notify_comment_moderation') : $moderator->notify_moderation;
                if ($notify_moderator) {
                    // add user to notify
                    $moderators[] = $moderator->user_ID;
                }
            }
            if ($UserSettings->get('notify_comment_moderation', $owner_User->ID) && is_email($owner_User->get('email'))) {
                // add blog owner
                $moderators[] = $owner_User->ID;
            }
            // Load all moderators, and check each edit permission on this comment
            $UserCache =& get_UserCache();
            $UserCache->load_list($moderators);
            foreach ($moderators as $index => $moderator_ID) {
                $moderator_User = $UserCache->get_by_ID($moderator_ID, false);
                if (!$moderator_User || !$moderator_User->check_perm('comment!CURSTATUS', 'edit', false, $this)) {
                    // User doesn't exists any more, or has no permission to edit this comment!
                    unset($moderators[$index]);
                } elseif ($only_moderators) {
                    $notify_users[$moderator_ID] = 'moderator';
                }
            }
        }
        if (!$only_moderators) {
            // Not only moderators needs to be notified:
            $except_condition = '';
            if ($except_moderators && !empty($moderators)) {
                // Set except moderators condition. Exclude moderators who already got a notification email.
                $except_condition = ' AND user_ID NOT IN ( "' . implode('", "', $moderators) . '" )';
            }
            // Check if we need to include the item creator user:
            $creator_User =& $edited_Item->get_creator_User();
            if ($UserSettings->get('notify_published_comments', $creator_User->ID) && !empty($creator_User->email) && !in_array($creator_User->ID, $moderators)) {
                // Post creator wants to be notified, and post author is not a moderator...
                $notify_users[$creator_User->ID] = 'creator';
            }
            // Get list of users who want to be notified about the this post comments:
            if ($edited_Blog->get_setting('allow_item_subscriptions')) {
                // item subscriptions is allowed
                $sql = 'SELECT DISTINCT user_ID
									FROM T_items__subscriptions INNER JOIN T_users ON isub_user_ID = user_ID
								 WHERE isub_item_ID = ' . $edited_Item->ID . '
								   AND isub_comments <> 0
								   AND LENGTH(TRIM(user_email)) > 0' . $except_condition;
                $notify_list = $DB->get_results($sql);
                // Preprocess list:
                foreach ($notify_list as $notification) {
                    $notify_users[$notification->user_ID] = 'item_subscription';
                }
            }
            // Get list of users who want to be notfied about this blog comments:
            if ($edited_Blog->get_setting('allow_subscriptions')) {
                // blog subscription is allowed
                $sql = 'SELECT DISTINCT user_ID
								FROM T_subscriptions INNER JOIN T_users ON sub_user_ID = user_ID
							 WHERE sub_coll_ID = ' . $edited_Blog->ID . '
							   AND sub_comments <> 0
							   AND LENGTH(TRIM(user_email)) > 0' . $except_condition;
                $notify_list = $DB->get_results($sql);
                // Preprocess list:
                foreach ($notify_list as $notification) {
                    $notify_users[$notification->user_ID] = 'blog_subscription';
                }
            }
        }
        if ($executed_by_userid != NULL && isset($notify_users[$executed_by_userid])) {
            // don't notify the user who just created/updated this comment
            unset($notify_users[$executed_by_userid]);
        }
        if (!count($notify_users)) {
            // No-one to notify:
            return false;
        }
        /*
         * We have a list of user IDs to notify:
         */
        // TODO: dh> this reveals the comments author's email address to all subscribers!!
        //           $notify_from should get used by default, unless the user has opted in to be the sender!
        // fp>If the subscriber has permission to moderate the comments, he SHOULD receive the email address.
        // Get author email address. It will be visible for moderators/blog/post owners only -- NOT for other subscribers
        if ($this->get_author_User()) {
            // Comment from a registered user:
            $reply_to = $this->author_User->get('email');
            $author_name = $this->author_User->get('login');
            $author_ID = $this->author_User->ID;
        } elseif (!empty($this->author_email)) {
            // non-member, but with email address:
            $reply_to = $this->author_email;
            $author_name = $this->dget('author');
            $author_ID = NULL;
        } else {
            // Fallback (we have no email address):  fp>TODO: or the subscriber is not allowed to view it.
            $reply_to = NULL;
            $author_name = $this->dget('author');
            $author_ID = NULL;
        }
        // Load all users who will be notified, becasuse another way the send_mail_to_User funtion would load them one by one
        $UserCache =& get_UserCache();
        $UserCache->load_list(array_keys($notify_users));
        // Load a list with the blocked emails  in cache
        load_blocked_emails(array_keys($notify_users));
        // Send emails:
        foreach ($notify_users as $notify_user_ID => $notify_type) {
            // get data content
            $notify_User = $UserCache->get_by_ID($notify_user_ID);
            $notify_email = $notify_User->get('email');
            // init notification setting
            locale_temp_switch($notify_User->get('locale'));
            $notify_user_Group = $notify_User->get_Group();
            $notify_full = $notify_type == 'moderator' && $notify_user_Group->check_perm('comment_moderation_notif', 'full') || $notify_user_Group->check_perm('comment_subscription_notif', 'full');
            switch ($this->type) {
                case 'trackback':
                    /* TRANS: Subject of the mail to send on new trackbacks. First %s is the blog's shortname, the second %s is the item's title. */
                    $subject = T_('[%s] New trackback on "%s"');
                    break;
                default:
                    /* TRANS: Subject of the mail to send on new comments. */
                    // In case of full notification the first %s is blog name, the second %s is the item's title.
                    // In case of short notification the first %s is author login, the second %s is the item's title.
                    $subject = $notify_full ? T_('[%s] New comment on "%s"') : T_('%s posted a new comment on "%s"');
                    if ($only_moderators) {
                        if ($this->status == 'draft') {
                            $subject = $notify_full ? T_('[%s] New comment awaiting moderation on "%s"') : T_('New comment awaiting moderation: ') . $subject;
                        } else {
                            $subject = $notify_full ? T_('[%s] New comment may need moderation on "%s"') : T_('New comment may need moderation: ') . $subject;
                        }
                    }
            }
            if ($notify_type == 'moderator') {
                // moderation email
                $user_reply_to = $reply_to;
            } else {
                if ($notify_type == 'blog_subscription') {
                    // blog subscription
                    $user_reply_to = NULL;
                } else {
                    if ($notify_type == 'item_subscription') {
                        // item subscription
                        $user_reply_to = NULL;
                    } else {
                        if ($notify_type == 'creator') {
                            // user is the creator of the post
                            $user_reply_to = $reply_to;
                        } else {
                            debug_die('Unknown user subscription type');
                        }
                    }
                }
            }
            $subject = sprintf($subject, $notify_full ? $edited_Blog->get('shortname') : $author_name, $edited_Item->get('title'));
            $email_template_params = array('notify_full' => $notify_full, 'Comment' => $this, 'Blog' => $edited_Blog, 'Item' => $edited_Item, 'author_name' => $author_name, 'author_ID' => $author_ID, 'notify_type' => $notify_type);
            if ($debug) {
                $notify_message = mail_template('comment_new', 'text', $email_template_params);
                $mail_dump = "Sending notification to {$notify_email}:<pre>Subject: {$subject}\n{$notify_message}</pre>";
                if ($debug >= 2) {
                    // output mail content - NOTE: this will kill sending of headers.
                    echo "<p>{$mail_dump}</p>";
                }
                $Debuglog->add($mail_dump, 'notification');
            }
            // Send the email:
            // Note: Note activated users won't get notification email
            send_mail_to_User($notify_user_ID, $subject, 'comment_new', $email_template_params, false, array('Reply-To' => $user_reply_to));
            blocked_emails_memorize($notify_User->email);
            locale_restore_previous();
        }
        blocked_emails_display();
    }
Example #21
0
    /**
     * Send email notifications to subscribed users
     *
     * @todo fp>> shall we notify suscribers of blog were this is in extra-cat? blueyed>> IMHO yes.
     *
     * @param boolean Display notification messages or not
     * @param array Already notified user ids, or NULL if it is not the case
     */
    function send_email_notifications($display = true, $already_notified = NULL)
    {
        global $DB, $admin_url, $baseurl, $debug, $Debuglog;
        $edited_Blog =& $this->get_Blog();
        if (!$edited_Blog->get_setting('allow_subscriptions')) {
            // Subscriptions not enabled!
            return;
        }
        if ($display) {
            echo "<div class=\"panelinfo\">\n";
            echo '<h3>', T_('Notifying subscribed users...'), "</h3>\n";
        }
        // Create condition to not select already notified modertor users
        $except_users_condition = empty($already_notified) ? '' : ' AND sub_user_ID NOT IN ( ' . implode(',', $already_notified) . ' )';
        // Get list of users who want to be notfied:
        // TODO: also use extra cats/blogs??
        $sql = 'SELECT DISTINCT sub_user_ID
							FROM T_subscriptions
						WHERE sub_coll_ID = ' . $this->get_blog_ID() . '
							AND sub_items <> 0' . $except_users_condition;
        $notify_users = $DB->get_col($sql);
        if (empty($notify_users)) {
            // No-one to notify:
            if ($display) {
                echo '<p>', T_('No-one to notify.'), "</p>\n</div>\n";
            }
            return false;
        }
        // Load all users who will be notified
        $UserCache =& get_UserCache();
        $UserCache->load_list($notify_users);
        /*
         * We have a list of user IDs to notify:
         */
        $this->get_creator_User();
        // Load a list with the blocked emails in cache
        load_blocked_emails($notify_users);
        // Send emails:
        $cache_by_locale = array();
        foreach ($notify_users as $user_ID) {
            $notify_User = $UserCache->get_by_ID($user_ID, false, false);
            if (empty($notify_User)) {
                // skip invalid users
                continue;
            }
            $notify_email = $notify_User->get('email');
            if (empty($notify_email)) {
                // skip users with empty email address
                continue;
            }
            $notify_locale = $notify_User->get('locale');
            $notify_user_Group = $notify_User->get_Group();
            $notify_full = $notify_user_Group->check_perm('post_subscription_notif', 'full');
            if (!isset($cache_by_locale[$notify_locale])) {
                // No message for this locale generated yet:
                locale_temp_switch($notify_locale);
                $cache_by_locale[$notify_locale]['subject']['short'] = sprintf(T_('%s created a new post in blog "%s"'), $this->creator_User->get('login'), $edited_Blog->get('shortname'));
                $cache_by_locale[$notify_locale]['subject']['full'] = sprintf(T_('[%s] New post: "%s"'), $edited_Blog->get('shortname'), $this->get('title'));
                locale_restore_previous();
            }
            $email_template_params = array('locale' => $notify_locale, 'notify_full' => $notify_full, 'Item' => $this, 'recipient_User' => $notify_User, 'notify_type' => 'subscription');
            if ($display) {
                echo T_('Notifying:') . $notify_email . "<br />\n";
            }
            if ($debug >= 2) {
                $message_content = mail_template('post_new', 'txt', $email_template_params);
                echo "<p>Sending notification to {$notify_email}:<pre>{$message_content}</pre>";
            }
            $subject_type = $notify_full ? 'full' : 'short';
            send_mail_to_User($user_ID, $cache_by_locale[$notify_locale]['subject'][$subject_type], 'post_new', $email_template_params);
            blocked_emails_memorize($notify_User->email);
        }
        blocked_emails_display();
        if ($display) {
            echo '<p>', T_('Done.'), "</p>\n</div>\n";
        }
    }
Example #22
0
     $DB->rollback();
     // Delete, in case there's no transaction support:
     $new_User->dbdelete($Debuglog);
     $Messages->add(T_('No user account has been created!'), 'error');
     break;
     // break out to _reg_form.php
 }
 // User created:
 $DB->commit();
 $UserCache->add($new_User);
 // Send email to admin (using his locale):
 /**
  * @var User
  */
 $AdminUser =& $UserCache->get_by_ID(1);
 locale_temp_switch($AdminUser->get('locale'));
 $message = T_('New user registration on your blog') . ":\n" . "\n" . T_('Login:'******'Email') . ": {$email}\n" . "\n" . T_('Edit user') . ': ' . $admin_url . '?ctrl=users&user_ID=' . $new_User->ID . "\n";
 send_mail($AdminUser->get('email'), T_('New user registration on your blog'), $message, $notify_from);
 // ok, if this may fail..
 locale_restore_previous();
 $Plugins->trigger_event('AfterUserRegistration', array('User' => &$new_User));
 if ($Settings->get('newusers_mustvalidate')) {
     // We want that the user validates his email address:
     if ($new_User->send_validate_email($redirect_to)) {
         $Messages->add(T_('An email has been sent to your email address. Please click on the link therein to validate your account.'), 'success');
     } else {
         $Messages->add(T_('Sorry, the email with the link to validate and activate your password could not be sent.') . '<br />' . T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error');
         // fp> TODO: allow to enter a different email address (just in case it's that kind of problem)
     }
 }
 // Autologin the user. This is more comfortable for the user and avoids
    imap_expunge($mbox);
    pbm_msg(sprintf(T_('Deleted %d processed message(s) from inbox.'), $del_cntr), true);
}
imap_close($mbox);
// Send reports
if ($post_cntr > 0) {
    pbm_msg(sprintf(T_('New posts created: %d'), $post_cntr), true);
    $UserCache =& get_UserCache();
    foreach ($pbm_items as $Items) {
        // Send report to post author
        $to_user_ID = 0;
        foreach ($Items as $Item) {
            if ($to_user_ID == 0) {
                // Get author ID
                $to_user_ID = $Item->Author->ID;
                break;
            }
        }
        $email_template_params = array('Items' => $Items);
        $to_User = $UserCache->get_by_ID($to_user_ID);
        // Change locale here to localize the email subject and content
        locale_temp_switch($to_User->get('locale'));
        send_mail_to_User($to_user_ID, T_('Post by email report'), 'post_by_email_report', $email_template_params);
        locale_restore_previous();
    }
    // sam2kb> TODO: Send detailed report to blog owner
    // global $pbm_messages;
    // send_mail( $blog_owner_email, $blog_owner_name, T_('Post by email detailed report'), implode("\n",$pbm_messages) );
}
return 1;
// success
Example #24
0
 /**
  * Template function: Temporarily switch to this post's locale
  */
 function locale_temp_switch()
 {
     locale_temp_switch($this->locale);
 }
Example #25
0
    /**
     * Send email notification to recipients on new thread or new message event.
     *
     * @param boolean true if new thread, false if new message in the current thread
     * @param boolean the User who sent the message, in case of current User it may be NULL ( This is not the current User e.g. in case of welcome messages )
     * @return boolean True if all messages could be sent, false otherwise.
     */
    function send_email_notifications($new_thread = true, $from_User = NULL)
    {
        global $DB, $current_User, $admin_url, $baseurl, $app_name;
        global $Settings, $UserSettings, $servertimenow;
        // Select recipients of the current thread:
        $SQL = new SQL();
        $SQL->SELECT('u.user_ID, us.uset_value as notify_messages');
        $SQL->FROM('T_messaging__threadstatus ts
						INNER JOIN T_messaging__contact c
							ON ts.tsta_user_ID = c.mct_to_user_ID AND c.mct_from_user_ID = ' . $this->author_user_ID . ' AND c.mct_blocked = 0
						INNER JOIN T_users u
							ON ts.tsta_user_ID = u.user_ID
						LEFT OUTER JOIN T_users__usersettings us ON u.user_ID = us.uset_user_ID AND us.uset_name = "notify_messages"');
        $SQL->WHERE('ts.tsta_thread_ID = ' . $this->Thread->ID . ' AND ts.tsta_user_ID <> ' . $this->author_user_ID);
        $thrd_recipients = $DB->get_assoc($SQL->get());
        // set message link:
        list($message_link, $prefs_link) = get_messages_link_to($this->thread_ID);
        // Construct message subject and body:
        if ($new_thread) {
            $subject = NT_('%s just sent you a new message!');
        } elseif (count($thrd_recipients) == 1) {
            $subject = NT_('%s just replied to your message!');
        } else {
            $subject = NT_('%s just replied to a conversation you are involved in!');
        }
        // Get other unread threads
        $other_unread_threads = get_users_unread_threads(array_keys($thrd_recipients), $this->thread_ID, 'array', 'html');
        // Load all users who will be notified
        $UserCache =& get_UserCache();
        $UserCache->load_list(array_keys($thrd_recipients));
        // Send email notifications.
        $ret = true;
        $def_notify_messages = $Settings->get('def_notify_messages');
        foreach ($thrd_recipients as $recipient_ID => $notify_messages) {
            // Send mail to recipients who needs to be notified. recipients are already loaded into the UserCache
            if (!($notify_messages || is_null($notify_messages) && $def_notify_messages)) {
                // User should NOT be notified
                continue;
            }
            $email_template_params = array('recipient_ID' => $recipient_ID, 'new_thread' => $new_thread, 'thrd_recipients' => $thrd_recipients, 'Message' => $this, 'message_link' => $message_link, 'other_unread_threads' => $other_unread_threads[$recipient_ID], 'from_User' => $from_User);
            $notify_User = $UserCache->get_by_ID($recipient_ID);
            // Change locale here to localize the email subject and content
            locale_temp_switch($notify_User->get('locale'));
            $sender_login = $from_User === NULL ? $current_User->login : $from_User->login;
            $localized_subject = sprintf(T_($subject), $sender_login);
            // Note: Not activated users won't get notification email
            if (send_mail_to_User($recipient_ID, $localized_subject, 'private_message_new', $email_template_params)) {
                // email sent successful, update las_unread_message_reminder timestamp, because the notification contains all unread messages
                $UserSettings->set('last_unread_messages_reminder', date2mysql($servertimenow), $recipient_ID);
            } else {
                // message was not sent
                $ret = false;
            }
            locale_restore_previous();
        }
        // update reminder timestamp changes
        $UserSettings->dbupdate();
        return $ret;
    }