Changeset 1926

Show
Ignore:
Timestamp:
04/16/08 10:50:21 (22 months ago)
Author:
takayama
Message:

Fixed BugId:76389
* Loop tags does not add 'glue', if row in loop tag was empty

  • MTFor
  • MTLoop
  • MTTags
  • MTEntryTags
  • MTEntries
  • MTEntryCategories
  • MTCategories
  • MTEntryAdditionalCategories
  • MTParentCategories
  • MTAssetTags
  • MTPagerBlock
Location:
branches/release-35
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/lib/MT/Template/ContextHandlers.pm

    r1911 r1926  
    13241324    my $vars = $ctx->{__stash}{vars} ||= {}; 
    13251325    my $glue = $args->{glue}; 
    1326     $glue = '' unless defined $glue; 
    13271326    my $var = $args->{var}; 
    13281327    for (my $i = $start; $i <= $end; $i += $incr) { 
     
    13361335        my $res = $builder->build($ctx, $tokens, $cond); 
    13371336        return $ctx->error($builder->errstr) unless defined $res; 
    1338         if ($res ne '') { 
    1339             $out .= $glue if $cnt > 1; 
    1340             $out .= $res; 
    1341             $cnt++; 
    1342         } 
     1337        $out .= $glue 
     1338            if defined $glue && $cnt > 1 && length($out) && length($res); 
     1339        $out .= $res; 
     1340        $cnt++; 
    13431341    } 
    13441342    return $out; 
     
    15901588    my $vars = $ctx->{__stash}{vars} ||= {}; 
    15911589    my $glue = $args->{glue}; 
    1592     $glue = '' unless defined $glue; 
    15931590    foreach my $item (@$var) { 
    15941591        local $vars->{__first__} = $i == 1; 
     
    16251622        return $ctx->error($builder->errstr) unless defined $res; 
    16261623        if ($res ne '') { 
    1627             $out .= $glue if $i > 1; 
     1624            $out .= $glue if defined $glue && $i > 1 && length($out) && length($res); 
    16281625            $out .= $res; 
    16291626            $i++; 
     
    19161913    my $tokens = $ctx->stash('tokens'); 
    19171914    my $needs_entries = (($ctx->stash('uncompiled') || '') =~ /<MT:?Entries/i) ? 1 : 0; 
    1918     my $glue = $args->{glue} || ''; 
     1915    my $glue = $args->{glue}; 
    19191916    my $res = ''; 
    19201917    local $ctx->{__stash}{all_tag_count} = undef; 
     
    19741971        defined(my $out = $builder->build($ctx, $tokens, $cond)) 
    19751972            or return $ctx->error( $builder->errstr ); 
    1976         $res .= $glue if $res ne ''; 
     1973        $res .= $glue if defined $glue && length($res) && length($out); 
    19771974        $res .= $out; 
    19781975    } 
     
    20972094    my $entry = $ctx->stash('entry'); 
    20982095    return '' unless $entry; 
    2099     my $glue = $args->{glue} || ''; 
     2096    my $glue = $args->{glue}; 
    21002097 
    21012098    local $ctx->{__stash}{tag_max_count} = undef; 
     
    21132110        defined(my $out = $builder->build($ctx, $tokens, $cond)) 
    21142111            or return $ctx->error( $builder->errstr ); 
    2115         $res .= $glue if $res ne ''; 
     2112        $res .= $glue if defined $glue && length($res) && length($out); 
    21162113        $res .= $out; 
    21172114    } 
     
    42294226        return $ctx->error( $builder->errstr ) unless defined $out; 
    42304227        $last_day = $this_day; 
    4231         $res .= $glue if defined $glue && $i; 
     4228        $res .= $glue if defined $glue && $i && length($res) && length($out); 
    42324229        $res .= $out; 
    42334230        $i++; 
     
    47394736    my $builder = $ctx->stash('builder'); 
    47404737    my $tokens = $ctx->stash('tokens'); 
    4741     my @res; 
     4738    my $res; 
     4739    my $glue = $args->{glue}; 
    47424740    for my $cat (@$cats) { 
    47434741        local $ctx->{__stash}->{category} = $cat; 
    47444742        defined(my $out = $builder->build($ctx, $tokens, $cond)) 
    47454743            or return $ctx->error( $builder->errstr ); 
    4746         push @res, $out if $out ne ''; 
    4747     } 
    4748     my $sep = $args->{glue} || ''; 
    4749     join $sep, @res; 
     4744        $res .= $glue if defined $glue && length($res) && length($out); 
     4745        $res .= $out; 
     4746    } 
     4747    $res; 
    47504748} 
    47514749 
     
    63146312    my $builder = $ctx->stash('builder'); 
    63156313    my $tokens = $ctx->stash('tokens'); 
    6316     my $glue = exists $args->{glue} ? $args->{glue} : ''; 
     6314    my $glue = $args->{glue}; 
    63176315    ## In order for this handler to double as the handler for 
    63186316    ## <MTArchiveList archive_type="Category">, it needs to support 
     
    63566354              ArchiveListFooter => $last })) 
    63576355            or return $ctx->error( $builder->errstr ); 
    6358         $res .= $glue if $res ne ''; 
     6356        $res .= $glue if defined $glue && length($res) && length($out); 
    63596357        $res .= $out; 
    63606358        $cat = $next_cat; 
     
    66376635    my $builder = $ctx->stash('builder'); 
    66386636    my $tokens = $ctx->stash('tokens'); 
    6639     my @res; 
     6637    my $res; 
     6638    my $glue = $args->{glue}; 
    66406639    for my $cat (@$cats) { 
    66416640        next if $e->category && ($cat->label eq $e->category->label); 
     
    66436642        defined(my $out = $builder->build($ctx, $tokens, $cond)) 
    66446643            or return $ctx->error( $builder->errstr ); 
    6645         push @res, $out; 
    6646     } 
    6647     my $sep = $args->{glue} || ''; 
    6648     join $sep, @res;  
     6644        $res .= $glue if defined $glue && length($res) && length($out); 
     6645        $res .= $out if length($out); 
     6646    } 
     6647    $res; 
    66496648} 
    66506649 
     
    71897188    # Get the arguments 
    71907189    my $exclude_current = $args->{'exclude_current'}; 
    7191     my $glue = $args->{'glue'} || ''; 
     7190    my $glue = $args->{'glue'}; 
    71927191 
    71937192    # Get the current category 
     
    71967195    return '' if ($cat eq ''); 
    71977196 
    7198     my @res; 
     7197    my $res; 
    71997198 
    72007199    # Put together the list of parent categories 
     
    72117210            $out = 'cat-' . $c->id; 
    72127211        } 
    7213         push @res, $out; 
    7214     } 
    7215  
    7216     # Slap them all together with some glue 
    7217     return join $glue, @res; 
     7212        $res .= $glue if defined $glue && length($res) && length($out); 
     7213        $res .= $out if length($out); 
     7214    } 
     7215    $res; 
    72187216} 
    72197217 
     
    79227920    my $asset = $ctx->stash('asset'); 
    79237921    return '' unless $asset; 
    7924     my $glue = $args->{glue} || ''; 
     7922    my $glue = $args->{glue}; 
    79257923 
    79267924    local $ctx->{__stash}{tag_max_count} = undef; 
     
    79437941        defined(my $out = $builder->build($ctx, $tokens, $cond)) 
    79447942            or return $ctx->error( $builder->errstr ); 
    7945         $res .= $glue if $res ne ''; 
     7943        $res .= $glue if defined $glue && length($res) && length($out); 
    79467944        $res .= $out; 
    79477945    } 
     
    88508848 
    88518849    my $glue = $args->{glue}; 
    8852     $glue = q() unless defined $glue; 
    88538850 
    88548851    my $output = q(); 
     
    88688865            } 
    88698866            )) or return $ctx->error( $build->errstr ); 
    8870         $output .= $glue if $i > 1; 
     8867        $output .= $glue if defined $glue && $i > 1 && length($output) && length($out); 
    88718868        $output .= $out; 
    88728869    } 
  • branches/release-35/php/lib/MTUtil.php

    r1800 r1926  
    891891        if ($ctx->stash('entry')) { 
    892892            $entry = $ctx->stash('entry'); 
     893            if (empty($entry['placement_category_id'])) 
     894                return null; 
    893895            if ($class == 'folder') 
    894896                $cat = $ctx->mt->db->fetch_folder($entry['placement_category_id']); 
  • branches/release-35/php/lib/block.mtassettags.php

    r1174 r1926  
    77 
    88function smarty_block_mtassettags($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count','all_tag_count'); 
     9    $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count','all_tag_count', '__out'); 
    1010    if (!isset($content)) { 
    1111        $ctx->localize($localvars); 
     
    3232        if (!is_array($tags)) $tags = array(); 
    3333        $ctx->stash('_tags', $tags); 
     34        $ctx->stash('__out', false); 
    3435         
    3536        $counter = 0; 
     
    3738        $tags = $ctx->stash('_tags'); 
    3839        $counter = $ctx->stash('_tags_counter'); 
     40        $out = $ctx->stash('__out'); 
    3941    } 
    4042    if ($counter < count($tags)) { 
     
    4345        $ctx->stash('_tags_counter', $counter + 1); 
    4446        $repeat = true; 
    45         if (($counter > 0) && isset($args['glue'])) { 
    46             $content = $content . $args['glue']; 
     47        if (isset($args['glue']) && !empty($content)) { 
     48            if ($out) 
     49                $content = $args['glue'] . $content; 
     50            else 
     51                $ctx->stash('__out', true); 
    4752        } 
    4853    } else { 
     54        if (isset($args['glue']) && $out && !empty($content)) 
     55            $content = $args['glue'] . $content; 
    4956        $ctx->restore($localvars); 
    5057        $repeat = false; 
  • branches/release-35/php/lib/block.mtcategories.php

    r1174 r1926  
    99    // status: incomplete 
    1010    // parameters: show_empty 
    11     $localvars = array('_categories', '_categories_counter', 'category', 'inside_mt_categories', 'entries', '_categories_glue', 'blog_id', 'blog'); 
     11    $localvars = array('_categories', '_categories_counter', 'category', 'inside_mt_categories', 'entries', '_categories_glue', 'blog_id', 'blog', '__out'); 
    1212    if (!isset($content)) { 
    1313        $ctx->localize($localvars); 
     
    1919        $ctx->stash('inside_mt_categories', 1); 
    2020        $ctx->stash('show_empty', isset($args['show_empty']) ? $args['show_empty'] : '0'); 
     21        $ctx->stash('__out', false); 
    2122        $counter = 0; 
    2223    } else { 
     
    2425        $counter = $ctx->stash('_categories_counter'); 
    2526        $glue = $ctx->stash('_categories_glue'); 
     27        $out =$ctx->stash('__out'); 
    2628    } 
    2729    if ($counter < count($categories)) { 
     
    3537        $ctx->stash('blog', 
    3638            $ctx->mt->db->fetch_blog($category['category_blog_id'])); 
    37         if ($counter > 0) $content = $content . $glue; 
     39        if (!empty($glue) && !empty($content)) { 
     40            if ($out) 
     41                $content = $glue . $content; 
     42            else 
     43                $ctx->stash('__out', true); 
     44        } 
    3845        $repeat = true; 
    3946    } else { 
     47        if (!empty($glue) && $out && !empty($content)) 
     48            $content = $glue . $content; 
    4049        $ctx->restore($localvars); 
    4150        $repeat = false; 
  • branches/release-35/php/lib/block.mtentries.php

    r1335 r1926  
    77 
    88function smarty_block_mtentries($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('entry', '_entries_counter','entries','current_timestamp','modification_timestamp','_entries_lastn', 'current_timestamp_end', 'DateHeader', 'DateFooter', '_entries_glue', 'blog', 'blog_id', 'conditional', 'else_content'); 
     9    $localvars = array('entry', '_entries_counter','entries','current_timestamp','modification_timestamp','_entries_lastn', 'current_timestamp_end', 'DateHeader', 'DateFooter', '_entries_glue', 'blog', 'blog_id', 'conditional', 'else_content', '__out'); 
    1010    if (isset($args['sort_by']) && $args['sort_by'] == 'score' && !isset($args['namespace'])) { 
    1111        return $ctx->error($ctx->mt->translate('sort_by="score" must be used in combination with namespace.')); 
     
    2929        $lastn = $args['lastn']; 
    3030        $ctx->stash('_entries_lastn', $lastn); 
     31        $ctx->stash('__out', false); 
    3132    } else { 
    3233        $lastn = $ctx->stash('_entries_lastn'); 
    3334        $counter = $ctx->stash('_entries_counter'); 
     35        $out = $ctx->stash('__out'); 
    3436    } 
    3537    if (!isset($args['class'])) { 
     
    119121        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1; 
    120122        $glue = $ctx->stash('_entries_glue'); 
    121         if ($glue != '') $content = $content . $glue; 
     123        if (isset($glue) && !empty($content)) { 
     124            if ($out) 
     125                $content = $glue . $content; 
     126            else 
     127                $ctx->stash('__out', true); 
     128        } 
    122129        $repeat = true; 
    123130    } else { 
     131        $glue = $ctx->stash('_entries_glue'); 
     132        if (isset($glue) && $out && !empty($content)) 
     133            $content = $glue . $content; 
    124134        $ctx->restore($localvars); 
    125135        $repeat = false; 
  • branches/release-35/php/lib/block.mtentryadditionalcategories.php

    r1174 r1926  
    77 
    88function smarty_block_mtentryadditionalcategories($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('_categories', 'category', '_categories_counter'); 
     9    $localvars = array('_categories', 'category', '_categories_counter', '__out'); 
    1010    if (!isset($content)) { 
    1111        $ctx->localize($localvars); 
     
    2323        } 
    2424        $ctx->stash('_categories', $categories); 
     25        $ctx->stash('__out', false); 
    2526        $counter = 0; 
    2627    } else { 
    2728        $categories = $ctx->stash('_categories'); 
    2829        $counter = $ctx->stash('_categories_counter'); 
     30        $out = $ctx->stash('__out'); 
    2931    } 
    3032    if ($counter < count($categories)) { 
     
    3335        $ctx->stash('_categories_counter', $counter + 1); 
    3436        $repeat = true; 
    35         if (($counter > 0) && isset($args['glue'])) { 
    36             $content = $content . $args['glue']; 
     37        if (isset($args['glue']) && !empty($content)) { 
     38            if ($out) 
     39                $content = $args['glue'] . $content; 
     40            else 
     41                $ctx->stash('__out', true); 
    3742        } 
    3843    } else { 
     44        if (isset($args['glue']) && $out && !empty($content)) 
     45            $content = $args['glue'] . $content; 
    3946        $ctx->restore($localvars); 
    4047        $repeat = false; 
  • branches/release-35/php/lib/block.mtentrycategories.php

    r1174 r1926  
    77 
    88function smarty_block_mtentrycategories($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('_categories', 'category', '_categories_counter'); 
     9  $localvars = array('_categories', 'category', '_categories_counter', '__out'); 
    1010    if (!isset($content)) { 
    1111        $ctx->localize($localvars); 
     
    1414        $categories = $ctx->mt->db->fetch_categories($args); 
    1515        $ctx->stash('_categories', $categories); 
     16        $ctx->stash('__out', false); 
    1617        $counter = 0; 
    1718    } else { 
    1819        $categories = $ctx->stash('_categories'); 
    1920        $counter = $ctx->stash('_categories_counter'); 
     21        $out = $ctx->stash('__out'); 
    2022    } 
    2123    if ($counter < count($categories)) { 
     
    2426        $ctx->stash('_categories_counter', $counter + 1); 
    2527        $repeat = true; 
    26         if (($counter > 0) && isset($args['glue'])) { 
    27             $content = $content . $args['glue']; 
     28        if (isset($args['glue']) && !empty($content)) { 
     29            if ($out) 
     30                $content = $args['glue'] . $content; 
     31            else 
     32                $ctx->stash('__out', true); 
    2833        } 
    2934    } else { 
     35        if (isset($args['glue']) && $out && !empty($content)) 
     36            $content = $args['glue'] . $content; 
    3037        $ctx->restore($localvars); 
    3138        $repeat = false; 
  • branches/release-35/php/lib/block.mtentrytags.php

    r1174 r1926  
    77 
    88function smarty_block_mtentrytags($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count','all_tag_count'); 
     9    $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count','all_tag_count', '__out'); 
    1010    if (!isset($content)) { 
    1111        $class = 'entry'; 
     
    3737        if (!is_array($tags)) $tags = array(); 
    3838        $ctx->stash('_tags', $tags); 
     39        $ctx->stash('__out', false); 
    3940         
    4041        $counter = 0; 
     
    4243        $tags = $ctx->stash('_tags'); 
    4344        $counter = $ctx->stash('_tags_counter'); 
     45        $out = $ctx->stash('__out'); 
    4446    } 
    4547    if ($counter < count($tags)) { 
     
    4850        $ctx->stash('_tags_counter', $counter + 1); 
    4951        $repeat = true; 
    50         if (($counter > 0) && isset($args['glue'])) { 
    51             $content = $content . $args['glue']; 
     52        if (isset($args['glue']) && !empty($content)) { 
     53            if ($out) 
     54                $content = $args['glue']. $content; 
     55            else 
     56                $ctx->stash('__out', true); 
    5257        } 
    5358    } else { 
     59        if (isset($args['glue']) && $out && !empty($content)) 
     60            $content = $args['glue']. $content; 
    5461        $ctx->restore($localvars); 
    5562        $repeat = false; 
  • branches/release-35/php/lib/block.mtfor.php

    r1174 r1926  
    77 
    88function smarty_block_mtfor($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('__for_end', '__for_var'); 
     9    $localvars = array('__for_end', '__for_var', '__out'); 
    1010 
    1111    if (!isset($content)) { 
     
    3030        $ctx->stash('__for_end', $end); 
    3131        $ctx->stash('__for_var', $var); 
     32        $ctx->stash('__out', false); 
    3233    } else { 
    3334        $index = $ctx->__stash['vars']['__index__'] + 1; 
     
    3536        $end = $ctx->stash('__for_end'); 
    3637        $var = $ctx->stash('__for_var'); 
     38        $out = $ctx->stash('__out'); 
    3739    } 
    3840 
     
    4648        if ($var) 
    4749            $ctx->__stash['vars'][$var] = $index; 
    48         if (array_key_exists('glue', $args)) { 
    49             if ($index < $end) 
    50                 $content = $content . $args['glue']; 
     50        if (isset($args['glue']) && !empty($content)) { 
     51            if ($out) 
     52                $content = $args['glue'] . $content; 
     53            else 
     54                $ctx->stash('__out', true); 
    5155        } 
    5256        $repeat = true; 
    5357    } else { 
     58        if (isset($args['glue']) && $out && !empty($content)) 
     59            $content = $args['glue'] . $content; 
    5460        $ctx->restore($localvars); 
    5561        $repeat = false; 
  • branches/release-35/php/lib/block.mtloop.php

    r1174 r1926  
    77 
    88function smarty_block_mtloop($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('__loop_keys', '__loop_values'); 
     9    $localvars = array('__loop_keys', '__loop_values', '__out'); 
    1010 
    1111    if (!isset($content)) { 
     
    6767        $counter = 1; 
    6868        $ctx->stash('__loop_values', $value); 
     69        $ctx->stash('__out', false); 
    6970    } 
    7071    else { 
     
    7273        $keys = $ctx->stash('__loop_keys'); 
    7374        $value = $ctx->stash('__loop_values'); 
     75        $out = $ctx->stash('__out'); 
    7476        if (!isset($keys) || $keys == 0) { 
    7577            $ctx->restore($localvars); 
    7678            $repeat = false; 
     79            if (isset($args['glue']) && $out && !empty($content)) 
     80                $content = $args['glue'] . $content; 
    7781            return $content; 
    7882        } 
     
    97101        } 
    98102    } 
    99     if (array_key_exists('glue', $args)) { 
    100         if (1 < $counter) 
    101             $content = $content . $args['glue']; 
     103    if (isset($args['glue']) && !empty($content)) { 
     104        if ($out) 
     105            $content = $args['glue'] . $content; 
     106        else 
     107            $ctx->stash('__out', true); 
    102108    } 
    103109    if ( 0 === count($keys) ) 
  • branches/release-35/php/lib/block.mtparentcategories.php

    r1800 r1926  
    2121 
    2222function smarty_block_mtparentcategories($args, $content, &$ctx, &$repeat) { 
    23     $localvars = array('_categories', 'category', '_categories_counter','glue'); 
     23    $localvars = array('_categories', 'category', '_categories_counter','glue', '__out'); 
    2424    if (!isset($content)) { 
    2525        $ctx->localize($localvars); 
     
    3939        $ctx->stash('_categories', $parents); 
    4040        $ctx->stash('glue', $glue); 
     41        $ctx->stash('__out', false); 
    4142        $counter = 0; 
    4243    } else { 
     
    4445        $counter = $ctx->stash('_categories_counter'); 
    4546        $glue = $ctx->stash('glue'); 
     47        $out = $ctx->stash('__out'); 
    4648    } 
    4749 
     
    5052        $ctx->stash('_categories_counter', $counter + 1); 
    5153        $repeat = true; 
     54        if (!empty($glue) && !empty($content)) { 
     55            if ($out) 
     56                $content = $glue . $content; 
     57            else 
     58                $ctx->stash('__out', true); 
     59        } 
    5260    } else { 
     61        if (!empty($glue) && $out && !empty($content)) 
     62            $content = $glue . $content; 
    5363        $repeat = false; 
    5464        $glue = ''; 
    5565        $ctx->restore($localvars); 
    5666    } 
    57     return $content.$glue; 
     67    return $content; 
    5868} 
    5969?> 
  • branches/release-35/php/lib/block.mttags.php

    r1174 r1926  
    77 
    88function smarty_block_mttags($args, $content, &$ctx, &$repeat) { 
    9     $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count', 'all_tag_count', 'include_blogs', 'exclude_blogs', 'blog_ids'); 
     9  $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count', 'all_tag_count', 'include_blogs', 'exclude_blogs', 'blog_ids', '__out'); 
    1010    if (!isset($content)) { 
    1111        $ctx->localize($localvars); 
     
    5454        $ctx->stash('all_tag_count', $all_count); 
    5555        $ctx->stash('_tags', $tags); 
     56        $ctx->stash('__out', false); 
    5657        $counter = 0; 
    5758    } else { 
    5859        $tags = $ctx->stash('_tags'); 
    5960        $counter = $ctx->stash('_tags_counter'); 
     61        $out = $ctx->stash('__out'); 
    6062    } 
    6163 
     
    6567        $ctx->stash('_tags_counter', $counter + 1); 
    6668        $repeat = true; 
    67         if (($counter > 0) && isset($args['glue'])) { 
    68             $content = $content . $args['glue']; 
     69        if (isset($args['glue'])) { 
     70            if ($out && !empty($content)) 
     71                $content = $args['glue'] . $content; 
     72            if (!$out && !empty($content)) 
     73              $ctx->stash('__out', true); 
    6974        } 
    7075    } else { 
     76        if (isset($args['glue'])) { 
     77            if ($out && !empty($content)) 
     78                $content = $args['glue'] . $content; 
     79        } 
    7180        $ctx->restore($localvars); 
    7281        $repeat = false;