<?php
/**
* Twitter PHP Script
* This script gets a user's twitter timeline and returns it as a multidimension array
* each array containing 'tweet, date and link' respectively.
*
* LICENSE: This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* http://www.gnu.org/licenses/
*
* @author Opeyemi Obembe <ray@devedgelabs.com>
* @copyright Copyright (c) 2010, devEdgeLabs.
*/
class Twitter
{
var $count;
var $feedUrl;
var $username;
//@params: twitter username, number of needed updates (20 max)
function Twitter($username, $count = 20)
{
$this->username = $username;
$this->feedUrl = 'http://api.twitter.com/1/statuses/user_timeline/'.$username.'.rss';
$this->count = $count > 20 ? 20 : $count;
}
function since($date)
{
$timestamp = strtotime($date);
$seconds = time() - $timestamp;
$units = array(
'second' => 1,
'minute' => 60,
'hour' => 3600,
'day' => 86400,
'month' => 2629743,
'year' => 31556926
);
foreach($units as $k => $v)
{
if($seconds >= $v)
{
$results = floor($seconds/$v);
if($k == 'day' | $k == 'month' | $k == 'year')
$timeago = date('D, d M, Y h:ia', $timestamp);
else
$timeago = ($results >= 2) ? 'about '.$results.' '.$k.'s ago' : 'about '.$results.' '.$k.' ago';
}
}
return $timeago;
}
// Returns a multidimentional array, each containg 'tweet, date and link' respectively
function get($count = 20)
{
$username = $this->username;
// Append the count
$url = $this->feedUrl;
$url .= '?count='.$count;
$tweets_cache_path = 'cache/twitter_'.$username.'_'.$count.'.cache';
if(file_exists($tweets_cache_path))
{
$tweets_cache_timer = intval((time()-filemtime($tweets_cache_path))/60);
}
else
{
$tweets_cache_timer = 0;
}
if ( (!file_exists($tweets_cache_path) OR $tweets_cache_timer > 15) && function_exists('curl_init') )
{
// The http CURL thingy
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 10);//10 secs max
$data = curl_exec($curl_handle);
curl_close($curl_handle);
// Some error? Return an empty array
// You may want to extend this to know the exact error
// echo curl_error($curl_handle);
// or know the http status
// echo curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
if(!$data) return array();
// Some reformatting
$pattern = array(
'/[^(:\/\/)](www\.[^ \n\r]+)/',
'/(https?:\/\/[^ \n\r]+)/',
'/@(\w+)/',
'/^'.$username.':\s*/i'
);
$replace = array(
'<a href="http://$1" rel="nofollow" target="_blank">$1</a>',
'<a href="$1" rel="nofollow" target="_blank">$1</a>',
'<a href="http://twitter.com/$1" rel="nofollow" target="_blank">@$1</a>'.
''
);
$tweets = array();
$xml = new SimpleXMLElement($data);
if(!empty($xml->channel->item) && isset($xml->channel->item))
{
foreach($xml->channel->item as $item)
{
$tweet = preg_replace($pattern, $replace, $item->description);
$title_twitter = strip_tags($tweet);
$date = $this->since($item->pubDate);
preg_match('/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;\'">\:\s\<\>\)\]\!])/', $item->description, $regular_link);
@$permalink = preg_replace('/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;\'">\:\s\<\>\)\]\!])/', '<a href="'.$regular_link[1].'" target="_blank">'.$regular_link[1].'</a>', $title_twitter);
$tweets[] = array($tweet, $date, $permalink);
}
}
if(file_exists($tweets_cache_path))
{
unlink($tweets_cache_path);
}
$myFile = $tweets_cache_path;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = serialize($tweets);
fwrite($fh, $stringData);
fclose($fh);
}
else
{
error_reporting(0);
$file = file_get_contents($tweets_cache_path, true);
if(!empty($file))
{
$tweets = unserialize($file);
if(!is_array($tweets))
{
$tweets = array();
}
}
}
return $tweets;
}
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
灰色简洁平面设计企业品牌官网整站模板_灰色保险_html网站模板_网页源码移动端前端_H5模板_自适应响应式源码.rar
共220个文件
png:86个
jpg:50个
html:29个
0 下载量 39 浏览量
2023-08-05
11:24:37
上传
评论
收藏 3.63MB RAR 举报
温馨提示
灰色简洁平面设计企业品牌官网整站模板_灰色保险_html网站模板_网页源码移动端前端_H5模板_自适应响应式源码.rar
资源推荐
资源详情
资源评论
收起资源包目录
灰色简洁平面设计企业品牌官网整站模板_灰色保险_html网站模板_网页源码移动端前端_H5模板_自适应响应式源码.rar (220个子文件)
style.css 77KB
screen.css 35KB
prettyPhoto.css 27KB
shCore.css 7KB
shThemeDefault.css 4KB
flexslider.css 3KB
custom.css 256B
loading.gif 9KB
loader.gif 6KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
loader.gif 2KB
slider_bg.gif 2KB
tabs_bg.gif 1KB
sidebar_line.gif 1KB
input-upload.gif 622B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
default_thumbnail.gif 227B
divider_line.gif 51B
wp-widgets-layout.html 51KB
shortcodes-columns-full2.html 42KB
shortcodes-tables.html 32KB
shortcodes-widgets.html 30KB
blog-details.html 27KB
shortcodes-tabs.html 27KB
shortcodes-columns.html 24KB
blog.html 23KB
blog-sidebar-l.html 23KB
page-pricing.html 22KB
page-bg-1.html 22KB
page-bg-3.html 22KB
page-bg-2.html 22KB
index.html 22KB
shortcodes-columns-full.html 21KB
shortcodes-media.html 20KB
shortcodes-lightbox.html 18KB
shortcodes-buttons.html 18KB
shortcodes-typography-fonts.html 18KB
shortcodes-text.html 18KB
shortcodes-typography.html 18KB
careers.html 17KB
about.html 17KB
cases.html 17KB
shortcodes-maps.html 17KB
shortcodes-charts.html 16KB
contact.html 16KB
services.html 15KB
index.html 0B
favicon.ico 1KB
slide-3.jpg 289KB
slide-2.jpg 251KB
slide-4.jpg 244KB
slide-1.jpg 244KB
slide-5.jpg 179KB
head_image_3.jpg 161KB
flex_slide_2.jpg 159KB
flex_slide_3.jpg 153KB
entry_08.jpg 140KB
flex_slide_1.jpg 131KB
head_image_4.jpg 115KB
head_image_1.jpg 109KB
head_image_2.jpg 106KB
map.jpg 93KB
entry_03.jpg 80KB
entry_04.jpg 70KB
entry_05.jpg 67KB
case_6.jpg 57KB
entry_06.jpg 53KB
case_4.jpg 53KB
case_2.jpg 50KB
entry_02.jpg 42KB
team_3.jpg 41KB
case_5.jpg 41KB
entry_07.jpg 41KB
case_1.jpg 39KB
author_image.jpg 37KB
fb_activity.jpg 37KB
thumb_5.jpg 36KB
thumb_4.jpg 35KB
thumb_3.jpg 35KB
thumb_10.jpg 35KB
thumb_8.jpg 35KB
team_1.jpg 35KB
thumb_9.jpg 34KB
thumb_1.jpg 33KB
case_3.jpg 33KB
framed_image_3.jpg 33KB
thumb_2.jpg 33KB
thumb_6.jpg 33KB
framed_image_1.jpg 32KB
thumb_7.jpg 31KB
team_2.jpg 26KB
entry_img_small_2.jpg 24KB
entry_img_small_1.jpg 23KB
framed_image_2.jpg 23KB
共 220 条
- 1
- 2
- 3
资源评论
supeerzdj
- 粉丝: 11
- 资源: 6184
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功