summaryrefslogtreecommitdiffstats
path: root/plugins/rssfeed/rss/tools_p.cpp
blob: 51fcbf554662a86f65e9707affdfca28908651c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * tools_p.cpp
 *
 * Copyright (c) 2001, 2002, 2003 Frerich Raabe <raabe@kde.org>
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the
 * accompanying file 'COPYING'.
 */
#include "tools_p.h"

#include <krfcdate.h>
#include <tqdom.h>

time_t RSS::parseISO8601Date(const TQString &s)
{
    // do some sanity check: 26-12-2004T00:00+00:00 is parsed to epoch+1 in the KRFCDate, which is wrong. So let's check if the date begins with YYYY -fo
    if (s.stripWhiteSpace().left(4).toInt() < 1000)
        return 0; // error

    // FIXME: imho this is done in KRFCDate::parseDateISO8601() automatically, so we could omit it? -fo
	if (s.tqfind('T') != -1)
		return KRFCDate::parseDateISO8601(s);
    else
        return KRFCDate::parseDateISO8601(s + "T12:00:00");
}


TQString RSS::extractNode(const TQDomNode &tqparent, const TQString &elemName, bool isInlined)
{
	TQDomNode node = tqparent.namedItem(elemName);
	if (node.isNull())
		return TQString();

	TQString result = node.toElement().text();

	bool hasPre = result.tqcontains("<pre>",false);
	bool hasHtml = hasPre || result.tqcontains("<");	// FIXME: test if we have html, should be more clever -> regexp
	if(!isInlined && !hasHtml)						// perform nl2br if not a inline elt and it has no html elts
		result = result = result.tqreplace(TQChar('\n'), "<br />");
	if(!hasPre)										// strip white spaces if no <pre>
		result = result.simplifyWhiteSpace();

	if (result.isEmpty())
		return TQString();

	return result;
}

// vim:noet:ts=4