Ticket #18: ticket_18.patch

File ticket_18.patch, 21.7 KB (added by Ivor Williams, 16 years ago)

Updated up to changeset [731]

  • trunk/templates/display_metadata.tt

     
    22<!-- METADATA STARTS -->
    33
    44<div id="metadata">
     5[% FOREACH field = address_fields %]
     6  [% IF address.$field %]
     7    [% address_populated = 1 %]
     8  [% END %]
     9[% END %]
    510[% IF phone OR fax OR address OR postcode OR formatted_website_text
    611      OR hours_text OR map_link %]
    712  <ul id="general_metadata">
     
    1621        <span class="metadata_label">Fax:</span> [% CGI.escapeHTML(fax) %]
    1722      </li>
    1823    [% END %]
    19     [% IF address %]
     24    [% IF address_populated %]
    2025      <li class="address">
    2126        <span class="metadata_label">Address:</span>
    22         [% CGI.escapeHTML(address) %]<!--, [% default_city %] --> [%# uncomment at left to show city %]
    23         [% IF map_link %]
     27      [% FOREACH field = address_fields %]
     28        [% IF address.$field %]
     29          [% CGI.escapeHTML(address.$field) -%][% IF loop.last %].[% ELSE %],[% END %]
     30        [% END %]
     31      [% END %]
     32      [% IF map_link %]
    2433          <a href="[% map_link %]">(map of this place)</a>
    25         [% END %]
     34      [% END %]
    2635      </li>
    2736    [% ELSIF map_link %]
    2837      <li class="map">
    2938        <span class="metadata_label"><a href="[% map_link %]">Map of this place</a></span>
    3039      </li>
    3140    [% END %]
    32     [% IF postcode %]
    33       <li class="postcode">
    34         <span class="metadata_label">Postcode:</span>
    35         [% CGI.escapeHTML(postcode) %]
    36       </li>
    37     [% END %]
    3841    [% IF formatted_website_text %]
    3942      <li class="website_link">
    4043        <span class="metadata_label">Website:</span> [% formatted_website_text %]
  • trunk/templates/edit_conflict.tt

     
    6666        <td><input type="text" size="50" id="hours" name="hours_text" value="[% stored_hours_text %]"></td>
    6767        <td>[% CGI.escapeHTML(new_hours_text) %]</td>
    6868      </tr>
     69        [% FOREACH field = address_fields %]
     70          [% USE String ( field ) %]
    6971            <tr>
    70         <td class="label"><label for="address">Address:</label></td>
    71         <td><input type="text" size="50" id="address" name="address" value="[% stored_address %]"></td>
    72         <td>[% CGI.escapeHTML(new_address) %]</td>
    73       </tr>
    74             <tr>
    75         <td class="label"><label for="postcode">Postcode:</label></td>
    76         <td><input type="text" size="50" id="postcode" name="postcode" value="[% stored_postcode %]"></td>
    77         <td>[% CGI.escapeHTML(new_postcode) %]</td>
    78       </tr>
    79             <tr>
     72              <td class="label"><label for="[% field %]">[% String.capital %]:</label></td>
     73              <td><input type="text" size="50" id="[% field %]" name="[% field %]" value="[% stored_address.$field %]"></td>
     74              <td>[% CGI.escapeHTML(new_address.$field) %]</td>
     75            </tr>
     76          [% END %]
     77        [% END %]
     78      <tr>
    8079        <td class="label"><label for="os_x">OS X coordinate:</label></td>
    8180        <td><input type="text" size="50" id="os_x" name="os_x" value="[% stored_os_x %]">
    8281        <td>[% CGI.escapeHTML(new_os_x) %]</td>
  • trunk/templates/edit_form.tt

     
     1[% USE CGI %]
    12[% INCLUDE header.tt page_title = "Edit $node_name - $site_name" %]
    23<div id="content">
    34
     
    7475              <td class="label"><label for="hours">Opening hours:</label></td>
    7576              <td><input type="text" size="50" id="hours" name="hours_text" value="[% hours_text %]" /></td>
    7677            </tr>
     78        [% FOREACH field = address_fields %]
     79          [% USE String( field ) %]
     80              <tr>
     81                <td class="label"><label for="[% field %]">[% String.capital %]:</label></td>
     82              [% IF preset.$field %]
     83                  <td><input type="checkbox" name="[% field %]" value="[% preset.$field %]"
     84            [% IF address.$field != '' %]
     85              checked
     86            [% END %]
     87            />
     88                    [% CGI.escapeHTML(preset.$field) %]</td>
     89          [% ELSE %]
     90                  <td><input type="text" size="50" name="[% field %]" value="[% address.$field %]" /></td>
     91          [% END %]
     92              </tr>
     93            [% END %]
    7794            <tr>
    78               <td class="label"><label for="address">Address:</label></td>
    79               <td><input type="text" size="50" id="address" name="address" value="[% address %]" /></td>
    80             </tr>
    81             <tr>
    82               <td class="label"><label for="postcode">Postcode:</label></td>
    83               <td><input type="text" size="50" id="postcode" name="postcode" value="[% postcode %]" /></td>
    84             </tr>
    85             <tr>
    8695              <td class="label"><label for="[% coord_field_1 %]">[% coord_field_1_name %]:</label></td>
    8796              <td><input type="text" size="50" id="[% coord_field_1 %]" name="[% coord_field_1 %]" value="[% coord_field_1_value %]" /></td>
    8897            </tr>
  • trunk/t/21_rdf.t

     
    2323                    script_url         => "http://wiki.example.com/",
    2424                    script_name        => "mywiki.cgi",
    2525                    site_name          => "CGI::Wiki Test Site",
    26                     default_city       => "London",
    27                     default_country    => "United Kingdom",
     26                    preset_city       => "London",
     27                    preset_country    => "United Kingdom",
    2828                }
    2929    );
    3030    eval { require CGI::Wiki::Search::Plucene; };
     
    103103    like( $rdfxml, qr|<dc:date>|, "date element included" );
    104104    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
    105105
    106     # Check that default city and country can be set to blank.
     106    # Check that preset city and country can be set to blank.
    107107    $config = OpenGuides::Test->make_basic_config;
    108     $config->default_city( "" );
    109     $config->default_country( "" );
     108    $config->preset_city( "" );
     109    $config->preset_country( "" );
    110110    my $guide = OpenGuides->new( config => $config );
    111111    OpenGuides::Test->write_data(
    112112                                    guide => $guide,
  • trunk/t/15_template.t

     
    55use OpenGuides::Config;
    66use OpenGuides::Template;
    77use Test::MockObject;
    8 use Test::More tests => 28;
     8use Test::More tests => 30;
    99
    1010my $config = OpenGuides::Config->new(
    1111       vars => {
     
    1313                 site_name             => 'CGI::Wiki Test Site',
    1414                 script_url            => 'http://wiki.example.com/',
    1515                 script_name           => 'mywiki.cgi',
    16                  default_country       => 'United Kingdom',
    17                  default_city          => 'London',
     16                 preset_country        => 'United Kingdom',
     17                 preset_city           => 'London',
    1818                 contact_email         => 'wiki@example.com',
    1919                 stylesheet_url        => 'http://wiki.example.com/styles.css',
    2020                 home_name             => 'Home Page',
    2121                 formatting_rules_node => 'Rules',
    2222                 formatting_rules_link => '',
     23                 address_format        => 'street,town,city,country,postcode',
    2324               }
    2425);
    2526
     
    9192like( $output, qr/OPENGUIDES VERSION: 0\.\d\d/,
    9293      "openguides_version set" );
    9394
     95# Test address fields list
     96like( $output, qr/ADDRESS FIELDS: Street,Town,City,Country,Postcode/,
     97      "address fields" );
     98
     99TODO: {
     100    local $TODO = "Address data test not ready in this module";
     101   
     102# Test address layout
     103like( $output, qr/ADDRESS: 1 High Street,London,United Kingdom,AZ1 1XY./,
     104      "address data" );
     105}
     106
    94107# Test TT variables auto-set from node name.
    95108$output = OpenGuides::Template->output(
    96109    wiki     => $fake_wiki,
  • trunk/t/templates/15_test.tt

     
    1717OMIT FORMATTING LINK: [% omit_formatting_link %]
    1818
    1919ENABLE PAGE DELETION: [% enable_page_deletion %]
     20
     21ADDRESS FIELDS:
     22[%- FOREACH field = address_fields %]
     23[%- USE String( field ) %]
     24[%- String.capital %],
     25[%- END %]
     26
     27ADDRESS:
     28[%- FOREACH field = address_fields %]
     29  [%- IF address.$field %]
     30    [%- address.$field %]
     31    [%- IF field.last %].[% ELSE %],[% END %]
     32  [%- END %]
     33[%- END %]
     34
     35
  • trunk/lib/OpenGuides/Config.pm

     
    88   dbtype dbname dbuser dbpass dbhost script_name install_directory script_url
    99   custom_lib_path use_plucene indexing_directory enable_page_deletion
    1010   admin_pass stylesheet_url site_name navbar_on_home_page home_name
    11    site_desc default_city default_country contact_email default_language
    12    formatting_rules_node formatting_rules_link backlinks_in_title template_path
    13    custom_template_path geo_handler ellipsoid gmaps_api_key centre_long
    14    centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
     11   site_desc address_format contact_email default_language
     12   formatting_rules_node formatting_rules_link
     13   backlinks_in_title template_path custom_template_path geo_handler ellipsoid
     14   gmaps_api_key centre_long centre_lat default_gmaps_zoom
     15   default_gmaps_search_zoom force_wgs84
    1516);
    1617my @questions = map { $_ . "__qu" } @variables;
    1718OpenGuides::Config->mk_accessors( @variables );
     
    7071                     navbar_on_home_page => 1,
    7172                     home_name => "Home",
    7273                     site_desc => "A default configuration of OpenGuides",
    73                      default_city => "",
    74                      default_country => "",
     74                     address_format => 'street,town,city,county,country,postcode',
    7575                     default_language => "en",
    7676                     formatting_rules_node => "Text Formatting Examples",
    7777                     formatting_rules_link => "http://openguides.org/page/text_formatting",
     
    101101    foreach my $var ( keys %defaults ) {
    102102        $self->$var( $defaults{$var} );
    103103    }
     104    my $adf = $stored{address_format} || $defaults{address_format};
     105    my @adf = map {
     106                /code/i ? () : "preset_".$_ }
     107                split ',',$adf;
     108    my @adf_qu = map {$_."__qu"} @adf;
     109
     110# Note: this is considering OpenGuides::Config a singleton, and is
     111# adding accessors for questions dependent on address_format
     112
     113    OpenGuides::Config->mk_accessors( @adf );
     114    OpenGuides::Config->mk_accessors( @adf_qu );
     115       
    104116    foreach my $var ( keys %stored ) {
    105117        if ( $self->can( $var ) ) { # handle any garbage in file gracefully
    106118            $self->$var( $stored{$var} );
     
    132144        navbar_on_home_page => "Do you want the navigation bar included on the home page?",
    133145        home_name => "What should the home page of the wiki be called?",
    134146        site_desc => "How would you describe the site?",
    135         default_city => "What city is the site based in?",
    136         default_country => "What country is the site based in?",
     147        address_format => "How would you like to present addresses? ",
    137148        contact_email => "Contact email address for the site administrator?",
    138149        default_language => "What language will the site be in? (Please give an ISO language code.)",
    139150        formatting_rules_node => "What's the name of the node or page to use for the text formatting rules link (this is by default an external document, but if you make formatting_rules_link empty, it will be a wiki node instead",
     
    151162    foreach my $var ( keys %questions ) {
    152163        my $method = $var . "__qu";
    153164        $self->$method( $questions{$var} );
     165        if ($var eq 'address_format') {
     166            my @address_fields = map {
     167                /code/i ? () : "preset_".$_ }
     168                split ',',$self->$var;
     169            my @address_fields_qu = map {$_."__qu"} @address_fields;
     170
     171# Note: this is considering OpenGuides::Config a singleton, and is
     172# adding accessors for questions dependent on address_format
     173
     174            OpenGuides::Config->mk_accessors( @address_fields );
     175            OpenGuides::Config->mk_accessors( @address_fields_qu );
     176            for (@address_fields) {
     177                my $meth = $_ . "__qu";
     178                $self->$meth( ucfirst($_)." which this guide is for? " );
     179            }
     180        }
    154181    }
    155182
    156183    return $self;
  • trunk/lib/OpenGuides/Template.pm

     
    115115
    116116    my $script_name  = $config->script_name;
    117117    my $script_url   = $config->script_url;
    118     my $default_city = $config->default_city;
     118    my $address_format = $config->address_format;
     119    my @address_fields = split /,/,$address_format;
     120    my %preset;
     121    for (@address_fields) {
     122        next if /code/i;   # Post code, zip code
     123        my $meth = "preset_$_";
     124        $preset{$_} = $config->$meth;
     125    }
    119126   
    120127    # Check cookie to see if we need to set the formatting_rules_link.
    121128    my ($formatting_rules_link, $omit_help_links);
     
    154161        openguides_version    => $OpenGuides::VERSION,
    155162        enable_page_deletion  => $enable_page_deletion,
    156163        language              => $config->default_language,
    157         default_city          => $default_city,
     164        address_fields        => \@address_fields,
     165        preset                => \%preset,
    158166        gmaps_api_key         => $config->gmaps_api_key
    159167    };
    160168
     
    250258    my $formatter = $args{wiki}->formatter;
    251259    my $config = $args{config};
    252260    my $script_name = $config->script_name;
     261    my @address_fields = split /,/,$config->address_format;
    253262
    254263    # Categories and locales are displayed as links in the page footer.
    255264    # We return these twice, as eg 'category' being a simple array of
     
    305314    );
    306315
    307316    if ( $args{metadata} ) {
    308         foreach my $var ( qw( phone fax address postcode os_x os_y osie_x
     317        foreach my $var ( qw( phone fax os_x os_y osie_x
    309318                              osie_y latitude longitude map_link website
    310319                              summary) ) {
    311320            $vars{$var} = $metadata{$var}[0];
    312321        }
     322
     323        $vars{address} = { map {$_, $metadata{$_}[0]} @address_fields };
     324
    313325        # Data for the distance search forms on the node display.
    314326        my $geo_handler = $config->geo_handler;
    315327        if ( $geo_handler == 1 ) {
     
    347359                    );
    348360        }
    349361    } else {
    350         foreach my $var ( qw( phone fax address postcode map_link website summary) ) {
     362        foreach my $var ( qw( phone fax map_link website summary) ) {
    351363            $vars{$var} = $q->param($var);
    352364        }
    353365
     366        $vars{address} = { map {$q->param($_) ? ($_, $q->param($_)) : ()}
     367                @address_fields };
     368
    354369        my $geo_handler = $config->geo_handler;
    355370        if ( $geo_handler == 1 ) {
    356371            require Geography::NationalGrid::GB;
  • trunk/lib/OpenGuides/RDF.pm

     
    33use strict;
    44
    55use vars qw( $VERSION );
    6 $VERSION = '0.08';
     6$VERSION = '0.09';
    77
    88use CGI::Wiki::Plugin::RSS::ModWiki;
    99use Time::Piece;
     
    4747        $node_url;
    4848      }; 
    4949    $self->{site_name}        = $config->site_name;
    50     $self->{default_city}     = $config->default_city     || "";
    51     $self->{default_country}  = $config->default_country  || "";
     50    my @adf  = split /,/,$config->address_format;
     51    $self->{address_fields}  = \@adf;
     52    for (@adf) {
     53        next if /code/i;
     54        $self->{"preset_$_"} = $config->{"preset_$_"};
     55    }
    5256    $self->{site_description} = $config->site_desc        || "";
    5357    $self->{og_version}       = $args{og_version};
    5458
     
    6872    my $opening_hours_text = $node_data{metadata}{opening_hours_text}[0] || '';
    6973    my $address            = $node_data{metadata}{address}[0]            || '';
    7074    my $postcode           = $node_data{metadata}{postcode}[0]           || '';
    71     my $city               = $node_data{metadata}{city}[0]               || $self->{default_city};
    72     my $country            = $node_data{metadata}{country}[0]            || $self->{default_country};
     75    my $town               = $node_data{metadata}{town}[0]               || $self->{preset_town};
     76    my $city               = $node_data{metadata}{city}[0]               || $self->{preset_city};
     77    my $county             = $node_data{metadata}{county}[0]             || $self->{preset_county};
     78    my $state              = $node_data{metadata}{state}[0]              || $self->{preset_state};
     79    my $country            = $node_data{metadata}{country}[0]            || $self->{preset_country};
    7380    my $latitude           = $node_data{metadata}{latitude}[0]           || '';
    7481    my $longitude          = $node_data{metadata}{longitude}[0]          || '';
    7582    my $version            = $node_data{version};
     
    8289
    8390    # replace any errant characters in data to prevent illegal XML
    8491    foreach ($phone, $fax, $website, $opening_hours_text, $address, $postcode,
    85              $city, $country, $latitude, $longitude, $version, $os_x, $os_y,
    86              @categories, @locales, $summary)
     92             $town, $city, $county, $state, $country, $latitude, $longitude,
     93             $version, $os_x, $os_y, @categories, @locales, $summary)
    8794    {
    8895      if ($_)
    8996      {
     
    150157    {
    151158      $rdf .= "\n    <!-- address and geospatial data -->\n\n";
    152159      $rdf .= "    <address>$address</address>\n"        if $address;
     160      $rdf .= "    <town>$town</town>\n"                 if $town;
    153161      $rdf .= "    <city>$city</city>\n"                 if $city;
     162      $rdf .= "    <county>$county</county>\n"           if $county;
     163      $rdf .= "    <state>$state</state>\n"              if $state;
    154164      $rdf .= "    <postalCode>$postcode</postalCode>\n" if $postcode;
    155165      $rdf .= "    <country>$country</country>\n"        if $country;
    156166
  • trunk/lib/OpenGuides.pm

     
    758758    $metadata{longitude} = delete $metadata{longitude_unmunged}
    759759        if $metadata{longitude_unmunged};
    760760
     761    # Unravel address data
     762    delete $metadata{address};
     763
     764    for (split ',',$config->address_format) {
     765        if ($metadata{preset}{$_}) {
     766            $metadata{$_} = "" unless $q->param($_);
     767        }
     768        else {
     769            $metadata{$_} = $q->param($_) if $q->param($_);
     770        }
     771    }
     772
     773    delete $metadata{preset};
     774
    761775    # Check to make sure all the indexable nodes are created
    762776    foreach my $type (qw(Category Locale)) {
    763777        my $lctype = lc($type);
  • trunk/INSTALL

     
    159159
    160160Self-explanatory.
    161161
     162  "How would you like to present addresses?"
     163 
     164Enter a comma separated list of metadata field names for an address.
     165The default of street,town,city,county,country,postalCode works for a UK
     166guide, but you are probably going to want to change this for other countries.
    162167
    163   "What city is the wiki based in?"
    164   "What country is the wiki based in?"
     168See http://www.columbia.edu/kermit/postal.html for some extreme cases, and
     169discussion as to why we can't standardise the whole thing easily.
    165170
    166 If the wiki will not be city or country specific you can leave either or
    167 both of these blank.
     171   "xxx which this guide is for? "
    168172
     173xxx is each of the fields in the address. This is how you preset a value for
     174all pages. For example, specify city as London and country as UK, leaving all
     175others blank.
    169176
    170177  "Contact email address for the wiki admin?"
    171178
  • trunk/Build.PL

     
    7575   install_directory template_path custom_template_path script_url
    7676   custom_lib_path use_plucene indexing_directory enable_page_deletion
    7777   admin_pass stylesheet_url site_name navbar_on_home_page home_name
    78    site_desc default_city default_country contact_email default_language
     78   site_desc address_format contact_email default_language
    7979   formatting_rules_node backlinks_in_title gmaps_api_key centre_long
    8080   centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
    8181  ) ) {
     
    141141    push @answers, { question => $qu,
    142142                     variable => $var,
    143143                     value    => $val };
     144    if ( $var eq "address_format" and !$skip_config ) {
     145        for (split ',',$val) {
     146            next if /code/i; # Post code, zip code
     147            my $advar = "preset_".$_;
     148            my $ucf = ucfirst $_;
     149            my $adqu = "$ucf which this guide is for? ";
     150            my $adval = Module::Build->prompt($adqu, $existing_config->$advar );
     151            push @answers, { question => $adqu,
     152                             variable => $advar,
     153                             value    => $adval } ;
     154        }
     155    }
    144156}
    145157
    146158# Now deal with the geo stuff.