Skip to content

Instantly share code, notes, and snippets.

@TheJaredWilcurt
Created October 30, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheJaredWilcurt/0a5b6044487cc55c705a to your computer and use it in GitHub Desktop.
Save TheJaredWilcurt/0a5b6044487cc55c705a to your computer and use it in GitHub Desktop.
<?php
//Set the Album ID's that are used for each building
$cpcsc = "251473051712334";
$bes = "706163866111939";
$ces = "290556731124119";
$pces = "753957011313835";
$swe = "700942789979520";
$wes = "694778440608716";
$cpi = "300475640123783";
$cpms = "515970251858827";
$wchs = "251473051712334"; //UPDATE LATER
$cpa = "251473051712334"; //UPDATE LATER
//Access Token from developers.facebook.com/tools/explorer
//Logged in as CENSORED FOR PUBLIC GIST
//Since all facebook pages should be public, we shouldn't need this token. Keep it purely for testing
$access_token = "access_token=CENSORED FOR PUBLIC GIST";
//Limit number of images to be pulled from Facebook
$limit = "photos?limit=10";
//Detect the URL input from the "LOAD HOMEPAGE ITEMS" section of the main JS, then assign a photo album ID to a variable
switch ($_GET['building']) {
case "cpcsc":
$albumid = "$cpcsc/$limit";
break;
//If the body has a class of "bes" then set the albumid variable to "706163866111939/photos?limit=10"
case "bes":
$albumid = "$bes/$limit";
break;
case "ces":
$albumid = "$ces/$limit";
break;
case "pces":
$albumid = "$pces/$limit";
break;
case "swe":
$albumid = "$swe/$limit";
break;
case "wes":
$albumid = "$wes/$limit";
break;
case "cpi":
$albumid = "$cpi/$limit";
break;
case "cpms":
$albumid = "$cpms/$limit";
break;
case "wchs":
$albumid = "$wchs/$limit";
break;
case "cpa":
$albumid = "$cpa/$limit";
break;
default:
$albumid = "$cpcsc/$limit";
break;
}
//Plug that information in to the Facebook API, then decode the data it sends back
$contents = file_get_contents("http://graph.facebook.com/$albumid");
$photos = json_decode($contents,true);
$photos = $photos['data'];
//Process that data and return it as usable HTML for the homepages slideshow box
foreach ($photos as $row)
{
//Set the span variable as empty every time the for loop is ran
//Otherwise photos without a caption will be given the same caption as the previous photo
$span = "";
//If there is a caption on the image create a span with that caption and assign it to the span var
if( $row['name'] != '' ){
$span = '<span class="fbcaption">' . $row ['name'] . '</span>';
}
//Generate HTML of each image and it's caption if it has one. Ready to be used by Owl-Carousel.
echo '
<div class="item">
<img src="' . $row['images'][1]['source'] . '" alt="' . $row ['name'] . '" />
' . $span . '
</div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment