Esempio n. 1
0
 /**
     Gets the User Time Line
 */
 public static function getUserTimeline($user, $size = 10)
 {
     $uri = sprintf('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=%s&count=%d', $user, $size);
     $feed = Radix_HTTP::get($uri);
     $json = json_decode($feed['body']);
     return $json;
 }
Esempio n. 2
0
 /**
     Perform a Google Search
     @return array of results
 */
 static function search($q)
 {
     $base = 'http://ajax.googleapis.com/ajax/services/search/web';
     $args = array('q' => $q, 'v' => '1.0', 'key' => self::$API_KEY, 'rsz' => 'large', 'start' => 0);
     $page = Radix_HTTP::get(sprintf('%s?%s', $base, http_build_query($args)));
     $json = json_decode($page['body']);
     return $json;
     // Radix::dump($json,true);
     // if (!empty($json->responseData->cursor->estimatedResultCount)) {
     //     $c = intval($json->responseData->cursor->estimatedResultCount);
     // }
     // $list = array();
     // if ( (!empty($json->responseData->results)) && (is_array($json->responseData->results)) ) {
     //     foreach ($json->responseData->results as $i=>$x) {
     //         $item = array(
     //             'q' => $q,
     //             'uri' => $x->url,
     //             'src' => 'google',
     //             'g-name' => $x->titleNoFormatting,
     //             'g-note' => $x->content,
     //             'g-rank' => (self::$_google_off + $i + 1),
     //         );
     //         self::_page_save($item);
     //         self::$_google_off++;
     //     }
     // }
 }
Esempio n. 3
0
 /**
     @param $ch Curl Handle
     @param $async do an async HTTP?
 */
 private static function _curl_exec($ch, $async = false)
 {
     if (self::$_opts['async']) {
         self::$_mc_exec = 0;
         if (empty(self::$_mc)) {
             self::$_mc = curl_multi_init();
         }
         curl_multi_add_handle(self::$_mc, $ch);
         curl_multi_exec(self::$_mc, self::$_mc_exec);
         self::$_mc_list[] = $ch;
         return self::$_mc_exec;
     } else {
         $r = array();
         $r['body'] = curl_exec($ch);
         $r['head'] = self::$_ch_head;
         if (empty($r['head']['content-encoding'])) {
             $r['head']['content-encoding'] = null;
         }
         $r['info'] = curl_getinfo($ch);
         $r['fail'] = sprintf('%d:%s', curl_errno($ch), curl_error($ch));
         if (!empty($r['head']['content-encoding'])) {
             switch ($r['head']['content-encoding']) {
                 case 'deflate':
                     $r['body'] = gzinflate($r['body']);
                     break;
                 case 'gzip':
                     $r['body'] = gzinflate(substr($r['body'], 10));
                     // if (preg_match('/gzip/i',$res['head']['content-encoding'])) {
                     // $res['body'] = gzdecode($res['body']);
                     break;
             }
         }
         return $r;
     }
 }