/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; // Get the current event $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar); if (null === $objEvent) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Overwrite the page title (see #2853 and #4955) if ($objEvent->title != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objEvent->title)); } // Overwrite the page description if ($objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($objEvent->teaser); } $intStartTime = $objEvent->startTime; $intEndTime = $objEvent->endTime; $span = \Calendar::calculateSpan($intStartTime, $intEndTime); // Do not show dates in the past if the event is recurring (see #923) if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) { while ($intStartTime < time() && $intEndTime < $objEvent->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } } $strDate = \Date::parse($objPage->dateFormat, $intStartTime); if ($span > 0) { $strDate = \Date::parse($objPage->dateFormat, $intStartTime) . ' – ' . \Date::parse($objPage->dateFormat, $intEndTime); } $strTime = ''; if ($objEvent->addTime) { if ($span > 0) { $strDate = \Date::parse($objPage->datimFormat, $intStartTime) . ' – ' . \Date::parse($objPage->datimFormat, $intEndTime); } elseif ($intStartTime == $intEndTime) { $strTime = \Date::parse($objPage->timeFormat, $intStartTime); } else { $strTime = \Date::parse($objPage->timeFormat, $intStartTime) . ' – ' . \Date::parse($objPage->timeFormat, $intEndTime); } } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) { $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd)); } } } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($objEvent->row()); $objTemplate->date = $strDate; $objTemplate->time = $strTime; $objTemplate->datetime = $objEvent->addTime ? date('Y-m-d\\TH:i:sP', $intStartTime) : date('Y-m-d', $intStartTime); $objTemplate->begin = $intStartTime; $objTemplate->end = $intEndTime; $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : ''; $objTemplate->recurring = $recurring; $objTemplate->until = $until; $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location']; $objTemplate->details = ''; $objTemplate->hasDetails = false; $objTemplate->hasTeaser = false; // Clean the RTE output if ($objEvent->teaser != '') { $objTemplate->hasTeaser = true; if ($objPage->outputFormat == 'xhtml') { $objTemplate->teaser = \StringUtil::toXhtml($objEvent->teaser); } else { $objTemplate->teaser = \StringUtil::toHtml5($objEvent->teaser); } $objTemplate->teaser = \StringUtil::encodeEmail($objTemplate->teaser); } // Display the "read more" button for external/article links if ($objEvent->source != 'default') { $objTemplate->details = true; $objTemplate->hasDetails = true; } else { $id = $objEvent->id; $objTemplate->details = function () use($id) { $strDetails = ''; $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $strDetails .= $this->getContentElement($objElement->current()); } } return $strDetails; }; $objTemplate->hasDetails = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0; } $objTemplate->addImage = false; // Add an image if ($objEvent->addImage && $objEvent->singleSRC != '') { $objModel = \FilesModel::findByUuid($objEvent->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objEvent->singleSRC)) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrEvent = $objEvent->row(); // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $arrEvent['size'] = $this->imgSize; } } $arrEvent['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrEvent); } } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } /** @var \CalendarModel $objCalendar */ $objCalendar = $objEvent->getRelated('pid'); $this->Template->allowComments = $objCalendar->allowComments; // Comments are not allowed if (!$objCalendar->allowComments) { return; } // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCalendar->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCalendar->notify != 'notify_admin') { /** @var \UserModel $objAuthor */ if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCalendar->perPage; $objConfig->order = $objCalendar->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCalendar->requireLogin; $objConfig->disableCaptcha = $objCalendar->disableCaptcha; $objConfig->bbcode = $objCalendar->bbcode; $objConfig->moderate = $objCalendar->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies); }
/** * Prepare widget options array * Used in backend and frontend * @param array|boolean $arrField Form field properties * @return array DCA/widget options */ public function prepareWidgetOptions($arrField = false) { if (!is_array($arrField)) { return false; } $strType = $arrField['type']; if (TL_MODE == 'FE' && !empty($arrField['formfieldType'])) { $strType = $arrField['formfieldType']; } elseif (TL_MODE == 'BE' && !empty($arrField['inputType'])) { $strType = $arrField['inputType']; } $arrOptions = array(); switch ($strType) { case 'efgLookupCheckbox': case 'efgLookupRadio': case 'efgLookupSelect': // Get efgLookupOptions: array('lookup_field' => TABLENAME.FIELDNAME, 'lookup_val_field' => TABLENAME.FIELDNAME, 'lookup_where' => CONDITION, 'lookup_sort' => ORDER BY) $arrLookupOptions = deserialize($arrField['efgLookupOptions']); $strLookupField = $arrLookupOptions['lookup_field']; $strLookupValField = strlen($arrLookupOptions['lookup_val_field']) ? $arrLookupOptions['lookup_val_field'] : null; $strLookupWhere = \String::decodeEntities($arrLookupOptions['lookup_where']); if (!empty($strLookupWhere)) { $strLookupWhere = $this->replaceInsertTags($strLookupWhere, false); } $arrLookupField = explode('.', $strLookupField); $sqlLookupTable = $arrLookupField[0]; $sqlLookupField = $arrLookupField[1]; $sqlLookupValField = strlen($strLookupValField) ? substr($strLookupValField, strpos($strLookupValField, '.') + 1) : null; $sqlLookupIdField = 'id'; $sqlLookupWhere = !empty($strLookupWhere) ? " WHERE " . $strLookupWhere : ""; $sqlLookupOrder = $arrLookupField[0] . '.' . $arrLookupField[1]; if (!empty($arrLookupOptions['lookup_sort'])) { $sqlLookupOrder = $arrLookupOptions['lookup_sort']; } $arrOptions = array(); // Handle lookup formdata if (substr($sqlLookupTable, 0, 3) == 'fd_') { $strFormKey = $this->arrFormsDcaKey[substr($sqlLookupTable, 3)]; $sqlLookupTable = 'tl_formdata f, tl_formdata_details fd'; $sqlLookupIdField = 'f.id'; $sqlLookupWhere = " WHERE (f.id=fd.pid AND f.form='" . $strFormKey . "' AND ff_name='" . $arrLookupField[1] . "')"; $arrDetailFields = array(); if (!empty($strLookupWhere) || !empty($arrLookupOptions['lookup_sort'])) { $objDetailFields = \Database::getInstance()->prepare("SELECT DISTINCT(ff.`name`) FROM tl_form f, tl_form_field ff WHERE f.storeFormdata=? AND (f.id=ff.pid) AND ff.`type` IN ('" . implode("','", $this->arrFFstorable) . "')")->execute('1'); if ($objDetailFields->numRows) { $arrDetailFields = $objDetailFields->fetchEach('name'); } } if (!empty($strLookupWhere)) { // Special treatment for fields in tl_formdata_details $arrPattern = array(); $arrReplace = array(); foreach ($arrDetailFields as $strDetailField) { $arrPattern[] = '/\\b' . $strDetailField . '\\b/i'; $arrReplace[] = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $strDetailField . '\'))'; } $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : " WHERE ") . "(" . preg_replace($arrPattern, $arrReplace, $strLookupWhere) . ")"; } $sqlLookupField = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $arrLookupField[1] . '\') ) AS `' . $arrLookupField[1] . '`'; if (!empty($arrLookupOptions['lookup_sort'])) { // Special treatment for fields in tl_formdata_details $arrPattern = array(); $arrReplace = array(); foreach ($arrDetailFields as $strDetailField) { $arrPattern[] = '/\\b' . $strDetailField . '\\b/i'; $arrReplace[] = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $strDetailField . '\'))'; } $sqlLookupOrder = preg_replace($arrPattern, $arrReplace, str_replace($arrLookupField[0] . '.', '', $arrLookupOptions['lookup_sort'])); } else { $sqlLookupOrder = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $arrLookupField[1] . '\'))'; } } // Handle lookup calendar events if ($sqlLookupTable == 'tl_calendar_events') { $sqlLookupOrder = ''; // Handle order (max. 2 fields) // .. default startTime ASC $arrSortKeys = array(array('field' => 'startTime', 'order' => 'ASC'), array('field' => 'startTime', 'order' => 'ASC')); if (!empty($arrLookupOptions['lookup_sort'])) { $sqlLookupOrder = $arrLookupOptions['lookup_sort']; $arrSortOn = trimsplit(',', $arrLookupOptions['lookup_sort']); $arrSortKeys = array(); foreach ($arrSortOn as $strSort) { $arrSortParam = explode(' ', $strSort); $arrSortKeys[] = array('field' => $arrSortParam[0], 'order' => strtoupper($arrSortParam[1]) == 'DESC' ? 'DESC' : 'ASC'); } } $sqlLookupWhere = !empty($strLookupWhere) ? "(" . $strLookupWhere . ")" : ""; $strReferer = $this->getReferer(); // If form is placed on an events detail page, automatically add restriction to event(s) if (strlen(\Input::get('events'))) { if (is_numeric(\Input::get('events'))) { $sqlLookupWhere .= (!empty($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.id=" . intval(\Input::get('events')) . " "; } elseif (is_string(\Input::get('events'))) { $sqlLookupWhere .= (!empty($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.alias='" . \Input::get('events') . "' "; } } // If linked from event reader page if (strpos($strReferer, 'event-reader/events/') || strpos($strReferer, '&events=')) { if (strpos($strReferer, 'events/')) { $strEvents = substr($strReferer, strrpos($strReferer, '/') + 1); } elseif (strpos($strReferer, '&events=')) { $strEvents = substr($strReferer, strpos($strReferer, '&events=') + strlen('&events=')); } if (is_numeric($strEvents)) { $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.id=" . intval($strEvents) . " "; } elseif (is_string($strEvents)) { $strEvents = str_replace('.html', '', $strEvents); $sqlLookupWhere .= (!empty($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.alias='" . $strEvents . "' "; } } $sqlLookup = "SELECT tl_calendar_events.* FROM tl_calendar_events, tl_calendar WHERE (tl_calendar.id=tl_calendar_events.pid) " . (!empty($sqlLookupWhere) ? " AND (" . $sqlLookupWhere . ")" : "") . (strlen($sqlLookupOrder) ? " ORDER BY " . $sqlLookupOrder : ""); $objEvents = \Database::getInstance()->prepare($sqlLookup)->execute(); $arrEvents = array(); if ($objEvents->numRows) { while ($arrEvent = $objEvents->fetchAssoc()) { $intDate = $arrEvent['startDate']; $intStart = time(); $intEnd = time() + 60 * 60 * 24 * 178; // max. half year $span = \Calendar::calculateSpan($arrEvent['startTime'], $arrEvent['endTime']); $strTime = ''; $strTime .= date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['startDate']); if ($arrEvent['addTime']) { if ($span > 0) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']) . ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } elseif ($arrEvent['startTime'] == $arrEvent['endTime']) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']); } else { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } } else { if ($span > 1) { $strTime .= ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']); } } if ($sqlLookupValField) { // $arrEvents[$arrEvent[$sqlLookupValField].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } else { // $arrEvents[$arrEvent['id'].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } // Recurring events if ($arrEvent['recurring']) { $count = 0; $arrRepeat = deserialize($arrEvent['repeatEach']); $blnSummer = date('I', $arrEvent['startTime']); $intEnd = time() + 60 * 60 * 24 * 178; // max. 1/2 Year while ($arrEvent['endTime'] < $intEnd) { if ($arrEvent['recurrences'] > 0 && $count++ >= $arrEvent['recurrences']) { break; } $arg = $arrRepeat['value']; $unit = $arrRepeat['unit']; if ($arg == 1) { $unit = substr($unit, 0, -1); } $strtotime = '+ ' . $arg . ' ' . $unit; $arrEvent['startTime'] = strtotime($strtotime, $arrEvent['startTime']); $arrEvent['endTime'] = strtotime($strtotime, $arrEvent['endTime']); if ($arrEvent['startTime'] >= $intStart || $arrEvent['endTime'] <= $intEnd) { $strTime = ''; $strTime .= date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['startTime']); if ($arrEvent['addTime']) { if ($span > 0) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']) . ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } elseif ($arrEvent['startTime'] == $arrEvent['endTime']) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']); } else { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } } if ($sqlLookupValField) { // $arrEvents[$arrEvent[$sqlLookupValField].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } else { // $arrEvents[$arrEvent['id'].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } } } } } // Sort events foreach ($arrEvents as $k => $arr) { if ($arrSortKeys[1]['order'] == 'DESC') { krsort($arrEvents[$k]); } else { ksort($arrEvents[$k]); } } if ($arrSortKeys[0]['order'] == 'DESC') { krsort($arrEvents); } else { ksort($arrEvents); } // Set options foreach ($arrEvents as $k1 => $arr1) { foreach ($arr1 as $k2 => $arr2) { foreach ($arr2 as $k3 => $arr3) { $arrOptions[] = $arr3; } } } if (count($arrOptions) == 1) { $blnDoNotAddEmptyOption = true; } // Include blank option if ($strType == 'efgLookupSelect') { if (!$blnDoNotAddEmptyOption) { array_unshift($arrOptions, array('value' => '', 'label' => '-')); } } } return $arrOptions; } else { $sqlLookup = "SELECT " . $sqlLookupIdField . (!empty($sqlLookupField) ? ', ' : '') . $sqlLookupField . (!empty($sqlLookupValField) ? ', ' : '') . $sqlLookupValField . " FROM " . $sqlLookupTable . $sqlLookupWhere . (!empty($sqlLookupOrder) ? " ORDER BY " . $sqlLookupOrder : ""); //Custom sql lookups for the beachcup website if ($sqlLookupOrder == "custom_sql_registration_de") { $user = !empty($this->replaceInsertTags("{{user::id}}")) ? $this->replaceInsertTags("{{user::id}}") : 0; $sqlLookup = "SELECT\n map.team_id AS id,\n CONCAT(player_1.name, ' und ', player_2.name) AS name\n FROM tl_beachcup_member_team AS map\n JOIN tl_member AS member ON member.id = map.member_id\n JOIN tl_beachcup_team AS team ON team.id = map.team_id\n JOIN (SELECT\n player.id,\n concat(player.name, ' ', player.surname) AS name\n FROM tl_beachcup_player AS player) AS player_1 ON player_1.id = team.player_1\n JOIN (SELECT\n player.id,\n concat(player.name, ' ', player.surname) AS name\n FROM tl_beachcup_player AS player) AS player_2 ON player_2.id = team.player_2\n WHERE member.id = {$user}\n GROUP BY map.id"; } else { if ($sqlLookupOrder == "custom_sql_registration_it") { $user = !empty($this->replaceInsertTags("{{user::id}}")) ? $this->replaceInsertTags("{{user::id}}") : 0; $sqlLookup = "SELECT\n map.team_id AS id,\n CONCAT(player_1.name, ' e ', player_2.name) AS name\n FROM tl_beachcup_member_team AS map\n JOIN tl_member AS member ON member.id = map.member_id\n JOIN tl_beachcup_team AS team ON team.id = map.team_id\n JOIN (SELECT\n player.id,\n concat(player.name, ' ', player.surname) AS name\n FROM tl_beachcup_player AS player) AS player_1 ON player_1.id = team.player_1\n JOIN (SELECT\n player.id,\n concat(player.name, ' ', player.surname) AS name\n FROM tl_beachcup_player AS player) AS player_2 ON player_2.id = team.player_2\n WHERE member.id = {$user}\n GROUP BY map.id"; } else { if ($sqlLookupOrder == "custom_sql_team") { $user = !empty($this->replaceInsertTags("{{user::id}}")) ? $this->replaceInsertTags("{{user::id}}") : 0; $sqlLookup = "SELECT DISTINCT tl_beachcup_player.id, CONCAT(tl_beachcup_player.name, ' ', tl_beachcup_player.surname) as `player_name`\n\t\t\t\t\t\t\t\t\t\tFROM tl_beachcup_member_player\n\t\t\t\t\t\t\t\t\t\tJOIN tl_beachcup_player ON tl_beachcup_member_player.player_id = tl_beachcup_player.id\n\t\t\t\t\t\t\t\t\t\tJOIN tl_member ON tl_beachcup_member_player.member_id = tl_member.id\n\t\t\t\t\t\t\t\t\t\tWHERE tl_beachcup_member_player.member_id = {$user}\n\t\t\t\t\t\t\t\t\t\tORDER BY `player_name`"; } else { if ($sqlLookupOrder == "custom_sql_registration_tournament_de") { $sqlLookup = "SELECT tournament.id AS id, CONCAT(stage.name_de, ' - ', tournament.name_de) AS name_de\n\t\t\t\t\t\t\t\t\t\tFROM tl_beachcup_tournament AS tournament\n\t\t\t\t\t\t\t\t\t\tJOIN tl_beachcup_stage AS stage ON stage.id = tournament.stage_id\n\t\t\t\t\t\t\t\t\t\tWHERE stage.is_enabled = 1;"; } else { if ($sqlLookupOrder == "custom_sql_registration_tournament_it") { $sqlLookup = "SELECT tournament.id AS id, CONCAT(stage.name_it, ' - ', tournament.name_it) AS name_it\n\t\t\t\t\t\t\t\t\t\tFROM tl_beachcup_tournament AS tournament\n\t\t\t\t\t\t\t\t\t\tJOIN tl_beachcup_stage AS stage ON stage.id = tournament.stage_id\n\t\t\t\t\t\t\t\t\t\tWHERE stage.is_enabled = 1;"; } } } } } if (!empty($sqlLookupTable)) { $objOptions = \Database::getInstance()->prepare($sqlLookup)->execute(); } if ($objOptions->numRows) { $arrOptions = array(); while ($arrOpt = $objOptions->fetchAssoc()) { if ($sqlLookupValField) { $arrOptions[$arrOpt[$sqlLookupValField]] = $arrOpt[$arrLookupField[1]]; } else { $arrOptions[$arrOpt['id']] = $arrOpt[$arrLookupField[1]]; } } } } $arrTempOptions = array(); // Include blank option if ($strType == 'efgLookupSelect') { if (!$blnDoNotAddEmptyOption) { $arrTempOptions[] = array('value' => '', 'label' => '-'); } } foreach ($arrOptions as $sK => $sV) { $strKey = (string) $sK; $arrTempOptions[] = array('value' => $strKey, 'label' => $sV); } $arrOptions = $arrTempOptions; break; case 'countryselect': // countryselectmenu $arrCountries = $this->getCountries(); $arrTempOptions = array(); foreach ($arrCountries as $strKey => $strVal) { $arrTempOptions[] = array('value' => $strKey, 'label' => $strVal); } $arrOptions = $arrTempOptions; break; case 'condition': // conditionalforms $arrOptions = array(array('value' => '1', 'label' => $arrField['label'])); break; case 'cm_alternative': // cm_alternativeforms $arrTempOptions = array(); if (!is_array($arrField['options'])) { $arrField['options'] = array($arrField['cm_alternativelabel'], $arrField['cm_alternativelabelelse']); } foreach ($arrField['options'] as $strKey => $strVal) { $arrTempOptions[] = array('value' => $strKey, 'label' => $strVal); } $arrOptions = $arrTempOptions; break; default: if ($arrField['options']) { $arrOptions = deserialize($arrField['options']); } else { $strClass = $GLOBALS['TL_FFL'][$arrField['type']]; if (class_exists($strClass)) { $objWidget = new $strClass($arrField); if ($objWidget instanceof \FormSelectMenu || $objWidget instanceof \FormCheckbox || $objWidget instanceof \FormRadioButton) { // HOOK: load form field callback if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $arrField['pid'], array()); } } $arrOptions = $objWidget->options; } } } break; } // Decode 'special chars', encoded by \Input::encodeSpecialChars (for example labels of checkbox options containing '(') $arrOptions = $this->decodeSpecialChars($arrOptions); return $arrOptions; }
protected function compile() { global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; if ($this->objEvent === null) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->event = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('events')) . '</p>'; // remove page from search index if ($this->cal_showInModal) { \HeimrichHannot\SearchPlus\Search::removePageFromIndex(\Environment::get('request')); } return; } // Overwrite the page title (see #2853 and #4955) if ($this->objEvent->title != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($this->objEvent->title)); } // Overwrite the page description if ($this->objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($this->objEvent->teaser); } $strUrl = ''; $objCalendar = \CalendarModel::findByPk($this->objEvent->pid); // Get the current "jumpTo" page if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) { $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s'); } $intStartTime = $this->objEvent->startTime; $intEndTime = $this->objEvent->endTime; $span = \Calendar::calculateSpan($intStartTime, $intEndTime); // Do not show dates in the past if the event is recurring (see #923) if ($this->objEvent->recurring) { $arrRange = deserialize($this->objEvent->repeatEach); while ($intStartTime < time() && $intEndTime < $this->objEvent->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } $objEvent = (object) $this->getEventDetails($this->objEvent, $intStartTime, $intEndTime, $strUrl, $intStartTime, $this->objEvent->pid); $arrSubEvents = array(); if (!$this->cal_ungroupSubevents) { $objChildEvents = CalendarPlusEventsModel::findPublishedSubEvents($objEvent->id); if ($objChildEvents !== null) { while ($objChildEvents->next()) { $arrSubEvents[$objChildEvents->id] = $this->addSingleEvent($objChildEvents, $intStartTime); } } } if ($objPage->outputFormat == 'xhtml') { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; } else { $strTimeStart = '<time datetime="' . date('Y-m-d\\TH:i:sP', $intStartTime) . '">'; $strTimeEnd = '<time datetime="' . date('Y-m-d\\TH:i:sP', $intEndTime) . '">'; $strTimeClose = '</time>'; } // Get date if ($span > 0) { $date = $strTimeStart . \Date::parse($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intEndTime) . $strTimeClose; } elseif ($intStartTime == $intEndTime) { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . ')' : '') . $strTimeClose; } else { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($objPage->timeFormat, $intEndTime) . ')' : '') . $strTimeClose; } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvent->repeatEnd)); } } // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $objEvent->size = $this->imgSize; } } $imgSize = false; // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) { $imgSize = $this->imgSize; } } $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData((array) $objEvent); $objTemplate->nav = $this->generateArrowNavigation($objEvent, $strUrl); if ($this->registration !== null) { $objTemplate->registration = $this->registration; $objTemplate->module = $this; // falback } if (is_array($arrSubEvents) && !empty($arrSubEvents)) { $strSubEvents = ''; foreach ($arrSubEvents as $subID => $arrSubEvent) { $objSubEventTemplate = new \FrontendTemplate($this->cal_templateSubevent); $objSubEventTemplate->setData($arrSubEvent); $this->addEventDetailsToTemplate($objSubEventTemplate, $arrSubEvent, '', '', $imgSize); $strSubEvents .= $objSubEventTemplate->parse() . "\n"; } $objTemplate->subEvents = $strSubEvents; } if ($this->addShare && in_array('share', $this->Config->getActiveModules())) { $objShare = new \HeimrichHannot\Share\Share($this->objModel, $objEvent); $objTemplate->share = $objShare->generate(); } $objTemplate->addImage = false; // Add an image if ($objEvent->addImage && $objEvent->singleSRC != '') { $objModel = \FilesModel::findByUuid($objEvent->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objEvent->singleSRC)) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrEvent = $objEvent->row(); $arrEvent['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $arrEvent); } } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $this->objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } $this->Template->allowComments = $objCalendar->allowComments; // Comments are not allowed if (!$objCalendar->allowComments) { return; } // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCalendar->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCalendar->notify != 'notify_admin') { if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCalendar->perPage; $objConfig->order = $objCalendar->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCalendar->requireLogin; $objConfig->disableCaptcha = $objCalendar->disableCaptcha; $objConfig->bbcode = $objCalendar->bbcode; $objConfig->moderate = $objCalendar->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies); }
protected function unregisterUser($objEvent) { \Database::getInstance()->prepare("DELETE FROM tl_event_registrations WHERE pid=? AND userId=?")->execute($objEvent->id, $this->User->id); $objMailerText = \Database::getInstance()->prepare("SELECT ser_cancel_subject AS subject, ser_cancel_text AS text, ser_cancel_html AS html FROM tl_calendar WHERE id=?")->execute($objEvent->pid); // Send notification $objEmail = new \Email(); $strFrom = $GLOBALS['TL_CONFIG']['adminEmail']; $strNotify = $objEvent->ser_email != "" ? $objEvent->ser_email : $GLOBALS['TL_CONFIG']['adminEmail']; $span = \Calendar::calculateSpan($objEvent->startTime, $objEvent->endTime); // Get date if ($span > 0) { $objEvent->date = \Date::parse($GLOBALS['TL_CONFIG'][$objEvent->addTime ? 'datimFormat' : 'dateFormat'], $objEvent->startTime) . ' - ' . \Date::parse($GLOBALS['TL_CONFIG'][$objEvent->addTime ? 'datimFormat' : 'dateFormat'], $objEvent->endTime); } elseif ($objEvent->startTime == $objEvent->endTime) { $objEvent->date = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objEvent->startTime) . ($objEvent->addTime ? ' (' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEvent->startTime) . ')' : ''); } else { $objEvent->date = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objEvent->startTime) . ($objEvent->addTime ? ' (' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEvent->startTime) . ' - ' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEvent->endTime) . ')' : ''); } $notifyText = $this->replaceInserts($objEvent, $GLOBALS['TL_LANG']['MSC']['ser_unregister_mail']); $notifySubject = $GLOBALS['TL_LANG']['MSC']['ser_unregister_subject']; $messageText = $this->replaceInserts($objEvent, html_entity_decode($objMailerText->text)); $messageHTML = $this->replaceInserts($objEvent, html_entity_decode($objMailerText->html)); $objEmail->from = $strFrom; $objEmail->subject = $this->replaceInserts($objEvent, html_entity_decode($objMailerText->subject)); $objEmail->text = $messageText; $objEmail->html = $messageHTML; $objEmail->sendTo($this->User->email); $objEmail->subject = $this->replaceInserts($objEvent, html_entity_decode($notifySubject)); $objEmail->text = $notifyText; $objEmail->html = nl2br($notifyText); $objEmail->sendTo($strNotify); $_SESSION['TL_SER_UNREGISTERED'] = true; $this->reload(); }
/** * Add an event to the array of active events * @param Database_Result * @param integer * @param integer * @param string * @param integer * @param integer * @param integer */ protected function addEvent(Database_Result $objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intLimit, $intCalendar) { global $objPage; $intDate = $intStart; $intKey = date('Ymd', $intStart); $span = Calendar::calculateSpan($intStart, $intEnd); $strDate = $this->parseDate($objPage->dateFormat, $intStart); $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)]; $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1]; if ($span > 0) { $strDate = $this->parseDate($objPage->dateFormat, $intStart) . ' - ' . $this->parseDate($objPage->dateFormat, $intEnd); $strDay = ''; } $strTime = ''; if ($objEvents->addTime) { if ($span > 0) { $strDate = $this->parseDate($objPage->datimFormat, $intStart) . ' - ' . $this->parseDate($objPage->datimFormat, $intEnd); } elseif ($intStart == $intEnd) { $strTime = $this->parseDate($objPage->timeFormat, $intStart); } else { $strTime = $this->parseDate($objPage->timeFormat, $intStart) . ' - ' . $this->parseDate($objPage->timeFormat, $intEnd); } } // Store raw data $arrEvent = $objEvents->row(); // Overwrite some settings $arrEvent['time'] = $strTime; $arrEvent['date'] = $strDate; $arrEvent['day'] = $strDay; $arrEvent['month'] = $strMonth; $arrEvent['parent'] = $intCalendar; $arrEvent['link'] = $objEvents->title; $arrEvent['target'] = ''; $arrEvent['title'] = specialchars($objEvents->title, true); $arrEvent['href'] = $this->generateEventUrl($objEvents, $strUrl); $arrEvent['class'] = $objEvents->cssClass != '' ? ' ' . $objEvents->cssClass : ''; $arrEvent['details'] = $this->String->encodeEmail($objEvents->details); $arrEvent['start'] = $intStart; $arrEvent['end'] = $intEnd; // Override the link target if ($objEvents->source == 'external' && $objEvents->target) { $arrEvent['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"'; } // Clean the RTE output if ($arrEvent['teaser'] != '') { if ($objPage->outputFormat == 'xhtml') { $arrEvent['teaser'] = $this->String->toXhtml($arrEvent['teaser']); } else { $arrEvent['teaser'] = $this->String->toHtml5($arrEvent['teaser']); } } // Display the "read more" button for external/article links if ($objEvents->source != 'default' && $objEvents->details == '') { $arrEvent['details'] = true; } else { if ($objPage->outputFormat == 'xhtml') { $arrEvent['details'] = $this->String->toXhtml($arrEvent['details']); } else { $arrEvent['details'] = $this->String->toHtml5($arrEvent['details']); } } // Get todays start and end timestamp if ($this->intTodayBegin === null) { $this->intTodayBegin = strtotime('00:00:00'); } if ($this->intTodayEnd === null) { $this->intTodayEnd = strtotime('23:59:59'); } // Mark past and upcoming events (see #3692) if ($intEnd < $this->intTodayBegin) { $arrEvent['class'] .= ' bygone'; } elseif ($intStart > $this->intTodayEnd) { $arrEvent['class'] .= ' upcoming'; } else { $arrEvent['class'] .= ' current'; } $this->arrEvents[$intKey][$intStart][] = $arrEvent; // Multi-day event for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) { // Only show first occurrence if ($this->cal_noSpan && $intDate >= $intBegin) { break; } $intDate = strtotime('+ 1 day', $intDate); $intNextKey = date('Ymd', $intDate); $this->arrEvents[$intNextKey][$intDate][] = $arrEvent; } }
/** * Generate the module */ protected function compile() { global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; // Get the current event $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar); if ($objEvent === null) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->event = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('events')) . '</p>'; return; } // Overwrite the page title if ($objEvent->title != '') { $objPage->pageTitle = strip_insert_tags($objEvent->title); } // Overwrite the page description if ($objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($objEvent->teaser); } $span = \Calendar::calculateSpan($objEvent->startTime, $objEvent->endTime); if ($objPage->outputFormat == 'xhtml') { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; } else { $strTimeStart = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->startTime) . '">'; $strTimeEnd = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->endTime) . '">'; $strTimeClose = '</time>'; } // Get date if ($span > 0) { $date = $strTimeStart . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->endTime) . $strTimeClose; } elseif ($objEvent->startTime == $objEvent->endTime) { $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . ')' : '') . $strTimeClose; } else { $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objPage->timeFormat, $objEvent->endTime) . ')' : '') . $strTimeClose; } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], $this->parseDate($objPage->dateFormat, $objEvent->repeatEnd)); } } // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0) { $objEvent->size = $this->imgSize; } } $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($objEvent->row()); $objTemplate->date = $date; $objTemplate->start = $objEvent->startTime; $objTemplate->end = $objEvent->endTime; $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : ''; $objTemplate->recurring = $recurring; $objTemplate->until = $until; // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objEvent->details = \String::toXhtml($objEvent->details); } else { $objEvent->details = \String::toHtml5($objEvent->details); } $objTemplate->details = \String::encodeEmail($objEvent->details); $objTemplate->addImage = false; // Add an image if ($objEvent->addImage && $objEvent->singleSRC != '') { if (!is_numeric($objEvent->singleSRC)) { $objTemplate->details = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } else { $objModel = \FilesModel::findByPk($objEvent->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { $objEvent->singleSRC = $objModel->path; $this->addImageToTemplate($objTemplate, $objEvent->row()); } } } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', $this->Config->getActiveModules())) { $this->Template->allowComments = false; return; } $objCalendar = $objEvent->getRelated('pid'); $this->Template->allowComments = $objCalendar->allowComments; // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCalendar->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCalendar->notify != 'notify_admin') { if (($objAuthor = $objEvent->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCalendar->perPage; $objConfig->order = $objCalendar->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCalendar->requireLogin; $objConfig->disableCaptcha = $objCalendar->disableCaptcha; $objConfig->bbcode = $objCalendar->bbcode; $objConfig->moderate = $objCalendar->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies); }
/** * Render a calendar event. * * @param GetCalendarEventEvent $event The event. * * @param string $eventName The event name. * * @param EventDispatcherInterface $eventDispatcher The event dispatcher. * * @return void * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function handleEvent(GetCalendarEventEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { if ($event->getCalendarEventHtml()) { return; } $calendarCollection = \CalendarModel::findAll(); if (!$calendarCollection) { return; } $calendarIds = $calendarCollection->fetchEach('id'); $eventModel = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($event->getCalendarEventId(), $calendarIds); if (!$eventModel) { return; } $calendarModel = $eventModel->getRelated('pid'); $objPage = \PageModel::findWithDetails($calendarModel->jumpTo); if ($event->getDateTime()) { $selectedStartDateTime = clone $event->getDateTime(); $selectedStartDateTime->setTime(date('H', $eventModel->startTime), date('i', $eventModel->startTime), date('s', $eventModel->startTime)); $secondsBetweenStartAndEndTime = $eventModel->endTime - $eventModel->startTime; $intStartTime = $selectedStartDateTime->getTimestamp(); $intEndTime = $intStartTime + $secondsBetweenStartAndEndTime; } else { $intStartTime = $eventModel->startTime; $intEndTime = $eventModel->endTime; } $span = \Calendar::calculateSpan($intStartTime, $intEndTime); // Do not show dates in the past if the event is recurring (see #923). if ($eventModel->recurring) { $arrRange = deserialize($eventModel->repeatEach); while ($intStartTime < time() && $intEndTime < $eventModel->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } if ($objPage->outputFormat == 'xhtml') { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; } else { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; // @codingStandardsIgnoreStart /* TODO $this->date and $this->time is used in the <a> title attribute and cannot contain HTML! $strTimeStart = '<time datetime="' . date('Y-m-d\TH:i:sP', $intStartTime) . '">'; $strTimeEnd = '<time datetime="' . date('Y-m-d\TH:i:sP', $intEndTime) . '">'; $strTimeClose = '</time>'; */ // @codingStandardsIgnoreEnd } // Get date. if ($span > 0) { $date = $strTimeStart . \Date::parse($eventModel->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($eventModel->addTime ? $objPage->datimFormat : $objPage->dateFormat, $intEndTime) . $strTimeClose; } elseif ($intStartTime == $intEndTime) { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($eventModel->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . ')' : '') . $strTimeClose; } else { $date = $strTimeStart . \Date::parse($objPage->dateFormat, $intStartTime) . ($eventModel->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStartTime) . $strTimeClose . ' - ' . $strTimeEnd . \Date::parse($objPage->timeFormat, $intEndTime) . ')' : '') . $strTimeClose; } $until = ''; $recurring = ''; // Recurring event. if ($eventModel->recurring) { $arrRange = deserialize($eventModel->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($eventModel->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $eventModel->repeatEnd)); } } // Override the default image size. // This is always false. if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0) { $eventModel->size = $this->imgSize; } } $objTemplate = new \FrontendTemplate($event->getTemplate()); $objTemplate->setData($eventModel->row()); $objTemplate->date = $date; $objTemplate->start = $intStartTime; $objTemplate->end = $intEndTime; $objTemplate->class = $eventModel->cssClass != '' ? ' ' . $eventModel->cssClass : ''; $objTemplate->recurring = $recurring; $objTemplate->until = $until; $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location']; $objTemplate->details = ''; $objElement = \ContentModel::findPublishedByPidAndTable($eventModel->id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $getContentElementEvent = new GetContentElementEvent($objElement->id); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_CONTENT_ELEMENT, $getContentElementEvent); $objTemplate->details .= $getContentElementEvent->getContentElementHtml(); } } $objTemplate->addImage = false; // Add an image. if ($eventModel->addImage && $eventModel->singleSRC != '') { $objModel = \FilesModel::findByUuid($eventModel->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($eventModel->singleSRC)) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303). $arrEvent = $eventModel->row(); $arrEvent['singleSRC'] = $objModel->path; $addImageToTemplateEvent = new AddImageToTemplateEvent($arrEvent, $objTemplate); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_ADD_IMAGE_TO_TEMPLATE, $addImageToTemplateEvent); } } $objTemplate->enclosure = array(); // Add enclosures. if ($eventModel->addEnclosure) { $addEnclosureToTemplateEvent = new AddEnclosureToTemplateEvent($eventModel->row(), $objTemplate); $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_ADD_ENCLOSURE_TO_TEMPLATE, $addEnclosureToTemplateEvent); } $calendarEvent = $objTemplate->parse(); $event->setCalendarEventHtml($calendarEvent); }
/** * Get all events of a certain period * @param array * @param integer * @param integer * @return array */ protected function getAllEventsExt($arrHolidays, $arrCalendars, $intStart, $intEnd, $showRecurrences = true) { if (!is_array($arrCalendars)) { return array(); } $this->arrEvents = array(); foreach ($arrCalendars as $id) { $strUrl = $this->strUrl; $objCalendar = \CalendarModel::findByPk($id); // Get the current "jumpTo" page if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) { $strUrl = $this->generateFrontendUrl($objTarget->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s'); } // Get the events of the current period $objEvents = \CalendarEventsModelExt::findCurrentByPid($id, $intStart, $intEnd); if ($objEvents === null) { continue; } while ($objEvents->next()) { $eventNumber = 1; $eventRecurrences = (int) $objEvents->recurrences + 1; if ($objEvents->recurring || $objEvents->recurringExt) { $objEvents->pos_idx = (int) $eventNumber; if ($objEvents->recurrences == 0) { $objEvents->pos_cnt = 0; } else { $objEvents->pos_cnt = (int) $eventRecurrences; } } // Check if we have to store the event if it's on weekend $weekday = (int) date('N', $objEvents->startTime); $store = true; if ($objEvents->hideOnWeekend) { if ($weekday == 0 || $weekday == 6 || $weekday == 7) { $store = false; } } if ($store === true) { $eventUrl = $strUrl . "?day=" . Date("Ymd", $objEvents->startTime) . "&times=" . $objEvents->startTime . "," . $objEvents->endTime; $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $eventUrl, $intStart, $intEnd, $id); // $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $strUrl, $intStart, $intEnd, $id); } /* * Recurring events and Ext. Recurring events * * Here we manage the recurrences. We take the repeat option and set the new values * if showRecurrences is false we do not need to go thru all recurring events... */ if (($objEvents->recurring && $objEvents->repeatEach || $objEvents->recurringExt && $objEvents->repeatEachExt) && $showRecurrences) { // list of months we need $arrMonth = array(1 => 'january', 2 => 'february', 3 => 'march', 4 => 'april', 5 => 'may', 6 => 'jun', 7 => 'july', 8 => 'august', 9 => 'september', 10 => 'october', 11 => 'november', 12 => 'december'); $count = 0; if ($objEvents->recurring) { $arrRepeat = deserialize($objEvents->repeatEach); } else { $arrRepeat = deserialize($objEvents->repeatEachExt); } // start and end time of the event $eventStartTime = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objEvents->startTime); $eventEndTime = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objEvents->endTime); // now we have to take care about the exception dates to skip if ($objEvents->useExceptions) { $skipInfos = deserialize($objEvents->exceptionList); } // time of the next event $nextTime = $objEvents->endTime; while ($nextTime < $intEnd) { $eventNumber++; $objEvents->pos_idx = (int) $eventNumber; if ($objEvents->recurrences == 0) { $objEvents->pos_cnt = 0; } else { $objEvents->pos_cnt = (int) $eventRecurrences; } if ($objEvents->recurrences > 0 && $count++ >= $objEvents->recurrences) { break; } $arg = $arrRepeat['value']; $unit = $arrRepeat['unit']; if ($objEvents->recurring) { // this is the contao default $strtotime = '+ ' . $arg . ' ' . $unit; $objEvents->startTime = strtotime($strtotime, $objEvents->startTime); $objEvents->endTime = strtotime($strtotime, $objEvents->endTime); } else { // extended version. $intyear = date('Y', $objEvents->startTime); $intmonth = date('n', $objEvents->startTime) + 1; $year = $intmonth == 13 ? $intyear + 1 : $intyear; $month = $intmonth == 13 ? 1 : $intmonth; $strtotime = $arg . ' ' . $unit . ' of ' . $arrMonth[$month] . ' ' . $year; $objEvents->startTime = strtotime($strtotime . ' ' . $eventStartTime, $objEvents->startTime); $objEvents->endTime = strtotime($strtotime . ' ' . $eventEndTime, $objEvents->endTime); } $nextTime = $objEvents->endTime; // check if there is any exception if (is_array($skipInfos)) { // reset cssClass $objEvents->cssClass = str_replace("exception", "", $objEvents->cssClass); // date to search for $searchDate = mktime(0, 0, 0, date('m', $objEvents->startTime), date("d", $objEvents->startTime), date("Y", $objEvents->startTime)); // store old date values for later reset $oldDate = array(); if (is_array($skipInfos[$searchDate])) { // $r = array_search($searchDate, $exception, true); $r = $searchDate; $action = $skipInfos[$r]['action']; if ($action == "hide") { //continue the while since we don't want to show the event continue; } else { if ($action == "mark") { //just add the css class to the event $objEvents->cssClass .= "exception"; } else { if ($action == "move") { //just add the css class to the event $objEvents->cssClass .= "moved"; // keep old date. we have to reset it later for the next recurrence $oldDate['startTime'] = $objEvents->startTime; $oldDate['endTime'] = $objEvents->endTime; // also keep the old values in the row $objEvents->oldDate = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objEvents->startTime); // value to add to the old date $newDate = $skipInfos[$r]['new_exception']; // store the reason for the move $objEvents->moveReason = $skipInfos[$r]['reason']; // check if we have to change the time of the event if ($skipInfos[$r]['new_start']) { $objEvents->oldStartTime = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objEvents->startTime); $objEvents->oldEndTime = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objEvents->endTime); // get the date of the event and add the new time to the new date $newStart = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objEvents->startTime) . ' ' . $skipInfos[$r]['new_start']; $newEnd = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objEvents->endTime) . ' ' . $skipInfos[$r]['new_end']; //set the new values $objEvents->startTime = strtotime($newDate, strtotime($newStart)); $objEvents->endTime = strtotime($newDate, strtotime($newEnd)); } else { $objEvents->startTime = strtotime($newDate, $objEvents->startTime); $objEvents->endTime = strtotime($newDate, $objEvents->endTime); } } } } } } // Skip events outside the scope if ($objEvents->endTime < $intStart || $objEvents->startTime > $intEnd) { // in case of a move we have to reset the original date if ($oldDate) { $objEvents->startTime = $oldDate['startTime']; $objEvents->endTime = $oldDate['endTime']; } // reset this values... $objEvents->moveReason = NULL; $objEvents->oldDate = NULL; $objEvents->oldStartTime = NULL; $objEvents->oldEndTime = NULL; continue; } $objEvents->isRecurrence = true; $weekday = date('N', $objEvents->startTime); $store = true; if ($objEvents->hideOnWeekend) { if ($weekday == 0 || $weekday == 6 || $weekday == 7) { $store = false; } } if ($store === true) { $eventUrl = $strUrl . "?day=" . Date("Ymd", $objEvents->startTime) . "&times=" . $objEvents->startTime . "," . $objEvents->endTime; $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $eventUrl, $intStart, $intEnd, $id); } // reset this values... $objEvents->moveReason = NULL; $objEvents->oldDate = NULL; $objEvents->oldStartTime = NULL; $objEvents->oldEndTime = NULL; // in case of a move we have to reset the original date if ($oldDate) { $objEvents->startTime = $oldDate['startTime']; $objEvents->endTime = $oldDate['endTime']; } } } } } // run thru all holiday calendars foreach ($arrHolidays as $id) { $strUrl = $this->strUrl; $objAE = $this->Database->prepare("SELECT allowEvents FROM tl_calendar WHERE id = ?")->limit(1)->execute($id); $allowEvents = $objAE->allowEvents == 1 ? true : false; $strUrl = $this->strUrl; $objCalendar = \CalendarModel::findByPk($id); // Get the current "jumpTo" page if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) { $strUrl = $this->generateFrontendUrl($objTarget->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s'); } // Get the events of the current period $objEvents = \CalendarEventsModel::findCurrentByPid($id, $intStart, $intEnd); if ($objEvents === null) { continue; } while ($objEvents->next()) { // at last we add the free multi-day / holiday or what ever kind of event $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $strUrl, $intStart, $intEnd, $id); /** * Multi-day event * first we have to find all free days */ $span = Calendar::calculateSpan($objEvents->startTime, $objEvents->endTime); // unset the first day of the multi-day event $intDate = $objEvents->startTime; $key = date('Ymd', $intDate); // check all events if the calendar allows events on free days if ($this->arrEvents[$key]) { foreach ($this->arrEvents[$key] as $k1 => $events) { foreach ($events as $k2 => $event) { // do not remove events from any holiday calendar $isHolidayEvent = array_search($event['pid'], $arrHolidays); // unset the event if showOnFreeDay is not set if ($allowEvents === false) { if ($isHolidayEvent === false) { unset($this->arrEvents[$key][$k1][$k2]); } } else { if ($isHolidayEvent === false && !$event['showOnFreeDay'] == 1) { unset($this->arrEvents[$key][$k1][$k2]); } } } } } // unset all the other days of the multi-day event for ($i = 1; $i <= $span && $intDate <= $intEnd; $i++) { $intDate = strtotime('+ 1 day', $intDate); $key = date('Ymd', $intDate); // check all events if the calendar allows events on free days if ($this->arrEvents[$key]) { foreach ($this->arrEvents[$key] as $k1 => $events) { foreach ($events as $k2 => $event) { // do not remove events from any holiday calendar $isHolidayEvent = array_search($event['pid'], $arrHolidays); // unset the event if showOnFreeDay is not set if ($allowEvents === false) { if ($isHolidayEvent === false) { unset($this->arrEvents[$key][$k1][$k2]); } } else { if ($isHolidayEvent === false && !$event['showOnFreeDay'] == 1) { unset($this->arrEvents[$key][$k1][$k2]); } } } } } } } } // Sort the array foreach (array_keys($this->arrEvents) as $key) { ksort($this->arrEvents[$key]); } // HOOK: modify the result set if (isset($GLOBALS['TL_HOOKS']['getAllEvents']) && is_array($GLOBALS['TL_HOOKS']['getAllEvents'])) { foreach ($GLOBALS['TL_HOOKS']['getAllEvents'] as $callback) { $this->import($callback[0]); $this->arrEvents = $this->{$callback}[0]->{$callback}[1]($this->arrEvents, $arrCalendars, $intStart, $intEnd, $this); } } return $this->arrEvents; }
/** * Add an event to the array of active events * * @param \CalendarEventsModel $objEvents * @param integer $intStart * @param integer $intEnd * @param string $strUrl * @param integer $intBegin * @param integer $intLimit * @param integer $intCalendar */ protected function addEvent($objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intLimit, $intCalendar) { /** @var \PageModel $objPage */ global $objPage; $span = \Calendar::calculateSpan($intStart, $intEnd); // Adjust the start time of a multi-day event (see #6802) if ($this->cal_noSpan && $span > 0 && $intStart < $intBegin && $intBegin < $intEnd) { $intStart = $intBegin; } $intDate = $intStart; $intKey = date('Ymd', $intStart); $strDate = \Date::parse($objPage->dateFormat, $intStart); $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)]; $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1]; if ($span > 0) { $strDate = \Date::parse($objPage->dateFormat, $intStart) . ' - ' . \Date::parse($objPage->dateFormat, $intEnd); $strDay = ''; } $strTime = ''; if ($objEvents->addTime) { if ($span > 0) { $strDate = \Date::parse($objPage->datimFormat, $intStart) . ' - ' . \Date::parse($objPage->datimFormat, $intEnd); } elseif ($intStart == $intEnd) { $strTime = \Date::parse($objPage->timeFormat, $intStart); } else { $strTime = \Date::parse($objPage->timeFormat, $intStart) . ' - ' . \Date::parse($objPage->timeFormat, $intEnd); } } // Store raw data $arrEvent = $objEvents->row(); // Overwrite some settings $arrEvent['time'] = $strTime; $arrEvent['date'] = $strDate; $arrEvent['day'] = $strDay; $arrEvent['month'] = $strMonth; $arrEvent['parent'] = $intCalendar; $arrEvent['calendar'] = $objEvents->getRelated('pid'); $arrEvent['link'] = $objEvents->title; $arrEvent['target'] = ''; $arrEvent['title'] = specialchars($objEvents->title, true); $arrEvent['href'] = $this->generateEventUrl($objEvents, $strUrl); $arrEvent['class'] = $objEvents->cssClass != '' ? ' ' . $objEvents->cssClass : ''; $arrEvent['begin'] = $intStart; $arrEvent['end'] = $intEnd; $arrEvent['details'] = ''; // Override the link target if ($objEvents->source == 'external' && $objEvents->target) { $arrEvent['target'] = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"'; } // Clean the RTE output if ($arrEvent['teaser'] != '') { if ($objPage->outputFormat == 'xhtml') { $arrEvent['teaser'] = \String::toXhtml($arrEvent['teaser']); } else { $arrEvent['teaser'] = \String::toHtml5($arrEvent['teaser']); } } // Display the "read more" button for external/article links if ($objEvents->source != 'default') { $arrEvent['details'] = true; } else { $id = $objEvents->id; $arrEvent['details'] = function () use($id) { $strDetails = ''; $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $strDetails .= $this->getContentElement($objElement->current()); } } return $strDetails; }; } // Get todays start and end timestamp if ($this->intTodayBegin === null) { $this->intTodayBegin = strtotime('00:00:00'); } if ($this->intTodayEnd === null) { $this->intTodayEnd = strtotime('23:59:59'); } // Mark past and upcoming events (see #3692) if ($intEnd < $this->intTodayBegin) { $arrEvent['class'] .= ' bygone'; } elseif ($intStart > $this->intTodayEnd) { $arrEvent['class'] .= ' upcoming'; } else { $arrEvent['class'] .= ' current'; } $this->arrEvents[$intKey][$intStart][] = $arrEvent; // Multi-day event for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) { // Only show first occurrence if ($this->cal_noSpan && $intDate >= $intBegin) { break; } $intDate = strtotime('+ 1 day', $intDate); $intNextKey = date('Ymd', $intDate); $this->arrEvents[$intNextKey][$intDate][] = $arrEvent; } }
/** * Add the type of input field * @param array * @return string */ public function listEvents($arrRow) { $span = Calendar::calculateSpan($arrRow['startTime'], $arrRow['endTime']); if ($span > 0) { $date = $this->parseDate($GLOBALS['TL_CONFIG'][$arrRow['addTime'] ? 'datimFormat' : 'dateFormat'], $arrRow['startTime']) . ' - ' . $this->parseDate($GLOBALS['TL_CONFIG'][$arrRow['addTime'] ? 'datimFormat' : 'dateFormat'], $arrRow['endTime']); } elseif ($arrRow['startTime'] == $arrRow['endTime']) { $date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrRow['startTime']) . ($arrRow['addTime'] ? ' ' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['startTime']) : ''); } else { $date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrRow['startTime']) . ($arrRow['addTime'] ? ' ' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['startTime']) . '-' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['endTime']) : ''); } return '<div class="tl_content_left">' . $arrRow['title'] . ' <span style="color:#b3b3b3;padding-left:3px">[' . $date . ']</span></div>'; }
/** * Return a form to choose a CSV file and import it * @param object * @return string */ public function exportRegisteredUsers(DataContainer $dc) { $strRedirectUrl = ampersand(str_replace('&key=serexport', '', $this->Environment->request)); if ($this->Input->get('key') != 'serexport') { $this->redirect($strRedirectUrl); } $pid = $this->Input->get('id'); $objUsers = $this->Database->prepare("SELECT * FROM tl_event_registrations WHERE pid=? AND ( userId!=0 OR (anonym=1 AND lastname != ''))")->execute($pid); if ($objUsers->numRows == 0) { $this->redirect($strRedirectUrl); } $fields = $GLOBALS['BE_MOD']['content']['calendar']['serexportfields']; $strUserfields = implode(',', $fields['user']); // get records $arrExport = array(); $objEventRow = $this->Database->prepare("SELECT *, (SELECT jumpTo FROM tl_calendar WHERE tl_calendar.id=tl_calendar_events.pid) AS jumpTo, (SELECT id FROM tl_page WHERE tl_page.id=jumpTo) AS pageId, (SELECT alias FROM tl_page WHERE tl_page.id=jumpTo) AS pageAlias FROM tl_calendar_events WHERE id=?")->execute($pid); $span = Calendar::calculateSpan($objEventRow->startTime, $objEventRow->endTime); // Get date if ($span > 0) { $objEventRow->date = \Date::parse($GLOBALS['TL_CONFIG'][$objEventRow->addTime ? 'datimFormat' : 'dateFormat'], $objEventRow->startTime) . ' - ' . \Date::parse($GLOBALS['TL_CONFIG'][$objEventRow->addTime ? 'datimFormat' : 'dateFormat'], $objEventRow->endTime); } elseif ($objEventRow->startTime == $objEventRow->endTime) { $objEventRow->date = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objEventRow->startTime) . ($objEventRow->addTime ? ' (' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEventRow->startTime) . ')' : ''); } else { $objEventRow->date = \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objEventRow->startTime) . ($objEventRow->addTime ? ' (' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEventRow->startTime) . ' - ' . \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $objEventRow->endTime) . ')' : ''); } $objEventRow->url = $this->generateEventUrl($objEventRow, $this->generateFrontendUrl(array('id' => $objEventRow->pageId, 'alias' => $objEventRow->pageAlias), 'events/%s')); $arrEvents = array(); foreach ($fields['event'] as $value) { $arrEvents[] = $objEventRow->{$value}; } while ($objUsers->next()) { if ($objUsers->anonym == 0) { $objUserRow = $this->Database->prepare("SELECT " . $strUserfields . " FROM tl_member WHERE id=?")->execute($objUsers->userId); $arrValues = $objUserRow->row(); } else { foreach ($fields['anuser'] as $v) { $arrValues[$v] = $objUsers->{$v}; } } $arrExport[] = array_merge($arrValues, $arrEvents); } $fieldlabels = array(); $this->loadLanguageFile('tl_member'); $this->loadLanguageFile('tl_calendar_events'); foreach ($fields['user'] as $value) { $fieldlabels[] = $GLOBALS['TL_LANG']['tl_member'][$value][0] != "" ? $GLOBALS['TL_LANG']['tl_member'][$value][0] : $value; } foreach ($fields['event'] as $value) { $fieldlabels[] = $GLOBALS['TL_LANG']['tl_calendar_events'][$value][0] != "" ? $GLOBALS['TL_LANG']['tl_calendar_events'][$value][0] : $value; } // start output $exportFile = 'simple_event_register_' . date("Ymd-Hi"); header('Content-Type: application/csv'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . $exportFile . '.csv"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); $output = ''; $output .= html_entity_decode(utf8_decode('"' . join('";"', $fieldlabels) . '"' . "\n")); foreach ($arrExport as $export) { $export['gender'] = $GLOBALS['TL_LANG']['MSC'][$export['gender']]; $output .= html_entity_decode(utf8_decode('"' . join('";"', $export) . '"' . "\n")); } echo $output; exit; }
/** * Prepare dca options array * @param array form field * @return array DCA options */ public function prepareDcaOptions($arrField = false) { if (!$arrField) { return false; } $strType = $arrField['type']; if ($arrField['inputType'] == 'efgLookupSelect') { $strType = 'efgLookupSelect'; } if ($arrField['inputType'] == 'efgLookupCheckbox') { $strType = 'efgLookupCheckbox'; } if ($arrField['inputType'] == 'efgLookupRadio') { $strType = 'efgLookupRadio'; } $arrOptions = array(); switch ($strType) { case 'efgLookupCheckbox': case 'efgLookupRadio': case 'efgLookupSelect': // get efgLookupOptions: array('lookup_field' => TABLENAME.FIELDNAME, 'lookup_val_field' => TABLENAME.FIELDNAME, 'lookup_where' => CONDITION, 'lookup_sort' => ORDER BY) $arrLookupOptions = deserialize($arrField['efgLookupOptions']); $strLookupField = $arrLookupOptions['lookup_field']; $strLookupValField = strlen($arrLookupOptions['lookup_val_field']) ? $arrLookupOptions['lookup_val_field'] : null; $strLookupWhere = $this->String->decodeEntities($arrLookupOptions['lookup_where']); if (strlen($strLookupWhere)) { $strLookupWhere = $this->replaceInsertTags($strLookupWhere); } $arrLookupField = explode('.', $strLookupField); $sqlLookupTable = $arrLookupField[0]; $sqlLookupField = $arrLookupField[1]; $sqlLookupValField = strlen($strLookupValField) ? substr($strLookupValField, strpos($strLookupValField, '.') + 1) : null; $sqlLookupIdField = 'id'; $sqlLookupWhere = strlen($strLookupWhere) ? " WHERE " . $strLookupWhere : ""; $sqlLookupOrder = $arrLookupField[0] . '.' . $arrLookupField[1]; if (strlen($arrLookupOptions['lookup_sort'])) { $sqlLookupOrder = $arrLookupOptions['lookup_sort']; } $arrOptions = array(); // handle lookup formdata if (substr($sqlLookupTable, 0, 3) == 'fd_') { // load formdata specific dca //if (!isset($GLOBALS['TL_DCA']['tl_formdata'])) { //$this->loadDataContainer($sqlLookupTable); //} $strFormKey = $this->arrFormsDcaKey[substr($sqlLookupTable, 3)]; $sqlLookupTable = 'tl_formdata f, tl_formdata_details fd'; $sqlLookupIdField = 'f.id'; $sqlLookupWhere = " WHERE (f.id=fd.pid AND f.form='" . $strFormKey . "' AND ff_name='" . $arrLookupField[1] . "')"; $arrDetailFields = array(); if (strlen($strLookupWhere) || strlen($arrLookupOptions['lookup_sort'])) { $objDetailFields = $this->Database->prepare("SELECT DISTINCT(ff.`name`) FROM tl_form f, tl_form_field ff WHERE f.storeFormdata=? AND (f.id=ff.pid) AND ff.`type` IN ('" . implode("','", $this->arrFFstorable) . "')")->execute('1'); if ($objDetailFields->numRows) { $arrDetailFields = $objDetailFields->fetchEach('name'); } } if (strlen($strLookupWhere)) { // special treatment for fields in tl_formdata_details $arrPattern = array(); $arrReplace = array(); foreach ($arrDetailFields as $strDetailField) { $arrPattern[] = '/\\b' . $strDetailField . '\\b/i'; $arrReplace[] = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $strDetailField . '\'))'; } $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : " WHERE ") . "(" . preg_replace($arrPattern, $arrReplace, $strLookupWhere) . ")"; } $sqlLookupField = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $arrLookupField[1] . '\') ) AS `' . $arrLookupField[1] . '`'; if (strlen($arrLookupOptions['lookup_sort'])) { // special treatment for fields in tl_formdata_details $arrPattern = array(); $arrReplace = array(); foreach ($arrDetailFields as $strDetailField) { $arrPattern[] = '/\\b' . $strDetailField . '\\b/i'; $arrReplace[] = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $strDetailField . '\'))'; } $sqlLookupOrder = preg_replace($arrPattern, $arrReplace, str_replace($arrLookupField[0] . '.', '', $arrLookupOptions['lookup_sort'])); } else { $sqlLookupOrder = '(SELECT value FROM tl_formdata_details fd WHERE (fd.pid=f.id AND ff_name=\'' . $arrLookupField[1] . '\'))'; } } // end lookup formdata // handle lookup calendar events if ($sqlLookupTable == 'tl_calendar_events') { //$sqlLookupOrder = 'startTime ASC'; $sqlLookupOrder = ''; // handle order (max. 2 fields) // .. default startTime ASC $arrSortKeys = array(array('field' => 'startTime', 'order' => 'ASC'), array('field' => 'startTime', 'order' => 'ASC')); if (strlen($arrLookupOptions['lookup_sort'])) { $sqlLookupOrder = $arrLookupOptions['lookup_sort']; $arrSortOn = trimsplit(',', $arrLookupOptions['lookup_sort']); $arrSortKeys = array(); foreach ($arrSortOn as $strSort) { $arrSortPar = explode(' ', $strSort); $arrSortKeys[] = array('field' => $arrSortPar[0], 'order' => strtoupper($arrSortPar[1]) == 'DESC' ? 'DESC' : 'ASC'); } } $sqlLookupWhere = strlen($strLookupWhere) ? "(" . $strLookupWhere . ")" : ""; $strReferer = $this->getReferer(); // if form is placed on an events detail page, automatically add restriction to event(s) if (strlen($this->Input->get('events'))) { if (is_numeric($this->Input->get('events'))) { $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.id=" . intval($this->Input->get('events')) . " "; } elseif (is_string($this->Input->get('events'))) { $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.alias='" . $this->Input->get('events') . "' "; } } // if linked from event reader page if (strpos($strReferer, 'event-reader/events/') || strpos($strReferer, '&events=')) { if (strpos($strReferer, 'events/')) { $strEvents = substr($strReferer, strrpos($strReferer, '/') + 1); } elseif (strpos($strReferer, '&events=')) { $strEvents = substr($strReferer, strpos($strReferer, '&events=') + strlen('&events=')); } if (is_numeric($strEvents)) { $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.id=" . intval($strEvents) . " "; } elseif (is_string($strEvents)) { $strEvents = str_replace('.html', '', $strEvents); $sqlLookupWhere .= (strlen($sqlLookupWhere) ? " AND " : "") . " tl_calendar_events.alias='" . $strEvents . "' "; } } $sqlLookup = "SELECT tl_calendar_events.* FROM tl_calendar_events, tl_calendar WHERE (tl_calendar.id=tl_calendar_events.pid) " . (strlen($sqlLookupWhere) ? " AND (" . $sqlLookupWhere . ")" : "") . (strlen($sqlLookupOrder) ? " ORDER BY " . $sqlLookupOrder : ""); $objEvents = $this->Database->prepare($sqlLookup)->execute(); $arrEvents = array(); if ($objEvents->numRows) { while ($arrEvent = $objEvents->fetchAssoc()) { $intDate = $arrEvent['startDate']; $intStart = time(); $intEnd = time() + 60 * 60 * 24 * 178; // max. 1/2 Jahr $span = Calendar::calculateSpan($arrEvent['startTime'], $arrEvent['endTime']); $strTime = ''; $strTime .= date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['startDate']); if ($arrEvent['addTime']) { if ($span > 0) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']) . ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } elseif ($arrEvent['startTime'] == $arrEvent['endTime']) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']); } else { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } } else { if ($span > 1) { $strTime .= ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']); } } if ($sqlLookupValField) { //$arrEvents[$arrEvent[$sqlLookupValField].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } else { //$arrEvents[$arrEvent['id'].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } // Recurring events if ($arrEvent['recurring']) { $count = 0; $arrRepeat = deserialize($arrEvent['repeatEach']); $blnSummer = date('I', $arrEvent['startTime']); $intEnd = time() + 60 * 60 * 24 * 178; // max. 1/2 Jahr while ($arrEvent['endTime'] < $intEnd) { if ($arrEvent['recurrences'] > 0 && $count++ >= $arrEvent['recurrences']) { break; } $arg = $arrRepeat['value']; $unit = $arrRepeat['unit']; if ($arg == 1) { $unit = substr($unit, 0, -1); } $strtotime = '+ ' . $arg . ' ' . $unit; $arrEvent['startTime'] = strtotime($strtotime, $arrEvent['startTime']); $arrEvent['endTime'] = strtotime($strtotime, $arrEvent['endTime']); if ($arrEvent['startTime'] >= $intStart || $arrEvent['endTime'] <= $intEnd) { $strTime = ''; $strTime .= date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['startTime']); if ($arrEvent['addTime']) { if ($span > 0) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['dateFormat'], $arrEvent['endTime']) . ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } elseif ($arrEvent['startTime'] == $arrEvent['endTime']) { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']); } else { $strTime .= ' ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['startTime']) . ' - ' . date($GLOBALS['TL_CONFIG']['timeFormat'], $arrEvent['endTime']); } } if ($sqlLookupValField) { //$arrEvents[$arrEvent[$sqlLookupValField].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } else { //$arrEvents[$arrEvent['id'].'@'.$strTime] = $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : ''); if (count($arrSortKeys) >= 2) { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent[$arrSortKeys[1]['field']]][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } else { $arrEvents[$arrEvent[$arrSortKeys[0]['field']]][$arrEvent['startTime']][] = array('value' => $arrEvent[$sqlLookupValField] . '@' . $strTime, 'label' => $arrEvent[$arrLookupField[1]] . (strlen($strTime) ? ', ' . $strTime : '')); } } } } // while endTime < intEnd } // if recurring } // while // sort events foreach ($arrEvents as $k => $arr) { if ($arrSortKeys[1]['order'] == 'DESC') { krsort($arrEvents[$k]); } else { ksort($arrEvents[$k]); } } if ($arrSortKeys[0]['order'] == 'DESC') { krsort($arrEvents); } else { ksort($arrEvents); } // set options foreach ($arrEvents as $k1 => $arr1) { foreach ($arr1 as $k2 => $arr2) { foreach ($arr2 as $k3 => $arr3) { $arrOptions[] = $arr3; } } } if (count($arrOptions) == 1) { $blnDoNotAddEmptyOption = true; } // include blank option to input type select if ($strType == 'efgLookupSelect') { if (!$blnDoNotAddEmptyOption) { array_unshift($arrOptions, array('value' => '', 'label' => '-')); } } } // if objEvents->numRows return $arrOptions; } else { $sqlLookup = "SELECT " . $sqlLookupIdField . (strlen($sqlLookupField) ? ', ' : '') . $sqlLookupField . (strlen($sqlLookupValField) ? ', ' : '') . $sqlLookupValField . " FROM " . $sqlLookupTable . $sqlLookupWhere . (strlen($sqlLookupOrder) > 1 ? " ORDER BY " . $sqlLookupOrder : ""); if (strlen($sqlLookupTable)) { $objOptions = $this->Database->prepare($sqlLookup)->execute(); } if ($objOptions->numRows) { $arrOptions = array(); while ($arrOpt = $objOptions->fetchAssoc()) { if ($sqlLookupValField) { $arrOptions[$arrOpt[$sqlLookupValField]] = $arrOpt[$arrLookupField[1]]; } else { $arrOptions[$arrOpt['id']] = $arrOpt[$arrLookupField[1]]; } } } } // end normal lookup table $arrTempOptions = array(); // include blank option to input type select if ($strType == 'efgLookupSelect') { if (!$blnDoNotAddEmptyOption) { $arrTempOptions[] = array('value' => '', 'label' => '-'); } } foreach ($arrOptions as $sK => $sV) { $strKey = (string) $sK; $arrTempOptions[] = array('value' => $strKey, 'label' => $sV); } $arrOptions = $arrTempOptions; break; // strType efgLookupCheckbox, efgLookupRadio or efgLookupSelect // countryselectmenu // strType efgLookupCheckbox, efgLookupRadio or efgLookupSelect // countryselectmenu case 'countryselect': $arrCountries = $this->getCountries(); $arrTempOptions = array(); foreach ($arrCountries as $strKey => $strVal) { $arrTempOptions[] = array('value' => $strKey, 'label' => $strVal); } $arrOptions = $arrTempOptions; break; default: if ($arrField['options']) { $arrOptions = deserialize($arrField['options']); } else { $strClass = $GLOBALS['TL_FFL'][$arrField['type']]; if ($this->classFileExists($strClass)) { $objWidget = new $strClass($arrField); if ($objWidget instanceof FormSelectMenu || $objWidget instanceof FormCheckbox || $objWidget instanceof FormRadioButton) { // HOOK: load form field callback if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $arrField['pid'], array()); } } $arrOptions = $objWidget->options; } } } break; } // end switch $arrField['type'] return $arrOptions; }
/** * Add an event to the array of active events * @param object * @param integer * @param integer * @param string * @param integer * @param integer * @param integer */ protected function addEvent($objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intLimit, $intCalendar) { $span = \Calendar::calculateSpan($intStart, $intEnd); // Adjust the start time of a multi-day event (see #6802) if ($this->cal_noSpan && $span > 0 && $intStart < $intBegin && $intBegin < $intEnd) { $intStart = $intBegin; } $intDate = $intStart; $intKey = date('Ymd', $intStart); $arrEvent = $this->getEventDetails($objEvents, $intStart, $intEnd, $strUrl, $intBegin, $intCalendar); $this->arrEvents[$intKey][$intStart][] = $arrEvent; // Multi-day event for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) { // Only show first occurrence if ($this->cal_noSpan && $intDate >= $intBegin) { break; } $intDate = strtotime('+ 1 day', $intDate); $intNextKey = date('Ymd', $intDate); $this->arrEvents[$intNextKey][$intDate][] = $arrEvent; } }
/** * Add the type of input field * * @param array $arrRow * * @return string */ public function listEvents($arrRow) { $span = Calendar::calculateSpan($arrRow['startTime'], $arrRow['endTime']); if ($span > 0) { $date = Date::parse(Config::get($arrRow['addTime'] ? 'datimFormat' : 'dateFormat'), $arrRow['startTime']) . ' – ' . Date::parse(Config::get($arrRow['addTime'] ? 'datimFormat' : 'dateFormat'), $arrRow['endTime']); } elseif ($arrRow['startTime'] == $arrRow['endTime']) { $date = Date::parse(Config::get('dateFormat'), $arrRow['startTime']) . ($arrRow['addTime'] ? ' ' . Date::parse(Config::get('timeFormat'), $arrRow['startTime']) : ''); } else { $date = Date::parse(Config::get('dateFormat'), $arrRow['startTime']) . ($arrRow['addTime'] ? ' ' . Date::parse(Config::get('timeFormat'), $arrRow['startTime']) . ' – ' . Date::parse(Config::get('timeFormat'), $arrRow['endTime']) : ''); } return '<div class="tl_content_left">' . $arrRow['title'] . ' <span style="color:#b3b3b3;padding-left:3px">[' . $date . ']</span></div>'; }
/** * Add an event to the array of active events * * @param CalendarEventsModel $objEvents * @param integer $intStart * @param integer $intEnd * @param integer $intBegin * @param integer $intLimit * @param integer $intCalendar */ protected function addEvent($objEvents, $intStart, $intEnd, $intBegin, $intLimit, $intCalendar) { /** @var PageModel $objPage */ global $objPage; // Backwards compatibility (4th argument was $strUrl) if (func_num_args() > 6) { @trigger_error('Calling Events::addEvent() with 7 arguments has been deprecated and will no longer work in Contao 5.0. Do not pass $strUrl as 4th argument anymore.', E_USER_DEPRECATED); $intBegin = func_get_arg(4); $intLimit = func_get_arg(5); $intCalendar = func_get_arg(6); } $span = \Calendar::calculateSpan($intStart, $intEnd); // Adjust the start time of a multi-day event (see #6802) if ($this->cal_noSpan && $span > 0 && $intStart < $intBegin && $intBegin < $intEnd) { $intStart = $intBegin; } $intDate = $intStart; $intKey = date('Ymd', $intStart); $strDate = \Date::parse($objPage->dateFormat, $intStart); $strDay = $GLOBALS['TL_LANG']['DAYS'][date('w', $intStart)]; $strMonth = $GLOBALS['TL_LANG']['MONTHS'][date('n', $intStart) - 1]; if ($span > 0) { $strDate = \Date::parse($objPage->dateFormat, $intStart) . ' – ' . \Date::parse($objPage->dateFormat, $intEnd); $strDay = ''; } $strTime = ''; if ($objEvents->addTime) { if ($span > 0) { $strDate = \Date::parse($objPage->datimFormat, $intStart) . ' – ' . \Date::parse($objPage->datimFormat, $intEnd); } elseif ($intStart == $intEnd) { $strTime = \Date::parse($objPage->timeFormat, $intStart); } else { $strTime = \Date::parse($objPage->timeFormat, $intStart) . ' – ' . \Date::parse($objPage->timeFormat, $intEnd); } } $until = ''; $recurring = ''; // Recurring event if ($objEvents->recurring) { $arrRange = deserialize($objEvents->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvents->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], \Date::parse($objPage->dateFormat, $objEvents->repeatEnd)); } } // Store raw data $arrEvent = $objEvents->row(); // Overwrite some settings $arrEvent['date'] = $strDate; $arrEvent['time'] = $strTime; $arrEvent['datetime'] = $objEvents->addTime ? date('Y-m-d\\TH:i:sP', $intStart) : date('Y-m-d', $intStart); $arrEvent['day'] = $strDay; $arrEvent['month'] = $strMonth; $arrEvent['parent'] = $intCalendar; $arrEvent['calendar'] = $objEvents->getRelated('pid'); $arrEvent['link'] = $objEvents->title; $arrEvent['target'] = ''; $arrEvent['title'] = specialchars($objEvents->title, true); $arrEvent['href'] = $this->generateEventUrl($objEvents); $arrEvent['class'] = $objEvents->cssClass != '' ? ' ' . $objEvents->cssClass : ''; $arrEvent['recurring'] = $recurring; $arrEvent['until'] = $until; $arrEvent['begin'] = $intStart; $arrEvent['end'] = $intEnd; $arrEvent['details'] = ''; $arrEvent['hasDetails'] = false; $arrEvent['hasTeaser'] = false; // Override the link target if ($objEvents->source == 'external' && $objEvents->target) { $arrEvent['target'] = ' target="_blank"'; } // Clean the RTE output if ($arrEvent['teaser'] != '') { $arrEvent['hasTeaser'] = true; $arrEvent['teaser'] = \StringUtil::toHtml5($arrEvent['teaser']); $arrEvent['teaser'] = \StringUtil::encodeEmail($arrEvent['teaser']); } // Display the "read more" button for external/article links if ($objEvents->source != 'default') { $arrEvent['details'] = true; $arrEvent['hasDetails'] = true; } else { $id = $objEvents->id; $arrEvent['details'] = function () use($id) { $strDetails = ''; $objElement = \ContentModel::findPublishedByPidAndTable($id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $strDetails .= $this->getContentElement($objElement->current()); } } return $strDetails; }; $arrEvent['hasDetails'] = \ContentModel::countPublishedByPidAndTable($id, 'tl_calendar_events') > 0; } // Get todays start and end timestamp if ($this->intTodayBegin === null) { $this->intTodayBegin = strtotime('00:00:00'); } if ($this->intTodayEnd === null) { $this->intTodayEnd = strtotime('23:59:59'); } // Mark past and upcoming events (see #3692) if ($intEnd < $this->intTodayBegin) { $arrEvent['class'] .= ' bygone'; } elseif ($intStart > $this->intTodayEnd) { $arrEvent['class'] .= ' upcoming'; } else { $arrEvent['class'] .= ' current'; } $this->arrEvents[$intKey][$intStart][] = $arrEvent; // Multi-day event for ($i = 1; $i <= $span && $intDate <= $intLimit; $i++) { // Only show first occurrence if ($this->cal_noSpan && $intDate >= $intBegin) { break; } $intDate = strtotime('+ 1 day', $intDate); $intNextKey = date('Ymd', $intDate); $this->arrEvents[$intNextKey][$intDate][] = $arrEvent; } }
/** * Add the type of input field * @param array * @return string */ public function listEvents($arrRow) { $time = time(); $key = $arrRow['published'] && ($arrRow['start'] == '' || $arrRow['start'] < $time) && ($arrRow['stop'] == '' || $arrRow['stop'] > $time) ? 'published' : 'unpublished'; $span = Calendar::calculateSpan($arrRow['startTime'], $arrRow['endTime']); if ($span > 0) { $date = $this->parseDate($GLOBALS['TL_CONFIG'][$arrRow['addTime'] ? 'datimFormat' : 'dateFormat'], $arrRow['startTime']) . ' - ' . $this->parseDate($GLOBALS['TL_CONFIG'][$arrRow['addTime'] ? 'datimFormat' : 'dateFormat'], $arrRow['endTime']); } elseif ($arrRow['startTime'] == $arrRow['endTime']) { $date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrRow['startTime']) . ($arrRow['addTime'] ? ' (' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['startTime']) . ')' : ''); } else { $date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrRow['startTime']) . ($arrRow['addTime'] ? ' (' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['startTime']) . ' - ' . $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrRow['endTime']) . ')' : ''); } return ' <div class="cte_type ' . $key . '"><strong>' . $arrRow['title'] . '</strong> - ' . $date . '</div> <div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h52' : '') . '"> ' . ($arrRow['details'] != '' ? $arrRow['details'] : $arrRow['teaser']) . ' </div>' . "\n"; }
/** * Generate the module */ protected function compile() { global $objPage; $this->Template->event = ''; $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $time = time(); // Get the current event $objEvent = $this->Database->prepare("SELECT *, author AS authorId, (SELECT title FROM tl_calendar WHERE tl_calendar.id=tl_calendar_events.pid) AS calendar, (SELECT name FROM tl_user WHERE id=author) author FROM tl_calendar_events WHERE pid IN(" . implode(',', array_map('intval', $this->cal_calendar)) . ") AND (id=? OR alias=?)" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<?) AND (stop='' OR stop>?) AND published=1" : ""))->limit(1)->execute(is_numeric($this->Input->get('events')) ? $this->Input->get('events') : 0, $this->Input->get('events'), $time, $time); if ($objEvent->numRows < 1) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->event = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $this->Input->get('events')) . '</p>'; return; } // Overwrite the page title if ($objEvent->title != '') { $objPage->pageTitle = strip_insert_tags($objEvent->title); } // Overwrite the page description if ($objEvent->teaser != '') { $objPage->description = $this->prepareMetaDescription($objEvent->teaser); } $span = Calendar::calculateSpan($objEvent->startTime, $objEvent->endTime); if ($objPage->outputFormat == 'xhtml') { $strTimeStart = ''; $strTimeEnd = ''; $strTimeClose = ''; } else { $strTimeStart = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->startTime) . '">'; $strTimeEnd = '<time datetime="' . date('Y-m-d\\TH:i:sP', $objEvent->endTime) . '">'; $strTimeClose = '</time>'; } // Get date if ($span > 0) { $date = $strTimeStart . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objEvent->addTime ? $objPage->datimFormat : $objPage->dateFormat, $objEvent->endTime) . $strTimeClose; } elseif ($objEvent->startTime == $objEvent->endTime) { $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . ')' : '') . $strTimeClose; } else { $date = $strTimeStart . $this->parseDate($objPage->dateFormat, $objEvent->startTime) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $objEvent->startTime) . $strTimeClose . ' - ' . $strTimeEnd . $this->parseDate($objPage->timeFormat, $objEvent->endTime) . ')' : '') . $strTimeClose; } $until = ''; $recurring = ''; // Recurring event if ($objEvent->recurring) { $arrRange = deserialize($objEvent->repeatEach); $strKey = 'cal_' . $arrRange['unit']; $recurring = sprintf($GLOBALS['TL_LANG']['MSC'][$strKey], $arrRange['value']); if ($objEvent->recurrences > 0) { $until = sprintf($GLOBALS['TL_LANG']['MSC']['cal_until'], $this->parseDate($objPage->dateFormat, $objEvent->repeatEnd)); } } // Override the default image size if ($this->imgSize != '') { $size = deserialize($this->imgSize); if ($size[0] > 0 || $size[1] > 0) { $objEvent->size = $this->imgSize; } } $objTemplate = new FrontendTemplate($this->cal_template); $objTemplate->setData($objEvent->row()); $objTemplate->date = $date; $objTemplate->start = $objEvent->startTime; $objTemplate->end = $objEvent->endTime; $objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : ''; $objTemplate->recurring = $recurring; $objTemplate->until = $until; $this->import('String'); // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objEvent->details = $this->String->toXhtml($objEvent->details); } else { $objEvent->details = $this->String->toHtml5($objEvent->details); } $objTemplate->details = $this->String->encodeEmail($objEvent->details); $objTemplate->addImage = false; // Add image if ($objEvent->addImage && is_file(TL_ROOT . '/' . $objEvent->singleSRC)) { $this->addImageToTemplate($objTemplate, $objEvent->row()); } $objTemplate->enclosure = array(); // Add enclosures if ($objEvent->addEnclosure) { $this->addEnclosuresToTemplate($objTemplate, $objEvent->row()); } $this->Template->event = $objTemplate->parse(); // HOOK: comments extension required if ($objEvent->noComments || !in_array('comments', $this->Config->getActiveModules())) { $this->Template->allowComments = false; return; } // Check whether comments are allowed $objCalendar = $this->Database->prepare("SELECT * FROM tl_calendar WHERE id=?")->limit(1)->execute($objEvent->pid); if ($objCalendar->numRows < 1 || !$objCalendar->allowComments) { $this->Template->allowComments = false; return; } $this->Template->allowComments = true; // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify system administrator if ($objCalendar->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify author if ($objCalendar->notify != 'notify_admin') { $objAuthor = $this->Database->prepare("SELECT email FROM tl_user WHERE id=?")->limit(1)->execute($objEvent->authorId); if ($objAuthor->numRows) { $arrNotifies[] = $objAuthor->email; } } $objConfig = new stdClass(); $objConfig->perPage = $objCalendar->perPage; $objConfig->order = $objCalendar->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCalendar->requireLogin; $objConfig->disableCaptcha = $objCalendar->disableCaptcha; $objConfig->bbcode = $objCalendar->bbcode; $objConfig->moderate = $objCalendar->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_calendar_events', $objEvent->id, $arrNotifies); }