Facebook events to CMS made simple

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
sderks
Forum Members
Forum Members
Posts: 10
Joined: Fri Aug 03, 2007 3:11 pm

Facebook events to CMS made simple

Post by sderks »

Hello all,

After a long search in all the module i didn't find a scprit what a Facebook event place into a list at the CMS made simple site.

So i make it my self. Below stay the code:
past it into a user define tag.

-----------------------------------------------------------------------------

Code: Select all


// paste the Facebook webcal link below and replace webcal to https
$webcal =("https://www.facebook.com/ical/u.php?uid=100002220601702&key=AQDlz7vxlN-7RIBv");

function build_table($aRevEvenementen){
//start table
    $html .= '<table width="80%">';
	$html .= '<tbody>';
// header row
    $html .= '<tr>';
    foreach($aRevEvenementen[0] as $key=>$value){
            $html .= '<td>' . $key . '</td>';
        }
    $html .= '</tr>';
// data rows
    foreach($aRevEvenementen as $value){
        $html .= '<tr>';
        foreach($value as $value2){
            $html .= '<td>' . $value2 . ' </td>';
        }
        $html .= '</tr>';
    }
// finish table and return it
	$html .= '</tbody>';
    $html .= '</table>';
    return $html;
    }

//Start main function

$aEvenementen = array ();
$handle = @fopen($webcal, "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        if (strpos($buffer, 'DTSTART') !== false){
    		$DTstart_year = substr($buffer, 8, -14);  // DTSTART:20170114T180000Z
			$DTstart_month = substr($buffer, 12, -12);
			$DTstart_day = substr($buffer, 14, -10);
			$DTstart_hour = (substr($buffer, 17, -7) + 1); // add 1 hour time zone compensation
			$DTstart_min = substr($buffer, 19, -5);
			$Date = $DTstart_day.' - '.$DTstart_month.' - '.$DTstart_year; // return 14 - 01 - 2017
			$StartTime = $DTstart_hour.':'.$DTstart_min; // return opening 18:00
		}
		if (strpos($buffer, 'DTEND') !== false){
			$DTend_year = substr($buffer, 6, -14);
			$DTend_month = substr($buffer, 10, -12);
			$DTend_day = substr($buffer, 12, -10);
			$DTend_hour = (substr($buffer, 15, -7) + 1); // add 1 hour time zone compensation
			$DTend_min = substr($buffer, 17, -5);
			if (($DTend_hour - $DTstart_hour) == 3){ // needed when no end time is filled defaut 3h
				$EndTime = '-';
			}
			else{
			$EndTime = ' '.$DTend_hour.':'.$DTend_min;
			}
		}
		if (strpos($buffer, 'SUMMARY') !== false){
			$summary = substr($buffer, 8, -1);  // returns "Text - SUMMARY"
// put strings into a multiple array
			$aEvenementen[$i] ['Date'] = $Date;
			$aEvenementen[$i] ['Summary'] = $summary;
			$aEvenementen[$i] ['Start Time'] = $StartTime;
			$aEvenementen[$i] ['End Time'] = $EndTime;
			$i=$i+1;
		}
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
	}
	fclose($handle);
}	

	$aRevEvenementen = array_reverse($aEvenementen); // place oldest date above
	echo build_table($aRevEvenementen);

Locked

Return to “Tips and Tricks”