public static function getRelatedEvents(\DataContainer $dc, array $arrRelation = array()) { $arrOptionGroups = array(); $arrOptions = array(); // front end mode with module & relation context if (!empty($arrRelation)) { $objEvents = \CalendarEventsModel::findUpcomingByPids(deserialize($dc->objModule->cal_calendar, true), 0, array('order' => 'title')); } else { $objEvents = \CalendarEventsModel::findAll(); } if ($objEvents === null) { return $arrOptions; } while ($objEvents->next()) { // return as optgroup if more than 1 $arrPids if (($objArchive = $objEvents->getRelated('pid')) === null) { continue; } $arrOptionGroups[$objArchive->title][$objEvents->id] = $objEvents->title; $arrOptions[$objEvents->id] = $objEvents->title; } $arrDca =& $GLOBALS['TL_DCA']['tl_submission']; // filter menu does not support optgroups if (TL_MODE == 'BE' && $dc->field != 'event') { return $arrOptions; } // remove optgroups if not wanted, or less than 2 optgroups if (count($arrOptionGroups) == 1 || $arrDca['fields'][$arrRelation['submissionField']]['eval']['optgroup'] === false) { return $arrOptions; } return $arrOptionGroups; }
/** * Generate an XML file and save it to the root directory * * @param array $arrFeed */ protected function generateFiles($arrFeed) { $arrCalendars = deserialize($arrFeed['calendars']); if (!is_array($arrCalendars) || empty($arrCalendars)) { return; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: \Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; $arrUrls = array(); $this->arrEvents = array(); $time = time(); // Get the upcoming events $objArticle = \CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']); // Parse the items if ($objArticle !== null) { while ($objArticle->next()) { $jumpTo = $objArticle->getRelated('pid')->jumpTo; // No jumpTo page set (see #4784) if (!$jumpTo) { continue; } // Get the jumpTo URL if (!isset($arrUrls[$jumpTo])) { $objParent = \PageModel::findWithDetails($jumpTo); // A jumpTo page is set but does no longer exist (see #5781) if ($objParent === null) { $arrUrls[$jumpTo] = false; } else { $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s', $objParent->language); } } // Skip the event if it requires a jumpTo URL but there is none if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') { continue; } $strUrl = $arrUrls[$jumpTo]; $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink); // Recurring events if ($objArticle->recurring) { $arrRepeat = deserialize($objArticle->repeatEach); if ($arrRepeat['value'] < 1) { continue; } $count = 0; $intStartTime = $objArticle->startTime; $intEndTime = $objArticle->endTime; $strtotime = '+ ' . $arrRepeat['value'] . ' ' . $arrRepeat['unit']; // Do not include more than 20 recurrences while ($count++ < 20) { if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) { break; } $intStartTime = strtotime($strtotime, $intStartTime); $intEndTime = strtotime($strtotime, $intEndTime); if ($intStartTime >= $time) { $this->addEvent($objArticle, $intStartTime, $intEndTime, $strUrl, $strLink); } } } } } $count = 0; ksort($this->arrEvents); // Add the feed items foreach ($this->arrEvents as $days) { foreach ($days as $events) { foreach ($events as $event) { if ($arrFeed['maxItems'] > 0 && $count++ >= $arrFeed['maxItems']) { break 3; } $objItem = new \FeedItem(); $objItem->title = $event['title']; $objItem->link = $event['link']; $objItem->published = $event['tstamp']; $objItem->begin = $event['begin']; $objItem->end = $event['end']; $objItem->author = $event['authorName']; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = \ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events'); if ($objElement !== null) { // Overwrite the request (see #7756) $strRequest = \Environment::get('request'); \Environment::set('request', $objItem->link); while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->current()); } \Environment::set('request', $strRequest); } } else { $strDescription = $event['teaser']; } $strDescription = $this->replaceInsertTags($strDescription, false); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); if (is_array($event['enclosure'])) { foreach ($event['enclosure'] as $enclosure) { $objItem->addEnclosure($enclosure); } } $objFeed->addItem($objItem); } } } // Create the file \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false)); }
/** * Generate an XML file and save it to the root directory * @param array */ protected function generateFiles($arrFeed) { $arrCalendars = deserialize($arrFeed['calendars']); if (!is_array($arrCalendars) || empty($arrCalendars)) { return; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: \Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; $arrUrls = array(); $this->arrEvents = array(); $time = time(); // Get the upcoming events $objArticle = \CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']); // Parse the items if ($objArticle !== null) { while ($objArticle->next()) { $jumpTo = $objArticle->getRelated('pid')->jumpTo; // No jumpTo page set (see #4784) if (!$jumpTo) { continue; } // Get the jumpTo URL if (!isset($arrUrls[$jumpTo])) { $objParent = $this->getPageDetails($jumpTo); $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s', $objParent->language); } $strUrl = $arrUrls[$jumpTo]; $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink); // Recurring events if ($objArticle->recurring) { $count = 0; $arrRepeat = deserialize($objArticle->repeatEach); // Do not include more than 20 recurrences while ($count++ < 20) { if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) { break; } $arg = $arrRepeat['value']; $unit = $arrRepeat['unit']; $strtotime = '+ ' . $arg . ' ' . $unit; $objArticle->startTime = strtotime($strtotime, $objArticle->startTime); $objArticle->endTime = strtotime($strtotime, $objArticle->endTime); if ($objArticle->startTime >= $time) { $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink); } } } } } $count = 0; ksort($this->arrEvents); // Add the feed items foreach ($this->arrEvents as $days) { foreach ($days as $events) { foreach ($events as $event) { if ($arrFeed['maxItems'] > 0 && $count++ >= $arrFeed['maxItems']) { break 3; } $objItem = new \FeedItem(); $objItem->title = $event['title']; $objItem->link = $event['link']; $objItem->published = $event['published']; $objItem->start = $event['start']; $objItem->end = $event['end']; $objItem->author = $event['authorName']; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = \ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events'); if ($objElement !== null) { while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->id); } } } else { $strDescription = $event['teaser']; } $strDescription = $this->replaceInsertTags($strDescription); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); if (is_array($event['enclosure'])) { foreach ($event['enclosure'] as $enclosure) { $objItem->addEnclosure($enclosure); } } $objFeed->addItem($objItem); } } } // Create file $objRss = new \File('share/' . $strFile . '.xml'); $objRss->write($this->replaceInsertTags($objFeed->{$strType}())); $objRss->close(); }