Last active
August 29, 2015 13:57
-
-
Save critmcdonald/9715299 to your computer and use it in GitHub Desktop.
Passing Caspio variable for Facebook sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First, in my Caspio search result, I don't include the | |
// detail page in the report, but instead create an HTML field that links | |
// to the report and passes two fields: the VenueID, which is used to pull | |
// the right record, and the SVenue, which is the name of the venue that | |
// I need for sharing. | |
<a href="venue.php?VenueID=[@field:VenueID]&Venue=[@field:SVenue]">[@field:SVenue]</a><br /> | |
// This gives me a url like this: | |
http://projects.statesman.com/happy-hours/venue.php?VenueID=3&Venue=Aussie%27s | |
// Here is the PHP code. It gets the URL, parses the Query part, breaks it into parts | |
// so I can get the last part, search and replaces things like commas accents | |
// and sets it as the variable to use later. | |
<?php | |
$url = $_SERVER['REQUEST_URI']; | |
$path = parse_url($url, PHP_URL_QUERY); | |
$pathFragments = explode('=', $path); | |
$venue = end($pathFragments); | |
$search = array("%20", "%27","%C3%A9"); | |
$replace = array(" ", "'","é"); | |
$venue = str_replace($search, $replace, $venue); | |
?> | |
// And with the $venue variable set, I use it to write the metatag | |
<meta property="og:title" content="Happy hour specials at <?php echo $venue; ?>"/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment