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

(-)a/C4/Record.pm (+108 lines)
Lines 55-60 $VERSION = 3.07.00.049; Link Here
55
  &marc2modsxml
55
  &marc2modsxml
56
  &marc2madsxml
56
  &marc2madsxml
57
  &marc2bibtex
57
  &marc2bibtex
58
  &marc2cites
58
  &marc2csv
59
  &marc2csv
59
  &changeEncoding
60
  &changeEncoding
60
);
61
);
Lines 811-816 sub marc2bibtex { Link Here
811
    return $tex;
812
    return $tex;
812
}
813
}
813
814
815
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
816
817
  my $cites = marc2cites($record);
818
819
Returns hashref of citation from MARC data, suitable to pass to templates.
820
Hash keys store citation system names, hash values citation string.
821
822
C<$record> - a MARC::Record object
823
824
=cut
825
826
sub marc2cites {
827
    my $record = shift;
828
    my $marcflavour = C4::Context->preference("marcflavour");
829
    my %cites = ();
830
    my @authors = ();
831
    my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
832
833
    my @authors;
834
    my @authorFields = ('100','110','111','700','710','711');
835
    @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" );
836
837
    foreach my $ftag ( @authorFields ) {
838
        foreach my $field ($record->field($ftag)) {
839
            my $author = '';
840
            if ( $marcflavour eq "UNIMARC" ) {
841
                $author = join ', ',
842
                ( $field->subfield("a"), $field->subfield("b") );
843
            } else {
844
                $author = $field->subfield("a");
845
            }
846
            if($author =~ /([^,]+),?(.*)/) {
847
                my %a;
848
                ($a{'surname'} = $1) =~ s/$re_clean//g;
849
                $a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2];
850
                push(@authors, \%a);
851
            }
852
        }
853
    }
854
855
    my %publication;
856
    if ( $marcflavour eq "UNIMARC" ) {
857
            %publication = (
858
                title     => $record->subfield("200", "a") || "",
859
                place     => $record->subfield("210", "a") || "",
860
                publisher => $record->subfield("210", "c") || "",
861
                date      => $record->subfield("210", "d") || $record->subfield("210", "h") || ""
862
            );
863
    } else {
864
            %publication = (
865
                title     => $record->subfield("245", "a") || "",
866
                place     => $record->subfield("260", "a") || "",
867
                publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
868
                date      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || ""
869
            );
870
    }
871
872
    $publication{$_} =~ s/$re_clean//g for keys %publication;
873
    $publication{'date'} =~ s/[\D-]//g;
874
875
    my $i = $#authors;
876
    my $last = 0;
877
    my $seclast = 0;
878
    for my $author (@authors) {
879
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
880
        $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
881
        $cites{'Harvard'} =~ s/\s+$//;
882
        $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', ');
883
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
884
        $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}};
885
        $cites{'Chicago'} =~ s/\s+$//;
886
        $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', ');
887
        $cites{'MLA'} .= $author->{'surname'} . ' ';
888
        $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}};
889
        $cites{'MLA'} =~ s/\s+$//;
890
        $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', ');
891
        $cites{'APA'} .= $author->{'surname'} . ' ';
892
        $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
893
        $cites{'APA'} =~ s/\s+$//;
894
        $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', ');
895
        $seclast = $#authors > 1 && $i-- == 2;
896
        $last = $i == 0;
897
    }
898
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
899
900
    $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
901
    $cites{'Chicago'} .= ' ' . $publication{'date'}  . '. ';
902
    $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
903
    $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
904
    $cites{'Harvard'} .= $publication{'title'} . '. ';
905
    $cites{'Chicago'} .= $publication{'title'} . '. ';
906
    $cites{'MLA'}     .= $publication{'place'} . ': ';
907
    $cites{'APA'}     .= $publication{'title'} . '. ';
908
    $cites{'Harvard'} .= $publication{'place'} . ': ';
909
    $cites{'Chicago'} .= $publication{'place'} . ': ';
910
    $cites{'MLA'}     .= $publication{'publisher'}  . '. ';
911
    $cites{'APA'}     .= $publication{'place'} . ': ';
912
    $cites{'Harvard'} .= $publication{'publisher'};
913
    $cites{'Chicago'} .= $publication{'publisher'};
914
    $cites{'MLA'}     .= $publication{'date'};
915
    $cites{'APA'}     .= $publication{'publisher'};
916
    $cites{$_} =~ s/  +/ / for keys %cites;
917
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
918
919
    return \%cites;
