Ignore:
Timestamp:
2019-09-16T12:30:00+12:00 (5 years ago)
Author:
kjdon
Message:

enabled having customsorttools in collection's perllib folder. you can implement any of sorttools functions to customise the formatting for the collection's sort.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/sorttools.pm

    r33451 r33476  
    2727# for sorting
    2828
     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
    2932package sorttools;
    3033
    3134use strict;
     35
     36my $has_custom_sort = 0;
     37
     38sub 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}
    3264
    3365# moved here from BasClas so import can share it
    3466sub format_metadata_for_sorting {
    3567    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   
    3673    if (!defined $metaname || $metaname !~ /\S/ || ! defined $metavalue || $metavalue !~ /\S/) {
    3774    return "";
     
    5188    # is this metadata likely to be a name?
    5289    my $function_name="format_string_name_$lang";
    53     if ($metaname =~ /^(?:\w+\.)?(?:Creators?|Authors?|Editors?)(?:[:,].*)?$/
     90    if ($metaname =~ /^(?:\w+\.)?(?:Creators?|Authors?|Editors?)(?:[:,].*)?$/ 
    5491    && exists &$function_name) {
    5592    no strict 'refs';
    5693    &$function_name(\$metavalue);
    5794    } else {
    58     $function_name="format_string_$lang";
     95    $function_name="format_string_$lang";   
    5996    if (exists &$function_name) {
    6097        no strict 'refs';
     
    75112sub format_string_en {
    76113    my $stringref = shift;
     114
     115    if ($has_custom_sort && defined (&customsorttools::format_string_en)) {
     116    return &customsorttools::format_string_en($stringref);
     117    }
     118   
    77119    $$stringref = lc($$stringref);
    78120    $$stringref =~ s/&[^\;]+\;//g; # html entities
     
    86128sub format_string_name_en {
    87129    my ($stringref) = @_;
     130
     131    if ($has_custom_sort && defined (&customsorttools::format_string_name_en)) {
     132    return &customsorttools::format_string_name_en($stringref);
     133    }
     134   
    88135    $$stringref =~ tr/A-Z/a-z/;
    89136    $$stringref =~ s/&\S+;//g;
     
    112159    my $stringref = shift;
    113160
     161    if ($has_custom_sort && defined (&customsorttools::format_string_fr)) {
     162    return &customsorttools::format_string_fr($stringref);
     163    }
     164
    114165    $$stringref = lc($$stringref);
    115166    $$stringref =~ s/&[^\;]+\;//g; # html entities
     
    123174sub format_string_es {
    124175    my $stringref = shift;
     176
     177    if ($has_custom_sort && defined (&customsorttools::format_string_es)) {
     178    return &customsorttools::format_string_es($stringref);
     179    }
    125180
    126181    $$stringref = lc($$stringref);
     
    142197    my ($day, $month, $year) = @_;
    143198
     199    if ($has_custom_sort && defined (&customsorttools::format_date)) {
     200    return &customsorttools::format_date($day, $month, $year);
     201    }
     202   
    144203    my %months = ('january' => '01', 'jan' => '01', 'february' => '02', 'feb' => '02',
    145204          'march' => '03', 'mar' => '03', 'april' => '04', 'apr' => '04',
Note: See TracChangeset for help on using the changeset viewer.