/**
 * Handle auto-removal of timed-out members.
 */
function cleanup_member_timeouts()
{
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    require_code('ocf_groups_action');
    require_code('ocf_groups_action2');
    require_code('ocf_members');
    $db = get_forum_type() == 'ocf' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $start = 0;
    $time = time();
    do {
        $timeouts = $db->query('SELECT member_id,group_id FROM ' . $db->get_table_prefix() . 'f_group_member_timeouts WHERE timeout<' . strval($time), 100, $start);
        foreach ($timeouts as $timeout) {
            $member_id = $timeout['member_id'];
            $group_id = $timeout['group_id'];
            $test = in_array($group_id, $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id));
            if ($test) {
                if (get_value('unofficial_ecommerce') == '1' && get_forum_type() != 'ocf') {
                    $GLOBALS['FORUM_DB']->remove_member_from_group($member_id, $group_id);
                } else {
                    if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_primary_group') == $group_id) {
                        $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_update('f_members', array('m_primary_group' => get_first_default_group()), array('id' => $member_id), '', 1);
                        $GLOBALS['FORUM_DRIVER']->MEMBER_ROWS_CACHED = array();
                    }
                    $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_delete('f_group_members', array('gm_group_id' => $group_id, 'gm_member_id' => $member_id), '', 1);
                }
                global $USERS_GROUPS_CACHE, $GROUP_MEMBERS_CACHE;
                $USERS_GROUPS_CACHE = array();
                $GROUP_MEMBERS_CACHE = array();
            }
        }
        $start += 100;
    } while (count($timeouts) == 100);
    $timeouts = $db->query('DELETE FROM ' . $db->get_table_prefix() . 'f_group_member_timeouts WHERE timeout<' . strval($time));
}
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
Exemple #3
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_members($db, $table_prefix, $file_base)
 {
     $default_group = get_first_default_group();
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'users u ORDER BY u.id', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['id']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['username']);
             if (!is_null($test)) {
                 import_id_remap_put('member', strval($row['id']), $test);
                 continue;
             }
             $language = '';
             if ($row['language'] != '') {
                 switch ($language) {
                     case 'english':
                     default:
                         $language = 'EN';
                         break;
                 }
             }
             //$primary_group=$default_group;
             $primary_group = import_id_remap_get('group', strval($row['u_member_group']), true);
             if (is_null($primary_group)) {
                 $primary_group = $default_group;
             }
             $secondary_groups = array();
             $custom_fields = array(ocf_make_boiler_custom_field('im_icq') => $row['icq'], ocf_make_boiler_custom_field('im_aim') => $row['aim'], ocf_make_boiler_custom_field('im_msn') => $row['msn'], ocf_make_boiler_custom_field('im_yahoo') => $row['yim'], ocf_make_boiler_custom_field('location') => $row['location']);
             if ($row['www'] != '') {
                 $custom_fields[ocf_make_boiler_custom_field('website')] = strlen($row['www']) > 0 ? '[url]' . $row['www'] . '[/url]' : '';
             }
             $signature = $this->fix_links($row['sig'], $db, $table_prefix, $file_base);
             $validated = $row['act_status'];
             $reveal_age = $row['birth_date'] != '' ? 1 : 0;
             $bits = explode('-', $row['birth_date']);
             if ($reveal_age == 1 && count($bits) == 3) {
                 list($bday_day, $bday_month, $bday_year) = $bits;
             } else {
                 list($bday_day, $bday_month, $bday_year) = array(0, 0, 0);
             }
             $views_signatures = 1;
             $preview_posts = 1;
             $track_posts = $row['pm_notify'];
             $title = $row['customtitle'];
             $title = @html_entity_decode($title, ENT_QUOTES, get_charset());
             // These are done in the members-files stage
             $avatar_url = $row['avatar'];
             $photo_url = $row['ppic'];
             $photo_thumb_url = '';
             $password = $row['password'];
             $type = 'aef';
             $salt = $row['salt'];
             $id_new = ocf_make_member($row['username'], $password, $row['email'], NULL, $bday_day, $bday_month, $bday_year, $custom_fields, strval($row['timezone']), $primary_group, $validated, $row['r_time'], $row['lastlogin_1'], '', $avatar_url, $signature, $row['temp_ban'] != 0 ? 1 : 0, $preview_posts, $reveal_age, $title, $photo_url, $photo_thumb_url, $views_signatures, $track_posts, $language, 1, 1, '', '', '', false, $type, $salt, 1);
             // Fix group leadership
             $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $id_new), array('g_group_leader' => -$row['id']));
             import_id_remap_put('member', strval($row['id']), $id_new);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemple #4
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_members($db, $table_prefix, $file_base)
 {
     $row_start = 0;
     $rows = array();
     $default_group = get_first_default_group();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'members  WHERE id_member<>-1 ORDER BY id_member', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['id_member']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['member_name']);
             if (!is_null($test)) {
                 import_id_remap_put('member', strval($row['id_member']), $test);
                 continue;
             }
             $language = 'EN';
             $secondary = explode(',', $row['additional_groups']);
             $secondary_groups = array();
             foreach ($secondary as $g) {
                 if (trim($g) != '') {
                     $g = import_id_remap_get('group', $g, true);
                     if (!is_null($g)) {
                         $secondary_groups[] = intval($g);
                     }
                 }
             }
             $primary_group = $row['id_group'];
             if ($primary_group == 0) {
                 $primary_group = $row['id_post_group'];
             }
             if ($primary_group == 0) {
                 $primary_group = $default_group;
             } else {
                 $primary_group = import_id_remap_get('group', strval($primary_group));
             }
             $custom_fields = array(ocf_make_boiler_custom_field('im_icq') => $row['icq'], ocf_make_boiler_custom_field('im_aim') => $row['aim'], ocf_make_boiler_custom_field('im_msn') => $row['msn'], ocf_make_boiler_custom_field('im_yahoo') => $row['yim']);
             if ($row['website_url'] != '') {
                 $custom_fields[ocf_make_boiler_custom_field('website')] = $row['website_url'];
             }
             $signature = str_replace(array('[html]', '[/html]'), array('', ''), html_to_comcode($row['signature']));
             $signature = $this->fix_links($signature, $db, $table_prefix, $file_base);
             $validated = 1;
             $reveal_age = 0;
             if ($row['birthdate'] != '') {
                 $birthdate = $row['birthdate'];
                 $birthdata = explode('-', $birthdate);
                 $bday_day = isset($birthdata[0]) && $birthdata[0] != '' ? $birthdata[0] : NULL;
                 $bday_month = isset($birthdata[1]) && $birthdata[1] != '' ? $birthdata[1] : NULL;
                 $bday_year = isset($birthdata[2]) && $birthdata[2] != '' ? $birthdata[2] : NULL;
             } else {
                 list($bday_day, $bday_month, $bday_year) = array(NULL, NULL, NULL);
             }
             $views_signatures = 1;
             $preview_posts = 1;
             $track_posts = $row['notify_announcements'];
             $title = '';
             // These are done in the members-files stage
             $avatar_url = '';
             $photo_url = '';
             $photo_thumb_url = '';
             $password = $row['passwd'];
             $type = 'smf';
             $salt = $row['password_salt'];
             $allow_emails = intval($row['instant_messages']) > 0 ? 1 : 0;
             if ($row['date_registered'] == 0) {
                 $row['date_registered'] = time();
             }
             $id_new = ocf_make_member($row['member_name'], $password, $row['email_address'], NULL, $bday_day, $bday_month, $bday_year, $custom_fields, $row['time_offset'] == 0 ? '' : strval($row['time_offset']), $primary_group, $validated, $row['date_registered'], $row['last_login'], '', $avatar_url, $signature, 0, $preview_posts, $reveal_age, $title, $photo_url, $photo_thumb_url, $views_signatures, $track_posts, $language, $allow_emails, 1, '', '', '', false, $type, $salt, 1);
             //cpf stuff
             $cpf_rows = $db->query('SELECT id_field, col_name FROM ' . $table_prefix . 'custom_fields');
             foreach ($cpf_rows as $cpf_row) {
                 $cpf_id = import_id_remap_get('cpf', strval($cpf_row['id_field']));
                 if (!($cpf_value = $db->query('SELECT value FROM ' . $table_prefix . 'themes WHERE id_member=' . $row['id_member'] . ' AND variable=\'' . $cpf_row['col_name'] . '\''))) {
                     continue;
                 }
                 $value = isset($cpf_value[0]['value']) ? $cpf_value[0]['value'] : '';
                 ocf_set_custom_field($id_new, $cpf_id, $value);
             }
             // Fix usergroup leadership
             $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $id_new), array('g_group_leader' => $row['id_member']));
             import_id_remap_put('member', strval($row['id_member']), $id_new);
             // Set up usergroup membership
             foreach ($secondary_groups as $s) {
                 ocf_add_member_to_group($id_new, $s, 1);
             }
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemple #5
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_members($db, $table_prefix, $file_base)
 {
     $default_group = get_first_default_group();
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'users u LEFT JOIN ' . $table_prefix . 'banlist b ON u.user_id=b.ban_userid WHERE u.user_id<>-1 ORDER BY u.user_id', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['user_id']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['username']);
             if (!is_null($test)) {
                 import_id_remap_put('member', strval($row['user_id']), $test);
                 continue;
             }
             $language = '';
             if ($row['user_lang'] != '') {
                 switch ($language) {
                     case 'english':
                         $language = 'EN';
                         break;
                 }
             }
             $primary_group = $default_group;
             $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'user_group WHERE user_id=' . strval((int) $row['user_id']), 200, $row_start);
             $secondary_groups = array();
             foreach ($rows2 as $row2) {
                 $g = import_id_remap_get('group', strval($row2['group_id']), true);
                 if (!is_null($g)) {
                     $secondary_groups[] = array($g, $row2['user_pending']);
                 }
             }
             if ($row['user_level'] == 1) {
                 $secondary_groups[] = array(db_get_first_id() + 1, 0);
             }
             $custom_fields = array(ocf_make_boiler_custom_field('im_icq') => $row['user_icq'], ocf_make_boiler_custom_field('im_aim') => $row['user_aim'], ocf_make_boiler_custom_field('im_msn') => $row['user_msnm'], ocf_make_boiler_custom_field('im_yahoo') => $row['user_yim'], ocf_make_boiler_custom_field('interests') => $row['user_interests'], ocf_make_boiler_custom_field('location') => $row['user_from'], ocf_make_boiler_custom_field('occupation') => $row['user_occ']);
             if ($row['user_website'] != '') {
                 $custom_fields[ocf_make_boiler_custom_field('website')] = strlen($row['user_website']) > 0 ? '[url]' . $row['user_website'] . '[/url]' : '';
             }
             $signature = $this->fix_links($row['user_sig'], $db, $table_prefix);
             $validated = $row['user_active'];
             $reveal_age = 0;
             list($bday_day, $bday_month, $bday_year) = array(NULL, NULL, NULL);
             $views_signatures = 1;
             $preview_posts = 1;
             $track_posts = $row['user_notify'];
             $title = '';
             // These are done in the members-files stage
             $avatar_url = '';
             $photo_url = '';
             $photo_thumb_url = '';
             $password = $row['user_password'];
             $type = 'md5';
             $salt = '';
             $id_new = ocf_make_member($row['username'], $password, $row['user_email'], NULL, $bday_day, $bday_month, $bday_year, $custom_fields, strval($row['user_timezone']), $primary_group, $validated, $row['user_regdate'], $row['user_lastvisit'], '', $avatar_url, $signature, !is_null($row['ban_id']) ? 1 : 0, $preview_posts, $reveal_age, $title, $photo_url, $photo_thumb_url, $views_signatures, $track_posts, $language, $row['user_allow_pm'], 1, '', '', '', false, $type, $salt, 1);
             // Fix usergroup leadership
             $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $id_new), array('g_group_leader' => -$row['user_id']));
             import_id_remap_put('member', strval($row['user_id']), $id_new);
             // Set up usergroup membership
             foreach ($secondary_groups as $s) {
                 list($group, $userpending) = $s;
                 ocf_add_member_to_group($id_new, $group, 1 - $userpending);
             }
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemple #6
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_banners($db, $table_prefix, $old_base_dir)
 {
     require_code('banners2');
     $categories = $db->query("SELECT title,id FROM " . $table_prefix . "categories WHERE section='com_banner'");
     foreach ($categories as $category) {
         $cat_title = $category['title'];
         $category_exist = $GLOBALS['SITE_DB']->query_value_null_ok('banner_types', 'id', array('id' => $category['title']));
         if (is_null($category_exist)) {
             add_banner_type($cat_title, 1, 160, 600, 70, 1);
         }
         $rows = $db->query("SELECT b.publish_down ,b.bid,c.title,b.name, b.clickurl, b.imageurl,b.date,bc.contact,bc.extrainfo,bc.email,b.showBanner,b.clicks,b.impmade FROM " . $table_prefix . "banner b INNER JOIN " . $table_prefix . "bannerclient bc ON b.cid=bc.cid INNER JOIN " . $table_prefix . "categories c ON b.catid=c.id AND c.title='" . db_escape_string($cat_title) . "' AND c.title <> ''");
         foreach ($rows as $row) {
             $name = $row['name'] . strval($row['bid']);
             $test = $GLOBALS['SITE_DB']->query_value_null_ok('banners', 'name', array('name' => $name));
             if (is_null($test)) {
                 if ($row['imageurl'] != '') {
                     $newimagepath = get_custom_file_base() . '/uploads/banners/' . rawurldecode($row['imageurl']);
                     $newimage = $row['imageurl'];
                     $oldimagepath = $old_base_dir . "/images/banners/" . rawurldecode($row['imageurl']);
                     @copy($oldimagepath, $newimagepath);
                 } else {
                     $newimage = '';
                 }
                 $type = 0;
                 // Permanent
                 $campaignremaining = 0;
                 // Irrelevant
                 $caption = $row['name'];
                 $end_date = $this->mysql_time_to_timestamp($row['publish_down']);
                 if ($end_date === false) {
                     $end_date = NULL;
                 }
                 $url = $row['clickurl'];
                 $image_url = $newimage;
                 $member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['contact']);
                 if (is_null($member)) {
                     $member = get_member();
                 }
                 $desc = $row['email'] . chr(10) . $row['extrainfo'];
                 $desc = html_to_comcode($desc);
                 add_banner($name, $image_url, '', $caption, $campaignremaining, $url, 10, $desc, $type, $end_date, $member, 1, $cat_title, NULL, 0, 0, $row['clicks'], 0, $row['impmade']);
             }
         }
     }
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query("SELECT u.id, u.username, u.password, u.email, u.id, u.registerDate, u.lastvisitDate, u.sendEmail FROM " . $table_prefix . "bannerclient AS b INNER JOIN " . $table_prefix . "users AS u ON b.contact=u.name", 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['id']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['username']);
             if (!is_null($test)) {
                 import_id_remap_put('member', strval($row['id']), $test);
                 continue;
             }
             $primary_group = get_first_default_group();
             $custom_fields = array();
             $datetimearr = explode(' ', $row['registerDate']);
             $datearr = explode('-', $datetimearr[0]);
             $timearr = explode(':', $datetimearr[1]);
             $date = $datearr[2];
             $month = $datearr[1];
             $year = $datearr[0];
             $hour = $timearr[0];
             $min = $timearr[1];
             $sec = $timearr[2];
             $register_date = mktime($hour, $min, $sec, $month, $date, $year);
             $datetimearr = explode(' ', $row['lastvisitDate']);
             $datearr = explode('-', $datetimearr[0]);
             $timearr = explode(':', $datetimearr[1]);
             $date = $datearr[2];
             $month = $datearr[1];
             $year = $datearr[0];
             $hour = $timearr[0];
             $min = $timearr[1];
             $sec = $timearr[2];
             $last_visit_date = mktime($hour, $min, $sec, $month, $date, $year);
             $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id'];
             $id_new = ocf_make_member($row['username'], $row['password'], $row['email'], NULL, NULL, NULL, NULL, $custom_fields, NULL, $primary_group, 1, $register_date, $last_visit_date, '', NULL, '', 0, 0, 1, $row['name'], '', '', 1, 1, NULL, $row['sendEmail'], $row['sendEmail'], '', NULL, '', FALSE, NULL, '', 1, $last_visit_date, $id, 0, '*', '');
             import_id_remap_put('member', strval($row['id']), $id_new);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemple #7
