本文整理汇总了PHP中scoper_get_otype_option函数的典型用法代码示例。如果您正苦于以下问题:PHP scoper_get_otype_option函数的具体用法?PHP scoper_get_otype_option怎么用?PHP scoper_get_otype_option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scoper_get_otype_option函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attachment_access
function attachment_access()
{
global $post, $wpdb;
if (empty($post)) {
global $wp_query;
if (!empty($wp_query->query_vars['attachment_id'])) {
$post = scoper_get_row("SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID = '{$wp_query->query_vars['attachment_id']}'");
} elseif (!empty($wp_query->query_vars['attachment'])) {
$post = scoper_get_row("SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_name = '{$wp_query->query_vars['attachment']}'");
}
}
if (!empty($post)) {
$object_type = scoper_get_var("SELECT post_type FROM {$wpdb->posts} WHERE ID = '{$post->post_parent}'");
// default to 'post' object type if retrieval failed for some reason
if (empty($object_type)) {
$object_type = 'post';
}
if ($post->post_parent) {
if (!current_user_can("read_{$object_type}", $post->post_parent)) {
if (scoper_get_otype_option('do_teaser', 'post')) {
if ($use_teaser_type = scoper_get_otype_option('use_teaser', 'post', $object_type)) {
AttachmentTemplate_RS::impose_post_teaser($post, $object_type, $use_teaser_type);
} else {
unset($post);
}
} else {
unset($post);
}
// WordPress generates 404 if teaser is not enabled
}
} elseif (defined('SCOPER_BLOCK_UNATTACHED_UPLOADS') && SCOPER_BLOCK_UNATTACHED_UPLOADS) {
unset($post);
}
}
}
示例2: otype_option_checkboxes
function otype_option_checkboxes($option_name, $caption, $tab_name, $section_name, $hint_text, $trailing_html, $args = array())
{
global $scoper, $scoper_admin;
$defaults = array('caption_header' => true);
$args = array_merge($defaults, $args);
extract($args);
$return = array('in_scope' => false, 'val' => array());
if (in_array($option_name, $this->form_options[$tab_name][$section_name])) {
$this->all_otype_options[] = $option_name;
if (isset($this->def_otype_options[$option_name])) {
if (!($return['val'] = scoper_get_option($option_name, $this->sitewide, $this->customize_defaults))) {
$return['val'] = array();
}
$return['val'] = array_merge($this->def_otype_options[$option_name], $return['val']);
$label_property = isset($args['label_property']) ? $args['label_property'] : 'name';
$first_pass = true;
foreach ($return['val'] as $src_otype => $val) {
if ($caption_header && $first_pass) {
printf($caption, $scoper_admin->interpret_src_otype($src_otype, $label_property));
echo '<br /><div style="margin-left: 2em">';
$first_pass = false;
}
$arr_src_otype = explode(':', $src_otype);
if (!scoper_get_otype_option('use_object_roles', $arr_src_otype[0], $arr_src_otype[1])) {
continue;
}
$item_label = $scoper_admin->interpret_src_otype($src_otype, $label_property);
//arg: use plural display name
$id = str_replace(':', '_', $option_name . '-' . $src_otype);
echo "<label for='{$id}'>";
echo "<input name='{$id}' type='checkbox' id='{$id}' value='1' ";
checked('1', $val);
echo " /> ";
if ($caption_header) {
echo $item_label;
} else {
printf($caption, $item_label);
}
echo '</label><br />';
}
// end foreach src_otype
if ($caption_header) {
echo '</div>';
}
if ($hint_text && $this->display_hints) {
echo "<span class='rs-subtext'>" . $hint_text . "</span>";
}
if ($trailing_html) {
echo $trailing_html;
}
}
// endif default option isset
$return['in_scope'] = true;
}
// endif in this option is controlled in this scope
return $return;
}
示例3: scoper_admin_init
function scoper_admin_init()
{
global $pagenow;
if (in_array($pagenow, array('update.php', 'plugin-install.php', 'update-core.php', 'plugins.php'))) {
require_once dirname(__FILE__) . '/plugin-update-watch_rs.php';
RS_UpdateWatch::update_watch();
}
if (!empty($_POST['rs_submit']) || !empty($_POST['rs_defaults']) || !empty($_POST['rs_flush_cache'])) {
// For 'options' and 'realm' admin panels, handle updated options right after current_user load (and before scoper init).
// By then, check_admin_referer is available, but Scoper config and WP admin menu has not been loaded yet.
require_once SCOPER_ABSPATH . '/submittee_rs.php';
$handler = new Scoper_Submittee();
if (isset($_POST['rs_submit'])) {
$sitewide = isset($_POST['rs_options_doing_sitewide']);
$customize_defaults = isset($_POST['rs_options_customize_defaults']);
$handler->handle_submission('update', $sitewide, $customize_defaults);
} elseif (isset($_POST['rs_defaults'])) {
$sitewide = isset($_POST['rs_options_doing_sitewide']);
$customize_defaults = isset($_POST['rs_options_customize_defaults']);
$handler->handle_submission('default', $sitewide, $customize_defaults);
} elseif (isset($_POST['rs_flush_cache'])) {
$handler->handle_submission('flush');
}
}
// work around conflict with Simple Fields plugin uploader
if (defined('EASY_FIELDS_URL')) {
if (strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/media-upload.php') || strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/async-upload.php')) {
define('DISABLE_QUERYFILTERS_RS', true);
}
}
if (defined('SSEO_VERSION')) {
require_once dirname(__FILE__) . '/eyes-only-admin_rs.php';
}
global $pagenow;
// prevent default_private option from forcing a draft/pending post into private publishing
if (in_array($pagenow, array('post.php', 'post-new.php'))) {
if (empty($_POST['publish']) && isset($_POST['post_status']) && isset($_POST['post_type']) && scoper_get_otype_option('default_private', 'post', $_POST['post_type'])) {
$stati = get_post_stati(array('public' => true, 'private' => true), 'names', 'or');
if ('private' == $_POST['visibility'] && !in_array($_POST['hidden_post_status'], $stati)) {
$_POST['post_status'] = $_POST['hidden_post_status'];
$_REQUEST['post_status'] = $_REQUEST['hidden_post_status'];
$_POST['visibility'] = 'public';
$_REQUEST['visibility'] = 'public';
}
}
}
}
示例4: flt_user_has_cap
function flt_user_has_cap($wp_blogcaps, $orig_reqd_caps, $args)
{
if (empty($args[2])) {
return $wp_blogcaps;
}
// Disregard caps which are not defined in Role Scoper config
if (!($rs_reqd_caps = array_intersect($orig_reqd_caps, $this->scoper->cap_defs->get_all_keys()))) {
return $wp_blogcaps;
}
$user_id = isset($args[1]) ? $args[1] : 0;
global $current_rs_user;
if ($user_id && $user_id != $current_rs_user->ID) {
$user = rs_get_user($user_id);
} else {
$user = $current_rs_user;
}
$object_id = (int) $args[2];
if (!($post_type = get_post_field('post_type', $object_id))) {
return $wp_blogcaps;
}
global $wpdb;
$use_term_roles = scoper_get_otype_option('use_term_roles', 'post', $post_type);
$use_object_roles = empty($src->no_object_roles) ? scoper_get_otype_option('use_object_roles', 'post', $post_type) : false;
$this_args = array('object_type' => $post_type, 'user' => $user, 'otype_use_term_roles' => $use_term_roles, 'otype_use_object_roles' => $use_object_roles, 'skip_teaser' => true);
$where = $this->query_interceptor->objects_where_role_clauses('post', $rs_reqd_caps, $this_args);
if ($where) {
$where = "AND ( {$where} )";
}
$id_ok = scoper_get_var("SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} WHERE 1=1 {$where} AND {$wpdb->posts}.ID = '{$object_id}' LIMIT 1");
$rs_reqd_caps = array_fill_keys($rs_reqd_caps, true);
if (!$id_ok) {
//d_echo("object_id $object_id not okay!" );
//rs_errlog( "object_id $object_id not okay!" );
return array_diff_key($wp_blogcaps, $rs_reqd_caps);
// required caps we scrutinized are excluded from this array
} else {
if ($restore_caps = array_diff($orig_reqd_caps, array_keys($rs_reqd_caps))) {
$rs_reqd_caps = $rs_reqd_caps + array_fill_keys($restore_caps, true);
}
//rs_errlog( 'RETURNING:' );
//rs_errlog( serialize(array_merge($wp_blogcaps, $rs_reqd_caps)) );
return array_merge($wp_blogcaps, $rs_reqd_caps);
}
}
示例5: flt_manage_posts_columns
function flt_manage_posts_columns($defaults)
{
global $current_user, $scoper, $scoper_role_usage;
$object_type = cr_find_post_type();
if ($blogwide_role_requirement = scoper_get_option('role_admin_blogwide_editor_only')) {
if ('admin' == $blogwide_role_requirement && !is_user_administrator_rs()) {
return $defaults;
} elseif ('content_admin' == $blogwide_role_requirement && !is_content_administrator_rs()) {
return $defaults;
} elseif ($blogwide_role_requirement) {
if (!$scoper->user_can_edit_blogwide('post', $object_type, array('require_others_cap' => true))) {
return $defaults;
}
}
}
$use_object_roles = scoper_get_otype_option('use_object_roles', 'post', $object_type);
$use_term_roles = scoper_get_otype_option('use_term_roles', 'post', $object_type);
if ($use_term_roles && !empty($scoper_role_usage->any_restricted_terms) || $use_object_roles && !empty($scoper_role_usage->any_restricted_objects)) {
if (scoper_get_otype_option('restrictions_column', 'post', $object_type)) {
$defaults['restricted'] = __('Restrict', 'scoper');
}
}
if (!empty($scoper_role_usage->have_termrole_ids['post'])) {
if (scoper_get_otype_option('term_roles_column', 'post', $object_type)) {
$defaults['termroles'] = __('Term Roles', 'scoper');
}
}
if ($use_object_roles && !empty($scoper_role_usage->have_objrole_ids['post'])) {
if (scoper_get_otype_option('object_roles_column', 'post', $object_type)) {
$otype_display_name = $scoper->data_sources->member_property('post', 'object_types', $object_type, 'display_name');
//$defaults['objroles'] = sprintf( _ x('%s Roles', 'Post or Page', 'scoper'), $otype_display_name);
$defaults['objroles'] = sprintf(__('%s Roles', 'scoper'), $otype_display_name);
}
}
return $defaults;
}
示例6: scoper_get_taxonomy_usage
function scoper_get_taxonomy_usage($src_name, $object_types = '')
{
$taxonomies = array();
$object_types = (array) $object_types;
foreach ($object_types as $object_type) {
if (taxonomy_exists($object_type)) {
$use_taxonomies = array($object_type => 1);
} else {
$use_taxonomies = scoper_get_otype_option('use_term_roles', $src_name, $object_type);
}
$taxonomies = array_merge($taxonomies, array_intersect((array) $use_taxonomies, array(1)));
// array cast prevents PHP warning on first-time execution following update to RS 1.2
}
if ($taxonomies) {
// make sure we indicate non-usage of term roles for taxonomies that are completely disabled for RS
if ('post' == $src_name) {
$use_taxonomies = scoper_get_option('use_taxonomies');
$taxonomies = array_intersect_key($taxonomies, array_intersect($use_taxonomies, array(1)));
}
return array_keys($taxonomies);
} else {
return array();
}
}
示例7: get_terms_reqd_caps
function get_terms_reqd_caps($taxonomy, $operation = '', $is_term_admin = false)
{
global $pagenow;
if (!($src_name = $this->taxonomies->member_property($taxonomy, 'object_source'))) {
if (taxonomy_exists($taxonomy)) {
$src_name = 'post';
}
}
$return_caps = array();
$is_term_admin = $is_term_admin || in_array($pagenow, array('edit-tags.php')) || ('nav_menu' == $taxonomy && 'nav-menus.php' == $pagenow || 'admin-ajax.php' == $pagenow && (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], array('add-menu-item', 'menu-locations-save'))));
// possible TODO: abstract for non-WP taxonomies
if ($is_term_admin) {
// query pertains to the management of terms
if ('post' == $src_name) {
$taxonomy_obj = get_taxonomy($taxonomy);
$return_caps[$taxonomy] = array($taxonomy_obj->cap->manage_terms);
} elseif ('link_category' == $taxonomy) {
$return_caps[$taxonomy] = array('manage_categories');
} else {
global $scoper;
$cap_defs = $scoper->cap_defs->get_matching($src_name, $taxonomy, OP_ADMIN_RS);
$return_caps[$taxonomy] = $cap_defs ? array_keys($cap_defs) : array();
}
} else {
// query pertains to reading or editing content within certain terms, or adding terms to content
$base_caps_only = true;
if ('post' == $src_name) {
if (!$operation) {
$operation = $this->is_front() || 'profile.php' == $pagenow || is_admin() && 's2' == $GLOBALS['plugin_page'] ? 'read' : 'edit';
}
// hack to support subscribe2 categories checklist
$status = 'read' == $operation ? 'publish' : 'draft';
// terms query should be limited to a single object type for post.php, post-new.php, so only return caps for that object type (TODO: do this in wp-admin regardless of URI ?)
if (in_array($pagenow, array('post.php', 'post-new.php'))) {
$object_type = cr_find_post_type();
}
} else {
if (!$operation) {
$operation = $this->is_front() ? 'read' : 'edit';
}
$status = '';
}
// The return array will indicate term role enable / disable, as well as associated capabilities
if (!empty($object_type)) {
$check_object_types = array($object_type);
} else {
if ($check_object_types = (array) $this->data_sources->member_property($src_name, 'object_types')) {
$check_object_types = array_keys($check_object_types);
}
}
if ('post' == $src_name) {
$use_post_types = scoper_get_option('use_post_types');
}
$enabled_object_types = array();
foreach ($check_object_types as $_object_type) {
if ($use_term_roles = scoper_get_otype_option('use_term_roles', $src_name, $_object_type)) {
if (!empty($use_term_roles[$taxonomy])) {
if ('post' != $src_name || !empty($use_post_types[$_object_type])) {
$enabled_object_types[] = $_object_type;
}
}
}
}
foreach ($enabled_object_types as $object_type) {
$return_caps[$object_type] = cr_get_reqd_caps($src_name, $operation, $object_type, $status, $base_caps_only);
}
}
return $return_caps;
}
示例8: display_ui_user_roles
//.........这里部分代码省略.........
}
// end foreach content date range
}
// end foreach role duration date range
$disable_role_admin = false;
global $profileuser;
$viewing_own_profile = !empty($profileuser) && $profileuser->ID == $current_rs_user->ID;
if (!$viewing_own_profile) {
if ($require_blogwide_editor = scoper_get_option('role_admin_blogwide_editor_only')) {
if ('admin' == $require_blogwide_editor && !is_user_administrator_rs()) {
return false;
}
if ('admin_content' == $require_blogwide_editor && !is_content_administrator_rs()) {
return false;
}
$disable_role_admin = !$scoper->user_can_edit_blogwide('post', '', array('require_others_cap' => true, 'status' => 'publish'));
}
}
foreach ($this->scoper->taxonomies->get_all() as $taxonomy => $tx) {
if (empty($term_roles[$taxonomy])) {
continue;
}
$val = ORDERBY_HIERARCHY_RS;
$args = array('order_by' => $val);
if (!($terms = $this->scoper->get_terms($taxonomy, UNFILTERED_RS, COLS_ALL_RS, 0, $args))) {
continue;
}
$object_types = array();
$obj_src = $this->scoper->data_sources->get($tx->object_source);
if (!$obj_src || !is_array($obj_src->object_types)) {
continue;
}
foreach (array_keys($obj_src->object_types) as $object_type) {
if (scoper_get_otype_option('use_term_roles', $tx->object_source, $object_type)) {
$object_types[] = $object_type;
}
}
if (!$object_types) {
continue;
}
$object_types[] = $taxonomy;
$admin_terms = $disable_role_admin ? array() : $this->scoper->get_terms($taxonomy, ADMIN_TERMS_FILTER_RS, COL_ID_RS);
$strict_terms = $this->scoper->get_restrictions(TERM_SCOPE_RS, $taxonomy);
$role_defs = $this->scoper->role_defs->get_matching('rs', $tx->object_source, $object_types);
$tx_src = $this->scoper->data_sources->get($tx->source);
$col_id = $tx_src->cols->id;
$col_name = $tx_src->cols->name;
$term_names = array();
foreach ($terms as $term) {
$term_names[$term->{$col_id}] = $term->{$col_name};
}
foreach (array_keys($term_roles[$taxonomy]) as $duration_key) {
if (is_serialized($duration_key)) {
$role_date_limits = unserialize($duration_key);
$role_date_limits->date_limited = true;
} else {
$role_date_limits = array();
}
foreach (array_keys($term_roles[$taxonomy][$duration_key]) as $date_key) {
if (is_serialized($date_key)) {
$content_date_limits = unserialize($date_key);
$content_date_limits->content_date_limited = true;
} else {
$content_date_limits = array();
}
$title = '';
示例9: flt_objects_listing
function flt_objects_listing($results, $src_name, $object_types, $args = array())
{
global $wpdb;
// it's not currently necessary or possible to log listed revisions from here
//if ( isset($wpdb->last_query) && strpos( $wpdb->last_query, "post_type = 'revision'") )
// return $results;
// if currently listed IDs are not already in post_cache, make our own equivalent memcache
// ( create this cache for any data source, front end or admin )
if ('post' == $src_name) {
global $wp_object_cache;
}
$listed_ids = array();
//if ( ('post' != $src_name) || empty($wp_object_cache->cache['posts']) ) {
if (empty($this->scoper->listed_ids[$src_name])) {
if ($col_id = $this->scoper->data_sources->member_property($src_name, 'cols', 'id')) {
$listed_ids = array();
// In edit.php, WP forces all objects into recordset for hierarchical post types. But for perf enchancement, we need to know IDs of items which are actually listed
if ('edit.php' == $GLOBALS['pagenow']) {
$post_type = !empty($_GET['post_type']) ? sanitize_key($_GET['post_type']) : 'post';
$determine_listed_ids = !is_content_administrator_rs() && is_post_type_hierarchical($post_type) && !empty($GLOBALS['query_interceptor']->last_request[$src_name]) && !strpos($GLOBALS['query_interceptor']->last_request[$src_name], 'LIMIT ');
if ($determine_listed_ids) {
// mimic recordset paging used in edit.php
$pagenum = isset($_GET['paged']) ? absint($_GET['paged']) : 0;
if (empty($pagenum)) {
$pagenum = 1;
}
$edit_per_page = 'edit_' . $post_type . '_per_page';
$per_page = (int) get_user_option($edit_per_page);
if (empty($per_page) || $per_page < 1) {
$per_page = 20;
}
$per_page = apply_filters($edit_per_page, $per_page);
$per_page = apply_filters('edit_posts_per_page', $per_page, $post_type);
if (count($results) <= $per_page) {
$determine_listed_ids = false;
}
}
} else {
$determine_listed_ids = false;
}
if ($determine_listed_ids) {
// Construct and execute a secondary query (for IDs only) which includes the paging clause that would be used if edit.php did not defeat it
$pgstrt = ($pagenum - 1) * $per_page . ', ';
$limits = ' LIMIT ' . $pgstrt . $per_page;
global $wpdb;
$qry = $GLOBALS['query_interceptor']->last_request[$src_name] . $limits;
$qry = str_replace("{$wpdb->posts}.*", "{$wpdb->posts}.ID", $qry);
$_results = scoper_get_results($qry);
foreach ($_results as $row) {
if (isset($row->{$col_id})) {
$listed_ids[$row->{$col_id}] = true;
}
}
} else {
// No secondary query, just buffer all IDs in the results set
foreach ($results as $row) {
if (isset($row->{$col_id})) {
$listed_ids[$row->{$col_id}] = true;
}
}
}
if (empty($this->scoper->listed_ids)) {
$this->scoper->listed_ids = array();
}
$this->scoper->listed_ids[$src_name] = $listed_ids;
}
} else {
return $results;
}
//}
// now determine what restrictions were in place on these results
// (currently only for post data source, front end or manage posts/pages)
//
// possible todo: support other data sources, WP role type
if ('edit.php' == $GLOBALS['pagenow']) {
if (scoper_get_otype_option('restrictions_column', 'post') || scoper_get_otype_option('term_roles_column', 'post') || scoper_get_otype_option('object_roles_column', 'post')) {
global $scoper_role_usage;
require_once dirname(__FILE__) . '/role_usage_rs.php';
$scoper_role_usage = new Role_Usage_RS();
$scoper_role_usage->determine_role_usage_rs('post', $listed_ids);
}
}
return $results;
}
示例10: flt_objects_where
//.........这里部分代码省略.........
}
// If the passed request contains a single status criteria, maintain that status exclusively (otherwise include status-specific conditions for each available status)
// (But not if user is anon and hidden content teaser is enabled. In that case, we need to replace the default "status=publish" clause)
$matches = array();
if ($num_matches = preg_match_all("/{$src_table}.{$col_status}\\s*=\\s*'([^']+)'/", $where, $matches)) {
$status_clause_pos = strpos($where, $matches[0][0]);
}
// note the match position for use downstream
if (1 == $num_matches) {
$use_status = $matches[1][0];
// Eliminate a primary plugin incompatibility by skipping this preservation of existing single status requirements if we're on the front end and the requirement is 'publish'.
// (i.e. include private posts that this user has access to via RS role assignment).
if (!$this->scoper->is_front() || 'publish' != $use_status || empty($args['user']->ID) && empty($tease_otypes) || defined('SCOPER_RETAIN_PUBLISH_FILTER')) {
$force_single_status = true;
foreach (array_keys($otype_status_reqd_caps) as $_object_type) {
$otype_status_reqd_caps[$_object_type] = array_intersect_key($otype_status_reqd_caps[$_object_type], array($use_status => true));
}
}
}
} else {
// this source doesn't define statuses
$basic_status_clause = array('' => '');
}
if (empty($skip_teaser) && !array_diff($object_types, $tease_otypes)) {
if ($status_clause_pos && $force_single_type) {
// All object types potentially returned by this query will have a teaser filter applied to results, so we don't need to filter the query
// override our sanity safeguard against exposing private posts to anonymous readers
if (empty($user->ID)) {
// Since we're dropping out of this function early in advance of teaser filtering,
// must take this opportunity to add private status to the query (otherwise WP excludes private for anon user)
// (But don't do this if teaser is configured to hide private content)
$check_otype = count($tease_otypes) && in_array('post', $tease_otypes) ? 'post' : $tease_otypes[0];
$post_type_obj = get_post_type_object($check_otype);
if (!scoper_get_otype_option('teaser_hide_private', $src_name, $check_otype) && (!$post_type_obj->hierarchical || scoper_get_otype_option('private_items_listable', 'post', 'page'))) {
if ($col_status && isset($otype_status_reqd_caps[$check_otype])) {
$status_or = "{$src_table}.{$col_status} = '" . implode("' OR {$src_table}.{$col_status} = '", array_keys($otype_status_reqd_caps[$check_otype])) . "'";
$where = str_replace($basic_status_clause['publish'], "( {$status_or} )", $where);
} else {
$where = str_replace($basic_status_clause['publish'], "1=1", $where);
}
}
}
}
return $where;
}
$is_administrator = is_content_administrator_rs();
// make sure administrators never have content limited
$status_or = '';
$status_where = array();
foreach ($otype_status_reqd_caps as $object_type => $status_reqd_caps) {
if (!is_array($status_reqd_caps)) {
rs_notice(sprintf('Role Scoper Configuration Error: reqd_caps for the %s data source must be array[operation][object_type][status] where operation is "read", "edit" or "admin".', $src_name));
return $where;
}
// don't bother generating these parameters if we're just going to pass the object type through for teaser filtering
if (!in_array($object_type, $tease_otypes)) {
if (true === $use_term_roles) {
// if boolean true was passed in, force usage of all term roles
if ('post' == $src_name) {
//$otype_use_term_roles = array_fill_keys( get_taxonomies( array( 'public' => true, 'object_type' => $object_type ) ), 1 );
$otype_use_term_roles = array();
foreach (get_taxonomies(array('public' => true), 'object') as $taxonomy => $taxonomy_obj) {
if (in_array($object_type, $taxonomy_obj->object_type)) {
$otype_use_term_roles[$taxonomy] = 1;
}
}
示例11: determine_role_usage_rs
function determine_role_usage_rs($src_name = 'post', $listed_ids = '')
{
global $scoper, $wpdb;
if ('post' != $src_name) {
return;
}
if (empty($listed_ids)) {
if (!empty($scoper->listed_ids[$src_name])) {
$listed_ids = $scoper->listed_ids[$src_name];
} else {
return;
}
}
if (empty($this->checked_ids[$src_name])) {
$this->checked_ids[$src_name] = array();
} else {
if (!array_diff_key($this->checked_ids[$src_name], $listed_ids)) {
return;
}
}
$this->checked_ids[$src_name] = $this->checked_ids[$src_name] + $listed_ids;
$src = $scoper->data_sources->get($src_name);
$col_id = $src->cols->id;
$col_type = isset($src->cols->type) ? $src->cols->type : '';
if ($viewing_object_type = cr_find_post_type()) {
$object_types = (array) $viewing_object_type;
} else {
$object_types = array_diff_key(get_post_types(array('public' => true)), array('attachment'));
}
// For now, only determine restricted posts if using RS role type.
// Backing this out will be more convoluted for WP role type; may need to just list which roles are restricted rather than trying to give an Restricted Read/Edit summary
$roles = array();
if (is_admin()) {
foreach ($object_types as $_post_type) {
$roles["edit"][$_post_type] = array("publish" => "rs_{$_post_type}_editor", "private" => "rs_{$_post_type}_editor", "draft" => "rs_{$_post_type}_contributor", "pending" => "rs_{$_post_type}_contributor", "future" => "rs_{$_post_type}_editor", "trash" => "rs_{$_post_type}_editor");
$roles["read"][$_post_type] = array("publish" => "rs_{$_post_type}_reader", "private" => "rs_private_{$_post_type}_reader", "draft" => "rs_{$_post_type}_reader", "pending" => "rs_{$_post_type}_reader", "future" => "rs_{$_post_type}_reader", "trash" => "rs_{$_post_type}_editor");
}
} else {
foreach ($object_types as $_post_type) {
$roles["read"][$_post_type] = array("publish" => "rs_{$_post_type}_reader", "private" => "rs_private_{$_post_type}_reader");
}
}
// which of these results ignore blog role assignments?
$uses_taxonomies = scoper_get_taxonomy_usage($src_name, $object_types);
if (!empty($uses_taxonomies)) {
foreach ($uses_taxonomies as $taxonomy) {
$tx_object_types = $object_types;
foreach ($tx_object_types as $key => $object_type) {
// ignore term restrictions / roles for object types which have them disabled
$_use_term_roles = scoper_get_otype_option('use_term_roles', $src_name, $object_type);
if (empty($_use_term_roles[$taxonomy])) {
unset($tx_object_types[$key]);
}
}
if (!$tx_object_types) {
continue;
}
if (!$scoper->taxonomies->is_member($taxonomy)) {
continue;
}
$qvars = $scoper->taxonomies->get_terms_query_vars($taxonomy);
$term_join = " INNER JOIN {$qvars->term->table} {$qvars->term->as} ON {$src->table}.{$src->cols->id} = {$qvars->term->alias}.{$qvars->term->col_obj_id} ";
// ======== Log term restrictions ========
//
if ($scoper->taxonomies->member_property($taxonomy, 'requires_term')) {
if ($strict_terms = $scoper->get_restrictions(TERM_SCOPE_RS, $taxonomy)) {
$this->any_restricted_terms = true;
}
$all_terms = $scoper->get_terms($taxonomy, UNFILTERED_RS, COL_ID_RS);
foreach (array_keys($roles) as $op_type) {
$status_where = array();
foreach ($tx_object_types as $object_type) {
$term_clauses = array();
foreach ($roles[$op_type][$object_type] as $status => $check_role) {
if (isset($strict_terms['restrictions'][$check_role]) && is_array($strict_terms['restrictions'][$check_role])) {
$this_strict_terms = array_keys($strict_terms['restrictions'][$check_role]);
} elseif (isset($strict_terms['unrestrictions'][$check_role]) && is_array($strict_terms['unrestrictions'][$check_role])) {
$this_strict_terms = array_diff($all_terms, array_keys($strict_terms['unrestrictions'][$check_role]));
} else {
$this_strict_terms = array();
}
if (!$this_strict_terms) {
// no terms in this taxonomy have restricted roles
$term_clauses[$status] = '1=2';
} elseif (count($this_strict_terms) < count($all_terms)) {
// some (but not all) terms in this taxonomy honor blog-wide assignment of the pertinent role
$term_clauses[$status] = " {$qvars->term->alias}.{$qvars->term->col_id} IN ('" . implode("', '", $this_strict_terms) . "')";
} else {
$term_clauses[$status] = '1=1';
}
if (isset($term_clauses[$status])) {
$status_where[$object_type][$status] = " {$src->cols->status} = '{$status}' AND ( {$term_clauses[$status]} ) ";
}
}
// end foreach statuses
if (isset($status_where[$object_type])) {
// object_type='type_val' AND ( (status 1 clause) OR (status 2 clause) ...
$status_where[$object_type] = " {$src->cols->type} = '{$object_type}' AND ( " . agp_implode(' ) OR ( ', $status_where[$object_type], ' ( ', ' ) ') . " )";
}
}
//.........这里部分代码省略.........
示例12: _flt_user_has_cap
//.........这里部分代码省略.........
$cache_tested_ids = array();
$cache_okay_ids = array();
$cache_where_clause = array();
} else {
$force_refresh = false;
}
// Check whether this object id was already tested for the same reqd_caps in a previous execution of this function within the same http request
if ($force_refresh || !isset($cache_tested_ids[$src_name][$object_type][$capreqs_key][$object_id])) {
//if ( ! isset($cache_tested_ids[$src_name][$object_type][$capreqs_key][$object_id]) ) {
// retrieve CR_Data_Source object, which contains database column names
$src_table = $this->scoper->data_sources->member_property($src_name, 'table');
$cols = $this->scoper->data_sources->member_property($src_name, 'cols');
// Before querying for caps on this object, check whether we have a record of other posts listed alongside it.
// If so, run the scoped query for ALL listed objects in that buffer, and buffer the results to static variable hascap_object_ids.
//
// (This is useful when front end code must check caps for each post
// to determine whether to display 'edit' link, etc.)
if (is_admin() && 'index.php' == $pagenow) {
// there's too much happening on the dashboard (and too much low-level query filtering) to buffer listed IDs reliably.
$listed_ids = array();
} else {
if (isset($this->scoper->listed_ids[$src_name])) {
$listed_ids = array_keys($this->scoper->listed_ids[$src_name]);
} else {
// note: don't use wp_object_cache because it includes posts not present in currently displayed resultset listing page
$listed_ids = array();
}
}
// make sure our current object_id is in the list
$listed_ids[] = $object_id;
// since the objects_where_role_clauses() output itself is not id-specific, also statically buffer it per reqd_caps
if ($force_refresh || !isset($cache_where_clause[$src_name][$object_type][$capreqs_key])) {
$check_otype = 'link_category' == $object_type ? 'link' : $object_type;
$use_term_roles = scoper_get_otype_option('use_term_roles', $src_name, $check_otype);
$no_object_roles = $this->scoper->data_sources->member_property($src_name, 'no_object_roles');
$use_object_roles = $no_object_roles ? false : scoper_get_otype_option('use_object_roles', $src_name, $object_type);
$this_args = array('object_type' => $object_type, 'user' => $user, 'otype_use_term_roles' => $use_term_roles, 'otype_use_object_roles' => $use_object_roles, 'skip_teaser' => true, 'require_full_object_role' => !empty($this->require_full_object_role));
//rs_errlog( serialize($rs_reqd_caps) );
//rs_errlog( serialize($this_args) );
$where = $this->query_interceptor->objects_where_role_clauses($src_name, $rs_reqd_caps, $this_args);
if ($where) {
$where = "AND ( {$where} )";
}
// update static variable
$cache_where_clause[$src_name][$object_type][$capreqs_key] = $where;
} else {
$where = $cache_where_clause[$src_name][$object_type][$capreqs_key];
}
// run the query
$query = "SELECT {$src_table}.{$cols->id} FROM {$src_table} WHERE 1=1 {$where} AND {$src_table}.{$cols->id} IN ('" . implode("', '", array_unique($listed_ids)) . "')";
if (isset($cache_okay_ids[$query])) {
$okay_ids = $cache_okay_ids[$query];
} else {
if ($okay_ids = scoper_get_col($query)) {
$okay_ids = array_fill_keys($okay_ids, true);
}
}
//dump($rs_reqd_caps);
//dump($query);
//dump($okay_ids);
//rs_errlog( $query );
//rs_errlog( 'results: ' . serialize( $okay_ids ) );
// update static cache_tested_ids to log scoped results for this object id, and possibly also for other listed IDs
if (empty($_GET['doaction']) || 'delete_post' != $args[0] && $object_type_obj->cap->delete_post != $args[0]) {
// bulk post/page deletion is broken by hascap buffering
foreach ($listed_ids as $_id) {
示例13: build_menu
function build_menu()
{
if (strpos($_SERVER['REQUEST_URI'], 'wp-admin/network/')) {
return;
}
global $plugin_page_cr;
if (!defined('USER_ROLES_RS') && isset($_POST['enable_group_roles'])) {
scoper_use_posted_init_options();
}
global $current_user;
$is_option_administrator = is_option_administrator_rs();
$is_user_administrator = is_user_administrator_rs();
$is_content_administrator = is_content_administrator_rs();
/*
// optional hack to prevent roles / restrictions menu for non-Administrators
//
// This is now handled as a Role Scoper Option.
// In Roles > Options > Features > Content Maintenance, set "Roles and Restrictions can be set" to "Administrators only"
//
// To prevent Role Scoper from filtering the backend at all, go to Roles > Options > Realm > Access Types and deselect "editing and administering content"
//
// end optional hack
*/
$require_blogwide_editor = scoper_get_option('role_admin_blogwide_editor_only');
if (!$is_content_administrator && 'admin_content' == $require_blogwide_editor) {
if (!$is_option_administrator) {
return;
}
}
if (!$is_user_administrator && 'admin' == $require_blogwide_editor) {
if (!$is_option_administrator) {
return;
}
}
$can_admin_objects = array();
$can_admin_terms = array();
$use_post_types = scoper_get_option('use_post_types');
$use_taxonomies = scoper_get_option('use_taxonomies');
// which object types does this user have any administration over?
foreach ($this->scoper->data_sources->get_all() as $src_name => $src) {
if (!empty($src->no_object_roles) || !empty($src->taxonomy_only) || 'group' == $src_name) {
continue;
}
$object_types = isset($src->object_types) ? $src->object_types : array($src_name => true);
foreach (array_keys($object_types) as $object_type) {
if ('post' == $src_name && empty($use_post_types[$object_type])) {
continue;
}
if (is_administrator_rs($src, 'user') || $this->user_can_admin_object($src_name, $object_type, 0, true)) {
if (scoper_get_otype_option('use_object_roles', "{$src_name}:{$object_type}")) {
$can_admin_objects[$src_name][$object_type] = true;
}
}
}
}
// which taxonomies does this user have any administration over?
foreach ($this->scoper->taxonomies->get_all() as $taxonomy => $tx) {
if (taxonomy_exists($taxonomy) && empty($use_taxonomies[$taxonomy]) && 'post' == $tx->object_source) {
continue;
}
if (is_taxonomy_used_rs($taxonomy) && (is_administrator_rs($tx->source, 'user') || $this->user_can_admin_terms($taxonomy))) {
$can_admin_terms[$taxonomy] = true;
}
}
// Users Tab
if (DEFINE_GROUPS_RS) {
$can_manage_groups = DEFINE_GROUPS_RS && ($is_user_administrator || current_user_can('recommend_group_membership'));
$cap_req = $can_manage_groups ? 'read' : 'manage_groups';
$groups_caption = defined('GROUPS_CAPTION_RS') ? GROUPS_CAPTION_RS : __('Role Groups', 'scoper');
if (!IS_MU_RS || !scoper_get_site_option('mu_sitewide_groups')) {
add_submenu_page('users.php', $groups_caption, $groups_caption, $cap_req, 'rs-groups', array(&$this, 'menu_handler'));
} elseif (IS_MU_RS && !awp_ver('3.1')) {
add_submenu_page("ms-admin.php", $groups_caption, $groups_caption, $cap_req, 'rs-groups', array(&$this, 'menu_handler'));
}
// satisfy WordPress' demand that all admin links be properly defined in menu
if ('rs-default_groups' == $plugin_page_cr) {
add_submenu_page('users.php', __('User Groups', 'scoper'), __('Default Groups', 'scoper'), $cap_req, 'rs-default_groups', array(&$this, 'menu_handler'));
}
if ('rs-group_members' == $plugin_page_cr) {
add_submenu_page('users.php', __('User Groups', 'scoper'), __('Group Members', 'scoper'), $cap_req, 'rs-group_members', array(&$this, 'menu_handler'));
}
}
// the rest of this function pertains to Roles and Restrictions menus
if (!$is_user_administrator && !$can_admin_terms && !$is_user_administrator && !$can_admin_objects) {
return;
}
$general_roles = $is_user_administrator;
// && scoper_get_option('rs_blog_roles'); // rs_blog_roles option has never been active in any RS release; leave commented here in case need arises
// determine the official WP-registered URL for roles and restrictions menus
$object_submenus_first = false;
$use_users_menu = defined('OZH_MENU_VER') && !defined('SCOPER_FORCE_ROLES_MENU') || defined('SCOPER_FORCE_USERS_MENU');
$tweak_menu = false;
if ($use_users_menu) {
$roles_menu = 'users.php';
$restrictions_menu = 'users.php';
if ($is_option_administrator) {
add_submenu_page($roles_menu, __('Role Options', 'scoper'), __('Role Options', 'scoper'), 'read', 'rs-options', array(&$this, 'menu_handler'));
}
} else {
if (!empty($can_admin_terms['category'])) {
//.........这里部分代码省略.........
示例14: flt_users_where
function flt_users_where($where, $reqd_caps = '', $object_src_name = '', $object_id = '', $args = array())
{
if (!USER_ROLES_RS && !GROUP_ROLES_RS) {
return $where;
}
global $wpdb;
static $stored_owner_id;
if (!isset($stored_owner_id)) {
$stored_owner_id = array();
}
$defaults = array('use_term_roles' => 1, 'use_blog_roles' => 1, 'skip_object_roles' => 0, 'querying_groups' => 0, 'ignore_group_roles' => false, 'ignore_user_roles' => false, 'object_type' => '', 'objscope_roles' => '', 'preserve_or_clause' => '', 'enforce_duration_limits' => true, 'enforce_content_date_limits' => true);
$args = array_merge($defaults, (array) $args);
extract($args);
// Default to not honoring custom user caps, but support option
$custom_user_blogcaps = SCOPER_CUSTOM_USER_BLOGCAPS;
// if reqd_caps are missing, try to determine context from URI
if (!$reqd_caps) {
return $where;
}
// no basis for filtering without required caps
$reqd_caps = (array) $reqd_caps;
// if rolenames are intermingled with caps in reqd_caps array, convert them to caps
$reqd_caps = $this->scoper->role_defs->role_handles_to_caps($reqd_caps, true);
//arg: also check for unprefixed WP rolenames
if ($object_id && !$object_src_name) {
$object_id = 0;
}
if ($object_id) {
foreach ($reqd_caps as $cap_name) {
if ($meta_caps = apply_filters('map_meta_cap_rs', (array) $cap_name, $cap_name, -1, $object_id)) {
$reqd_caps = array_diff($reqd_caps, array($cap_name));
$reqd_caps = array_unique(array_merge($reqd_caps, $meta_caps));
}
}
if ('post' == $object_src_name && ($use_term_roles || $use_blog_roles)) {
if ($post = get_post($object_id)) {
$object_date_gmt = $post->post_date_gmt;
}
} else {
$object_date_gmt = '';
}
}
$owner_has_all_caps = true;
// IMPORTANT: set this false downstream as appropriate
$rs_where = array();
// Group the required caps by object type (as defined by $scoper->cap_defs).
// The 2nd arg causes caps without an otype association to be included with a nullstring src_name key
// The 3rd arg forces caps with a data source other than $object_src to be also lumped in with sourceless caps
// $caps_by_otype[src_name][object_type] = array of cap names
$caps_by_otype = $this->scoper->cap_defs->organize_caps_by_otype($reqd_caps, true, $object_src_name, $object_type);
foreach ($caps_by_otype as $src_name => $otypes) {
if ($object_type) {
$otypes = array_intersect_key($otypes, array($object_type => 1));
}
// Cap reqs that pertain to other data sources or have no data source association
// will only be satisfied by blog roles.
$args['use_term_roles'] = $use_term_roles && $src_name == $object_src_name;
$args['skip_object_roles'] = $skip_object_roles || $src_name != $object_src_name;
$this_src_object_id = $src_name == $object_src_name ? $object_id : 0;
if ($src_name) {
if (!($src = $this->scoper->data_sources->get($src_name))) {
continue;
}
$uses_taxonomies = scoper_get_taxonomy_usage($src_name, array_keys($otypes));
if ($this_src_object_id && $args['use_term_roles'] && !empty($uses_taxonomies)) {
$args['object_terms'] = array();
foreach ($uses_taxonomies as $taxonomy) {
$args['object_terms'][$taxonomy] = $this->scoper->get_terms($taxonomy, UNFILTERED_RS, COL_ID_RS, $this_src_object_id);
}
}
}
foreach ($otypes as $object_type => $this_otype_caps) {
$qry_roles = array();
$args['use_term_roles'] = $args['use_term_roles'] && scoper_get_otype_option('use_term_roles', $src_name, $object_type);
//$caps_by_op = $this->scoper->cap_defs->organize_caps_by_op($this_otype_caps, true); //arg: retain caps which are not scoper-defined
//foreach ( $caps_by_op as $op => $this_op_caps ) {
foreach ($this_otype_caps as $cap_name) {
// If supporting custom user blogcaps, a separate role clause for each cap
// Otherwise (default) all reqd_caps from one role assignment (whatever scope it may be)
if ($custom_user_blogcaps) {
$reqd_caps_arg = array($cap_name);
} else {
$reqd_caps_arg = $this_otype_caps;
$cap_name = '';
}
// 'blog' argument forces inclusion of qualifying WP roles even if scoping with RS roles
// (will later strip out non-scopable roles for term role / object role clauses)
$args['roles'] = $this->scoper->role_defs->qualify_roles($reqd_caps_arg, '', '', array('all_wp_caps' => true));
if ($args['roles'] || !$src_name) {
if (USER_ROLES_RS && !$ignore_user_roles) {
$qry_roles[$cap_name]['general'][ROLE_BASIS_USER] = $this->users_queryroles($reqd_caps_arg, $src_name, $this_src_object_id, $args);
}
if (GROUP_ROLES_RS && !$ignore_group_roles) {
$qry_roles[$cap_name]['general'][ROLE_BASIS_GROUPS] = $this->users_queryroles($reqd_caps_arg, $src_name, $this_src_object_id, $args);
}
}
// potentially, a separate set of role clauses for object owner
if ($this_src_object_id && $src->cols->owner) {
$owner_needs_caps = $this->scoper->cap_defs->get_base_caps($reqd_caps_arg);
//returns array of caps the owner needs, after removing those which are credited to owners automatically
//.........这里部分代码省略.........
示例15: rs_tally_term_counts
function rs_tally_term_counts(&$terms, $taxonomy, $args = array())
{
global $wpdb, $scoper;
$defaults = array('pad_counts' => true, 'skip_teaser' => false, 'post_type' => '');
$args = array_merge($defaults, (array) $args);
extract($args);
if (!$terms) {
return;
}
$term_items = array();
$terms_by_id = array();
foreach ($terms as $key => $term) {
$terms_by_id[$term->term_id] =& $terms[$key];
$term_ids[$term->term_taxonomy_id] = $term->term_id;
// key and value will match for non-taxonomy category types
}
$tx_obj = get_taxonomy($taxonomy);
$post_types = array_unique((array) $tx_obj->object_type);
$enabled_types = array();
foreach ($post_types as $_post_type) {
if (scoper_get_otype_option('use_term_roles', 'post', $_post_type)) {
$enabled_types[] = $_post_type;
}
}
if (!$enabled_types) {
return;
}
if ($post_type) {
$post_type = (array) $post_type;
$enabled_types = array_intersect($enabled_types, $post_type);
}
// Get the object and term ids and stick them in a lookup table
$request = "SELECT DISTINCT {$wpdb->posts}.ID, tt.term_taxonomy_id, tt.term_id, tr.object_id" . " FROM {$wpdb->posts}" . " INNER JOIN {$wpdb->term_relationships} AS tr ON {$wpdb->posts}.ID = tr.object_id " . " INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id " . " WHERE tt.taxonomy = '{$taxonomy}' AND tt.term_id IN ('" . implode("','", $term_ids) . "') " . " AND {$wpdb->posts}.post_type IN ('" . implode("','", $enabled_types) . "')";
// no need to pass any parameters which do not pertain to the objects_request filter
$args = array_intersect_key($args, array_flip(array('skip_teaser')));
//$post_type = reset($enabled_types);
$post_type = $enabled_types;
// note: don't pass in a taxonomies arg because we need to consider restrictions associated with any taxonomy to determine readable objects for terms of this taxonomy
$request = apply_filters('objects_request_rs', $request, 'post', $post_type, $args);
$results = scoper_get_results($request);
foreach ($results as $row) {
$id = $term_ids[$row->term_taxonomy_id];
if (isset($term_items[$id][$row->object_id])) {
++$term_items[$id][$row->object_id];
} else {
$term_items[$id][$row->object_id] = 1;
}
}
// credit each term for every object contained in any of its descendant terms
if ($pad_counts && ScoperAncestry::get_terms_children($taxonomy)) {
foreach ($term_ids as $term_id) {
$child_term_id = $term_id;
while (isset($terms_by_id[$child_term_id]->parent)) {
if (!($parent_term_id = $terms_by_id[$child_term_id]->parent)) {
break;
}
if (!empty($term_items[$term_id])) {
foreach (array_keys($term_items[$term_id]) as $item_id) {
$term_items[$parent_term_id][$item_id] = 1;
}
}
$child_term_id = $parent_term_id;
}
}
}
// Tally and apply the item credits
foreach ($term_items as $term_id => $items) {
if (isset($terms_by_id[$term_id])) {
$terms_by_id[$term_id]->count = count($items);
}
}
// update count property for zero-item terms too
foreach (array_keys($terms_by_id) as $term_id) {
if (!isset($term_items[$term_id])) {
if (is_object($terms_by_id[$term_id])) {
$terms_by_id[$term_id]->count = 0;
}
}
}
}