function act_parse_query_for_direct_access(&$query) { if (empty($query->query_vars['attachment']) || false === strpos($_SERVER['QUERY_STRING'], 'rs_rewrite')) { //rs_errlog( 'not an attachment: ' . serialize($_SERVER) ); return; } require_once dirname(__FILE__) . '/attachment-filters_rs.php'; AttachmentFilters_RS::parse_query_for_direct_access($query); }
function parse_query_for_direct_access(&$query) { if (empty($query->query_vars['attachment']) || false === strpos($_SERVER['QUERY_STRING'], 'rs_rewrite')) { return; } $file = $query->query_vars['attachment']; require_once dirname(__FILE__) . '/uploads_rs.php'; $uploads = scoper_get_upload_info(); $return_attachment_id = 0; $matched_published_post = array(); if (AttachmentFilters_RS::_user_can_read_file($file, $return_attachment_id, $matched_published_post, $uploads)) { agp_return_file($file, $return_attachment_id); return; } // File access was not granted. Since a 404 page will now be displayed, add filters which (for performance) were suppressed on the direct file access request global $scoper; $scoper->direct_file_access = false; $scoper->add_main_filters(); $scoper->add_hardway_filters(); //Determine if teaser message should be triggered if (file_exists($uploads['basedir'] . "/{$file}")) { if ($matched_published_post && scoper_get_otype_option('do_teaser', 'post')) { foreach (array_keys($matched_published_post) as $object_type) { if ($use_teaser_type = scoper_get_otype_option('use_teaser', 'post', $object_type)) { if ($matched_published_post[$object_type]) { if (!defined('SCOPER_QUIET_FILE_404')) { // note: subsequent act_attachment_access will call impose_post_teaser() $will_tease = true; // will_tease flag only used within this function $wp_query->query_vars['attachment'] = $matched_published_post[$object_type]; break; } } } } } status_header(401); // Unauthorized if (empty($will_tease)) { // User is not qualified to access the requested attachment, and no teaser will apply // Normally, allow the function to return for WordPress 404 handling // But end script execution here if requested attachment is a media type (or if definition set) // Linking pages won't want WP html returned in place of inaccessable image / video if (defined('SCOPER_QUIET_FILE_404')) { exit; } // this may not be necessary $wp_query->is_404 = true; $wp_query->is_single = true; $wp_query->is_singular = true; $wp_query->query_vars['is_single'] = true; } } }