function _cme_update_pp_usage()
{
    static $updated;
    if (!empty($updated)) {
        return true;
    }
    if (!current_user_can('pp_manage_settings')) {
        return false;
    }
    if (!empty($_REQUEST['update_filtered_types'])) {
        // update Press Permit "Filtered Post Types".  This determines whether type-specific capability definitions are forced
        $options = array('enabled_post_types', 'enabled_taxonomies');
        foreach ($options as $option_basename) {
            if (!isset($_POST["{$option_basename}-options"])) {
                continue;
            }
            $unselected = array();
            $value = array();
            foreach ($_POST["{$option_basename}-options"] as $key) {
                if (empty($_POST["{$option_basename}-{$key}"])) {
                    $unselected[$key] = true;
                } else {
                    $value[$key] = true;
                }
            }
            if ($current = pp_get_option($option_basename)) {
                if ($current = array_diff_key($current, $unselected)) {
                    $value = array_merge($current, $value);
                }
                // retain setting for any types which were previously enabled for filtering but are currently not registered
            }
            $value = stripslashes_deep($value);
            pp_update_option($option_basename, $value);
            $updated = true;
        }
        if (pp_wp_ver('3.5')) {
            pp_update_option('define_create_posts_cap', !empty($_REQUEST['pp_define_create_posts_cap']));
        }
    }
    if (!empty($_REQUEST['SaveRole'])) {
        if (!empty($_REQUEST['role'])) {
            $pp_only = (array) pp_get_option('supplemental_role_defs');
            if (empty($_REQUEST['pp_only_role'])) {
                $pp_only = array_diff($pp_only, array($_REQUEST['role']));
            } else {
                $pp_only[] = $_REQUEST['role'];
            }
            pp_update_option('supplemental_role_defs', array_unique($pp_only));
            _cme_pp_default_pattern_role($_REQUEST['role']);
        }
    }
    if ($updated) {
        pp_refresh_options();
    }
    return $updated;
}
 public static function activate_key()
 {
     if (PP_MULTISITE && !is_super_admin() && (pp_is_network_activated(PPC_BASENAME) || pp_is_mu_plugin(PPC_FILE))) {
         return;
     }
     require_once dirname(__FILE__) . '/plugin_pp.php';
     $request_vars = array('key' => pp_sanitize_key($_GET['key']), 'site' => site_url(''));
     $response = PP_Plugin_Status::callhome('activate-key', $request_vars);
     $result = json_decode($response);
     if ($result[0] == "1") {
         pp_update_option('support_key', $result);
     }
     echo $response;
     exit;
 }
Exemple #3
0
 function update_page_options($args)
 {
     global $pp_default_options;
     do_action('pp_update_options', $args);
     $default_prefix = apply_filters('pp_options_apply_default_prefix', '', $args);
     foreach (explode(',', $_POST['all_options']) as $option_basename) {
         $value = isset($_POST[$option_basename]) ? $_POST[$option_basename] : '';
         if (!is_array($value)) {
             $value = trim($value);
         }
         if ('beta_updates' == $option_basename) {
             if (stripslashes_deep($value) != pp_get_option('beta_updates')) {
                 // force regeneration and buffering of file update urls
                 delete_site_transient('update_plugins');
                 pp_get_version_info(true, false, true);
                 wp_update_plugins();
             }
         }
         pp_update_option($default_prefix . $option_basename, stripslashes_deep($value), $args);
     }
     foreach (explode(',', $_POST['all_otype_options']) as $option_basename) {
         // support stored default values (to apply to any post type which does not have an explicit setting)
         if (isset($_POST[$option_basename][0])) {
             $_POST[$option_basename][''] = $_POST[$option_basename][0];
             unset($_POST[$option_basename][0]);
         }
         $value = isset($pp_default_options[$option_basename]) ? $pp_default_options[$option_basename] : array();
         if ($current = pp_get_option($option_basename)) {
             // retain setting for any types which were previously enabled for filtering but are currently not registered
             $value = array_merge($value, $current);
         }
         if (isset($_POST[$option_basename])) {
             $value = array_merge($value, $_POST[$option_basename]);
         }
         foreach (array_keys($value) as $key) {
             $value[$key] = stripslashes_deep($value[$key]);
         }
         pp_update_option($default_prefix . $option_basename, $value, $args);
     }
     if (!empty($_POST['post_blockage_priority'])) {
         // once this is switched on manually, don't ever default-disable it again
         if (get_option('ppperm_legacy_exception_handling')) {
             delete_option('ppperm_legacy_exception_handling');
             require_once dirname(__FILE__) . '/admin/admin-load_pp.php';
             _pp_dashboard_dismiss_msg();
         }
     }
     if (!empty($_POST['do_group_index_drop'])) {
         if (get_option('pp_need_group_index_drop')) {
             require_once dirname(__FILE__) . '/admin/update_pp.php';
             PP_Updated::do_index_drop(PP_Updated::drop_group_indexes_sql(), 'pp_did_group_index_drop');
             delete_option('pp_need_group_index_drop');
         }
     }
 }
