-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery.php
76 lines (53 loc) · 2.5 KB
/
query.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of the Strillone package.
*
* (c) Informatici Senza Frontiere Onlus <http://informaticisenzafrontiere.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include 'config.php';
if (is_numeric($_GET['edizione'])) {
$edizione = substr($_GET['edizione'],0,4) . "-" . substr($_GET['edizione'],4,2) . "-" . substr($_GET['edizione'],6,2);
$wrong_string = array("%","<TAB>","<i>","<I>","</i>","</I>","<b>","<B>","</b>","</B>","<br>","<BR>","<BR />","<BR/>"," ","’","«","»","&");
$right_string = array(" %","","","","","","","","",""," "," "," "," "," ","'","'","'","e");
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<giornale>
<lingua>it</lingua>
<testata>Brescia on line</testata>
<edizione>" . $edizione . "</edizione>";
$query = "SELECT * FROM articoli WHERE (edizione = '" . $_GET['edizione'] . "') AND (sezione != '') AND (testo != '') AND ((occhiello != '') OR (titolo != '') OR (sottotitolo != '')) ORDER BY sezione;";
$result = mysql_query($query) or $esito = mysql_error();
$sezione_attiva = '';
$i = 0;
$j = 0;
while ($linea = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($linea['sezione'] != $sezione_attiva) {
$i++;
$j = 0;
if ($i > 1) {
$xml .= " </sezione>";
}
$xml .= "\n <sezione>
<nome>Sezione " . $i . ": " . $linea['sezione'] . "</nome>";
}
$j++;
$xml .= "
<articolo>
<titolo><![CDATA[Articolo " . $j . ": " . trim(str_replace($wrong_string, $right_string, $linea['occhiello'])) . " " . trim(str_replace($wrong_string, $right_string, $linea['titolo'])) . " " . trim(str_replace($wrong_string, $right_string, $linea['sottotitolo'])) . "]]></titolo>
<testo><![CDATA[" . trim(str_replace($wrong_string, $right_string, $linea['testo'])) . "]]></testo>
</articolo>\n";
$sezione_attiva = $linea['sezione'];
}
$xml .= " </sezione>
</giornale>";
header('Content-Type: text/xml; charset=utf-8');
echo($xml);
} else {
echo "errore";
}
// da normalizzare in futuro gli articoli di questi tipi:
// "SELECT * FROM articoli WHERE sezione = '';
// "SELECT * FROM articoli WHERE testo = '';"
// "SELECT COUNT(*) FROM articoli WHERE (edizione = '20121120') AND ((occhiello = '') OR (titolo = '') OR (sottotitolo = ''));"