<?php

require_once("reputation_management_macros.php");

$key = get_option( 'rb_api_key');
$limit = get_option( 'rb_no_of_reviews');
$internal = get_option( 'internal_review');
$yelp =	get_option( 'yelp');
$google_plus	= get_option( 'google_plus' );
if (isset($_GET['offset']) && $_GET['offset']) {
	$offset = $_GET['offset'];
} else {
	$offset = 0;
}
$tReviewOptions = array(
    'internal',
    'yelp',
    'google',
    'yahoo',
    'citysearch',
    'opentable',
    'facebook',
    'foursquare',
    'insiderpages',
    'zillow',
    'Avvo',
    'Booking',
    'Caring',
    'Cars',
    'CreditKarma',
    'CustomerLobby',
    'DealerRater',
    'Expedia',
    'GoldenReviews',
    'HomeAdvisor',
    'Houzz',
    'JudysBook',
    'Kudzu',
    'MenuPages',
    'Orbitz',
    'OurParents',
    'RateMds',
    'RealPatientRatings',
    'Rent',
    'RentersVoice',
    'SeniorAdvisor',
    'SeniorHomes',
    'Snap21',
    'Travelocity',
    'Trip',
    'TripAdvisor',
    'Trulia',
    'UCompareHealthCare',
    'Vitals',
    'YellowPages',
    'ZocDoc',
);

$tQuery = [];

foreach ($tReviewOptions as $Option) {
	// Hacky I know, but I'm not aware of the reliance on the option being named internal_review / google_plus
	if ($Option == 'internal')
		$tQuery[$Option] = get_option('internal_review');
	elseif ($Option == 'google')
		$tQuery[$Option] = get_option('google_plus');
	else
		$tQuery[$Option] = get_option($Option);
}
$url = REPUTATION_API_URL . "apiKey=$key&noOfReviews=$limit&offset=" . $offset . '&' . http_build_query($tQuery);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($cURL,CURLOPT_HTTPHEADER,array ("Accept: application/json"));
exit(curl_exec($ch));
