コード例 #1
0
function sp_admin_bar_do_install()
{
    global $spThisUser;
    $oldOptions = sp_get_option('sfadminsettings');
    $newOptions = sp_get_option('spAdminBar');
    if (!isset($oldOptions['sfqueue']) && empty($newOptions)) {
        $newOptions = array();
        $newOptions['dashboardposts'] = false;
        $newOptions['dbversion'] = SPABDBVERSION;
        sp_add_option('spAdminBar', $newOptions);
        $options = sp_get_member_item($spThisUser->ID, 'admin_options');
        $options['sfadminbar'] = true;
        sp_update_member_item($spThisUser->ID, 'admin_options', $options);
    } else {
        if (empty($newOptions)) {
            $newOptions = array();
            $newOptions['dashboardposts'] = $oldOptions['sfdashboardposts'];
            $newOptions['dbversion'] = SPABDBVERSION;
            sp_add_option('spAdminBar', $newOptions);
            $options = sp_get_member_item($spThisUser->ID, 'admin_options');
            $options['sfadminbar'] = true;
            sp_update_member_item($spThisUser->ID, 'admin_options', $options);
            unset($oldOptions['sfqueue']);
            unset($oldOptions['sfmodasadmin']);
            unset($oldOptions['sfshowmodposts']);
            unset($oldOptions['sfbaronly']);
            unset($oldOptions['sfdashboardposts']);
            sp_update_option('sfadminsettings', $oldOptions);
        }
    }
    # permission for bypassing akismet checks
    sp_add_auth('bypass_akismet', __('Can bypass akismet check on posts', 'spab'), 1, 0, 0, 0, 3);
    sp_activate_auth('bypass_akismet');
    # create new Akismet setting
    $akismet = sp_get_option('spAkismet');
    if (empty($akismet)) {
        sp_add_option('spAkismet', 1);
    }
    # get auto update running
    $autoup = array('spabupdate', 'sp_ahah=admin-bar-update&target=newposts');
    sp_add_sfmeta('autoupdate', 'admin', $autoup, 1);
}
コード例 #2
0
ファイル: sp-ahah-profile.php プロジェクト: bself/nuimage-wp
    while (false !== ($file = readdir($dlist))) {
        if ($file != "." && $file != "..") {
            echo '<img class="spAvatarPool" src="' . esc_url(SFAVATARPOOLURL . '/' . $file) . '" alt="" onclick="spjSelAvatar(\'' . $file . '\', \'' . esc_js("<p class=\\'spCenter\\'>" . sp_text('Avatar selected. Please save pool avatar') . "</p>") . '\'); return jQuery(\'#dialog\').dialog(\'close\');" />&nbsp;&nbsp;';
        }
    }
    echo '</p>';
    closedir($dlist);
    die;
}
if (isset($_GET['poolremove']) && ($spThisUser->ID == $userid || $spThisUser->admin)) {
    if (empty($userid)) {
        die;
    }
    $avatar = sp_get_member_item($userid, 'avatar');
    $avatar['pool'] = '';
    sp_update_member_item($userid, 'avatar', $avatar);
    echo '<strong>' . sp_text('No pool avatar currently selected') . '</strong>';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=profile&sfnonce=' . wp_create_nonce('forum-ahah') . "&action=update-display-avatar&user={$userid}";
    ?>
	<script type="text/javascript">
	jQuery(document).ready(function() {
        jQuery('#spProfileDisplayAvatar').load('<?php 
    echo $ahahURL;
    ?>
');
	})
	</script>
<?php 
    die;
}
die;
コード例 #3
0
function sp_convert_ranks()
{
    spdb_query('ALTER TABLE ' . SFMEMBERS . ' ADD (special_ranks text default NULL)');
    # convert special rank users to new column in sfmembers
    $special_rankings = sp_get_sfmeta('special_rank');
    if ($special_rankings) {
        foreach ($special_rankings as $rank) {
            if (empty($rank['meta_value']['users'])) {
                continue;
            }
            $users = $rank['meta_value']['users'];
            foreach ($users as $user) {
                $memberData = sp_get_member_item($user, 'special_ranks');
                $memberData[] = $rank['meta_key'];
                sp_update_member_item($user, 'special_ranks', $memberData);
            }
            unset($rank['meta_value']['users']);
            sp_update_sfmeta('special_rank', $rank['meta_key'], $rank['meta_value'], $rank['meta_id'], 1);
        }
    }
}
コード例 #4
0
function sp_destroy_users_newposts($forumid = '')
{
    global $spThisUser;
    if (empty($forumid) || empty($spThisUser->newposts['topics'])) {
        $newPostList = array();
        $newPostList['topics'] = array();
        $newPostList['forums'] = array();
        $spThisUser->newposts = '';
    } else {
        $newPostList = $spThisUser->newposts;
        foreach ($spThisUser->newposts['forums'] as $index => $forum) {
            if ($forum == $forumid) {
                unset($newPostList['topics'][$index]);
                unset($newPostList['forums'][$index]);
            }
        }
        $newPostList['topics'] = array_values($newPostList['topics']);
        $newPostList['forums'] = array_values($newPostList['forums']);
        $spThisUser->newposts = $newPostList;
    }
    sp_update_member_item($spThisUser->ID, 'newposts', $newPostList);
    sp_update_member_item($spThisUser->ID, 'checktime', 0);
    sp_set_server_timezone();
    $spThisUser->checktime = sp_apply_timezone(time(), 'mysql');
}
コード例 #5
0
function sp_UpdateProfile()
{
    global $spGlobals, $spThisUser;
    # make sure nonce is there
    check_admin_referer('forum-profile', 'forum-profile');
    $message = array();
    # dont update forum if its locked down
    if ($spGlobals['lockdown']) {
        $message['type'] = 'error';
        $message['text'] = sp_text('This forum is currently locked - access is read only - profile not updated');
        return $message;
    }
    # do we have a form to update?
    if (isset($_GET['form'])) {
        $thisForm = sp_esc_str($_GET['form']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid form');
        return $message;
    }
    # do we have an actual user to update?
    if (isset($_GET['userid'])) {
        $thisUser = sp_esc_int($_GET['userid']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    # Check the user ID for current user of admin edit
    if ($thisUser != $spThisUser->ID && !$spThisUser->admin) {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
        $pass1 = $pass2 = '';
        if (isset($_POST['pass1'])) {
            $pass1 = $_POST['pass1'];
        }
        if (isset($_POST['pass2'])) {
            $pass2 = $_POST['pass2'];
        }
        if (empty($pass1) || empty($pass2) || $pass1 != $pass2) {
            $message['type'] = 'error';
            $message['text'] = sp_text('Cannot save profile until password has been changed');
            return $message;
        }
    }
    # form save filter
    $thisForm = apply_filters('sph_profile_save_thisForm', $thisForm);
    # valid save attempt, so lets process the save
    switch ($thisForm) {
        case 'show-memberships':
            # update memberships
            # any usergroup removals?
            if (isset($_POST['usergroup_leave'])) {
                foreach ($_POST['usergroup_leave'] as $membership) {
                    sp_remove_membership(sp_esc_str($membership), $thisUser);
                }
            }
            # any usergroup joins?
            if (isset($_POST['usergroup_join'])) {
                foreach ($_POST['usergroup_join'] as $membership) {
                    sp_add_membership(sp_esc_int($membership), $thisUser);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileMemberships', $message, $thisUser);
            # output update message
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Memberships updated');
            }
            break;
        case 'account-settings':
            # update account settings
            # check for password update
            $pass1 = $pass2 = '';
            if (isset($_POST['pass1'])) {
                $pass1 = $_POST['pass1'];
            }
            if (isset($_POST['pass2'])) {
                $pass2 = $_POST['pass2'];
            }
            if (!empty($pass1) || !empty($pass2)) {
                if ($pass1 != $pass2) {
                    $message['type'] = 'error';
                    $message['text'] = sp_text('Please enter the same password in the two password fields');
                    return $message;
                } else {
                    # update the password
                    $user = new stdClass();
                    $user->ID = (int) $thisUser;
                    $user->user_pass = $pass1;
                    wp_update_user(get_object_vars($user));
                    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
                        delete_user_meta($spThisUser->ID, 'sp_change_pw');
                    }
                }
            }
            # now check the email is valid and unique
            $update = apply_filters('sph_ProfileUserEmailUpdate', true);
            if ($update) {
                $curEmail = sp_filter_email_save($_POST['curemail']);
                $email = sp_filter_email_save($_POST['email']);
                if ($email != $curEmail) {
                    if (empty($email)) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Please enter a valid email address');
                        return $message;
                    } elseif (($owner_id = email_exists($email)) && $owner_id != $thisUser) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('The email address is already registered. Please choose another one');
                        return $message;
                    }
                    # save new email address
                    $sql = 'UPDATE ' . SFUSERS . " SET user_email='{$email}' WHERE ID=" . $thisUser;
                    spdb_query($sql);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSettings', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Account settings updated');
            }
            break;
        case 'edit-profile':
            # update profile settings
            # validate any username change
            $update = apply_filters('sph_ProfileUserDisplayNameUpdate', true);
            if ($update) {
                $spProfile = sp_get_option('sfprofile');
                if ($spProfile['nameformat'] || $spThisUser->admin) {
                    $display_name = !empty($_POST['display_name']) ? trim($_POST['display_name']) : spdb_table(SFUSERS, "ID={$thisUser}", 'user_login');
                    $display_name = sp_filter_name_save($display_name);
                    # make sure display name isnt already used
                    if ($_POST['oldname'] != $display_name) {
                        $records = spdb_table(SFMEMBERS, "display_name='{$display_name}'");
                        if ($records) {
                            foreach ($records as $record) {
                                if ($record->user_id != $thisUser) {
                                    $message['type'] = 'error';
                                    $message['text'] = $display_name . ' ' . sp_text('is already in use - please choose a different display name');
                                    return $message;
                                }
                            }
                        }
                        # validate display name
                        $errors = new WP_Error();
                        $user = new stdClass();
                        $user->display_name = $display_name;
                        sp_validate_display_name($errors, true, $user);
                        if ($errors->get_error_codes()) {
                            $message['type'] = 'error';
                            $message['text'] = sp_text('The display name you have chosen is not allowed on this site');
                            return $message;
                        }
                        # now save the display name
                        sp_update_member_item($thisUser, 'display_name', $display_name);
                        # Update new users list with changed display name
                        sp_update_newuser_name(sp_filter_name_save($_POST['oldname']), $display_name);
                        # do we need to sync display name with wp?
                        $options = sp_get_member_item($thisUser, 'user_options');
                        if ($options['namesync']) {
                            spdb_query('UPDATE ' . SFUSERS . ' SET display_name="' . $display_name . '" WHERE ID=' . $thisUser);
                        }
                    }
                }
            }
            # save the url
            $update = apply_filters('sph_ProfileUserWebsiteUpdate', true);
            if ($update) {
                $url = sp_filter_url_save($_POST['website']);
                $sql = 'UPDATE ' . SFUSERS . ' SET user_url="' . $url . '" WHERE ID=' . $thisUser;
                spdb_query($sql);
            }
            # update first name, last name, location and biorgraphy
            $update = apply_filters('sph_ProfileUserFirstNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'first_name', sp_filter_name_save(trim($_POST['first_name'])));
            }
            $update = apply_filters('sph_ProfileUserLastNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'last_name', sp_filter_name_save(trim($_POST['last_name'])));
            }
            $update = apply_filters('sph_ProfileUserLocationUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'location', sp_filter_title_save(trim($_POST['location'])));
            }
            $update = apply_filters('sph_ProfileUserBiographyUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'description', sp_filter_save_kses($_POST['description']));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileProfile', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Profile settings updated');
            }
            break;
        case 'edit-identities':
            # update identity settings
            # update the user identities
            $update = apply_filters('sph_ProfileUserAIMUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'aim', sp_filter_title_save(trim($_POST['aim'])));
            }
            $update = apply_filters('sph_ProfileUserYahooUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'yim', sp_filter_title_save(trim($_POST['yim'])));
            }
            $update = apply_filters('sph_ProfileUserGoogleUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'jabber', sp_filter_title_save(trim($_POST['jabber'])));
            }
            $update = apply_filters('sph_ProfileUserMSNUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'msn', sp_filter_title_save(trim($_POST['msn'])));
            }
            $update = apply_filters('sph_ProfileUserICQUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'icq', sp_filter_title_save(trim($_POST['icq'])));
            }
            $update = apply_filters('sph_ProfileUserSkypeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'skype', sp_filter_title_save(trim($_POST['skype'])));
            }
            $update = apply_filters('sph_ProfileUserFacebookUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'facebook', sp_filter_title_save(trim($_POST['facebook'])));
            }
            $update = apply_filters('sph_ProfileUserMySpaceUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'myspace', sp_filter_title_save(trim($_POST['myspace'])));
            }
            $update = apply_filters('sph_ProfileUserTwitterUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'twitter', sp_filter_title_save(trim($_POST['twitter'])));
            }
            $update = apply_filters('sph_ProfileUserLinkedInUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'linkedin', sp_filter_title_save(trim($_POST['linkedin'])));
            }
            $update = apply_filters('sph_ProfileUserYouTubeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'youtube', sp_filter_title_save(trim($_POST['youtube'])));
            }
            $update = apply_filters('sph_ProfileUserGooglePlusUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'googleplus', sp_filter_title_save(trim($_POST['googleplus'])));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileIdentities', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Identities updated');
            }
            break;
        case 'avatar-upload':
            # upload avatar
            # did we get an avatar to upload?
            if (empty($_FILES['avatar-upload']['name'])) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar filename was empty');
                return $message;
            }
            # Verify the file extension
            global $spPaths;
            $uploaddir = SF_STORE_DIR . '/' . $spPaths['avatars'] . '/';
            $filename = basename($_FILES['avatar-upload']['name']);
            $path = pathinfo($filename);
            $ext = strtolower($path['extension']);
            if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, only JPG, JPEG, PNG, or GIF files are allowed');
                return $message;
            }
            # check image file mimetype
            $mimetype = 0;
            $mimetype = exif_imagetype($_FILES['avatar-upload']['tmp_name']);
            if (empty($mimetype) || $mimetype == 0 || $mimetype > 3) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file is an invalid format');
                return $message;
            }
            # make sure file extension and mime type actually match
            if ($mimetype == 1 && $ext != 'gif' || $mimetype == 2 && ($ext != 'jpg' && $ext != 'jpeg') || $mimetype == 3 && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the file mime type does not match file extension');
                return $message;
            }
            # Clean up file name just in case
            $filename = date('U') . sp_filter_filename_save(basename($_FILES['avatar-upload']['name']));
            $uploadfile = $uploaddir . $filename;
            # check for existence
            if (file_exists($uploadfile)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file already exists');
                return $message;
            }
            # check file size against limit if provided
            $spAvatars = sp_get_option('sfavatars');
            if ($_FILES['avatar-upload']['size'] > $spAvatars['sfavatarfilesize']) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file exceeds the maximum allowed size');
                return $message;
            }
            # valid avatar, so try moving the uploaded file to the avatar storage directory
            if (move_uploaded_file($_FILES['avatar-upload']['tmp_name'], $uploadfile)) {
                @chmod("{$uploadfile}", 0644);
                # do we need to resize?
                $sfavatars = sp_get_option('sfavatars');
                if ($sfavatars['sfavatarresize']) {
                    $editor = wp_get_image_editor($uploadfile);
                    if (is_wp_error($editor)) {
                        @unlink($uploadfile);
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Sorry, there was a problem resizing the avatar');
                        return $message;
                    } else {
                        $editor->resize($sfavatars['sfavatarsize'], $sfavatars['sfavatarsize'], true);
                        $imageinfo = $editor->save($uploadfile);
                        $filename = $imageinfo['file'];
                    }
                }
                # update member avatar data
                $avatar = sp_get_member_item($thisUser, 'avatar');
                $avatar['uploaded'] = $filename;
                sp_update_member_item($thisUser, 'avatar', $avatar);
            } else {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file could not be moved to the avatar storage location');
                return $message;
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarUpload', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Uploaded avatar updated');
            }
            break;
        case 'avatar-pool':
            # pool avatar
            # get pool avatar name
            $filename = sp_filter_filename_save($_POST['spPoolAvatar']);
            # error if no pool avatar provided
            if (empty($filename)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, you must select a pool avatar before trying to save it');
                return $message;
            }
            # save the pool avatar
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['pool'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarPool', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Pool avatar updated');
            }
            break;
        case 'avatar-remote':
            # remote avatar
            # get remote avatar name
            $filename = sp_filter_url_save($_POST['spAvatarRemote']);
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['remote'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarRemote', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Remote avatar updated');
            }
            break;
        case 'edit-signature':
            # save signature
            # Check if maxmium links has been exceeded
            $numLinks = substr_count($_POST['postitem'], '</a>');
            $spFilters = sp_get_option('sffilters');
            if (!sp_get_auth('create_links', 'global', $thisUser) && $numLinks > 0 && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('You are not allowed to put links in signatures');
                return $message;
            }
            if (sp_get_auth('create_links', 'global', $thisUser) && $spFilters['sfmaxlinks'] != 0 && $numLinks > $spFilters['sfmaxlinks'] && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Maximum number of allowed links exceeded in signature') . ': ' . $spFilters['sfmaxlinks'] . ' ' . sp_text('allowed');
                return $message;
            }
            //			$sig = esc_sql(sp_filter_save_kses(trim($_POST['postitem'])));
            $sig = sp_filter_content_save($_POST['postitem'], 'edit');
            sp_update_member_item($thisUser, 'signature', $sig);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSignature', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Signature updated');
            }
            break;
        case 'edit-photos':
            # save photos
            $photos = array();
            $spProfileOptions = sp_get_option('sfprofile');
            for ($x = 0; $x < $spProfileOptions['photosmax']; $x++) {
                $photos[$x] = sp_filter_url_save($_POST['photo' . $x]);
            }
            update_user_meta($thisUser, 'photos', $photos);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePhotos', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Photos updated');
            }
            break;
        case 'edit-global-options':
            # save global options
            $options = sp_get_member_item($thisUser, 'user_options');
            $options['hidestatus'] = isset($_POST['hidestatus']) ? true : false;
            $update = apply_filters('sph_ProfileUserSyncNameUpdate', true);
            if ($update) {
                $options['namesync'] = isset($_POST['namesync']) ? true : false;
            }
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileGlobalOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Global options updated');
            }
            break;
        case 'edit-posting-options':
            # save posting options
            $update = apply_filters('sph_ProfileUserEditorUpdate', true);
            if ($update) {
                $options = sp_get_member_item($thisUser, 'user_options');
                if (isset($_POST['editor'])) {
                    $options['editor'] = sp_esc_int($_POST['editor']);
                }
                sp_update_member_item($thisUser, 'user_options', $options);
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePostingOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Posting options updated');
            }
            break;
        case 'edit-display-options':
            # save display options
            $options = sp_get_member_item($thisUser, 'user_options');
            if (isset($_POST['timezone'])) {
                if (preg_match('/^UTC[+-]/', $_POST['timezone'])) {
                    # correct for manual UTC offets
                    $userOffset = preg_replace('/UTC\\+?/', '', $_POST['timezone']) * 3600;
                } else {
                    # get timezone offset for user
                    $date_time_zone_selected = new DateTimeZone(sp_esc_str($_POST['timezone']));
                    $userOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # get timezone offset for server based on wp settings
                $wptz = get_option('timezone_string');
                if (empty($wptz)) {
                    $serverOffset = get_option('gmt_offset');
                } else {
                    $date_time_zone_selected = new DateTimeZone($wptz);
                    $serverOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # calculate time offset between user and server
                $options['timezone'] = (int) round(($userOffset - $serverOffset) / 3600, 2);
                $options['timezone_string'] = sp_esc_str($_POST['timezone']);
            } else {
                $options['timezone'] = 0;
                $options['timezone_string'] = 'UTC';
            }
            if (isset($_POST['unreadposts'])) {
                $sfcontrols = sp_get_option('sfcontrols');
                $options['unreadposts'] = is_numeric($_POST['unreadposts']) ? max(min(sp_esc_int($_POST['unreadposts']), $sfcontrols['sfmaxunreadposts']), 0) : $sfcontrols['sfdefunreadposts'];
            }
            $options['topicASC'] = isset($_POST['topicASC']);
            $options['postDESC'] = isset($_POST['postDESC']);
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileDisplayOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Display options updated');
            }
            break;
        default:
            break;
    }
    # let plugins do their thing on success
    $message = apply_filters('sph_ProfileFormSave_' . $thisForm, $message, $thisUser, $thisForm);
    do_action('sph_UpdateProfile', $thisUser, $thisForm);
    # reset the plugin_data just in case
    sp_reset_member_plugindata($thisUser);
    # done saving - return the messages
    return $message;
}
function sp_setup_page_type()
{
    global $spVars, $spGlobals, $spThisUser, $spBootCache, $spStatus;
    if ($spStatus != 'ok') {
        return;
    }
    if (isset($spGlobals['pagetypedone']) && $spGlobals['pagetypedone'] == true) {
        return;
    }
    $spGlobals['pagetypedone'] = true;
    # If user has made no posts yet optionaly load the profile form
    $pageview = '';
    $goProfile = false;
    if ($spThisUser->member && $spThisUser->posts == -1) {
        sp_update_member_item($spThisUser->ID, 'posts', 0);
        # reset posts to 0 on first visit
        # do new users need to visit profile first?
        $sfprofile = sp_get_option('sfprofile');
        $goProfile = $sfprofile['firstvisit'];
    }
    # do we need to redirec to profile for pw change or first visit?
    if ($spThisUser->member && ($goProfile || isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw)) {
        $spVars['member'] = (int) $spThisUser->ID;
        $pageview = 'profileedit';
        $spVars['forumslug'] = '';
        $spVars['topicslug'] = '';
    }
    if ($pageview == '') {
        if (!empty($spVars['feed'])) {
            $pageview = 'feed';
        } else {
            if (!empty($spVars['forumslug'])) {
                $pageview = 'forum';
            } else {
                if (!empty($spVars['profile'])) {
                    if ($spVars['profile'] == 'edit') {
                        $pageview = 'profileedit';
                    }
                    if ($spVars['profile'] == 'show') {
                        $pageview = 'profileshow';
                    }
                } else {
                    if (!empty($spVars['newposts'])) {
                        $pageview = 'newposts';
                    } else {
                        if (!empty($spVars['members'])) {
                            $pageview = 'members';
                        } else {
                            $pageview = 'group';
                            # and if a single group id is passed load ot ointo spVars
                            if (isset($_GET['group'])) {
                                $spVars['singlegroupid'] = sp_esc_int($_GET['group']);
                            }
                            # Check if single forum only is on
                            if (isset($spGlobals['display']['forums']['singleforum']) && $spGlobals['display']['forums']['singleforum']) {
                                $fid = sp_single_forum_user();
                                if ($fid) {
                                    $cforum = spdb_table(SFFORUMS, "forum_id={$fid}", 'row');
                                    $spVars['forumid'] = $fid;
                                    $spVars['forumslug'] = $cforum->forum_slug;
                                    $spVars['forumname'] = $cforum->forum_name;
                                    $spBootCache = '';
                                    $pageview = 'forum';
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!empty($spVars['topicslug'])) {
            $pageview = 'topic';
        }
        if (isset($_GET['search']) && !empty($spVars['searchvalue'])) {
            $pageview = 'search';
        }
    }
    # profile via ssl if doing ssl logins
    if ($pageview == 'profileedit' && force_ssl_admin() && !is_ssl()) {
        if (sp_profile_tab_active('profile') && sp_profile_menu_active('account-settings')) {
            if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) {
                wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
                exit;
            } else {
                wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
                exit;
            }
        }
    }
    $spVars['pageview'] = apply_filters('sph_pageview', $pageview);
}
コード例 #7
0
 function saveData()
 {
     global $spVars, $spGlobals;
     $this->abort = false;
     $this->newpost['action'] = $this->action;
     # make the entire class object available for modification before saving
     # warning:  note the passing by reference.  other end could wreak havoc
     do_action_ref_array('sph_new_post_pre_save', array(&$this));
     # Write the topic if needed
     if ($this->action == 'topic') {
         $this->newpost = apply_filters('sph_new_topic_pre_data_saved', $this->newpost);
         $spdb = new spdbComplex();
         $spdb->table = SFTOPICS;
         $spdb->fields = array('topic_name', 'topic_slug', 'topic_date', 'forum_id', 'topic_status', 'topic_pinned', 'user_id');
         $spdb->data = array($this->newpost['topicname'], $this->newpost['topicslug'], $this->newpost['postdate'], $this->newpost['forumid'], $this->newpost['topicstatus'], $this->newpost['topicpinned'], $this->newpost['userid']);
         $spdb = apply_filters('sph_new_topic_data', $spdb);
         $this->newpost['db'] = $spdb->insert();
         if ($this->newpost['db'] == true) {
             $this->newpost['topicid'] = $spVars['insertid'];
             $this->newpost = apply_filters('sph_new_topic_data_saved', $this->newpost);
         } else {
             $this->abort = true;
             $this->message = sp_text('Unable to save new topic record');
             return;
         }
         # failsafe: check the topic slug and if empty use the topic id
         if (empty($this->newpost['topicslug'])) {
             $this->newpost['topicslug'] = 'topic-' . $this->newpost['topicid'];
             spdb_query('UPDATE ' . SFTOPICS . " SET topic_slug='" . $this->newpost['topicslug'] . "' WHERE topic_id=" . $this->newpost['topicid']);
         }
     }
     # Write the post
     # Double check forum id is correct - it has been known for a topic to have just been moved!
     $this->newpost['forumid'] = spdb_table(SFTOPICS, 'topic_id=' . $this->newpost['topicid'], 'forum_id');
     # Get post count in topic to enable post index setting
     $index = spdb_count(SFPOSTS, 'topic_id = ' . $this->newpost['topicid']);
     $index++;
     $this->newpost['postindex'] = $index;
     # if topic lock set in post reply update topic (post only)
     if ($this->action == 'post' && $this->newpost['topicstatus']) {
         spdb_query('UPDATE ' . SFTOPICS . ' SET topic_status=1 WHERE topic_id=' . $this->newpost['topicid']);
     }
     $this->newpost = apply_filters('sph_new_post_pre_data_saved', $this->newpost);
     $spdb = new spdbComplex();
     $spdb->table = SFPOSTS;
     $spdb->fields = array('post_content', 'post_date', 'topic_id', 'forum_id', 'user_id', 'guest_name', 'guest_email', 'post_pinned', 'post_index', 'post_status', 'poster_ip', 'source');
     $spdb->data = array($this->newpost['postcontent'], $this->newpost['postdate'], $this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['userid'], $this->newpost['guestname'], $this->newpost['guestemail'], $this->newpost['postpinned'], $this->newpost['postindex'], $this->newpost['poststatus'], $this->newpost['posterip'], $this->newpost['source']);
     $spdb = apply_filters('sph_new_post_data', $spdb);
     $this->newpost['db'] = $spdb->insert();
     if ($this->newpost['db'] == true) {
         $this->newpost['postid'] = $spVars['insertid'];
         $this->newpost = apply_filters('sph_new_post_data_saved', $this->newpost);
     } else {
         $this->abort = true;
         $this->message = sp_text('Unable to save new post message');
         return;
     }
     # Update the timestamp of the last post
     sp_update_option('poststamp', $this->newpost['postdate']);
     $this->returnURL = sp_build_url($this->newpost['forumslug'], $this->newpost['topicslug'], 0, $this->newpost['postid']);
     if ($this->newpost['poststatus']) {
         $this->newpost['submsg'] .= ' - ' . sp_text('placed in moderation') . ' ';
     }
     # Now for all that post-save processing required
     if ($this->guest) {
         $sfguests = sp_get_option('sfguests');
         if ($sfguests['storecookie']) {
             sp_write_guest_cookie($this->newpost['guestname'], $this->newpost['guestemail']);
         }
     } else {
         $postcount = sp_get_member_item($this->newpost['userid'], 'posts');
         $postcount++;
         sp_update_member_item($this->newpost['userid'], 'posts', $postcount);
         # see if postcount qualifies member for new user group membership
         # get rankings information
         if (!$this->admin) {
             # ignore for admins as they dont belong to user groups
             global $spGlobals;
             if (!empty($spGlobals['forum_rank'])) {
                 $index = 0;
                 foreach ($spGlobals['forum_rank'] as $x => $info) {
                     $rankdata['title'][$index] = $x;
                     $rankdata['posts'][$index] = $info['posts'];
                     $rankdata['usergroup'][$index] = $info['usergroup'];
                     $index++;
                 }
                 # sort rankings
                 array_multisort($rankdata['posts'], SORT_ASC, $rankdata['title'], $rankdata['usergroup']);
                 # check for new ranking
                 for ($x = 0; $x < count($rankdata['posts']); $x++) {
                     if ($postcount <= $rankdata['posts'][$x] && !empty($rankdata['usergroup'][$x])) {
                         # if a user group is tied to forum rank add member to the user group
                         if ($rankdata['usergroup'][$x] != 'none') {
                             sp_add_membership($rankdata['usergroup'][$x], $this->newpost['userid']);
                         }
                         break;
                         # only update highest rank
                     }
                 }
             }
         }
     }
     # set new url for email
     $this->newpost['url'] = $this->returnURL;
     # allow plugins to add to post message
     $this->newpost['submsg'] = apply_filters('sph_post_message', $this->newpost['submsg'], $this->newpost);
     # add to or remove from admins new post queue
     if ($this->admin || $this->moderator) {
         # remove topic from waiting...
         sp_remove_from_waiting(false, $this->newpost['topicid']);
     } else {
         # add topic to waiting
         sp_add_to_waiting($this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['postid'], $this->newpost['userid']);
     }
     # if a new post remove topic from the users new post list if in it
     if ($this->action == 'post') {
         sp_remove_users_newposts($this->newpost['topicid'], $this->newpost['userid']);
     }
     # do we need to approve any posts in moderation in this topic?
     if ($this->admin && $spGlobals['admin']['sfadminapprove'] || $this->moderator && $spGlobals['admin']['sfmoderapprove']) {
         sp_approve_post(true, 0, $this->newpost['topicid'], false, $this->newpost['forumid']);
     }
     # if post in moderatiuon then add entry to notices
     if ($this->newpost['poststatus'] != 0) {
         $nData = array();
         $nData['user_id'] = $this->newpost['userid'];
         $nData['guest_email'] = $this->newpost['guestemail'];
         $nData['post_id'] = $this->newpost['postid'];
         $nData['link'] = $this->newpost['url'];
         $nData['link_text'] = $this->newpost['topicname'];
         $nData['message'] = sp_text('Your post is awaiting moderation in the topic');
         $nData['expires'] = time() + 30 * 24 * 60 * 60;
         # 30 days; 24 hours; 60 mins; 60secs
         sp_add_notice($nData);
     }
     # Add this new item to the new tpic/post cache
     $meta = sp_get_sfmeta_key('topic_cache', 'new');
     $cacheSize = sp_get_option('topic_cache');
     $a = array();
     $a[LISTFORUM] = (int) $this->newpost['forumid'];
     $a[LISTTOPIC] = (int) $this->newpost['topicid'];
     $a[LISTPOST] = (int) $this->newpost['postid'];
     $a[LISTSTATUS] = (int) $this->newpost['poststatus'];
     if (isset($spGlobals['topic_cache']['new']) && !empty($spGlobals['topic_cache']['new'])) {
         array_unshift($spGlobals['topic_cache']['new'], $a);
         if (count($spGlobals['topic_cache']['new']) > $cacheSize) {
             array_pop($spGlobals['topic_cache']['new']);
         }
     }
     sp_update_sfmeta('topic_cache', 'new', $spGlobals['topic_cache']['new'], $meta, true);
     # remove group level caches to accommodate new post
     spdb_query('DELETE FROM ' . SFCACHE . " WHERE cache_id LIKE '%*group'");
     # save post in cache for flood control
     sp_add_cache('floodcontrol', time() + sp_get_option('floodcontrol'));
     # Update forum, topic and post index data
     sp_build_post_index($this->newpost['topicid']);
     sp_build_forum_index($this->newpost['forumid']);
     # send out email notifications
     sp_email_notifications($this->newpost);
     # one final filter - just in case
     do_action_ref_array('sph_post_new_completed', array(&$this));
     # and a final action hook
     do_action('sph_new_post', $this->newpost);
     do_action('sph_post_create', $this->newpost);
 }
コード例 #8
0
function sp_destroy_users_newposts()
{
    global $spThisUser;
    $newPostList = array();
    $newPostList['topics'] = array();
    $newPostList['forums'] = array();
    sp_update_member_item($spThisUser->ID, 'newposts', $newPostList);
    sp_update_member_item($spThisUser->ID, 'checktime', 0);
    sp_set_server_timezone();
    $spThisUser->checktime = sp_apply_timezone(time(), 'mysql');
    $spThisUser->newposts = '';
}
コード例 #9
0
function sp_set_last_visited($userid)
{
    global $spThisUser;
    # before setting last visit check and save timezone difference just to be sure.
    $opts = sp_get_member_item($userid, 'user_options');
    if (!empty($opts['timezone_string'])) {
        if (preg_match('/^UTC[ \\t+-]/', $opts['timezone_string'])) {
            # correct for manual UTC offets
            $userOffset = preg_replace('/UTC\\+?/', '', $opts['timezone_string']) * 3600;
        } else {
            # get timezone offset for user
            $date_time_zone_selected = new DateTimeZone(sp_esc_str($opts['timezone_string']));
            $userOffset = timezone_offset_get($date_time_zone_selected, date_create());
        }
        $wptz = get_option('timezone_string');
        if (empty($wptz)) {
            $serverOffset = get_option('gmt_offset');
        } else {
            $date_time_zone_selected = new DateTimeZone($wptz);
            $serverOffset = timezone_offset_get($date_time_zone_selected, date_create());
        }
        # calculate time offset between user and server
        $ntz = (int) round(($userOffset - $serverOffset) / 3600, 2);
        if ($opts['timezone'] != $ntz) {
            $opts['timezone'] = $ntz;
            $spThisUser->timezone = $ntz;
            sp_update_member_item($userid, 'user_options', $opts);
            sp_update_member_item($userid, 'checktime', 0);
        }
    }
    # Now set the last visit date/time
    sp_update_member_item($userid, 'lastvisit', 0);
}
コード例 #10
0
function sp_perform_install($phase, $subphase = 0)
{
    global $current_user, $spVars;
    switch ($phase) {
        case 1:
            # create an array of installed tables to save for uninstall. plugins will add theirs to be sure we get good cleanup
            $tables = array();
            # sfauthcats table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHCATS . ' (
					authcat_id tinyint(4) NOT NULL auto_increment,
					authcat_name varchar(50) NOT NULL,
					authcat_slug varchar(50) NOT NULL,
					authcat_desc tinytext,
					PRIMARY KEY	 (authcat_id),
					KEY authcat_slug_idx (authcat_slug)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHCATS;
            # sfauths table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHS . " (\n\t\t\t\t\tauth_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tauth_name varchar(50) NOT NULL,\n\t\t\t\t\tauth_desc text,\n\t\t\t\t\tactive smallint(1) NOT NULL default '0',\n\t\t\t\t\tignored smallint(1) NOT NULL default '0',\n\t\t\t\t\tenabling smallint(1) NOT NULL default '0',\n\t\t\t\t\tadmin_negate smallint(1) NOT NULL default '0',\n\t\t\t\t\tauth_cat bigint(20) NOT NULL default '1',\n\t\t\t\t\twarning tinytext,\n\t\t\t\t\tPRIMARY KEY\t (auth_id),\n\t\t\t\t\tKEY auth_name_idx (auth_name)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHS;
            # the cache table (5.4.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFCACHE . " (\n\t\t\t\t\tcache_id varchar(40) NOT NULL DEFAULT '',\n\t\t\t\t\tcache_out bigint(6) DEFAULT NULL,\n\t\t\t\t\tcache mediumtext,\n\t\t\t\t\tPRIMARY KEY (cache_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFCACHE;
            # sfdefpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFDEFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFDEFPERMISSIONS;
            # error log table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFERRORLOG . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\terror_date datetime NOT NULL,\n\t\t\t\t\terror_type varchar(10) NOT NULL,\n\t\t\t\t\terror_cat varchar(13) NOT NULL default 'spaErrOther',\n\t\t\t\t\tkeycheck varchar(45),\n\t\t\t\t\terror_count smallint(6),\n\t\t\t\t\terror_text text,\n\t\t\t\t\tPRIMARY KEY (id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFERRORLOG;
            # sfforums table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFFORUMS . " (\n\t\t\t\t\tforum_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_name varchar(200) NOT NULL,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_seq int(4) default NULL,\n\t\t\t\t\tforum_desc text default NULL,\n\t\t\t\t\tforum_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_disabled smallint(1) NOT NULL default '0',\n\t\t\t\t\tforum_slug varchar(200) NOT NULL,\n\t\t\t\t\tforum_rss text default NULL,\n\t\t\t\t\tforum_icon varchar(50) default NULL,\n\t\t\t\t\tforum_icon_new varchar(50) default NULL,\n\t\t\t\t\tforum_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_new varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_pinned varchar(50) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\ttopic_count mediumint(8) default '0',\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tforum_rss_private smallint(1) NOT NULL default '0',\n\t\t\t\t\tparent bigint(20) NOT NULL default '0',\n\t\t\t\t\tchildren text default NULL,\n\t\t\t\t\tforum_message text,\n\t\t\t\t\tkeywords varchar(256) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (forum_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY forum_slug_idx (forum_slug),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFFORUMS;
            # sfgroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFGROUPS . ' (
					group_id bigint(20) NOT NULL auto_increment,
					group_name text,
					group_seq int(4) default NULL,
					group_desc text,
					group_rss text,
					group_icon varchar(50) default NULL,
					group_message text,
					PRIMARY KEY	 (group_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFGROUPS;
            # install log table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOG . ' (
					id bigint(20) NOT NULL auto_increment,
					user_id bigint(20) NOT NULL,
					install_date date NOT NULL,
					release_type varchar(20),
					version varchar(10) NOT NULL,
					build int(6) NOT NULL,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOG;
            # install log section table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOGMETA . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					version varchar(10) DEFAULT NULL,
					log_data tinytext,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOGMETA;
            # sfmembers table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERS . " (\n\t\t\t\t\tuser_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tdisplay_name varchar(100) default NULL,\n\t\t\t\t\tmoderator smallint(1) NOT NULL default '0',\n\t\t\t\t\tavatar longtext default NULL,\n\t\t\t\t\tsignature text default NULL,\n\t\t\t\t\tposts int(4) default NULL,\n\t\t\t\t\tlastvisit datetime default NULL,\n\t\t\t\t\tnewposts longtext,\n\t\t\t\t\tchecktime datetime default NULL,\n\t\t\t\t\tadmin smallint(1) NOT NULL default '0',\n\t\t\t\t\tfeedkey varchar(36) default NULL,\n\t\t\t\t\tadmin_options longtext default NULL,\n\t\t\t\t\tuser_options longtext default NULL,\n\t\t\t\t\tauths longtext default NULL,\n\t\t\t\t\tmemberships longtext default NULL,\n\t\t\t\t\tplugin_data longtext default NULL,\n\t\t\t\t\tPRIMARY KEY\t (user_id),\n\t\t\t\t\tKEY admin_idx (admin),\n\t\t\t\t\tKEY moderator_idx (moderator)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERS;
            # sfmemberships table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERSHIPS . " (\n\t\t\t\t\tmembership_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (membership_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERSHIPS;
            # sfmeta table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMETA . " (\n\t\t\t\t\tmeta_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tmeta_type varchar(20) NOT NULL,\n\t\t\t\t\tmeta_key varchar(100) default NULL,\n\t\t\t\t\tmeta_value longtext,\n\t\t\t\t\tautoload tinyint(2) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY (meta_id),\n\t\t\t\t\tKEY meta_type_idx (meta_type),\n\t\t\t\t\tKEY autoload_idx (autoload)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMETA;
            # user notices table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFNOTICES . " (\n\t\t\t\t\tnotice_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tlink varchar(255) default NULL,\n\t\t\t\t\tlink_text varchar(200) default NULL,\n\t\t\t\t\tmessage varchar(255) NOT NULL default '',\n\t\t\t\t\texpires int(4) default NULL,\n\t\t\t\t\tPRIMARY KEY (notice_id),\n\t\t\t\t\tKEY user_id_idx (user_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFNOTICES;
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFOPTIONS . " (\n\t\t\t\t\toption_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t\toption_name varchar(64) NOT NULL default '',\n\t\t\t\t\toption_value longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY (option_name),\n\t\t\t\t\tKEY option_id_idx (option_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFOPTIONS;
            # sfpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPERMISSIONS;
            # sfposts table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPOSTS . " (\n\t\t\t\t\tpost_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tpost_content longtext,\n\t\t\t\t\tpost_date datetime NOT NULL,\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tguest_name varchar(50) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_status int(4) NOT NULL default '0',\n\t\t\t\t\tpost_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\tpost_index mediumint(8) default '0',\n\t\t\t\t\tpost_edit mediumtext,\n\t\t\t\t\tposter_ip varchar(39) NOT NULL default '0.0.0.0',\n\t\t\t\t\tcomment_id bigint(20) default NULL,\n\t\t\t\t\tsource smallint(1) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (post_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY guest_name_idx (guest_name),\n\t\t\t\t\tKEY comment_id_idx (comment_id),\n\t\t\t\t\tKEY post_date_idx (post_date)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPOSTS;
            # sfroles table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFROLES . " (\n\t\t\t\t\trole_id mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t\trole_name varchar(50) NOT NULL default '',\n\t\t\t\t\trole_desc varchar(150) NOT NULL default '',\n\t\t\t\t\trole_auths longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY\t (role_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFROLES;
            # special ranks (5.3.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFSPECIALRANKS . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) default NULL,
					special_rank varchar(100),
					PRIMARY KEY (id),
					KEY user_id_idx (user_id),
					KEY special_rank_idx (special_rank)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFSPECIALRANKS;
            # sftopics table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTOPICS . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttopic_name varchar(200) NOT NULL,\n\t\t\t\t\ttopic_date datetime NOT NULL,\n\t\t\t\t\ttopic_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\ttopic_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\ttopic_opened bigint(20) NOT NULL default '0',\n\t\t\t\t\ttopic_slug varchar(200) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tPRIMARY KEY\t(topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_slug_idx (topic_slug),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTOPICS;
            # sftrack table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTRACK . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttrackuserid bigint(20) default '0',\n\t\t\t\t\ttrackname varchar(50) NOT NULL,\n\t\t\t\t\ttrackdate datetime NOT NULL,\n\t\t\t\t\tforum_id bigint(20) default NULL,\n\t\t\t\t\ttopic_id bigint(20) default NULL,\n\t\t\t\t\tpageview varchar(50) NOT NULL,\n\t\t\t\t\tnotification varchar(1024) default NULL,\n\t\t\t\t\tdevice char(1) default 'D',\n\t\t\t\t\tdisplay varchar(255) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (id),\n\t\t\t\t\tKEY trackuserid_idx (trackuserid),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTRACK;
            # user activity (5.3.2 - in preparation)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERACTIVITY . ' (
					id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) NOT NULL,
					type_id smallint(4) NOT NULL,
					item_id bigint(20) NOT NULL,
					meta_id bigint(20) DEFAULT NULL,
					PRIMARY KEY (id),
					KEY type_id_idx (type_id),
					KEY user_id_idx (user_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERACTIVITY;
            # sfusergroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERGROUPS . " (\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tusergroup_name text NOT NULL,\n\t\t\t\t\tusergroup_desc text default NULL,\n\t\t\t\t\tusergroup_badge varchar(50) default NULL,\n\t\t\t\t\tusergroup_join tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_is_moderator tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERGROUPS;
            # sfwaiting table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFWAITING . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tpost_count int(4) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tuser_id bigint(20) unsigned default '0',\n\t\t\t\t\tPRIMARY KEY\t (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFWAITING;
            # now save off installed tables
            sp_add_option('installed_tables', $tables);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Tables created') . '</h5>';
            break;
        case 2:
            # populate auths
            spa_setup_auth_cats();
            spa_setup_auths();
            # set up the default permissions/roles
            spa_setup_permissions();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Permission data built') . '</h5>';
            break;
        case 3:
            # Create default 'Guest' user group data
            $guests = spa_create_usergroup_row('Guests', 'Default Usergroup for guests of the forum', '', '0', '0', false);
            # Create default 'Members' user group data
            $members = spa_create_usergroup_row('Members', 'Default Usergroup for registered users of the forum', '', '0', '0', false);
            # Create default 'Moderators' user group data
            $moderators = spa_create_usergroup_row('Moderators', 'Default Usergroup for moderators of the forum', '', '0', '1', false);
            # Create default user groups
            sp_add_sfmeta('default usergroup', 'sfguests', $guests);
            # default usergroup for guests
            sp_add_sfmeta('default usergroup', 'sfmembers', $members);
            # default usergroup for members
            sp_create_usergroup_meta($members);
            # create default usergroups for existing wp roles
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Usergroup data built') . '</h5>';
            break;
        case 4:
            $page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => $current_user->ID, 'ping_status' => 'closed', 'comment_status' => 'closed', 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'post_content' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_title' => 'Forum', 'page_template' => 'default');
            $page_id = wp_insert_post($page_args);
            $page = spdb_table(SFWPPOSTS, "ID={$page_id}", 'row');
            sp_add_option('sfslug', $page->post_name);
            # Update the guid for the new page
            $guid = get_permalink($page_id);
            spdb_query('UPDATE ' . SFWPPOSTS . " SET guid='{$guid}' WHERE ID={$page_id}");
            sp_add_option('sfpage', $page_id);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Forum page created') . '</h5>';
            break;
        case 5:
            # Create Base Option Records (V1)
            sp_add_option('sfuninstall', false);
            sp_add_option('sfdates', get_option('date_format'));
            sp_add_option('sftimes', get_option('time_format'));
            sp_add_option('sfpermalink', get_permalink(sp_get_option('sfpage')));
            sp_add_option('sflockdown', false);
            $rankdata['posts'] = 2;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'New Member', $rankdata, 1);
            $rankdata['posts'] = 1000;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'Member', $rankdata, 1);
            $sfimage = array();
            $sfimage['enlarge'] = true;
            $sfimage['process'] = true;
            $sfimage['thumbsize'] = 100;
            $sfimage['style'] = 'left';
            $sfimage['constrain'] = true;
            $sfimage['forceclear'] = false;
            sp_add_option('sfimage', $sfimage);
            sp_add_option('sfbadwords', '');
            sp_add_option('sfreplacementwords', '');
            sp_add_option('sfeditormsg', '');
            $sfmail = array();
            $sfmail['sfmailsender'] = get_bloginfo('name');
            $admin_email = get_bloginfo('admin_email');
            $comp = explode('@', $admin_email);
            $sfmail['sfmailfrom'] = $comp[0];
            $sfmail['sfmaildomain'] = $comp[1];
            $sfmail['sfmailuse'] = true;
            sp_add_option('sfmail', $sfmail);
            $sfmail = array();
            $sfmail['sfusespfreg'] = true;
            $sfmail['sfnewusersubject'] = 'Welcome to %BLOGNAME%';
            $sfmail['sfnewusertext'] = 'Welcome %USERNAME% to %BLOGNAME% %NEWLINE%Please find below your login details: %NEWLINE%Username: %USERNAME% %NEWLINE%Password: %PASSWORD% %NEWLINE%%LOGINURL%';
            sp_add_option('sfnewusermail', $sfmail);
            $sfpostmsg = array();
            $sfpostmsg['sfpostmsgtext'] = '';
            $sfpostmsg['sfpostmsgtopic'] = false;
            $sfpostmsg['sfpostmsgpost'] = false;
            sp_add_option('sfpostmsg', $sfpostmsg);
            $sflogin = array();
            $sflogin['sfregmath'] = true;
            $sflogin['sfloginurl'] = sp_url();
            $sflogin['sflogouturl'] = sp_url();
            $sflogin['sfregisterurl'] = '';
            $sflogin['sfloginemailurl'] = esc_url(wp_login_url());
            $sflogin['sptimeout'] = 20;
            sp_add_option('sflogin', $sflogin);
            $sfadminsettings = array();
            $sfadminsettings['sfdashboardstats'] = true;
            $sfadminsettings['sfadminapprove'] = false;
            $sfadminsettings['sfmoderapprove'] = false;
            $sfadminsettings['editnotice'] = true;
            $sfadminsettings['movenotice'] = true;
            sp_add_option('sfadminsettings', $sfadminsettings);
            $sfauto = array();
            $sfauto['sfautoupdate'] = false;
            $sfauto['sfautotime'] = 300;
            sp_add_option('sfauto', $sfauto);
            $sffilters = array();
            $sffilters['sfnofollow'] = false;
            $sffilters['sftarget'] = true;
            $sffilters['sfurlchars'] = 40;
            $sffilters['sffilterpre'] = false;
            $sffilters['sfmaxlinks'] = 0;
            $sffilters['sfnolinksmsg'] = "<b>** you do not have permission to see this link **</b>";
            $sffilters['sfdupemember'] = 0;
            $sffilters['sfdupeguest'] = 0;
            $sffilters['sfmaxsmileys'] = 0;
            sp_add_option('sffilters', $sffilters);
            $sfseo = array();
            $sfseo['sfseo_overwrite'] = false;
            $sfseo['sfseo_blogname'] = false;
            $sfseo['sfseo_pagename'] = false;
            $sfseo['sfseo_homepage'] = true;
            $sfseo['sfseo_topic'] = true;
            $sfseo['sfseo_forum'] = true;
            $sfseo['sfseo_noforum'] = false;
            $sfseo['sfseo_page'] = true;
            $sfseo['sfseo_sep'] = '|';
            sp_add_option('sfseo', $sfseo);
            $sfsigimagesize = array();
            $sfsigimagesize['sfsigwidth'] = 0;
            $sfsigimagesize['sfsigheight'] = 0;
            sp_add_option('sfsigimagesize', $sfsigimagesize);
            # (V4.1.0)
            $sfmembersopt = array();
            $sfmembersopt['sfcheckformember'] = true;
            $sfmembersopt['sfsinglemembership'] = false;
            $sfmembersopt['sfhidestatus'] = true;
            sp_add_option('sfmemberopts', $sfmembersopt);
            $sfcontrols = array();
            $sfcontrols['showtopcount'] = 10;
            $sfcontrols['shownewcount'] = 10;
            $sfcontrols['sfdefunreadposts'] = 50;
            $sfcontrols['sfusersunread'] = false;
            $sfcontrols['sfmaxunreadposts'] = 50;
            sp_add_option('sfcontrols', $sfcontrols);
            $sfblock = array();
            $sfblock['blockadmin'] = false;
            $sfblock['blockprofile'] = false;
            $sfblock['blockroles'] = 'administrator';
            $sfblock['blockredirect'] = get_permalink(sp_get_option('sfpage'));
            sp_add_option('sfblockadmin', $sfblock);
            $sfmetatags = array();
            $sfmetatags['sfdescr'] = '';
            $sfmetatags['sfdescruse'] = 1;
            $sfmetatags['sfusekeywords'] = 2;
            $sfmetatags['sfkeywords'] = 'forum';
            sp_add_option('sfmetatags', $sfmetatags);
            # display array
            $sfdisplay = array();
            $sfdisplay['pagetitle']['notitle'] = false;
            $sfdisplay['pagetitle']['banner'] = '';
            $sfdisplay['forums']['singleforum'] = false;
            $sfdisplay['topics']['perpage'] = 12;
            $sfdisplay['topics']['sortnewtop'] = true;
            $sfdisplay['posts']['perpage'] = 20;
            $sfdisplay['posts']['sortdesc'] = false;
            sp_add_option('sfdisplay', $sfdisplay);
            sp_add_sfmeta('sort_order', 'forum', '', 1);
            sp_add_sfmeta('sort_order', 'topic', '', 1);
            # guest settings
            $sfguests = array();
            $sfguests['reqemail'] = true;
            $sfguests['storecookie'] = true;
            sp_add_option('sfguests', $sfguests);
            # profile management
            $sfprofile = array();
            $sfprofile['nameformat'] = true;
            $sfprofile['fixeddisplayformat'] = 0;
            $sfprofile['namelink'] = 2;
            $sfprofile['displaymode'] = 1;
            $sfprofile['displaypage'] = '';
            $sfprofile['displayquery'] = '';
            $sfprofile['formmode'] = 1;
            $sfprofile['formpage'] = '';
            $sfprofile['formquery'] = '';
            $sfprofile['photosmax'] = 0;
            $sfprofile['photoswidth'] = 0;
            $sfprofile['photosheight'] = 0;
            $sfprofile['firstvisit'] = true;
            $sfprofile['forcepw'] = false;
            sp_add_option('sfprofile', $sfprofile);
            # avatar options
            $sfavatars = array();
            $sfavatars['sfshowavatars'] = true;
            $sfavatars['sfavataruploads'] = true;
            $sfavatars['sfavatarpool'] = false;
            $sfavatars['sfavatarremote'] = false;
            $sfavatars['sfgmaxrating'] = 1;
            $sfavatars['sfavatarsize'] = 50;
            $sfavatars['sfavatarresize'] = true;
            $sfavatars['sfavatarresizequality'] = 90;
            $sfavatars['sfavatarfilesize'] = 10240;
            $sfavatars['sfavatarpriority'] = array(0, 2, 3, 1, 4, 5);
            # gravatar, upload, spf, wp, pool, remote
            sp_add_option('sfavatars', $sfavatars);
            # RSS stuff
            $sfrss = array();
            $sfrss['sfrsscount'] = 15;
            $sfrss['sfrsswords'] = 0;
            $sfrss['sfrsstopicname'] = false;
            $sfrss['sfrssfeedkey'] = true;
            sp_add_option('sfrss', $sfrss);
            sp_add_option('sffiltershortcodes', true);
            sp_add_option('sfwplistpages', true);
            # Script in footer
            sp_add_option('sfscriptfoot', false);
            # the_content filter options
            sp_add_option('sfinloop', false);
            sp_add_option('sfmultiplecontent', true);
            sp_add_option('sfwpheadbypass', false);
            sp_add_option('spwptexturize', false);
            sp_add_option('spheaderspace', 0);
            # auto update stuff in sfmeta
            $autoup = array('spjUserUpdate', 'sp_ahah=autoupdate&amp;sfnonce=' . wp_create_nonce('forum-ahah'));
            sp_add_sfmeta('autoupdate', 'user', $autoup, 1);
            # Set up unique key
            $uKey = substr(chr(rand(97, 122)) . md5(time()), 0, 10);
            sp_add_option('spukey', $uKey);
            # default theme
            $theme = array();
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            sp_add_option('sp_current_theme', $theme);
            $theme = array();
            $theme['active'] = false;
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            $theme['usetemplate'] = false;
            $theme['pagetemplate'] = '';
            $theme['notitle'] = true;
            sp_add_option('sp_mobile_theme', $theme);
            sp_add_option('sp_tablet_theme', $theme);
            sp_add_option('account-name', '');
            sp_add_option('display-name', '');
            sp_add_option('guest-name', '');
            # Create smileys Record
            sp_build_base_smileys();
            # set up daily transient clean up cron
            wp_schedule_event(time(), 'daily', 'sph_transient_cleanup_cron');
            # profile tabs
            spa_new_profile_setup();
            # build the list of moderators per forum
            sp_update_forum_moderators();
            # set up hourly stats generation
            sp_add_option('sp_stats_interval', 3600);
            wp_schedule_event(time(), 'hourly', 'sph_stats_cron');
            # set up weekly news processing
            wp_schedule_event(time(), 'sp_news_interval', 'sph_news_cron');
            sp_add_sfmeta('news', 'news', array('id' => -999.999, 'show' => 0, 'news' => esc_sql(spa_text('Latest Simple Press News will be shown here'))));
            # create initial last post time stamp
            sp_add_option('poststamp', current_time('mysql'));
            # setup mysql search sfmeta values (5.2.0)
            $s = array();
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_min_word_len'");
            empty($v->Value) ? $s['min'] = 4 : ($s['min'] = $v->Value);
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_max_word_len'");
            empty($v->Value) ? $s['max'] = 84 : ($s['max'] = $v->Value);
            sp_add_sfmeta('mysql', 'search', $s, true);
            # combined css and js cache fles
            sp_add_option('combinecss', false);
            sp_add_option('combinejs', false);
            sp_add_option('post_count_delete', false);
            $spError = array();
            $spError['spErrorLogOff'] = false;
            $spError['spNoticesOff'] = false;
            sp_update_option('spErrorOptions', $spError);
            # new posts/topic cached array
            sp_add_sfmeta('topic_cache', 'new', '', true);
            sp_add_option('topic_cache', 200);
            sp_add_option('floodcontrol', 10);
            sp_add_option('captcha-value', time());
            sp_add_option('editpostdays', 7);
            sp_create_inspectors();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Default forum options created') . '</h5>';
            break;
        case 6:
            # Create sp-resources folder for the current install - does not include themes, plugins or languages
            $perms = fileperms(SF_STORE_DIR);
            $owners = stat(SF_STORE_DIR);
            if ($perms === false) {
                $perms = 0755;
            }
            $basepath = '';
            if (is_multisite()) {
                # construct multisite storage directory structure and create if necessary
                $basepath .= 'blogs.dir/' . SFBLOGID;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/files';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/';
            }
            $basepath .= 'sp-resources';
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
            }
            # hive off the basepath for later use - use wp options
            add_option('sp_storage1', SF_STORE_DIR . '/' . $basepath);
            # Did it get created?
            $success = true;
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                $success = false;
            }
            sp_add_option('spStorageInstall1', $success);
            # Is the ownership correct?
            $ownersgood = false;
            if ($success) {
                $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                    $ownersgood = true;
                } else {
                    @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                    @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    }
                }
            }
            sp_add_option('spOwnersInstall1', $ownersgood);
            $basepath .= '/';
            $sfconfig = array();
            $sfconfig['avatars'] = $basepath . 'forum-avatars';
            $sfconfig['avatar-pool'] = $basepath . 'forum-avatar-pool';
            $sfconfig['smileys'] = $basepath . 'forum-smileys';
            $sfconfig['ranks'] = $basepath . 'forum-badges';
            $sfconfig['custom-icons'] = $basepath . 'forum-custom-icons';
            $sfconfig['cache'] = $basepath . 'forum-cache';
            # Create sp-resources folder and themes, plugins and languages folders
            # if not multisite, just add to sp-resource created above
            # if multisite try to use set up of main blog (id 1) or create in wp-content if main blog does not have SP installed
            global $wpdb;
            if (is_multisite()) {
                $basepath = 'sp-resources';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                # Did it get created?
                $success = true;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    $success = false;
                }
                sp_add_option('spStorageInstall2', $success);
                # Is the ownership correct?
                $ownersgood = false;
                if ($success) {
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    } else {
                        @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                        @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                        $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                        if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                            $ownersgood = true;
                        }
                    }
                }
                sp_add_option('spOwnersInstall2', $ownersgood);
                add_option('sp_storage2', SF_STORE_DIR . '/' . $basepath);
                $basepath .= '/';
                if ($wpdb->blogid == 1) {
                    $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                    $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                    $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                    $sfconfig['plugins'] = $basepath . 'forum-plugins';
                    $sfconfig['themes'] = $basepath . 'forum-themes';
                } else {
                    $blog_prefix = $wpdb->get_blog_prefix(1);
                    $row = $wpdb->get_row("SELECT * FROM {$blog_prefix}sfoptions WHERE option_name 'sfconfig'");
                    if (is_object($row)) {
                        $mainConfig = unserialize($row->option_value);
                        $sfconfig['language-sp'] = $mainConfig['language-sp'];
                        $sfconfig['language-sp-plugins'] = $mainConfig['language-sp-plugins'];
                        $sfconfig['language-sp-themes'] = $mainConfig['language-sp-themes'];
                        $sfconfig['plugins'] = $mainConfig['plugins'];
                        $sfconfig['themes'] = $mainConfig['themes'];
                    } else {
                        $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                        $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                        $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                        $sfconfig['plugins'] = $basepath . 'forum-plugins';
                        $sfconfig['themes'] = $basepath . 'forum-themes';
                    }
                }
            } else {
                add_option('sp_storage2', get_option('sp_storage1'));
                sp_add_option('spStorageInstall2', true);
                sp_add_option('spOwnersInstall2', true);
                $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                $sfconfig['plugins'] = $basepath . 'forum-plugins';
                $sfconfig['themes'] = $basepath . 'forum-themes';
            }
            sp_add_option('sfconfig', $sfconfig);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($success) {
                spa_etext('Storage location created') . '</h5>';
            } else {
                spa_etext('Storage location creation failed') . '</h5>';
            }
            break;
        case 7:
            # Move and extract zip install archives
            # first do stuff that could be in blogs.dir for multisite
            $successCopy1 = false;
            $successExtract1 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part1.zip';
            $extract_to = get_option('sp_storage1');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part1.zip')) {
                $successCopy1 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part1.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract1 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip1', $successCopy1);
            sp_add_option('spUnZip1', $successExtract1);
            # now do stuff that could should not be blogs.dir for multisite
            $successCopy2 = false;
            $successExtract2 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part2.zip';
            $extract_to = get_option('sp_storage2');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part2.zip')) {
                $successCopy2 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part2.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract2 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip2', $successCopy2);
            sp_add_option('spUnZip2', $successExtract2);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($successCopy1 && $successExtract1 && $successCopy2 && $successExtract2) {
                spa_etext('Resources created') . '</h5>';
            } elseif (!$successCopy1 || !$successCopy2) {
                spa_etext('Resources file failed to copy') . '</h5>';
            } elseif (!$successExtract1 || !$successExtract2) {
                spa_etext('Resources file failed to unzip');
                echo ' - ' . $archive->error_string . '</h5>';
            }
            break;
        case 8:
            # CREATE MEMBERS TABLE ---------------------------
            sp_install_members_table($subphase);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            echo spa_text('Members data created for existing users') . ' ' . (($subphase - 1) * 200 + 1) . ' - ' . $subphase * 200 . '</h5>';
            break;
        case 9:
            # add our caps
            sp_add_caps();
            # grant spf capabilities to installer
            $user = new WP_User($current_user->ID);
            $user->add_cap('SPF Manage Options');
            $user->add_cap('SPF Manage Forums');
            $user->add_cap('SPF Manage User Groups');
            $user->add_cap('SPF Manage Permissions');
            $user->add_cap('SPF Manage Components');
            $user->add_cap('SPF Manage Admins');
            $user->add_cap('SPF Manage Users');
            $user->add_cap('SPF Manage Profiles');
            $user->add_cap('SPF Manage Toolbox');
            $user->add_cap('SPF Manage Plugins');
            $user->add_cap('SPF Manage Themes');
            $user->add_cap('SPF Manage Integration');
            sp_update_member_item($current_user->ID, 'admin', 1);
            # admin your option defaults
            $sfadminoptions = array();
            $sfadminoptions['sfnotify'] = false;
            $sfadminoptions['notify-edited'] = true;
            sp_update_member_item($current_user->ID, 'admin_options', $sfadminoptions);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Admin permission data built') . '</h5>';
            break;
        case 10:
            # UPDATE VERSION/BUILD NUMBERS -------------------------
            sp_log_event(SPRELEASE, SPVERSION, SPBUILD);
            # Lets update permalink and force a rewrite rules flush
            sp_update_permalink(true);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Version number updated') . '</h5>';
            break;
        case 11:
            # REPORTS ERRORS IF COPY OR UNZIP FAILED ---------------
            $sCreate1 = sp_get_option('spStorageInstall1');
            $sCreate2 = sp_get_option('spStorageInstall2');
            $sOwners1 = sp_get_option('spOwnersInstall1');
            $sOwners2 = sp_get_option('spOwnersInstall2');
            $sCopy1 = sp_get_option('spCopyZip1');
            $sUnzip1 = sp_get_option('spUnZip1');
            $sCopy2 = sp_get_option('spCopyZip2');
            $sUnzip2 = sp_get_option('spUnZip2');
            if ($sCreate1 && $sCreate2 && $sCopy1 && $sUnzip1 && $sCopy2 && $sUnzip2 && $sOwners1 && $sOwners2) {
                echo '<h5>' . spa_text('The installation has been completed') . '</h5>';
            } else {
                $image = "<img src='" . SF_PLUGIN_URL . "/sp-startup/install/resources/images/important.png' alt='' style='float:left;padding: 5px 5px 20px 0;' />";
                echo '<h5>';
                spa_etext('YOU WILL NEED TO PERFORM THE FOLLOWING TASKS TO ALLOW SIMPLE:PRESS TO WORK CORRECTLY');
                echo '</h5><br />';
                if (!$sCreate1) {
                    echo $image . '<p style="margin-top:0">[';
                    spa_etext('Storage location part 1 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage1');
                    echo '</p>';
                } else {
                    if (!$sOwners1) {
                        echo $image . '<p>[';
                        spa_etext('Storage location part 1 ownership failed');
                        echo '] - ';
                        echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage1');
                        echo '</p>';
                    }
                }
                if (!$sCreate2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                } elseif (!$sOwners2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 ownership failed');
                    echo '] - ';
                    echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sCopy1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 1 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part1.zip' to the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sCopy2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part2.zip' to the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sUnzip1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part1.zip' in the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sUnzip2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part2.zip' in the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
            }
            delete_option('sfInstallID');
            delete_option('sp_storage1');
            delete_option('sp_storage2');
            sp_delete_option('spStorageInstall1');
            sp_delete_option('spStorageInstall2');
            sp_delete_option('spOwnersInstall1');
            sp_delete_option('spOwnersInstall2');
            sp_delete_option('spCopyZip1');
            sp_delete_option('spCopyZip2');
            sp_delete_option('spUnZip1');
            sp_delete_option('spUnZip2');
            break;
    }
}
コード例 #11
0
function sp_update_member_moderator_flag($userid)
{
    $ugs = sp_get_user_memberships($userid);
    if ($ugs) {
        foreach ($ugs as $ug) {
            $mod = spdb_table(SFUSERGROUPS, "usergroup_id={$ug['usergroup_id']}", 'usergroup_is_moderator');
            if ($mod) {
                sp_update_member_item($userid, 'moderator', 1);
                # see if our forum moderator list changed
                sp_update_forum_moderators();
                return;
            }
        }
    }
    # not a moderator if we get here
    sp_update_member_item($userid, 'moderator', 0);
}
コード例 #12
0
            sp_reset_auths();
        }
    }
    #remove old create links global option
    unset($sffilters['sfallowlinks']);
    sp_update_option('sffilters', $sffilters);
    sp_response($section);
}
$section = 9176;
if ($build < $section) {
    $users = spdb_select('set', 'SELECT user_id, admin_options FROM ' . SFMEMBERS . ' WHERE admin=1 OR moderator=1');
    if ($users) {
        foreach ($users as $user) {
            $options = unserialize($user->admin_options);
            $options['notify-edited'] = true;
            sp_update_member_item($user->user_id, 'admin_options', $options);
        }
    }
    sp_response($section);
}
$section = 9216;
if ($build < $section) {
    # Add default to poster_ip in sfposts
    spdb_query('ALTER TABLE ' . SFPOSTS . " CHANGE poster_ip poster_ip VARCHAR(39) NOT NULL DEFAULT '0.0.0.0'");
    sp_response($section);
}
$section = 9285;
if ($build < $section) {
    sp_add_option('combinecss', false);
    sp_add_option('combinejs', false);
    sp_response($section);
コード例 #13
0
function spa_save_admins_newadmin_data()
{
    check_admin_referer('forum-adminform_sfaddadmins', 'forum-adminform_sfaddadmins');
    if (isset($_POST['member_id'])) {
        $newadmins = array_unique($_POST['member_id']);
    } else {
        $mess = spa_text('No users selected!');
        return $mess;
    }
    if (isset($_POST['add-opts'])) {
        $opts = $_POST['add-opts'];
    } else {
        $opts = '';
    }
    if (isset($_POST['add-forums'])) {
        $forums = $_POST['add-forums'];
    } else {
        $forums = '';
    }
    if (isset($_POST['add-ugs'])) {
        $ugs = $_POST['add-ugs'];
    } else {
        $ugs = '';
    }
    if (isset($_POST['add-perms'])) {
        $perms = $_POST['add-perms'];
    } else {
        $perms = '';
    }
    if (isset($_POST['add-comps'])) {
        $comps = $_POST['add-comps'];
    } else {
        $comps = '';
    }
    if (isset($_POST['add-users'])) {
        $users = $_POST['add-users'];
    } else {
        $users = '';
    }
    if (isset($_POST['add-profiles'])) {
        $profiles = $_POST['add-profiles'];
    } else {
        $profiles = '';
    }
    if (isset($_POST['add-admins'])) {
        $admins = $_POST['add-admins'];
    } else {
        $admins = '';
    }
    if (isset($_POST['add-tools'])) {
        $tools = $_POST['add-tools'];
    } else {
        $tools = '';
    }
    if (isset($_POST['add-plugins'])) {
        $plugins = $_POST['add-plugins'];
    } else {
        $plugins = '';
    }
    if (isset($_POST['add-themes'])) {
        $themes = $_POST['add-themes'];
    } else {
        $themes = '';
    }
    if (isset($_POST['add-integration'])) {
        $integration = $_POST['add-integration'];
    } else {
        $integration = '';
    }
    $added = false;
    for ($index = 0; $index < count($newadmins); $index++) {
        # get user index and sanitize
        $uid = intval($newadmins[$index]);
        $user = new WP_User(sp_esc_int($uid));
        if ($opts == 'on') {
            $user->add_cap('SPF Manage Options');
        }
        if ($forums == 'on') {
            $user->add_cap('SPF Manage Forums');
        }
        if ($ugs == 'on') {
            $user->add_cap('SPF Manage User Groups');
        }
        if ($perms == 'on') {
            $user->add_cap('SPF Manage Permissions');
        }
        if ($comps == 'on') {
            $user->add_cap('SPF Manage Components');
        }
        if ($users == 'on') {
            $user->add_cap('SPF Manage Users');
        }
        if ($profiles == 'on') {
            $user->add_cap('SPF Manage Profiles');
        }
        if ($admins == 'on') {
            $user->add_cap('SPF Manage Admins');
        }
        if ($tools == 'on') {
            $user->add_cap('SPF Manage Toolbox');
        }
        if ($plugins == 'on') {
            $user->add_cap('SPF Manage Plugins');
        }
        if ($themes == 'on') {
            $user->add_cap('SPF Manage Themes');
        }
        if ($integration == 'on') {
            $user->add_cap('SPF Manage Integration');
        }
        $newadmin = $opts == 'on' || $forums == 'on' || $ugs == 'on' || $perms == 'on' || $comps == 'on' || $users == 'on' || $profiles == 'on' || $admins == 'on' || $tools == 'on' || $plugins == 'on' || $themes == 'on' || $integration == 'on';
        $newadmin = apply_filters('sph_admin_caps_new', $newadmin, $user);
        if ($newadmin) {
            $added = true;
            # flag as admin with remove moderator flag
            sp_update_member_item($uid, 'admin', 1);
            sp_update_member_item($uid, 'moderator', 0);
            # admin default options
            $sfadminoptions = array();
            $sfadminoptions['sfnotify'] = false;
            $sfadminoptions['notify-edited'] = false;
            $sfadminoptions['bypasslogout'] = false;
            sp_update_member_item($uid, 'admin_options', $sfadminoptions);
            # remove any usergroup permissions
            spdb_query('DELETE FROM ' . SFMEMBERSHIPS . " WHERE user_id={$uid}");
            do_action('sph_admin_new_admin', $uid);
        }
        # reset auths and memberships for new admins
        sp_reset_memberships($uid);
        sp_reset_auths($uid);
    }
    do_action('sph_admin_new_save');
    if ($added) {
        $mess = spa_text('New admins added!');
    } else {
        $mess = spa_text('No data changed!');
    }
    return $mess;
}
コード例 #14
0
 function __construct($ident = 0, $current = false, $small = false)
 {
     global $spStatus, $spGlobals;
     $id = 0;
     if (is_numeric($ident)) {
         $w = "ID={$ident}";
     } else {
         if ($ident != false) {
             $w = "user_login='******'";
         }
     }
     if ($ident) {
         # Users data
         $d = spdb_table(SFUSERS, $w, 'row');
         if ($d) {
             $this->ID = $d->ID;
             $id = $d->ID;
         }
     }
     $includeList = spUser_build_filter_list();
     if ($id) {
         # Others
         $this->member = true;
         $this->guest = 0;
         $this->guest_name = '';
         $this->guest_email = '';
         $this->offmember = false;
         $this->usertype = 'User';
         # Users data
         foreach ($d as $key => $item) {
             if (array_key_exists($key, $includeList)) {
                 $this->{$key} = $item;
             }
         }
         $this->user_registered = sp_member_registration_to_server_tz($this->user_registered);
         # usermeta data
         $d = spdb_table(SFUSERMETA, "user_id={$id}");
         if ($d) {
             foreach ($d as $m) {
                 $t = $m->meta_key;
                 if (array_key_exists($t, $includeList)) {
                     $this->{$t} = maybe_unserialize($m->meta_value);
                 }
             }
         }
         # If awaiting installation then dive out now to avoid errors
         if ($spStatus == 'Install') {
             return;
         }
         # sfmembers data
         $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         #check for ghost user
         if (empty($d)) {
             #create the member
             sp_create_member_data($id);
             $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         }
         if ($d) {
             foreach ($d as $key => $item) {
                 if ($key == 'admin_options' && !empty($item)) {
                     $opts = unserialize($item);
                     foreach ($opts as $opt => $set) {
                         $this->{$opt} = $set;
                     }
                 } else {
                     if ($key == 'user_options' && !empty($item)) {
                         $opts = unserialize($item);
                         foreach ($opts as $opt => $set) {
                             $this->{$opt} = $set;
                         }
                     } else {
                         if ($key == 'lastvisit') {
                             $this->lastvisit = $item;
                         } else {
                             $this->{$key} = maybe_unserialize($item);
                         }
                     }
                 }
             }
         }
         # Check for new post list size
         if (!isset($this->unreadposts) || empty($this->unreadposts)) {
             $controls = sp_get_option('sfcontrols');
             $this->unreadposts = empty($controls['sfunreadposts']) ? 50 : $controls['sfunreadposts'];
         }
         # usertype for moderators
         if ($this->moderator) {
             $this->usertype = 'Moderator';
         }
         # check for super admins and make admin a moderator as well
         if ($this->admin || is_multisite() && is_super_admin($id)) {
             $this->admin = true;
             $this->moderator = true;
             $this->usertype = 'Admin';
             $ins = sp_get_option('spInspect');
             if (!empty($ins) && array_key_exists($id, $ins)) {
                 $this->inspect = $ins[$id];
             } else {
                 $this->inspect = '';
             }
         }
         # plugins can add iterms for members...
         if (!$small) {
             do_action_ref_array('sph_user_class_member', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_member_small', array(&$this));
         }
     } else {
         # some basics for guests
         $this->ID = 0;
         $this->guest = true;
         $this->member = 0;
         $this->admin = false;
         $this->moderator = false;
         $this->display_name = 'guest';
         $this->guest_name = '';
         $this->guest_email = '';
         $this->usertype = 'Guest';
         $this->offmember = sp_check_unlogged_user();
         $this->timezone = 0;
         $this->timezone_string = '';
         $this->posts = 0;
         $this->avatar = '';
         $this->user_email = '';
         $this->auths = sp_get_option('sf_guest_auths');
         $this->memberships = sp_get_option('sf_guest_memberships');
         # plugins can add iterms for guests...
         if (!$small) {
             do_action_ref_array('sph_user_class_guest', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_guest_small', array(&$this));
         }
     }
     # Only perform this last section if forum is operational
     if ($spStatus == 'ok') {
         # Ranking
         $this->rank = sp_get_user_forum_rank($this->usertype, $id, $this->posts);
         $this->special_rank = $this->member ? sp_get_user_special_ranks($id) : array();
         # if no memberships rebuild them and save
         if (empty($this->memberships)) {
             $memberships = array();
             if (!empty($id)) {
                 if (!$this->admin) {
                     # get the usergroup memberships for the user and save in sfmembers table
                     $memberships = sp_get_user_memberships($id);
                     sp_update_member_item($id, 'memberships', $memberships);
                 }
             } else {
                 # user is a guest or unassigned member so get the global permissions from the guest usergroup and save as option
                 $value = sp_get_sfmeta('default usergroup', 'sfguests');
                 $memberships[] = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $value[0]['meta_value'], 'row', '', '', ARRAY_A);
                 sp_update_option('sf_guest_memberships', $memberships);
             }
             # put in the data
             $this->memberships = $memberships;
         }
         # if no auths rebuild them and save
         if (empty($this->auths)) {
             $this->auths = sp_rebuild_user_auths($id);
         }
     }
     $this->ip = sp_get_ip();
     $this->trackid = -1;
     # Things to do if user is current user
     if ($current) {
         # Set up editor type
         $spGlobals['editor'] = 0;
         # for a user...
         if ($this->member && !empty($this->editor)) {
             $spGlobals['editor'] = $this->editor;
         }
         # and if not defined or is for a guest...
         if ($spGlobals['editor'] == 0) {
             $defeditor = sp_get_option('speditor');
             if (!empty($defeditor)) {
                 $spGlobals['editor'] = $defeditor;
             }
         }
         # final check to ensure selected editor type is indeed available
         if ($spGlobals['editor'] == 0 || $spGlobals['editor'] == 1 && !defined('RICHTEXT') || $spGlobals['editor'] == 2 && !defined('HTML') || $spGlobals['editor'] == 3 && !defined('BBCODE')) {
             $spGlobals['editor'] = PLAINTEXT;
             if (defined('BBCODE')) {
                 $spGlobals['editor'] = BBCODE;
             }
             if (defined('HTML')) {
                 $spGlobals['editor'] = HTML;
             }
             if (defined('RICHTEXT')) {
                 $spGlobals['editor'] = RICHTEXT;
             }
         }
         # Grab any notices present
         if ($this->guest && !empty($this->guest_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "guest_email='" . $this->guest_email . "'", '', $order = 'notice_id');
         } elseif ($this->member && !empty($this->user_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "user_id=" . $this->ID, '', $order = 'notice_id');
         }
         # plugins can add iterms for the current user (so no small allowed here)
         do_action_ref_array('sph_current_user_class', array(&$this));
     }
     # Finally filter the data for display
     foreach ($includeList as $item => $filter) {
         if (property_exists($this, $item)) {
             $this->{$item} = spUser_filter_item($this->{$item}, $filter);
         }
     }
     # allow plugins to add items to user class - regardless small or otherwise, current or otherwise
     do_action_ref_array('sph_user_class', array(&$this));
 }
コード例 #15
0
ファイル: sp-db-management.php プロジェクト: bself/nuimage-wp
function sp_delete_post($postid, $topicid, $forumid, $show = true, $poster = 0)
{
    global $spThisUser;
    if (!$postid || !$topicid || !$forumid) {
        return '';
    }
    if (sp_get_auth('delete_any_post', $forumid) || sp_get_auth('delete_own_posts', $forumid) && $spThisUser->ID == $poster) {
        # Check post actually exsists - might be a browsser refresh!
        $target = spdb_table(SFPOSTS, "post_id={$postid}", 'row');
        if (empty($target)) {
            if ($show) {
                sp_notify(SPSUCCESS, sp_text('Post already deleted'));
            }
            return;
        }
        # if just one post then remove topic as well
        $pcount = spdb_table(SFTOPICS, "topic_id={$topicid}", 'post_count');
        if ($pcount == 1) {
            sp_delete_topic($topicid, $forumid, $show);
        } else {
            if (spdb_query('DELETE FROM ' . SFPOSTS . " WHERE post_id={$postid}") == false) {
                if ($show) {
                    sp_notify(SPFAILURE, sp_text('Deletion failed'));
                }
            } else {
                if ($show) {
                    sp_notify(SPSUCCESS, sp_text('Post deleted'));
                }
            }
            # adjust post count if needed
            $adjust = sp_get_option('post_count_delete');
            if ($adjust) {
                $count = sp_get_member_item($target->user_id, 'posts') - 1;
                sp_update_member_item($target->user_id, 'posts', $count);
            }
            # re number post index
            sp_build_post_index($topicid);
            sp_build_forum_index($forumid);
            # post delete hook
            do_action('sph_post_delete', $target, $spThisUser->ID);
            # flush and rebuild topic cache (since one or more posts approved)
            sp_rebuild_topic_cache();
        }
        # need to look in sfwaiting to see if it's in there...
        sp_remove_from_waiting(true, $topicid, $postid);
        sp_delete_notice('post_id', $postid);
    } else {
        if (!is_user_logged_in()) {
            $msg = sp_text('Access denied - are you logged in?');
        } else {
            $msg = sp_text('Access denied - you do not have permission');
        }
        sp_notify(SPFAILURE, $msg);
    }
}
コード例 #16
0
function sp_rebuild_user_auths($userid)
{
    global $spGlobals;
    $user_auths = array();
    $user_auths['global'] = array();
    if (sp_is_forum_admin($userid)) {
        # forum admins get full auths
        $forums = spdb_table(SFFORUMS);
        if ($forums) {
            foreach ($forums as $forum) {
                foreach ($spGlobals['auths_map'] as $auth) {
                    if ($spGlobals['auths'][$auth]->admin_negate) {
                        $user_auths[$forum->forum_id][$auth] = 0;
                        $user_auths['global'][$auth] = 0;
                    } else {
                        $user_auths[$forum->forum_id][$auth] = 1;
                        $user_auths['global'][$auth] = 1;
                    }
                }
            }
        }
    } else {
        $memberships = sp_get_user_memberships($userid);
        if (empty($memberships)) {
            $value = sp_get_sfmeta('default usergroup', 'sfguests');
            $memberships[0]['usergroup_id'] = $value[0]['meta_value'];
        }
        # no memberships means no permissions
        if (empty($memberships)) {
            return;
        }
        # get the roles
        $roles_data = spdb_table(SFROLES, 0);
        foreach ($roles_data as $role) {
            $roles[$role->role_id] = unserialize($role->role_auths);
        }
        # now build auths for user
        foreach ($memberships as $membership) {
            # get the permissions for the membership
            $permissions = spdb_table(SFPERMISSIONS, 'usergroup_id=' . $membership['usergroup_id']);
            if ($permissions) {
                foreach ($permissions as $permission) {
                    if (!isset($user_auths[$permission->forum_id])) {
                        $user_auths[$permission->forum_id] = $roles[$permission->permission_role];
                    } else {
                        foreach (array_keys($roles[$permission->permission_role]) as $auth_id) {
                            if (!isset($user_auths[$permission->forum_id][$auth_id])) {
                                $user_auths[$permission->forum_id][$auth_id] = $roles[$permission->permission_role][$auth_id];
                            } else {
                                $user_auths[$permission->forum_id][$auth_id] |= $roles[$permission->permission_role][$auth_id];
                            }
                        }
                    }
                    foreach ($roles[$permission->permission_role] as $auth_id => $auth) {
                        if (empty($user_auths['global'][$auth_id])) {
                            $user_auths['global'][$auth_id] = $auth;
                        } else {
                            $user_auths['global'][$auth_id] |= $auth;
                        }
                    }
                }
            }
        }
    }
    # now save the user auths
    if (!empty($user_auths)) {
        if (!empty($userid)) {
            sp_update_member_item($userid, 'auths', $user_auths);
        } else {
            sp_update_option('sf_guest_auths', $user_auths);
        }
    }
    return $user_auths;
}
コード例 #17
0
function sp_ttags_new_admin($uid)
{
    $sfadminoptions = sp_get_member_item($uid, 'admin_options');
    $sfadminoptions['offline_message'] = '';
    sp_update_member_item($uid, 'admin_options', $sfadminoptions);
}