0
/**
 * Handling of a usergroup subscription.
 *
 * @param  ID_TEXT	The purchase ID.
 * @param  array		Details relating to the product.
 * @param  ID_TEXT	The product.
 */
function handle_usergroup_subscription($purchase_id, $details, $product)
{
    $member_id = $GLOBALS['SITE_DB']->query_value_null_ok('subscriptions', 's_member_id', array('id' => intval($purchase_id)));
    if (is_null($member_id)) {
        return;
    }
    require_code('ocf_groups_action');
    require_code('ocf_groups_action2');
    require_code('ocf_members');
    require_code('notifications');
    $usergroup_subscription_id = intval(substr($product, 9));
    $dbs_bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
    $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
    $rows = $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_select('f_usergroup_subs', array('*'), array('id' => $usergroup_subscription_id), '', 1);
    $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_bak;
    if (array_key_exists(0, $rows)) {
        $myrow = $rows[0];
        $new_group = $myrow['s_group_id'];
        $object = find_product($product);
    } else {
        $object = NULL;
    }
    if (is_null($object)) {
        return;
        // The usergroup subscription has been deleted, and this was to remove the payment for it
    }
    $test = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'subscriptions WHERE (' . db_string_equal_to('s_state', 'cancelled') . ') AND ' . db_string_equal_to('id', $purchase_id));
    if (!is_null($test)) {
        $test = in_array($new_group, $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id));
        if ($test) {
            // Remove them from the group
            if (is_null($GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_value_null_ok('f_group_member_timeouts', 'member_id', array('member_id' => $member_id, 'group_id' => $new_group)))) {
                if (get_value('unofficial_ecommerce') == '1' && get_forum_type() != 'ocf') {
                    $GLOBALS['FORUM_DB']->remove_member_from_group($member_id, $new_group);
                } else {
                    //				if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id,'m_primary_group')==$new_group)
                    if ($myrow['s_uses_primary'] == 1) {
                        $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_update('f_members', array('m_primary_group' => get_first_default_group()), array('id' => $member_id), '', 1);
                    } else {
                        $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_delete('f_group_members', array('gm_group_id' => $new_group, 'gm_member_id' => $member_id));
                        // ,'',1
                    }
                }
                dispatch_notification('paid_subscription_ended', NULL, do_lang('PAID_SUBSCRIPTION_ENDED', NULL, NULL, NULL, get_lang($member_id)), get_translated_text($myrow['s_mail_end'], NULL, get_lang($member_id)), array($member_id), A_FROM_SYSTEM_PRIVILEGED);
            }
        }
    } else {
        $test = in_array($new_group, $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id));
        if (!$test) {
            // Add them to the group
            if (get_value('unofficial_ecommerce') == '1' && get_forum_type() != 'ocf') {
                $GLOBALS['FORUM_DB']->add_member_to_group($member_id, $new_group);
            } else {
                if ($myrow['s_uses_primary'] == 1) {
                    $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_update('f_members', array('m_primary_group' => $new_group), array('id' => $member_id), '', 1);
                } else {
                    ocf_add_member_to_group($member_id, $new_group);
                }
            }
            $GLOBALS[get_forum_type() == 'ocf' ? 'FORUM_DB' : 'SITE_DB']->query_delete('f_group_member_timeouts', array('member_id' => $member_id, 'group_id' => $new_group));
            dispatch_notification('paid_subscription_started', NULL, do_lang('PAID_SUBSCRIPTION_STARTED'), get_translated_text($myrow['s_mail_start'], NULL, get_lang($member_id)), array($member_id), A_FROM_SYSTEM_PRIVILEGED);
        }
    }
}
Exemple #8
0
/**
 * Import wordpress db
 */
function import_wordpress_db()
{
    disable_php_memory_limit();
    $data = get_wordpress_data();
    $is_validated = post_param_integer('wp_auto_validate', 0);
    $to_own_account = post_param_integer('wp_add_to_own', 0);
    // Create members
    require_code('ocf_members_action');
    require_code('ocf_groups');
    $def_grp_id = get_first_default_group();
    $cat_id = array();
    $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
    $NEWS_CATS = list_to_map('id', $NEWS_CATS);
    foreach ($data as $values) {
        if (get_forum_type() == 'ocf') {
            $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login']));
            if (is_null($member_id)) {
                if (post_param_integer('wp_import_wordpress_users', 0) == 1) {
                    $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress');
                } else {
                    $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin');
                    // Set admin as owner
                    if (is_null($member_id)) {
                        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1;
                    }
                }
            }
        } else {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
        }
        // Guest user
        // If post should go to own account
        if ($to_own_account == 1) {
            $member_id = get_member();
        }
        if (array_key_exists('POSTS', $values)) {
            // Create posts in blog
            foreach ($values['POSTS'] as $post_id => $post) {
                if (array_key_exists('category', $post)) {
                    $cat_id = array();
                    foreach ($post['category'] as $cat_code => $category) {
                        $cat_code = NULL;
                        if ($category == 'Uncategorized') {
                            continue;
                        }
                        // Skip blank category creation
                        foreach ($NEWS_CATS as $id => $existing_cat) {
                            if (get_translated_text($existing_cat['nc_title']) == $category) {
                                $cat_code = $id;
                            }
                        }
                        if (is_null($cat_code)) {
                            $cat_code = add_news_category($category, 'newscats/community', $category);
                            $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'));
                            $NEWS_CATS = list_to_map('id', $NEWS_CATS);
                        }
                        $cat_id = array_merge($cat_id, array($cat_code));
                    }
                }
                $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id));
                if ($post['post_type'] == 'post') {
                    $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, '');
                } elseif ($post['post_type'] == 'page') {
                    // If dont have permission to write comcode page, skip the post
                    if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) {
                        continue;
                    }
                    require_code('comcode');
                    // Save articles as new comcode pages
                    $zone = filter_naughty(post_param('zone', 'site'));
                    $lang = filter_naughty(post_param('lang', 'EN'));
                    $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']);
                    // Filter non alphanumeric charactors
                    $parent_page = post_param('parent_page', '');
                    $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
                    // Check existancy of new page
                    $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
                    if (!is_null($submiter)) {
                        continue;
                    }
                    // Skip existing titled articles	- may need change
                    require_code('submit');
                    give_submit_points('COMCODE_PAGE_ADD');
                    if (!addon_installed('unvalidated')) {
                        $is_validated = 1;
                    }
                    $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0));
                    if (!file_exists($fullpath)) {
                        $_content = html_to_comcode($post['post_content']);
                        $myfile = @fopen($fullpath, 'wt');
                        if ($myfile === false) {
                            intelligent_write_error($fullpath);
                        }
                        if (fwrite($myfile, $_content) < strlen($_content)) {
                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                        }
                        fclose($myfile);
                        sync_file($fullpath);
                    }
                    require_code('seo2');
                    seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', ''));
                    require_code('permissions2');
                    set_page_permissions_from_environment($zone, $file);
                }
                $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true);
                $content_title = $post['post_title'];
                // Add comments
                if (post_param_integer('wp_import_blog_comments', 0) == 1) {
                    if (array_key_exists('COMMENTS', $post)) {
                        $submitter = NULL;
                        foreach ($post['COMMENTS'] as $comment) {
                            $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author']));
                            if (is_null($submitter)) {
                                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
                            }
                            // If comment is made by a non-member, assign comment to guest account
                            $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news');
                            $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false);
                        }
                    }
                }
            }
        }
    }
}
/**
 * Add a usergroup.
 *
 * @param  SHORT_TEXT	The name of the usergroup.
 * @param  BINARY			Whether members are automatically put into the when they join.
 * @param  BINARY			Whether members of this usergroup are all super administrators.
 * @param  BINARY			Whether members of this usergroup are all super moderators.
 * @param  SHORT_TEXT 	The title for primary members of this usergroup that don't have their own title.
 * @param  URLPATH		The rank image for this.
 * @param  ?GROUP			The that members of this usergroup get promoted to at point threshold (NULL: no promotion prospects).
 * @param  ?integer		The point threshold for promotion (NULL: no promotion prospects).
 * @param  ?MEMBER		The leader of this usergroup (NULL: none).
 * @param  integer		The number of seconds that members of this usergroup must endure between submits (group 'best of' applies).
 * @param  integer		The number of seconds that members of this usergroup must endure between accesses (group 'best of' applies).
 * @param  integer		The number of megabytes that members of this usergroup may attach per day (group 'best of' applies).
 * @param  integer		The number of attachments that members of this usergroup may attach to something (group 'best of' applies).
 * @param  integer		The maximum avatar width that members of this usergroup may have (group 'best of' applies).
 * @param  integer		The maximum avatar height that members of this usergroup may have (group 'best of' applies).
 * @param  integer		The maximum post length that members of this usergroup may make (group 'best of' applies).
 * @param  integer		The maximum signature length that members of this usergroup may make (group 'best of' applies).
 * @param  integer		The number of gift points that members of this usergroup start with (group 'best of' applies).
 * @param  integer		The number of gift points that members of this usergroup get per day (group 'best of' applies).
 * @param  BINARY			Whether e-mail confirmation is needed for new IP addresses seen for any member of this usergroup (group 'best of' applies).
 * @param  BINARY			Whether the usergroup is presented for joining at joining (implies anyone may be in the, but only choosable at joining)
 * @param  BINARY			Whether the name and membership of the is hidden
 * @param  ?integer		The display order this will be given, relative to other usergroups. Lower numbered usergroups display before higher numbered usergroups (NULL: next).
 * @param  BINARY			Whether the rank image will not be shown for secondary membership
 * @param  BINARY			Whether members may join this usergroup without requiring any special permission
 * @param  BINARY			Whether this usergroup is a private club. Private clubs may be managed in the CMS zone, and do not have any special permissions - except over their own associated forum.
 * @return AUTO_LINK		The ID of the new.
 */
