Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

XMLResults plugin updates

Quote Reply
XMLResults plugin updates
I have identified a few issues concerning the old XMLResults plugin, and thought others might be interested.

Character problems?
I use LSQL in various languages, and have had problems with character encoding of the generated XML. I have found that the solution is to hard-code the encoding into the header.
Solution:
In the /Plugins, you have XMLResults.pm. Find the section below and edit to something like:

Code:
sub pre_search_results {
# -------------------------------------------------------------------
# This is run before the actual search, and is just used to print
# a proper text/xml header (as long as we do it before the text/html
# we are ok).
#
my @args = @_;
if ($IN->param('xml_feed')) {
print $IN->header('text/xml; Charset="ISO-8859-1"');
}
return @_;
}
In XML, the preference is UTF-8, so really it should say: 'text/xml; Charset="UTF-8"'.

I am not an expert in character encoding but think that you cannot "trick" the content to become any kind of charset just by declaring it so. The declaration must match the content. Out of the box LSQL creates pure ASCII-US, I think.

The character encoding must also be specified in the generated XML, of course. Edit the xml_search_results.xml template. The template below is tested and works for me, and might be an inspiration for others. This template creates the more modern RSS 2.0, by the way.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>

<title><%site_title%></title>
<link><%build_root_url%></link>
<description>xxx</description>
<language>sv</language>
<lastBuildDate><%date%> <%time%>GMT</lastBuildDate>
<copyright>xxx</copyright>
<managingEditor>xxx</managingEditor>
<webMaster>xxx</webMaster>

<%loop link_results_loop%>
<item>
<title><%Title%></title>
<link><%build_cgi_url%>/page.cgi?g=artiklar%2F<%ID%>.shtml</link>
<description><%Description%></description>
<pubDate><%Add_Date%> <%time%> GMT</pubDate>
<guid isPermaLink="false"><%build_cgi_url%>/page.cgi?g=pages%2F<%ID%>.html</guid>
</item>
<%endloop%>
</channel>
</rss>

<%time%> is fake time - I use a global (below) that inserts the current time. Strictly speaking, this is not right, of course, but otherwise one must create a timestamp field.

Code:
sub {
# Displays the current time.
my ($sec,$min,$hr) = localtime( time + ($Links::CFG->{date_offset} *3600));
return sprintf ("%02d:%02d:%02d", $hr, $min, $sec);
}

John

Last edited by:

gotze: Dec 28, 2004, 2:48 PM
Quote Reply
Re: [gotze] XMLResults plugin updates In reply to
Hello,

I've the same problem that my feed is not valid. I'm using the above solution with this template:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>

<title><%site_title%></title>
<link><%build_root_url%></link>
<description>xxx</description>
<language>de</language>
<lastBuildDate><%date%> <%time%> GMT</lastBuildDate>
<copyright>xxx</copyright>
<managingEditor>xx@xxx.de (xxx)</managingEditor>
<webMaster>webmaster@xxx.de (xxx)</webMaster>

<%loop link_results_loop%>
<item>
<title><%Title%></title>
<link><%db_cgi_url%>/detail_page.cgi?ID=<%ID%></link>
<description><%Description%></description>
<pubDate><%Add_Date%> <%time%> GMT</pubDate>
<guid isPermaLink="false"><%db_cgi_url%>/detail_page.cgi?ID=<%ID%></guid>
</item>
<%endloop%>
</channel>
</rss>

My problem is that I'm using a german version and therefore I've german date format. So the feed is not valid, because I need international format. This is what validator says: pubDate must be an RFC-822 date-time: Sonntag, 29.08.2010 19:50:55 GMT.

Any ideas?

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
So what does your file actually look like? (the date bit specifically)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
Hi Andy,

