Skip to content

Instantly share code, notes, and snippets.

@komkanit
Last active March 2, 2018 16:42
Show Gist options
  • Save komkanit/cea84ebedeb898b451ce0472b479fe55 to your computer and use it in GitHub Desktop.
Save komkanit/cea84ebedeb898b451ce0472b479fe55 to your computer and use it in GitHub Desktop.
<?php
$SITE_ROOT = "https://www.example.com";
$jsonData = getData($SITE_ROOT);
makePage($jsonData, $SITE_ROOT);
function getData($siteRoot) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $siteRoot.'/api/recipes/'.$_GET['id']);
$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
return $response;
}
function makePage($data, $siteRoot) {
$pageUrl = $siteRoot . "/recipes/" . $data->url_name;
$title = $data->title;
$description = $data->description;
?>
<!DOCTYPE html>
<html>
<head>
<meta property="og:image:url" content="<?php echo $data->picture; ?>" />
<meta property="og:image:secure_url" content="<?php echo $data->picture; ?>" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:title" content="<?php echo $title; ?>" />
<meta property="og:description" content="<?php echo $description; ?>" />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="315" />
<meta property="og:type" content="website" />
<meta property="fb:app_id" content="APP_ID" />
<meta property="og:url" content="<?php echo $pageUrl; ?>" />
<!-- etc. -->
</head>
<body>
</body>
</html>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment