Facebook Events Widget

Very useful for groups etc. Display the events from your facebook events page on your website. Could easily be edited to add the events to google calendar

 <link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table {
	background-color: #C3DEBA;
	padding: 5px;
	text-align: left;
	margin: 5px;
}
table strong {
	colour: #000;
}
.detail {
	color: #339;
	background-color: #FFF;
	border: 1px solid #006D03;
	cursor:pointer;
	padding: 1px 3px 1px 3px;
}
.desc {
	color: #000;
	cursor:auto;
}

body {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
</style>
<script type="text/javascript">

var events = new Array();
<?php 
function breakdown($string, $searchTerm, $endSearch)
{
	$length=strlen($searchTerm);
	if ($length >0) {
	$pos = (strpos($string, $searchTerm))+$length; }
	$pos2 = strpos($string, $endSearch, $pos); 
$pos2=$pos2-$pos;
$replace = array (chr(92), chr(13).chr(10).chr(32), chr(13), chr(10) );
return str_replace($replace, '',substr($string, $pos, $pos2));
	
}


 $url = // IMPORTANT: to get the script to work you need to click export from your events page
// on facebook and paste the address in here. Change the beginning web:// to http://
    $str = file_get_contents($url);
	
	$array=spliti('DTSTART:', $str);
for ($i=1; $i < count($array); $i++) {
$startDate=breakdown($array[$i], '' , 'T');
$Syear=substr($startDate, 0, 4); $Smonth=substr($startDate, 4, 2); $Sday=substr($startDate, 6, 2);
$startTime=substr(breakdown($array[$i], 'T' , 'Z'), 0, 2).':'.substr(breakdown($array[$i], 'T' , 'Z'), 2, 2);
$end=breakdown($array[$i], 'DTEND:' , 'UID:');
$endDate=breakdown($end, '' , 'T');
$Eyear=substr($endDate, 0, 4); $Emonth=substr($endDate, 4, 2); $Eday=substr($endDate, 6, 2);
$endTime=substr(breakdown($end, 'T' , 'Z'), 0, 2).':'.substr(breakdown($end, 'T' , 'Z'), 2, 2);
$summary=breakdown($array[$i], 'SUMMARY:' , 'LOCATION:');
$location=str_replace('"', '',breakdown($array[$i], 'LOCATION:' , 'URL:'));
$url=breakdown($array[$i], 'URL:' , 'DESCRIPTION:');
$description=str_replace('"', '',breakdown($array[$i], 'DESCRIPTION:' , '\n\n'));
$date=mktime(0,0,0,$Smonth,$Sday,$Syear);
$sql=("select * from events where URL = '$url'");
$recordset=mysql_query($sql,$connection);
$num_rows = mysql_num_rows($recordset);
if ($num_rows ==0) {
	$sql=("INSERT INTO events (URL) VALUES ('$url')");
	EmailSubscribers($summary, $description, $location, date("l jS F Y", $date), $startTime, $url );
mysql_query($sql,$connection);
}	



$event= 'events['.$i.']="'."<br /><strong>Where:</strong> $location<br /><strong>Description: </strong>$description<br /><strong>More Info:</strong> <a href='".$url."'>Facebook Event Link</a>".'";';
echo $event;

$table= "<tr>
    <td><strong>$startTime - ".date("l jS F Y", $date)."</strong></td></tr><tr>
    <td onclick='eventshow($i)' class='detail'>
 <u>$summary</u> <font class='desc' id='event$i'></font></td></tr> ".$table;

	
}

?>	
function eventshow(content)
{
	castles = 'testing </br > <br / >'
	if (document.getElementById('event'+content).innerHTML==''){
		document.getElementById('event'+content).innerHTML=events[content];}else{
			document.getElementById('event'+content).innerHTML='';}}	

</script>

<table id="eventcal" width="250" border="0" cellspacing="2">

<?php echo $table; ?>

</table>

Usage

The code as above will create a google calendar like widget in agenda view on your webpage. Obviously you can strip it down to just the PHP and use it for all manner of things such as uploading the events to you google calendar with the gcal api. To get the script to work you need to click export from your events page on facebook and paste the address in $url= then Change the beginning web:// to http://


Comments

guest
Posted on 30.01.2012 13:19

Hi, i cant get this work. I have exporten and inserter the url under $Url but is gives me the following error:
Parse error: parse error in C:\wamp\www\facebook-events-widget.php on line 47
syntax error, unexpected ':'

Regards
Pontus

Add your comment