Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
Removed unique attribute, added local to one line.
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Gorichanaz <[email protected]>
  • Loading branch information
CNG committed Jun 2, 2011
1 parent 21e5e47 commit ac56771
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
28 changes: 13 additions & 15 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@ example, to show the last 30 unique entries and ActionStreams items:
</mt:OrderDateFooter>

<mt:Entries lastn="30">
<mt:OrderItem unique="1">
<mt:setvarblock name="order_by">
<mt:OrderItem>
<mt:setvarblock name="order_by" strip_linefeeds="1" trim="1">
<mt:EntryDate utc="1" format="%Y%m%d%H%M%S">
</mt:setvarblock>
<mt:Include module="Entry">
</mt:OrderItem>
</mt:Entries>

<mt:ActionStreams limit="30">
<mt:OrderItem unique="1">
<mt:setvarblock name="order_by">
<$mt:StreamActionDate format="%Y%m%d%H%M%S"$>
</mt:setvarblock>
<p><a href="<mt:StreamActionURL escape="html">"><img src="/img/icons/<mt:var name="service_type">_16.png" width="12" height="12"></a> <a href="<mt:StreamActionURL escape="html">" class="actionlink"><mt:StreamActionTitle></a></p>
</mt:OrderItem>
<mt:setvarblock name="actionurl"><mt:StreamActionURL escape="html"></mt:setvarblock>
<mt:If name="actionurl" like="mysite.com">
<mt:Else>
<mt:OrderItem>
<mt:setvarblock name="order_by" strip_linefeeds="1" trim="1">
<$mt:StreamActionDate format="%Y%m%d%H%M%S"$>
</mt:setvarblock>
<p><a href="<mt:StreamActionURL escape="html">"><img src="/img/icons/<mt:var name="service_type">_16.png" width="12" height="12"></a> <a href="<mt:StreamActionURL escape="html">" class="actionlink"><mt:StreamActionTitle></a></p>
</mt:OrderItem>
</mt:If>
</mt:ActionStreams>

<mt:OrderFooter>
</div>
</mt:OrderFooter>
Expand Down Expand Up @@ -151,12 +155,6 @@ attribute is considered. That is, if you order 11 items, pin one to `-1`
(last), and use `limit="10"` on the `mt:Order` tag, the pinned item will *not*
be shown (it was the eleventh of ten items).

### `unique` ###

In cases where two or more `mt:OrderItem`s have the same `order_by` value, the
same first 18 characters of content and the attribute `unique` set to the value
`1`, all duplicate `mt:OrderItem`s are removed.


## `mt:OrderHeader` ##

Expand Down
29 changes: 3 additions & 26 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,7 @@ sub tag_order {
push @objs, $sort->(@$items);
}
}

my $test_unique = 0;
for my $obj (@objs) {
$test_unique = 1 if $obj->[2];
}
if ($test_unique) {
use Digest::MD5 qw(md5_base64);
my $j = 0;
my %used;
for my $obj (@objs) {
if ($obj->[2]) {
my $hash = md5_base64($obj->[0].$obj->[1]);
splice (@objs, $j, 1) if exists $used{$hash};
$used{$hash}++;
}
$j++;
}
}


if (my $offset = $args->{offset}) {
# Delete the first $offset items.
splice @objs, 0, $offset;
Expand Down Expand Up @@ -131,7 +113,7 @@ sub tag_order {
$footer++;
}
my $header = $today ne $yesterday;
$ctx->{current_timestamp} = $o->[0];
local $ctx->{current_timestamp} = $o->[0];
my ($h_html, $f_html) = ('')x2;
if ($header && $ctx->stash('order_date_header')) {
my $result = $builder->build($ctx, $ctx->stash('order_date_header'), {});
Expand Down Expand Up @@ -198,14 +180,9 @@ sub tag_order_item {
my $order_value = $ctx->var($order_var) || q{};
$order_value =~ s{ \A \s+ | \s+ \z }{}xmsg;

my $is_unique = 0;
if (defined $args->{unique} && $args->{unique}) {
$is_unique = 1;
}

my $groups = $ctx->stash('order_items');
my $group = ($groups->{$group_id} ||= []);
push @$group, [ $order_value, $output, $is_unique ];
push @$group, [ $order_value, $output];

}

Expand Down

0 comments on commit ac56771

Please sign in to comment.