###############################################################################
# ExtendedProfiles.pm #
# $Date: 01.05.16 $ #
###############################################################################
# YaBB: Yet another Bulletin Board #
# Version: YaBB 2.6.12 #
# Packaged: January 5, 2016 #
# Distributed by: http://www.yabbforumsoftware.com #
# =========================================================================== #
# Copyright (c) 2000-2016 YaBB (www.yabbforumsoftware.com) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
###############################################################################
# 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 #
###############################################################################
our $VERSION = '2.6.12';
$extendedprofilespmver = 'YaBB 2.6.12 $Revision: 1914 $';
if ( $action eq 'detailedversion' ) { return 1; }
LoadLanguage('ExtendedProfiles');
$ext_spacer_hr = q~
~;
$ext_spacer_br = q~ ~;
$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 unformatted date
sub ext_get {
my (
$pusername, $fieldname, $no_parse, @ext_profile,
@options, $field, $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 q{} || $no_parse == 0 ) {
$field = ext_get_field($id);
if ( $field{'type'} eq 'text' ) {
@options = split /\^/xsm, $field{'options'};
if ( $options[3] ne q{} && $value eq q{} ) { $value = $options[3]; }
if ( $options[4] == 1 ) {
$value = ext_parse_ubbc( $value, $pusername );
}
}
elsif ( $field{'type'} eq 'text_multi' && $value ne q{} ) {
@options = split /\^/xsm, $field{'options'};
if ( $options[3] == 1 ) {
$value = ext_parse_ubbc( $value, $pusername );
}
}
elsif ( $field{'type'} eq 'select' ) {
@options = split /\^/xsm, $field{'options'};
if ( $value > $#options || $value eq q{} ) { $value = 0; }
$value = $options[$value];
}
elsif ( $field{'type'} eq 'radiobuttons' ) {
@options = split /\^/xsm, $field{'options'};
if ( $value > $#options ) { $value = 0; }
if ( !$field{'radiounselect'} && $value eq q{} ) { $value = 0; }
if ( $value ne q{} ) { $value = $options[$value]; }
}
elsif ( $field{'type'} eq 'date' && $value ne q{} ) {
@mytime = split /\//xsm, $value;
$mytime = timelocal(0,0,0, $mytime[1],$mytime[0]-1,$mytime[2]);
$mytime = timeformatcal($mytime);
$value = dtonly ($mytime);
}
elsif ( $field{'type'} eq 'checkbox' ) {
if ( $value == 1 ) { $value = $lang_ext{'true'} }
else { $value = $lang_ext{'false'} }
}
elsif ( $field{'type'} eq 'spacer' ) {
@options = split /\^/xsm, $field{'options'};
if ( $options[0] == 1 ) { $value = qq~$ext_spacer_br~; }
else { $value = qq~$ext_spacer_hr~; }
}
elsif ( $field{'type'} eq 'url' && $value ne q{} ) {
if ( $value !~ m{\Ahttp://}sm ) { $value = "http://$value"; }
}
elsif ( $field{'type'} eq 'image' && $value ne q{} ) {
@options = split /\^/xsm, $field{'options'};
if ( $options[2] ne q{} ) {
@allowed_extensions = split /\ /xsm, $options[2];
$match = 0;
foreach my $extension (@allowed_extensions) {
if ( grep { /$extension$/ism } $value ) {
$match = 1;
last;
}
}
if ( $match == 0 ) { return q{}; }
}
if ( $options[0] ne q{} && $options[0] != 0 ) {
$width = q~ width="~ . ( $options[0] + 0 ) . q~"~;
}
else { $width = q{}; }
if ( $options[1] ne q{} && $options[1] != 0 ) {
$height = q~ height="~ . ( $options[1] + 0 ) . q~"~;
}
else { $height = q{}; }
if ( $value !~ m{\Ahttp://}sm ) { $value = "http://$value"; }
$value = qq~~;
}
}
return $value;
}
# loads the (extended) profile of a user
sub ext_get_profile {
LoadUser(shift);
return;
}
# 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++;
}
return @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 my $current (@ext_prof_fields) {
( $currentname, $dummy ) = split /\|/xsm, $current;
if ( $currentname eq $fieldname ) { $id = $count; last; }
$count++;
}
return $id;
}
# returns all settings of a specific 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 /\|/xsm, $ext_prof_fields[ $field{'id'} ];
return;
}
# returns whenever the current user is allowed to view a field or not
sub ext_has_access {
my (
$allowed_users, $allowed_groups, $access, $usergroup,
$useraddgroup, $postcount, $user, @users,
$group, @groups, $groupid, $postamount
)
= (
shift, shift, 0,
${ $uid . $username }{'position'},
${ $uid . $username }{'addgroups'},
${ $uid . $username }{'postcount'}, undef,
);
if ( ( $allowed_users ne q{} ) || ( $allowed_groups ne q{} ) ) {
if ( $allowed_users ne q{} ) {
@users = split /\,/xsm, $allowed_users;
foreach my $user (@users) {
if ( $user eq $username ) { $access = 1; return $access; }
}
}
if ( $allowed_groups ne q{} ) {
# generate list of allowed groups
# example: @groups = ('Administrator', 'Moderator', 'Global Moderator', 'Post{-1}', 'NoPost{1}');
@groups = split /\s*\,\s*/xsm, $allowed_groups;
for my $group (@groups) {
# check if user is in one of these groups
if ( $group eq 'Administrator'
|| $group eq 'Moderator'
|| $group eq 'Mid Moderator'
|| $group eq 'Global Moderator' )
{
if ( $group eq $usergroup ) { $access = 1; return $access; }
}
elsif ( $group =~ m/^NoPost\{(\d+)}$/sm ) {
# check if user is on a post-independent group
$groupid = $1;
# check if group exists at all
if ( exists $NoPost{$groupid} && $groupid ne q{} ) {
# check if group id is in user position or addgroup field
if ( $usergroup eq $groupid ) {
$access = 1;
return $access;
}
foreach my $group ( split /,/xsm, $useraddgroup ) {
if ( $group eq $groupid ) {
$access = 1;
return $access;
}
}
}
}
elsif ( $group =~ m/^Post\{(\d+)}$/sm ) {
# check if user is in one of the post-depending groups...
$groupid = $1;
foreach my $postamount ( reverse sort { $a <=> $b } keys %Post ) {
if ( $postcount > $postamount ) {
# found the group the user is in
if ( $postamount eq $groupid ) {
$access = 1;
return $access;
}
}
}
}
}
}
}
else { $access = 1; }
return $access;
}
# applies UBBC code to a string
sub ext_parse_ubbc {
my ( $source, $displayname ) = @_;
my $temp = $message;
$message = $source;
require Sources::YaBBC;
$displayname = $pusername; # must be set for /me tag
DoUBBC();
ToChars($message);
$source = $message;
$message = $temp;
return $source;
}
# returns the output for the viewprofile page
sub ext_viewprofile {
my (
$pusername, @ext_profile, $field, $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[-1] );
}
foreach my $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 q{} && $previous != 1 ) {
$pre_output = $ext_pre_output;
$previous = 1;
}
# format the output dependend of the field type
if ( ( $field{'type'} eq 'text' && $value ne q{} )
|| ( $field{'type'} eq 'text_multi' && $value ne q{} )
|| ( $field{'type'} eq 'select' && $value ne q{ } )
|| ( $field{'type'} eq 'radiobuttons' && $value ne q{} )
|| ( $field{'type'} eq 'date' && $value ne q{} )
|| $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 == 0 || $field{'comment'} ne q{} )
&& $id ne $last_field_id )
{
if ( $value eq $ext_spacer_br ) {
$output .= qq~