実行結果
設置サンプル
picplz APIからフィードを取得し、投稿写真を一覧表示。
参照:picplz API
設置サンプルのソース
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title>設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jquery.jsonp.js"></script>
<!-- JS -->
<script type="text/javascript">
$(function(){
// picplzのRSSフィードを取得
var url="https://api.picplz.com/api/v2/user.json?include_pics=1&username=cocoism&callback={callback}";
//(特定のユーザーが投稿した写真のみ検索する場合)
//var url="http://search.twitter.com/search.json?q=p.twipple.jp+from%3Acocoism&rpp=100&callback={callback}";
$.getJSONP(url, function(json){
var s=ss="";
var formatStr="";
var _users=json.value.users[0];
ss+="<a href='http://picplz.com/user/"+_users.username+"/' class='prof'><img src='"+_users.icon.url+"' /></a>";
ss+="<p>";
ss+="<strong><a href='http://picplz.com/"+_users.username+"'>"+_users.display_name+"</a></strong>";
ss+="</p>";
ss+="<p>";
ss+="フォロー数:"+_users.following_count+" ";
ss+="フォロワー数:"+_users.follower_count+" ";
ss+="投稿写真数:"+_users.pic_count;
ss+="</p>";
$.each(_users.pics, function(i, item){
formatStr=formatTwitterString(item.caption);
s="<li><div class='box'>";
s+="<p>";
s+="id:"+item.id+"<br>";
s+="date:"+item.date+"<br>";
s+="view_count:"+item.view_count+"<br>";
// s+="url:"+item.url+"<br>";
s+="like_count:"+item.like_count+"<br>";
s+="description:"+formatStr;
s+="</p>";
$.each(item.pic_files, function(j, item2){
if(j=="100sh"){// 320rh, 640r
s+="<div class='thumb'><a href='"+item.url+"'><img src='"+item2.img_url+"' /></a></div>";
}
});
s+="</div></li>";
$("#tw ul").append(s);
});
$("#tw").before("<div id='myprof'>"+ss+"</div>");
});
});
// リンク内につぶやきを含むURLに変更
function formatTwitterString(str){
str = str.replace(/((ftp|http|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
str = str.replace(/@(\w+)/gm,'<a href="http://twitter.com/$1" target="_blank">@$1</a>');
str = str.replace(/#(\w+)/gm,'<a href="http://search.twitter.com/search?q=$1" target="_blank">#$1</a>');
return str;
}
function relativeTime(pastTime){
var origStamp = Date.parse(pastTime);
var curDate = new Date();
var currentStamp = curDate.getTime();
var difference = parseInt((currentStamp - origStamp)/1000);
if(difference < 0) return false;
if(difference <= 5) return "いまさっき";
if(difference <= 20) return "数秒前";
if(difference <= 60) return "1分以内";
if(difference < 3600) return parseInt(difference/60)+" 分前";
if(difference <= 1.5*3600) return "One hour ago";
if(difference < 23.5*3600) return Math.round(difference/3600)+" 時間前";
if(difference < 1.5*24*3600) return "1日前";
var dateArr = pastTime.split(' ');
return (parseInt(difference / 86400)).toString() + '日前';
}
</script>
<style type="text/css">
#tw {
margin:0; padding:0;
clear:both;
}
#tw ul {
list-style:none;
margin:0; padding:0;
border:1px solid #ccc;
font-size:12px;
background:#eee;
webkit-border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;
font-size:10px;
overflow:hidden;
}
#tw li {
list-style:none;
display:block;
margin:10px 10px 10px 10px; padding:0 0 0 105px;
height:200px;
position:relative;
}
#tw p {
margin:0 0 0 105px; padding:0;
}
#tw div.thumb {
display:block;
width:202px; height:202px;
position:absolute;
top:0; left:0;
}
#tw div.thumb img {
border:1px solid #000;
webkit-border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;
}
#myprof {
clear:both;
margin:10px 0; padding:0;
overflow:hidden;
height:75px;
border:1px solid #ccc;
font-size:12px;
background:#eee;
webkit-border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;
}
#myprof p {
margin:10px 0 0 0; padding:0;
}
#myprof strong {
font-size:15px;
}
#myprof a.prof {
width:75px; height:75px;
float:left;
margin:0 10px 0 0; padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<div id="wrap">
<h1>設置サンプル</h1>
<p>picplz APIからフィードを取得し、投稿写真を一覧表示。</p>
<p>参照:<a href='http://sites.google.com/site/picplzapi/home'>picplz API</a></p>
<!-- CODE -->
<div id="tw">
<ul></ul>
</div>
<!-- / CODE -->
</div>
</body>
</html>