Ticket #18: ticket_18.patch
| File ticket_18.patch, 21.7 kB (added by ivorw, 3 years ago) |
|---|
-
trunk/templates/display_metadata.tt
2 2 <!-- METADATA STARTS --> 3 3 4 4 <div id="metadata"> 5 [% FOREACH field = address_fields %] 6 [% IF address.$field %] 7 [% address_populated = 1 %] 8 [% END %] 9 [% END %] 5 10 [% IF phone OR fax OR address OR postcode OR formatted_website_text 6 11 OR hours_text OR map_link %] 7 12 <ul id="general_metadata"> … … 16 21 <span class="metadata_label">Fax:</span> [% CGI.escapeHTML(fax) %] 17 22 </li> 18 23 [% END %] 19 [% IF address %]24 [% IF address_populated %] 20 25 <li class="address"> 21 26 <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 %] 24 33 <a href="[% map_link %]">(map of this place)</a> 25 [% END %]34 [% END %] 26 35 </li> 27 36 [% ELSIF map_link %] 28 37 <li class="map"> 29 38 <span class="metadata_label"><a href="[% map_link %]">Map of this place</a></span> 30 39 </li> 31 40 [% END %] 32 [% IF postcode %]33 <li class="postcode">34 <span class="metadata_label">Postcode:</span>35 [% CGI.escapeHTML(postcode) %]36 </li>37 [% END %]38 41 [% IF formatted_website_text %] 39 42 <li class="website_link"> 40 43 <span class="metadata_label">Website:</span> [% formatted_website_text %] -
trunk/templates/edit_conflict.tt
66 66 <td><input type="text" size="50" id="hours" name="hours_text" value="[% stored_hours_text %]"></td> 67 67 <td>[% CGI.escapeHTML(new_hours_text) %]</td> 68 68 </tr> 69 [% FOREACH field = address_fields %] 70 [% USE String ( field ) %] 69 71 <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> 80 79 <td class="label"><label for="os_x">OS X coordinate:</label></td> 81 80 <td><input type="text" size="50" id="os_x" name="os_x" value="[% stored_os_x %]"> 82 81 <td>[% CGI.escapeHTML(new_os_x) %]</td> -
trunk/templates/edit_form.tt
1 [% USE CGI %] 1 2 [% INCLUDE header.tt page_title = "Edit $node_name - $site_name" %] 2 3 <div id="content"> 3 4 … … 74 75 <td class="label"><label for="hours">Opening hours:</label></td> 75 76 <td><input type="text" size="50" id="hours" name="hours_text" value="[% hours_text %]" /></td> 76 77 </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 %] 77 94 <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>86 95 <td class="label"><label for="[% coord_field_1 %]">[% coord_field_1_name %]:</label></td> 87 96 <td><input type="text" size="50" id="[% coord_field_1 %]" name="[% coord_field_1 %]" value="[% coord_field_1_value %]" /></td> 88 97 </tr> -
trunk/t/21_rdf.t
23 23 script_url => "http://wiki.example.com/", 24 24 script_name => "mywiki.cgi", 25 25 site_name => "CGI::Wiki Test Site", 26 default_city => "London",27 default_country => "United Kingdom",26 preset_city => "London", 27 preset_country => "United Kingdom", 28 28 } 29 29 ); 30 30 eval { require CGI::Wiki::Search::Plucene; }; … … 103 103 like( $rdfxml, qr|<dc:date>|, "date element included" ); 104 104 unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" ); 105 105 106 # Check that default city and country can be set to blank.106 # Check that preset city and country can be set to blank. 107 107 $config = OpenGuides::Test->make_basic_config; 108 $config-> default_city( "" );109 $config-> default_country( "" );108 $config->preset_city( "" ); 109 $config->preset_country( "" ); 110 110 my $guide = OpenGuides->new( config => $config ); 111 111 OpenGuides::Test->write_data( 112 112 guide => $guide, -
trunk/t/15_template.t
5 5 use OpenGuides::Config; 6 6 use OpenGuides::Template; 7 7 use Test::MockObject; 8 use Test::More tests => 28;8 use Test::More tests => 30; 9 9 10 10 my $config = OpenGuides::Config->new( 11 11 vars => { … … 13 13 site_name => 'CGI::Wiki Test Site', 14 14 script_url => 'http://wiki.example.com/', 15 15 script_name => 'mywiki.cgi', 16 default_country=> 'United Kingdom',17 default_city=> 'London',16 preset_country => 'United Kingdom', 17 preset_city => 'London', 18 18 contact_email => 'wiki@example.com', 19 19 stylesheet_url => 'http://wiki.example.com/styles.css', 20 20 home_name => 'Home Page', 21 21 formatting_rules_node => 'Rules', 22 22 formatting_rules_link => '', 23 address_format => 'street,town,city,country,postcode', 23 24 } 24 25 ); 25 26 … … 91 92 like( $output, qr/OPENGUIDES VERSION: 0\.\d\d/, 92 93 "openguides_version set" ); 93 94 95 # Test address fields list 96 like( $output, qr/ADDRESS FIELDS: Street,Town,City,Country,Postcode/, 97 "address fields" ); 98 99 TODO: { 100 local $TODO = "Address data test not ready in this module"; 101 102 # Test address layout 103 like( $output, qr/ADDRESS: 1 High Street,London,United Kingdom,AZ1 1XY./, 104 "address data" ); 105 } 106 94 107 # Test TT variables auto-set from node name. 95 108 $output = OpenGuides::Template->output( 96 109 wiki => $fake_wiki, -
trunk/t/templates/15_test.tt
17 17 OMIT FORMATTING LINK: [% omit_formatting_link %] 18 18 19 19 ENABLE PAGE DELETION: [% enable_page_deletion %] 20 21 ADDRESS FIELDS: 22 [%- FOREACH field = address_fields %] 23 [%- USE String( field ) %] 24 [%- String.capital %], 25 [%- END %] 26 27 ADDRESS: 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
8 8 dbtype dbname dbuser dbpass dbhost script_name install_directory script_url 9 9 custom_lib_path use_plucene indexing_directory enable_page_deletion 10 10 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 15 16 ); 16 17 my @questions = map { $_ . "__qu" } @variables; 17 18 OpenGuides::Config->mk_accessors( @variables ); … … 70 71 navbar_on_home_page => 1, 71 72 home_name => "Home", 72 73 site_desc => "A default configuration of OpenGuides", 73 default_city => "", 74 default_country => "", 74 address_format => 'street,town,city,county,country,postcode', 75 75 default_language => "en", 76 76 formatting_rules_node => "Text Formatting Examples", 77 77 formatting_rules_link => "http://openguides.org/page/text_formatting", … … 101 101 foreach my $var ( keys %defaults ) { 102 102 $self->$var( $defaults{$var} ); 103 103 } 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 104 116 foreach my $var ( keys %stored ) { 105 117 if ( $self->can( $var ) ) { # handle any garbage in file gracefully 106 118 $self->$var( $stored{$var} ); … … 132 144 navbar_on_home_page => "Do you want the navigation bar included on the home page?", 133 145 home_name => "What should the home page of the wiki be called?", 134 146 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? ", 137 148 contact_email => "Contact email address for the site administrator?", 138 149 default_language => "What language will the site be in? (Please give an ISO language code.)", 139 150 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", … … 151 162 foreach my $var ( keys %questions ) { 152 163 my $method = $var . "__qu"; 153 164 $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 } 154 181 } 155 182 156 183 return $self; -
trunk/lib/OpenGuides/Template.pm
115 115 116 116 my $script_name = $config->script_name; 117 117 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 } 119 126 120 127 # Check cookie to see if we need to set the formatting_rules_link. 121 128 my ($formatting_rules_link, $omit_help_links); … … 154 161 openguides_version => $OpenGuides::VERSION, 155 162 enable_page_deletion => $enable_page_deletion, 156 163 language => $config->default_language, 157 default_city => $default_city, 164 address_fields => \@address_fields, 165 preset => \%preset, 158 166 gmaps_api_key => $config->gmaps_api_key 159 167 }; 160 168 … … 250 258 my $formatter = $args{wiki}->formatter; 251 259 my $config = $args{config}; 252 260 my $script_name = $config->script_name; 261 my @address_fields = split /,/,$config->address_format; 253 262 254 263 # Categories and locales are displayed as links in the page footer. 255 264 # We return these twice, as eg 'category' being a simple array of … … 305 314 ); 306 315 307 316 if ( $args{metadata} ) { 308 foreach my $var ( qw( phone fax address postcodeos_x os_y osie_x317 foreach my $var ( qw( phone fax os_x os_y osie_x 309 318 osie_y latitude longitude map_link website 310 319 summary) ) { 311 320 $vars{$var} = $metadata{$var}[0]; 312 321 } 322 323 $vars{address} = { map {$_, $metadata{$_}[0]} @address_fields }; 324 313 325 # Data for the distance search forms on the node display. 314 326 my $geo_handler = $config->geo_handler; 315 327 if ( $geo_handler == 1 ) { … … 347 359 ); 348 360 } 349 361 } else { 350 foreach my $var ( qw( phone fax address postcodemap_link website summary) ) {362 foreach my $var ( qw( phone fax map_link website summary) ) { 351 363 $vars{$var} = $q->param($var); 352 364 } 353 365 366 $vars{address} = { map {$q->param($_) ? ($_, $q->param($_)) : ()} 367 @address_fields }; 368 354 369 my $geo_handler = $config->geo_handler; 355 370 if ( $geo_handler == 1 ) { 356 371 require Geography::NationalGrid::GB; -
trunk/lib/OpenGuides/RDF.pm
3 3 use strict; 4 4 5 5 use vars qw( $VERSION ); 6 $VERSION = '0.0 8';6 $VERSION = '0.09'; 7 7 8 8 use CGI::Wiki::Plugin::RSS::ModWiki; 9 9 use Time::Piece; … … 47 47 $node_url; 48 48 }; 49 49 $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 } 52 56 $self->{site_description} = $config->site_desc || ""; 53 57 $self->{og_version} = $args{og_version}; 54 58 … … 68 72 my $opening_hours_text = $node_data{metadata}{opening_hours_text}[0] || ''; 69 73 my $address = $node_data{metadata}{address}[0] || ''; 70 74 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}; 73 80 my $latitude = $node_data{metadata}{latitude}[0] || ''; 74 81 my $longitude = $node_data{metadata}{longitude}[0] || ''; 75 82 my $version = $node_data{version}; … … 82 89 83 90 # replace any errant characters in data to prevent illegal XML 84 91 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) 87 94 { 88 95 if ($_) 89 96 { … … 150 157 { 151 158 $rdf .= "\n <!-- address and geospatial data -->\n\n"; 152 159 $rdf .= " <address>$address</address>\n" if $address; 160 $rdf .= " <town>$town</town>\n" if $town; 153 161 $rdf .= " <city>$city</city>\n" if $city; 162 $rdf .= " <county>$county</county>\n" if $county; 163 $rdf .= " <state>$state</state>\n" if $state; 154 164 $rdf .= " <postalCode>$postcode</postalCode>\n" if $postcode; 155 165 $rdf .= " <country>$country</country>\n" if $country; 156 166 -
trunk/lib/OpenGuides.pm
758 758 $metadata{longitude} = delete $metadata{longitude_unmunged} 759 759 if $metadata{longitude_unmunged}; 760 760 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 761 775 # Check to make sure all the indexable nodes are created 762 776 foreach my $type (qw(Category Locale)) { 763 777 my $lctype = lc($type); -
trunk/INSTALL
159 159 160 160 Self-explanatory. 161 161 162 "How would you like to present addresses?" 163 164 Enter a comma separated list of metadata field names for an address. 165 The default of street,town,city,county,country,postalCode works for a UK 166 guide, but you are probably going to want to change this for other countries. 162 167 163 "What city is the wiki based in?" 164 "What country is the wiki based in?" 168 See http://www.columbia.edu/kermit/postal.html for some extreme cases, and 169 discussion as to why we can't standardise the whole thing easily. 165 170 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? " 168 172 173 xxx is each of the fields in the address. This is how you preset a value for 174 all pages. For example, specify city as London and country as UK, leaving all 175 others blank. 169 176 170 177 "Contact email address for the wiki admin?" 171 178 -
trunk/Build.PL
75 75 install_directory template_path custom_template_path script_url 76 76 custom_lib_path use_plucene indexing_directory enable_page_deletion 77 77 admin_pass stylesheet_url site_name navbar_on_home_page home_name 78 site_desc default_city default_countrycontact_email default_language78 site_desc address_format contact_email default_language 79 79 formatting_rules_node backlinks_in_title gmaps_api_key centre_long 80 80 centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 81 81 ) ) { … … 141 141 push @answers, { question => $qu, 142 142 variable => $var, 143 143 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 } 144 156 } 145 157 146 158 # Now deal with the geo stuff.
