メモ

<?php

$rssurl = "http://twitter.com/statuses/user_timeline/$username.rss";
//$searchrssurl = "http://twitter.1x1.jp/rss/search/?keyword=$username+&text=1";	//被言及検索URL Twitter検索
$searchrssurl = "http://buzztter.com/ja/rss/$username";	//被言及検索URL バズッター
$substrstartpos = 19;
$source = "";
$search = array(
	"\n",
	$username.": ",
	"@@@@置換対象文字列を入れる配列ですが何か@@@@");
$replace = array(
	"<br>",
	"",
	"置き換える文字列");

if(false !== strstr ($_SERVER['HTTP_USER_AGENT'],"KDDI")){
	$source ="TwitterFox";
	header("Cache-Control:no-cache");
	$dummy = "?d=".mt_rand();
}
if(false !== strstr ($_SERVER['HTTP_USER_AGENT'],"WILLCOM")){
	$source ="twitterrific";
}

if(isset($_GET['to'])){$to = "@".$_GET['to']." ";}

//ポスト
if(isset($_POST['status']))
{
	$status = trim($_POST['status']);
	$rss = simplexml_load_file($rssurl);

	if($status != "" && $rss->channel->item[0]->description != $username.": ".$status)
	{
		$url = "http://twitter.com/statuses/update.xml?";
		$params = "status=". rawurlencode($status);
		if($source != "")$params .= "&source=$source";
		$result = file_get_contents($url.$params , false, stream_context_create(array(
			"http" => array(
				"method" => "POST",
				"header" => "Authorization: Basic ". base64_encode($username. ":". $password)
			)
		)));
		usleep(500000);
	}
	header("Location: ./$exe$dummy");//.$base_url);
	exit;
}

?><html><head><title>post</title></head><body><a name="top"></a><form action=
<?php echo "\"./$exe\""
?> method="POST"><textarea name="status" cols="45" rows="7" wrap="soft"><?php
echo str_replace("\t"," \r\n",$to);
?></textarea><br><input type="submit" name="write" value="up"> <a href=<?php
echo "\"./$exe\"";
?>>reload</a> <a href="#at">@</a> <a href="#ft">link</a> <a href="./u.php?u=http://m.twitter.com/<?php
echo "$username";
?>"><?php
echo "$username";
?></a></form><div><?php

//タイムライン表示
$rss = simplexml_load_file($rssurl);
$date = "";
for($i = 0; $i < 10; $i++) {
	$pubDate = strtotime($rss->channel->item[$i]->pubDate);
	$description = str_replace($search,$replace,$rss->channel->item[$i]->description);
	if($date != date("Ymd",$pubDate)){
		$date = date("Ymd",$pubDate);
		echo "<font size=-2 color=#555>$date</font><br>";
	}
	echo '<font size=-2 color=#999>'.date("H:i:s",$pubDate)."</font><br>";
	echo $description."<br>";
}

?><a name="at"><hr></a><a href="#top">top</a><br><?php

$rss = simplexml_load_file($searchrssurl);
for($i = 0; $i < 20; $i++) {
	$pubDate = strtotime($rss->channel->item[$i]->pubDate);
	$description = str_replace($search,$replace,$rss->channel->item[$i]->description);
	if($description == ""){
		break;
	}
	$link = $rss->channel->item[$i]->link;
	$to = substr($link,$substrstartpos,strpos($link,'/statuses/')-$substrstartpos); //バズッター
//	$to = substr($rss->channel->item[$i]->title,$substrstartpos,strpos($rss->channel->item[$i]->title,"<")-1-$substrstartpos); //Twitter検索

	if($date != date("Ymd",$pubDate)){
		$date = date("Ymd",$pubDate);
		echo "<font size=-2 color=#555>$date</font><br>";
	}
	echo '<font size=-2 color=#999>'.date("H:i:s",$pubDate)."</font> ";
	echo '<a href="./'.$exe.'?to='.$to."%09".$link.'">'.$to.'</a>';
	echo "<br>".substr($description,strpos($description,":")+1)."<br>";
}
//echo "<pre>";var_dump ($rss);echo "</pre>";

?><a name="ft"><hr></a><a href="#top">top</a> | <a href="./u.php?u=http://m.twitter.com/">m.twitter</a></div></body></html>
<?php
//echo "<pre>";var_dump ($rss);echo "</pre>";