comparison atom.php @ 0:629389204276

Import initial
author Franck Deroche <webmaster@defr.org>
date Sat, 20 Oct 2007 14:15:10 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:629389204276
1 <?php
2
3 include("classes.php");
4
5 function utf8_ensure($str) {
6 return seems_utf8($str)?$str:utf8_encode($str);
7 }
8
9 function seems_utf8($Str) {
10 for ($i=0; $i<strlen($Str) && $i<150; $i++) {
11 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
12 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
13 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
14 elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
15 elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
16 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
17 else return false; # Does not match any model
18 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
19 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
20 return false;
21 }
22 }
23 return true;
24 }
25
26 if(stristr($_SERVER['HTTP_ACCEPT'], "application/atom+xml"))
27 header("Content-Type: application/atom+xml; charset=utf-8");
28 else
29 header("Content-Type: application/xml; charset=utf-8");
30 echo("<?xml version='1.0' encoding='utf-8'?>\n");
31 $Data = new DataAccess();
32 $Data->Query("SELECT * FROM Mess ORDER BY num_mess DESC LIMIT 0, 1");
33 $val=$Data->GetRow();
34 $modifiedDate=gmdate("Y-m-d", strtotime($val['DatePost'])) . "T" . gmdate("H:i:s-02:00", strtotime($val['DatePost']));
35 ?>
36 <feed xmlns="http://www.w3.org/2005/Atom" xml:lang='fr-FR'>
37 <title>Dual Blog</title>
38 <subtitle>Le blog de DeFr, parlant de tout et de rien ^^;</subtitle>
39 <link rel='alternate' type='text/html' href='http://defr.org/blog/' />
40 <link rel='self' type='application/atom+xml' href='http://defr.org/blog/dualblog.atom' />
41 <updated><?php echo $modifiedDate; ?></updated>
42 <author>
43 <name>Deroche Franck</name>
44 <uri>http://defr.org</uri>
45 </author>
46 <id>urn:uuid:cface534-634f-4ce8-a07b-3a4187982583</id>
47 <?php
48
49 $result=$Data->Query("SELECT * FROM Mess ORDER BY num_mess DESC LIMIT 0, 20");
50 while($val=$Data->GetRow()) {
51 $utf8_Mess=str_replace("</P>", "</p>", str_replace("<P>", "<p>", (str_replace("&euro;", "&#x20AC;", utf8_ensure($val['Message'])))));
52 $utf8_Mess = str_replace("&nbsp;", " ", $utf8_Mess);
53 $utf8_Titre=utf8_ensure($val['Titre']);
54 $issuedDate=gmdate("Y-m-d", strtotime($val['DatePost'])) . "T" . gmdate("H:i:s-02:00", strtotime($val['DatePost']));
55 echo("
56 <entry>
57 <title type='xhtml'>
58 <div xmlns='http://www.w3.org/1999/xhtml'>
59 {$utf8_Titre}
60 </div>
61 </title>
62 <id>tag:defr.org,2006:{$val['num_mess']}</id>
63 <content type='xhtml'>
64 <div xmlns='http://www.w3.org/1999/xhtml'>
65 {$utf8_Mess}
66 </div>
67 </content>
68 <published>{$issuedDate}</published>
69 <updated>{$issuedDate}</updated>
70 <link rel='alternate' type='text/html' href='http://www.defr.org/blog/posts/{$val['id']}' />
71 </entry>
72 ");
73 }
74 ?>
75 </feed>