/** * 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); while ($intStartTime < time() && $intEndTime < $objEvent->repeatEnd) { $intStartTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intStartTime); $intEndTime = strtotime('+' . $arrRange['value'] . ' ' . $arrRange['unit'], $intEndTime); } } 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; } } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($objEvent->row()); $objTemplate->date = $date; $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 = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objEvent->id, 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $objTemplate->details .= $this->getContentElement($objElement->current()); } } $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, $objEvent->row()); } ////////// CHANGES BY ModuleEventReaderTags $objTemplate->showTags = $this->event_showtags; if ($this->event_showtags) { $helper = new \TagHelper(); $tagsandlist = $helper->getTagsAndTaglistForIdAndTable($objEvent->id, 'tl_calendar_events', $this->tag_jumpTo); $tags = $tagsandlist['tags']; $taglist = $tagsandlist['taglist']; $objTemplate->showTagClass = $this->tag_named_class; $objTemplate->tags = $tags; $objTemplate->taglist = $taglist; } ////////// CHANGES BY ModuleEventReaderTags $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); }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $blnClearInput = false; $intYear = \Input::get('year'); $intMonth = \Input::get('month'); $intDay = \Input::get('day'); // Jump to the current period if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) { switch ($this->cal_format) { case 'cal_year': $intYear = date('Y'); break; case 'cal_month': $intMonth = date('Ym'); break; case 'cal_day': $intDay = date('Ymd'); break; } $blnClearInput = true; } $blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year')); // Create the date object try { if ($blnDynamicFormat && $intYear) { $this->Date = new \Date($intYear, 'Y'); $this->cal_format = 'cal_year'; $this->headline .= ' ' . date('Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intMonth) { $this->Date = new \Date($intMonth, 'Ym'); $this->cal_format = 'cal_month'; $this->headline .= ' ' . \Date::parse('F Y', $this->Date->tstamp); } elseif ($blnDynamicFormat && $intDay) { $this->Date = new \Date($intDay, 'Ymd'); $this->cal_format = 'cal_day'; $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $this->Date->tstamp); } else { $this->Date = new \Date(); } } catch (\OutOfBoundsException $e) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format); // Get all events $arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd); $sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort'; // Sort the days $sort($arrAllEvents); // Sort the events foreach (array_keys($arrAllEvents) as $key) { $sort($arrAllEvents[$key]); } $arrEvents = array(); $dateBegin = date('Ymd', $strBegin); $dateEnd = date('Ymd', $strEnd); // Remove events outside the scope foreach ($arrAllEvents as $key => $days) { if ($key < $dateBegin || $key > $dateEnd) { continue; } foreach ($days as $day => $events) { foreach ($events as $event) { $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)]; $event['firstDate'] = \Date::parse($objPage->dateFormat, $day); $event['datetime'] = date('Y-m-d', $day); $arrEvents[] = $event; } } } unset($arrAllEvents); $total = count($arrEvents); $limit = $total; $offset = 0; // Overall limit if ($this->cal_limit > 0) { $total = min($this->cal_limit, $total); $limit = $total; } // Pagination if ($this->perPage > 0) { $id = 'page_e' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $offset = ($page - 1) * $this->perPage; $limit = min($this->perPage + $offset, $total); $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $strMonth = ''; $strDate = ''; $strEvents = ''; $dayCount = 0; $eventCount = 0; $headerCount = 0; $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; } } // Parse events for ($i = $offset; $i < $limit; $i++) { $event = $arrEvents[$i]; $blnIsLastEvent = false; // Last event on the current day if ($i + 1 == $limit || !isset($arrEvents[$i + 1]['firstDate']) || $event['firstDate'] != $arrEvents[$i + 1]['firstDate']) { $blnIsLastEvent = true; } /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_template); $objTemplate->setData($event); // Month header if ($strMonth != $event['month']) { $objTemplate->newMonth = true; $strMonth = $event['month']; } // Day header if ($strDate != $event['firstDate']) { $headerCount = 0; $objTemplate->header = true; $objTemplate->classHeader = ($dayCount % 2 == 0 ? ' even' : ' odd') . ($dayCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : ''); $strDate = $event['firstDate']; ++$dayCount; } // Show the teaser text of redirect events (see #6315) if (is_bool($event['details'])) { $objTemplate->details = $event['teaser']; } // Add the template variables $objTemplate->classList = $event['class'] . ($headerCount % 2 == 0 ? ' even' : ' odd') . ($headerCount == 0 ? ' first' : '') . ($blnIsLastEvent ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->classUpcoming = $event['class'] . ($eventCount % 2 == 0 ? ' even' : ' odd') . ($eventCount == 0 ? ' first' : '') . ($offset + $eventCount + 1 >= $limit ? ' last' : '') . ' cal_' . $event['parent']; $objTemplate->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $event['title'])); $objTemplate->more = $GLOBALS['TL_LANG']['MSC']['more']; $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location']; // Short view if ($this->cal_noSpan) { $objTemplate->day = $event['day']; $objTemplate->date = $event['date']; $objTemplate->span = $event['time'] == '' && $event['day'] == '' ? $event['date'] : ''; } else { $objTemplate->day = $event['firstDay']; $objTemplate->date = $event['firstDate']; $objTemplate->span = ''; } $objTemplate->addImage = false; // Add an image if ($event['addImage'] && $event['singleSRC'] != '') { $objModel = \FilesModel::findByUuid($event['singleSRC']); if ($objModel === null) { if (!\Validator::isUuid($event['singleSRC'])) { $objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { if ($imgSize) { $event['size'] = $imgSize; } $event['singleSRC'] = $objModel->path; $this->addImageToTemplate($objTemplate, $event); } } $objTemplate->enclosure = array(); // Add enclosure if ($event['addEnclosure']) { $this->addEnclosuresToTemplate($objTemplate, $event); } ////////// CHANGES BY ModuleEventlistTags $objTemplate->showTags = $this->event_showtags; if ($this->event_showtags) { $helper = new \TagHelper(); $tagsandlist = $helper->getTagsAndTaglistForIdAndTable($event['id'], 'tl_calendar_events', $this->tag_jumpTo); $tags = $tagsandlist['tags']; $taglist = $tagsandlist['taglist']; $objTemplate->showTagClass = $this->tag_named_class; $objTemplate->tags = $tags; $objTemplate->taglist = $taglist; } ////////// CHANGES BY ModuleEventlistTags $strEvents .= $objTemplate->parse(); ++$eventCount; ++$headerCount; } // No events found if ($strEvents == '') { $strEvents = "\n" . '<div class="empty">' . $strEmpty . '</div>' . "\n"; } // See #3672 $this->Template->headline = $this->headline; $this->Template->events = $strEvents; // Clear the $_GET array (see #2445) if ($blnClearInput) { \Input::setGet('year', null); \Input::setGet('month', null); \Input::setGet('day', null); } ////////// CHANGES BY ModuleEventlistTags $headlinetags = array(); if (strlen(\Input::get('tag')) && !$this->tag_ignore || strlen($this->tag_filter)) { if (strlen($this->tag_filter)) { $headlinetags = preg_split("/,/", $this->tag_filter); $tagids = $this->getFilterTags(); $first = false; } else { $headlinetags = array(); } $relatedlist = strlen(\Input::get('related')) ? preg_split("/,/", \Input::get('related')) : array(); $tagArray = strlen(\Input::get('tag')) ? array(\Input::get('tag')) : array(); $headlinetags = array_merge($headlinetags, $tagArray); if (count($relatedlist)) { $headlinetags = array_merge($headlinetags, $relatedlist); } } if (strlen($this->Template->events) == 0) { $headlinetags = array_merge(array(\Input::get('tag')), $relatedlist); $this->Template->events = $GLOBALS['TL_LANG']['MSC']['emptyevents']; } $this->Template->tags_activetags = $headlinetags; ////////// CHANGES BY ModuleEventlistTags }