function ocf_make_group($name, $is_default = 0, $is_super_admin = 0, $is_super_moderator = 0, $title = '', $rank_image = '', $promotion_target = NULL, $promotion_threshold = NULL, $group_leader = NULL, $flood_control_submit_secs = 5, $flood_control_access_secs = 0, $max_daily_upload_mb = 70, $max_attachments_per_post = 50, $max_avatar_width = 100, $max_avatar_height = 100, $max_post_length_comcode = 30000, $max_sig_length_comcode = 700, $gift_points_base = 25, $gift_points_per_day = 1, $enquire_on_new_ips = 0, $is_presented_at_install = 0, $hidden = 0, $order = NULL, $rank_image_pri_only = 1, $open_membership = 0, $is_private_club = 0)
{
    //	if (is_null($group_leader)) $group_leader=db_get_first_id()+1;
    if (!running_script('stress_test_loader')) {
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON g.g_name=t.id WHERE ' . db_string_equal_to('text_original', $name), 'g.id');
        if (!is_null($test)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name)));
        }
    }
    if (is_null($is_super_admin)) {
        $is_super_admin = 0;
    }
    if (is_null($is_super_moderator)) {
        $is_super_moderator = 0;
    }
    if (!running_script('stress_test_loader')) {
        if (is_null($order)) {
            $order = $GLOBALS['FORUM_DB']->query_value('f_groups', 'MAX(g_order)');
            if (is_null($order)) {
                $order = 0;
            } else {
                $order++;
            }
        }
    } else {
        $order = 100;
    }
    $group_id = $GLOBALS['FORUM_DB']->query_insert('f_groups', array('g_name' => insert_lang($name, 2, $GLOBALS['FORUM_DB']), 'g_is_default' => $is_default, 'g_is_presented_at_install' => $is_presented_at_install, 'g_is_super_admin' => $is_super_admin, 'g_is_super_moderator' => $is_super_moderator, 'g_group_leader' => $group_leader, 'g_title' => insert_lang($title, 2, $GLOBALS['FORUM_DB']), 'g_promotion_target' => $promotion_target, 'g_promotion_threshold' => $promotion_threshold, 'g_flood_control_submit_secs' => $flood_control_submit_secs, 'g_flood_control_access_secs' => $flood_control_access_secs, 'g_max_daily_upload_mb' => $max_daily_upload_mb, 'g_max_attachments_per_post' => $max_attachments_per_post, 'g_max_avatar_width' => $max_avatar_width, 'g_max_avatar_height' => $max_avatar_height, 'g_max_post_length_comcode' => $max_post_length_comcode, 'g_max_sig_length_comcode' => $max_sig_length_comcode, 'g_gift_points_base' => $gift_points_base, 'g_gift_points_per_day' => $gift_points_per_day, 'g_enquire_on_new_ips' => $enquire_on_new_ips, 'g_rank_image' => $rank_image, 'g_hidden' => $hidden, 'g_order' => $order, 'g_rank_image_pri_only' => $rank_image_pri_only, 'g_open_membership' => $open_membership, 'g_is_private_club' => $is_private_club), true);
    if ($group_id > db_get_first_id() + 8 && $is_private_club == 0) {
        // Copy permissions from members
        require_code('ocf_groups');
        $group_members = get_first_default_group();
        $member_access = $GLOBALS['SITE_DB']->query_select('gsp', array('*'), array('group_id' => $group_members));
        foreach ($member_access as $access) {
            $access['group_id'] = $group_id;
            $GLOBALS['SITE_DB']->query_insert('gsp', $access, false, true);
            // failsafe, in case we have put in some permissions for a group since deleted (can happen during install)
        }
        $member_access = $GLOBALS['SITE_DB']->query_select('group_category_access', array('*'), array('group_id' => $group_members));
        foreach ($member_access as $access) {
            $access['group_id'] = $group_id;
            $GLOBALS['SITE_DB']->query_insert('group_category_access', $access, false, true);
            // failsafe, in case we have put in some permissions for a group since deleted (can happen during install)
        }
        $member_access = $GLOBALS['SITE_DB']->query_select('group_zone_access', array('*'), array('group_id' => $group_members));
        foreach ($member_access as $access) {
            $access['group_id'] = $group_id;
            $GLOBALS['SITE_DB']->query_insert('group_zone_access', $access, false, true);
            // failsafe, in case we have put in some permissions for a group since deleted (can happen during install)
        }
    }
    log_it('ADD_GROUP', strval($group_id), $name);
    if ($is_private_club == 1) {
        require_code('notifications');
        $subject = do_lang('NEW_CLUB_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $name);
        $view_url = build_url(array('page' => 'groups', 'type' => 'view', 'id' => $group_id), get_module_zone('groups'), NULL, false, false, true);
        $mail = do_lang('NEW_CLUB_NOTIFICATION_MAIL', get_site_name(), comcode_escape($name), array(comcode_escape($view_url->evaluate())));
        dispatch_notification('ocf_club', NULL, $subject, $mail);
    }
    return $group_id;
}
Exemple #10
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_members($db, $table_prefix, $file_base)
 {
     $row_start = 0;
     $rows = array();
     $default_group = get_first_default_group();
     do {
         $rows = $db->query('SELECT u.ID_MEMBER AS \'muid\',u.*,b.* FROM ' . $table_prefix . 'members u LEFT JOIN ' . $table_prefix . 'ban_items b ON u.ID_MEMBER=b.ID_MEMBER WHERE u.ID_MEMBER<>-1 ORDER BY u.ID_MEMBER', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member', strval($row['muid']))) {
                 continue;
             }
             $test = $GLOBALS['OCF_DRIVER']->get_member_from_username($row['memberName']);
             if (!is_null($test)) {
                 import_id_remap_put('member', strval($row['muid']), $test);
                 continue;
             }
             $language = 'EN';
             $secondary = explode(',', $row['additionalGroups']);
             $secondary_groups = array();
             foreach ($secondary as $g) {
                 if (trim($g) != '') {
                     $g = import_id_remap_get('group', $g, true);
                     if (!is_null($g)) {
                         $secondary_groups[] = intval($g);
                     }
                 }
             }
             $primary_group = $row['ID_GROUP'];
             if ($primary_group == 0) {
                 $primary_group = $row['ID_POST_GROUP'];
             }
             if ($primary_group == 0) {
                 $primary_group = $default_group;
             } else {
                 $primary_group = import_id_remap_get('group', strval($primary_group));
             }
             $custom_fields = array(ocf_make_boiler_custom_field('im_icq') => $row['ICQ'], ocf_make_boiler_custom_field('im_aim') => $row['AIM'], ocf_make_boiler_custom_field('im_msn') => $row['MSN'], ocf_make_boiler_custom_field('im_yahoo') => $row['YIM']);
             if ($row['websiteUrl'] != '') {
                 $custom_fields[ocf_make_boiler_custom_field('website')] = $row['websiteUrl'];
             }
             $signature = $this->fix_links($row['signature'], $db, $table_prefix, $file_base);
             $validated = 1;
             $reveal_age = 0;
             if ($row['birthdate'] != '') {
                 $birthdate = $row['birthdate'];
                 $birthdata = explode('-', $birthdate);
                 $bday_day = isset($birthdata[0]) && $birthdata[0] != '' ? $birthdata[0] : NULL;
                 $bday_month = isset($birthdata[1]) && $birthdata[1] != '' ? $birthdata[1] : NULL;
                 $bday_year = isset($birthdata[2]) && $birthdata[2] != '' ? $birthdata[2] : NULL;
             } else {
                 list($bday_day, $bday_month, $bday_year) = array(NULL, NULL, NULL);
             }
             $views_signatures = 1;
             $preview_posts = 1;
             $track_posts = $row['notifyAnnouncements'];
             $title = '';
             // These are done in the members-files stage
             $avatar_url = '';
             $photo_url = '';
             $photo_thumb_url = '';
             $password = $row['passwd'];
             $type = 'smf';
             $salt = $row['passwordSalt'];
             if ($row['dateRegistered'] == 0) {
                 $row['dateRegistered'] = time();
             }
             $id_new = ocf_make_member($row['memberName'], $password, $row['emailAddress'], NULL, $bday_day, $bday_month, $bday_year, $custom_fields, strval($row['timeOffset']), $primary_group, $validated, $row['dateRegistered'], $row['lastLogin'], '', $avatar_url, $signature, 0, $preview_posts, $reveal_age, $title, $photo_url, $photo_thumb_url, $views_signatures, $track_posts, $language, $row['instantMessages'], 1, '', '', '', false, $type, $salt, 1);
             // Fix usergroup leadership
             $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_group_leader' => $id_new), array('g_group_leader' => -$row['muid']));
             import_id_remap_put('member', strval($row['muid']), $id_new);
             // Set up usergroup membership
             foreach ($secondary_groups as $s) {
                 ocf_add_member_to_group($id_new, $s, 1);
             }
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
/**
 * Delete a usergroup.
 *
 * @param  AUTO_LINK		The ID of the usergroup to delete.
 * @param  ?GROUP			The usergroup to move primary members to (NULL: main members).
 */
function ocf_delete_group($group_id, $target_group = NULL)
{
    $orig_target_group = $target_group;
    if (is_null($target_group)) {
        $target_group = get_first_default_group();
    }
    if ($group_id == db_get_first_id() + 0 || $group_id == db_get_first_id() + 1 || $group_id == db_get_first_id() + 8) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    $_group_info = $GLOBALS['FORUM_DB']->query_select('f_groups', array('g_name', 'g_title', 'g_rank_image'), array('id' => $group_id), '', 1);
    if (!array_key_exists(0, $_group_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $_name = $_group_info[0]['g_name'];
    $_title = $_group_info[0]['g_title'];
    $name = get_translated_text($_name, $GLOBALS['FORUM_DB']);
    delete_lang($_name, $GLOBALS['FORUM_DB']);
    delete_lang($_title, $GLOBALS['FORUM_DB']);
    $GLOBALS['FORUM_DB']->query_update('f_groups', array('g_promotion_target' => NULL), array('g_promotion_target' => $group_id));
    $GLOBALS['FORUM_DB']->query_update('f_members', array('m_primary_group' => $target_group), array('m_primary_group' => $group_id));
    if (!is_null($orig_target_group)) {
        $GLOBALS['FORUM_DB']->query_update('f_group_members', array('gm_group_id' => $target_group), array('gm_group_id' => $group_id), '', NULL, NULL, false, true);
    }
    $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_group_id' => $group_id));
    $GLOBALS['FORUM_DB']->query_delete('f_groups', array('id' => $group_id), '', 1);
    // No need to delete ocPortal permission stuff, as it could be on any MSN site, and ocPortal is coded with a tolerance due to the forum driver system. However, to be tidy...
    $GLOBALS['SITE_DB']->query_delete('gsp', array('group_id' => $group_id));
    $GLOBALS['SITE_DB']->query_delete('group_zone_access', array('group_id' => $group_id));
    $GLOBALS['SITE_DB']->query_delete('group_category_access', array('group_id' => $group_id));
    $GLOBALS['SITE_DB']->query_delete('group_page_access', array('group_id' => $group_id));
    if (addon_installed('ecommerce')) {
        $GLOBALS['FORUM_DB']->query_delete('f_usergroup_subs', array('s_group_id' => $group_id));
    }
    require_code('themes2');
    tidy_theme_img_code(NULL, $_group_info[0]['g_rank_image'], 'f_groups', 'g_rank_image', $GLOBALS['FORUM_DB']);
    log_it('DELETE_GROUP', strval($group_id), $name);
}
Exemple #12
0
/**
 * Get the primary usergroup of a member in LDAP.
 *
 * @param  MEMBER	The member.
 * @return GROUP	The.
 */
function ocf_ldap_get_member_primary_group($member_id)
{
    global $PRIMARY_GROUP_MEMBERS;
    global $LDAP_CONNECTION;
    if (get_option('ldap_is_windows') == '0') {
        $results = ldap_search($LDAP_CONNECTION, member_search_qualifier() . get_option('ldap_base_dn'), '(&(objectclass=' . get_member_class() . ')(' . member_property() . '=' . ocp_ldap_escape(ocf_member_ocfid_to_ldapcn($member_id)) . '))', array('gidnumber'));
        $entries = ldap_get_entries($LDAP_CONNECTION, $results);
        $gid = array_key_exists(0, $entries) ? $entries[0]['gidnumber'][0] : NULL;
        ldap_free_result($results);
        if (!is_null($gid)) {
            $gid = ocf_group_ldapgid_to_ocfid($gid);
        }
        if (is_null($gid)) {
            $gid = get_first_default_group();
        }
    } else {
        // Whilst Windows has primaryGroupID, it has an ID that refers outside of LDAP, so is of no use to us. We use the last a member is in as the primary
        $results = ldap_search($LDAP_CONNECTION, member_search_qualifier() . get_option('ldap_base_dn'), '(&(objectclass=' . get_member_class() . ')(' . member_property() . '=' . ocp_ldap_escape(ocf_member_ocfid_to_ldapcn($member_id)) . '))', array('memberof'));
        $entries = ldap_get_entries($LDAP_CONNECTION, $results);
        if (array_key_exists(0, $entries) && array_key_exists('memberof', $entries[0])) {
            $group = $entries[0]['memberof'][count($entries[0]['memberof']) - 2];
            // Last is -2 due to count index
            $cn = ocf_long_cn_to_short_cn($group, group_property());
            $gid = ocf_group_ldapcn_to_ocfid($cn);
            if (is_null($gid)) {
                $gid = get_first_default_group();
            }
        } else {
            $gid = get_first_default_group();
        }
        ldap_free_result($results);
    }
    $PRIMARY_GROUP_MEMBERS[$member_id] = $gid;
    return $gid;
}
/**
 * Get form fields for adding/editing/finishing a member profile.
 *
 * @param  boolean			Whether we are only handling the essential details of a profile.
 * @param  ?MEMBER			The ID of the member we are handling (NULL: new member).
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  SHORT_TEXT		The e-mail address.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  ?integer			Day of date of birth (NULL: not known).
 * @param  ?integer			Month of date of birth (NULL: not known).
 * @param  ?integer			Year of date of birth (NULL: not known).
 * @param  ?ID_TEXT			The member timezone (NULL: site default).
 * @param  ?ID_TEXT			The members default theme (NULL: not known).
 * @param  BINARY				Whether the members age may be shown.
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The members language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?GROUP				The members primary (NULL: not known).
 * @param  SHORT_TEXT		The username.
 * @param  BINARY				Whether the member is permanently banned.
 * @param  ID_TEXT			The special type of profile this is (blank: not a special type).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @param  ?TIME				When the member is on probation until (NULL: just finished probation / or effectively was never on it)
 * @return array				A pair: The form fields, Hidden fields (both Tempcode).
 */
function ocf_get_member_fields_settings($mini_mode = true, $member_id = NULL, $groups = NULL, $email_address = '', $preview_posts = 0, $dob_day = NULL, $dob_month = NULL, $dob_year = NULL, $timezone = NULL, $theme = NULL, $reveal_age = 1, $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $validated = 1, $primary_group = NULL, $username = '', $is_perm_banned = 0, $special_type = '', $zone_wide = 1, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '', $on_probation_until = NULL)
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    $hidden = new ocp_tempcode();
    if (has_actual_page_access(get_member(), 'admin_ocf_join')) {
        $dob_optional = true;
    } else {
        $dob_optional = get_option('no_dob_ask') == '2';
    }
    if ($member_id === $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    require_code('form_templates');
    require_code('encryption');
    if ($special_type == '' && !is_null($member_id)) {
        if (ocf_is_ldap_member($member_id)) {
            $special_type = 'ldap';
        }
        if (ocf_is_httpauth_member($member_id)) {
            $special_type = 'httpauth';
        }
        if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_password_compat_scheme') == 'remote') {
            $special_type = 'remote';
        }
    }
    if (is_null($groups)) {
        $groups = is_null($member_id) ? ocf_get_all_default_groups(true) : $GLOBALS['OCF_DRIVER']->get_members_groups($member_id);
    }
    $fields = new ocp_tempcode();
    // Human name / Username
    if ($special_type != 'ldap' && $special_type != 'remote' && $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_password_compat_scheme') != 'facebook') {
        if (is_null($member_id) || has_actual_page_access(get_member(), 'admin_ocf_join') || has_specific_permission($member_id, 'rename_self')) {
            if (get_option('signup_fullname') == '1') {
                $fields->attach(form_input_line(do_lang_tempcode('NAME'), do_lang_tempcode('_DESCRIPTION_NAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
            } else {
                $prohibit_username_whitespace = get_option('prohibit_username_whitespace', true);
                if ($prohibit_username_whitespace == '1') {
                    $fields->attach(form_input_codename(do_lang_tempcode('USERNAME'), do_lang_tempcode('DESCRIPTION_USERNAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
                } else {
                    $fields->attach(form_input_line(do_lang_tempcode('USERNAME'), do_lang_tempcode('DESCRIPTION_USERNAME'), is_null($member_id) ? 'username' : 'edit_username', $username, true));
                }
            }
        }
    }
    // Password
    if ($special_type == '') {
        if (is_null($member_id) || $member_id == get_member() || has_specific_permission(get_member(), 'assume_any_member')) {
            $fields->attach(form_input_password(do_lang_tempcode('PASSWORD'), do_lang_tempcode('DESCRIPTION_PASSWORD' . (!is_null($member_id) ? '_EDIT' : '')), is_null($member_id) ? 'password' : 'edit_password', $mini_mode));
            $fields->attach(form_input_password(do_lang_tempcode('CONFIRM_PASSWORD'), '', 'password_confirm', $mini_mode));
        }
    }
    // E-mail address
    if ($email_address == '') {
        $email_address = trim(get_param('email_address', ''));
    }
    if ($special_type != 'remote') {
        $fields->attach(form_input_email(do_lang_tempcode('EMAIL_ADDRESS'), get_option('skip_email_confirm_join') == '1' ? new ocp_tempcode() : do_lang_tempcode('MUST_BE_REAL_ADDRESS'), 'email_address', $email_address, !has_specific_permission(get_member(), 'member_maintenance')));
        if (is_null($member_id) && $email_address == '' && get_option('skip_email_confirm_join') == '0') {
            $fields->attach(form_input_email(do_lang_tempcode('CONFIRM_EMAIL_ADDRESS'), '', 'email_address_confirm', '', !has_specific_permission(get_member(), 'member_maintenance')));
        }
    }
    // DOB
    $default_time = is_null($dob_month) ? NULL : usertime_to_utctime(mktime(0, 0, 0, $dob_month, $dob_day, $dob_year));
    if (get_option('no_dob_ask') != '1') {
        $fields->attach(form_input_date(do_lang_tempcode(get_option('no_dob_ask') == '2' ? 'BIRTHDAY' : 'DATE_OF_BIRTH'), '', 'dob', $dob_optional, false, false, $default_time, -130));
        if (addon_installed('ocf_forum')) {
            $fields->attach(form_input_tick(do_lang_tempcode('RELATED_FIELD', do_lang_tempcode('REVEAL_AGE')), do_lang_tempcode('DESCRIPTION_REVEAL_AGE'), 'reveal_age', $reveal_age == 1));
        }
    }
    // Work out what options we need to present
    $doing_international = get_option('allow_international') == '1' && $special_type != 'remote';
    $_langs = find_all_langs();
    $doing_langs = multi_lang() && $special_type != 'remote';
    $doing_email_option = get_option('allow_email_disable') == '1';
    $doing_email_from_staff_option = get_option('allow_email_from_staff_disable') == '1';
    $unspecced_width_zone_exists = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_name', array('zone_wide' => NULL));
    $unspecced_theme_zone_exists = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'zones WHERE ' . db_string_equal_to('zone_theme', '') . ' OR ' . db_string_equal_to('zone_theme', '-1'));
    $doing_wide_option = $special_type != 'remote' && !is_null($unspecced_width_zone_exists) && !$mini_mode;
    $doing_theme_option = $unspecced_theme_zone_exists != 0 && !$mini_mode;
    $doing_local_forum_options = addon_installed('ocf_forum') && $special_type != 'remote' && !$mini_mode;
    if ($doing_international || $doing_langs || $doing_email_option || $doing_wide_option || $doing_theme_option || $doing_local_forum_options) {
        $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('FORCE_OPEN' => is_null($member_id) ? true : NULL, 'TITLE' => do_lang_tempcode('SETTINGS'))));
    }
    require_lang('config');
    // Timezones, if enabled
    if ($doing_international) {
        $timezone_list = nice_get_timezone_list($timezone);
        $fields->attach(form_input_list(do_lang_tempcode('TIME_ZONE'), do_lang_tempcode('DESCRIPTION_TIMEZONE_MEMBER'), 'timezone', $timezone_list));
    }
    // Language choice, if we have multiple languages on site
    if ($doing_langs) {
        $lang_list = new ocp_tempcode();
        $no_lang_set = is_null($language) || $language == '';
        $allow_no_lang_set = get_value('allow_no_lang_selection') === '1';
        if ($allow_no_lang_set) {
            $lang_list->attach(form_input_list_entry('', $no_lang_set, do_lang_tempcode('UNSET')));
        } else {
            if ($no_lang_set) {
                $language = user_lang();
            }
        }
        $lang_list->attach(nice_get_langs($language));
        $fields->attach(form_input_list(do_lang_tempcode('LANGUAGE'), '', 'language', $lang_list, NULL, false, !$allow_no_lang_set));
    }
    // Email privacy
    if ($doing_email_option) {
        $fields->attach(form_input_tick(do_lang_tempcode('ALLOW_EMAILS'), do_lang_tempcode('DESCRIPTION_ALLOW_EMAILS'), 'allow_emails', $allow_emails == 1));
    }
    if ($doing_email_from_staff_option) {
        $fields->attach(form_input_tick(do_lang_tempcode('ALLOW_EMAILS_FROM_STAFF'), do_lang_tempcode('DESCRIPTION_ALLOW_EMAILS_FROM_STAFF'), 'allow_emails_from_staff', $allow_emails_from_staff == 1));
    }
    if (!$mini_mode) {
        // Wide-option, if we have any zones giving a choice
        require_lang('zones');
        if ($doing_wide_option) {
            $fields->attach(form_input_tick(do_lang_tempcode('WIDE'), do_lang_tempcode('DESCRIPTION_MEMBER_ZONE_WIDE'), 'zone_wide', $zone_wide == 1));
        }
        // Theme, if we have any zones giving a choice
        require_code('themes2');
        $entries = nice_get_themes($theme, false, false, 'RELY_SITE_DEFAULT');
        require_lang('themes');
        if ($doing_theme_option) {
            $fields->attach(form_input_list(do_lang_tempcode('THEME'), do_lang_tempcode('DESCRIPTION_THEME'), 'theme', $entries));
        }
        // Various forum options
        if (addon_installed('ocf_forum')) {
            if ($special_type != 'remote') {
                if (get_option('forced_preview_option') == '1') {
                    $fields->attach(form_input_tick(do_lang_tempcode('PREVIEW_POSTS'), do_lang_tempcode('DESCRIPTION_PREVIEW_POSTS'), 'preview_posts', $preview_posts == 1));
                }
                if (get_value('disable_views_sigs_option') !== '1') {
                    if (addon_installed('ocf_signatures')) {
                        $fields->attach(form_input_tick(do_lang_tempcode('VIEWS_SIGNATURES'), do_lang_tempcode('DESCRIPTION_VIEWS_SIGNATURES'), 'views_signatures', $views_signatures == 1));
                    }
                } else {
                    $hidden->attach(form_input_hidden('views_signatures', '1'));
                }
                //$fields->attach(form_input_tick(do_lang_tempcode('AUTO_NOTIFICATION_CONTRIB_CONTENT'),do_lang_tempcode('DESCRIPTION_AUTO_NOTIFICATION_CONTRIB_CONTENT'),'auto_monitor_contrib_content',$auto_monitor_contrib_content==1));
                $usergroup_list = new ocp_tempcode();
                $lgroups = $GLOBALS['OCF_DRIVER']->get_usergroup_list(true, true);
                foreach ($lgroups as $key => $val) {
                    if ($key != db_get_first_id()) {
                        $usergroup_list->attach(form_input_list_entry(strval($key), $pt_allow == '*' || count(array_intersect(array(strval($key)), explode(',', $pt_allow))) != 0, $val));
                    }
                }
                if (get_value('disable_pt_restrict') !== '1') {
                    $fields->attach(form_input_multi_list(do_lang_tempcode('PT_ALLOW'), addon_installed('chat') ? do_lang_tempcode('PT_ALLOW_DESCRIPTION_CHAT') : do_lang_tempcode('PT_ALLOW_DESCRIPTION'), 'pt_allow', $usergroup_list));
                    $fields->attach(form_input_text_comcode(do_lang_tempcode('PT_RULES_TEXT'), do_lang_tempcode('PT_RULES_TEXT_DESCRIPTION'), 'pt_rules_text', $pt_rules_text, false));
                }
            }
        }
        // Prepare list of usergroups, if maybe we are gonna let (a) usergroup-change field(s)
        $group_count = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)');
        $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id', 'g_name', 'g_hidden', 'g_open_membership'), $group_count > 200 ? array('g_is_private_club' => 0) : NULL, 'ORDER BY g_order');
        $_groups = new ocp_tempcode();
        $default_primary_group = get_first_default_group();
        $current_primary_group = NULL;
        foreach ($rows as $group) {
            if ($group['id'] != db_get_first_id()) {
                $selected = $group['id'] == $primary_group || is_null($primary_group) && $group['id'] == $default_primary_group;
                if ($selected) {
                    $current_primary_group = $group['id'];
                }
                $_groups->attach(form_input_list_entry(strval($group['id']), $selected, get_translated_text($group['g_name'], $GLOBALS['FORUM_DB'])));
            }
        }
        // Some admin options...
        if (has_specific_permission(get_member(), 'member_maintenance')) {
            $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('MEMBER_ACCESS'))));
            // Probation
            if (has_specific_permission(get_member(), 'probate_members')) {
                $fields->attach(form_input_date(do_lang_tempcode('ON_PROBATION_UNTIL'), do_lang_tempcode('DESCRIPTION_ON_PROBATION_UNTIL'), 'on_probation_until', true, is_null($on_probation_until) || $on_probation_until <= time(), true, $on_probation_until, 2));
            }
            // Primary usergroup
            if ($special_type != 'ldap') {
                if (has_specific_permission(get_member(), 'assume_any_member')) {
                    if (is_null($member_id) || !$GLOBALS['FORUM_DRIVER']->is_super_admin($member_id) || count($GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), 2)) > 1) {
                        $fields->attach(form_input_list(do_lang_tempcode('PRIMARY_GROUP'), do_lang_tempcode('DESCRIPTION_PRIMARY_GROUP'), 'primary_group', $_groups));
                    }
                }
            }
        }
        // Secondary usergroups
        if ($special_type != 'ldap') {
            $_groups2 = new ocp_tempcode();
            $members_groups = is_null($member_id) ? array() : $GLOBALS['OCF_DRIVER']->get_members_groups($member_id, false, false);
            foreach ($rows as $group) {
                if ($group['g_hidden'] == 1 && !array_key_exists($group['id'], $members_groups) && !has_specific_permission(get_member(), 'see_hidden_groups')) {
                    continue;
                }
                if ($group['id'] != db_get_first_id() && $group['id'] != $current_primary_group && (array_key_exists($group['id'], $members_groups) || has_specific_permission(get_member(), 'assume_any_member') || $group['g_open_membership'] == 1)) {
                    $selected = array_key_exists($group['id'], $members_groups);
                    $_groups2->attach(form_input_list_entry(strval($group['id']), $selected, get_translated_text($group['g_name'], $GLOBALS['FORUM_DB'])));
                }
            }
            $sec_url = build_url(array('page' => 'groups', 'type' => 'misc'), get_module_zone('groups'));
            if (!$_groups2->is_empty()) {
                $fields->attach(form_input_multi_list(do_lang_tempcode('SECONDARY_GROUP_MEMBERSHIP'), do_lang_tempcode('DESCRIPTION_SECONDARY_GROUP', escape_html($sec_url->evaluate())), 'secondary_groups', $_groups2));
            }
        }
        // Special admin options
        if (has_specific_permission(get_member(), 'member_maintenance')) {
            if ($validated == 0) {
                $validated = get_param_integer('validated', 0);
                if ($validated == 1) {
                    attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING'));
                }
            }
            if (addon_installed('unvalidated')) {
                $fields->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_MEMBER_VALIDATED'), 'validated', $validated == 1));
            }
            if (get_value('disable_highlight_name') !== '1') {
                $fields->attach(form_input_tick(do_lang_tempcode('HIGHLIGHTED_NAME'), do_lang_tempcode(addon_installed('pointstore') ? 'DESCRIPTION_HIGHLIGHTED_NAME_P' : 'DESCRIPTION_HIGHLIGHTED_NAME'), 'highlighted_name', $highlighted_name == 1));
            }
            if (!is_null($member_id) && $member_id != get_member()) {
                // Can't ban someone new, and can't ban yourself
                $fields->attach(form_input_tick(do_lang_tempcode('_BANNED'), do_lang_tempcode('DESCRIPTION_MEMBER_BANNED'), 'is_perm_banned', $is_perm_banned == 1));
            }
        }
    }
    return array($fields, $hidden);
}
Exemple #14
0
/**
 * Actualise the join form.
 *
 * @param  boolean		Whether to handle CAPTCHA (if enabled at all)
 * @param  boolean		Whether to ask for intro messages (if enabled at all)
 * @param  boolean		Whether to check for invites (if enabled at all)
 * @param  boolean		Whether to check email-address restrictions (if enabled at all)
 * @param  boolean		Whether to require staff confirmation (if enabled at all)
 * @param  boolean		Whether to force email address validation (if enabled at all)
 * @param  boolean		Whether to do COPPA checks (if enabled at all)
 * @param  boolean		Whether to instantly log the user in
 * @return array			A tuple: Messages to show (currently nothing else in tuple)
 */
