<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Horn Network &#187; JavaScript</title>
	<atom:link href="http://klcin.tw/net/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://klcin.tw/net</link>
	<description>Horn Network (.NET, ASP.NET, C#, VB.NET, JavaScript, Ubuntu, Android ...)</description>
	<lastBuildDate>Fri, 04 Mar 2011 07:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[PHP]PO3 一次幫你從3個地方（Buboo,Plurk,Twitter）讀取訊息！</title>
		<link>http://klcin.tw/net/pop3-read</link>
		<comments>http://klcin.tw/net/pop3-read#comments</comments>
		<pubDate>Wed, 09 Jul 2008 15:41:05 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PO3]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Buboo]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[Plurk]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=8</guid>
		<description><![CDATA[為了統一來源及安全限制，我在server端放一個ajax.php用來取得Buboo,Plurk,Twitter的json資料，在client使用javascript處理資料呈現。 資料來源及內容： Buboo [資料來源] : http://api.buboo.tw/user_timeline/{使用者帳號}.rss?count={訊息數量}created_at : 日期（2008-07-07 23:15）text : 訊息內容id : 訊息代號（8f8170289cba351） 原文網址：http://buboo.tw/msg/{id}.html Plurk [資料來源] : 無直接網址。需先取的userid(數字)，再POST到 http://www.plurk.com/TimeLine/getPlurks ，其中欄位 user_id=$useridqualifier : 動作（”:”表示未指定）content_raw : 訊息內容content : 訊息內容（已格式成HTML）posted : 日期（new Date(&#34;Mon, 07 Jul 2008 04:08:40 GMT&#34;)） 原文網址：無 Twitter [資料來源] : http://twitter.com/statuses/user_timeline/{使用者帳號}.json&#38;count={訊息數量}text : 訊息內容Source : 發訊來源id : 訊息代號（851703528）created_at : 日期（Mon Jul 07 04:08:41 +0000 2008） 原文網址：http://twitter.com/{user.screen_name}/statuses/{id} &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>為了統一來源及安全限制，我在server端放一個ajax.php用來取得Buboo,Plurk,Twitter的json資料，在client使用javascript處理資料呈現。</p>
<p><span id="more-8"></span>
<p><strong>資料來源及內容：</strong></p>
<hr size="1" />
<a href="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsonbuboo.gif"><img title="json-buboo" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 0px 0px; border-right-width: 0px" height="218" alt="json-buboo" src="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsonbuboo_thumb.gif" width="167" align="left" border="0" /></a>
<p><strong>Buboo</strong> <sup>[<a href="http://buboo.tw/apidoc" target="_blank">資料來源</a>]</sup> : <font color="#ff0000">http://api.buboo.tw/user_timeline/{使用者帳號}.rss?count={訊息數量}</font><br />created_at : 日期（2008-07-07 23:15）<br />text : 訊息內容<br />id : 訊息代號（8f8170289cba351）</p>
<p>原文網址：<font color="#ff0000">http://buboo.tw/msg/{id}.html</font><br clear="all" /></p>
<hr size="1" />
<a href="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsonplurk.gif"><img title="json-plurk" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 0px 0px; border-right-width: 0px" height="278" alt="json-plurk" src="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsonplurk_thumb.gif" width="144" align="left" border="0" /></a>
<p><strong>Plurk</strong> <sup>[<a href="http://plurkwiki.badchemicals.net/index.php?title=TimeLine/getPlurks" target="_blank">資料來源</a>]</sup> : 無直接網址。<br />需先取的userid(數字)，再POST到 <font color="#ff0000">http://www.plurk.com/TimeLine/getPlurks</font> ，其中欄位 user_id=$userid<br />qualifier : 動作（”:”表示未指定）<br />content_raw : 訊息內容<br />content : 訊息內容（已格式成HTML）<br />posted : 日期（new Date(&quot;Mon, 07 Jul 2008 04:08:40 GMT&quot;)）</p>
<p>原文網址：無<br clear="all" /></p>
<hr size="1" />
<a href="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsontwitter.gif"><img title="json-twitter" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 0px 0px; border-right-width: 0px" height="313" alt="json-twitter" src="http://klcin.tw/net/images/PHPPO33BubooPlurkTwitter_13E10/jsontwitter_thumb.gif" width="185" align="left" border="0" /></a>
<p><strong>Twitter</strong> <sup>[<a href="http://groups.google.com/group/twitter-development-talk/web/api-documentation#StatusMethods" target="_blank">資料來源</a>]</sup> : <font color="#ff0000">http://twitter.com/statuses/user_timeline/{使用者帳號}.json&amp;count={訊息數量}</font><br />text : 訊息內容<br />Source : 發訊來源<br />id : 訊息代號（851703528）<br />created_at : 日期（Mon Jul 07 04:08:41 +0000 2008）</p>
<p>原文網址：<font color="#ff0000">http://twitter.com/{user.screen_name}/statuses/{id}</font><br clear="all" /></p>
<p>&nbsp;</p>
<p><strong>Server端 ajax.php：</strong></p>
<pre class="brush: php">&lt;?php
# 設定傳入參數改以 p_ 開頭變數表示
import_request_variables(&#039;gp&#039;, &#039;p_&#039;);

if ( $p_type==&quot;plurk&quot; ) {
	// plurk 特別處理
	echo get_plurk($p_username);
} // if
else {
	// 一般指定url
	echo file_get_contents($p_url, 1000000);
} // else

// 取得plurk資料
function get_plurk($uid) {
	if ( $uid==&quot;&quot; ) return &quot;&quot;;

	$curl_handle = curl_init();
	curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

	// 先從網頁解析出user_id
	curl_setopt($curl_handle, CURLOPT_URL, &quot;http://www.plurk.com/user/$uid&quot;);
	$html = curl_exec($curl_handle);
	preg_match(&#039;/var GLOBAL = \{.*&quot;uid&quot;: ([\d]+),.*\}/imU&#039;, $html, $matches);
	$uid = $matches[1];

	if ( $uid == &#039;&#039; )
		$json = &quot;No User&quot;;
	else {
		// 用POST送出請求
		curl_setopt($curl_handle, CURLOPT_URL, &#039;http://www.plurk.com/TimeLine/getPlurks&#039;);
		curl_setopt($curl_handle, CURLOPT_POSTFIELDS, &quot;user_id=$uid&quot;);
		$json = curl_exec($curl_handle);
	} // else

	curl_close($curl_handle);

	return $json;
}

?&gt;</pre>
<p>&nbsp;</p>
<p><strong>Client端 javascript：</strong></p>
<p>AJAX (prototype)</p>
<pre class="brush: javascript">function ajaxBuboo() {
	var uid = $(&#039;userid&#039;).value;
	$(&#039;divBuboo&#039;).innerHTML = &quot;loading (&quot;+uid +&quot;)...&quot;;
	var url = &#039;ajax.php?url=http://api.buboo.tw/user_timeline.json?uid=&#039;+uid +&#039;&amp;amp;count=5&#039;;
	new Ajax.Request(url,
　		{
　　	method: &#039;get&#039;,
	　　asynchronous: true,
　　	onSuccess:showResultBuboo,
	　　onFailure:ShowFailure
　		}
	);
}
function showResultBuboo(httpObj) {
	$(&#039;divBuboo&#039;).innerHTML = buboo(httpObj.responseText.evalJSON(false));
}</pre>
<p>Buboo</p>
<pre class="brush: javascript">function buboo(json) {
	var retHtml = &quot;&quot;;
	for (var i=0; i&lt;json.length &amp;&amp; i&lt;&lt;?=$count?&gt;; i++){
		retHtml += (&#039;&lt;li&gt;&#039;+json[i].text+&#039; &lt;a href=&quot;http://buboo.tw/msg/&#039;+
			json[i].id+&#039;.html&quot; target=&quot;_blank&quot;&gt;url&lt;/a&gt;&lt;/li&gt;&#039;
		);
	} // for
	return retHtml;
}</pre>
<p>Plurk</p>
<pre class="brush: javascript">function plurk(json) {
	var retHtml = &quot;&quot;;
	for (var i=0; i&lt;json.length ; i++){
		retHtml += (&#039;&lt;li&gt;&#039;+
			(json[i].qualifier==&quot;:&quot;?&quot;&quot;:json[i].qualifier+&quot;:&quot; )+&#039; &#039;+
			json[i].content+&#039; [&#039;+json[i].response_count+&#039;]&lt;/li&gt;&#039;
		);
	} // for
	return retHtml;
}</pre>
<p>Twitter</p>
<pre class="brush: javascript">function twitter(json) {
	var retHtml = &quot;&quot;;
	var username = &quot;&quot;;
	for (var i=0; i&lt;json.length; i++){
		retHtml += (&#039;&lt;li&gt;&#039;+json[i].text+&#039; &lt;a href=&quot;http://twitter.com/&#039;+
			json[i].user.screen_name+&#039;/statuses/&#039;+json[i].id+&#039;&quot; target=&quot;_blank&quot;&gt;url&lt;/a&gt;&lt;/li&gt;&#039;
		);
	} // for
	return retHtml;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/pop3-read/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

