Ejemplo n.º 1
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;
    }
}
Ejemplo n.º 2
0
/**
 * Sends an email, using Piwigo specific informations.
 *
 * @param string|array $to
 * @param array $args
 *       o from: sender [default value webmaster email]
 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
 *       o subject [default value 'Piwigo']
 *       o content: content of mail [default value '']
 *       o content_format: format of mail content [default value 'text/plain']
 *       o email_format: global mail format [default value $conf_mail['default_email_format']]
 *       o theme: theme to use [default value $conf_mail['mail_theme']]
 *       o mail_title: main title of the mail [default value $conf['gallery_title']]
 *       o mail_subtitle: subtitle of the mail [default value subject]
 * @param array $tpl - use these options to define a custom content template file
 *       o filename
 *       o dirname (optional)
 *       o assign (optional)
 *
 * @return boolean
 */
function pwg_mail($to, $args = array(), $tpl = array())
{
    global $conf, $conf_mail, $lang_info, $page;
    if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
        return true;
    }
    if (!isset($conf_mail)) {
        $conf_mail = get_mail_configuration();
    }
    include_once PHPWG_ROOT_PATH . 'include/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    foreach (get_clean_recipients_list($to) as $recipient) {
        $mail->addAddress($recipient['email'], $recipient['name']);
    }
    $mail->WordWrap = 76;
    $mail->CharSet = 'UTF-8';
    // Compute root_path in order have complete path
    set_make_full_url();
    if (empty($args['from'])) {
        $from = array('email' => $conf_mail['email_webmaster'], 'name' => $conf_mail['name_webmaster']);
    } else {
        $from = unformat_email($args['from']);
    }
    $mail->setFrom($from['email'], $from['name']);
    $mail->addReplyTo($from['email'], $from['name']);
    // Subject
    if (empty($args['subject'])) {
        $args['subject'] = 'Piwigo';
    }
    $args['subject'] = trim(preg_replace('#[\\n\\r]+#s', '', $args['subject']));
    $mail->Subject = $args['subject'];
    // Cc
    if (!empty($args['Cc'])) {
        foreach (get_clean_recipients_list($args['Cc']) as $recipient) {
            $mail->addCC($recipient['email'], $recipient['name']);
        }
    }
    // Bcc
    $Bcc = get_clean_recipients_list(@$args['Bcc']);
    if ($conf_mail['send_bcc_mail_webmaster']) {
        $Bcc[] = array('email' => get_webmaster_mail_address(), 'name' => '');
    }
    if (!empty($Bcc)) {
        foreach ($Bcc as $recipient) {
            $mail->addBCC($recipient['email'], $recipient['name']);
        }
    }
    // theme
    if (empty($args['theme']) or !in_array($args['theme'], array('clear', 'dark'))) {
        $args['theme'] = $conf_mail['mail_theme'];
    }
    // content
    if (!isset($args['content'])) {
        $args['content'] = '';
    }
    // try to decompose subject like "[....] ...."
    if (!isset($args['mail_title']) and !isset($args['mail_subtitle'])) {
        if (preg_match('#^\\[(.*)\\](.*)$#', $args['subject'], $matches)) {
            $args['mail_title'] = $matches[1];
            $args['mail_subtitle'] = $matches[2];
        }
    }
    if (!isset($args['mail_title'])) {
        $args['mail_title'] = $conf['gallery_title'];
    }
    if (!isset($args['mail_subtitle'])) {
        $args['mail_subtitle'] = $args['subject'];
    }
    // content type
    if (empty($args['content_format'])) {
        $args['content_format'] = 'text/plain';
    }
    $content_type_list = array();
    if ($conf_mail['mail_allow_html'] and @$args['email_format'] != 'text/plain') {
        $content_type_list[] = 'text/html';
    }
    $content_type_list[] = 'text/plain';
    $contents = array();
    foreach ($content_type_list as $content_type) {
        // key compose of indexes witch allow to cache mail data
        $cache_key = $content_type . '-' . $lang_info['code'];
        if (!isset($conf_mail[$cache_key])) {
            // instanciate a new Template
            if (!isset($conf_mail[$cache_key]['theme'])) {
                $conf_mail[$cache_key]['theme'] = get_mail_template($content_type);
                trigger_notify('before_parse_mail_template', $cache_key, $content_type);
            }
            $template =& $conf_mail[$cache_key]['theme'];
            $template->set_filename('mail_header', 'header.tpl');
            $template->set_filename('mail_footer', 'footer.tpl');
            $template->assign(array('GALLERY_URL' => get_gallery_home_url(), 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '', 'CONTENT_ENCODING' => get_pwg_charset(), 'CONTACT_MAIL' => $conf_mail['email_webmaster']));
            if ($content_type == 'text/html') {
                if ($template->smarty->templateExists('global-mail-css.tpl')) {
                    $template->set_filename('global-css', 'global-mail-css.tpl');
                    $template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global-css');
                }
                if ($template->smarty->templateExists('mail-css-' . $args['theme'] . '.tpl')) {
                    $template->set_filename('css', 'mail-css-' . $args['theme'] . '.tpl');
                    $template->assign_var_from_handle('MAIL_CSS', 'css');
                }
            }
        }
        $template =& $conf_mail[$cache_key]['theme'];
        $template->assign(array('MAIL_TITLE' => $args['mail_title'], 'MAIL_SUBTITLE' => $args['mail_subtitle']));
        // Header
        $contents[$content_type] = $template->parse('mail_header', true);
        // Content
        // Stored in a temp variable, if a content template is used it will be assigned
        // to the $CONTENT template variable, otherwise it will be appened to the mail
        if ($args['content_format'] == 'text/plain' and $content_type == 'text/html') {
            // convert plain text to html
            $mail_content = '<p>' . nl2br(preg_replace('/(https?:\\/\\/([-\\w\\.]+[-\\w])+(:\\d+)?(\\/([\\w\\/_\\.\\#-]*(\\?\\S+)?[^\\.\\s])?)?)/i', '<a href="$1">$1</a>', htmlspecialchars($args['content']))) . '</p>';
        } else {
            if ($args['content_format'] == 'text/html' and $content_type == 'text/plain') {
                // convert html text to plain text
                $mail_content = strip_tags($args['content']);
            } else {
                $mail_content = $args['content'];
            }
        }
        // Runtime template
        if (isset($tpl['filename'])) {
            if (isset($tpl['dirname'])) {
                $template->set_template_dir($tpl['dirname'] . '/' . $content_type);
            }
            if ($template->smarty->templateExists($tpl['filename'] . '.tpl')) {
                $template->set_filename($tpl['filename'], $tpl['filename'] . '.tpl');
                if (!empty($tpl['assign'])) {
                    $template->assign($tpl['assign']);
                }
                $template->assign('CONTENT', $mail_content);
                $contents[$content_type] .= $template->parse($tpl['filename'], true);
            } else {
                $contents[$content_type] .= $mail_content;
            }
        } else {
            $contents[$content_type] .= $mail_content;
        }
        // Footer
        $contents[$content_type] .= $template->parse('mail_footer', true);
    }
    // Undo Compute root_path in order have complete path
    unset_make_full_url();
    // Send content to PHPMailer
    if (isset($contents['text/html'])) {
        $mail->isHTML(true);
        $mail->Body = move_css_to_body($contents['text/html']);
        if (isset($contents['text/plain'])) {
            $mail->AltBody = $contents['text/plain'];
        }
    } else {
        $mail->isHTML(false);
        $mail->Body = $contents['text/plain'];
    }
    if ($conf_mail['use_smtp']) {
        // now we need to split port number
        if (strpos($conf_mail['smtp_host'], ':') !== false) {
            list($smtp_host, $smtp_port) = explode(':', $conf_mail['smtp_host']);
        } else {
            $smtp_host = $conf_mail['smtp_host'];
            $smtp_port = 25;
        }
        $mail->IsSMTP();
        // enables SMTP debug information (for testing) 2 - debug, 0 - no message
        $mail->SMTPDebug = 0;
        $mail->Host = $smtp_host;
        $mail->Port = $smtp_port;
        if (!empty($conf_mail['smtp_secure']) and in_array($conf_mail['smtp_secure'], array('ssl', 'tls'))) {
            $mail->SMTPSecure = $conf_mail['smtp_secure'];
        }
        if (!empty($conf_mail['smtp_user'])) {
            $mail->SMTPAuth = true;
            $mail->Username = $conf_mail['smtp_user'];
            $mail->Password = $conf_mail['smtp_password'];
        }
    }
    $ret = true;
    $pre_result = trigger_change('before_send_mail', true, $to, $args, $mail);
    if ($pre_result) {
        $ret = $mail->send();
        if (!$ret and (!ini_get('display_errors') or is_admin())) {
            trigger_error('Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING);
        }
        if ($conf['debug_mail']) {
            pwg_send_mail_test($ret, $mail, $args);
        }
    }
    return $ret;
}
function begin_users_env_nbm($is_to_send_mail = false)
{
    global $user, $lang, $lang_info, $conf, $env_nbm;
    // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
    $env_nbm['save_user'] = $user;
    // Save current language to stack, necessary because $user change during NBM
    switch_lang_to($user['language']);
    $env_nbm['is_to_send_mail'] = $is_to_send_mail;
    if ($is_to_send_mail) {
        // Init mail configuration
        $env_nbm['email_format'] = get_str_email_format($conf['nbm_send_html_mail']);
        $env_nbm['send_as_name'] = (isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : get_mail_sender_name();
        $env_nbm['send_as_mail_address'] = get_webmaster_mail_address();
        $env_nbm['send_as_mail_formated'] = format_email($env_nbm['send_as_name'], $env_nbm['send_as_mail_address']);
        // Init mail counter
        $env_nbm['error_on_mail_count'] = 0;
        $env_nbm['sent_mail_count'] = 0;
        // Save sendmail message info and error in the original language
        $env_nbm['msg_info'] = l10n('Mail sent to %s [%s].');
        $env_nbm['msg_error'] = l10n('Error when sending email to %s [%s].');
    }
}
Ejemplo n.º 4
0
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('tail' => 'footer.tpl'));
trigger_notify('loc_begin_page_tail');
$template->assign(array('VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : ''));
//--------------------------------------------------------------------- contact
if (!is_a_guest()) {
    $template->assign('CONTACT_MAIL', get_webmaster_mail_address());
}
//------------------------------------------------------------- generation time
$debug_vars = array();
if ($conf['show_queries']) {
    $debug_vars = array_merge($debug_vars, array('QUERIES_LIST' => $debug));
}
if ($conf['show_gt']) {
    if (!isset($page['count_queries'])) {
        $page['count_queries'] = 0;
        $page['queries_time'] = 0;
    }
    $time = get_elapsed_time($t2, get_moment());
    $debug_vars = array_merge($debug_vars, array('TIME' => $time, 'NB_QUERIES' => $page['count_queries'], 'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ') . ' s'));
}
$template->assign('debug', $debug_vars);
Ejemplo n.º 5
0
/**
 * Add new registered user in Piwigo users table from audit/synch action
 * To solve password synch problem, passwords are reset to NULL to force users to get a new password on their profile page
 * 
 * Based on user_mass_register plugin (thx to plg!)
 * 
 * @return : $errors
 */
function Synch_Piwigo_Adduser($fluxbb_id, $username, $password, $email)
{
    global $conf;
    load_language('plugin.lang', REGFLUXBB_PATH);
    $errors = register_user($username, $password, $email, false);
    if (empty($errors)) {
        include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
        $keyargs_content = array(get_l10n_args('Hello %s,', $username), get_l10n_args('To synchronize your forum access with the gallery you have been registered at %s!', $conf['gallery_title']), get_l10n_args('', ''), get_l10n_args('Here are your connection settings', ''), get_l10n_args('Username: %s', $username), get_l10n_args('Password: %s', $password), get_l10n_args('Email: %s', $email), get_l10n_args('', ''), get_l10n_args('Please change your password at your first connexion on the gallery', ''), 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($email, array('subject' => '[' . $conf['gallery_title'] . '] ' . l10n('Registration'), 'content' => l10n_args($keyargs_content), 'content_format' => 'text/plain'));
        $pwg_id = get_userid($username);
        FluxBB_Linkuser($pwg_id, $fluxbb_id, "NOK");
    }
    return $errors;
}