Exemple #4
0
/**
 * Retrieve the Permission Group object for a WP Role or other metagroup, by providing its name
 * @param string metagroup_type
 * @param string metagroup_id
 * @param array args :
 *   - cols (return format - 'all' | 'id')
 * @return object Permission Group (unless cols = 'id')
 *  - ID
 *  - group_name
 *  - group_description
 *  - metagroup_type
 *  - metagroup_id
 */
function pp_get_metagroup($metagroup_type, $metagroup_id, $args = array())
{
    $defaults = array('cols' => 'all');
    extract(array_merge($defaults, $args), EXTR_SKIP);
    global $wpdb;
    $site_key = md5(get_option('site_url') . constant('DB_NAME') . $wpdb->prefix);
    // guard against groups table being imported into a different database (with mismatching options table)
    if (!($buffered_groups = pp_get_option("buffer_metagroup_id_{$site_key}"))) {
        $buffered_groups = array();
    }
    $key = $metagroup_id . ':' . $wpdb->pp_groups;
    // PP setting may change to/from netwide groups after buffering
    if (!isset($buffered_groups[$key])) {
        if ($group = $wpdb->get_row("SELECT * FROM {$wpdb->pp_groups} WHERE metagroup_type = '{$metagroup_type}' AND metagroup_id = '{$metagroup_id}' LIMIT 1")) {
            $group->group_id = $group->ID;
            $group->status = 'active';
            $buffered_groups[$key] = $group;
            pp_update_option("buffer_metagroup_id_{$site_key}", $buffered_groups);
        }
    }
    if ('id' == $cols) {
        return isset($buffered_groups[$key]) ? $buffered_groups[$key]->ID : false;
    } else {
        return isset($buffered_groups[$key]) ? $buffered_groups[$key] : false;
    }
}
 function processAdminGeneral($post)
 {
     global $wp_roles;
     // Create a new role.
     if (!empty($post['CreateRole'])) {
         if ($newrole = $this->createRole($post['create-name'])) {
             ak_admin_notify(__('New role created.', $this->cm->ID));
             $this->cm->current = $newrole;
         } else {
             if (empty($post['create-name']) && (!defined('WPLANG') || !WPLANG)) {
                 ak_admin_error('Error: No role name specified.', $this->cm->ID);
             } else {
                 ak_admin_error(__('Error: Failed creating the new role.', $this->cm->ID));
             }
         }
         // Copy current role to a new one.
     } elseif (!empty($post['CopyRole'])) {
         $current = get_role($post['current']);
         if ($newrole = $this->createRole($post['copy-name'], $current->capabilities)) {
             ak_admin_notify(__('New role created.', $this->cm->ID));
             $this->cm->current = $newrole;
         } else {
             if (empty($post['copy-name']) && (!defined('WPLANG') || !WPLANG)) {
                 ak_admin_error('Error: No role name specified.', $this->cm->ID);
             } else {
                 ak_admin_error(__('Error: Failed creating the new role.', $this->cm->ID));
             }
         }
         // Save role changes. Already saved at start with self::saveRoleCapabilities().
     } elseif (!empty($post['SaveRole'])) {
         if (MULTISITE) {
             global $wp_roles;
             if (method_exists($wp_roles, 'reinit')) {
                 $wp_roles->reinit();
             }
         }
         $this->saveRoleCapabilities($post['current'], $post['caps'], $post['level']);
         if (defined('PP_ACTIVE')) {
             // log customized role caps for subsequent restoration
             // for bbPress < 2.2, need to log customization of roles following bbPress activation
             $plugins = function_exists('bbp_get_version') && version_compare(bbp_get_version(), '2.2', '<') ? array('bbpress.php') : array();
             // back compat
             if (!($customized_roles = get_option('pp_customized_roles'))) {
                 $customized_roles = array();
             }
             $customized_roles[$post['role']] = (object) array('caps' => array_map('boolval', $post['caps']), 'plugins' => $plugins);
             update_option('pp_customized_roles', $customized_roles);
             global $wpdb;
             $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = 'pp_customized_roles'");
         }
         // Create New Capability and adds it to current role.
     } elseif (!empty($post['AddCap'])) {
         if (MULTISITE) {
             global $wp_roles;
             if (method_exists($wp_roles, 'reinit')) {
                 $wp_roles->reinit();
             }
         }
         $role = get_role($post['current']);
         $role->name = $post['current'];
         // bbPress workaround
         if ($newname = $this->createNewName($post['capability-name'])) {
             $role->add_cap($newname['name']);
             $this->cm->message = __('New capability added to role.');
             // for bbPress < 2.2, need to log customization of roles following bbPress activation
             $plugins = function_exists('bbp_get_version') && version_compare(bbp_get_version(), '2.2', '<') ? array('bbpress.php') : array();
             // back compat
             if (!($customized_roles = get_option('pp_customized_roles'))) {
                 $customized_roles = array();
             }
             $customized_roles[$post['role']] = (object) array('caps' => array_merge($role->capabilities, array($newname['name'] => 1)), 'plugins' => $plugins);
             update_option('pp_customized_roles', $customized_roles);
             global $wpdb;
             $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = 'pp_customized_roles'");
         } else {
             $this->cm->message = __('Incorrect capability name.');
         }
     } elseif (!empty($post['update_filtered_types'])) {
         if (cme_update_pp_usage()) {
             ak_admin_notify(__('Capability settings saved.', $this->cm->ID));
         } else {
             ak_admin_error(__('Error saving capability settings.', $this->cm->ID));
         }
     } else {
         // TODO: Implement exceptions. This must be a fatal error.
         ak_admin_error(__('Bad form received.', $this->cm->ID));
     }
     if (!empty($newrole) && defined('PP_ACTIVE')) {
         if (!empty($post['CreateRole']) && !empty($_REQUEST['new_role_pp_only']) || !empty($post['CopyRole']) && !empty($_REQUEST['copy_role_pp_only'])) {
             $pp_only = (array) pp_get_option('supplemental_role_defs');
             $pp_only[] = $newrole;
             pp_update_option('supplemental_role_defs', $pp_only);
             _cme_pp_default_pattern_role($newrole);
             pp_refresh_options();
         }
     }
 }
 /**
  * Prepare the query variables
  *
  * @access private
  */
 function prepare_query()
 {
     global $wpdb;
     $qv =& $this->query_vars;
     $groups_table = apply_filters('pp_use_groups_table', $wpdb->pp_groups, $this->agent_type);
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $this->query_fields[] = $groups_table . '.' . esc_sql($field);
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$groups_table}.*";
     } else {
         $this->query_fields = "{$groups_table}.ID";
     }
     $this->query_from = "FROM {$groups_table}";
     $this->query_where = "WHERE 1=1";
     $group_variant = isset($_REQUEST['group_variant']) ? pp_sanitize_key($_REQUEST['group_variant']) : '';
     $group_variant = apply_filters('pp_query_group_variant', $group_variant);
     $require_meta_types = array();
     if ('wp_role' == $group_variant) {
         $require_meta_types[] = 'wp_role';
     }
     if ($require_meta_types) {
         $this->query_where .= " AND {$groups_table}.metagroup_type IN ('" . implode("','", $require_meta_types) . "')";
     }
     $skip_meta_types = array();
     if ($group_variant && 'wp_role' != $group_variant) {
         $skip_meta_types[] = 'wp_role';
     } else {
         $pp_only_roles = (array) pp_get_option('supplemental_role_defs');
         if (defined('CAPSMAN_ENH_VERSION') && version_compare(CAPSMAN_ENH_VERSION, '1.4.10', '<')) {
             // version 1.4.9 and earlier stored redundant elements
             $_pp_only_roles = (array) $pp_only_roles;
             $pp_only_roles = array_unique($pp_only_roles);
             if (count($pp_only_roles) != count($_pp_only_roles)) {
                 pp_update_option('supplemental_role_defs', $pp_only_roles);
             }
         }
         if (pp_get_option('anonymous_unfiltered')) {
             $pp_only_roles = array_merge($pp_only_roles, array('wp_anon', 'wp_all'));
         }
         $pp_only_roles = implode("','", $pp_only_roles);
         $this->query_where .= " AND ( ( {$groups_table}.metagroup_type != 'wp_role' ) OR ( {$groups_table}.metagroup_id NOT IN ( '{$pp_only_roles}' ) ) )";
     }
     if ($skip_meta_types) {
         $this->query_where .= " AND {$groups_table}.metagroup_type NOT IN ('" . implode("','", $skip_meta_types) . "')";
     }
     global $wp_roles;
     $admin_roles = array();
     if (isset($wp_roles->role_objects)) {
         foreach (array_keys($wp_roles->role_objects) as $wp_role_name) {
             if (!empty($wp_roles->role_objects[$wp_role_name]->capabilities['pp_administer_content']) || !empty($wp_roles->role_objects[$wp_role_name]->capabilities['pp_unfiltered'])) {
                 $admin_roles[$wp_role_name] = true;
             }
         }
     }
     if ($admin_roles) {
         $this->query_where .= " AND {$groups_table}.metagroup_id NOT IN ('" . implode("','", array_keys($admin_roles)) . "')";
     }
     $skip_meta_ids = array();
     if (!defined('RVY_VERSION') || defined('SCOPER_DEFAULT_MONITOR_GROUPS') || defined('PP_DEFAULT_MONITOR_GROUPS')) {
         $skip_meta_ids = array_merge($skip_meta_ids, array('rv_pending_rev_notice_ed_nr_', 'rv_scheduled_rev_notice_ed_nr_'));
     }
     if ($skip_meta_ids) {
         $this->query_where .= " AND {$groups_table}.metagroup_id NOT IN ('" . implode("','", $skip_meta_ids) . "')";
     }
     //$this->query_where .= "AND $groups_table.metagroup_id != 'wp_anon'";
     // sorting
     if ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) {
         $orderby = 'ID';
     } else {
         $orderby = 'group_name';
     }
     $qv['order'] = strtoupper($qv['order']);
     if ('ASC' == $qv['order']) {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     $this->query_orderby = "ORDER BY {$orderby} {$order}";
     // limit
     if ($qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
         }
     }
     $search = trim($qv['search']);
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         if (is_numeric($search)) {
             $search_columns = array('ID');
         } else {
             $search_columns = array('group_name');
         }
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     // if user cannot edit all groups, filter displayed groups based on group-specific role assignments
     if (!pp_is_user_administrator()) {
         $reqd_caps = apply_filters('pp_edit_groups_reqd_caps', 'pp_manage_members', 'edit-group');
         if (!current_user_can($reqd_caps)) {
             global $wpdb, $pp_current_user;
             $exc_agent_type = in_array($this->agent_type, array('pp_group', 'pp_net_group')) ? 'pp_group' : $this->agent_type;
             $group_ids = isset($pp_current_user->except['manage_' . $exc_agent_type][$exc_agent_type]['']['additional'][$exc_agent_type]['']) ? $pp_current_user->except['manage_' . $exc_agent_type][$exc_agent_type]['']['additional'][$exc_agent_type][''] : array();
             $this->query_where .= " AND {$groups_table}.ID IN ('" . implode("','", $group_ids) . "')";
         }
     }
     $blog_id = absint($qv['blog_id']);
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$groups_table}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$groups_table}.ID NOT IN ({$ids})";
     }
     do_action_ref_array('pp_pre_group_query', array(&$this));
 }
