/** * has_grade_caps( $user_id ) * * Checks if $user_id has grade management capabilities * * @param Int $user_id ID of the user capabilities to be checked * @return True if $user_id is eligible and False if not. */ function has_gradebook_caps($user_id) { $is_ok = true; //Treat super admins if (is_super_admin($user_id)) { $this->add_grade_caps($user_id); } $user = new nxt_User($user_id); foreach ($this->caps as $c) { if (!$user->has_cap($c)) { $is_ok = false; } } if (!get_option('bpsp_allow_only_admins')) { if (!bp_group_is_admin()) { $is_ok = false; } } return $is_ok; }
if ($ddate_m == $dmonths[$j]) { $ddate_m = $j + 1; } } $time_zn = intval($date_arr[4]) * 36; $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y); $ddate_U = $ddate_U - $time_zn; $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference); $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U); } } } // Set $post_status based on $author_found and on author's publish_posts capability if ($author_found) { $user = new nxt_User($post_author); $post_status = $user->has_cap('publish_posts') ? 'publish' : 'pending'; } else { // Author not found in DB, set status to pending. Author already set to admin. $post_status = 'pending'; } $subject = trim($subject); if ($content_type == 'multipart/alternative') { $content = explode('--' . $boundary, $content); $content = $content[2]; // match case-insensitive content-transfer-encoding if (preg_match('/Content-Transfer-Encoding: quoted-printable/i', $content, $delim)) { $content = explode($delim[0], $content); $content = $content[1]; } $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>'); }
/** * @deprecated 3.1.0 * * @param int $user_id User ID. * @param bool $exclude_zeros Optional, default is true. Whether to exclude zeros. * @return unknown */ function get_editable_user_ids($user_id, $exclude_zeros = true, $post_type = 'post') { _deprecated_function(__FUNCTION__, '3.1', 'get_users()'); global $nxtdb; $user = new nxt_User($user_id); $post_type_obj = get_post_type_object($post_type); if (!$user->has_cap($post_type_obj->cap->edit_others_posts)) { if ($user->has_cap($post_type_obj->cap->edit_posts) || !$exclude_zeros) { return array($user->ID); } else { return array(); } } if (!is_multisite()) { $level_key = $nxtdb->get_blog_prefix() . 'user_level'; } else { $level_key = $nxtdb->get_blog_prefix() . 'capabilities'; } // nxtmu site admins don't have user_levels $query = $nxtdb->prepare("SELECT user_id FROM {$nxtdb->usermeta} WHERE meta_key = %s", $level_key); if ($exclude_zeros) { $query .= " AND meta_value != '0'"; } return $nxtdb->get_col($query); }
/** * Add OpenID HTML link tags when appropriate. */ function openid_provider_link_tags() { if (is_front_page()) { if (!defined('OPENID_DISALLOW_OWNER') || !OPENID_DISALLOW_OWNER) { $user = get_user_by('login', get_option('openid_blog_owner')); } } else { if (is_author()) { global $nxt_query; $user = $nxt_query->get_queried_object(); } } if (isset($user) && $user) { // if user doesn't have capability, bail $user_object = new nxt_User($user->ID); if (!$user_object->has_cap('use_openid_provider')) { return; } if (get_user_meta($user->ID, 'openid_delegate', true)) { $services = get_user_meta($user->ID, 'openid_delegate_services', true); $openid_1 = false; $openid_2 = false; foreach ($services as $service) { if (!$openid_1 && $service['openid:Delegate']) { echo ' <link rel="openid.server" href="' . $service['URI'] . '" /> <link rel="openid.delegate" href="' . $service['openid:Delegate'] . '" />'; $openid_1 = true; } if (!$openid_2 && $service['LocalID']) { echo ' <link rel="openid2.provider" href="' . $service['URI'] . '" /> <link rel="openid2.local_id" href="' . $service['LocalID'] . '" />'; $openid_2 = true; } } } else { $server = openid_server_url(); $identifier = get_author_posts_url($user->ID); echo ' <link rel="openid2.provider" href="' . $server . '" /> <link rel="openid2.local_id" href="' . $identifier . '" /> <link rel="openid.server" href="' . $server . '" /> <link rel="openid.delegate" href="' . $identifier . '" />'; } } }
/** * has_student_caps( $user_id ) * * Checks if $user_id has response management capabilities * * @param Int $user_id ID of the user capabilities to be checked, default null * @return True if $user_id is eligible and False if not. */ function has_student_caps($user_id = null) { global $bp; if (!$user_id) { $user_id = $bp->loggedin_user->id; } $user_role = xprofile_get_field_data(__('Role'), $user_id); // Go away teacher if (__('Student', 'bpsp') != $user_role && !empty($user_role)) { return false; } // Treat super admins if (is_super_admin($user_id)) { $this->add_response_caps($user_id); } $user = new nxt_User($user_id); foreach ($this->students_caps as $c) { if (!$user->has_cap($c)) { $user->add_cap($c); } } return true; }
/** * Function for safely deleting a role and transferring the deleted role's users to the default role. Note that * this function can be extremely intensive. Whenever a role is deleted, it's best for the site admin to assign * the user's of the role to a different role beforehand. * * @since 0.2.0 * @param string $role The name of the role to delete. */ function members_delete_role($role) { /* Get the default role. */ $default_role = get_option('default_role'); /* Don't delete the default role. Site admins should change the default before attempting to delete the role. */ if ($role == $default_role) { return; } /* Get all users with the role to be deleted. */ $users = get_users(array('role' => $role)); /* Check if there are any users with the role we're deleting. */ if (is_array($users)) { /* If users are found, loop through them. */ foreach ($users as $user) { /* Create a new user object. */ $new_user = new nxt_User($user->ID); /* If the user has the role, remove it and set the default. Do we need this check? */ if ($new_user->has_cap($role)) { $new_user->remove_role($role); $new_user->set_role($default_role); } } } /* Remove the role. */ remove_role($role); }
/** * Create a new NXTClass user with the specified identity URL and user data. * * @param string $identity_url OpenID to associate with the newly * created account * @param array $user_data array of user data */ function openid_create_new_user($identity_url, &$user_data) { global $nxtdb; // Identity URL is new, so create a user @(include_once ABSPATH . 'nxt-admin/upgrade-functions.php'); // 2.1 @(include_once ABSPATH . nxtINC . '/registration-functions.php'); // 2.0.4 // otherwise, try to use preferred username if (empty($username) && array_key_exists('nickname', $user_data)) { $username = openid_generate_new_username($user_data['nickname'], false); } // finally, build username from OpenID URL if (empty($username)) { $username = openid_generate_new_username($identity_url); } $user_data['user_login'] = $username; $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7); $user_id = nxt_insert_user($user_data); if ($user_id) { // created ok $user_data['ID'] = $user_id; // XXX this all looks redundant, see openid_set_current_user $user = new nxt_User($user_id); if (!nxt_login($user->user_login, $user_data['user_pass'])) { openid_message(__('User was created fine, but nxt_login() for the new user failed. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); return; } // notify of user creation nxt_new_user_notification($user->user_login); nxt_clearcookie(); nxt_setcookie($user->user_login, md5($user->user_pass), true, '', '', true); // Bind the provided identity to the just-created user openid_add_user_identity($user_id, $identity_url); openid_status('redirect'); if (!$user->has_cap('edit_posts')) { $redirect_to = '/nxt-admin/profile.php'; } } else { // failed to create user for some reason. openid_message(__('OpenID authentication successful, but failed to create NXTClass user. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); } }
/** * Validates whether this comment is allowed to be made. * * @since 2.0.0 * @uses $nxtdb * @uses apply_filters() Calls 'pre_comment_approved' hook on the type of comment * @uses apply_filters() Calls 'comment_duplicate_trigger' hook on commentdata. * @uses do_action() Calls 'check_comment_flood' hook on $comment_author_IP, $comment_author_email, and $comment_date_gmt * * @param array $commentdata Contains information on the comment * @return mixed Signifies the approval status (0|1|'spam') */ function nxt_allow_comment($commentdata) { global $nxtdb; extract($commentdata, EXTR_SKIP); // Simple duplicate check // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) $dupe = "SELECT comment_ID FROM {$nxtdb->comments} WHERE comment_post_ID = '{$comment_post_ID}' AND comment_approved != 'trash' AND ( comment_author = '{$comment_author}' "; if ($comment_author_email) { $dupe .= "OR comment_author_email = '{$comment_author_email}' "; } $dupe .= ") AND comment_content = '{$comment_content}' LIMIT 1"; if ($nxtdb->get_var($dupe)) { do_action('comment_duplicate_trigger', $commentdata); if (defined('DOING_AJAX')) { die(__('Duplicate comment detected; it looks as though you’ve already said that!')); } nxt_die(__('Duplicate comment detected; it looks as though you’ve already said that!')); } do_action('check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt); if (isset($user_id) && $user_id) { $userdata = get_userdata($user_id); $user = new nxt_User($user_id); $post_author = $nxtdb->get_var($nxtdb->prepare("SELECT post_author FROM {$nxtdb->posts} WHERE ID = %d LIMIT 1", $comment_post_ID)); } if (isset($userdata) && ($user_id == $post_author || $user->has_cap('moderate_comments'))) { // The author and the admins get respect. $approved = 1; } else { // Everyone else's comments will be checked. if (check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type)) { $approved = 1; } else { $approved = 0; } if (nxt_blacklist_check($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent)) { $approved = 'spam'; } } $approved = apply_filters('pre_comment_approved', $approved, $commentdata); return $approved; }