/**
  * Twitter Search Endpoint 
  */
 public function searchAction()
 {
     Zend_Layout::getMvcInstance()->disableLayout();
     $params = $this->getRequest()->getParams();
     $search = array_key_exists("q", $params) ? $params["q"] : null;
     $response = $this->searchApi->search($search);
     $this->getResponse()->setHeader(Zend_Http_Client::CONTENT_TYPE, 'application/json')->appendBody(json_encode($response));
 }
Beispiel #2
0
 /**
  * Search Twitter
  *
  * @param string $terms Search terms
  * @param int $page Page of the timeline to request
  * @return $data array of tweets found from search
  * @author Aaron Hill armahillo@gmail.com / amhill.net
  */
 public function search($terms, $page = 1)
 {
     $twitter = $this->_initTwitter();
     $cache = $this->_initCache();
     $resultsPerPage = 40;
     $data = array();
     try {
         $search = new Zend_Service_Twitter_Search();
         $timeline = $search->search($terms, array('page' => $page, 'since_id' => 1520639490, 'rpp' => $resultsPerPage));
         foreach ($timeline['results'] as $t) {
             $data[] = array('id' => (string) $t['id'], 'user-profile_image_url' => (string) $t['profile_image_url'], 'user-name' => (string) $t['from_user'], 'user-screen_name' => (string) $t['from_user'], 'text' => $this->_processTweet((string) $t['text']), 'created_at' => (string) $t['created_at'], 'elapsed_time' => $this->_elapsedTime(strtotime($t['created_at'])), 'source' => html_entity_decode($t['source']), 'in_reply_to_screen_name' => '', 'in_reply_to_status_id' => '');
         }
         if ($page == 1) {
             $cache->save($data, 'search');
         }
     } catch (Exception $e) {
         if ($page != 1 || !($data = $cache->load('search'))) {
             throw $e;
         }
     }
     return $data;
 }
        	</div>
		</div>
		<div class="yui-b">
        
		<div id="searchtips"><div class="tweet"><ul class="tweet_list">
		<?php 
// This is the Twitter component (requires Zend)
?>
		
		<?php 
require_once "Zend/Loader.php";
require_once "Zend/Service/Twitter.php";
require_once "Zend/Service/Twitter/Search.php";
$twitter_search = new Zend_Service_Twitter_Search('json');
$limit = 7;
$twit_results = $twitter_search->search($politicsname, array('lang' => 'en', 'rpp' => $limit));
echo "<h3>Musings on " . $politicsname . " (Twitter)</h3>";
$i = 0;
while ($i <= $limit - 1) {
    echo "\n            <li class='tweet_first tweet_odd'>\n            <a href='http://www.twitter.com/" . $twit_results["results"][$i]["from_user"] . "' class='tweet_avatar' ><img src='" . $twit_results["results"][$i]["profile_image_url"] . "' width='48' height='48' border='0' /></a>\n            <a href='http://twitter.com/" . $twit_results["results"][$i]["from_user"] . "/'>" . $twit_results["results"][$i]["from_user"] . "</a>";
    $twit_results["results"][$i]["text"] = preg_replace('/(http|ftp)+(s)?:(\\/\\/)((\\w|\\.)+)(\\/)?(\\S+)?/i', '<a href="\\0">\\4</a>', strip_tags($twit_results["results"][$i]["text"]));
    echo " <span class='tweet_text'>" . $twit_results["results"][$i]["text"] . "</span>\n            </li>";
    $i = $i + 1;
}
echo "<a href='http://twitter.com/#search?q=" . $politicsname . "'>More...</a>";
?>
        </ul></div></div>
        </div>
	</div>

</div>