protected function generateFiles($arrFeed)
	{
		$arrCalendars = StringUtil::deserialize($arrFeed['calendars']);

		if (empty($arrCalendars) || !\is_array($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] = $objParent->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/events/%s');
					}
				}

				// 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);

				// Recurring events
				if ($objArticle->recurring)
				{
					$arrRepeat = StringUtil::deserialize($objArticle->repeatEach);

					if (!\is_array($arrRepeat) || !isset($arrRepeat['unit']) || !isset($arrRepeat['value']) || $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);
						}
					}
				}
			}
		}

		$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['startTime'];
					$objItem->end = $event['endTime'];

					if (($objAuthor = UserModel::findById($event['author'])) !== null)
					{
						$objItem->author = $objAuthor->name;
					}

					// 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['media:content']))
					{
						foreach ($event['media:content'] as $enclosure)
						{
							$objItem->addEnclosure($enclosure, $strLink, 'media:content');
						}
					}

					if (\is_array($event['enclosure']))
					{
						foreach ($event['enclosure'] as $enclosure)
						{
							$objItem->addEnclosure($enclosure, $strLink);
						}
					}

					$objFeed->addItem($objItem);
				}
			}
		}

		// Create the file
		File::putContent('web/share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->$strType(), false));
	}
protected function generateFiles($arrFeed)
	{
		$arrCalendars = StringUtil::deserialize($arrFeed['calendars']);

		if (empty($arrCalendars) || !\is_array($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();

		
		$objArticle = CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']);

		
		if ($objArticle !== null)
		{
			while ($objArticle->next())
			{
				$jumpTo = $objArticle->getRelated('pid')->jumpTo;

				
				if (!$jumpTo)
				{
					continue;
				}

				
				if (!isset($arrUrls[$jumpTo]))
				{
					$objParent = PageModel::findWithDetails($jumpTo);

					
					if ($objParent === null)
					{
						$arrUrls[$jumpTo] = false;
					}
					else
					{
						$arrUrls[$jumpTo] = $objParent->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/events/%s');
					}
				}

				
				if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default')
				{
					continue;
				}

				$strUrl = $arrUrls[$jumpTo];
				$this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl);

				
				if ($objArticle->recurring)
				{
					$arrRepeat = StringUtil::deserialize($objArticle->repeatEach);

					if (!\is_array($arrRepeat) || !isset($arrRepeat['unit']) || !isset($arrRepeat['value']) || $arrRepeat['value'] < 1)
					{
						continue;
					}

					$count = 0;
					$intStartTime = $objArticle->startTime;
					$intEndTime = $objArticle->endTime;
					$strtotime = '+ ' . $arrRepeat['value'] . ' ' . $arrRepeat['unit'];

					
					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);
						}
					}
				}
			}
		}

		$count = 0;
		ksort($this->arrEvents);

		
		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['startTime'];
					$objItem->end = $event['endTime'];

					if (($objAuthor = UserModel::findById($event['author'])) !== null)
					{
						$objItem->author = $objAuthor->name;
					}

					
					if ($arrFeed['source'] == 'source_text')
					{
						$strDescription = '';
						$objElement = ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events');

						if ($objElement !== null)
						{
							
							$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['media:content']))
					{
						foreach ($event['media:content'] as $enclosure)
						{
							$objItem->addEnclosure($enclosure, $strLink, 'media:content');
						}
					}

					if (\is_array($event['enclosure']))
					{
						foreach ($event['enclosure'] as $enclosure)
						{
							$objItem->addEnclosure($enclosure, $strLink);
						}
					}

					$objFeed->addItem($objItem);
				}
			}
		}

		
		File::putContent('web/share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->$strType(), false));
	}
protected function generateFiles ( $ arrFeed ) { $ arrCalendars = StringUtil :: deserialize ( $ arrFeed [ 'calendars' ] ) ; if ( empty ( $ arrCalendars ) || ! \ is_array ( $ 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 ] = $ objParent -> getAbsoluteUrl ( Config :: get ( 'useAutoItem' ) ? '/%s' : '/events/%s' ) ; } } // 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 ) ; // Recurring events if ( $ objArticle -> recurring ) { $ arrRepeat = StringUtil :: deserialize ( $ objArticle -> repeatEach ) ; if ( ! \ is_array ( $ arrRepeat ) || ! isset ( $ arrRepeat [ 'unit' ] ) || ! isset ( $ arrRepeat [ 'value' ] ) || $ 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 ) ; } } } } } $ 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 [ 'startTime' ] ; $ objItem -> end = $ event [ 'endTime' ] ; if ( ( $ objAuthor = UserModel :: findById ( $ event [ 'author' ] ) ) !== null ) { $ objItem -> author = $ objAuthor -> name ; } // 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 [ 'media:content' ] ) ) { foreach ( $ event [ 'media:content' ] as $ enclosure ) { $ objItem -> addEnclosure ( $ enclosure , $ strLink , 'media:content' ) ; } } if ( \ is_array ( $ event [ 'enclosure' ] ) ) { foreach ( $ event [ 'enclosure' ] as $ enclosure ) { $ objItem -> addEnclosure ( $ enclosure , $ strLink ) ; } } $ objFeed -> addItem ( $ objItem ) ; } } } // Create the file File :: putContent ( 'web/share/' . $ strFile . '.xml' , $ this -> replaceInsertTags ( $ objFeed -> $ strType ( ) , false ) ) ; }
Generate an XML file and save it to the root directory

@param array $arrFeed
Generate an XML file and save it to the root directory