Example #1
0
    /**
     * Rewrites the admin user input into a select element containing existing WordPress administrators.
     *
     * @return boolean True if the select element was created, otherwise false.
     **/
    function populate_keymaster_user_login_from_user_tables()
    {
        $data =& $this->data[3]['form']['keymaster_user_login'];
        // Get the existing WordPress admin users
        // Setup variables and constants if available
        global $bb;
        if (!empty($this->data[2]['form']['wp_table_prefix']['value'])) {
            $bb->wp_table_prefix = $this->data[2]['form']['wp_table_prefix']['value'];
        }
        if (!empty($this->data[2]['form']['user_bbdb_name']['value'])) {
            $bb->user_bbdb_name = $this->data[2]['form']['user_bbdb_name']['value'];
        }
        if (!empty($this->data[2]['form']['user_bbdb_user']['value'])) {
            $bb->user_bbdb_user = $this->data[2]['form']['user_bbdb_user']['value'];
        }
        if (!empty($this->data[2]['form']['user_bbdb_password']['value'])) {
            $bb->user_bbdb_password = $this->data[2]['form']['user_bbdb_password']['value'];
        }
        if (!empty($this->data[2]['form']['user_bbdb_host']['value'])) {
            $bb->user_bbdb_host = $this->data[2]['form']['user_bbdb_host']['value'];
        }
        if (!empty($this->data[2]['form']['user_bbdb_charset']['value'])) {
            $bb->user_bbdb_charset = preg_replace('/[^a-z0-9_-]/i', '', $this->data[2]['form']['user_bbdb_charset']['value']);
        }
        if (!empty($this->data[2]['form']['user_bbdb_collate']['value'])) {
            $bb->user_bbdb_charset = preg_replace('/[^a-z0-9_-]/i', '', $this->data[2]['form']['user_bbdb_collate']['value']);
        }
        if (!empty($this->data[2]['form']['custom_user_table']['value'])) {
            $bb->custom_user_table = preg_replace('/[^a-z0-9_-]/i', '', $this->data[2]['form']['custom_user_table']['value']);
        }
        if (!empty($this->data[2]['form']['custom_user_meta_table']['value'])) {
            $bb->custom_user_meta_table = preg_replace('/[^a-z0-9_-]/i', '', $this->data[2]['form']['custom_user_meta_table']['value']);
        }
        global $bbdb;
        global $bb_table_prefix;
        // Resolve the custom user tables for bpdb
        bb_set_custom_user_tables();
        if (isset($bb->custom_databases) && isset($bb->custom_databases['user'])) {
            $bbdb->add_db_server('user', $bb->custom_databases['user']);
        }
        // Add custom tables if required
        if (isset($bb->custom_tables['users']) || isset($bb->custom_tables['usermeta'])) {
            $bbdb->tables = array_merge($bbdb->tables, $bb->custom_tables);
            if (is_wp_error($bbdb->set_prefix($bb_table_prefix))) {
                die(__('Your user table prefix may only contain letters, numbers and underscores.'));
            }
        }
        $bb_keymaster_meta_key = $bbdb->escape($bb_table_prefix . 'capabilities');
        $wp_administrator_meta_key = $bbdb->escape($bb->wp_table_prefix . 'capabilities');
        if (!empty($this->data[2]['form']['wordpress_mu_primary_blog_id']['value'])) {
            $wp_administrator_meta_key = $bb->wp_table_prefix . $this->data[2]['form']['wordpress_mu_primary_blog_id']['value'] . '_capabilities';
        }
        $keymaster_query = <<<EOQ
\t\t\tSELECT
\t\t\t\tuser_login, user_email, display_name
\t\t\tFROM
\t\t\t\t{$bbdb->users}
\t\t\tLEFT JOIN
\t\t\t\t{$bbdb->usermeta} ON
\t\t\t\t{$bbdb->users}.ID = {$bbdb->usermeta}.user_id
\t\t\tWHERE
\t\t\t\t(
\t\t\t\t\t(
\t\t\t\t\t\tmeta_key = '{$wp_administrator_meta_key}' AND
\t\t\t\t\t\tmeta_value LIKE '%administrator%'
\t\t\t\t\t) OR
\t\t\t\t\t(
\t\t\t\t\t\tmeta_key = '{$bb_keymaster_meta_key}' AND
\t\t\t\t\t\tmeta_value LIKE '%keymaster%'
\t\t\t\t\t)
\t\t\t\t) AND
\t\t\t\tuser_email IS NOT NULL AND
\t\t\t\tuser_email != ''
\t\t\tORDER BY
\t\t\t\tuser_login;
EOQ;
        $bbdb->suppress_errors();
        if ($keymasters = $bbdb->get_results($keymaster_query, ARRAY_A)) {
            $bbdb->suppress_errors(false);
            if (count($keymasters)) {
                $email_maps = '';
                $data['options'] = array();
                $data['onchange'] = 'changeKeymasterEmail( this, \'keymaster_user_email\' );';
                $data['note'] = __('Please select an existing bbPress Keymaster or WordPress administrator.');
                $data['options'][''] = '';
                foreach ($keymasters as $keymaster) {
                    $email_maps .= 'emailMap[\'' . $keymaster['user_login'] . '\'] = \'' . $keymaster['user_email'] . '\';' . "\n\t\t\t\t\t\t\t\t";
                    if ($keymaster['display_name']) {
                        $data['options'][$keymaster['user_login']] = $keymaster['user_login'] . ' (' . $keymaster['display_name'] . ')';
                    } else {
                        $data['options'][$keymaster['user_login']] = $keymaster['user_login'];
                    }
                }
                $this->strings[3]['scripts']['changeKeymasterEmail'] = <<<EOS
\t\t\t\t\t\t<script type="text/javascript" charset="utf-8">
\t\t\t\t\t\t\tfunction changeKeymasterEmail( selectObj, target ) {
\t\t\t\t\t\t\t\tvar emailMap = new Array;
\t\t\t\t\t\t\t\temailMap[''] = '';
\t\t\t\t\t\t\t\t{$email_maps}
\t\t\t\t\t\t\t\tvar targetObj = document.getElementById( target );
\t\t\t\t\t\t\t\tvar selectedAdmin = selectObj.options[selectObj.selectedIndex].value;
\t\t\t\t\t\t\t\ttargetObj.value = emailMap[selectedAdmin];
\t\t\t\t\t\t\t}
\t\t\t\t\t\t</script>
EOS;
                $this->data[3]['form']['keymaster_user_type']['value'] = 'old';
                return true;
            }
        }
        $bbdb->suppress_errors(false);
        return false;
    }
