View | Details | Raw Unified | Return to bug 9579
Collapse All | Expand All

(-)a/C4/Search.pm (-10 lines)
Lines 573-589 sub getRecords { Link Here
573
                                my $facet_link_value = $one_facet;
573
                                my $facet_link_value = $one_facet;
574
                                $facet_link_value =~ s/[()!?¡¿؟]/ /g;
574
                                $facet_link_value =~ s/[()!?¡¿؟]/ /g;
575
575
576
                                # fix the length that will display in the label,
577
                                my $facet_label_value = $one_facet;
576
                                my $facet_label_value = $one_facet;
578
                                my $facet_max_length  = C4::Context->preference(
579
                                    'FacetLabelTruncationLength')
580
                                  || 20;
581
                                $facet_label_value =
582
                                  substr( $one_facet, 0, $facet_max_length )
583
                                  . "..."
584
                                  if length($facet_label_value) >
585
                                      $facet_max_length;
586
587
                            # if it's a branch, label by the name, not the code,
577
                            # if it's a branch, label by the name, not the code,
588
                                if ( $link_value =~ /branch/ ) {
578
                                if ( $link_value =~ /branch/ ) {
589
                                    if (   defined $branches
579
                                    if (   defined $branches
(-)a/Koha/Template/Plugin/TruncateByWord.pm (+100 lines)
Line 0 Link Here
1
#
2
# $Id: TruncateByWord.pm,v 1.3 2008/06/20 06:17:12 oneroad Exp $
3
#
4
package Koha::Template::Plugin::TruncateByWord;
5
6
use strict;
7
use warnings;
8
9
our $VERSION = '0.11';
10
11
use Template::Plugin::Filter;
12
use base 'Template::Plugin::Filter';
13
14
use Encode;
15
16
our $FILTER_NAME_DEFAULT = 'truncate_by_word';
17
our $ORG_ENC_DEFAULT = 'utf8';
18
19
sub init {
20
    my $self = shift;
21
    $self->{_DYNAMIC} = 1;
22
    $self->install_filter($self->{_CONFIG}->{name}||$FILTER_NAME_DEFAULT);
23
    $self->{_CONFIG}->{enc} ||= $self->{_ARGS}->[0] || $ORG_ENC_DEFAULT;
24
    return $self;
25
}
26
27
sub filter {
28
    my($self, $string, $args, $conf) = @_;
29
30
    return '' unless $string;
31
32
    # decode
33
    my $org_enc;
34
    unless ( utf8::is_utf8($string) ) {
35
        $org_enc = $self->{_CONFIG}->{enc};
36
        $string = Encode::decode($org_enc, $string);
37
    }
38
39
    my $org_length = CORE::length($string);
40
    my $length = $args->[0] || $org_length;
41
    return if $length =~ /\D/;
42
    $string = CORE::substr($string, 0, $length);
43
44
    my $suffix = $args->[1]||'';
45
    # revive encode
46
    $string = Encode::encode($org_enc, $string) if $org_enc;
47
    return $org_length > $length ? $string.$suffix : $string ;
48
}
49
50
1;
51
__END__
52
53
=head1 NAME
54
55
Template::Plugin::TruncateByWord - A Template Toolkit filter to truncate not the number of bytes but characters
56
57
=head1 SYNOPSIS
58
59
  # result is 'ab'
60
  [% USE TruncateByWord %]
61
  [% 'abcdefg' | truncate_by_word(2) %]
62
63
  # result is 'abc....'
64
  [% USE TruncateByWord %]
65
  [% FILTER truncate_by_word(3,'....') %]
66
  abcdefg
67
  [% END %]
68
69
  # default charset = 'utf8'. you can change this.
70
  # result is 'abcd'
71
  [% USE TruncateByWord 'euc-jp' %]
72
  [% FILTER truncate_by_word(4) %]
73
  abcdefg
74
  [% END %]
75
76
=head1 DESCRIPTION
77
78
Template::Plugin::TruncateByWord is a filter plugin for Template Toolkit which truncate text not the number of bytes but the number of characters.
79
80
=head1 BUGS
81
82
If found, please Email me. I tested utf8, euc-jp, shiftjis, 7bit-jis, big5, and euc-kr. Please send me more test cases.
83
84
=head1 SEE ALSO
85
86
L<Template>, L<Template::Plugin::Filter>, and t/*.t
87
88
=head1 AUTHOR
89
90
User & KAWABATA Kazumichi (Higemaru) E<lt>kawabata@cpan.orgE<gt>
91
92
=head1 COPYRIGHT AND LICENSE
93
94
Copyright (C) 2008- KAWABATA Kazumichi
95
96
This library is free software; you can redistribute it and/or modify
97
it under the same terms as Perl itself.
98
99
100
=cut
(-)a/catalogue/search.pl (+1 lines)
Lines 679-684 $template->param( Link Here
679
            opacfacets => 1,
679
            opacfacets => 1,
680
            facets_loop => $facets,
680
            facets_loop => $facets,
681
            displayFacetCount=> C4::Context->preference('displayFacetCount')||0,
681
            displayFacetCount=> C4::Context->preference('displayFacetCount')||0,
682
            FacetLabelTruncationLength => C4::Context->preference('FacetLabelTruncationLength') || 20,
682
            scan => $scan,
683
            scan => $scan,
683
            search_error => $error,
684
            search_error => $error,
684
);
685
);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc (-1 / +3 lines)
Lines 1-3 Link Here
1
[% USE TruncateByWord %]
2
1
[% IF ( opacfacets ) %]
3
[% IF ( opacfacets ) %]
2
[% IF ( facets_loop ) %]
4
[% IF ( facets_loop ) %]
3
<div id="search-facets">
5
<div id="search-facets">
Lines 19-25 Link Here
19
[% IF ( facets_loo.type_label_Libraries ) %]Libraries[% END %]
21
[% IF ( facets_loo.type_label_Libraries ) %]Libraries[% END %]
20
[% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
22
[% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
21
<ul>
23
<ul>
22
        [% FOREACH facet IN facets_loo.facets %]<li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by %][% END %]&amp;limit=[% facet.type_link_value %]:[% facet.facet_link_value %]" title="[% facet.facet_title_value %]">[% facet.facet_label_value %]</a> [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]</li>[% END %][% IF ( facets_loo.expandable ) %]
24
        [% FOREACH facet IN facets_loo.facets %]<li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by %][% END %]&amp;limit=[% facet.type_link_value %]:[% facet.facet_link_value %]" title="[% facet.facet_title_value %]">[% facet.facet_label_value |truncate_by_word(FacetLabelTruncationLength, '&hellip;') %]</a> [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]</li>[% END %][% IF ( facets_loo.expandable ) %]
23
        <li class="showmore"><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by %][% END %][% IF ( offset ) %]&amp;offset=[% offset %][% END %]&amp;expand=[% facets_loo.expand %]#[% facets_loo.type_id %]">Show more</a></li>
25
        <li class="showmore"><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by %][% END %][% IF ( offset ) %]&amp;offset=[% offset %][% END %]&amp;expand=[% facets_loo.expand %]#[% facets_loo.type_id %]">Show more</a></li>
24
[% END %]
26
[% END %]
25
</ul></li>
27
</ul></li>
(-)a/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc (-1 / +3 lines)
Lines 1-3 Link Here
1
[% USE TruncateByWord %]
2
1
[% IF ( opacfacets ) %]
3
[% IF ( opacfacets ) %]
2
[% IF ( facets_loop ) %]
4
[% IF ( facets_loop ) %]
3
<div id="search-facets">
5
<div id="search-facets">
Lines 20-26 Link Here
20
[% END %]
22
[% END %]
21
[% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
23
[% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
22
<ul>
24
<ul>
23
        [% FOREACH facet IN facets_loo.facets %]<li><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |html %][% END %]&amp;limit=[% facet.type_link_value %]:[% facet.facet_link_value %]" title="[% facet.facet_title_value |html %]">[% facet.facet_label_value %]</a> [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]</li>[% END %][% IF ( facets_loo.expandable ) %]
25
        [% FOREACH facet IN facets_loo.facets %]<li><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |html %][% END %]&amp;limit=[% facet.type_link_value %]:[% facet.facet_link_value %]" title="[% facet.facet_title_value |html %]">[% facet.facet_label_value |truncate_by_word(FacetLabelTruncationLength, '&hellip;') %]</a> [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]</li>[% END %][% IF ( facets_loo.expandable ) %]
24
        <li class="showmore"><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |html %][% END %][% IF ( offset ) %]&amp;offset=[% offset %][% END %]&amp;expand=[% facets_loo.expand %]#[% facets_loo.type_id %]">Show more</a></li>
26
        <li class="showmore"><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |html %][% END %][% IF ( offset ) %]&amp;offset=[% offset %][% END %]&amp;expand=[% facets_loo.expand %]#[% facets_loo.type_id %]">Show more</a></li>
25
[% END %]
27
[% END %]
26
</ul></li>
28
</ul></li>
(-)a/opac/opac-search.pl (-1 / +1 lines)
Lines 862-867 $template->param( Link Here
862
            opacfacets => 1,
862
            opacfacets => 1,
863
            facets_loop => $facets,
863
            facets_loop => $facets,
864
            displayFacetCount=> C4::Context->preference('displayFacetCount')||0,
864
            displayFacetCount=> C4::Context->preference('displayFacetCount')||0,
865
            FacetLabelTruncationLength => C4::Context->preference('FacetLabelTruncationLength') || 20,
865
            scan => $scan,
866
            scan => $scan,
866
            search_error => $error,
867
            search_error => $error,
867
);
868
);
868
- 

Return to bug 9579