Ejemplo n.º 1
0
function spa_save_display_data()
{
    check_admin_referer('forum-adminform_display', 'forum-adminform_display');
    $mess = spa_text('Display options updated');
    $sfdisplay = sp_get_option('sfdisplay');
    $sfcontrols = sp_get_option('sfcontrols');
    # Page Title
    $sfdisplay['pagetitle']['notitle'] = isset($_POST['sfnotitle']);
    $sfdisplay['pagetitle']['banner'] = sp_filter_save_cleanurl($_POST['sfbanner']);
    # Stats
    $sfcontrols['shownewcount'] = isset($_POST['shownewcount']) ? sp_esc_int($_POST['shownewcount']) : 6;
    $newuserlist = sp_get_option('spRecentMembers');
    if (is_array($newuserlist)) {
        $ccount = count($newuserlist);
        while ($ccount > $sfcontrols['shownewcount']) {
            array_pop($newuserlist);
            $ccount--;
        }
        sp_update_option('spRecentMembers', $newuserlist);
    }
    $sfcontrols['showtopcount'] = isset($_POST['showtopcount']) ? sp_esc_int($_POST['showtopcount']) : 6;
    # adjust stats interval
    $statsInterval = !empty($_POST['statsinterval']) ? sp_esc_str($_POST['statsinterval']) * 3600 : 3600;
    $oldStatsInterval = sp_get_option('sp_stats_interval') * 3600;
    if ($statsInterval != $oldStatsInterval) {
        sp_update_option('sp_stats_interval', $statsInterval);
        wp_clear_scheduled_hook('sph_stats_cron');
        wp_schedule_event(time(), 'sp_stats_interval', 'sph_stats_cron');
    }
    # unread posts
    $sfcontrols['sfdefunreadposts'] = is_numeric($_POST['sfdefunreadposts']) ? max(0, sp_esc_int($_POST['sfdefunreadposts'])) : 50;
    $sfcontrols['sfusersunread'] = isset($_POST['sfusersunread']);
    $sfcontrols['sfmaxunreadposts'] = is_numeric($_POST['sfmaxunreadposts']) ? max(0, sp_esc_int($_POST['sfmaxunreadposts'])) : $sfcontrols['sfdefunreadposts'];
    include_once SF_PLUGIN_DIR . '/forum/database/sp-db-statistics.php';
    $topPosters = sp_get_top_poster_stats((int) $sfcontrols['showtopcount']);
    sp_update_option('spPosterStats', $topPosters);
    $sfdisplay['forums']['singleforum'] = isset($_POST['sfsingleforum']);
    $sfdisplay['topics']['perpage'] = isset($_POST['sfpagedtopics']) ? sp_esc_int($_POST['sfpagedtopics']) : 20;
    $sfdisplay['topics']['sortnewtop'] = isset($_POST['sftopicsort']);
    $sfdisplay['posts']['perpage'] = isset($_POST['sfpagedposts']) ? sp_esc_int($_POST['sfpagedposts']) : 20;
    $sfdisplay['posts']['sortdesc'] = isset($_POST['sfsortdesc']);
    $sfdisplay['editor']['toolbar'] = isset($_POST['sftoolbar']);
    sp_update_option('sfcontrols', $sfcontrols);
    sp_update_option('sfdisplay', $sfdisplay);
    do_action('sph_option_display_save');
    return $mess;
}
function spa_save_messages_data()
{
    check_admin_referer('forum-adminform_messages', 'forum-adminform_messages');
    # custom message for editor
    $sfpostmsg = array();
    $sfpostmsg['sfpostmsgtext'] = sp_filter_text_save(trim($_POST['sfpostmsgtext']));
    $sfpostmsg['sfpostmsgtopic'] = isset($_POST['sfpostmsgtopic']);
    $sfpostmsg['sfpostmsgpost'] = isset($_POST['sfpostmsgpost']);
    sp_update_option('sfpostmsg', $sfpostmsg);
    sp_update_option('sfeditormsg', sp_filter_text_save(trim($_POST['sfeditormsg'])));
    # if set update, otherwise its empty, so remove
    if ($_POST['sfsneakpeek'] != '') {
        sp_add_sfmeta('sneakpeek', 'message', sp_filter_text_save(trim($_POST['sfsneakpeek'])));
    } else {
        $msg = sp_get_sfmeta('sneakpeek', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    $sflogin = array();
    $sflogin = sp_get_option('sflogin');
    $sflogin['sfsneakredirect'] = sp_filter_save_cleanurl($_POST['sfsneakredirect']);
    sp_update_option('sflogin', $sflogin);
    # if set update, otherwise its empty, so remove
    if ($_POST['sfadminview'] != '') {
        sp_add_sfmeta('adminview', 'message', sp_filter_text_save(trim($_POST['sfadminview'])));
    } else {
        $msg = sp_get_sfmeta('adminview', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    # if set update, otherwise its empty, so remove
    if ($_POST['sfuserview'] != '') {
        sp_add_sfmeta('userview', 'message', sp_filter_text_save(trim($_POST['sfuserview'])));
    } else {
        $msg = sp_get_sfmeta('userview', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    do_action('sph_component_messages_save');
    $mess = spa_text('Custom messages updated');
    return $mess;
}
function spa_save_forums_global_rss()
{
    check_admin_referer('forum-adminform_globalrss', 'forum-adminform_globalrss');
    # update the globla rss replacement url
    sp_update_option('sfallRSSurl', sp_filter_save_cleanurl($_POST['sfallrssurl']));
    $mess = spa_text('Global RSS settings updated');
    do_action('sph_forum_global_rss');
    # clear out group cache tpo enable change_user
    sp_flush_cache('group');
    return $mess;
}
Ejemplo n.º 4
0
function sp_filter_url_save($url)
{
    #save unedited content
    $original = $url;
    # 1: clean up url for database
    $url = sp_filter_save_cleanurl($url);
    # 2: apply any users custom filters
    $url = apply_filters('sph_save_url_filter', $url, $original);
    return $url;
}
Ejemplo n.º 5
0
function spa_save_options_data()
{
    check_admin_referer('forum-adminform_options', 'forum-adminform_options');
    $mess = spa_text('Profile options updated');
    $sfprofile = sp_get_option('sfprofile');
    $old_sfprofile = $sfprofile;
    $sfprofile['nameformat'] = isset($_POST['nameformat']);
    $sfprofile['fixeddisplayformat'] = sp_esc_int($_POST['fixeddisplayformat']);
    $sfprofile['displaymode'] = sp_esc_int($_POST['displaymode']);
    $sfprofile['displaypage'] = sp_filter_save_cleanurl($_POST['displaypage']);
    $sfprofile['displayquery'] = sp_filter_title_save(trim($_POST['displayquery']));
    $sfprofile['formmode'] = sp_esc_int($_POST['formmode']);
    $sfprofile['formpage'] = sp_filter_save_cleanurl($_POST['formpage']);
    $sfprofile['formquery'] = sp_filter_title_save(trim($_POST['formquery']));
    $sfprofile['photosmax'] = sp_esc_int($_POST['photosmax']);
    $sfprofile['photoswidth'] = sp_esc_int($_POST['photoswidth']);
    $sfprofile['photosheight'] = sp_esc_int($_POST['photosheight']);
    if ($sfprofile['photosmax'] && $sfprofile['photoswidth'] == 0) {
        $sfprofile['photoswidth'] = 300;
    }
    $sfsigimagesize = array();
    $sfsigimagesize['sfsigwidth'] = sp_esc_int($_POST['sfsigwidth']);
    $sfsigimagesize['sfsigheight'] = sp_esc_int($_POST['sfsigheight']);
    sp_update_option('sfsigimagesize', $sfsigimagesize);
    $sfprofile['firstvisit'] = isset($_POST['firstvisit']);
    $sfprofile['forcepw'] = isset($_POST['forcepw']);
    $sfprofile['sfprofiletext'] = sp_filter_text_save(trim($_POST['sfprofiletext']));
    sp_update_option('sfprofile', $sfprofile);
    # if changed force pw from true to false, remove any users waiting for pw change
    if ($old_sfprofile['forcepw'] && !$sfprofile['forcepw']) {
        delete_metadata('user', 0, 'sp_change_pw', '', true);
    }
    # If the name format changes from dynamic to fixed, we need to update
    # the display_name field for all users based on the selection from the dropdown
    # If there is a conflict between display names, a numeric value will be added to the
    # end of the display name to make them unique.
    # ----------------------------------------------------------------------------------
    if ($old_sfprofile['nameformat'] != $sfprofile['nameformat'] && empty($sfprofile['nameformat']) || $old_sfprofile['fixeddisplayformat'] != $sfprofile['fixeddisplayformat'] && empty($sfprofile['nameformat'])) {
        # The display format determines the WHERE clause and the tables to join.
        # ----------------------------------------------------------------------
        $fields = '';
        $user_join = SFUSERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFUSERS . '.ID';
        $first_name_join = SFUSERMETA . ' a ON (' . SFUSERS . '.ID = a.user_id AND a.meta_key = \'first_name\')';
        $last_name_join = SFUSERMETA . ' b ON (' . SFUSERS . '.ID = b.user_id AND b.meta_key = \'last_name\')';
        # Determine how many passes its going to take to update all users in the system
        # based on 100 users per pass.
        # -----------------------------------------------------------------------------
        $num_records = spdb_count(SFMEMBERS, '');
        $passes = ceil($num_records / 100);
        $dupes = array();
        for ($i = 0; $i <= $passes; $i++) {
            $limit = 100;
            $offset = $i * $limit;
            $fields = SFMEMBERS . '.user_id, ' . SFUSERS . '.user_login, ' . SFUSERS . '.display_name, a.meta_value as first_name, b.meta_value as last_name';
            $join = array($user_join, $first_name_join, $last_name_join);
            $spdb = new spdbComplex();
            $spdb->table = SFMEMBERS;
            $spdb->fields = $fields;
            $spdb->left_join = $join;
            $spdb->limits = $limit . ' OFFSET ' . $offset;
            $spdb->order = SFMEMBERS . '.user_id';
            $spdb = apply_filters('sph_fixeddisplayformat_query', $spdb);
            $records = $spdb->select();
            foreach ($records as $r) {
                switch ($sfprofile['fixeddisplayformat']) {
                    default:
                    case '0':
                        $display_name = $r->display_name;
                        break;
                    case '1':
                        $display_name = $r->user_login;
                        break;
                    case '2':
                        $display_name = $r->first_name;
                        break;
                    case '3':
                        $display_name = $r->last_name;
                        break;
                    case '4':
                        $display_name = $r->first_name . ' ' . $r->last_name;
                        break;
                    case '5':
                        $display_name = $r->last_name . ', ' . $r->first_name;
                        break;
                    case '6':
                        $display_name = $r->first_name[0] . ' ' . $r->last_name;
                        break;
                    case '7':
                        $display_name = $r->first_name . ' ' . $r->last_name[0];
                        break;
                    case '8':
                        $display_name = $r->first_name[0] . $r->last_name[0];
                        break;
                }
                # If the display name is empty for any reason, default to the user login name
                $display_name = trim($display_name);
                if (empty($display_name)) {
                    $display_name = $r->user_login;
                }
                # Check to see if there are any matching users with this display name.  If so
                # assign a random number to the end to eliminate the duplicate
                # ----------------------------------------------------------------------------
                $conflict = spdb_count(SFMEMBERS, 'display_name = "' . $display_name . '" AND user_id <> ' . $r->user_id);
                if ($conflict > 0) {
                    if (array_key_exists($display_name, $dupes)) {
                        $dupes[$display_name]++;
                    } else {
                        $dupes[$display_name] = 1;
                    }
                    $display_name = $display_name . $dupes[$display_name];
                }
                # Now Update the member record
                # ----------------------------
                $display_name = sp_filter_name_save($display_name);
                $query = 'UPDATE ' . SFMEMBERS . ' SET display_name = "' . $display_name . '" WHERE user_id = ' . $r->user_id;
                $result = spdb_query($query);
            }
        }
        # update the recent members in stats too
        sp_update_recent_members();
    }
    do_action('sph_profiles_options_save');
    return $mess;
}