function scoper_maybe_expire_file_rules($new_option_value, $old_option_value)
{
    if ($old_option_value !== $new_option_value) {
        scoper_expire_file_rules();
    }
    return $new_option_value;
}
function scoper_requested_file_rule_expire()
{
    if (scoper_get_option('file_filtering')) {
        if ($key = scoper_get_option('file_filtering_regen_key')) {
            if (!empty($_GET['key']) && $key == $_GET['key']) {
                // user must store their own non-null key before this will work
                global $wpdb;
                if (IS_MU_RS) {
                    $blog_ids = scoper_get_col("SELECT blog_id FROM {$wpdb->blogs} ORDER BY blog_id");
                    $orig_blog_id = $GLOBALS['blog_id'];
                    foreach ($blog_ids as $id) {
                        switch_to_blog($id);
                        scoper_query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_rs_file_key'");
                    }
                } else {
                    scoper_query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_rs_file_key'");
                }
                scoper_expire_file_rules();
                if (IS_MU_RS) {
                    _e("File attachment access keys and rewrite rules will be regenerated for each site at next access.", 'scoper');
                } else {
                    _e("File attachment access keys and rewrite rules were regenerated.", 'scoper');
                }
            } else {
                _e('Invalid argument.', 'scoper');
            }
        } else {
            _e('Please configure File Filtering options!', 'scoper');
        }
    } else {
        _e('The function is disabled.', 'scoper');
    }
    exit(0);
}
 function _scoper_activate()
 {
     // set_current_user may have triggered DB setup already
     if (empty($GLOBALS['scoper_db_setup_done'])) {
         require_once dirname(__FILE__) . '/db-setup_rs.php';
         $ver = (array) get_option('scoper_version');
         $db_ver = isset($ver['db_version']) ? $ver['db_version'] : '';
         scoper_db_setup($db_ver);
     }
     require_once dirname(__FILE__) . '/admin/admin_lib_rs.php';
     ScoperAdminLib::sync_wproles();
     scoper_flush_site_rules();
     scoper_expire_file_rules();
 }
function scoper_apply_constants($stored_options)
{
    // If file filtering option is on but the DISABLE constant has been set, turn the option off and regenerate .htaccess
    if (defined('DISABLE_ATTACHMENT_FILTERING') && DISABLE_ATTACHMENT_FILTERING) {
        if (!empty($stored_options['scoper_file_filtering'])) {
            // in this case, we need to both convert the option value to constant value AND trigger .htaccess regeneration
            $stored_options['file_filtering'] = 0;
            update_option('scoper_file_filtering', 0);
            scoper_flush_site_rules();
            scoper_expire_file_rules();
        }
    }
    return $stored_options;
}
Example #5
0
 function admin_head_base()
 {
     if (isset($_POST['rs_defaults'])) {
         // User asked to restore default options, so restore htaccess rule for attachment filtering (if it's not disabled)
         scoper_flush_site_rules();
         scoper_expire_file_rules();
     }
 }
