Show
Ignore:
Timestamp:
03/12/09 09:11:52 (9 months ago)
Author:
fumiakiy
Message:

Merged sockfish to trunk. "svn merge -r3114:3527 http://code.sixapart.com/svn/movabletype/branches/sockfish/ ."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/MT/Template/Context.pm

    r3082 r3531  
    1 # Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd. 
     1# Movable Type (r) Open Source (C) 2001-2009 Six Apart, Ltd. 
    22# This program is distributed under the terms of the 
    33# GNU General Public License, version 2. 
     
    3030    my $ctx = shift; 
    3131    weaken($ctx->{config} = MT->config); 
     32    $ctx->stash('vars', {}); 
    3233    $ctx->init_handlers(); 
    3334    $ctx; 
     
    8283                    } 
    8384                    if (ref($block->{$orig_tag}) eq 'HASH') { 
    84                         $h->{$tag} = [ $block->{$orig_tag}{handler}, $type, $prev_hdlr ]; 
     85                        if ( $block->{$orig_tag}{handler} ) { 
     86                            $h->{$tag} = [ $block->{$orig_tag}{handler}, $type, $prev_hdlr ]; 
     87                        } 
    8588                    } else { 
    8689                        $h->{$tag} = [ $block->{$orig_tag}, $type, $prev_hdlr ]; 
     
    182185    my ($h) = $ctx->handler_for($tag) or return $ctx->error("No handler for tag $tag"); 
    183186    local $ctx->{__stash}{tag} = $tag; 
    184     return $h->($ctx, @_); 
     187    my ($args, $cond) = @_; 
     188    $args ||= {}; 
     189    my $out = $h->($ctx, $args, $cond); 
     190    if (defined $out) { 
     191        if (my $ph = $ctx->post_process_handler) { 
     192            $out = $ph->( $ctx, $args, $out ); 
     193        } 
     194    } 
     195    return $out; 
    185196} 
    186197 
     
    446457    foreach my $tag (@$tags) { 
    447458        my $name = $tag->name; 
     459        ## FIXME: this implementation can't handle tags which starts 
     460        ## with hash mark and numbers related. because they could break 
     461        ## our mid-compiled expression. now just skip them. 
     462        next if $name =~ /^\s*\#\d+\s*$/; 
    448463        my $id = $tag->id; 
    449         if ($tag_expr =~ s/(?<![#\d])\Q$name\E/#$id/g) { 
     464 
     465        ## search for tags from expression and replace them with its IDs. 
     466        ## allowed only existing tag name and some logical operators 
     467        ## ( AND, OR, NOT, and round brackets ). 
     468        if ($tag_expr =~ s/ 
     469                ( 
     470                    \sAND\s 
     471                    | \sOR\s 
     472                    | \s?NOT\s 
     473                    | \( 
     474                    | \A 
     475                ) 
     476                \s*? 
     477                \Q$name\E 
     478                \s*? 
     479                ( 
     480                    \Z 
     481                    | \) 
     482                    | \sAND\s 
     483                    | \sOR\s 
     484                    | \sNOT\s 
     485                ) 
     486            /$1#$id$2/igx) # Change all matches to #$id (e.g. #932) 
     487        { 
    450488            $tags_used{$id} = $tag; 
    451489        } 
     
    627665    $tag_name = 'mt' . $tag_name unless $tag_name =~ m/^MT/i; 
    628666    return $ctx->error(MT->translate( 
    629         "You used an '[_1]' tag outside of the context of an page; " . 
    630         "perhaps you mistakenly placed it outside of an 'MTPages' container?", 
     667        "You used an '[_1]' tag outside of the context of a page; " . 
     668        "perhaps you mistakenly placed it outside of a 'MTPages' container?", 
    631669        $tag_name 
    632670    ));