Example #1
0
 private static function execute($search_string)
 {
     self::$error_msg = false;
     if (Controller::$debug) {
         var_dump(self::$url . '?' . $search_string);
     }
     $returned = curl_request(self::$url . '?' . $search_string);
     if (!$returned) {
         self::$error_msg = 'Invalid Twitter API request';
         if (Controller::$debug) {
             var_dump(self::$url . '?' . $search_string);
         }
         return false;
     } else {
         if (!($result = json_decode($returned))) {
             self::$error_msg = 'Invalid JSON returned: ' . $returned;
             return false;
         }
     }
     if (array_key_exists('error', $result)) {
         self::$error_msg = $result->error;
     } else {
         return is_object($result) && isset($result->results) ? $result->results : false;
     }
     if (!empty(self::$error_msg) && Controller::$debug) {
         Backend::addError('TwitterSearch: ' . self::$error_msg);
     }
     return false;
 }
<?php

require_once dirname(__FILE__) . "/lib/TwitterSearch.php";
echo "Starting PHP  Worker101\n";
$payload = getPayload();
echo "We got following params\n";
print_r($payload);
echo "\nSearching Twitter\n";
$query = $payload->query;
$search = new TwitterSearch($query);
$results = $search->results();
print_r($results);
$file = 'output.txt';
echo "Writing to file";
file_put_contents($file, $results[0]->text);
$from_file = file_get_contents($file);
echo "Text from file\n";
print_r($from_file);
echo "\nWorker101 completed.";
<?php

