/** * Add the specified custom field to the forum (some forums implemented this using proper custom profile fields, others through adding a new field). * * @param object Link to the real forum driver * @param string The name of the new custom field * @param integer The length of the new custom field * @param BINARY Whether the field is locked * @param BINARY Whether the field is for viewing * @param BINARY Whether the field is for setting * @param BINARY Whether the field is required * @param string Description * @param string The field type * @param BINARY Whether the field is encrypted * @param ?string Default field value (NULL: standard for field type) * @return boolean Whether the custom field was created successfully */ function _helper_install_create_custom_field($this_ref, $name, $length, $locked = 1, $viewable = 0, $settable = 0, $required = 0, $description = '', $type = 'long_text', $encrypted = 0, $default = NULL) { unset($length); ocf_require_all_forum_stuff(); require_code('ocf_members_action'); $name = 'ocp_' . $name; $id = $this_ref->connection->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $this_ref->connection->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $name)); if (is_null($id)) { if (is_null($default)) { $default = strpos($name, 'points') !== false ? '0' : ''; } $id = ocf_make_custom_field($name, $locked, $description, $default, $viewable, $viewable, $settable, $encrypted, $type, $required); } return !is_null($id); }
/** * 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_custom_profile_fields($db, $table_prefix, $file_base) { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'profilefield'); $members = $db->query('SELECT * FROM ' . $table_prefix . 'userfield'); foreach ($rows as $row) { if (import_check_if_imported('cpf', strval($row['profilefieldid']))) { continue; } $type = 'short_text'; if ($row['type'] == 'input') { $type = 'short_text'; } elseif ($row['type'] == 'textarea') { $type = 'long_text'; } if (!array_key_exists('title', $row)) { $row['title'] = $db->query_value_null_ok_full('SELECT text FROM ' . $table_prefix . 'phrase WHERE ' . db_string_equal_to('product', 'vbulletin') . ' AND ' . db_string_equal_to('varname', 'field' . strval($row['profilefieldid']) . '_title')); $row['description'] = $db->query_value_null_ok_full('SELECT text FROM ' . $table_prefix . 'phrase WHERE ' . db_string_equal_to('product', 'vbulletin') . ' AND ' . db_string_equal_to('varname', 'field' . strval($row['profilefieldid']) . '_desc')); } $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $row['title'])); if (is_null($id_new)) { $id_new = ocf_make_custom_field($row['title'], 0, $row['description'], '', 1 - $row['hidden'], 1 - $row['hidden'], $row['editable'], 0, $type, $row['required'], $row['memberlist'], $row['memberlist'], $row['displayorder'], '', true); } foreach ($members as $member) { $v = $member['field' . strval($row['profilefieldid'])]; $member_id = import_id_remap_get('member', strval($member['userid']), true); if ($v != '' && !is_null($member_id)) { ocf_set_custom_field($member_id, $id_new, $v); } } import_id_remap_put('cpf', strval($row['profilefieldid']), $id_new); } }
/** * Standard aed_module add actualiser. * * @return ID_TEXT The entry added */ function add_actualisation() { $only_group = array_key_exists('only_group', $_POST) ? is_array($_POST['only_group']) ? implode(',', $_POST['only_group']) : post_param('only_group') : ''; $id = ocf_make_custom_field(post_param('name'), 0, post_param('description'), post_param('default'), post_param_integer('public_view', 0), post_param_integer('owner_view', 0), post_param_integer('owner_set', 0), post_param_integer('encrypted', 0), post_param('type'), post_param_integer('required', 0), post_param_integer('show_in_posts', 0), post_param_integer('show_in_post_previews', 0), post_param_integer('order'), $only_group, false, post_param_integer('show_on_join_form', 0)); return strval($id); }
/** * Make a custom profile field from one of the predefined templates (this is often used by importers). * * @param ID_TEXT The identifier of the boiler custom profile field. * @return AUTO_LINK The ID of the new custom profile field. */ function ocf_make_boiler_custom_field($type) { $_type = 'long_trans'; if (substr($type, 0, 3) == 'im_' || substr($type, 0, 3) == 'sn_') { $_type = 'short_text'; } elseif ($type == 'location') { $_type = 'short_text'; } elseif ($type == 'occupation') { $_type = 'short_text'; } elseif ($type == 'website') { $_type = 'short_trans'; } $public_view = 1; $owner_view = 1; $owner_set = 1; if ($type == 'staff_notes') { $public_view = 0; $owner_view = 0; $owner_set = 0; } global $CUSTOM_FIELD_CACHE; $CUSTOM_FIELD_CACHE = array(); if (substr($type, 0, 4) == 'ocp_') { $title = do_lang('SPECIAL_CPF__' . $type); $description = ''; } else { $title = do_lang('DEFAULT_CPF_' . $type . '_NAME'); $description = do_lang('DEFAULT_CPF_' . $type . '_DESCRIPTION'); } return ocf_make_custom_field($title, 0, $description, '', $public_view, $owner_view, $owner_set, 0, $_type, 0, 0, 0, NULL, '', true); }
/** * 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_custom_profile_fields($db, $table_prefix) { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'custom_fields'); foreach ($rows as $row) { if (import_check_if_imported('cpf', $row['id_field'])) { continue; } $name = $row['field_name']; $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $name)); if (is_null($id_new)) { $default = $row['default_value']; $options = $row['field_options']; $pub_view = 1; $own_view = 1; $own_set = 1; $req = 0; $on_join = 0; $show_in_posts = $row['show_display']; $desc = $row['field_desc']; $private = (int) $row['private']; switch ($private) { case 0: $pub_view = 1; $own_view = 1; $own_set = 1; break; case 1: $pub_view = 1; $own_view = 1; $own_set = 0; break; case 2: $pub_view = 0; $own_view = 1; $own_set = 1; break; case 3: $pub_view = 0; $own_view = 0; $own_set = 0; break; } switch ($row['show_reg']) { case 0: $on_join = 0; $req = 0; break; case 1: $on_join = 1; break; case 2: $on_join = 1; $req = 1; break; } $type = 'short_text'; switch ($row['field_type']) { case 'text': if ($row['bbc'] == 1) { $type = 'short_trans'; } else { $type = 'short_text'; } break; case 'textarea': $default = ''; if ($row['bbc'] == 1) { $type = 'long_trans'; } else { $type = 'long_text'; } break; case 'select': $type = 'list'; break; case 'check': $type = 'tick'; break; case 'radio': $type = 'radiolist'; break; } $def = !empty($default) ? $default : ''; if (!empty($options) && !empty($def)) { $def = $this->cpf_options_string($def, $options); } $id_new = ocf_make_custom_field($name, 0, $desc, $def, $pub_view, $own_view, $own_set, 0, $type, $req, $show_in_posts, 0, NULL, '', false, $on_join); } import_id_remap_put('cpf', $row['id_field'], $id_new); } }
/** * 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_custom_profile_fields($db, $table_prefix, $file_base) { if ($this->on_same_msn($file_base)) { return; } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'f_custom_fields'); foreach ($rows as $row) { if (import_check_if_imported('cpf', strval($row['id']))) { continue; } $name = $this->get_lang_string($db, $row['cf_name']); $existing = $GLOBALS['FORUM_DB']->query_select('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', array('f.id', 'cf_type'), array('text_original' => $name), '', 1); if (!array_key_exists(0, $existing) || $existing[0]['cf_type'] != $row['cf_type']) { $only_group = $row['cf_only_group']; if ($only_group != '') { $only_group2 = ''; foreach (explode(',', $only_group) as $_only_group) { if ($only_group2 != '') { $only_group2 .= ','; } $group = import_id_remap_get('group', $_only_group, true); if (is_null($group)) { continue; } $only_group2 .= strval($group); } $only_group2 = $only_group; } $id_new = ocf_make_custom_field($name, $row['cf_locked'], $this->get_lang_string($db, $row['cf_description']), $row['cf_default'], $row['cf_public_view'], $row['cf_owner_view'], $row['cf_owner_set'], array_key_exists('cf_encrypted', $row) ? $row['cf_encrypted'] : 0, $row['cf_type'], $row['cf_required'], $row['cf_show_in_posts'], $row['cf_show_in_post_previews'], $row['cf_order'], !is_string($only_group) ? is_null($only_group) ? '' : strval($only_group) : $only_group); } else { $id_new = $existing[0]['id']; } import_id_remap_put('cpf', strval($row['id']), $id_new); } // import member cpf_perms $this->_import_f_member_cpf_perms($db, $table_prefix); }
/** * Standard modular file writing function for OcCLE FS hooks. * * @param array The current meta-directory path * @param string The root node of the current meta-directory * @param string The file name * @param string The new file contents * @param array A reference to the OcCLE filesystem object * @return boolean Success? */ function write_file($meta_dir, $meta_root_node, $file_name, $contents, &$occle_fs) { if (get_forum_type() != 'ocf') { return false; } if (count($meta_dir) == 1) { //We're in a member's directory, and writing one of their profile fields $coded_fields = array('theme' => 'm_theme', 'avatar' => 'm_avatar_url', 'validated' => 'm_validated', 'timezone_offset' => 'm_timezone_offset', 'primary_group' => 'm_primary_group', 'signature' => 'm_signature', 'banned' => 'm_is_perm_banned', 'preview_posts' => 'm_preview_posts', 'dob_day' => 'm_dob_day', 'dob_month' => 'm_dob_month', 'dob_year' => 'm_dob_year', 'reveal_age' => 'm_reveal_age', 'e-mail' => 'm_email_address', 'title' => 'm_title', 'photo' => 'm_photo_url', 'photo_thumb' => 'm_photo_thumb_url', 'view_signatures' => 'm_views_signatures', 'auto_monitor_contrib_content' => 'm_auto_monitor_contrib_content', 'language' => 'm_language', 'allow_e-mails' => 'm_allow_emails', 'allow_e-mails_from_staff' => 'm_allow_emails_from_staff', 'notes' => 'm_notes', 'wide' => 'm_zone_wide', 'max_attach_size' => 'm_max_email_attach_size_mb', 'highlighted_name' => 'm_highlighted_name'); if (array_key_exists($file_name, $coded_fields)) { $GLOBALS['FORUM_DB']->query_update('f_members', array($coded_fields[$file_name] => $contents), array('id' => $GLOBALS['FORUM_DRIVER']->get_member_from_username($meta_dir[0])), '', 1); return true; } require_code('ocf_members_action'); require_code('ocf_members_action2'); $field_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.cf_name', 'f.id', array('text_original' => $file_name)); if (is_null($field_id)) { $GLOBALS['FORUM_DRIVER']->install_create_custom_field($file_name, 10); $field_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.cf_name', 'f.id', array('text_original' => $file_name)); } if (is_null($field_id)) { $field_id = ocf_make_custom_field($file_name); } ocf_set_custom_field($GLOBALS['FORUM_DRIVER']->get_member_from_username($meta_dir[0]), $field_id, $contents); } elseif (count($meta_dir) == 2) { if ($meta_dir[1] != 'groups') { return false; } //We're in a member's usergroup directory, and writing one of their usergroup associations require_code('ocf_groups_action'); require_code('ocf_groups_action2'); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); $group_id = array_search($file_name, $groups); if ($group_id !== false) { ocf_add_member_to_group($GLOBALS['FORUM_DRIVER']->get_member_from_username($meta_dir[0]), $group_id, 1); } else { return false; } } else { return false; } //Group files can't be written, and other files shouldn't even exist anywhere else! return true; }
/** * The actualiser for importing a CSV file. * * @return tempcode The UI */ function _import_csv() { $title = get_page_title('IMPORT_MEMBER_CSV'); disable_php_memory_limit(); // Even though we split into chunks, PHP does leak memory :( $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/import_csv'; if (function_exists('set_time_limit')) { @set_time_limit(0); } require_lang('ocf'); require_code('ocf_members_action'); $default_password = post_param('default_password'); $num_added = 0; $num_edited = 0; $done = 0; $headings = $this->_get_csv_headings(); $all_cpfs = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_default', 'cf_type', 'cf_name'), NULL, 'ORDER BY cf_order'); foreach ($all_cpfs as $i => $c) { $c['text_original'] = get_translated_text($c['cf_name'], $GLOBALS['FORUM_DB']); $all_cpfs[$i] = $c; $headings[$c['text_original']] = NULL; } $_all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, false, true); $all_groups = array_flip($_all_groups); $all_members = collapse_2d_complexity('id', 'm_username', $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username'))); $all_members_flipped = array_flip($all_members); // Import require_code('uploads'); if (is_swf_upload(true) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) { $_csv_data = array(); $fixed_contents = unixify_line_format(file_get_contents($_FILES['file']['tmp_name'])); $myfile = @fopen($_FILES['file']['tmp_name'], 'wb'); if ($myfile !== false) { fwrite($myfile, $fixed_contents); fclose($myfile); } $myfile = fopen($_FILES['file']['tmp_name'], 'rb'); $del = ','; $csv_header = fgetcsv($myfile, 102400, $del); if ($csv_header === false) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } if (count($csv_header) == 1 && strpos($csv_header[0], ';') !== false) { $del = ';'; rewind($myfile); $csv_header = fgetcsv($myfile, 102400, $del); } while (($csv_line = fgetcsv($myfile, 102400, $del)) !== false) { $line = array(); foreach ($csv_header as $i => $h) { $extracted_value = trim(unixify_line_format(array_key_exists($i, $csv_line) ? $csv_line[$i] : '')); if (strpos($h, ':') !== false) { $parts = explode(':', $h, 2); $h = trim($parts[0]); if ($extracted_value != '') { $extracted_value = $parts[1] . ': ' . $extracted_value; } } if (array_key_exists($h, $line)) { if ($extracted_value != '') { $line[$h] .= ($line[$h] != '' ? chr(10) : '') . $extracted_value; } } else { $line[$h] = $extracted_value; } } if (!array_key_exists('Username', $line) || $line['Username'] == '') { // Can we auto-generate it $forename = NULL; if (array_key_exists('Forenames', $line)) { $forename = $line['Forenames']; } if (array_key_exists('Forename', $line)) { $forename = $line['Forename']; } if (array_key_exists('First name', $line)) { $forename = $line['First name']; } if (array_key_exists('First Name', $line)) { $forename = $line['First Name']; } $surname = NULL; if (array_key_exists('Surname', $line)) { $surname = $line['Surname']; } if (array_key_exists('Last name', $line)) { $surname = $line['Last name']; } if (array_key_exists('Last Name', $line)) { $surname = $line['Last Name']; } if (!is_null($forename) || !is_null($surname)) { // Can we get a year too? $year = ''; foreach ($line as $tl_key => $tl_val) { if (substr($tl_key, 0, 4) == 'Year') { $year = $tl_val; break; } } if (strlen($year) == 4 && (substr($year, 0, 2) == '19' || substr($year, 0, 2) == '20')) { $year = substr($year, 2); } // Tidy up forename $_forename = preg_replace('#[^\\w]#', '', preg_replace('#[\\s\\.].*#', '', $forename)); // Tidy up surname (last bit strips like 'OBE') $_surname = preg_replace('#[^\\w]#', '', trim(preg_replace('#\\s*[A-Z\\d][A-Z\\d]+#', '', $surname))); // Put it together $line['Username'] = ucfirst($_forename) . ucfirst($_surname) . $year; } else { continue; // This field is needed } } $username = $line['Username']; $linked_id = NULL; if (array_key_exists('ID', $line)) { $linked_id = $line['ID'] != '' && array_key_exists(intval($line['ID']), $all_members) ? intval($line['ID']) : NULL; } if (is_null($linked_id)) { $linked_id = array_key_exists($username, $all_members_flipped) ? $all_members_flipped[$username] : NULL; } $new_member = is_null($linked_id); $email_address_key = 'E-mail address'; if (array_key_exists('Email address', $line)) { $email_address_key = 'Email address'; } if (array_key_exists('E-mail Address', $line)) { $email_address_key = 'E-mail Address'; } if (array_key_exists('Email Address', $line)) { $email_address_key = 'Email Address'; } if (array_key_exists('E-mail', $line)) { $email_address_key = 'E-mail'; } if (array_key_exists('Email', $line)) { $email_address_key = 'Email'; } $dob_key = 'Date of birth'; if (array_key_exists('Date Of Birth', $line)) { $dob_key = 'Date Of Birth'; } if (array_key_exists('DOB', $line)) { $dob_key = 'DOB'; } // If it's an edited member, add in their existing CSV details, so that if it's a partial merge it'll still work without deleting anything! if (!$new_member) { $member_groups = $GLOBALS['FORUM_DB']->query_select('f_group_members', array('gm_member_id', 'gm_group_id'), array('gm_validated' => 1, 'gm_member_id' => $linked_id)); $member_cpfs = list_to_map('mf_member_id', $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), array('mf_member_id' => $linked_id), '', 1)); $this_record = $this->_get_csv_member_record($member_cpfs, $GLOBALS['FORUM_DRIVER']->get_member_row($linked_id), $_all_groups, $headings, $all_cpfs, $member_groups); // Remember "+" in PHP won't overwrite existing keys if (!array_key_exists($email_address_key, $line)) { unset($this_record['E-mail address']); } if (!array_key_exists($dob_key, $line)) { unset($this_record['Date of birth']); } $line += $this_record; } // Set up member row if (array_key_exists('Password', $line) && $line['Password'] != '') { $parts = explode('/', $line['Password']); $password = $parts[0]; $salt = array_key_exists(1, $parts) ? $parts[1] : NULL; $password_compatibility_scheme = array_key_exists(2, $parts) ? $parts[2] : NULL; } else { $password = NULL; $salt = NULL; $password_compatibility_scheme = NULL; } $matches = array(); if (array_key_exists($email_address_key, $line)) { $email_address = $line[$email_address_key]; } else { $email_address = NULL; } if (preg_match('#^([^\\s]*)\\s+\\(.*\\)$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (preg_match('#^.*\\s+<(.*)>$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (array_key_exists($dob_key, $line)) { $parts = explode('/', $line[$dob_key]); $dob_day = array_key_exists(2, $parts) ? intval($parts[2]) : NULL; $dob_month = array_key_exists(1, $parts) ? intval($parts[1]) : NULL; $dob_year = array_key_exists(0, $parts) ? intval($parts[0]) : NULL; } else { $dob_day = NULL; $dob_month = NULL; $dob_year = NULL; } $validated = array_key_exists('Validated', $line) ? strtoupper($line['Validated']) == 'YES' || $line['Validated'] == '1' || strtoupper($line['Validated']) == 'Y' || strtoupper($line['Validated']) == 'ON' ? 1 : 0 : 1; if (array_key_exists('Join time', $line)) { if (strpos($line['Join time'], '-') !== false) { $parts = explode('-', $line['Join time']); } else { $parts = explode('/', $line['Join time']); } if (!array_key_exists(1, $parts)) { $parts[1] = '1'; } if (!array_key_exists(2, $parts)) { $parts[2] = '1'; } if (strlen($parts[2]) != 4) { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[2]), intval($parts[0])); // yy(yy)-mm-dd } else { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[0]), intval($parts[2])); // dd-mm-yyyy } if ($join_time > time()) { $join_time = time(); } // Fixes MySQL out of range error that could happen } else { $join_time = NULL; } $avatar_url = array_key_exists('Avatar', $line) ? $line['Avatar'] : ''; if (!is_null($avatar_url)) { if (substr($avatar_url, 0, strlen(get_base_url() . '/')) == get_base_url() . '/') { $avatar_url = substr($avatar_url, strlen(get_base_url() . '/')); } } $signature = array_key_exists('Signature', $line) ? $line['Signature'] : ''; $is_perm_banned = array_key_exists('Banned', $line) ? strtoupper($line['Banned']) == 'YES' || $line['Banned'] == '1' || strtoupper($line['Banned']) == 'Y' || strtoupper($line['Banned']) == 'ON' ? 1 : 0 : 0; $reveal_age = array_key_exists('Reveal age', $line) ? strtoupper($line['Reveal age']) == 'YES' || $line['Reveal age'] == '1' || strtoupper($line['Reveal age']) == 'Y' || strtoupper($line['Reveal age']) == 'ON' ? 1 : 0 : 0; $language = array_key_exists('Language', $line) ? $line['Language'] : ''; $allow_emails = array_key_exists('Accept member e-mails', $line) ? strtoupper($line['Accept member e-mails']) == 'YES' || $line['Accept member e-mails'] == '1' || strtoupper($line['Accept member e-mails']) == 'Y' || strtoupper($line['Accept member e-mails']) == 'ON' ? 1 : 0 : 0; $allow_emails_from_staff = array_key_exists('Opt-in', $line) ? strtoupper($line['Opt-in']) == 'YES' || $line['Opt-in'] == '1' || strtoupper($line['Opt-in']) == 'Y' || strtoupper($line['Opt-in']) == 'ON' ? 1 : 0 : 0; $primary_group = NULL; $groups = NULL; if (array_key_exists('Usergroup', $line)) { $parts = explode('/', $line['Usergroup']); foreach ($parts as $p) { if (!array_key_exists($p, $all_groups)) { require_code('ocf_groups_action'); $g_id = ocf_make_group($p, 0, 0, 0, ''); $all_groups[$p] = $g_id; $_group_edit_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $g_id), get_module_zone('admin_ocf_groups')); $group_edit_url = $_group_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_GROUP_ADDED', escape_html($p), escape_html($group_edit_url)), 'inform'); } } $primary_group = $all_groups[$parts[0]]; unset($parts[0]); $groups = array(); foreach ($parts as $p) { $groups[] = $all_groups[$p]; } } $photo_url = array_key_exists('Photo', $line) ? $line['Photo'] : ''; if ($photo_url != '') { require_code('images'); $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . uniqid('', true) . '.png'; convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false); } else { $photo_thumb_url = ''; } $custom_fields = array(); foreach ($all_cpfs as $cpf) { $custom_fields[$cpf['id']] = array_key_exists($cpf['text_original'], $line) ? $line[$cpf['text_original']] : $cpf['cf_default']; if (!array_key_exists($cpf['text_original'], $line) && $cpf['cf_type'] == 'list') { $parts = explode($custom_fields[$cpf['id']], '|'); $custom_fields[$cpf['id']] = $parts[0]; } if ($cpf['cf_type'] == 'integer') { $custom_fields[$cpf['id']] = intval($custom_fields[$cpf['id']]); } elseif ($cpf['cf_type'] == 'tick') { $custom_fields[$cpf['id']] = strtoupper($custom_fields[$cpf['id']]) == 'YES' || strtoupper($custom_fields[$cpf['id']]) == 'Y' || strtoupper($custom_fields[$cpf['id']]) == 'ON' || $custom_fields[$cpf['id']] == '1' ? 1 : 0; } elseif ($cpf['cf_type'] == 'short_text' || $cpf['cf_type'] == 'short_trans') { $custom_fields[$cpf['id']] = substr(str_replace(chr(10), ', ', str_replace(',' . chr(10), chr(10), $custom_fields[$cpf['id']])), 0, 255); } elseif ($cpf['cf_type'] == 'long_text' || $cpf['cf_type'] == 'long_trans') { //$custom_fields[$cpf['id']]=$custom_fields[$cpf['id']]; } elseif ($cpf['cf_type'] == 'float') { if (preg_match('#^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\n(\\d\\d\\d\\d)$#', $custom_fields[$cpf['id']]) != 0) { $parts = explode(chr(10), $custom_fields[$cpf['id']], 2); $month_lookup = array('Jan' => 0.1, 'Feb' => 0.2, 'Mar' => 0.3, 'Apr' => 0.4, 'May' => 0.5, 'Jun' => 0.6, 'Jul' => 0.7, 'Aug' => 0.8, 'Sep' => 0.9, 'Oct' => 0.1, 'Nov' => 0.11, 'Dec' => 0.12); $custom_fields[$cpf['id']] = floatval($parts[1]) + $month_lookup[$parts[0]]; } else { $custom_fields[$cpf['id']] = floatval($custom_fields[$cpf['id']]); } } unset($line[$cpf['text_original']]); } foreach (array_keys($headings) as $h) { unset($line[$h]); } unset($line[$email_address_key]); unset($line[$dob_key]); foreach ($line as $h => $f) { $cf_id = ocf_make_custom_field($h, 0, '', '', 0, 0, 0, 0, 'long_text'); $_cpf_edit_url = build_url(array('page' => 'admin_ocf_customprofilefields', 'type' => '_ed', 'id' => $cf_id), get_module_zone('admin_ocf_customprofilefields')); $cpf_edit_url = $_cpf_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_CPF_ADDED', escape_html($h), escape_html($cpf_edit_url)), 'inform'); $custom_fields[$cf_id] = $f; $all_cpfs[] = array('id' => $cf_id, 'cf_default' => '', 'text_original' => $h, 'cf_type' => 'short_line'); } if ($new_member) { if (is_null($password)) { $password = $default_password; } if (is_null($salt)) { $salt = ''; } if (is_null($password_compatibility_scheme)) { $password_compatibility_scheme = ''; } $linked_id = ocf_make_member($username, $password, is_null($email_address) ? '' : $email_address, $groups, $dob_day, $dob_month, $dob_year, $custom_fields, NULL, $primary_group, $validated, $join_time, NULL, '', $avatar_url, $signature, $is_perm_banned, get_option('default_preview_guests') == '1' ? 1 : 0, $reveal_age, '', $photo_url, $photo_thumb_url, 1, 1, $language, $allow_emails, $allow_emails_from_staff, '', NULL, '', false, $password_compatibility_scheme, $salt, 1, NULL, NULL, 0, '*', ''); $all_members[$linked_id] = $username; $all_members_flipped[$username] = $linked_id; $num_added++; } else { $old_username = $GLOBALS['OCF_DRIVER']->get_member_row_field($linked_id, 'm_username'); if ($old_username == $username) { $username = NULL; } ocf_edit_member($linked_id, $email_address, NULL, $dob_day, $dob_month, $dob_year, NULL, $primary_group, $custom_fields, NULL, $reveal_age, NULL, NULL, $language, $allow_emails, $allow_emails_from_staff, $validated, $username, $password, NULL, NULL, NULL, NULL, NULL, $join_time, $avatar_url, $signature, $is_perm_banned, $photo_url, $photo_thumb_url, $salt, $password_compatibility_scheme, true); $num_edited++; } $done++; } fclose($myfile); } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } if ($done == 0) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS')), array('_SEARCH:admin_ocf_join:import_csv', do_lang_tempcode('IMPORT_MEMBER_CSV')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return inform_screen($title, do_lang_tempcode('NUM_MEMBERS_IMPORTED', escape_html(integer_format($num_added)), escape_html(integer_format($num_edited)))); }
/** * 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_custom_profile_fields($db, $table_prefix, $file_base) { $where = '*'; if (either_param('importer') == 'ipb2') { $where = 'pf_position as forder,pf_type as ftype,pf_id as fid,pf_title as ftitle,pf_desc as fdesc,pf_member_hide as fhide,pf_member_edit as fedit,pf_show_on_reg as freq'; } $rows = $db->query('SELECT ' . $where . ' FROM ' . $table_prefix . 'pfields_data'); $members = $db->query('SELECT * FROM ' . $table_prefix . 'pfields_content'); foreach ($rows as $row) { if (import_check_if_imported('cpf', strval($row['fid']))) { continue; } $type = 'short_text'; if ($row['ftype'] == 'text') { $type = 'short_text'; } elseif ($row['ftype'] == 'area') { $type = 'long_text'; } $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $row['ftitle'])); if (is_null($id_new)) { $id_new = ocf_make_custom_field($row['ftitle'], 0, $row['fdesc'], '', 1 - $row['fhide'], 1 - $row['fhide'], $row['fedit'], 0, $type, $row['freq'], 0, 0, $row['forder'], '', true); } foreach ($members as $member) { ocf_set_custom_field($member['member_id'], $id_new, @html_entity_decode($member['field_' . strval($row['fid'])], ENT_QUOTES, get_charset())); } import_id_remap_put('cpf', strval($row['fid']), $id_new); } }
/** * 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_custom_profile_fields($db, $table_prefix, $file_base) { $rows = $db->query('SELECT f.*,lang_explain FROM ' . $table_prefix . 'profile_fields f LEFT JOIN ' . $table_prefix . 'profile_lang l ON l.field_id=f.field_id'); foreach ($rows as $row) { if (import_check_if_imported('cpf', $row['field_ident'])) { continue; } $name = $row['field_name']; $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $name)); if (is_null($id_new)) { $default = $row['field_default_value']; $type = 'short_text'; switch ($row['field_type']) { case FIELD_INT: $type = 'integer'; break; case FIELD_TEXT: $type = 'long_text'; break; case FIELD_BOOL: $type = 'tick'; break; case FIELD_DROPDOWN: $type = 'list'; $values = collapse_1d_complexity('lang_default_value', $db->query('SELECT lang_default_value FROM ' . $table_prefix . 'profile_lang WHERE field_id=' . strval($row['field_id']))); $_default = $default; foreach ($values as $value) { if ($value != $default) { if ($_default == '') { $_default .= '|'; } $_default .= $value; } } $default = $_default; break; /*case FIELD_DATE: Unsupported $type='integer'; break;*/ } $id_new = ocf_make_custom_field($name, 0, is_null($row['lang_explain']) ? '' : $row['lang_explain'], $default, 1 - $row['field_hide'], 1 - $row['field_no_view'], 1 - $row['field_no_view'], 0, $type, $row['field_show_on_reg'], 0, 0, $row['field_order']); } import_id_remap_put('cpf', $row['field_ident'], $id_new); } }
/** * 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_custom_profile_fields($db, $table_prefix, $file_base) { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'profilefields'); $members = $db->query('SELECT * FROM ' . $table_prefix . 'userfields'); foreach ($rows as $row) { if (import_check_if_imported('cpf', strval($row['fid']))) { continue; } $type = 'short_text'; if ($row['type'] == 'text') { $type = 'short_text'; } elseif ($row['type'] == 'textarea') { $type = 'long_text'; } $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON f.cf_name=t.id', 'f.id', array('text_original' => $row['name'])); if (is_null($id_new)) { $id_new = ocf_make_custom_field($row['name'], 0, $row['description'], '', 1 - $row['hidden'], 1 - $row['hidden'], $row['editable'], 0, $type, $row['required'], 0, 0, $row['disporder'], '', true); } foreach ($members as $member) { $v = $member['fid' . strval($row['fid'])]; $member_id = import_id_remap_get('member', strval($member['ufid']), true); if ($v != '' && !is_null($member_id)) { ocf_set_custom_field($member_id, $id_new, $v); } } import_id_remap_put('cpf', strval($row['fid']), $id_new); } }