Mercurial > defr > DualBlog
comparison tb_send.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 include("classes.php"); | |
3 $Data = new DataAccess(); | |
4 $Data->Query("SELECT * FROM Mess WHERE num_mess=255"); | |
5 $row = $Data->GetRow(); | |
6 $tbAddress = "http://www.defr.org/blog/tb.php?id=255"; | |
7 $ar_tbAddress = parse_url($tbAddress); | |
8 if(!array_key_exists('port', $ar_tbAddress)) $ar_tbAddress['port'] = 80; | |
9 if(!array_key_exists('path', $ar_tbAddress)) $ar_tbAddress['path'] = '/'; | |
10 if(array_key_exists('query', $ar_tbAddress)) $ar_tbAddress['query'] = '?' . $ar_tbAddress['query']; | |
11 var_export($ar_tbAddress); | |
12 $fp = fsockopen($ar_tbAddress['host'], 80, $errno, $errstr, 15); | |
13 if($fp) { | |
14 $genToSend = "POST {$ar_tbAddress['path']}{$ar_tbAddress['query']} HTTP/1.0\r\n"; | |
15 $genToSend .= "Host: {$ar_tbAddress['host']}\r\n"; | |
16 $genToSend .= "Content-Type: application/x-www-form-urlencoded \n"; | |
17 | |
18 // Essai de récuperation de l'encodage...Envoie en iso si pas d'indication d'UTF... | |
19 $argToSend = "__info=1"; | |
20 $toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n"; | |
21 $toSend .= $argToSend; | |
22 echo("<pre>$toSend</pre>"); | |
23 fwrite($fp, $toSend); | |
24 while(!feof($fp)) | |
25 $result .= fgets($fp, 128); | |
26 fclose($fp); | |
27 if(!preg_match('/<encoding>(UTF-8|utf-8)<\/encoding>/msU',$result)) { | |
28 $row['Titre'] = utf8_decode($row['Titre']); | |
29 $row['Message'] = utf8_decode($row['Message']); | |
30 echo("Snif, utilisation d'ISO..."); | |
31 } | |
32 | |
33 $fp = fsockopen($ar_tbAddress['host'], 80, $errno, $errstr, 15); | |
34 $argToSend = "title=" . htmlentities(urlencode($row['Titre'])) . "&blog_name=Dual+Blog"; | |
35 $argToSend .= "&url=http://defr.org/blog/posts/{$row['num_mess']}&excerpt=" . htmlentities(urlencode(substr(strip_tags($row['Message']), 0, 255) . "...")); | |
36 | |
37 $toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n"; | |
38 $toSend .= $argToSend; | |
39 echo("<pre>$toSend</pre>"); | |
40 fwrite($fp, $toSend); | |
41 while (!feof($fp)) { | |
42 echo fgets($fp, 128); | |
43 } | |
44 fclose($fp); | |
45 } else { | |
46 echo("Pb de connexion : $errno - $errstr"); | |
47 } | |
48 ?> |