here's my rss feed

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>xxx</title>
<link>http://www.xxx.de</link>
<description>xxx</description>
<language>de</language>
<lastBuildDate>Montag, 30.08.2010 21:52:02 GMT</lastBuildDate>
<copyright>xxx</copyright>
<managingEditor>xxx@xxx.de (xxx)</managingEditor>
<webMaster>xxx@xxx.de (xxx)</webMaster>
<item>
<title>Winterlicher Reisebericht von der Algarve</title>
<link>http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9803</link>
<description>Wenn man bei grauem Schneematschwetter Ende Januar in Deutschland gestartet ist und in Faro landet, ist es wie ein Wunder: Man schaut sich um und alles ist unglaublich hell und von gedämpftem Sonnenlicht überflutet. Bei angenehm milder Außentemperatur so um die 20 Grad muss man sich erst mal der Strumpfhose unter den Jeans entledigen, bevor man in seinen (bereits in Deutschland günstig gebuchten) Mietwagen steigt und losfährt in den Frühling! Überall dieses unbeschreibliche Licht und blühende Mandelbäume, die einen begleiten auf der Fahrt durch diese traumhafte Gartenlandschaft. Netter und umfangreicher Reisebericht.</description>
<pubDate>Dienstag, 17.08.2010 21:52:02 GMT</pubDate>
<guid isPermaLink="false">http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9803</guid>
</item>
<item>
<title>Der Cão de Água Português</title>
<link>http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9804</link>
<description>Alles über den Portugiesischen Wasserhund: Bilder, Überraschendes, Nützliches, Wissenswertes Sachen zum schmunzeln, weiterführende Links ein Gästebuch für eigene Kommentare, Erfahrungen, Anregungen und Streitbares. Ganz nett gemacht.</description>
<pubDate>Montag, 16.08.2010 21:52:02 GMT</pubDate>
<guid isPermaLink="false">http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9804</guid>
</item>
<item>
<title>Ferienhaus auf Santa Maria Azoren</title>
<link>http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9802</link>
<description>Auf dieser Seite erhalten Sie viele Information über die Azoreninsel Santa Maria. Es werden außerdem einige Ferienhäuser angeboten. Es gibt viele Bilder rund um die Inseln Santa Maria.</description>
<pubDate>Dienstag, 17.08.2010 21:52:02 GMT</pubDate>
<guid isPermaLink="false">http://www.xxx.de/cgi-bin/detail_page.cgi?ID=9802</guid>
</item>

hope this helps

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
Untested, but in place of <%date%>, try this tag:

Code:
<%GT::Date::date_transform($date,"%dddd%, %dd%.%mm%.%yyyy%", "%dd%-%mm%-%yyyy%")%>

This should convert it to the right format.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
thx Andy, but doesn't work at all ...

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
What does it do? No value there at all?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
no value ... only the time-global shows the time

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
In Setup > Date Options > date_long_format , what do you have set?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
Code:
%dddd%, %dd%. %mmmm% %yyyy%

Problem is, that I've german values there ...

date_days_long is
Code:
Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Sonnabend
and date_days_short
Code:
So,Mo,Di,Mi,Do,Fr,Sa
which doesn't fit into the rfc-rules for rss 2.0

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
Mmm ok, based on the code you provided earlier, I didn't think this would work - but seeing as this is how you have your settings - please try:

<%GT::Date::date_transform($date,"%dddd%, %dd%. %mmmm% %yyyy%", "%dd%-%mm%-%yyyy%")%>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
there must be a mistake - doesn't work either ... what is wrong there?

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
One of the crappy things with GT::Date is when you set the date language, you have to reset it when you're trying to parse and generate english dates.

Adrian
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
You try it with a global:

convert_to_eng_format_for_sitemap
Code:
sub {
my $date = $_[0];
if ($date =~ m/\d\d\.\d\d\.\d\d\d\d$/) {
return qq|${3}-${2}-${1}|;
}
}

..then call with:

Code:
<%convert_to_eng_format_for_sitemap($date)%>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
thx Andy, but no value again. I've tested the template with another global and it works ... I've a global called "date" could this affect yours?

Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
Aah ok - so what code do you have in the "date" global?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
Code:
sub {
# Displays the current date.
Links::init_date();
GT::Date::date_set_format($CFG->{'date_user_format'});
my $date = GT::Date::date_get();
GT::Date::date_set_format($CFG->{'date_db_format'});
return $date;
}
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
Ah, well there is our problem <G>

Try this for the "date" sum (rename the global to something else, if you are using the <%date%> sub anywhere else)

Code:
sub {
# Displays the current date.
Links::init_date();
GT::Date::date_set_format('%yyyy%-%mm%-%dd%');
my $date = GT::Date::date_get();
return $date;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Sep 1, 2010, 11:39 PM
Quote Reply
Re: [Andy] XMLResults plugin updates In reply to
Hallo Andy,

1. I've changed my date-global with your code
2. I've used your global to convert the date
3. again nothing ...
Kai
___________________________________________
http://www.westalgarve.de
http://www.portugalforum.org
http://www.portugal-links.de
Quote Reply
Re: [kailew] XMLResults plugin updates In reply to
Hi,

Sorry, was a typo (serves me right posting so late in the evening ;))

Please try this:

Code:
sub {
# Displays the current date.
Links::init_date();
GT::Date::date_set_format('%yyyy%-%mm%-%dd%');
my $date = GT::Date::date_get();
return $date;
}

I just tested it, and seems to work fine.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!