include "TwitterSearch.phps";
$term = $_GET['term'];
$what = $_GET['what'];
$search = new TwitterSearch($term);
$search->user_agent = 'phptwittersearch:rajarshi.guha@gmail.com';
$results = $search->rpp(50000)->results();
#print_r($results[0]);
if ($what == "text") {
    $ret = "";
    foreach ($results as $result) {
        $ret = $ret . " " . $result->{'text'};
    }
    # remove some common words - we do this here
    # as I can't see how to make the jQuery plugin
    # to this
    $needles = array(" RT ", " #ACS_Boston ", " Meeting ", "ACSNatlMtg", "OK", "ACS", "Boston", "Visit", "Meeting", "Still", "Just", "Need", "Want", "Attending", "Getting", "SADI", "Join", "Currently", "Meet", "Everyone", "Hotel", "Seaport", "Ballroom", "June", "Guess", "Session", "Follow", "First", "LeighJKBoerner", "Booth", "PM", "PSI", "Monday", "Will", "Somewhere");
    foreach ($needles as $needle) {
        $ret = str_replace($needle, "", $ret);
    }
    echo $ret;
} else {
    if ($what == "author") {
        $ret = array();
        foreach ($results as $result) {
            $author = $result->{'from_user'};
            if ($ret[$author] == NULL) {
                $ret[$author] = 1;
            } else {
                $ret[$author] = $ret[$author] + 1;
Example #4
0
<?php

include_once 'inc/common.inc.php';
include_once 'core/TwitterAPI.php';
if ($_GET['pass'] == $vw_password) {
    // Search from Twitter
    $search = new TwitterSearch();
    $search->user_agent = $vw_useragent;
    $results = $search->results($vw_userid);
    // Select latest date from DB
    $tsql = "SELECT date FROM vws_words ORDER BY date DESC LIMIT 0, 1;";
    $tresult = $db->query($tsql);
    if ($row = $db->fetch_array($tresult)) {
        $last_item_timestamp = $row['date'];
    } else {
        $last_item_timestamp = 0;
    }
    foreach ($results as $key) {
        if (strpos($key->text, $vw_hashtag)) {
            // Get word from hashtag tweet
            $tweet = substr($key->text, 0, strrpos($key->text, '#'));
            $notation = array(',', '.', ',', '。');
            $tweet = str_replace($notation, ',', $tweet);
            $words = explode(',', $tweet);
            $words = array_map('trim', $words);
            $date = $key->created_at;
            $date = strtotime(substr($date, 0, 25));
            foreach ($words as $word) {
                $word = new query_Word($word);
                $dict = new query_qqDict();
                $d = $word->query($dict);
Example #5
0
	</style> 
    <style type="text/css" media="print"> 
		@import url("print.css");
	</style> 
</head>
<body>
<form action="index.php" method="submit">
<input name="twitterq" type="text" id="twitterq" />
<input name="Search" type="submit" value="Search" />
</form>
<?php 
include 'TwitterSearch.phps';
if ($_GET['twitterq']) {
    $twitter_query = $_GET['twitterq'];
    echo '<div><p>Query is: ' . $twitter_query . '</p></div>';
    $search = new TwitterSearch($twitter_query);
    $search->rpp(100);
    $results = $search->results();
    if (count($results) < 1) {
        echo '<div><p>No results found</p></div>';
    }
    $odd = true;
    echo '<table class="master"><tr><td class="left">';
    foreach ($results as $result) {
        $odd = !$odd;
        $oddEven = $odd ? "odd" : "even";
        echo '<div class="twitter_status ' . $oddEven . '">';
        echo '<img src="' . $result->profile_image_url . '" class="twitter_image">';
        // replace embedded URLs
        $text_n = preg_replace('/https?:\\/\\/[^\\s]+/i', '<a href="$0" target="output">$0</a>', $result->text);
        // toLink($result->text);
Example #6
0
<?php

if (isset($_GET['key']) && ($_GET['key'] = 'jhdfasjdfhjsmd423423lksfdflsdfjk234234234Lklkasdlkdkdkdscool')) {
    require_once "libs/TwitterSearch.php";
    require_once "settings.php";
    $search = new TwitterSearch();
    $tweets = $search->geocode(55.580787, 38.141439, 10, 'km')->rpp(100)->results();
    mysql_connect($DATABASE['host'], $DATABASE['user'], $DATABASE['password']) or die('Cant connect to server');
    mysql_select_db($DATABASE['name']);
    mysql_set_charset('utf8');
    if (isset($tweets)) {
        foreach ($tweets as $tweet) {
            $user = mysql_real_escape_string($tweet->from_user);
            $user_name = mysql_real_escape_string($tweet->from_user_name);
            $text = mysql_real_escape_string($tweet->text);
            $profile_image = $tweet->profile_image_url;
            $created = $tweet->created_at;
            $id_str = $tweet->id_str;
            $tweet_hash = md5($user . $user_name . $text . $id_str);
            $added = time();
            $proverka_povtorov = mysql_query("SELECT tweet_hash from tweets WHERE tweet_hash = '{$tweet_hash}' AND created = '{$created}'");
            if (mysql_num_rows($proverka_povtorov) == 0) {
                $q = "INSERT INTO tweets (user, user_name, text, profile_image, created, tweet_hash, added, id_str) VALUES ('{$user}', '{$user_name}', '{$text}', '{$profile_image}', '{$created}', '{$tweet_hash}', '{$added}', '{$id_str}')";
                mysql_query($q) or die(mysql_error());
                $last_id_tweet = mysql_insert_id();
                if (preg_match('/\\#(\\w+)/u', $text, $hash_zagluska) != 0) {
                    preg_match_all('/\\#(\\w+)/u', $text, $hashtags);
                    $hashtags = $hashtags[1];
                    foreach ($hashtags as $tag) {
                        $proverka_tagov = mysql_query("SELECT text FROM hashtags WHERE text = '{$tag}'");
                        if (mysql_num_rows($proverka_tagov) == 0) {
Example #7
0
Nunc massa orci, fringilla egestas semper nec, pulvinar id elit. Nulla in lacinia sem. Donec et sapien nunc, vel pellentesque orci. Donec aliquet est a diam faucibus at luctus mauris luctus. Aenean felis velit, semper in consectetur at, bibendum nec ipsum. Curabitur erat arcu, venenatis et hendrerit dictum, faucibus sed massa. Mauris cursus aliquet odio tempor pretium. Nullam iaculis nulla in erat iaculis varius. Curabitur pretium euismod nulla, vel suscipit nunc convallis eu. Curabitur eleifend, libero ac dapibus egestas, turpis lectus pharetra eros, non accumsan sem mauris a eros. Phasellus porttitor viverra enim eget euismod. Mauris ut libero ante, ultrices ornare ipsum. Nulla nisi leo, rhoncus a laoreet eget, placerat nec sem.
</p>

			</div>
			
			<div class="col4">
				

				<center><img src="images/icon_birdy.png" width="50px" style="margin:15px 0px 0px 0px"></center>
				<br/>
				<div id="tweets">
				<?php 
// ------------------
// Twitter API
require_once "api/TwitterSearch.php";
$tw = new TwitterSearch("#ICPC2012");
$twResults = $tw->from("BrainBattleICPC")->rpp(6)->results();
foreach ($twResults as $tt) {
    echo "<a href='http://www.twitter.com/BrainBattleICPC/' class='tweet_from'>@", $tt->from_user, "</a> <p class='tweet_text'>", $tt->text, "</p> <div class='tweet_date'>", substr($tt->created_at, 0, 25), "</div>";
}
?>
				</div>
				
				
				<h2>Competition archive</h2>
				<ul id="side_nav">
					<li class="int_nav_head">Harbin, China 2010</li>
					<li><a href="?page=archive&subp=harbin_video">One hour version</a></li>
					<li><a href="#">Country information</a></li>
					<li><a href="?page=archive&subp=harbin_credits">Cast and credits</a></li>
					<li class="int_nav_head">Stockholm, Sweden 2009</li>
Example #8
0
<?php

// Include Twitter Search API wrapper class
require "./lib/TwitterSearch.php";
$id = "";
// Id of the last recived tweet
$file = fopen("id.txt", "r+");
// The last rquests tweet id is stored in id.txt
$id = $id . fgets($file);
// Read the last tweet id to $id
$search = new TwitterSearch('"i love you"');
// Initialize search class with query "i love you"
$search->user_agent = 'phptwittersearch:emotion@gmail.com';
// Set the user agent, something twitter API would like us to set!
if ($id != 0) {
    // well if id!=0, that is the initial case or first run get just two tweets to start the timeline
    $results = $search->since($id)->rpp(100)->results();
} else {
    $results = $search->rpp(2)->results();
}
// Just get 2 tweets just to get the id of the tweet which ca be used in futeure request
$id = $results[0]->id_str;
// get the id of the first tweet ie., latest tweet
$file = fopen("id.txt", "w+");
fwrite($file, $id);
//write the id to file id.txt, so we can retieve the id in next request
fclose($file);
// Set the JSON header
header("Content-type: text/json");
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;