Lines 57-62
use vars qw(@ISA @EXPORT);
Link Here
|
57 |
&marc2modsxml |
57 |
&marc2modsxml |
58 |
&marc2madsxml |
58 |
&marc2madsxml |
59 |
&marc2bibtex |
59 |
&marc2bibtex |
|
|
60 |
&marc2cites |
60 |
&marc2csv |
61 |
&marc2csv |
61 |
&changeEncoding |
62 |
&changeEncoding |
62 |
); |
63 |
); |
Lines 859-864
sub marc2bibtex {
Link Here
|
859 |
return $tex; |
860 |
return $tex; |
860 |
} |
861 |
} |
861 |
|
862 |
|
|
|
863 |
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations |
864 |
|
865 |
my $cites = marc2cites($record); |
866 |
|
867 |
Returns hashref of citation from MARC data, suitable to pass to templates. |
868 |
Hash keys store citation system names, hash values citation string. |
869 |
|
870 |
C<$record> - a MARC::Record object |
871 |
|
872 |
=cut |
873 |
|
874 |
sub marc2cites { |
875 |
my $record = shift; |
876 |
my $marcflavour = C4::Context->preference("marcflavour"); |
877 |
my %cites = (); |
878 |
my @authors = (); |
879 |
my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/; |
880 |
|
881 |
my @authors; |
882 |
my @authorFields = ('100','110','111','700','710','711'); |
883 |
@authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" ); |
884 |
|
885 |
foreach my $ftag ( @authorFields ) { |
886 |
foreach my $field ($record->field($ftag)) { |
887 |
my $author = ''; |
888 |
if ( $marcflavour eq "UNIMARC" ) { |
889 |
$author = join ', ', |
890 |
( $field->subfield("a"), $field->subfield("b") ); |
891 |
} else { |
892 |
$author = $field->subfield("a"); |
893 |
} |
894 |
if($author =~ /([^,]+),?(.*)/) { |
895 |
my %a; |
896 |
($a{'surname'} = $1) =~ s/$re_clean//g; |
897 |
$a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2]; |
898 |
push(@authors, \%a); |
899 |
} |
900 |
} |
901 |
} |
902 |
|
903 |
my %publication; |
904 |
if ( $marcflavour eq "UNIMARC" ) { |
905 |
%publication = ( |
906 |
title => $record->subfield("200", "a") || "", |
907 |
place => $record->subfield("210", "a") || "", |
908 |
publisher => $record->subfield("210", "c") || "", |
909 |
date => $record->subfield("210", "d") || $record->subfield("210", "h") || "" |
910 |
); |
911 |
} else { |
912 |
%publication = ( |
913 |
title => $record->subfield("245", "a") || "", |
914 |
place => $record->subfield("260", "a") || "", |
915 |
publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "", |
916 |
date => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || "" |
917 |
); |
918 |
} |
919 |
|
920 |
$publication{$_} =~ s/$re_clean//g for keys %publication; |
921 |
$publication{'date'} =~ s/[\D-]//g; |
922 |
|
923 |
my $i = $#authors; |
924 |
my $last = 0; |
925 |
my $seclast = 0; |
926 |
for my $author (@authors) { |
927 |
$cites{'Harvard'} .= $author->{'surname'} . ' '; |
928 |
$cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; |
929 |
$cites{'Harvard'} =~ s/\s+$//; |
930 |
$cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
931 |
$cites{'Chicago'} .= $author->{'surname'} . ' '; |
932 |
$cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}}; |
933 |
$cites{'Chicago'} =~ s/\s+$//; |
934 |
$cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
935 |
$cites{'MLA'} .= $author->{'surname'} . ' '; |
936 |
$cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}}; |
937 |
$cites{'MLA'} =~ s/\s+$//; |
938 |
$cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
939 |
$cites{'APA'} .= $author->{'surname'} . ' '; |
940 |
$cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; |
941 |
$cites{'APA'} =~ s/\s+$//; |
942 |
$cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', '); |
943 |
$seclast = $#authors > 1 && $i-- == 2; |
944 |
$last = $i == 0; |
945 |
} |
946 |
$cites{$_} =~ s/([^\.])$/$1./ for keys %cites; |
947 |
|
948 |
$cites{'Harvard'} .= ' (' . $publication{'date'} . '). '; |
949 |
$cites{'Chicago'} .= ' ' . $publication{'date'} . '. '; |
950 |
$cites{'MLA'} .= ' ' . $publication{'title'} . '. '; |
951 |
$cites{'APA'} .= ' (' . $publication{'date'} . '). '; |
952 |
$cites{'Harvard'} .= $publication{'title'} . '. '; |
953 |
$cites{'Chicago'} .= $publication{'title'} . '. '; |
954 |
$cites{'MLA'} .= $publication{'place'} . ': '; |
955 |
$cites{'APA'} .= $publication{'title'} . '. '; |
956 |
$cites{'Harvard'} .= $publication{'place'} . ': '; |
957 |
$cites{'Chicago'} .= $publication{'place'} . ': '; |
958 |
$cites{'MLA'} .= $publication{'publisher'} . '. '; |
959 |
$cites{'APA'} .= $publication{'place'} . ': '; |
960 |
$cites{'Harvard'} .= $publication{'publisher'}; |
961 |
$cites{'Chicago'} .= $publication{'publisher'}; |
962 |
$cites{'MLA'} .= $publication{'date'}; |
963 |
$cites{'APA'} .= $publication{'publisher'}; |
964 |
$cites{$_} =~ s/ +/ / for keys %cites; |
965 |
$cites{$_} =~ s/([^\.])$/$1./ for keys %cites; |
966 |
|
967 |
return \%cites; |
968 |
} |
969 |
|
862 |
|
970 |
|
863 |
=head1 INTERNAL FUNCTIONS |
971 |
=head1 INTERNAL FUNCTIONS |
864 |
|
972 |
|