function ocf_join_actual($captcha_if_enabled = true, $intro_message_if_enabled = true, $invites_if_enabled = true, $one_per_email_address_if_enabled = true, $confirm_if_enabled = true, $validate_if_enabled = true, $coppa_if_enabled = true, $instant_login = false)
{
    ocf_require_all_forum_stuff();
    require_css('ocf');
    require_code('ocf_members_action');
    require_code('ocf_members_action2');
    // Read in data
    $username = trim(post_param('username'));
    ocf_check_name_valid($username, NULL, NULL, true);
    // Adjusts username if needed
    $password = trim(post_param('password'));
    $password_confirm = trim(post_param('password_confirm'));
    if ($password != $password_confirm) {
        warn_exit(make_string_tempcode(escape_html(do_lang('PASSWORD_MISMATCH'))));
    }
    $confirm_email_address = post_param('email_address_confirm', NULL);
    $email_address = trim(post_param('email_address'));
    if (!is_null($confirm_email_address)) {
        if (trim($confirm_email_address) != $email_address) {
            warn_exit(make_string_tempcode(escape_html(do_lang('EMAIL_ADDRESS_MISMATCH'))));
        }
    }
    require_code('type_validation');
    if (!is_valid_email_address($email_address)) {
        warn_exit(do_lang_tempcode('INVALID_EMAIL_ADDRESS'));
    }
    if ($invites_if_enabled) {
        if (get_option('is_on_invites') == '1') {
            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address, 'i_taken' => 0));
            if (is_null($test)) {
                warn_exit(do_lang_tempcode('NO_INVITE'));
            }
        }
        $GLOBALS['FORUM_DB']->query_update('f_invites', array('i_taken' => 1), array('i_email_address' => $email_address, 'i_taken' => 0), '', 1);
    }
    $dob_day = post_param_integer('dob_day', NULL);
    $dob_month = post_param_integer('dob_month', NULL);
    $dob_year = post_param_integer('dob_year', NULL);
    $reveal_age = post_param_integer('reveal_age', 0);
    $timezone = post_param('timezone', get_users_timezone());
    $language = post_param('language', get_site_default_lang());
    $allow_emails = post_param_integer('allow_emails', 0);
    $allow_emails_from_staff = post_param_integer('allow_emails_from_staff', 0);
    $groups = ocf_get_all_default_groups(true);
    // $groups will contain the built in default primary group too (it is not $secondary_groups)
    $primary_group = post_param_integer('primary_group', NULL);
    if ($primary_group !== NULL && !in_array($primary_group, $groups)) {
        // Check security
        $test = $GLOBALS['FORUM_DB']->query_value('f_groups', 'g_is_presented_at_install', array('id' => $primary_group));
        if ($test == 1) {
            $groups = ocf_get_all_default_groups(false);
            // Get it so it does not include the built in default primary group
            $groups[] = $primary_group;
            // And add in the *chosen* primary group
        } else {
            $primary_group = NULL;
        }
    } else {
        $primary_group = NULL;
    }
    if ($primary_group === NULL) {
        $primary_group = get_first_default_group();
    }
    $custom_fields = ocf_get_all_custom_fields_match($groups, NULL, NULL, NULL, NULL, NULL, NULL, 0, true);
    $actual_custom_fields = ocf_read_in_custom_fields($custom_fields);
    // Check that the given address isn't already used (if one_per_email_address on)
    $member_id = NULL;
    if ($one_per_email_address_if_enabled) {
        if (get_option('one_per_email_address') == '1') {
            $test = $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username'), array('m_email_address' => $email_address), '', 1);
            if (array_key_exists(0, $test)) {
                if ($test[0]['m_username'] != $username) {
                    $reset_url = build_url(array('page' => 'lostpassword', 'email_address' => $email_address), get_module_zone('lostpassword'));
                    warn_exit(do_lang_tempcode('EMAIL_ADDRESS_IN_USE', escape_html(get_site_name()), escape_html($reset_url->evaluate())));
                }
                $member_id = $test[0]['id'];
            }
        }
    }
    if ($captcha_if_enabled) {
        if (addon_installed('captcha')) {
            require_code('captcha');
            enforce_captcha();
        }
    }
    if (addon_installed('ldap')) {
        require_code('ocf_ldap');
        if (ocf_is_ldap_member_potential($username)) {
            warn_exit(do_lang_tempcode('DUPLICATE_JOIN_AUTH'));
        }
    }
    // Add member
    $skip_confirm = get_option('skip_email_confirm_join') == '1';
    if (!$confirm_if_enabled) {
        $skip_confirm = true;
    }
    $validated_email_confirm_code = $skip_confirm ? '' : strval(mt_rand(1, 32000));
    $require_new_member_validation = get_option('require_new_member_validation') == '1';
    if (!$validate_if_enabled) {
        $require_new_member_validation = false;
    }
    $coppa = get_option('is_on_coppa') == '1' && utctime_to_usertime(time() - mktime(0, 0, 0, $dob_month, $dob_day, $dob_year)) / 31536000.0 < 13.0;
    if (!$coppa_if_enabled) {
        $coppa = false;
    }
    $validated = $require_new_member_validation || $coppa ? 0 : 1;
    if (is_null($member_id)) {
        $member_id = ocf_make_member($username, $password, $email_address, $groups, $dob_day, $dob_month, $dob_year, $actual_custom_fields, $timezone, $primary_group, $validated, time(), time(), '', NULL, '', 0, get_option('default_preview_guests') == '1' ? 1 : 0, $reveal_age, '', '', '', 1, get_value('no_auto_notifications') === '1' ? 0 : 1, $language, $allow_emails, $allow_emails_from_staff, '', get_ip_address(), $validated_email_confirm_code, true, '', '');
    }
    // Send confirm mail
    if (!$skip_confirm) {
        $zone = get_module_zone('join');
        if ($zone != '') {
            $zone .= '/';
        }
        $_url = build_url(array('page' => 'join', 'type' => 'step4', 'email' => $email_address, 'code' => $validated_email_confirm_code), $zone, NULL, false, false, true);
        $url = $_url->evaluate();
        $_url_simple = build_url(array('page' => 'join', 'type' => 'step4'), $zone, NULL, false, false, true);
        $url_simple = $_url_simple->evaluate();
        $redirect = get_param('redirect', '');
        if ($redirect != '') {
            $url .= '&redirect=' . ocp_url_encode($redirect);
        }
        $message = do_lang('OCF_SIGNUP_TEXT', comcode_escape(get_site_name()), comcode_escape($url), array($url_simple, $email_address, $validated_email_confirm_code), $language);
        require_code('mail');
        if (!$coppa) {
            mail_wrap(do_lang('CONFIRM_EMAIL_SUBJECT', get_site_name(), NULL, NULL, $language), $message, array($email_address), $username, '', '', 3, NULL, false, NULL, false, false, false, 'MAIL', true);
        }
    }
    // Send COPPA mail
    if ($coppa) {
        $fields_done = do_lang('THIS_WITH_COMCODE', do_lang('USERNAME'), $username) . "\n\n";
        foreach ($custom_fields as $custom_field) {
            if ($custom_field['cf_type'] != 'upload') {
                $fields_done .= do_lang('THIS_WITH_COMCODE', $custom_field['trans_name'], post_param('custom_' . $custom_field['id'] . '_value')) . "\n";
            }
        }
        $_privacy_url = build_url(array('page' => 'privacy'), '_SEARCH', NULL, false, false, true);
        $privacy_url = $_privacy_url->evaluate();
        $message = do_lang('COPPA_MAIL', comcode_escape(get_option('site_name')), comcode_escape(get_option('privacy_fax')), array(comcode_escape(get_option('privacy_postal_address')), comcode_escape($fields_done), comcode_escape($privacy_url)), $language);
        require_code('mail');
        mail_wrap(do_lang('COPPA_JOIN_SUBJECT', $username, get_site_name(), NULL, $language), $message, array($email_address), $username);
    }
    // Send 'validate this member' notification
    if ($require_new_member_validation) {
        require_code('notifications');
        $_validation_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $member_id), get_module_zone('members'), NULL, false, false, true, 'tab__edit');
        $validation_url = $_validation_url->evaluate();
        $message = do_lang('VALIDATE_NEW_MEMBER_MAIL', comcode_escape($username), comcode_escape($validation_url), comcode_escape(strval($member_id)), get_site_default_lang());
        dispatch_notification('ocf_member_needs_validation', NULL, do_lang('VALIDATE_NEW_MEMBER_SUBJECT', $username, NULL, NULL, get_site_default_lang()), $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
    }
    // Send new member notification
    require_code('notifications');
    $_member_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $member_id), get_module_zone('members'), NULL, false, false, true);
    $member_url = $_member_url->evaluate();
    $message = do_lang('NEW_MEMBER_NOTIFICATION_MAIL', comcode_escape($username), comcode_escape(get_site_name()), array(comcode_escape($member_url), comcode_escape(strval($member_id))), get_site_default_lang());
    dispatch_notification('ocf_new_member', NULL, do_lang('NEW_MEMBER_NOTIFICATION_MAIL_SUBJECT', $username, get_site_name(), NULL, get_site_default_lang()), $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
    // Intro post
    if ($intro_message_if_enabled) {
        $forum_id = get_option('intro_forum_id');
        if ($forum_id != '') {
            if (!is_numeric($forum_id)) {
                $_forum_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'id', array('f_name' => $forum_id));
                if (is_null($_forum_id)) {
                    $forum_id = strval(db_get_first_id());
                } else {
                    $forum_id = strval($_forum_id);
                }
            }
            $intro_title = post_param('intro_title', '');
            $intro_post = post_param('intro_post', '');
            if ($intro_post != '') {
                require_code('ocf_topics_action');
                if ($intro_title == '') {
                    $intro_title = do_lang('INTRO_POST_DEFAULT', $username);
                }
                $topic_id = ocf_make_topic(intval($forum_id));
                require_code('ocf_posts_action');
                ocf_make_post($topic_id, $intro_title, $intro_post, 0, true, NULL, 0, NULL, NULL, NULL, $member_id);
            }
        }
    }
    // Alert user to situation
    $message = new ocp_tempcode();
    if ($coppa) {
        if (!$skip_confirm) {
            $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL'));
        }
        $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL_COPPA'));
    } elseif ($require_new_member_validation) {
        if (!$skip_confirm) {
            $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL'));
        }
        $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL_VALIDATED', escape_html(get_custom_base_url())));
    } elseif ($skip_confirm) {
        if ($instant_login) {
            require_code('users_active_actions');
            handle_active_login($username);
            $message->attach(do_lang_tempcode('OCF_LOGIN_AUTO'));
        } else {
            $_login_url = build_url(array('page' => 'login', 'redirect' => get_param('redirect', NULL)), get_module_zone('login'));
            $login_url = $_login_url->evaluate();
            $message->attach(do_lang_tempcode('OCF_LOGIN_INSTANT', escape_html($login_url)));
        }
    } else {
        if (!$skip_confirm) {
            $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL'));
        }
        $message->attach(do_lang_tempcode('OCF_WAITING_CONFIRM_MAIL_INSTANT'));
    }
    $message = protect_from_escaping($message);
    return array($message);
}
 /**
  * Standard aed_module edit form filler.
  *
  * @param  ID_TEXT		The entry being edited
  * @return array			A triple: fields, hidden-fields, delete-fields
  */
 function fill_in_edit_form($id)
 {
     $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('id' => intval($id)), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     $username = '';
     if (!is_null($myrow['g_group_leader'])) {
         $username = $GLOBALS['FORUM_DRIVER']->get_username($myrow['g_group_leader']);
         if (is_null($username)) {
             $username = '';
         }
         //do_lang('UNKNOWN');
     }
     if (intval($id) == db_get_first_id() + 8 && $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)', array('g_is_presented_at_install' => '1')) == 0) {
         $myrow['g_is_presented_at_install'] = 1;
     }
     list($fields, $hidden) = $this->get_form_fields(intval($id), get_translated_text($myrow['g_name'], $GLOBALS['FORUM_DB']), $myrow['g_is_default'], $myrow['g_is_super_admin'], $myrow['g_is_super_moderator'], $username, get_translated_text($myrow['g_title'], $GLOBALS['FORUM_DB']), $myrow['g_rank_image'], $myrow['g_promotion_target'], $myrow['g_promotion_threshold'], $myrow['g_flood_control_submit_secs'], $myrow['g_flood_control_access_secs'], $myrow['g_gift_points_base'], $myrow['g_gift_points_per_day'], $myrow['g_max_daily_upload_mb'], $myrow['g_max_attachments_per_post'], $myrow['g_max_avatar_width'], $myrow['g_max_avatar_height'], $myrow['g_max_post_length_comcode'], $myrow['g_max_sig_length_comcode'], $myrow['g_enquire_on_new_ips'], $myrow['g_is_presented_at_install'], $myrow['g_hidden'], $myrow['g_order'], $myrow['g_rank_image_pri_only'], $myrow['g_open_membership'], $myrow['g_is_private_club']);
     $default_group = get_first_default_group();
     $groups = new ocp_tempcode();
     $group_count = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)');
     if ($myrow['g_is_private_club'] == 1 && $group_count > 300) {
         $delete_fields = form_input_integer(do_lang_tempcode('NEW_USERGROUP'), do_lang_tempcode('DESCRIPTION_NEW_USERGROUP'), 'new_usergroup', NULL, false);
     } else {
         $rows = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id', 'g_name'), $group_count > 300 ? array('g_is_private_club' => 0) : NULL);
         foreach ($rows as $row) {
             if ($row['id'] != db_get_first_id() && $row['id'] != intval($id)) {
                 $groups->attach(form_input_list_entry(strval($row['id']), $row['id'] == $default_group, get_translated_text($row['g_name'], $GLOBALS['FORUM_DB'])));
             }
         }
         $delete_fields = form_input_list(do_lang_tempcode('NEW_USERGROUP'), do_lang_tempcode('DESCRIPTION_NEW_USERGROUP'), 'new_usergroup', $groups);
     }
     $text = $this->edit_text;
     if (addon_installed('ecommerce')) {
         $usergroup_subs = $GLOBALS['FORUM_DB']->query_select('f_usergroup_subs', array('id', 's_title'), array('s_group_id' => intval($id)));
         if (count($usergroup_subs) != 0) {
             $subs = new ocp_tempcode();
             foreach ($usergroup_subs as $i => $sub) {
                 if ($i != 0) {
                     $subs->attach(do_lang_tempcode('LIST_SEP'));
                 }
                 $subs->attach(hyperlink(build_url(array('page' => 'admin_ecommerce', 'type' => '_ed', 'id' => $sub['id']), get_module_zone('admin_ecommerce')), get_translated_text($sub['s_title']), false, true));
             }
             require_lang('ecommerce');
             $text->attach(paragraph(do_lang_tempcode('HAS_THESE_SUBS', $subs)));
         }
     }
     return array($fields, $hidden, $delete_fields, $text);
 }