<?php
$apiKey="1e1c0a7b9491a4s45238591099254058f9";
$apiBaseUrl='https://www.globallimos.com';
$time=date('Ymdhis');
$ipaddress=$_SERVER['REMOTE_ADDR'];
$websiteid=12;
function GetApiDataSchema($apiUrl,$postdata){
	$post = urldecode($postdata);
	$curl = curl_init($apiUrl);
			

	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_USERAGENT , 'Mozilla 5.0');
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
	curl_setopt($curl, CURLOPT_VERBOSE , true);		
	$resp = curl_exec($curl);	
	return $resp;
}
$link =(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];   
//echo $link; 
$apiUrl=$apiBaseUrl."/api/schema/details.php?apikey=".$apiKey."&time=".$time;
$postdata=$postdata.'&websiteid='.$websiteid.'&pageurl='.$link;
//echo $apiUrl;
$resp=GetApiDataSchema($apiUrl,$postdata);
$responseAPI=json_decode($resp);
//print_r($responseAPI);
if($responseAPI->errorcode==100){
	if($responseAPI->schematypeid==1){
	?>
	<script type="application/ld+json">	
	{
		"@context": "http://schema.org",
		"@type": "http://schema.org/<?=$responseAPI->schematype?>",
		"@id": "<?=$responseAPI->pageurl?>",
		"name": "Empire Limousine",
		"sameAs": [<? if($responseAPI->sameAs1!=''){?>"<?=$responseAPI->sameAs1?>"<? }?> <? if($responseAPI->sameAs2!=''){?>,"<?=$responseAPI->sameAs2?>"<? }?> <? if($responseAPI->sameAs3!=''){?>,"<?=$responseAPI->sameAs3?>"<? }?> <? if($responseAPI->sameAs4!=''){?>,"<?=$responseAPI->sameAs4?>"<? }?>],
		"address": {
			"@type": "PostalAddress",
			"addressCountry": "US",
			"streetAddress": "<?=$responseAPI->streetAddress?>",
			"addressLocality": "<?=$responseAPI->addressLocality?>",
			"addressRegion": "<?=$responseAPI->addressRegion?>",
			"postalCode": "<?=$responseAPI->postalCode?>"
		},
		"aggregateRating": {
			"@type": "AggregateRating",
			"ratingValue": <?=$responseAPI->schemaReviewAvgFinalCount?>,
			"reviewCount": <?=$responseAPI->schemaReviewCount?>
		},
		"geo": {
			"@type": "GeoCoordinates",
			"latitude": <?=$responseAPI->latitude?>,
			"longitude": <?=$responseAPI->longitude?>
		},
		"telephone": "<?=$responseAPI->telephone?>",
		"openingHours": ["Mo-Su"],
		"image": "<?=$responseAPI->imagetype?>"
		<? if($responseAPI->displayReview > 0){
				$SchemaReviewDt=$responseAPI->SchemaReview;	
				$indx=0;	
			?>
		,"review": [
		<?  $reviewItem='';
			for($indx=0;$indx < $responseAPI->schemaReviewCount;$indx=$indx+1){
				$rowRD=$SchemaReviewDt[$indx];
				$reviewbody=str_replace('<p>','',$rowRD->reviewbody);
				$reviewbody=str_replace('</p>','',$reviewbody);
				//print_r($rowRD);
				$reviewItem=$reviewItem.'{"@type": "Review","itemReviewed": "Empire Limousine","author": {"@type": "Person","name": "'.$rowRD->reviewername.'"},"name": "'.$rowRD->reviewtitle.'","reviewBody": "'.$reviewbody.'",	"reviewRating": {"@type": "Rating","ratingValue": '.$rowRD->rating.'},"datePublished": "'.$rowRD->datepublished.'"},';		 
		 	}
		 	$reviewItem=substr($reviewItem,0,strlen($reviewItem)-1);
			echo $reviewItem;
		 ?>	
		]
	<? }?>	
	}	
	{
		"@context": "https://schema.org",
		"@type": "BreadcrumbList",
		"itemListElement": [{
			"@type": "ListItem",
			"position": <?=$responseAPI->bcposition?>,
			"item": {
				"@id": "<?=$responseAPI->bcurl?>",
				"name": "<?=$responseAPI->bcname?>"
			}
		}]
	}
	</script>
<? }elseif($responseAPI->schematypeid==2 || $responseAPI->schematypeid==3 || $responseAPI->schematypeid==4){?>
	<script type="application/ld+json">			
	{
		"@context": "http://schema.org",
		"@type": "Product",
		"description": "<?=$responseAPI->description?>",
		"name": "<?=$responseAPI->schematypename?>",
		"image": "<?=$responseAPI->imagetype?>",
		"brand": "<?=$responseAPI->itemOfferedmanufacturer?>",
  		"sku": "SKU<?=$responseAPI->websiteschemaid?>",
		"offers": {
			"@type": "Offer",
			"availability": "http://schema.org/InStock",
			"name": "<?=$responseAPI->itemOfferedname?>",
			"url": "<?=$responseAPI->itemOfferedurl?>",
			"image": "<?=$responseAPI->itemOfferedimage?>",
			"price": "<?=$responseAPI->price?>",
			"priceCurrency": "USD"
		}
		<? if($responseAPI->schemaReviewCount > 0){
				$SchemaReviewDt=$responseAPI->SchemaReview;	
				$indx=0;	
			?>
		,"aggregateRating": {
			"@type": "AggregateRating",
			"ratingValue": <?=$responseAPI->schemaReviewAvgFinalCount?>,
			"reviewCount": <?=$responseAPI->schemaReviewCount?>
		}
		,"review": [
		<?  $reviewItem='';
			for($indx=0;$indx < $responseAPI->schemaReviewCount;$indx=$indx+1){
				$rowRD=$SchemaReviewDt[$indx];
				$reviewbody=str_replace('<p>','',$rowRD->reviewbody);
				$reviewbody=str_replace('</p>','',$reviewbody);
				//print_r($rowRD);
				$reviewItem=$reviewItem.'{"@type": "Review","itemReviewed": "Empire Limousine","author": {"@type": "Person","name": "'.$rowRD->reviewername.'"},"name": "'.$rowRD->reviewtitle.'","reviewBody": "'.$reviewbody.'",	"reviewRating": {"@type": "Rating","ratingValue": '.$rowRD->rating.'},"datePublished": "'.$rowRD->datepublished.'"},';		 
		 	}
		 	$reviewItem=substr($reviewItem,0,strlen($reviewItem)-1);
			echo $reviewItem;
		 ?>	
		]
	<? }?>
	}	
	{
		"@context": "https://schema.org",
		"@type": "BreadcrumbList",
		"itemListElement": [{
			"@type": "ListItem",
			"position": <?=$responseAPI->bcposition?>,
			"item": {
				"@id": "<?=$responseAPI->bcurl?>",
				"name": "<?=$responseAPI->bcname?>"
			}
		},
		{
			"@type":"ListItem",
			"position":<?=$responseAPI->bcposition2?>,
			"item":{
				"@id":"<?=$responseAPI->bcurl2?>",
				"name":"<?=$responseAPI->bcname2?>"
				}
		}]
	}
	</script>
	<?
	}
}
$sessionid='slcn'.session_id();
$apiUrlWT=$apiBaseUrl."/api/schema/webtracking.php?apikey=".$apiKey."&time=".$time;
$postdataWT=$postdataWT.'&websiteid='.$websiteid.'&pageurl='.$link.'&ipaddress='.$ipaddress.'&sessionid='.$sessionid;
$respWT=GetApiDataSchema($apiUrlWT,$postdataWT);
$responseAPIWT=json_decode($respWT);
?>