Changeset 33476 for main/trunk/greenstone2/perllib/sorttools.pm
- Timestamp:
- 2019-09-16T12:30:00+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/sorttools.pm
r33451 r33476 27 27 # for sorting 28 28 29 # To customise sort functions for a particular collection, create a customsorttools.pm inside 30 # collection's perllib folder, and implement any of the functions you want to change. 31 29 32 package sorttools; 30 33 31 34 use strict; 35 36 my $has_custom_sort = 0; 37 38 sub setup_custom_sort { 39 40 my $collectdir = $ENV{'GSDLCOLLECTDIR'}; 41 my $customperllibfolder = &FileUtils::filenameConcatenate($collectdir, 'perllib'); 42 my $customsortfile = &FileUtils::filenameConcatenate($customperllibfolder, 'customsorttools.pm'); 43 if (&FileUtils::fileExists($customsortfile)) { 44 # add perllib folder to INC, if its not already there 45 my $found_perllibfolder = 0; 46 foreach my $path (@INC) 47 { 48 if ($path eq $customperllibfolder) 49 { 50 $found_perllibfolder = 1; 51 last; 52 } 53 } 54 if (!$found_perllibfolder) 55 { 56 unshift (@INC, $customperllibfolder); 57 } 58 59 require customsorttools; 60 $has_custom_sort = 1; 61 } 62 63 } 32 64 33 65 # moved here from BasClas so import can share it 34 66 sub format_metadata_for_sorting { 35 67 my ($metaname, $metavalue, $doc_obj) = @_; 68 69 if ($has_custom_sort && defined (&customsorttools::format_metadata_for_sorting)) { 70 return &customsorttools::format_metadata_for_sorting($metaname, $metavalue, $doc_obj); 71 } 72 36 73 if (!defined $metaname || $metaname !~ /\S/ || ! defined $metavalue || $metavalue !~ /\S/) { 37 74 return ""; … … 51 88 # is this metadata likely to be a name? 52 89 my $function_name="format_string_name_$lang"; 53 if ($metaname =~ /^(?:\w+\.)?(?:Creators?|Authors?|Editors?)(?:[:,].*)?$/ 90 if ($metaname =~ /^(?:\w+\.)?(?:Creators?|Authors?|Editors?)(?:[:,].*)?$/ 54 91 && exists &$function_name) { 55 92 no strict 'refs'; 56 93 &$function_name(\$metavalue); 57 94 } else { 58 $function_name="format_string_$lang"; 95 $function_name="format_string_$lang"; 59 96 if (exists &$function_name) { 60 97 no strict 'refs'; … … 75 112 sub format_string_en { 76 113 my $stringref = shift; 114 115 if ($has_custom_sort && defined (&customsorttools::format_string_en)) { 116 return &customsorttools::format_string_en($stringref); 117 } 118 77 119 $$stringref = lc($$stringref); 78 120 $$stringref =~ s/&[^\;]+\;//g; # html entities … … 86 128 sub format_string_name_en { 87 129 my ($stringref) = @_; 130 131 if ($has_custom_sort && defined (&customsorttools::format_string_name_en)) { 132 return &customsorttools::format_string_name_en($stringref); 133 } 134 88 135 $$stringref =~ tr/A-Z/a-z/; 89 136 $$stringref =~ s/&\S+;//g; … … 112 159 my $stringref = shift; 113 160 161 if ($has_custom_sort && defined (&customsorttools::format_string_fr)) { 162 return &customsorttools::format_string_fr($stringref); 163 } 164 114 165 $$stringref = lc($$stringref); 115 166 $$stringref =~ s/&[^\;]+\;//g; # html entities … … 123 174 sub format_string_es { 124 175 my $stringref = shift; 176 177 if ($has_custom_sort && defined (&customsorttools::format_string_es)) { 178 return &customsorttools::format_string_es($stringref); 179 } 125 180 126 181 $$stringref = lc($$stringref); … … 142 197 my ($day, $month, $year) = @_; 143 198 199 if ($has_custom_sort && defined (&customsorttools::format_date)) { 200 return &customsorttools::format_date($day, $month, $year); 201 } 202 144 203 my %months = ('january' => '01', 'jan' => '01', 'february' => '02', 'feb' => '02', 145 204 'march' => '03', 'mar' => '03', 'april' => '04', 'apr' => '04',
Note:
See TracChangeset
for help on using the changeset viewer.