Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting( E_ALL );
- ini_set( 'display_errors', 1 );
- /*
- =====================================================
- vldPersonals - by VLD Interactive Inc.
- ----------------------------------------------------
- http://www.vldpersonals.com/
- http://www.vldinteractive.com/
- -----------------------------------------------------
- Copyright (c) 2005-2014 VLD Interactive Inc.
- =====================================================
- THIS IS COPYRIGHTED SOFTWARE
- PLEASE READ THE LICENSE AGREEMENT
- http://www.vldpersonals.com/agreement/
- =====================================================
- */
- //------------------------------------------------
- // Includes
- //------------------------------------------------
- include SYS_PATH . 'includes/languages/' . SYS_LANG . '/lang.lib.account_register.php';
- include SYS_PATH . 'includes/fns/fns.validate.php';
- include SYS_PATH . 'includes/core/core.image.php';
- //------------------------------------------------
- // Check if the user is logged in
- //------------------------------------------------
- if ($SESSION->auth)
- redirect(VIR_PATH);
- //------------------------------------------------
- // Select registration form
- //------------------------------------------------
- show_register();
- //------------------------------------------------
- // Show registration form
- //------------------------------------------------
- function show_register()
- {
- global $DB, $LANG, $TEMPLATE, $SESSION, $PREFS;
- //------------------------------------------------
- // Set template file
- //------------------------------------------------
- $TEMPLATE->set_template("account_register.tpl");
- //------------------------------------------------
- // Assign page title
- //------------------------------------------------
- $TEMPLATE->assign("app_page", ($LANG['register']['app_register']));
- //------------------------------------------------
- // Check if registration is allowed
- //------------------------------------------------
- if ($PREFS->conf['allow_registration'] != 1)
- {
- $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1);
- return 0;
- }
- //------------------------------------------------
- // Set default values
- //------------------------------------------------
- $username = isset($_POST['username']) && $_POST['username'] ? $DB->strip_slashes(trim($_POST['username'])) : "";
- $password = isset($_POST['password']) && $_POST['password'] ? $DB->strip_slashes(trim($_POST['password'])) : "";
- $password_confirm = isset($_POST['password_confirm']) && $_POST['password_confirm'] ? $DB->strip_slashes(trim($_POST['password_confirm'])) : "";
- $email = isset($_POST['email']) && $_POST['email'] ? $DB->strip_slashes(trim($_POST['email'])) : "";
- $email_confirm = isset($_POST['email_confirm']) && $_POST['email_confirm'] ? $DB->strip_slashes(trim($_POST['email_confirm'])) : "";
- $captcha = isset($_POST['captcha']) && $_POST['captcha'] ? $DB->strip_slashes(trim($_POST['captcha'])) : "";
- $tos = isset($_POST['tos']) && $_POST['tos'] ? 1 : 0;
- $photo = isset($_FILES['photo']) ? $_FILES['photo'] : "";
- if ( isset($_POST['type_id']) && is_numeric($_POST['type_id']) && isset($PREFS->conf['profile_types'][$_POST['type_id']]) ) {
- $type_id = intval($_POST['type_id']);
- }
- elseif ( isset($_GET['type_id']) && is_numeric($_GET['type_id']) && isset($PREFS->conf['profile_types'][$_GET['type_id']]) ) {
- $type_id = intval($_GET['type_id']);
- }
- else {
- $type_id = $PREFS->conf['default_profile_type'];
- }
- $t = $index_type_id = 0;
- $fields = $default_fields = array();
- //------------------------------------------------
- // Parse profile groups and fields
- //------------------------------------------------
- foreach ($PREFS->conf['profile_types'] as $profile_type)
- {
- $i = 0;
- $fields[$t]['type_id'] = $profile_type['type_id'];
- $fields[$t]['type_label'] = $profile_type['type_label'];
- $fields[$t]['type_name'] = $profile_type['type_name'];
- foreach ($profile_type['profile_groups'] as $profile_group)
- {
- $j = 0;
- //------------------------------------------------
- // Assign dynamic group
- //------------------------------------------------
- if ($profile_group['group_in_registration'])
- {
- $fields[$t]['profile_groups'][$i] = $profile_group;
- $fields[$t]['profile_groups'][$i]['profile_fields'] = array();
- //------------------------------------------------
- // Assign static group
- //------------------------------------------------
- $TEMPLATE->assign('profile_group_' . $profile_group['group_label'], $profile_group['group_name']);
- }
- foreach ($profile_group['profile_fields'] as $profile_field)
- {
- if ($profile_field['field_in_registration'] && $profile_group['group_in_registration'])
- {
- //------------------------------------------------
- // Assign dynamic field
- //------------------------------------------------
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j] = $profile_field;
- //------------------------------------------------
- // Create years
- //------------------------------------------------
- if ($profile_field['field_type'] == "date" || $profile_field['field_type'] == "time" || $profile_field['field_type'] == "datetime")
- {
- $default_years = explode("\n", $profile_field['field_default'], 2);
- if ( count($default_years) == 2 ) {
- $startyear = date("Y") + $default_years[0];
- $endyear = date("Y") + $default_years[1];
- }
- else {
- $startyear = $endyear = date("Y");
- }
- $years = array();
- for ($y = $startyear; $y <= $endyear; $y++) {
- $years[$y] = $y;
- }
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['years'] = $years;
- }
- //------------------------------------------------
- // Set value
- //------------------------------------------------
- $value = $profile_field['field_type'] != "checkbox" ? '' : array();
- if (isset($_POST['isregister']) && $_POST['isregister'] && $profile_type['type_id'] == $type_id)
- {
- $index_type_id = $t;
- //------------------------------------------------
- // Set custom
- //------------------------------------------------
- if ($profile_field['field_type'] == "birthday")
- {
- $date_day = isset($_POST[$profile_field['field_label'].'_day']) && $_POST[$profile_field['field_label'].'_day'] ? intval($_POST[$profile_field['field_label'].'_day']) : 0;
- $date_month = isset($_POST[$profile_field['field_label'].'_month']) && $_POST[$profile_field['field_label'].'_month'] ? intval($_POST[$profile_field['field_label'].'_month']) : 0;
- $date_year = isset($_POST[$profile_field['field_label'].'_year']) && $_POST[$profile_field['field_label'].'_year'] ? intval($_POST[$profile_field['field_label'].'_year']) : 0;
- $value = ( $date_day && $date_month && $date_year ) ? str_pad($date_year, 4, "0", STR_PAD_LEFT) . str_pad($date_month, 2, "0", STR_PAD_LEFT) . str_pad($date_day, 2, "0", STR_PAD_LEFT) : '';
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = $date_day;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = $date_month;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = $date_year;
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_day', $date_day);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_month', $date_month);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_year', $date_year);
- }
- elseif ($profile_field['field_type'] == "date" || $profile_field['field_type'] == "time" || $profile_field['field_type'] == "datetime")
- {
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute']= isset($_POST[$profile_field['field_label'].'_minute']) && $_POST[$profile_field['field_label'].'_minute'] ? intval($_POST[$profile_field['field_label'].'_minute']) : 0;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour'] = isset($_POST[$profile_field['field_label'].'_hour']) && $_POST[$profile_field['field_label'].'_hour'] ? intval($_POST[$profile_field['field_label'].'_hour']) : 0;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = isset($_POST[$profile_field['field_label'].'_day']) && $_POST[$profile_field['field_label'].'_day'] ? intval($_POST[$profile_field['field_label'].'_day']) : 0;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = isset($_POST[$profile_field['field_label'].'_month']) && $_POST[$profile_field['field_label'].'_month'] ? intval($_POST[$profile_field['field_label'].'_month']) : 0;
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = isset($_POST[$profile_field['field_label'].'_year']) && $_POST[$profile_field['field_label'].'_year'] ? intval($_POST[$profile_field['field_label'].'_year']) : 0;
- $value = mktime($fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute'], 0, $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year']);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_minute', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute']);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_hour', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour']);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_day', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day']);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_month', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month']);
- $TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_year', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year']);
- }
- elseif ($profile_field['field_type'] == "checkbox")
- {
- $value = ( isset($_POST[$profile_field['field_label']]) ) ? $_POST[$profile_field['field_label']] : array();
- }
- elseif ($profile_field['field_type'] == "textarea")
- {
- $value = isset($_POST[$profile_field['field_label']]) ? $DB->strip_slashes(trim($_POST[$profile_field['field_label']])) : "";
- $value = str_replace("\r", '', $value);
- $value = preg_replace('/[ ]+/', ' ', $value);
- $value = preg_replace('/\n{3,}/', "\n\n", $value);
- $value = filter_wordwrap($value);
- }
- else
- {
- $value = isset($_POST[$profile_field['field_label']]) ? $DB->strip_slashes(trim($_POST[$profile_field['field_label']])) : "";
- }
- //------------------------------------------------
- // Apply filter if necessary
- //------------------------------------------------
- if ($SESSION->conf['apply_word_filter'] && ($profile_field['field_type'] == "textarea" || $profile_field['field_type'] == "text")) {
- $value = filter_words($value);
- }
- //------------------------------------------------
- // Assign dynamic field
- //------------------------------------------------
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value'] = $value;
- }
- else
- {
- if ( in_array($profile_field['field_type'], array("radio", "combo")) )
- {
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value'] = $profile_field['field_default'];
- }
- elseif ( in_array($profile_field['field_type'], array("date", "datetime", "time", "birthday")) )
- {
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = '';
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = '';
- $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = '';
- }
- }
- //------------------------------------------------
- // Assign static field
- //------------------------------------------------
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_name', $profile_field['field_name']);
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_type', $profile_field['field_type']);
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_maxlength', $profile_field['field_maxlength']);
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_default', $profile_field['field_default']);
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_items', $profile_field['field_items']);
- $TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_value', $value);
- $j++;
- }
- elseif ( $profile_type['type_id'] == $type_id )
- {
- $default_fields[] = $profile_field;
- }
- }
- if ($profile_group['group_in_registration'])
- {
- $i++;
- }
- }
- $t++;
- }
- echo '<pre>';
- var_dump ($TEMPLATE) ;
- echo '</pre>';
- //------------------------------------------------
- // Check if the user has clicked on Submit
- //------------------------------------------------
- if (isset($_POST['isregister']) && $_POST['isregister'])
- {
- //------------------------------------------------
- // Register user
- //------------------------------------------------
- save_register($type_id, $index_type_id, $username, $password, $password_confirm, $email, $email_confirm, $photo, $tos, $captcha, $fields, $default_fields);
- }
- else
- {
- //------------------------------------------------
- // Set default birthday
- //------------------------------------------------
- $birthday_day = 1;
- $birthday_month = 1;
- $birthday_year = date("Y") - $PREFS->conf['min_age'];
- }
- $_SESSION['captcha'] = random_string(5);
- //------------------------------------------------
- // Create minutes array
- //------------------------------------------------
- for ($i = 0; $i <= 59; $i++)
- $minutes[str_pad($i, 2, '0', STR_PAD_LEFT)] = str_pad($i, 2, '0', STR_PAD_LEFT);
- //------------------------------------------------
- // Create hours array
- //------------------------------------------------
- for ($i = 0; $i <= 23; $i++)
- $hours[str_pad($i, 2, '0', STR_PAD_LEFT)] = str_pad($i, 2, '0', STR_PAD_LEFT);
- //------------------------------------------------
- // Create days array
- //------------------------------------------------
- for ($i = 1; $i <= 31; $i++)
- $days[$i] = $i;
- //------------------------------------------------
- // Create years array
- //------------------------------------------------
- $startyear = date("Y") - $PREFS->conf['min_age'];
- $endyear = date("Y") - 90;
- $birthdayyears = array();
- for ($i = $startyear; $i >= $endyear; $i--)
- $birthdayyears[$i] = $i;
- //------------------------------------------------
- // Create months array
- //------------------------------------------------
- $months[1] = ($LANG['core']['bday_january']);
- $months[2] = ($LANG['core']['bday_february']);
- $months[3] = ($LANG['core']['bday_march']);
- $months[4] = ($LANG['core']['bday_april']);
- $months[5] = ($LANG['core']['bday_may']);
- $months[6] = ($LANG['core']['bday_june']);
- $months[7] = ($LANG['core']['bday_july']);
- $months[8] = ($LANG['core']['bday_august']);
- $months[9] = ($LANG['core']['bday_september']);
- $months[10] = ($LANG['core']['bday_october']);
- $months[11] = ($LANG['core']['bday_november']);
- $months[12] = ($LANG['core']['bday_december']);
- //------------------------------------------------
- // Create yes/no array
- //------------------------------------------------
- $yesnobox[1] = ($LANG['core']['yes']);
- $yesnobox[0] = ($LANG['core']['no']);
- //------------------------------------------------
- // Get profile types
- //------------------------------------------------
- $profiletypes = get_profile_types(1);
- //------------------------------------------------
- // Assign template vars
- //------------------------------------------------
- $TEMPLATE->assign("registration_username", htmlentities2utf8($username));
- $TEMPLATE->assign("registration_password", htmlentities2utf8($password));
- $TEMPLATE->assign("registration_password_confirm", htmlentities2utf8($password_confirm));
- $TEMPLATE->assign("registration_email", htmlentities2utf8($email));
- $TEMPLATE->assign("registration_email_confirm", htmlentities2utf8($email_confirm));
- $TEMPLATE->assign("registration_type_id", $type_id);
- $TEMPLATE->assign("is_tos", $PREFS->conf['registration_tos']);
- $TEMPLATE->assign("is_captcha", $PREFS->conf['registration_captcha'] && extension_loaded('gd'));
- $TEMPLATE->assign("registration_tos", $tos);
- $TEMPLATE->assign("days", $days);
- $TEMPLATE->assign("months", $months);
- $TEMPLATE->assign("birthday_years", $birthdayyears);
- $TEMPLATE->assign("minutes", $minutes);
- $TEMPLATE->assign("hours", $hours);
- $TEMPLATE->assign("profile_types", $fields);
- $TEMPLATE->assign("yesnobox", $yesnobox);
- $TEMPLATE->assign("profiletypes", $profiletypes);
- return 1;
- }
- // End Function
- //------------------------------------------------
- // Save registration form
- //------------------------------------------------
- function save_register($type_id, $index_type_id, $username, $password, $password_confirm, $email, $email_confirm, $photo, $tos, $captcha, $fields, $default_fields)
- {
- global $DB, $LANG, $TEMPLATE, $PREFS, $SESSION;
- //------------------------------------------------
- // Validate username
- //------------------------------------------------
- $valid_username = validate_username($username, $PREFS->conf['min_username_length']);
- if ($username == "")
- {
- $TEMPLATE->set_message("error", ($LANG['register']['empty_username']), 0, 0);
- return 0;
- }
- elseif ($valid_username == 1)
- {
- $TEMPLATE->set_message("error", str_replace("%1%", $PREFS->conf['min_username_length'], ($LANG['register']['username_too_long'])), 0, 0);
- return 0;
- }
- elseif ($valid_username == 2)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_username']), 0, 0);
- return 0;
- }
- elseif ($valid_username == 3)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_username_digits']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Check if username is banned
- //------------------------------------------------
- $usernames = array_map('trim', explode("\n", $PREFS->conf['banned_usernames']));
- if ( in_array($username, $usernames) )
- {
- $TEMPLATE->set_message("error", ($LANG['register']['banned_username']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Validate password
- //------------------------------------------------
- $valid_password = validate_password($password, $PREFS->conf['min_password_length']);
- if ($password == "" || $password_confirm == "")
- {
- $TEMPLATE->set_message("error", ($LANG['register']['empty_passwords']), 0);
- return 0;
- }
- elseif ($valid_password == 1)
- {
- $TEMPLATE->set_message("error", str_replace("%1%", $PREFS->conf['min_password_length'], ($LANG['register']['password_too_long'])), 0, 0);
- return 0;
- }
- elseif ($valid_password == 2)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_password']), 0, 0);
- return 0;
- }
- elseif ($password != $password_confirm)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['passwords_dont_match']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Validate email
- //------------------------------------------------
- $valid_email = validate_email($email);
- if ($email == "")
- {
- $TEMPLATE->set_message("error", ($LANG['register']['empty_emails']), 0, 0);
- return 0;
- }
- elseif ($valid_email == 1)
- {
- $TEMPLATE->set_message("error", str_replace("%1%", 4, ($LANG['register']['email_too_long'])), 0, 0);
- return 0;
- }
- elseif ($valid_email == 2)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_email']), 0, 0);
- return 0;
- }
- elseif ($email != $email_confirm)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['emails_dont_match']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Check if email address is allowed
- //------------------------------------------------
- $emails = explode("\n", $PREFS->conf['banned_emails']);
- //------------------------------------------------
- // Check if the email is banned
- //------------------------------------------------
- foreach ($emails as $value)
- {
- $value = trim($value);
- if (substr($value, 0, 1) == '@' && strpos(strtolower($email), strtolower($value)) !== false)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['banned_email']), 0, 0);
- return 0;
- }
- elseif ($value == $email)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['banned_email']), 0, 0);
- return 0;
- }
- }
- if (!$type_id)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['empty_type_id']), 0, 0);
- return 0;
- }
- $query_keys = $query_values = "";
- $items_values = array();
- //------------------------------------------------
- // Validate profile fields
- //------------------------------------------------
- if ( isset($fields[$index_type_id]['profile_groups']) )
- {
- foreach ($fields[$index_type_id]['profile_groups'] as $field_group)
- {
- foreach($field_group['profile_fields'] as $field)
- {
- if ($field_group['group_in_registration'] && $field['field_in_registration'])
- {
- //------------------------------------------------
- // Parse items
- //------------------------------------------------
- if ($field['field_type'] == 'checkbox')
- {
- foreach ( $field['field_value'] as $item_id ) {
- if ( is_numeric($item_id) && isset($field['field_items'][$item_id]) ) {
- $items_values[$field['field_id']][] = $item_id;
- }
- }
- if ($field['field_required'] && (!isset($items_values[$field['field_id']]) || !$items_values[$field['field_id']]) ) {
- $TEMPLATE->set_message("error", str_replace("%1%", $field['field_name'], ($LANG['register']['empty_required'])), 0, 0);
- return 0;
- }
- }
- elseif ($field['field_type'] == 'birthday')
- {
- $member_age = $field['field_value_year'].str_pad($field['field_value_month'], 2, '0', STR_PAD_LEFT).str_pad($field['field_value_day'], 2, '0', STR_PAD_LEFT);
- $allowed_age = (date("Y") - $PREFS->conf['min_age']).date("md");
- if ( $member_age > $allowed_age )
- {
- $TEMPLATE->set_message("error", str_replace("%age%", $PREFS->conf['min_age'], ($LANG['register']['young_member'])), 0, 0);
- return 0;
- }
- }
- //------------------------------------------------
- // Validate the value
- //------------------------------------------------
- if ($field['field_required'] && ($field['field_type'] != "image" && $field['field_value'] == ""))
- {
- $TEMPLATE->set_message("error", str_replace("%1%", $field['field_name'], ($LANG['register']['empty_required'])), 0, 0);
- return 0;
- }
- elseif ($field['field_maxlength'] && strlen($field['field_value']) > $field['field_maxlength'])
- {
- $TEMPLATE->set_message("error", str_replace("%1%", $field['field_name'], str_replace("%2%", $field['field_maxlength'], ($LANG['register']['field_too_long']))), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Build query
- //------------------------------------------------
- if ($field['field_type'] != "image" && $field['field_type'] != "checkbox") {
- $query_keys .= ",data_" . $field['field_label'];
- $query_values .= ",'" . mysql_real_escape_string($field['field_value']) . "'";
- }
- }
- }
- }
- }
- //------------------------------------------------
- // Validate profile fields
- //------------------------------------------------
- foreach ($default_fields as $field)
- {
- if ($field['field_type'] != "checkbox") {
- $query_keys .= ",data_" . $field['field_label'];
- $query_values .= ",'" . mysql_real_escape_string($field['field_default']) . "'";
- }
- elseif ($field['field_type'] != "image") {
- if ( $field['field_default'] ) {
- $field['field_default'] = @array_map("intval", explode(",", $field['field_default']));
- if ( isset($field['field_default'][0]) && $field['field_default'][0] == 0 ) {
- unset($field['field_default'][0]);
- }
- if ( $field['field_default'] ) {
- $items_values[$field['field_id']] = $field['field_default'];
- }
- }
- }
- }
- //------------------------------------------------
- // Check if TOS is available and accepted
- //------------------------------------------------
- if ($PREFS->conf['registration_tos'] != 0 && !$tos)
- {
- $TEMPLATE->set_message("error", ($LANG['register']['no_tos']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Check if captcha is available and accepted
- //------------------------------------------------
- if ($PREFS->conf['registration_captcha'] != 0 && strcasecmp($_SESSION['captcha'], $captcha) != 0 && extension_loaded('gd'))
- {
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_catcha']), 0, 0);
- return 0;
- }
- //------------------------------------------------
- // Escape the ip
- //------------------------------------------------
- $ipaddress = mysql_real_escape_string(trim($SESSION->get_ip()));
- $joindate = time();
- //------------------------------------------------
- // Make sure username and email are unique
- //------------------------------------------------
- $result = $DB->query("SELECT username, email, ipaddress, joindate
- FROM " . DB_PREFIX . "members
- WHERE username='$username' OR email='$email' OR (ipaddress='$ipaddress' AND joindate>".($joindate-$PREFS->conf['registration_delay']*60*60).")
- LIMIT 1");
- //------------------------------------------------
- // Check if resultset contains rows
- //------------------------------------------------
- if ($DB->num_rows($result))
- {
- //------------------------------------------------
- // Fetch result set
- //------------------------------------------------
- $obj = $DB->fetch_object($result);
- //------------------------------------------------
- // Check if username or email was taken
- //------------------------------------------------
- if (strcmp(strtolower($obj->username), strtolower($username)) == 0)
- {
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("error", ($LANG['register']['username_taken']), 0, 0);
- return 0;
- }
- elseif (strcmp(strtolower($obj->email), strtolower($email)) == 0)
- {
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("error", ($LANG['register']['email_taken']), 0, 0);
- return 0;
- }
- elseif (strcmp($obj->ipaddress, $ipaddress) == 0 && $joindate-$obj->joindate < ($PREFS->conf['registration_delay']*60*60))
- {
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("error", (str_replace('%hours%', $PREFS->conf['registration_delay'],$LANG['register']['double_registration'])), 0, 0);
- return 0;
- }
- }
- //------------------------------------------------
- // Clean up
- //------------------------------------------------
- unset($obj);
- unset($result);
- //------------------------------------------------
- // Check if file was selected
- //------------------------------------------------
- if ( $PREFS->conf['enable_registration_photo'] && $PREFS->conf['require_registration_photo'] && ( !isset($photo['error']) || $photo['error'] ) )
- {
- $TEMPLATE->set_message("error", ($LANG['register']['empty_photo']), 0, 0);
- return;
- }
- elseif ( $PREFS->conf['enable_registration_photo'] && isset($photo['error']) && !$photo['error'] )
- {
- //------------------------------------------------
- // Check if file was uploaded
- //------------------------------------------------
- if (!@is_uploaded_file($photo['tmp_name']))
- {
- $TEMPLATE->set_message("error", ($LANG['register']['cant_upload']), 0, 0);
- return;
- }
- //------------------------------------------------
- // Get picture's extention and it's length
- //------------------------------------------------
- $fext = explode('.', $photo['name']);
- $fext = strtolower(end($fext));
- $fextlen = strlen($fext . "0") + 1;
- //------------------------------------------------
- // Check file format
- //------------------------------------------------
- if ($fext != "gif" && $fext != "jpg" && $fext != "jpeg" && $fext != "png")
- {
- $TEMPLATE->set_message("error", ($LANG['register']['invalid_photo_file']), 0, 0);
- return;
- }
- //------------------------------------------------
- // Check file size
- //------------------------------------------------
- if ($photo['size'] >= ($PREFS->conf['max_photo_size'] * 1024))
- {
- ($LANG['register']['photo_file_too_big'] = str_replace("%size%", $PREFS->conf['max_photo_size'], $LANG['register']['photo_file_too_big']));
- $TEMPLATE->set_message("error", ($LANG['register']['photo_file_too_big']), 0, 0);
- return;
- }
- //------------------------------------------------
- // Generate unique filename
- //------------------------------------------------
- do
- {
- $fname = 'photo_0' . random_string(32 - $fextlen, 0);
- $picname = $fname . '.' . $fext;
- }
- while(@is_file(SYS_PIC_PATH . $picname));
- //------------------------------------------------
- // Generate unique filename for album
- //------------------------------------------------
- if ( $PREFS->conf['default_album_name'] )
- {
- do
- {
- $fname2 = 'picture_0' . random_string(32 - $fextlen, 0);
- $picname2 = $fname2 . '.' . $fext;
- }
- while(@is_file(SYS_PIC_PATH . $picname2));
- }
- //------------------------------------------------
- // Make sure picture is not too small
- //------------------------------------------------
- list($width, $height) = @getimagesize($photo['tmp_name']);
- if ($width < $PREFS->conf['min_photo_width'] || $height < $PREFS->conf['min_photo_height'])
- {
- ($LANG['register']['photo_too_small'] = str_replace("%height%", $PREFS->conf['min_photo_height'], $LANG['register']['photo_too_small']));
- ($LANG['register']['photo_too_small'] = str_replace("%width%", $PREFS->conf['min_photo_width'], $LANG['register']['photo_too_small']));
- $TEMPLATE->set_message("error", ($LANG['register']['photo_too_small']), 0, 0);
- return;
- }
- //------------------------------------------------
- // Move the picture to member's folder
- //------------------------------------------------
- if (!@move_uploaded_file($photo['tmp_name'], SYS_PIC_PATH . $picname))
- {
- $picname = '';
- }
- else
- {
- @chmod(SYS_PIC_PATH . $picname, 0644);
- }
- //------------------------------------------------
- // Copy for album
- //------------------------------------------------
- if ( $PREFS->conf['default_album_name'] )
- {
- @copy(SYS_PIC_PATH . $picname, SYS_PIC_PATH . $picname2);
- @chmod(SYS_PIC_PATH . $picname2, 0644);
- }
- //------------------------------------------------
- // Create image class
- //------------------------------------------------
- $IMG = new Image(SYS_PIC_PATH);
- //------------------------------------------------
- // Resize photo
- //------------------------------------------------
- if ( isset($picname) && $picname && extension_loaded('gd') )
- {
- //------------------------------------------------
- // Resize original image
- //------------------------------------------------
- $IMG->prefix = TN_PREFIX;
- $IMG->cutoff = $PREFS->conf['cut_photos'];
- if (!$IMG->resize($fname, $fext, $PREFS->conf['thumbnail_photo_width'], $PREFS->conf['thumbnail_photo_height'], (isset($PREFS->conf['enable_photo_watermark']) && $PREFS->conf['enable_photo_watermark'] ? 'overlay_photo.png' : '')))
- {
- $picname = '';
- }
- else
- {
- @chmod(SYS_PIC_PATH . TN_PREFIX . $picname, 0644);
- //------------------------------------------------
- // Create thumbnail from the original image
- //------------------------------------------------
- $IMG->prefix = '';
- $IMG->cutoff = 0;
- if (!$IMG->resize($fname, $fext, $PREFS->conf['image_width'], $PREFS->conf['image_height'], (isset($PREFS->conf['enable_photo_watermark']) && $PREFS->conf['enable_photo_watermark'] ? 'overlay_photo.png' : '')))
- {
- @unlink(SYS_PIC_PATH . TN_PREFIX . $picname);
- $picname = '';
- }
- else
- {
- @chmod(SYS_PIC_PATH . $picname, 0644);
- }
- }
- }
- //------------------------------------------------
- // Resize album picture
- //------------------------------------------------
- if ( $PREFS->conf['default_album_name'] && isset($picname2) && $picname2 && extension_loaded('gd') )
- {
- if ($PREFS->conf['thumbnails'] && extension_loaded('gd'))
- {
- $IMG->prefix = $PREFS->conf['thumbnail_prefix'];
- $IMG->cutoff = $PREFS->conf['cut_images'];
- if (!$IMG->resize($fname2, $fext, $PREFS->conf['thumbnail_width'], $PREFS->conf['thumbnail_height'], (isset($PREFS->conf['enable_sm_watermark']) && $PREFS->conf['enable_sm_watermark'] ? 'overlay_picture_small.png' : '')))
- {
- $picname2 = '';
- }
- else
- {
- @chmod(SYS_PIC_PATH . $PREFS->conf['thumbnail_prefix'] . $picname2, 0644);
- }
- }
- else
- {
- @copy(SYS_PIC_PATH . $picname2, SYS_PIC_PATH . TN_PREFIX . $picname2);
- @chmod(SYS_PIC_PATH . TN_PREFIX . $picname2, 0644);
- }
- if ($PREFS->conf['resize_image'] && extension_loaded('gd'))
- {
- $IMG->prefix = '';
- $IMG->cutoff = 0;
- if (!$IMG->resize($fname2, $fext, $PREFS->conf['image_width'], $PREFS->conf['image_height'], (isset($PREFS->conf['enable_lg_watermark']) && $PREFS->conf['enable_lg_watermark'] ? 'overlay_picture_big.png' : '')))
- {
- $picname2 = '';
- }
- else
- {
- @chmod(SYS_PIC_PATH . $picname2, 0644);
- }
- }
- }
- }
- //------------------------------------------------
- // Get referal id
- //------------------------------------------------
- if ($PREFS->conf['enable_referals'] && isset($_COOKIE['ref']) && is_numeric($_COOKIE['ref']))
- {
- $refid = intval($_COOKIE['ref']);
- //------------------------------------------------
- // Get referal
- //------------------------------------------------
- $result = $DB->query("SELECT group_id, totalreferrals FROM " . DB_PREFIX . "members WHERE member_id='$refid' LIMIT 1");
- //------------------------------------------------
- // Check if resultset contains any rows
- //------------------------------------------------
- if ($DB->num_rows($result))
- {
- //------------------------------------------------
- // Fetch resultset
- //------------------------------------------------
- $obj = $DB->fetch_object($result);
- //------------------------------------------------
- // Check if member can refer members
- //------------------------------------------------
- if ($PREFS->get_permissions($obj->group_id, 'can_refer_members'))
- {
- //------------------------------------------------
- // Update referal's counter
- //------------------------------------------------
- $DB->query("UPDATE " . DB_PREFIX . "members SET totalreferrals=totalreferrals+1 WHERE member_id='$refid' LIMIT 1");
- $obj->totalreferrals++;
- //------------------------------------------------
- // Check if referal upgrades are enabled
- //------------------------------------------------
- if ($PREFS->conf['referals_upgrade_members'] && $PREFS->get_permissions($obj->group_id, 'can_refer_upgrades'))
- {
- //------------------------------------------------
- // Check if upgrade is required
- //------------------------------------------------
- if ( $obj->totalreferrals && ($obj->totalreferrals % $PREFS->conf['referals_upgrade_members']) == 0)
- {
- //------------------------------------------------
- // Update member's group
- //------------------------------------------------
- set_membership_term($refid, 0, $PREFS->conf['referals_member_group'], 'day', $PREFS->conf['referals_upgrade_length']);
- }
- }
- //------------------------------------------------
- // Delete cookie
- //------------------------------------------------
- @setcookie("ref", "", time()-60, "/");
- }
- else
- $refid = 0;
- }
- else
- $refid = 0;
- }
- else
- $refid = 0;
- //------------------------------------------------
- // Set expiration date if trial is enabled
- //------------------------------------------------
- $expiration = $PREFS->conf['trial_member_length'] ? (time() + 60*60*24*$PREFS->conf['trial_member_length']) : 0;
- if ($expiration) $PREFS->conf['regular_member_group'] = $PREFS->conf['trial_member_group'];
- $joindate = time();
- //------------------------------------------------
- // Generate activation hash
- //------------------------------------------------
- $sessionhash = md5($username.md5($password));
- //------------------------------------------------
- // Get welcome defaults
- //------------------------------------------------
- $favorites_ids = $PREFS->conf['def_favorites_ids'] ? explode(",", $PREFS->conf['def_favorites_ids']) : array();
- $totalfavorites = count($favorites_ids);
- $totalalbums = $PREFS->conf['default_album_name'] && isset($picname2) && $picname2 ? 1 : 0;
- $totalaguestbooks = $PREFS->conf['def_signee_id'] && $PREFS->conf['def_welcome_guestbook'] ? 1 : 0;
- $totalimessages = $PREFS->conf['def_signee_id'] && $PREFS->conf['def_welcome_msg_subject'] ? 1 : 0;
- $newmessages = $PREFS->conf['def_signee_id'] && $PREFS->conf['def_welcome_msg_subject'] ? 1 : 0;
- $actpic = $PREFS->get_permissions($PREFS->conf['regular_member_group'], 'can_approve_own_pictures') ? 1 : 0 ;
- //------------------------------------------------
- // Save user details to the database
- //------------------------------------------------
- $DB->query("INSERT INTO " . DB_PREFIX . "members (group_id, type_id, username, password, email, ipaddress, picture, picture_active, picture_date,
- joindate, expirationdate, active, totalfavorites, totalaguestbooks, totalimessages, newmessages, totalalbums, referral_id, totalcredits)
- VALUES ('" . ($PREFS->conf['activation_type'] == 1 ? $PREFS->conf['regular_member_group'] : $PREFS->conf['pending_member_group']) . "', '$type_id',
- '$username', '" . md5($password) . "', '$email', '$ipaddress',
- " . ( isset($picname) && $picname ? "'".substr($picname, 6)."'" : "''" ) . ",
- " . ( isset($picname) && $picname && $actpic ? 1 : 0 ). ",
- " . ( isset($picname) && $picname ? time() : 0 ). ",
- '" . $joindate . "', '$expiration', '1', '$totalfavorites', '$totalaguestbooks', '$totalimessages', '$newmessages', '$totalalbums',
- '$refid', '".$PREFS->conf['trial_member_credits']."')");
- //------------------------------------------------
- // Get insert id
- //------------------------------------------------
- $user_id = $DB->get_insert_id();
- //------------------------------------------------
- // Save user config and data to the database
- //------------------------------------------------
- $config_data = array(
- 'notify_private_messages' => $PREFS->conf['def_notify_private_messages'],
- 'notify_gifts' => $PREFS->conf['def_notify_gifts'],
- 'notify_blog_comments' => $PREFS->conf['def_notify_blog_comments'],
- 'notify_guestbook_comments' => $PREFS->conf['def_notify_guestbook_comments'],
- 'access_guestbook_moderate' => $PREFS->conf['def_moderate_guestbooks'],
- 'notify_pictures_comments' => $PREFS->conf['def_notify_pictures_comments'],
- 'notify_videos_comments' => $PREFS->conf['def_notify_videos_comments'],
- 'notify_friends_requests' => $PREFS->conf['def_notify_friends_requests'],
- 'notify_limit' => $PREFS->conf['def_notify_daily_limit'],
- 'enable_newsletters' => $PREFS->conf['def_enable_newsletters'],
- 'showadult' => $PREFS->conf['default_adult_pictures'],
- 'timeformat' => $PREFS->conf['timeformat'],
- 'timezone' => $PREFS->conf['timezone'],
- 'template_id' => $SESSION->conf['template_id'],
- 'language_id' => $SESSION->conf['language_id'],
- );
- $config_keys = implode(",", array_keys($config_data));
- $config_values = implode(",", $config_data);
- $DB->query("INSERT INTO " . DB_PREFIX . "members_conf (conf_id, $config_keys) VALUES ($user_id, $config_values)");
- $DB->query("INSERT INTO " . DB_PREFIX . "members_data_".$PREFS->conf['profile_types'][$type_id]['type_label']." (data_id $query_keys) VALUES ($user_id $query_values)");
- foreach ( $items_values as $field_id => $items_value ) {
- foreach ( $items_value as $item_val ) {
- $DB->query("INSERT INTO " . DB_PREFIX . "members_items (data_id, field_id, item_id) VALUES($user_id, $field_id, $item_val)");
- }
- }
- //------------------------------------------------
- // Add member to integrated software if enabled
- //------------------------------------------------
- call_module_function('members', 'update', array(
- 'member_id' => $user_id,
- 'password' => ($password ? $password : ''),
- 'block' => ($PREFS->conf['activation_type'] == 1 ? 0 : 1),
- ));
- //------------------------------------------------
- // Create media folder
- //------------------------------------------------
- $mediapath = get_media_path($joindate, $user_id);
- recursive_mkdir(SYS_PIC_PATH, $mediapath, $PREFS->conf['chmod_folder']);
- //------------------------------------------------
- // Move profile picture
- //------------------------------------------------
- if ( isset($picname) && $picname ) {
- @rename(SYS_PIC_PATH . $picname, SYS_PIC_PATH . $mediapath . $picname);
- @rename(SYS_PIC_PATH . TN_PREFIX . $picname, SYS_PIC_PATH . $mediapath . TN_PREFIX . $picname);
- // WALL
- @copy(SYS_PIC_PATH . $mediapath . TN_PREFIX . $picname, './wall/media/profile/'.$picname);
- $sURLPhoto = $picname;
- // JTCHAT
- @copy(SYS_PIC_PATH . $mediapath . TN_PREFIX . $picname, './jtchat/avatar/'.$picname);
- }
- //------------------------------------------------
- // Move album picture
- //------------------------------------------------
- if ( isset($picname2) && $picname2 ) {
- @rename(SYS_PIC_PATH . $picname2, SYS_PIC_PATH . $mediapath . $picname2);
- @rename(SYS_PIC_PATH . TN_PREFIX . $picname2, SYS_PIC_PATH . $mediapath . TN_PREFIX . $picname2);
- }
- //------------------------------------------------
- // Add favorites
- //------------------------------------------------
- foreach ( $favorites_ids as $favorite_id ) {
- $DB->query("INSERT INTO " . DB_PREFIX . "favorites (member_id, favorite_id) VALUES('$user_id', '$favorite_id')");
- }
- //------------------------------------------------
- // Add guestbook message
- //------------------------------------------------
- if ( $totalaguestbooks ) {
- $PREFS->conf['def_welcome_guestbook'] = str_replace(
- array(
- '{username}',
- '{email}',
- '{website}',
- ),
- array(
- $username,
- $email,
- VIR_PATH,
- ), $PREFS->conf['def_welcome_guestbook']);
- $DB->query("INSERT INTO " . DB_PREFIX . "guestbooks (member_id, poster_id, postdate, body, active)
- VALUES('$user_id', '".$PREFS->conf['def_signee_id']."', '".time()."', '".mysql_real_escape_string($PREFS->conf['def_welcome_guestbook'])."', '1')");
- }
- //------------------------------------------------
- // Add private message
- //------------------------------------------------
- if ( $totalimessages ) {
- $PREFS->conf['def_welcome_msg_body'] = str_replace(
- array(
- '{username}',
- '{email}',
- '{website}',
- ),
- array(
- $username,
- $email,
- VIR_PATH,
- ), $PREFS->conf['def_welcome_msg_body']);
- $DB->query("INSERT INTO " . DB_PREFIX . "messages (member_id1, member_id2, senddate, subject, body, new, delete1, delete2)
- VALUES('".$PREFS->conf['def_signee_id']."', '$user_id', '".time()."', '".mysql_real_escape_string($PREFS->conf['def_welcome_msg_subject'])."',
- '".mysql_real_escape_string($PREFS->conf['def_welcome_msg_body'])."', '1', '1', '0')");
- }
- //------------------------------------------------
- // Add default album
- //------------------------------------------------
- if ( $PREFS->conf['default_album_name'] && isset($picname2) && $picname2 )
- {
- $DB->query("INSERT INTO " . DB_PREFIX . "albums (member_id, filename, description, dateadded, dateupdated, totalapictures, totalipictures, accesslevel)
- VALUES('$user_id', '".substr($picname2, 8)."', '".mysql_real_escape_string($PREFS->conf['default_album_name'])."',
- '" . time() . "', '0', '".($actpic ? 1 : 0)."', '".($actpic ? 0 : 1)."', '0')");
- $aid = $DB->get_insert_id();
- $DB->query("INSERT INTO " . DB_PREFIX . "pictures (member_id, album_id, filename, description, adult, rated, comments, dateadded, active, albumcover, orderid)
- VALUES('$user_id', '$aid', '".substr($picname2, 8)."', '', '0', '1', '1', '" . time() . "', '$actpic', '1', '".($actpic ? 1 : 0)."')");
- }
- //------------------------------------------------
- // Notify admin about user registration
- //------------------------------------------------
- if ($PREFS->conf['admin_notify_registration'])
- {
- send_email_template($PREFS->conf['admin_email'], 'admin_notify_registration', array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- 'hash' => $sessionhash,
- 'activation_link' => VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/activate/$user_id/$sessionhash/" : "index.php?m=account_activate&id=$user_id&hash=$sessionhash&a=1"),
- 'decline_link' => VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/decline/$user_id/$sessionhash/" : "index.php?m=account_activate&id=$user_id&hash=$sessionhash&a=2"),
- ), $SESSION->conf['language_id']);
- }
- //------------------------------------------------
- // Auto activation
- //------------------------------------------------
- if ($PREFS->conf['activation_type'] == 1)
- {
- //------------------------------------------------
- // Send out welcome message to user
- //------------------------------------------------
- if ($PREFS->conf['member_notify_registration'])
- {
- send_email_template($email, 'validated_member_notify', array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- ), $SESSION->conf['language_id']);
- }
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("info", ($LANG['register']['auto_activation']), 0, 0);
- //------------------------------------------------
- // Login member
- //------------------------------------------------
- $_SESSION['member_id'] = $user_id;
- $_SESSION['member_code'] = md5($email.md5($password));
- $_SESSION['member_name'] = $username;
- $_SESSION['username'] = $username;
- $_SESSION['member_time'] = time();
- redirect( VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/home/active" : "index.php?m=account_home&active=1") );
- }
- //------------------------------------------------
- // Email activation
- //------------------------------------------------
- elseif ($PREFS->conf['activation_type'] == 2)
- {
- send_email_template($email, 'member_activation_instructions', array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- 'hash' => $sessionhash,
- 'activation_link' => VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/activate/$user_id/$sessionhash/" : "index.php?m=account_activate&id=$user_id&hash=$sessionhash&a=1"),
- ), $SESSION->conf['language_id']);
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("info", ($LANG['register']['email_activation']), 0, 0);
- }
- //------------------------------------------------
- // Admin activation
- //------------------------------------------------
- elseif ($PREFS->conf['activation_type'] == 3)
- {
- send_email_template($email, 'member_activation_instructions', array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- 'hash' => '',
- 'activation_link' => 'Pending administrator review',
- ), $SESSION->conf['language_id']);
- //------------------------------------------------
- // Set the message
- //------------------------------------------------
- $TEMPLATE->set_message("info", ($LANG['register']['admin_activation']), 0, 0);
- }
- //------------------------------------------------
- // Redirect to the registration page
- //------------------------------------------------
- redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/login/" : "index.php?m=account_login"));
- return 1;
- }
- // End Function
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement