-
-
Save sethshoultes/5847ed7d04ac303e28a6 to your computer and use it in GitHub Desktop.
Event Espresso API Examples
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
<?php | |
session_start(); | |
//Upcoming Events w/Caching | |
/* This shows how you can utilize Event Espresso's internal caching to create a cached the result on the server. Then display the results. */ | |
$curdate = date("Y-m-d H:i:s"); | |
//Clear the session | |
if ( isset($_REQUEST['clear_session']) && !empty($_REQUEST['clear_session']) ){ | |
if ($_REQUEST['clear_session'] == 'true'){ | |
$_SESSION['ee_api_session'] = ''; | |
header( 'Location: '.$_SERVER['HTTP_REFERER'] ) ; | |
} | |
} | |
//Creates a cached version of the data on the server | |
$cache_create_url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/events/public?Datetime.event_start__gt=".urlencode($curdate)."&cache_result=true"; | |
if (!isset($_SESSION['ee_api_session']['cache_key']) || empty($_SESSION['ee_api_session']['cache_key'])){ | |
$get_response = file_get_contents($cache_create_url, true); //getting the file content | |
$decode_response = json_decode($get_response, true); //getting the file content as array | |
//echo $decode_response['body']['cached_result_key']; | |
$_SESSION['ee_api_session']['cache_key'] = $decode_response['body']['cached_result_key']; | |
} | |
//Retrieve the cached data | |
$cached_url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/cachedresults/".$_SESSION['ee_api_session']['cache_key']."/public"; | |
$json = file_get_contents($cached_url, true); //getting the file content | |
$decode = json_decode($json, true); //getting the file content as array | |
$count = count($decode['body']['Events']); //counting the number of results | |
//Show raw results | |
/*echo "<pre>"; | |
print_r($decode_response); | |
echo "</pre>";*/ | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Espresso JSON API - Caching Live Example</title> | |
<style type='text/css'> | |
body { | |
font-family: Helvetica, Sans, Arial; | |
} | |
p, ul { | |
padding: 5px; | |
} | |
p span{ | |
font-weight:bold; | |
} | |
p a { | |
color: #06F; | |
text-decoration:none; | |
} | |
h3 { | |
margin-left:10px; | |
} | |
.red { | |
color:red; | |
} | |
div.style{ | |
margin: 10px; | |
border: 2px dashed #999; | |
float:left; | |
} | |
div.events { | |
clear:both; | |
margin:20px; | |
} | |
div.event { | |
clear:both; | |
margin:10px; | |
float:left; | |
} | |
.json-image { width: 100px; height: 100px; overflow: hidden; float:right; } | |
.json-image img { width: 100%;} | |
#footer { | |
width:570px; | |
clear:both; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="style"> | |
<h3>Upcoming Events (<span class="red">cached</span>)</h3> | |
<div id="events"> | |
<?php | |
if ($count > 0){ | |
foreach ($decode['body']['Events'] as $event){ | |
echo '<div class="event">'; | |
echo isset($event['metadata']['event_thumbnail_url']) && !empty($event['metadata']['event_thumbnail_url']) ? '<div class="json-image"><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'"><img src="'.stripslashes($event['metadata']['event_thumbnail_url']).'" /></a></div>' : ''; | |
echo '<p><span><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'">'.$event['name'].'</a></span><br />'.date('l jS \of F Y @h:i A',strtotime($event['Datetimes'][0]['event_start'])).'</p>'; | |
echo '</div>'; | |
//Might have to turn off featured images when using the 'description' value | |
//'.$event['description'].' | |
} | |
} | |
?> | |
</div> | |
</div> | |
<div id="footer"><p>Showing <strong><?php echo $count ?></strong> <span class="red">cached</span> results, that start after <strong><?php echo date('l jS \of F Y h:i:s A', strtotime($curdate)) ?></strong>, using this url:<br /> | |
<a href="<?php echo $cached_url ?>" target="_blank"><?php echo $cached_url ?></a></p> | |
<p><a href="?clear_session=true">Start New Session</a></p> | |
<p>Please visit the <a href="http://codex.eventespresso.com/index.php?title=Rest_api">Event Espresso API Codex</a> and <a href="http://codex.eventespresso.com/index.php?title=Rest_api#Caching.2C_Counting_and_Query_Limits" target="_blank">Caching, Counting and Query Limits</a> info pages.</p></div> | |
</body> | |
</html> |
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
<?php | |
session_start(); | |
//Past Events w/Caching | |
/* This shows how you can utilize Event Espresso's internal caching to create a cached the result on the server. Then display the results. */ | |
$curdate = date("Y-m-d H:i:s"); | |
//Clear the session | |
if ( isset($_REQUEST['clear_session']) && !empty($_REQUEST['clear_session']) ){ | |
if ($_REQUEST['clear_session'] == 'true'){ | |
$_SESSION['ee_api_session'] = ''; | |
header( 'Location: '.$_SERVER['HTTP_REFERER'] ) ; | |
} | |
} | |
//Creates a cached version of the data on the server | |
$cache_create_url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/events/public?Datetime.event_start__lt=".urlencode($curdate)."&cache_result=true"; | |
if (!isset($_SESSION['ee_api_session']['cache_key']) || empty($_SESSION['ee_api_session']['cache_key'])){ | |
$get_response = file_get_contents($cache_create_url, true); //getting the file content | |
$decode_response = json_decode($get_response, true); //getting the file content as array | |
//echo $decode_response['body']['cached_result_key']; | |
$_SESSION['ee_api_session']['cache_key'] = $decode_response['body']['cached_result_key']; | |
} | |
//Retrieve the cached data | |
$cached_url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/cachedresults/".$_SESSION['ee_api_session']['cache_key']."/public"; | |
$json = file_get_contents($cached_url, true); //getting the file content | |
$decode = json_decode($json, true); //getting the file content as array | |
$count = count($decode['body']['Events']); //counting the number of results | |
//Show raw results | |
/*echo "<pre>"; | |
print_r($decode_response); | |
echo "</pre>";*/ | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Espresso JSON API - Past Evetns Caching Live Example</title> | |
<style type='text/css'> | |
body { | |
font-family: Helvetica, Sans, Arial; | |
} | |
p, ul { | |
padding: 5px; | |
} | |
p span{ | |
font-weight:bold; | |
} | |
p a { | |
color: #06F; | |
text-decoration:none; | |
} | |
h3 { | |
margin-left:10px; | |
} | |
.red { | |
color:red; | |
} | |
div.style{ | |
margin: 10px; | |
border: 2px dashed #999; | |
float:left; | |
} | |
div.events { | |
clear:both; | |
margin:20px; | |
} | |
div.event { | |
clear:both; | |
margin:10px; | |
float:left; | |
} | |
.session-button { | |
color: #F60; | |
margin-left:10px; | |
font-size:24px; | |
} | |
.json-image { width: 100px; height: 100px; overflow: hidden; float:right; } | |
.json-image img { width: 100%;} | |
#footer { | |
width:570px; | |
clear:both; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="style"> | |
<h3>Past Events (<span class="red">cached</span>)</h3> | |
<p><a class="session-button" href="?clear_session=true">Start New Session</a></p> | |
<div id="events"> | |
<?php | |
if ($count > 0){ | |
foreach ($decode['body']['Events'] as $event){ | |
echo '<div class="event">'; | |
echo isset($event['metadata']['event_thumbnail_url']) && !empty($event['metadata']['event_thumbnail_url']) ? '<div class="json-image"><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'"><img src="'.stripslashes($event['metadata']['event_thumbnail_url']).'" /></a></div>' : ''; | |
echo '<p><span><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'">'.$event['name'].'</a></span><br />'.date('l jS \of F Y @h:i A',strtotime($event['Datetimes'][0]['event_start'])).'</p>'; | |
echo '</div>'; | |
//Might have to turn off featured images when using the 'description' value | |
//'.$event['description'].' | |
} | |
} | |
?> | |
</div> | |
</div> | |
<div id="footer"><p>Showing <strong><?php echo $count ?></strong> <span class="red">cached</span> results, that started before <strong><?php echo date('l jS \of F Y h:i:s A', strtotime($curdate)) ?></strong>, using this url:<br /> | |
<a href="<?php echo $cached_url ?>" target="_blank"><?php echo $cached_url ?></a></p> | |
<p>Please visit the <a href="http://codex.eventespresso.com/index.php?title=Rest_api">Event Espresso API Codex</a> and <a href="http://codex.eventespresso.com/index.php?title=Rest_api#Caching.2C_Counting_and_Query_Limits" target="_blank">Caching, Counting and Query Limits</a> info pages.</p></div> | |
</body> | |
</html> |
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
<?php | |
//Past Events | |
//Load times may vary because all available results are retrieved from the database. | |
$curdate = date("Y-m-d H:i:s"); | |
$url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/events/public?Datetime.event_start__lt=".urlencode($curdate); | |
//Retrieve the data | |
$json = file_get_contents($url, true); //getting the file content | |
$decode = json_decode($json, true); //getting the file content as array | |
$count = count($decode['body']['Events']); //counting the number of results | |
//Show raw results | |
/*echo "<pre>"; | |
print_r($decode); | |
echo "</pre>";*/ | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Espresso JSON API - Past Events Live Example</title> | |
<style type='text/css'> | |
body { | |
font-family: Helvetica, Sans, Arial; | |
} | |
p, ul { | |
padding: 5px; | |
} | |
p span{ | |
font-weight:bold; | |
} | |
p a { | |
color: #06F; | |
text-decoration:none; | |
} | |
h3 { | |
margin-left:10px; | |
} | |
div.style{ | |
margin: 10px; | |
border: 2px dashed #999; | |
float:left; | |
} | |
div.events { | |
clear:both; | |
margin:20px; | |
} | |
div.event { | |
clear:both; | |
margin:10px; | |
float:left; | |
} | |
.json-image { width: 100px; height: 100px; overflow: hidden; float:right; } | |
.json-image img { width: 100%;} | |
#footer { | |
width:570px; | |
clear:both; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="style"> | |
<h3>Past Events</h3> | |
<div id="events"> | |
<?php | |
if ($count > 0){ | |
foreach ($decode['body']['Events'] as $event){ | |
echo '<div class="event">'; | |
echo isset($event['metadata']['event_thumbnail_url']) && !empty($event['metadata']['event_thumbnail_url']) ? '<div class="json-image"><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'"><img src="'.stripslashes($event['metadata']['event_thumbnail_url']).'" /></a></div>' : ''; | |
echo '<p><span><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'">'.$event['name'].'</a></span><br />'.date('l jS \of F Y @h:i A',strtotime($event['Datetimes'][0]['event_start'])).'</p>'; | |
echo '</div>'; | |
//Might have to turn off featured images when using the 'description' value | |
//'.$event['description'].' | |
} | |
} | |
?> | |
</div> | |
</div> | |
<div id="footer"><p>Showing <strong><?php echo $count ?></strong> results, that started before <strong><?php echo date('l jS \of F Y h:i:s A', strtotime($curdate)) ?></strong>, using this url:<br /> | |
<a href="<?php echo $url ?>"><?php echo $url ?></a></p></div> | |
</body> | |
</html> |
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
<?php | |
//Upcoming Events | |
//Load times may vary because all available results are retrieved from the database. | |
$curdate = date("Y-m-d H:i:s"); | |
$url = "http://eventespresso.com/sandbox/dev2/espresso-api/v1/events/public?Datetime.event_start__gt=".urlencode($curdate); | |
//Retrieve the data | |
$json = file_get_contents($url, true); //getting the file content | |
$decode = json_decode($json, true); //getting the file content as array | |
$count = count($decode['body']['Events']); //counting the number of results | |
//Show raw results | |
/*echo "<pre>"; | |
print_r($decode); | |
echo "</pre>";*/ | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Espresso JSON API - Simple Live Example</title> | |
<style type='text/css'> | |
body { | |
font-family: Helvetica, Sans, Arial; | |
} | |
p, ul { | |
padding: 5px; | |
} | |
p span{ | |
font-weight:bold; | |
} | |
p a { | |
color: #06F; | |
text-decoration:none; | |
} | |
h3 { | |
margin-left:10px; | |
} | |
div.style{ | |
margin: 10px; | |
border: 2px dashed #999; | |
float:left; | |
} | |
div.events { | |
clear:both; | |
margin:20px; | |
} | |
div.event { | |
clear:both; | |
margin:10px; | |
float:left; | |
} | |
.json-image { width: 100px; height: 100px; overflow: hidden; float:right; } | |
.json-image img { width: 100%;} | |
#footer { | |
width:570px; | |
clear:both; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="style"> | |
<h3>Upcoming Events</h3> | |
<div id="events"> | |
<?php | |
if ($count > 0){ | |
foreach ($decode['body']['Events'] as $event){ | |
echo '<div class="event">'; | |
echo isset($event['metadata']['event_thumbnail_url']) && !empty($event['metadata']['event_thumbnail_url']) ? '<div class="json-image"><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'"><img src="'.stripslashes($event['metadata']['event_thumbnail_url']).'" /></a></div>' : ''; | |
echo '<p><span><a href="http://eventespresso.com/sandbox/dev2/event-registration/?ee='.$event['id'].'">'.$event['name'].'</a></span><br />'.date('l jS \of F Y @h:i A',strtotime($event['Datetimes'][0]['event_start'])).'</p>'; | |
echo '</div>'; | |
//Might have to turn off featured images when using the 'description' value | |
//'.$event['description'].' | |
} | |
} | |
?> | |
</div> | |
</div> | |
<div id="footer"><p>Showing <strong><?php echo $count ?></strong> results, that start after <strong><?php echo date('l jS \of F Y h:i:s A', strtotime($curdate)) ?></strong>, using this url:<br /> | |
<a href="<?php echo $url ?>"><?php echo $url ?></a></p></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These are a few examples of listing upcoming and past events using caching and no caching.