diff tb_send.php @ 0:629389204276

Import initial
author Franck Deroche <webmaster@defr.org>
date Sat, 20 Oct 2007 14:15:10 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tb_send.php	Sat Oct 20 14:15:10 2007 +0200
@@ -0,0 +1,48 @@
+<?php
+	include("classes.php");
+	$Data = new DataAccess();
+	$Data->Query("SELECT * FROM Mess WHERE num_mess=255");
+	$row = $Data->GetRow();
+	$tbAddress = "http://www.defr.org/blog/tb.php?id=255";
+	$ar_tbAddress = parse_url($tbAddress);
+	if(!array_key_exists('port', $ar_tbAddress)) $ar_tbAddress['port'] = 80;
+	if(!array_key_exists('path', $ar_tbAddress)) $ar_tbAddress['path'] = '/';
+	if(array_key_exists('query', $ar_tbAddress)) $ar_tbAddress['query'] = '?' . $ar_tbAddress['query'];
+	var_export($ar_tbAddress);
+		$fp = fsockopen($ar_tbAddress['host'], 80, $errno, $errstr, 15);
+		if($fp) {
+			$genToSend = "POST {$ar_tbAddress['path']}{$ar_tbAddress['query']} HTTP/1.0\r\n";
+			$genToSend .= "Host: {$ar_tbAddress['host']}\r\n";
+			$genToSend .= "Content-Type: application/x-www-form-urlencoded \n";
+			
+			// Essai de récuperation de l'encodage...Envoie en iso si pas d'indication d'UTF...
+			$argToSend = "__info=1";
+			$toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n";
+			$toSend .= $argToSend;
+			echo("<pre>$toSend</pre>");
+			fwrite($fp, $toSend);
+			while(!feof($fp))
+				$result .= fgets($fp, 128);
+			fclose($fp);
+			if(!preg_match('/<encoding>(UTF-8|utf-8)<\/encoding>/msU',$result)) {
+				$row['Titre'] = utf8_decode($row['Titre']);
+				$row['Message'] = utf8_decode($row['Message']);
+				echo("Snif, utilisation d'ISO...");
+			}
+			
+			$fp = fsockopen($ar_tbAddress['host'], 80, $errno, $errstr, 15);
+			$argToSend = "title=" . htmlentities(urlencode($row['Titre'])) . "&blog_name=Dual+Blog";
+			$argToSend .= "&url=http://defr.org/blog/posts/{$row['num_mess']}&excerpt=" . htmlentities(urlencode(substr(strip_tags($row['Message']), 0, 255) . "..."));
+
+			$toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n";
+			$toSend .= $argToSend;
+			echo("<pre>$toSend</pre>");
+			fwrite($fp, $toSend);
+			while (!feof($fp)) {
+				echo fgets($fp, 128);
+			}
+			fclose($fp);
+		} else {
+			echo("Pb de connexion : $errno - $errstr");
+		}
+?>
\ No newline at end of file