920
}
921
814
922
815
=head1 INTERNAL FUNCTIONS
923
=head1 INTERNAL FUNCTIONS
816
924
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc (+16 lines)
Lines 1-3 Link Here
1
<div id="citemodal" class="modal hide" role="dialog" aria-labelledby="citeLabel" aria-hidden="true">
2
    <div class="modal-header">
3
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
4
        <h2 id="citeLabel">[% title OR 'Citation' | html %]</h2>
5
    </div>
6
    <div class="modal-body">
7
        [% FOREACH system IN cites.keys.sort %]
8
        <h3>[% system %]</h3>
9
        <p>[% cites.$system | html %]</p>
10
        [% END %]
11
    </div>
12
    <div class="modal-footer">
13
    </div>
14
</div>
15
1
<ul id="action">
16
<ul id="action">
2
    [% UNLESS ( norequests ) %]
17
    [% UNLESS ( norequests ) %]
3
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
18
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
Lines 9-14 Link Here
9
        [% END %]
24
        [% END %]
10
    [% END %]
25
    [% END %]
11
    <li><a class="print-large" href="#" onclick="window.print();">Print</a></li>
26
    <li><a class="print-large" href="#" onclick="window.print();">Print</a></li>
27
    <li><a href="#citemodal" id="cite" data-toggle="modal">Cite</a></li>
12
    [% IF Koha.Preference( 'virtualshelves' ) == 1 %]
28
    [% IF Koha.Preference( 'virtualshelves' ) == 1 %]
13
        [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername ) %]
29
        [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername ) %]
14
            <li><a class="addtoshelf" href="/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]" onclick="Dopop('opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]'); return false;">
30
            <li><a class="addtoshelf" href="/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]" onclick="Dopop('opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]'); return false;">
(-)a/opac/opac-ISBDdetail.pl (+4 lines)
Lines 48-53 use C4::Output; Link Here
48
use CGI qw ( -utf8 );
48
use CGI qw ( -utf8 );
49
use MARC::Record;
49
use MARC::Record;
50
use C4::Biblio;
50
use C4::Biblio;
51
use C4::Record;
51
use C4::Items;
52
use C4::Items;
52
use C4::Reserves;
53
use C4::Reserves;
53
use C4::Acquisition;
54
use C4::Acquisition;
Lines 205-208 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ Link Here
205
    $template->param('OPACSearchForTitleIn' => $search_for_title);
206
    $template->param('OPACSearchForTitleIn' => $search_for_title);
206
}
207
}
207
208
209
# Cites
210
$template->{VARS}->{'cites'} = marc2cites($record);
211
208
output_html_with_http_headers $query, $cookie, $template->output;
212
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-MARCdetail.pl (+4 lines)
Lines 51-56 use C4::Output; Link Here
51
use CGI qw ( -utf8 );
51
use CGI qw ( -utf8 );
52
use MARC::Record;
52
use MARC::Record;
53
use C4::Biblio;
53
use C4::Biblio;
54
use C4::Record;
54
use C4::Items;
55
use C4::Items;
55
use C4::Reserves;
56
use C4::Reserves;
56
use C4::Members;
57
use C4::Members;
Lines 335-338 $template->param( Link Here
335
    biblionumber        => $biblionumber,
336
    biblionumber        => $biblionumber,
336
);
337
);
337
338
339
# Cites
340
$template->{VARS}->{'cites'} = marc2cites($record);
341
338
output_html_with_http_headers $query, $cookie, $template->output;
342
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-detail.pl (-1 / +4 lines)
Lines 31-36 use C4::Koha; Link Here
31
use C4::Serials;    #uses getsubscriptionfrom biblionumber
31
use C4::Serials;    #uses getsubscriptionfrom biblionumber
32
use C4::Output;
32
use C4::Output;
33
use C4::Biblio;
33
use C4::Biblio;
34
use C4::Record;
34
use C4::Items;
35
use C4::Items;
35
use C4::Circulation;
36
use C4::Circulation;
36
use C4::Tags qw(get_tags);
37
use C4::Tags qw(get_tags);
Lines 1152-1155 $template->param( Link Here
1152
    'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'),
1153
    'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'),
1153
);
1154
);
1154
1155
1156
# Cites
1157
$template->{VARS}->{'cites'} = marc2cites($record);
1158
1155
output_html_with_http_headers $query, $cookie, $template->output;
1159
output_html_with_http_headers $query, $cookie, $template->output;
1156
- 

Return to bug 14670