function set_permissions()
 {
     $nxt_roles = new nxt_Roles();
     $all_roles = $nxt_roles->get_names();
     foreach ($all_roles as $role => $name) {
         $role_object = get_role($role);
         foreach ($this->permissions as $cap => $grant) {
             if ($cap == 'publish_wiki_pages' && $role == 'wiki_editor') {
                 continue;
             } else {
                 $role_object->add_cap($cap);
             }
         }
     }
 }
示例#2
0
/**
 * Add XRDS entries for OpenID Server.  Entries added will be highly 
 * dependant on the requested URL and plugin configuration.
 *
 * @uses apply_filters() Calls 'openid_server_xrds_types' before returning XRDS Types for OpenID authentication services.
 */
function openid_provider_xrds_simple($xrds)
{
    global $nxt_roles;
    if (!$nxt_roles) {
        $nxt_roles = new nxt_Roles();
    }
    $provider_enabled = false;
    foreach ($nxt_roles->role_names as $key => $name) {
        $role = $nxt_roles->get_role($key);
        if ($role->has_cap('use_openid_provider')) {
            $provider_enabled = true;
            break;
        }
    }
    if (!$provider_enabled) {
        return $xrds;
    }
    $user = openid_server_requested_user();
    if (!$user && get_option('openid_blog_owner')) {
        $url_parts = parse_url(get_option('home'));
        $path = array_key_exists('path', $url_parts) ? $url_parts['path'] : '';
        $path = trailingslashit($path);
        $script = preg_replace('/index.php$/', '', $_SERVER['SCRIPT_NAME']);
        $script = trailingslashit($script);
        if ($path != $script && !is_admin()) {
            return $xrds;
        }
        if (!defined('OPENID_DISALLOW_OWNER') || !OPENID_DISALLOW_OWNER) {
            $user = get_user_by('login', get_option('openid_blog_owner'));
        }
    }
    if ($user) {
        // if user doesn't have capability, bail
        $user_object = new nxt_User($user->ID);
        if (!$user_object->has_cap('use_openid_provider')) {
            return $xrds;
        }
        if (get_user_meta($user->ID, 'openid_delegate', true)) {
            $services = get_user_meta($user->ID, 'openid_delegate_services', true);
        } else {
            $services = array();
            $tmp_types = apply_filters('openid_server_xrds_types', array('http://specs.openid.net/auth/2.0/signon'));
            $types = array();
            foreach ($tmp_types as $t) {
                $types[] = array('content' => $t);
            }
            $services[] = array('Type' => $types, 'URI' => openid_server_url(), 'LocalID' => get_author_posts_url($user->ID));
            $tmp_types = apply_filters('openid_server_xrds_types', array('http://openid.net/signon/1.1'));
            $types = array();
            foreach ($tmp_types as $t) {
                $types[] = array('content' => $t);
            }
            $services[] = array('Type' => $types, 'URI' => openid_server_url(), 'openid:Delegate' => get_author_posts_url($user->ID));
        }
    } else {
        $services = array(array('Type' => array(array('content' => 'http://specs.openid.net/auth/2.0/server')), 'URI' => openid_server_url(), 'LocalID' => 'http://specs.openid.net/auth/2.0/identifier_select'));
    }
    if (!empty($services)) {
        foreach ($services as $index => $service) {
            $name = 'OpenID Provider Service (' . $index . ')';
            $xrds = xrds_add_service($xrds, 'main', $name, $service, $index);
        }
    }
    return $xrds;
}
示例#3
0
/**
 * Count number of users who have each of the user roles.
 *
 * Assumes there are neither duplicated nor orphaned capabilities meta_values.
 * Assumes role names are unique phrases.  Same assumption made by nxt_User_Query::prepare_query()
 * Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users.
 * Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see nxt Bug #12257.
 *
 * @since 3.0.0
 * @param string $strategy 'time' or 'memory'
 * @return array Includes a grand total and an array of counts indexed by role strings.
 */
function count_users($strategy = 'time')
{
    global $nxtdb, $nxt_roles;
    // Initialize
    $id = get_current_blog_id();
    $blog_prefix = $nxtdb->get_blog_prefix($id);
    $result = array();
    if ('time' == $strategy) {
        global $nxt_roles;
        if (!isset($nxt_roles)) {
            $nxt_roles = new nxt_Roles();
        }
        $avail_roles = $nxt_roles->get_names();
        // Build a CPU-intensive query that will return concise information.
        $select_count = array();
        foreach ($avail_roles as $this_role => $name) {
            $select_count[] = "COUNT(NULLIF(`meta_value` LIKE '%" . like_escape($this_role) . "%', FALSE))";
        }
        $select_count = implode(', ', $select_count);
        // Add the meta_value index to the selection list, then run the query.
        $row = $nxtdb->get_row("SELECT {$select_count}, COUNT(*) FROM {$nxtdb->usermeta} WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N);
        // Run the previous loop again to associate results with role names.
        $col = 0;
        $role_counts = array();
        foreach ($avail_roles as $this_role => $name) {
            $count = (int) $row[$col++];
            if ($count > 0) {
                $role_counts[$this_role] = $count;
            }
        }
        // Get the meta_value index from the end of the result set.
        $total_users = (int) $row[$col];
        $result['total_users'] = $total_users;
        $result['avail_roles'] =& $role_counts;
    } else {
        $avail_roles = array();
        $users_of_blog = $nxtdb->get_col("SELECT meta_value FROM {$nxtdb->usermeta} WHERE meta_key = '{$blog_prefix}capabilities'");
        foreach ($users_of_blog as $caps_meta) {
            $b_roles = unserialize($caps_meta);
            if (is_array($b_roles)) {
                foreach ($b_roles as $b_role => $val) {
                    if (isset($avail_roles[$b_role])) {
                        $avail_roles[$b_role]++;
                    } else {
                        $avail_roles[$b_role] = 1;
                    }
                }
            }
        }
        $result['total_users'] = count($users_of_blog);
        $result['avail_roles'] =& $avail_roles;
    }
    return $result;
}
示例#4
0
function wlcms_get_all_caps_from_nxt_roles()
{
    $nxt_Roles = new nxt_Roles();
    $role_names = $nxt_Roles->get_names();
    $all_caps = array();
    if (count($nxt_Roles->roles) > 0) {
        foreach ($nxt_Roles->roles as $role_id => $row) {
            foreach ($row['capabilities'] as $capability => $allowed) {
                $all_caps[$capability] = $capability;
            }
        }
    }
    return $all_caps;
}
示例#5
0
 /**
  * Retrieve all of the role capabilities and merge with individual capabilities.
  *
  * All of the capabilities of the roles the user belongs to are merged with
  * the users individual roles. This also means that the user can be denied
  * specific roles that their role might have, but the specific user isn't
  * granted permission to.
  *
  * @since 2.0.0
  * @uses $nxt_roles
  * @access public
  */
 function get_role_caps()
 {
     global $nxt_roles;
     if (!isset($nxt_roles)) {
         $nxt_roles = new nxt_Roles();
     }
     //Filter out caps that are not role names and assign to $this->roles
     if (is_array($this->caps)) {
         $this->roles = array_filter(array_keys($this->caps), array(&$nxt_roles, 'is_role'));
     }
     //Build $allcaps from role caps, overlay user's $caps
     $this->allcaps = array();
     foreach ((array) $this->roles as $role) {
         $the_role = $nxt_roles->get_role($role);
         $this->allcaps = array_merge((array) $this->allcaps, (array) $the_role->capabilities);
     }
     $this->allcaps = array_merge((array) $this->allcaps, (array) $this->caps);
 }