############################################################################### # ExtendedProfiles.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Version: YaBB 3.0 Beta # # Packaged: October 05, 2010 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### $extendedprofilesplver = 'YaBB 3.0 Beta $Revision: 328 $'; if ($action eq 'detailedversion') { return 1; } ############################################################################### # This file was part of the Extended Profiles Mod which has been created by # # Michael Prager. Last modification by him: 15.11.07 # # Added to the YaBB default code on 07. September 2008 # ############################################################################### # file formats used by this code: # # username.vars - contains the additional user profile information. Number is field-id # ------------- # ... # 'ext_0',"value" # 'ext_1',"value" # 'ext_2',"value" # ... # # @ext_prof_order - contains the order in which the fields will be displayed # --------------------------- # ("name","name","name",....) # # extended_profiles_fields.txt - defines the new profile fields. Uses line number as field-id # ---------------------------- # ("name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname|radiounselect",....) # # Here are all types with their possible type-specific options. If options contain multiple entries, seperated by ^ # - text limit_len^width^is_numberic^default_value^allow_ubbc # - text_multi limit_len^rows^cols^allow_ubbc # - select option1^option2^option3... (first option is default) # - radiobuttons option1^option2^option3... (first option is default) # - spacer br_or_hr^visible_in_editprofile # - checkbox - # - date - # - emial - # - url - # - image width^height^allowed_extensions # # required_on_reg can have value 0 (disabled), 1 (required on registration) and 2 (not req. but display on reg. page anyway) # editable_by_user can have value 0 (will only show on the "admin edits" page), 1 ("edit profile" page), 2 ("contact information" page), 3 ("Options" page) and 4 ("PM Preferences" page) # allowed_extensions is a space-seperated list of file extensions, example: "jpg jpeg gif bmp png" # v_groups, p_groups, m_groups, pp_groups format: "Administrator" or "Moderator" or "Global Moderator" or NoPost{...} or Post{...} # # NOTE: use prefix "ext_" in sub-, variable- and formnames to prevent conflicts with other mods # # easy mod integration: use &ext_get($username,"fieldname") go get user's field value # ############################################################################### &LoadLanguage("ExtendedProfiles"); $ext_spacer_hr = qq~
~; $ext_spacer_br = qq~
~; $ext_max_email_length = 60; $ext_max_url_length = 100; $ext_max_image_length = 100; my %field; # outputs the value of a user's extended profile field ## USAGE: $value = ext_get("admin","my_custom_fieldname"); ## or $value_raw = ext_get("admin","my_custom_fieldname",1); ## pass the third argument if you want to get the raw content e.g. an unformated date sub ext_get { my ($pusername, $fieldname, $no_parse, @ext_profile, @options, $id, $value, $width, $height, @allowed_extensions, $extension, $match) = (shift, shift, shift); &ext_get_profile($pusername); $id = &ext_get_field_id($fieldname); $value = ${$uid.$pusername}{'ext_'.$id}; if ($no_parse eq "" || $no_parse == 0) { &ext_get_field($id); if ($field{'type'} eq "text") { @options = split(/\^/,$field{'options'}); if ($options[3] ne "" && $value eq "") { $value = $options[3]; } if ($options[4] == 1) { $value = &ext_parse_ubbc($value, $pusername); } } elsif ($field{'type'} eq "text_multi" && $value ne "") { @options = split(/\^/,$field{'options'}); if ($options[3] == 1) { $value = &ext_parse_ubbc($value, $pusername); } } elsif ($field{'type'} eq "select") { @options = split(/\^/,$field{'options'}); if ($value > $#options || $value eq "") { $value = 0; } $value = $options[$value]; } elsif ($field{'type'} eq "radiobuttons") { @options = split(/\^/,$field{'options'}); if ($value > $#options) { $value = 0; } if(!$field{'radiounselect'} && $value eq "") { $value = 0; } if($value ne "") { $value = $options[$value]; } } elsif ($field{'type'} eq "date" && $value ne "") { $value = &ext_timeformat($value); } elsif ($field{'type'} eq "checkbox") { if ($value == 1) { $value = $lang_ext{'true'} } else { $value = $lang_ext{'false'} } } elsif ($field{'type'} eq "spacer") { @options = split(/\^/,$field{'options'}); if ($options[0] == 1) { $value = qq~$ext_spacer_br~; } else { $value = qq~$ext_spacer_hr~; } } elsif ($field{'type'} eq "url" && $value ne "") { if ($value !~ m~\Ahttp://~) { $value = "http://$value"; } } elsif ($field{'type'} eq "image" && $value ne "") { @options = split(/\^/,$field{'options'}); if ($options[2] ne "") { @allowed_extensions = split(/ /,$options[2]); $match = 0; foreach $extension (@allowed_extensions){ if (grep /$extension$/i,$value) { $match = 1; last; } } if ($match == 0) { return ""; } } if ($options[0] ne "" && $options[0] != 0) { $width = " width=\"".($options[0]+0)."\""; } else { $width = ""; } if ($options[1] ne "" && $options[1] != 0) { $height = " height=\"".($options[1]+0)."\""; } else { $height = ""; } if ($value !~ m~\Ahttp://~) { $value = "http://$value"; } $value = qq~~; } } $value; } # loads the (extended) profile of a user sub ext_get_profile { &LoadUser(shift); } # returns an array of the form qw(ext_0 ext_1 ext_2 ...) sub ext_get_fields_array { my ($count, @result) = (0); foreach (@ext_prof_fields) { push(@result, "ext_$count"); $count++; } @result; } # returns the id of a field through the fieldname sub ext_get_field_id { my ($fieldname, $count, $id, $current, $currentname, $dummy) = (shift, 0); foreach $current (@ext_prof_fields) { ($currentname, $dummy) = split(/\|/, $current); if ($currentname eq $fieldname) { $id = $count; last; } $count++; } $id; } # returns all settings of a specifig field sub ext_get_field { $field{'id'} = shift; ($field{'name'}, $field{'type'}, $field{'options'}, $field{'active'}, $field{'comment'}, $field{'required_on_reg'}, $field{'visible_in_viewprofile'}, $field{'v_users'}, $field{'v_groups'}, $field{'visible_in_posts'}, $field{'p_users'}, $field{'p_groups'}, $field{'p_displayfieldname'}, $field{'visible_in_memberlist'}, $field{'m_users'}, $field{'m_groups'}, $field{'editable_by_user'}, $field{'visible_in_posts_popup'}, $field{'pp_users'}, $field{'pp_groups'}, $field{'pp_displayfieldname'}, $field{'radiounselect'}, undef) = split(/\|/, $ext_prof_fields[$field{'id'}]); } # formats a MM/DD/YYYY string to the user's prefered format, ignores time completely! sub ext_timeformat { my ($mytimeselected,$oldformat,$newformat,$mytimeformat,$newday,$newday2,$newmonth,$newmonth2,$newyear,$newshortyear,$oldmonth,$oldday,$oldyear,$newweekday,$newyearday,$newweek,$dummy,$usefullmonth); if (${$uid.$username}{'timeselect'} > 0) { $mytimeselected = ${$uid.$username}{'timeselect'}; } else { $mytimeselected = $timeselected; } $oldformat = shift; if ($oldformat eq '' || $oldformat eq "\n") { return $oldformat; } $oldmonth = substr($oldformat,0,2); $oldday = substr($oldformat,3,2); $oldyear = substr($oldformat,6,4); if ($oldformat ne '') { $newday = $oldday+0; $newmonth = $oldmonth+0; $newyear = $oldyear+0; $newshortyear = substr($newyear,2,2); if ($newmonth < 10) { $newmonth = "0$newmonth"; } if ($newday < 10 && $mytimeselected != 4) { $newday = "0$newday"; } if ($mytimeselected == 1) { qq~$newmonth/$newday/$newshortyear~; } elsif ($mytimeselected == 2) { qq~$newday.$newmonth.$newshortyear~; } elsif ($mytimeselected == 3) { qq~$newday.$newmonth.$newyear~; } elsif ($mytimeselected == 4) { $newmonth2 = $months[$newmonth - 1]; if( $newday > 10 && $newday < 20 ) { $newday2 = "$timetxt{'4'}"; } elsif( $newday % 10 == 1 ) { $newday2 = "$timetxt{'1'}"; } elsif( $newday % 10 == 2 ) { $newday2 = "$timetxt{'2'}"; } elsif( $newday % 10 == 3 ) { $newday2 = "$timetxt{'3'}"; } else{ $newday2 = "$timetxt{'4'}"; } qq~$newmonth2 $newday$newday2, $newyear~; } elsif ($mytimeselected == 5) { qq~$newmonth/$newday/$newshortyear~; } elsif ($mytimeselected == 6) { $newmonth2 = $months[$newmonth - 1]; qq~$newday. $newmonth2 $newyear~; } elsif ($mytimeselected == 7) { ($dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$newweekday,$newyearday,$dummy) = gmtime($oldformat); $newweek = int(( $newyearday + 1 - $newweekday ) / 7 )+1; $mytimeformat = ${$uid.$username}{'timeformat'}; if ($mytimeformat =~ m/MM/) {$usefullmonth = 1;} $mytimeformat =~ s/(?:\s)*\@(?:\s)*//g; $mytimeformat =~ s/HH(?:\s)?//g; $mytimeformat =~ s/mm(?:\s)?//g; $mytimeformat =~ s/ss(?:\s)?//g; $mytimeformat =~ s/://g; $mytimeformat =~ s/ww(?:\s)?//g; $mytimeformat =~ s/(.*?)(?:\s)*$/$1/g; if ($mytimeformat =~ m/\+/) { if( $newday > 10 && $newday < 20 ) { $dayext = "$timetxt{'4'}"; } elsif( $newday % 10 == 1 ) { $dayext = "$timetxt{'1'}"; } elsif( $newday % 10 == 2 ) { $dayext = "$timetxt{'2'}"; } elsif( $newday % 10 == 3 ) { $dayext = "$timetxt{'3'}"; } else { $dayext = "$timetxt{'4'}"; } } $mytimeformat =~ s/YYYY/$newyear/g; $mytimeformat =~ s/YY/$newshortyear/g; $mytimeformat =~ s/DD/$newday/g; $mytimeformat =~ s/D/$newday/g; $mytimeformat =~ s/\+/$dayext/g; if ($usefullmonth == 1){ $mytimeformat =~ s/MM/$months[$newmonth - 1]/g; } else { $mytimeformat =~ s/M/$newmonth/g; } $mytimeformat =~ s/\*//g; $mytimeformat; } } else { ''; } } # returns whenever the current user is allowed to view a field or not sub ext_has_access { my ($allowed_users, $allowed_groups, $usergroup, $useraddgroup, $postcount, $groupid) = (shift, shift, 0, ${$uid.$username}{'position'}, ${$uid.$username}{'addgroups'}, ${$uid.$username}{'postcount'}, undef); if ($allowed_users ne "" || $allowed_groups ne "") { foreach (split(/,/, $allowed_users)) { return 1 if $_ eq $username; } # example list of allowed groups: # ('Administrator', 'Moderator', 'Global Moderator', 'Post{-1}', 'NoPost{1}') foreach my $group (split(/\s*,\s*/, $allowed_groups)) { # check if user is in one of these groups if ($group eq "Administrator" || $group eq "Moderator" || $group eq "Global Moderator") { if ($usergroup eq $group) { return 1; } # check if user is on a post-independend group } elsif ($group =~ m~^NoPost{(\d+)}$~) { $groupid = $1; # check if group exists at all if ($groupid ne "" && exists $NoPost{$groupid}) { # check if group id is in user position or addgroup field if ($usergroup eq $groupid) { return 1; } foreach (split(/,/,$useraddgroup)) { if ($_ eq $groupid) { return 1; } } } # check if user is in one of the post-depending groups... } elsif ($group =~ m~^Post{(\d+)}$~) { $groupid = $1; foreach (sort { $b <=> $a } keys %Post) { if ($postcount > $_) { # found the group the user is in if ($_ eq $groupid) { return 1; } } } } } return 0; } return 1; } # applies UBBC code to a string sub ext_parse_ubbc { my ($source, $temp); ($source, $displayname, $temp) = ($_[0], $_[1], $message); $message = $source; require "$sourcedir/YaBBC.pl"; &DoUBBC; &ToChars($message); $source = $message; $message = $temp; $source; } # returns the output for the viewprofile page sub ext_viewprofile { my ($pusername, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $count, $last_field_id, $pre_output) = (shift); if ($#ext_prof_order > 0) { $last_field_id = &ext_get_field_id($ext_prof_order[$#ext_prof_order]); } foreach $fieldname (@ext_prof_order) { $id = &ext_get_field_id($fieldname); &ext_get_field($id); $value = &ext_get($pusername,$fieldname); # make sure the field is visible and the user allowed to view the current field if ($field{'visible_in_viewprofile'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'v_users'},$field{'v_groups'})) { if ($output eq "" && $previous ne 1) { $pre_output = qq~ ~; $previous = 1; } # format the output dependend of the field type if (($field{'type'} eq "text" && $value ne "") || ($field{'type'} eq "text_multi" && $value ne "") || ($field{'type'} eq "select" && $value ne " ") || ($field{'type'} eq "radiobuttons" && $value ne "") || ($field{'type'} eq "date" && $value ne "") || $field{'type'} eq "checkbox") { $output .= qq~
$field{'name'}:
$value 
~; $previous = 0; } elsif ($field{'type'} eq "spacer") { # only print spacer if the previous entry was no spacer of the same type and if this is not the last entry if (($previous eq 0 || $field{'comment'} ne "") && $id ne $last_field_id) { if ($value eq $ext_spacer_br) { $output .= qq~
$ext_spacer_br
~; $previous = 0; } else { $output .= qq~ ~; if ($field{'comment'} ne "") { $output .= qq~   $field{'comment'} ~; } else { $output .= qq~ ~; } $previous = 1; } } } elsif ($field{'type'} eq "email" && $value ne "") { $output .= qq~
$field{'name'}:
~ . &enc_eMail($img_txt{'69'},$value,'','') . qq~
~; $previous = 0; } elsif ($field{'type'} eq "url" && $value ne "") { $output .= qq~
$field{'name'}:
$value
~; $previous = 0; } elsif ($field{'type'} eq "image" && $value ne "") { $output .= qq~
$field{'name'}:
$value
~; $previous = 0; } } } # only add spacer if there there is at least one field displayed if ($output ne "") { $output = $pre_output . $output . qq~ ~; } $output; } # returns the output for the post page sub ext_viewinposts { my ($pusername, $popup, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $pre_output, $visible, $users, $groups, $displayfieldname) = (shift, shift); if ($pusername ne 'Guest') { foreach $fieldname (@ext_prof_order) { $id = &ext_get_field_id($fieldname); &ext_get_field($id); $value = &ext_get($pusername,$fieldname); if ($popup ne "") { $visible = $field{'visible_in_posts_popup'}; $users = $field{'pp_users'}; $groups = $field{'pp_groups'}; $displayfieldname = $field{'pp_displayfieldname'}; } else { $visible = $field{'visible_in_posts'}; $users = $field{'p_users'}; $groups = $field{'p_groups'}; $displayfieldname = $field{'p_displayfieldname'}; } # make sure the field is visible and the user allowed to view the current field if ($visible == 1 && $field{'active'} == 1 && &ext_has_access($users,$groups)) { if ($displayfieldname == 1) { $displayedfieldname = "$field{'name'}: "; } else { $displayedfieldname = ""; } if ($output eq "") { $output = qq~$ext_spacer_br\n~; } # format the output dependend of the field type if (($field{'type'} eq "text" && $value ne "") || ($field{'type'} eq "text_multi" && $value ne "") || ($field{'type'} eq "select" && $value ne " ") || ($field{'type'} eq "radiobuttons" && $value ne "") || ($field{'type'} eq "date" && $value ne "") || $field{'type'} eq "checkbox") { $output .= qq~$displayedfieldname$value
\n~; $previous = ""; } elsif ($field{'type'} eq "spacer") { # those tags are required to keep the doc XHTML 1.0 valid if ($previous ne "$value") { $previous = qq~$value~; $output .= $previous; } } elsif ($field{'type'} eq "email" && $value ne "") { $output .= $displayedfieldname . &enc_eMail($img_txt{'69'},$value,'','') . qq~
\n~; $previous = ""; } elsif ($field{'type'} eq "url" && $value ne "") { $output .= qq~$displayedfieldname$value
\n~; $previous = ""; } elsif ($field{'type'} eq "image" && $value ne "") { $output .= qq~$displayedfieldname$value
\n~; $previous = ""; } } } } # check if there we have any output (except spacers) at all. If so, return empty output $pre_output = $output; $pre_output =~ s~(?:\
(?:(?:$ext_spacer_hr)|(?:$ext_spacer_br)))|\n|(?:\)~~ig; if ($pre_output eq "") { $output = ""; } $output; } { # we need a "static" variable to produce unique element ids my $ext_usercount = 0; # returns the output for the post page (popup box) sub ext_viewinposts_popup { my ($pusername,$link,$output) = (shift,shift); $output = &ext_viewinposts($pusername, "popup"); $output =~ s~^$ext_spacer_br\n~~ig; if ($output ne "") { $link =~ s~$value~; } } if ($value eq "") { $value .= " "; } $output .= qq~$value\n~; $count++; } } $output; } # returns the edit mask of a field (used on registration and edit profile page) sub ext_gen_editfield { my ($id, $pusername, @ext_profile, $output, @options, $selected, $count, $required_prefix, $dayormonth, $dayormonthd, $dayormonthm, $value, $template1, $template2) = (shift, shift); &LoadLanguage("Profile"); &ext_get_field($id); # if username is obmitted, we'll generate the code for the registration page if ($pusername ne "") { $value = &ext_get($pusername,$field{'name'},1); } &FromHTML($field{'comment'}); $template1 = qq~~; if ($field{'required_on_reg'} == 1) { $template2 = " *"; } $template2 .= qq~\n~; # format the output dependend on field type my $name_id = "ext_$id"; if ($field{'type'} eq "text") { @options = split(/\^/,$field{'options'}); if ($options[0] ne "") { $options[0] = qq~ maxlength="$options[0]"~; } if ($options[1] ne "") { $options[1] = qq~ size="$options[1]"~; } if ($options[3] ne "" && $value eq "") { $options[3] = qq~ value="$options[3]"~; } else { $options[3] = qq~ value="$value"~; } $output .= $template1 . qq~~ . $template2; } elsif ($field{'type'} eq "text_multi") { @options = split(/\^/,$field{'options'}); if ($options[0]) { $field{'options'} = qq~
$lang_ext{'max_chars1'}$options[0]$lang_ext{'max_chars2'} ~; } else { $field{'options'} = ""; } if ($options[1] ne "") { $options[1] = qq~ rows="$options[1]"~; } else { $options[1] = qq~ rows="4"~; } if ($options[2] ne "") { $options[2] = qq~ cols="$options[2]"~; } else { $options[2] = qq~ cols="50"~; } $value =~ s//\n/g; $output .= $template1 . qq~$field{'options'}~ . $template2; } elsif ($field{'type'} eq "select") { $output .= $template1 . qq~~ . $template2; } elsif ($field{'type'} eq "radiobuttons") { $output .= $template1; @options = split(/\^/,$field{'options'}); if ($value > $#options) { $value = 0; } if(!$field{'radiounselect'} && $value eq "") { $value = 0; } $count = 0; foreach (@options) { if ($value ne "" && $count == $value) { $selected = qq~ id="ext_$id" checked="checked"~; } else { $selected = ""; } $output .= qq~$_\n~; $count++; } $output .= $template2; } elsif ($field{'type'} eq "date") { if ($value !~ /[0-9\/]/) { $value = ""; } @options = split(/\//,$value); $dayormonthm = qq~ $profile_txt{'564'} ~; $dayormonthd = qq~ $profile_txt{'565'} ~; if ((${$uid.$pusername}{'timeselect'} == 2 || ${$uid.$pusername}{'timeselect'} == 3 || ${$uid.$pusername}{'timeselect'} == 6) || ($timeselected == 2 || $timeselected == 3 || $timeselected == 6)) { $dayormonth=$dayormonthd.$dayormonthm; $name_id = "ext_$id\_day"; } else { $dayormonth=$dayormonthm.$dayormonthd; $name_id = "ext_$id\_month"; } $output .= $template1 . qq~$dayormonth $profile_txt{'566'} ~ . $template2; } elsif ($field{'type'} eq "checkbox") { if ($value == 1) { $value = " checked=\"checked\""; } else { $value = ""; } # we have to use a little trick here to get a value from a checkbox if it has been unchecked by adding a hidden before it $output .= $template1 . qq~~ . $template2; } elsif ($field{'type'} eq "spacer") { @options = split(/\^/,$field{'options'}); if ($options[1] == 1) { #if ($options[0] == 1) { $output .= qq~
\n~; } #else { $output .= qq~
\n~; } $output .= qq~$field{'comment'} \n~; } } elsif ($field{'type'} eq "email") { $output .= $template1 . qq~~ . $template2; } elsif ($field{'type'} eq "url") { $output .= $template1 . qq~~ . $template2; } elsif ($field{'type'} eq "image") { if ($value eq "") { $value = "http://"; } $output .= $template1 . qq~~ . $template2; } $output =~ s/