function scoper_filter_terms_for_status($taxonomy, $selected_terms, &$user_terms, $args = array())
{
    if (defined('DISABLE_QUERYFILTERS_RS') || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $selected_terms;
    }
    global $scoper;
    $defaults = array('object_id' => 0, 'object_type' => '', 'status' => '');
    $args = array_merge($defaults, $args);
    extract($args);
    if (!($tx = $scoper->taxonomies->get($taxonomy))) {
        return $selected_terms;
    }
    if (!($src = $scoper->data_sources->get($tx->object_source))) {
        return $selected_terms;
    }
    if (!isset($src->statuses) || count($src->statuses) < 2) {
        return $selected_terms;
    }
    if (!$object_id) {
        $object_id = scoper_get_object_id($src->name);
    }
    if (!$status) {
        // determine current post status
        if (defined('XMLRPC_REQUEST') && !empty($GLOBALS['scoper_xmlrpc_post_status'])) {
            $status = $GLOBALS['scoper_xmlrpc_post_status'];
        } else {
            if (!($status = $scoper->data_sources->get_from_http_post('status', $src))) {
                if ($object_id) {
                    $status = $scoper->data_sources->get_from_db('status', $src, $object_id);
                }
            }
        }
    }
    if (!$object_type) {
        if (!($object_type = cr_find_object_type($src->name, $object_id))) {
            if (defined('XMLRPC_REQUEST')) {
                $object_type = 'post';
            } else {
                return $selected_terms;
            }
        }
    }
    if ('auto-draft' == $status) {
        $status = 'draft';
    }
    // make sure _others caps are required only for objects current user doesn't own
    $base_caps_only = true;
    if ($object_id && !empty($src->cols->owner)) {
        $col_owner = $src->cols->owner;
        if ($object = $scoper->data_sources->get_object($src->name, $object_id)) {
            if (!empty($object->{$col_owner}) && $object->{$col_owner} != $GLOBALS['current_user']->ID) {
                $base_caps_only = false;
            }
        }
    }
    if (!($reqd_caps = cr_get_reqd_caps($src->name, OP_EDIT_RS, $object_type, $status, $base_caps_only))) {
        return $selected_terms;
    }
    $qualifying_roles = $scoper->role_defs->qualify_roles($reqd_caps);
    if ($qualifying_term_assigner_roles = $scoper->role_defs->qualify_roles(array("assign_{$taxonomy}"))) {
        $qualifying_roles = array_merge($qualifying_roles, $qualifying_term_assigner_roles);
    }
    $user_terms = $scoper->qualify_terms_daterange($reqd_caps, $taxonomy, $qualifying_roles);
    foreach (array_keys($user_terms) as $date_key) {
        $date_clause = '';
        if ($date_key && is_serialized($date_key)) {
            // Check stored post date against any role date limits associated whith this set of terms (if not stored, check current date)
            $content_date_limits = unserialize($date_key);
            $post_date_gmt = $object_id ? $scoper->data_sources->get_from_db('date', $src, $object_id) : 0;
            if (!$post_date_gmt) {
                $post_date_gmt = agp_time_gmt();
            }
            if ($post_date_gmt < $content_date_limits->content_min_date_gmt || $post_date_gmt > $content_date_limits->content_max_date_gmt) {
                unset($user_terms[$date_key]);
            }
        }
    }
    $user_terms = agp_array_flatten($user_terms);
    $selected_terms = array_intersect($selected_terms, $user_terms);
    return $selected_terms;
}
function scoper_expire_file_rules()
{
    if (IS_MU_RS) {
        scoper_update_option('file_htaccess_min_date', agp_time_gmt(), true);
    } else {
        if (did_action('scoper_init')) {
            scoper_flush_file_rules();
        } else {
            add_action('scoper_init', 'scoper_flush_file_rules');
        }
    }
}
 function set_agent_formatting($date_limits, &$title, &$limit_class, &$link_class, &$limit_style, $title_wrap = true)
 {
     static $current_gmt, $default_gmt_time, $gmt_seconds, $datef_no_time, $datef_time;
     static $starts_caption, $started_caption, $expired_caption, $expires_caption, $content_range_caption, $content_min_caption, $content_max_caption;
     if (!isset($current_gmt)) {
         $current_gmt = agp_time_gmt();
         $gmt_offset = get_option('gmt_offset');
         $gmt_seconds = $gmt_offset * 3600;
         $default_gmt_hour = -intval($gmt_offset);
         if ($default_gmt_hour < 0) {
             $default_gmt_hour = 24 + $default_gmt_hour;
         }
         $default_gmt_time = "{$default_gmt_hour}:00";
         // comparison string to determine whether date limit entry has a non-default time value
         if ($gmt_offset < 10) {
             $default_gmt_time = '0' . $default_gmt_time;
         }
         $datef_no_time = __awp('M j, Y');
         $datef_time = __awp('M j, Y G:i');
         $starts_caption = __('TO START on %s', 'scoper');
         $started_caption = __('started on %s', 'scoper');
         $expired_caption = __('EXPIRED on %s', 'scoper');
         $expires_caption = __('expire on %s', 'scoper');
         $content_range_caption = __('(for content %1$s to %2$s)', 'scoper');
         $content_min_caption = __('(for content after %1$s)', 'scoper');
         $content_max_caption = __('(for content before %1$s)', 'scoper');
     }
     $title_captions = array();
     $content_title_caption = '';
     if (!empty($date_limits['date_limited'])) {
         if ($date_limits['start_date_gmt'] != SCOPER_MIN_DATE_STRING) {
             $limit_class .= ' rs-has_start';
             $start_date_gmt = strtotime($date_limits['start_date_gmt']);
             $datef = strpos($date_limits['start_date_gmt'], $default_gmt_time) ? $datef_no_time : $datef_time;
             if ($start_date_gmt > $current_gmt) {
                 //$limit_class .= ' rs-future';
                 $limit_style = 'style="background-color: #cfc" ';
                 $title_captions[] = sprintf($starts_caption, agp_date_i18n($datef, $start_date_gmt + $gmt_seconds));
             } else {
                 $title_captions[] = sprintf($started_caption, agp_date_i18n($datef, $start_date_gmt + $gmt_seconds));
             }
         }
         if ($date_limits['end_date_gmt'] != SCOPER_MAX_DATE_STRING) {
             $limit_class .= ' rs-has_end';
             $end_date_gmt = strtotime($date_limits['end_date_gmt']);
             $datef = strpos($date_limits['end_date_gmt'], $default_gmt_time) ? $datef_no_time : $datef_time;
             if (strtotime($date_limits['end_date_gmt']) < $current_gmt) {
                 //$limit_class .= ' rs-expired';
                 $limit_style = 'style="background-color: #fcc" ';
                 $title_captions[] = sprintf($expired_caption, agp_date_i18n($datef, $end_date_gmt + $gmt_seconds));
             } else {
                 $title_captions[] = sprintf($expires_caption, agp_date_i18n($datef, $end_date_gmt + $gmt_seconds));
             }
         }
     }
     if (!empty($date_limits['content_date_limited'])) {
         if ($date_limits['content_min_date_gmt'] != SCOPER_MIN_DATE_STRING) {
             $limit_class .= ' rs-has_cmin';
             $link_class = 'rs-custom_link';
             $content_min_date_gmt = strtotime($date_limits['content_min_date_gmt']);
             $datef_min = strpos($date_limits['content_min_date_gmt'], $default_gmt_time) ? $datef_no_time : $datef_time;
         }
         if ($date_limits['content_max_date_gmt'] != SCOPER_MAX_DATE_STRING) {
             $limit_class .= ' rs-has_cmax';
             $content_max_date_gmt = strtotime($date_limits['content_max_date_gmt']);
             $datef_max = strpos($date_limits['content_max_date_gmt'], $default_gmt_time) ? $datef_no_time : $datef_time;
             if ($date_limits['content_min_date_gmt'] != SCOPER_MIN_DATE_STRING) {
                 $content_title_caption = sprintf($content_range_caption, agp_date_i18n($datef_min, $content_min_date_gmt + $gmt_seconds), agp_date_i18n($datef_max, $content_max_date_gmt + $gmt_seconds));
             } else {
                 $content_title_caption = sprintf($content_max_caption, agp_date_i18n($datef_max, $content_max_date_gmt + $gmt_seconds));
             }
         } else {
             $content_title_caption = sprintf($content_min_caption, agp_date_i18n($datef_min, $content_min_date_gmt + $gmt_seconds));
         }
     }
     if ($title_captions || $content_title_caption) {
         $title = implode(", ", $title_captions) . ' ' . $content_title_caption;
     }
 }
 function resync_file_rules()
 {
     // Don't allow this to execute too frequently, to prevent abuse or accidental recursion
     if (agp_time_gmt() - get_option('last_htaccess_resync_rs') > 30) {
         update_option('last_htaccess_resync_rs', agp_time_gmt());
         // Only the files / uploads .htaccess for current blog is regenerated
         scoper_flush_file_rules();
         usleep(10000);
         // Allow 10 milliseconds for server to regather itself following .htaccess update
     }
 }