Exemple #7
0
 public static function get_version_info($force_refresh = false, $return_all = false, $update_transient = false)
 {
     $updates = get_site_transient('ppc_update_info');
     // pull current stored values from DB
     if (!is_object($updates)) {
         $updates = (object) array('response' => array());
     }
     static $done;
     // sanity check - never call more than once in a single http request (but support exception to pull Available Extensions info)
     if (!empty($updates->response) && isset($done) && !($force_refresh || !$return_all)) {
         return $updates;
     }
     $done = true;
     $ext_by_basename = array();
     global $pp_extensions;
     foreach ($pp_extensions as $ext) {
         $ext_by_basename[$ext->basename] = $ext;
     }
     if (empty($_REQUEST['deactivate']) && empty($_REQUEST['deactivate-multi']) && ($force_refresh || empty($updates) || !isset($updates->response[PPC_BASENAME]) || array_diff_key($ext_by_basename, $updates->response))) {
         $raw_response = self::callhome("update-check-ppc");
         $all_updates = isset($raw_response->all) ? $raw_response->all : array();
         set_site_transient('ppc_all_updates', $all_updates);
         foreach ($pp_extensions as $ext_slug => $ext) {
             if (isset($raw_response->extensions) && isset($raw_response->extensions[$ext_slug])) {
                 $updates->response[$ext->basename] = (object) $raw_response->extensions[$ext_slug];
             } else {
                 $updates->response[$ext->basename] = false;
             }
         }
         unset($raw_response->extensions);
         $updates->response[PPC_BASENAME] = $raw_response;
         // for support key status and alerts
         if ($raw_response && -1 !== $raw_response) {
             if (!defined('UPDATED_PP_PLUGIN')) {
                 set_site_transient('ppc_update_info', $updates, 7200);
             }
             //caching for 2 hours
         }
     }
     if ($updates && !empty($updates->response)) {
         foreach ($updates->response as $info) {
             if (!empty($info->alert) && current_user_can('pp_manage_settings')) {
                 static $did_alerts;
                 if (!isset($did_alerts)) {
                     $did_alerts = array();
                 }
                 if (!isset($did_alerts[$info->slug])) {
                     global $pp_plugin_page;
                     if (empty($pp_plugin_page)) {
                         $message = '<span class="pp_alert">' . esc_html($info->alert) . '</span>';
                         add_action('admin_notices', create_function('', 'echo \'<div id="message" class="error fade" style="color: black">' . $message . '</div>\';'), 5);
                     }
                     $did_alerts[$info->slug] = true;
                 }
             }
         }
     }
     $plugin_updates = (object) get_site_transient('update_plugins');
     $any_update_modifications = false;
     if ($updates && !empty($updates->response)) {
         if (!empty($updates->response[PPC_BASENAME])) {
             if ($update_transient) {
                 // update expiration date (in case of new expiration approach, expiration or renewal)
                 $_key = pp_get_option('support_key');
                 if (!is_array($_key)) {
                     $_key = array();
                 }
                 if (isset($updates->response[PPC_BASENAME]->key_status)) {
                     $_key[0] = $updates->response[PPC_BASENAME]->key_status;
                 }
                 if (isset($updates->response[PPC_BASENAME]->expire_date_gmt)) {
                     $_key['expire_date_gmt'] = $updates->response[PPC_BASENAME]->expire_date_gmt;
                 } else {
                     unset($_key['expire_date_gmt']);
                 }
                 pp_update_option('support_key', $_key);
             }
         }
         foreach ($ext_by_basename as $ext_base => $ext) {
             if (!empty($updates->response[$ext_base]->package)) {
                 $plugin_updates->response[$ext_base] = (object) array('slug' => $ext->slug);
                 // Add this PP extension to the WP plugin update notification count
                 $any_update_modifications = true;
             } elseif (isset($plugin_updates->response) && isset($plugin_updates->response[$ext_base])) {
                 unset($plugin_updates->response[$ext_base]);
                 $any_update_modifications = true;
             }
         }
     }
     if ($update_transient && $any_update_modifications && !defined('UPDATED_PP_PLUGIN')) {
         set_site_transient('update_plugins', $plugin_updates);
     }
     if ($return_all) {
         return $all_updates;
     } else {
         return $updates;
     }
 }
