tweetmonitor/admin/monitor-timeline.php
2016-02-09 14:23:43 +01:00

67 lines
2 KiB
PHP

<?php
include('../config/config.php');
include('html/html.inc.php');
include('../includes/classes/class.Tweet.php');
include('../includes/classes/class.User.php');
include('includes/functions.php');
include('includes/tmhOAuth.php');
$objUser=new User();
$objTweet=new Tweet();
$allUsers=$objUser->getAllUserNames();
if($allUsers)
{
foreach($allUsers as $user)
{
$objTweet->user_id=$user->user_id;
$getSinceId=$objTweet->getLatestUserTweet();
$since_id=$getSinceId[0]->tweet_id;
$connection = new tmhOAuth(array( 'consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'user_token' => $user_token, 'user_secret' => $user_secret ));
$http_code = $connection->request('GET',$connection->url('1.1/statuses/user_timeline'), array('screen_name' => $user->screen_name,'since_id'=>$since_id));
if ($http_code == 200)
{
$tweet_data = json_decode($connection->response['response'],true);
if(sizeof($tweet_data)>0 && $tweet_data)
{
$userArray=array();
foreach($tweet_data as $user)
{
$userArray=$user['user'];
}
if(sizeof($userArray)>0)
{
$objUser->id=$userArray['id_str'];
$user_id=$userArray['id_str'];
$objUser->screen_name=$userArray['screen_name'];
$objUser->name=$userArray['name'];
$objUser->profile_image_url=$userArray['profile_image_url'];
$objUser->location=$userArray['location'];
$objUser->created_at=date('y-m-d h:m:s',strtotime($userArray['created_at']));
$objUser->friends_count=$userArray['friends_count'];
$objUser->followers_count=$userArray['followers_count'];
$objUser->statuses_count=$userArray['statuses_count'];
$objUser->updateUserAccount();
}
foreach($tweet_data as $tweet)
{
if(isset($tweet['retweeted_status']))
{
continue;
}
$objTweet->id=$tweet['id_str'];
$objTweet->tweet_text=base64_encode($tweet['text']);
$objTweet->created_at=date('y-m-d h:m:s',strtotime($tweet['created_at']));
$objTweet->user_id=$user_id;
$objTweet->saveTweet();
}
}
}
}
}
?>