";
print_r($val);
echo '';
}
// print_r3($calArray);
function convertSmartQuotes($string) {
$search = array(chr(145),
chr(146),
'’',
'`',
chr(147),
chr(148),
chr(151),
chr(160),
'',
'',
'
Speaker:',
'
Remote Access:',
'
Abstract:',
'
About the Speaker:',
'
Sponsor:');
$replace = array("'",
"'",
"'",
"'",
'"',
'"',
'-',
' ',
'',
'',
'
Speaker: ',
'
Remote Access: ',
'
Abstract: ',
'
About The Speaker: ',
'
Sponsor: ');
return str_replace($search, $replace, $string);
}
// This list is coded in a table w/ inline styles because it permits the page contents to
// be copied and pasted into an e-mail for broadcast to subscribers w/ no loss of layout fidelity
// style th & td swapped in for variables to make the code more readable and editable:
$styledTH = "
\n ";
$styledTD = " | ";
$dateH3 = "";
$renderBlob = ""; // this is only the current 'blob';
$renderBlobFuture = "";
$renderBlobPast = "";
$prevEvDate = "";
$nowDateObj = new DateTime();
foreach($calArray['items'] as $elements) {
// updated 3/16/2016
// this 'if' catches the condition when users (accidentally?) set the visibility of seminars to 'private',
// we don't render events that are set to private;
// we render cal events when visibility is (a) NOT set, and (b) visibility 'is explicitly set to public
if (((!isset($elements["visibility"])) || ($elements["visibility"] == "public")) && isset($elements['summary']) && ($elements['summary'] !== "")) {
new DateTime($elements["start"]["dateTime"]);
$curDateObj = new DateTime($elements["start"]["dateTime"]);
$curDate = date_format($curDateObj,"F j, Y");
if ($prevEvDate == "") {
$renderBlob .= $dateH3 . $curDate . "\n";
}
if (($prevEvDate !== "") && ($curDate !== $prevEvDate)) {
$renderBlob .= $dateH3 . $curDate . "\n";
}
$ExpandLinkID = "Exp" . rand(10000,49999);
$ExpandDescrID = $ExpandLinkID . "a";
$eventTop = "Top" . $ExpandLinkID;
$renderBlob .= "\n\n";
$renderBlob .= $styledTH . "Title:\n";
// 2016-05-24: adding 'new' indicator to the title field
// $elements['created'] gives the date the seminar entry was created in the format:
// "2014-11-22T13:10:20.000Z"
// Take the first 10 chars of this field and get PHP to see it as a date,
// then test to see if the date is < 1 week ago, and print 'New' if it is less than 1 week ago
$creationDateString = substr($elements['created'],5,2)."/".substr($elements['created'],8,2)."/".substr($elements['created'],0,4);
$creationDate = (date_create($creationDateString));
$creationDateFormatted = date("m-d-Y", (strtotime($creationDateString)));
$today = date_create();
$daysAgo = date_diff($today,$creationDate);
if (($daysAgo->days) < 8) {
$newString = "New ";
}
else {
$newString = "";
}
$renderBlob .= $styledTD . $newString;
// if 'future', show link to calendar entry
if ($listType == 'future') {
$renderBlob .= "" . $elements['summary'] . "";
}
// if 'past', no link to calendar, just the event title
if ($listType == 'past') {
$renderBlob .= "" . $elements['summary'] . "";
}
$renderBlob .= "\n \n";
// extract the presenter's name and affiliation from the end of the description field, enclosed in {}
if (isset($elements['description']) && ($elements['description'] !== "")) { // if there is content in the description
$descr = $elements['description'];
}
if (!isset($elements['description']) || ($elements['description'] == "")) { // if no content in description
$descr = "No description has been supplied for this seminar. Check back soon for complete details.";
}
$descr = convertSmartQuotes($descr); // remove unneeded html tags and bad characters
$renderBlob .= $styledTH . "Presenter(s):\n";
// there is no data field in the Google calendar for seminar presenter
// we create such a field for our calendar listing by doing the following:
// at the end of the description field, we ask everyone who creates a seminar listing
// UPDATE: 5/4/2018
// to add, in a separate line, enclosed by CURLY BRACES, the name and affiliation of the presenter(s)
// so the presenter name looks like: {Dr. Marian Smith, University of Akron, Department of Oceanography}
// so when we want to render that presenter info into this listing, the next line of code extracts the content between the curly braces
// have to keep the parenthetical option for backward compatibility
$lastChars = substr($descr,-20);
$descrLngth = strlen($descr);
// echo $lastChars;
if (stripos($lastChars,'}')) { // if using {} for presenter block at bottom
$PresStart = strripos($descr,'{');
$PresEnd = strripos($descr,'}');
$presenterString = (substr($descr, $PresStart+1, ($PresEnd - $PresStart - 1)));
$descr_minusPresenter = substr($descr, 0, $PresStart-1);
}
else if (stripos($lastChars,')')) { // using parens
$PresStart = strripos($descr,'(');
$PresEnd = strripos($descr,')');
$presenterString = (substr($descr, $PresStart+1, ($PresEnd - $PresStart - 1)));
$descr_minusPresenter = substr($descr, 0, $PresStart-1);
}
else {
$presenterString = "TBD";
$descr_minusPresenter = $descr;
}
$renderBlob .= $styledTD . $presenterString ."\n \n";
$startTime=new DateTime($elements["start"]["dateTime"]);
$startTimeFormatted = date_format($startTime,'g:i a');
$endTime = new DateTime($elements["end"]["dateTime"]);
$endTimeFormatted = date_format($endTime,'g:i a');
$renderBlob .= $styledTH . "Date & Time:\n" . $styledTD . $curDate . "\n";
$renderBlob .= " " . $startTimeFormatted ." - " . $endTimeFormatted ." ET\n \n";
if (isset($elements['location'])) {
$location = $elements['location'];
} else {
$location = 'TBD';
}
$renderBlob .= $styledTH . "Location:\n" . $styledTD . $location . "\n \n";
$tmeid = substr($elements['htmlLink'],(strpos($elements['htmlLink'],'=')+1)); // $tmeid is a Google event identifier that we use to build the URL
// when the description field is rendered onto the page,
// we remove the presenter name from the end, to reduce redundancy
// the description is rendered into a div that is initially not visible but expanded by clicking the link that says 'Expand'.
$renderBlob .= $styledTH . "Description:\n";
$renderBlob .= $styledTD . "\n";
$renderBlob .= " \n";
$renderBlob .= " \n";
$renderBlob .= $descr_minusPresenter ." \n \n";
// only rendering the 'add to calendar' button for FUTURE events, not PAST
$todayVal = date_timestamp_get($today);
$startTimeVal = date_timestamp_get($startTime);
// if ($todayVal < $startTimeVal) { // if the event in question is in the FUTURE
if ($listType == 'future') {
$renderBlob .= $styledTH . "Add seminar:\n";
$renderBlob .= $styledTD . " = $nowDateObj) { // if this is a future event
$renderBlobFuture .= $renderBlob;
}
else { // if this is a past event
$renderBlobPast .= $renderBlob;
}
$renderBlob = ""; // reset var to start over with the next event
} // end of 'if' for catching events set to private and not displaying them. - 10/2/2015
}
// future list type, has content
if (($listType=='future') && (strlen($renderBlobFuture) > 10)) {
echo $renderBlobFuture;
}
// past list type, has content
if (($listType=='past') && (strlen($renderBlobPast) > 10)) {
echo $renderBlobPast;
}
// future list type, no content
if (($listType=='future') && (strlen($renderBlobFuture) < 10)) {
echo " Please check back later for new seminars. ";
}
// past list type, no content
if (($listType=='past') && (strlen($renderBlobPast) < 10)) {
echo " No past seminars for this period to display. ";
}
} // end of function bracket
?> |