Simplepie拡張アドオン「simplepie_twittersearch.inc」
- 投稿日 : 2010-12-09, 11:40
- 最終更新日時 : 2011-01-15 15:27:31(履歴)
- タグ(Nucleus / NucleusPlugin / Simplepie)
- カテゴリ(Nucleus Plugin)
- 記し人(luvsic)[PDF]
- 閲覧数(9779)
Twitter Search の検索結果フィードをパースする simplepie_twittersearch.inc です。基本的なコードのみ。
スキン記述
<%simplepie(http://search.twitter.com/search.atom?lang=ja&q=nucleus+-%40Nucleus_+-torn,twittersearch,simplepie/twitter,8,,180)%>
simplepie_twittersearch.inc
<?php
/**
* SimplePie Add-on for Twitter Search
*
* Copyright (c) 2010, Luvsic All rights reserved.
* License matches the current SimplePie license.
*
* ver 0.1b : create the basic method.
* ver 0.11b : change -> get_twitter_published()
*
*/
class SimplePie_Item_Twittersearch extends SimplePie_Item
{
// New method
function get_twitter_id()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id');
return $data[0]['data'];
}
// New method
function get_twitter_published()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published');
$postdate = date( "n/d H:i", strtotime($data[0]['data']));
return $postdate;
}
// New method
function get_twitter_alternate()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link');
return $data[0]['attribs']['']['href'];
}
// New method
function get_twitter_title()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title');
return $data[0]['data'];
}
// New method
function get_twitter_content()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content');
return $data[0]['data'];
}
// New method
function get_twitter_updated()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated');
return $data[0]['data'];
}
// New method
function get_twitter_images()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link');
return $data[1]['attribs']['']['href'];
}
// New method
function get_twitter_geo()
{
$data = $this->get_item_tags('http://api.twitter.com/', 'geo');
return $data[0]['data'];
}
// New method
function get_twitter_metadata()
{
$data = $this->get_item_tags('http://api.twitter.com/', 'metadata');
$data = $data[0]['child']['http://api.twitter.com/']['result_type'];
return $data[0]['data'];
}
// New method
function get_twitter_source()
{
$data = $this->get_item_tags('http://api.twitter.com/', 'source');
$data = $data[1]['attribs']['']['href'];
if (preg_match("/twittbot/i", $data)) {
} else {
return $data[1]['attribs']['']['href'];
}
}
// New method
function get_twitter_lang()
{
$data = $this->get_item_tags('http://api.twitter.com/', 'lang');
return $data[0]['data'];
}
// New method
function get_twitter_author_name()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
$data = $data[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'];
return $data[0]['data'];
}
// New method
function get_twitter_author_uri()
{
$data = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
$data = $data[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'];
return $data[0]['data'];
}
}
?>
[参考]
Twitter Search API Method: search
SimplePie Documentation: Grab custom tags or attributes
SimplePie Documentation: API Reference
No comments yet