function update_user_comment_guestbook($comment, $post_key)
{
    global $conf;
    $comment_action = 'validate';
    if (!verify_ephemeral_key($post_key)) {
        $comment_action = 'reject';
    } else {
        if (!$conf['guestbook']['comments_validation'] or is_admin()) {
            $comment_action = 'validate';
        } else {
            $comment_action = 'moderate';
        }
    }
    if ($comment_action != 'reject') {
        $user_where_clause = '';
        if (!is_admin()) {
            $user_where_clause = '   AND author_id = \'' . $GLOBALS['user']['id'] . '\'';
        }
        $query = '
UPDATE ' . GUESTBOOK_TABLE . '
  SET content = \'' . $comment['content'] . '\',
      validated = \'' . ($comment_action == 'validate' ? 'true' : 'false') . '\',
      validation_date = ' . ($comment_action == 'validate' ? 'NOW()' : 'NULL') . '
  WHERE id = ' . $comment['comment_id'] . $user_where_clause . '
;';
        $result = pwg_query($query);
        // mail admin and ask to validate the comment
        if ($result and $conf['guestbook']['email_admin_on_comment_validation'] and 'moderate' == $comment_action) {
            include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
            $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id' => $comm['id']));
            $keyargs_content = array(get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username'])), get_l10n_args('Comment: %s', stripslashes($comment['content'])), get_l10n_args('', ''), get_l10n_args('Manage this user comment: %s', $comment_url), get_l10n_args('', ''), get_l10n_args('(!) This comment requires validation', ''));
            pwg_mail_notification_admins(get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username'])), $keyargs_content);
        }
    }
    return $comment_action;
}
예제 #2
0
/**
 * Notifies admins about updated or deleted comment.
 * Only used when no validation is needed, otherwise pwg_mail_notification_admins() is used.
 *
 * @param string $action edit, delete
 * @param array $comment
 */
function email_admin($action, $comment)
{
    global $conf;
    if (!in_array($action, array('edit', 'delete')) or $action == 'edit' and !$conf['email_admin_on_comment_edition'] or $action == 'delete' and !$conf['email_admin_on_comment_deletion']) {
        return;
    }
    include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
    $keyargs_content = array(get_l10n_args('Author: %s', $comment['author']));
    if ($action == 'delete') {
        $keyargs_content[] = get_l10n_args('This author removed the comment with id %d', $comment['comment_id']);
    } else {
        $keyargs_content[] = get_l10n_args('This author modified following comment:');
        $keyargs_content[] = get_l10n_args('Comment: %s', $comment['content']);
    }
    pwg_mail_notification_admins(get_l10n_args('Comment by %s', $comment['author']), $keyargs_content);
}
예제 #3
0
/**
 * Creates a new user.
 *
 * @param string $login
 * @param string $password
 * @param string $mail_adress
 * @param bool $notify_admin
 * @param array &$errors populated with error messages
 * @param bool $notify_user
 * @return int|false user id or false
 */
function register_user($login, $password, $mail_address, $notify_admin = true, &$errors = array(), $notify_user = false)
{
    global $conf;
    if ($login == '') {
        $errors[] = l10n('Please, enter a login');
    }
    if (preg_match('/^.* $/', $login)) {
        $errors[] = l10n('login mustn\'t end with a space character');
    }
    if (preg_match('/^ .*$/', $login)) {
        $errors[] = l10n('login mustn\'t start with a space character');
    }
    if (get_userid($login)) {
        $errors[] = l10n('this login is already used');
    }
    if ($login != strip_tags($login)) {
        $errors[] = l10n('html tags are not allowed in login');
    }
    $mail_error = validate_mail_address(null, $mail_address);
    if ('' != $mail_error) {
        $errors[] = $mail_error;
    }
    if ($conf['insensitive_case_logon'] == true) {
        $login_error = validate_login_case($login);
        if ($login_error != '') {
            $errors[] = $login_error;
        }
    }
    $errors = trigger_change('register_user_check', $errors, array('username' => $login, 'password' => $password, 'email' => $mail_address));
    // if no error until here, registration of the user
    if (count($errors) == 0) {
        $insert = array($conf['user_fields']['username'] => pwg_db_real_escape_string($login), $conf['user_fields']['password'] => $conf['password_hash']($password), $conf['user_fields']['email'] => $mail_address);
        single_insert(USERS_TABLE, $insert);
        $user_id = pwg_db_insert_id();
        // Assign by default groups
        $query = '
SELECT id
  FROM ' . GROUPS_TABLE . '
  WHERE is_default = \'' . boolean_to_string(true) . '\'
  ORDER BY id ASC
;';
        $result = pwg_query($query);
        $inserts = array();
        while ($row = pwg_db_fetch_assoc($result)) {
            $inserts[] = array('user_id' => $user_id, 'group_id' => $row['id']);
        }
        if (count($inserts) != 0) {
            mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $inserts);
        }
        $override = array();
        if ($language = get_browser_language()) {
            $override['language'] = $language;
        }
        create_user_infos($user_id, $override);
        if ($notify_admin and $conf['email_admin_on_new_user']) {
            include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
            $admin_url = get_absolute_root_url() . 'admin.php?page=user_list&username='******'User: %s', stripslashes($login)), get_l10n_args('Email: %s', $mail_address), get_l10n_args(''), get_l10n_args('Admin: %s', $admin_url));
            pwg_mail_notification_admins(get_l10n_args('Registration of %s', stripslashes($login)), $keyargs_content);
        }
        if ($notify_user and email_check_format($mail_address)) {
            include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
            $keyargs_content = array(get_l10n_args('Hello %s,', stripslashes($login)), get_l10n_args('Thank you for registering at %s!', $conf['gallery_title']), get_l10n_args('', ''), get_l10n_args('Here are your connection settings', ''), get_l10n_args('', ''), get_l10n_args('Link: %s', get_absolute_root_url()), get_l10n_args('Username: %s', stripslashes($login)), get_l10n_args('Password: %s', stripslashes($password)), get_l10n_args('Email: %s', $mail_address), get_l10n_args('', ''), get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()));
            pwg_mail($mail_address, array('subject' => '[' . $conf['gallery_title'] . '] ' . l10n('Registration'), 'content' => l10n_args($keyargs_content), 'content_format' => 'text/plain'));
        }
        trigger_notify('register_user', array('id' => $user_id, 'username' => $login, 'email' => $mail_address));
        return $user_id;
    } else {
        return false;
    }
}
예제 #4
0
/**
 * Function called from main.inc.php to send validation email
 *
 * @param : Type of email, user id, username, email address, confirmation (optional)
 * 
 */
