Changeset 983

Show
Ignore:
Timestamp:
12/21/06 22:39:36 (2 years ago)
Author:
bchoate
Message:

Applied rules for filtering results based on If-Modified-Since header for feeds from David Phillips. BugId: 33328

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/wheeljack/lib/MT/App/Search.pm

    r982 r983  
    1313 
    1414use File::Spec; 
    15 use MT::Util qw(encode_html ts2epoch); 
     15use MT::Util qw(encode_html ts2epoch epoch2ts); 
    1616use HTTP::Date qw(str2time time2str); 
    1717 
     
    419419    require MT::Entry; 
    420420 
    421     if ($app->{searchparam}{SearchCutoff} && 
    422         $app->{searchparam}{SearchCutoff} != 9999999) { 
    423         my @ago = MT::Util::offset_time_list(time - 3600 * 24 * 
    424             $app->{searchparam}{SearchCutoff}); 
    425         my $ago = sprintf "%04d%02d%02d%02d%02d%02d", 
    426             $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0]; 
    427         $terms{created_on} = [ $ago ]; 
     421    # Override SearchCutoff if If-Modified-Since header is present 
     422    if (my $mod_since = $app->get_header('If-Modified-Since')) { 
     423        my $tz_offset = 15;  # Start with maximum possible offset to UTC 
     424        my $blog_selected; 
     425        my $iter; 
     426        if ($app->{searchparam}{IncludeBlogs}) { 
     427            $iter = MT::Blog->load_iter({ id => [ keys %{ $app->{searchparam}{IncludeBlogs} }] }); 
     428        } else { 
     429            $iter = MT::Blog->load_iter; 
     430        } 
     431        while (my $blog = $iter->()) { 
     432            my $blog_offset = $blog->server_offset ? 
     433                $blog->server_offset : 0; 
     434            if ($blog_offset < $tz_offset) { 
     435                $tz_offset = $blog_offset; 
     436                $blog_selected = $blog; 
     437            } 
     438        } 
     439        $mod_since = epoch2ts($blog_selected, str2time($mod_since)); 
     440        $terms{created_on} = [ $mod_since ]; 
    428441        $args{range} = { created_on => 1 }; 
     442    } else { 
     443        if ($app->{searchparam}{SearchCutoff} && 
     444            $app->{searchparam}{SearchCutoff} != 9999999) { 
     445            my @ago = MT::Util::offset_time_list(time - 3600 * 24 * 
     446                $app->{searchparam}{SearchCutoff}); 
     447            my $ago = sprintf "%04d%02d%02d%02d%02d%02d", 
     448                $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0]; 
     449            $terms{created_on} = [ $ago ]; 
     450            $args{range} = { created_on => 1 }; 
     451        } 
    429452    } 
    430453 
     
    467490    my %args = (direction => $app->{searchparam}{ResultDisplay}, 
    468491                'sort' => 'created_on'); 
    469     if ($app->{searchparam}{SearchCutoff} && 
    470         $app->{searchparam}{SearchCutoff} != 9999999) { 
    471         my @ago = MT::Util::offset_time_list(time - 3600 * 24 * 
    472                   $app->{searchparam}{SearchCutoff}); 
    473         my $ago = sprintf "%04d%02d%02d%02d%02d%02d", 
    474             $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0]; 
    475         $terms{created_on} = [ $ago ]; 
     492    # Override SearchCutoff if If-Modified-Since header is present 
     493    if (my $mod_since = $app->get_header('If-Modified-Since')) { 
     494        my $tz_offset = 15;  # Start with maximum possible offset to UTC 
     495        my $blog_selected; 
     496        my $iter; 
     497        if ($app->{searchparam}{IncludeBlogs}) { 
     498            $iter = MT::Blog->load_iter({ id => [ keys %{ $app->{searchparam}{IncludeBlogs} }] }); 
     499        } else { 
     500            $iter = MT::Blog->load_iter; 
     501        } 
     502        while (my $blog = $iter->()) { 
     503            my $blog_offset = $blog->server_offset ? 
     504                $blog->server_offset : 0; 
     505            if ($blog_offset < $tz_offset) { 
     506                $tz_offset = $blog_offset; 
     507                $blog_selected = $blog; 
     508            } 
     509        } 
     510        $mod_since = epoch2ts($blog_selected, str2time($mod_since)); 
     511        $terms{created_on} = [ $mod_since ]; 
    476512        $args{range} = { created_on => 1 }; 
     513    } else { 
     514        if ($app->{searchparam}{SearchCutoff} && 
     515            $app->{searchparam}{SearchCutoff} != 9999999) { 
     516            my @ago = MT::Util::offset_time_list(time - 3600 * 24 * 
     517                      $app->{searchparam}{SearchCutoff}); 
     518            my $ago = sprintf "%04d%02d%02d%02d%02d%02d", 
     519                $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0]; 
     520            $terms{created_on} = [ $ago ]; 
     521            $args{range} = { created_on => 1 }; 
     522        } 
    477523    } 
    478524