function _cme_new_blog($new_blog_id)
{
    if ($autocreate_roles = get_site_option('cme_autocreate_roles')) {
        global $wp_roles, $blog_id;
        $restore_blog_id = $blog_id;
        switch_to_blog(1);
        $wp_roles->reinit();
        $main_site_caps = array();
        $role_captions = array();
        $admin_role = $wp_roles->get_role('administrator');
        $main_admin_caps = $admin_role->capabilities;
        if (defined('PP_ACTIVE')) {
            $main_pp_only = (array) pp_get_option('supplemental_role_defs');
        }
        //$pp_only[]= $newrole;
        foreach ($autocreate_roles as $role_name) {
            if ($role = get_role($role_name)) {
                $main_site_caps[$role_name] = $role->capabilities;
                $role_captions[$role_name] = $wp_roles->role_names[$role_name];
            }
        }
        switch_to_blog($new_blog_id);
        $wp_roles->reinit();
        if (defined('PP_ACTIVE')) {
            pp_refresh_options();
            $blog_pp_only = (array) pp_get_option('supplemental_role_defs');
        }
        foreach ($main_site_caps as $role_name => $caps) {
            if ($blog_role = $wp_roles->get_role($role_name)) {
                $stored_role_caps = !empty($blog_role->capabilities) && is_array($blog_role->capabilities) ? array_intersect($blog_role->capabilities, array(true, 1)) : array();
                // Find caps to add and remove
                $add_caps = array_diff_key($caps, $stored_role_caps);
                $del_caps = array_intersect_key(array_diff_key($stored_role_caps, $caps), $main_admin_caps);
                // don't mess with caps that are totally unused on main site
                // Add new capabilities to role
                foreach ($add_caps as $cap => $grant) {
                    $blog_role->add_cap($cap);
                }
                // Remove capabilities from role
                foreach ($del_caps as $cap => $grant) {
                    $blog_role->remove_cap($cap);
                }
            } else {
                $wp_roles->add_role($role_name, $role_captions[$role_name], $caps);
            }
            if (defined('PP_ACTIVE')) {
                if (in_array($role_name, $main_pp_only)) {
                    _cme_pp_default_pattern_role($role_name);
                    $blog_pp_only[] = $role_name;
                } else {
                    array_diff($blog_pp_only, array($role_name));
                }
            }
        }
        if (defined('PP_ACTIVE')) {
            pp_update_option('supplemental_role_defs', $blog_pp_only);
        }
        switch_to_blog($restore_blog_id);
        $wp_roles->reinit();
        if (defined('PP_ACTIVE')) {
            pp_refresh_options();
        }
    }
}