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 |
|