Example #2
0
}
// Don't accept a plugin location called "all". Unlikely, but really not desirable.
if (isset($bb->plugin_locations['all'])) {
    unset($bb->plugin_locations['all']);
}
$_default_theme_locations = array('core' => array('dir' => BB_CORE_THEME_DIR, 'url' => BB_CORE_THEME_URL, 'cap' => 'manage_themes'), 'user' => array('dir' => BB_THEME_DIR, 'url' => BB_THEME_URL, 'cap' => 'manage_themes'));
if (isset($bb->theme_locations) && is_array($bb->theme_locations)) {
    $bb->theme_locations = array_merge($_default_theme_locations, $bb->theme_locations);
} else {
    $bb->theme_locations = $_default_theme_locations;
}
/**
 * Add custom tables if present
 */
// Resolve the various ways custom user tables might be setup
bb_set_custom_user_tables();
// Add custom databases if required
if (isset($bb->custom_databases)) {
    foreach ($bb->custom_databases as $connection => $database) {
        $bbdb->add_db_server($connection, $database);
    }
}
unset($connection, $database);
// Add custom tables if required
if (isset($bb->custom_tables)) {
    $bbdb->tables = array_merge($bbdb->tables, $bb->custom_tables);
    if (is_nxt_error($bbdb->set_prefix($bbdb->prefix))) {
        die(__('Your user table prefix may only contain letters, numbers and underscores.'));
    }
}
/**