function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
{
    global $conf;
    $conf_UAM = unserialize($conf['UserAdvManager']);
    $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
    include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
    $infos1_perso = "";
    $infos2_perso = "";
    $subject = "";
    // We have to get the user's language in database
    // ----------------------------------------------
    $query = '
SELECT user_id, language
FROM ' . USER_INFOS_TABLE . '
WHERE user_id = ' . $id . '
;';
    $data = pwg_db_fetch_assoc(pwg_query($query));
    // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language
    // -------------------------------------------------------------------------------------------------------------------------------
    if (empty($data)) {
        // And switch gallery to this language before using personalized and multilangual contents
        // ---------------------------------------------------------------------------------------
        $language = pwg_get_session_var('lang_switch', $user['language']);
        switch_lang_to($language);
    } else {
        // And switch gallery to this language before using personalized and multilangual contents
        // ---------------------------------------------------------------------------------------
        //$language = $data['language']; // Usefull for debugging
        switch_lang_to($data['language']);
        load_language('plugin.lang', UAM_PATH);
    }
    switch ($typemail) {
        case 1:
            // Confirmation email on user registration - Without information email (already managed by Piwigo)
            if (isset($conf_UAM['CONFIRMMAIL_SUBJECT']) and !empty($conf_UAM['CONFIRMMAIL_SUBJECT'])) {
                // Management of Extension flags ([username], [mygallery])
                // -------------------------------------------------------
                $patterns[] = '#\\[username\\]#i';
                $replacements[] = $username;
                $patterns[] = '#\\[mygallery\\]#i';
                $replacements[] = $conf['gallery_title'];
                if (function_exists('get_user_language_desc')) {
                    $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT'])) . "\n\n";
                } else {
                    $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT'])) . "\n\n";
                }
            }
            break;
        case 2:
            // Confirmation email on user profile update - Information email if modification done in user profile
            if (isset($conf_UAM['INFOMAIL_SUBJECT']) and !empty($conf_UAM['INFOMAIL_SUBJECT'])) {
                // Management of Extension flags ([username], [mygallery])
                // -------------------------------------------------------
                $patterns[] = '#\\[username\\]#i';
                $replacements[] = $username;
                $patterns[] = '#\\[mygallery\\]#i';
                $replacements[] = $conf['gallery_title'];
                if (function_exists('get_user_language_desc')) {
                    $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT'])) . "\n\n";
                } else {
                    $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT'])) . "\n\n";
                }
            }
            $password = !empty($password) ? $password : l10n('UAM_no_update_pwd');
            if (isset($conf_UAM['MAILINFO_TEXT']) and !empty($conf_UAM['MAILINFO_TEXT'])) {
                // Management of Extension flags ([username], [mygallery], [myurl])
                // ----------------------------------------------------------------
                $patterns[] = '#\\[username\\]#i';
                $replacements[] = $username;
                $patterns[] = '#\\[mygallery\\]#i';
                $replacements[] = $conf['gallery_title'];
                $patterns[] = '#\\[myurl\\]#i';
                $replacements[] = get_gallery_home_url();
                if (function_exists('get_user_language_desc')) {
                    $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT'])) . "\n\n";
                } else {
                    $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT'])) . "\n\n";
                }
            }
            if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') {
                if (isset($conf_UAM['HIDEPASSW']) and $conf_UAM['HIDEPASSW'] == 'true') {
                    $infos1 = array(get_l10n_args('UAM_infos_mail %s', stripslashes($username)), get_l10n_args('UAM_User: %s', stripslashes($username)), get_l10n_args('UAM_Password: %s', $password), get_l10n_args('Email: %s', $email), get_l10n_args('', ''));
                } else {
                    $infos1 = array(get_l10n_args('UAM_infos_mail %s', stripslashes($username)), get_l10n_args('UAM_User: %s', stripslashes($username)), get_l10n_args('Email: %s', $email), get_l10n_args('', ''));
                }
            }
            break;
    }
    if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true' and $confirm) {
        $infos2 = array(get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), get_l10n_args('', ''));
        if (isset($conf_UAM['CONFIRMMAIL_TEXT']) and !empty($conf_UAM['CONFIRMMAIL_TEXT'])) {
            // Management of Extension flags ([username], [mygallery], [myurl], [Kdays])
            // -------------------------------------------------------------------------
            $patterns[] = '#\\[username\\]#i';
            $replacements[] = $username;
            $patterns[] = '#\\[mygallery\\]#i';
            $replacements[] = $conf['gallery_title'];
            $patterns[] = '#\\[myurl\\]#i';
            $replacements[] = get_gallery_home_url();
            if (isset($conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT']) and $conf_UAM_ConfirmMail['CONFIRMMAIL_TIMEOUT'] == 'true') {
                $patterns[] = '#\\[Kdays\\]#i';
                $replacements[] = $conf_UAM_ConfirmMail['CONFIRMMAIL_DELAY'];
            }
            if (function_exists('get_user_language_desc')) {
                $infos2_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_TEXT'])) . "\n\n";
            } else {
                $infos2_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_TEXT'])) . "\n\n";
            }
        }
    }
    //	 $converted_res = ($confirm) ? 'true' : 'false';
    //	 UAMLog($typemail,$converted_res,$conf_UAM['CONFIRM_MAIL'],$subject);
    // Sending the email with subject and contents
    // -------------------------------------------
    if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local' and $confirm) {
        switch_lang_to(get_default_language());
        load_language('plugin.lang', UAM_PATH);
        $subject_admin = get_l10n_args('UAM_Subject admin validation for %s', $username);
        $content_admin = array(get_l10n_args('UAM_Manual_validation_needed_for %s', stripslashes($username)), get_l10n_args('', ''), get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)));
        pwg_mail_notification_admins($subject_admin, $content_admin, true);
    }
    if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true' and $confirm) {
        // Adding gallery URL at the end of the email
        if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') {
            $content_confirmation = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "") . get_absolute_root_url();
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_confirmation, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_confirmation);
            }
        } elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') {
            $content_confirmation = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "");
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_confirmation, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_confirmation);
            }
        } else {
            $content_confirmation = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "");
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_confirmation, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_confirmation);
            }
        }
    }
    if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true' and $typemail != 1) {
        // Adding gallery URL at the end of the email
        if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true') {
            $content_info = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "") . get_absolute_root_url();
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_info, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_info);
            }
        } elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false') {
            $content_info = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "");
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_info, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_info);
            }
        } else {
            $content_info = (isset($infos1) ? $infos1_perso . l10n_args($infos1) . "\n\n" : "") . (isset($infos2) ? $infos2_perso . l10n_args($infos2) . "\n\n" : "");
            pwg_mail(array('name' => stripslashes($username), 'email' => $email), array('content' => $content_info, 'content_format' => 'text/plain', 'subject' => $subject));
            // Send a copy to admins
            if (isset($conf_UAM['EMAILS_COPY_TO_ADMINS']) and $conf_UAM['EMAILS_COPY_TO_ADMINS'] == 'true') {
                UAM_Copy2Admins($subject, $content_info);
            }
        }
    }
    // Switching back to default language
    // ----------------------------------
    switch_lang_back();
}