Ejemplo n.º 1
0
	// make sure request came from valid source
	if (array_key_exists('HTTP_REFERER', $_SERVER)) {
		$referer = parse_url(esc_attr($_SERVER['HTTP_REFERER']));
		if ($referer['host'] != esc_attr($_SERVER['SERVER_NAME']) && $referer['host'] != 'www.' . esc_attr($_SERVER['SERVER_NAME'])) {
			echo $wp_json->encode(array('error' => __('Request from unauthorized page', 'tweetblender') . ".\n" . esc_attr($_SERVER['SERVER_NAME']) . "\n" . $referer['host']));
			exit;
		}
	}
	
	// TODO: make sure the source we are caching for is in the config of at least one widget
	
	// make sure data is really JSON
	$data = stripslashes($_POST['tweets']);
	if($tweets = $wp_json->decode($data)) {

		if(tb_save_cache($tweets)) {
			// return OK
			echo $wp_json->encode(array('OK' => 1));
		}
		else {
			echo $wp_json->encode(array('error' => __('Cannot store tweets to DB', 'tweetblender')));
		}
		exit;
	}
	else {
		echo $wp_json->encode(array('error' => __('Invalid data format', 'tweetblender')));
		exit;
	}		
}

?>
Ejemplo n.º 2
0
        echo $json_data;
        exit;
    } else {
        echo $json->encode(array('error' => "Can't retrieve limit info from Twitter"));
        exit;
    }
} elseif ($_GET['action'] == 'cache_data') {
    // make sure request came from valid source
    if (array_key_exists('HTTP_REFERER', $_SERVER)) {
        $referer = parse_url($_SERVER['HTTP_REFERER']);
        if ($referer['host'] != $_SERVER['SERVER_NAME'] && $referer['host'] != 'www.' . $_SERVER['SERVER_NAME']) {
            echo $json->encode(array('error' => "Request from unauthorized page. \n" . $_SERVER['SERVER_NAME'] . "\n" . $referer['host']));
            exit;
        }
    }
    // TODO: make sure the source we are caching for is in the config of at least one widget
    // make sure data is really JSON
    $data = stripslashes($_POST['tweets']);
    if ($tweets = $json->decode($data)) {
        if (tb_save_cache(array(), $tweets)) {
            // return OK
            echo $json->encode(array('OK' => 1));
        } else {
            echo $json->encode(array('error' => 'Cannot store tweets to DB'));
        }
        exit;
    } else {
        echo $json->encode(array('error' => 'Invalid data format'));
        exit;
    }
}
Ejemplo n.º 3
0
     $oAuth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $tb_o['oauth_access_token']['oauth_token'], $tb_o['oauth_access_token']['oauth_token_secret']);
     $json_data = $oAuth->OAuthRequest($tb_api_base_url . $api_endpoint . '.json', 'GET', $api_params);
     //error_log('***** url = ' . $tb_api_base_url . $api_endpoint . '.json');
     //error_log('***** sources = ' . print_r($sources,true));
     //error_log('**** params = ' . print_r($api_params,true));
     if ($oAuth->http_code == 200) {
         echo $json_data;
         //error_log('**** response=' . $json_data);
         // update rate limit info
         $headers = $oAuth->http_header;
         $tb_o['rate_limit_data'][$api_endpoint] = array('limit' => $headers['x_rate_limit_limit'], 'remaining' => $headers['x_rate_limit_remaining'], 'reset' => $headers['x_rate_limit_reset'], 'last_used' => time());
         // save rate limit data to options
         update_option('tweet-blender', $tb_o);
         //error_log('**** json data: ' . $json_data);
         // cache response
         tb_save_cache($wp_json->decode($json_data), $sources);
         exit;
     } else {
         if ($json_data = tb_get_cached_tweets_json($sources)) {
             echo $json_data;
         } else {
             echo $json->encode(array('error' => __('No cache. Connection status code', 'tweetblender') . ' ' . $oAuth->http_code));
         }
         exit;
     }
 } else {
     //error_log('getting it from cache');
     if ($json_data = tb_get_cached_tweets_json($sources)) {
         echo $json_data;
     } else {
         echo $json->encode(array('error' => __('Reached Twitter API limit and there is no cache.', 'tweetblender')));