function scoper_version_updated($prev_version)
{
    if (function_exists('wpp_cache_flush')) {
        wpp_cache_flush_all_sites();
    }
    // single-pass do loop to easily skip unnecessary version checks
    do {
        // roles were stored with invalid assign_for value under some conditions
        if (version_compare($prev_version, '1.3.45-beta', '<')) {
            global $wpdb;
            scoper_query("UPDATE {$wpdb->user2role2object_rs} SET assign_for = 'entity' WHERE assign_for = ''");
        }
        // file filtering rules were not written for new attachments if restriction was based solely on category restrictions
        if (version_compare($prev_version, '1.3.29-beta', '<')) {
            scoper_flush_site_rules();
            scoper_expire_file_rules();
        }
        // Delete any roles or restrictions inappropriately stored for attachments, revisions or auto-drafts
        if (version_compare($prev_version, '1.3', '<')) {
            global $wpdb;
            scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE role_type = 'wp' AND scope='blog' AND obj_or_term_id = '0'");
            scoper_sync_wproles();
            scoper_query("DELETE FROM {$wpdb->role_scope_rs} WHERE src_or_tx_name = 'post' AND obj_or_term_id IN ( SELECT ID FROM {$wpdb->posts} WHERE post_type IN ('attachment', 'revision') OR post_status = 'auto-draft' )");
            scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE src_or_tx_name = 'post' AND obj_or_term_id IN ( SELECT ID FROM {$wpdb->posts} WHERE post_type IN ('attachment', 'revision') OR post_status = 'auto-draft' )");
        }
        // 1.3.RC4 changed RS cache path to subfolder, so flush the root-stored cache one last time (only for MU / Multisite due to potentially large # of folders, files)
        if (IS_MU_RS && version_compare($prev_version, '1.3.RC4', '<') && !defined('SKIP_CACHE_MAINT_RS')) {
            global $wpp_object_cache;
            $wpp_object_cache = new WP_Persistent_Object_Cache(false);
            $wpp_object_cache->global_groups = array('');
            // forces use of cache root for this maint operation
            $wpp_object_cache->rm_cache_dir('');
            // will delete any files and folders in cache root except .htaccess
            $wpp_object_cache->cache_enabled = false;
            // avoid further updating cache in this http session
        }
        // 1.2.8 Beta disabled caps for custom post type roles under some circumstances
        if (version_compare($prev_version, '1.2.7', '>') && version_compare($prev_version, '1.2.8', '<')) {
            if ($disabled_role_caps = get_option('scoper_disabled_role_caps')) {
                $okay_role_prefix = array('rs_post', 'rs_page', 'rs_category', 'rs_link', 'rs_ngg');
                foreach (array_keys($disabled_role_caps) as $role_handle) {
                    $role_okay = false;
                    foreach ($okay_role_prefix as $pfx) {
                        if (0 === strpos($role_handle, $pfx)) {
                            $role_okay = true;
                            break;
                        }
                    }
                    if (!$role_okay) {
                        unset($disabled_role_caps[$role_handle]);
                        $_modified = true;
                    }
                }
                if (!empty($_modified)) {
                    update_option('scoper_disabled_role_caps', $disabled_role_caps);
                }
            }
        }
        // changes to taxonomy options storage in 1.1.8
        if (version_compare($prev_version, '1.1.8', '<')) {
            global $wp_taxonomies;
            $enable_tx = get_option('scoper_enable_wp_taxonomies');
            $old_use_term_roles = get_option('scoper_use_term_roles');
            $use_term_roles = array();
            if (is_array($old_use_term_roles)) {
                // convert existing use_term_roles entries to new array key structure
                foreach ($old_use_term_roles as $src_otype => $val) {
                    if (is_array($val)) {
                        // don't do this twice!
                        break 2;
                    }
                    if (strpos($src_otype, ':')) {
                        $arr_src_otype = explode(':', $src_otype);
                        $src_name = $arr_src_otype[0];
                        if ('post' == $src_name) {
                            $use_term_roles[$src_otype]['category'] = intval($val);
                        } elseif ('link' == $src_name) {
                            $use_term_roles[$src_otype]['link_category'] = intval($val);
                        } elseif ('ngg_gallery' == $src_name) {
                            $use_term_roles[$src_otype]['ngg_album'] = intval($val);
                        }
                        // compat workaround for old versions of Role Scoping for NGG which use old otype option key structure
                    }
                }
            }
            if (is_array($enable_tx)) {
                // Post_tag and custom taxonomies were activated for scoping via enable_wp_taxonomies storage.  Move those entries to use_term_roles instead.
                foreach ($enable_tx as $taxonomy => $val) {
                    if ('post_tag' == $taxonomy) {
                        $use_term_roles['post:post'][$taxonomy] = intval($val);
                    } elseif ($taxonomy && !in_array($taxonomy, array('category', 'link_category'))) {
                        if ($wp_tx = get_taxonomy($taxonomy)) {
                            $object_types = (array) $wp_tx->object_type;
                            foreach ($object_types as $object_type) {
                                $use_term_roles["post:{$object_type}"][$taxonomy] = intval($val);
                            }
                        }
                    }
                }
            }
            if ($use_term_roles) {
                update_option('scoper_use_term_roles', $use_term_roles);
            }
            //delete_option( 'scoper_enable_wp_taxonomies' );
        } else {
            break;
        }
        if (version_compare($prev_version, '1.1', '<')) {
            // htaccess rules modified in v1.1
            scoper_flush_site_rules();
            scoper_expire_file_rules();
            // Option update did not set autoload to no prior to 1.1
            global $wpdb;
            $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name LIKE 'scoper_%' AND option_name != 'scoper_version'");
            // stopped storing needless postmeta data for parent=0 in 1.1
            global $wpdb;
            $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_value = '0' AND meta_key = '_scoper_last_parent'");
        } else {
            break;
        }
        // stopped using rs_get_page_children() in 1.0.8
        if (version_compare($prev_version, '1.0.8', '<')) {
            delete_option('scoper_page_children');
        } else {
            break;
        }
        if (version_compare($prev_version, '1.0.0', '<')) {
            include dirname(__FILE__) . '/update-legacy_rs.php';
            scoper_version_updated_from_legacy($prev_version);
        }
    } while (0);
    // end single-pass version check loop
}