public static function modifyPalette()
 {
     $arrDca =& $GLOBALS['TL_DCA']['tl_calendar_events'];
     if (($objEvent = \CalendarEventsModel::findByPk(\Input::get('id'))) !== null && $objEvent->useMemberAuthor) {
         $arrDca['palettes']['default'] = str_replace('author,', ',', $arrDca['palettes']['default']);
     } else {
         $arrDca['palettes']['default'] = str_replace('memberAuthor,', ',', $arrDca['palettes']['default']);
     }
 }
 /**
  * Load events from churchtools api based on calendar settings
  * Deletes all events in databse, so temporary changes will get lost
  *
  * @param /DataContainer $dc
  */
 public static function loadAndParseEvents($dc)
 {
     $calendar = \CalendarModel::findByPk($dc->id);
     $arrCategoryIds = deserialize($calendar->churchtoolsCalendars);
     $api = new ChurchtoolsApi();
     $events = $api->loadEvents($arrCategoryIds, $calendar->churchtoolsDaysFrom, $calendar->churchtoolsDaysTo);
     //Clear Database
     $collection = \CalendarEventsModel::findByPid($dc->id);
     if (isset($collection)) {
         while ($collection->next()) {
             $collection->delete();
         }
     }
     foreach ($events as $event) {
         $startdate = new \DateTime($event->startdate);
         $enddate = new \DateTime($event->enddate);
         $fullDayEvent = $startdate->format('His') == 00 && $enddate->format('His') == 00 ? true : false;
         $model = new \CalendarEventsModel();
         $model->pid = $dc->id;
         $model->tstamp = time();
         $model->title = $event->bezeichnung;
         //$model->alias =
         //$model->author =
         if (!$fullDayEvent) {
             $model->addTime = 1;
             $model->startTime = $startdate->getTimestamp();
             $model->endTime = $enddate->getTimestamp();
         } else {
             $model->startTime = $startdate->getTimestamp();
             $model->endTime = $enddate->getTimestamp();
         }
         $model->startDate = $startdate->getTimestamp();
         if ($startdate != $enddate) {
             $model->endDate = $enddate->getTimestamp();
         }
         //$model->location =
         //$model->teaser =
         $model->published = 1;
         $model->save();
     }
     if (\Input::get('key')) {
         \Controller::redirect(preg_replace('/(&(amp;)?|\\?)key=[^& ]*/i', '', \Environment::get('request')));
     }
 }
Esempio n. 3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Respond to month
     if (\Input::get('month')) {
         $this->Date = new \Date(\Input::get('month'), 'Ym');
     } elseif (\Input::get('day')) {
         $this->Date = new \Date(\Input::get('day'), 'Ymd');
     } else {
         $this->Date = new \Date();
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('Ym', $objMinMax->dateFrom);
     $intRightBoundary = date('Ym', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     // Instantiate the template
     $objTemplate = new \FrontendTemplate($this->cal_ctemplate ? $this->cal_ctemplate : 'cal_default');
     // Store year and month
     $intYear = date('Y', $this->Date->tstamp);
     $intMonth = date('m', $this->Date->tstamp);
     $objTemplate->intYear = $intYear;
     $objTemplate->intMonth = $intMonth;
     // Previous month
     $prevMonth = $intMonth == 1 ? 12 : $intMonth - 1;
     $prevYear = $intMonth == 1 ? $intYear - 1 : $intYear;
     $lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear;
     $intPrevYm = intval($prevYear . str_pad($prevMonth, 2, 0, STR_PAD_LEFT));
     // Only generate a link if there are events (see #4160)
     if ($intPrevYm >= $intLeftBoundary) {
         $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . \Input::get('id') . '&' : '?') . 'month=' . $intPrevYm;
         $objTemplate->prevTitle = specialchars($lblPrevious);
         $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
         $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
     }
     // Current month
     $objTemplate->current = $GLOBALS['TL_LANG']['MONTHS'][date('m', $this->Date->tstamp) - 1] . ' ' . date('Y', $this->Date->tstamp);
     // Next month
     $nextMonth = $intMonth == 12 ? 1 : $intMonth + 1;
     $nextYear = $intMonth == 12 ? $intYear + 1 : $intYear;
     $lblNext = $GLOBALS['TL_LANG']['MONTHS'][$nextMonth - 1] . ' ' . $nextYear;
     $intNextYm = $nextYear . str_pad($nextMonth, 2, 0, STR_PAD_LEFT);
     // Only generate a link if there are events (see #4160)
     if ($intNextYm <= $intRightBoundary) {
         $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . \Input::get('id') . '&amp;' : '?') . 'month=' . $intNextYm;
         $objTemplate->nextTitle = specialchars($lblNext);
         $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
         $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
     }
     // Set the week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     $objTemplate->days = $this->compileDays();
     $objTemplate->weeks = $this->compileWeeks();
     $objTemplate->substr = $GLOBALS['TL_LANG']['MSC']['dayShortLength'];
     $this->Template->calendar = $objTemplate->parse();
 }
Esempio n. 4
0
 /**
  * Returns the event title concatenated with its date/time
  * @param $varEvent object|int The event id or the event object itself
  */
 public static function getDateTimeFormattedEvent($varEvent, $blnSeparatedDateTime = true, $strFormat = '%s (%s)')
 {
     $objEvent = $varEvent;
     if (is_numeric($varEvent)) {
         if (($objEvent = \CalendarEventsModel::findByPk($varEvent)) === null) {
             return '';
         }
     }
     $strDateTime = DateUtil::getFormattedDateTime($objEvent, $blnSeparatedDateTime);
     return sprintf($strFormat, $objEvent->title, $strDateTime);
 }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $arrItems = array();
     $t = 'tl_calendar_events';
     if ($this->include_type == 'archives') {
         $arrArchiveIds = deserialize($this->include_archives, true);
         $strSortOrder = $this->sortOrder == 'ascending' ? 'ASC' : 'DESC';
         if (sizeof($arrArchiveIds)) {
             $arrColumns = array("{$t}.pid IN(" . implode(',', array_map('intval', $arrArchiveIds)) . ")");
             if (!BE_USER_LOGGED_IN) {
                 $time = time();
                 $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
             }
             $objItems = \CalendarEventsModel::findBy($arrColumns, null, array('order' => 'startDate ' . $strSortOrder));
         }
     } else {
         $arrItemIds = deserialize($this->include_items, true);
         if (sizeof($arrItemIds)) {
             $arrItems = array_map(function () {
                 return '';
             }, array_flip($arrItemIds));
             $arrColumns = array("{$t}.id IN(" . implode(',', array_map('intval', $arrItemIds)) . ")");
             if (!BE_USER_LOGGED_IN) {
                 $time = time();
                 $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
             }
             $objItems = \CalendarEventsModel::findBy($arrColumns, null);
         }
     }
     if (!is_null($objItems)) {
         while ($objItems->next()) {
             $objReaderPage = \PageModel::findById($objItems->getRelated('pid')->jumpTo);
             $arrItem = $objItems->row();
             $arrItem['dateStart'] = \Date::parse('Y-m-d', $objItems->startDate);
             $arrItem['dateStartReadable'] = \Date::parse(\Config::get('dateFormat') ?: 'Y-m-d', $objItems->startDate);
             if ($objItems->endDate) {
                 $arrItem['dateEnd'] = \Date::parse('Y-m-d', $objItems->endDate);
                 $arrItem['dateEndReadable'] = \Date::parse(\Config::get('dateFormat') ?: 'Y-m-d', $objItems->endDate);
             }
             $arrItem['href'] = ampersand($this->generateFrontendUrl($objReaderPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objItems->alias != '' ? $objItems->alias : $objItems->id)));
             $arrItems[$objItems->id] = $arrItem;
         }
     }
     $this->Template->items = array_filter($arrItems);
 }
 /**
  * @param AddDataForContentEvent $event
  */
 public function addDataForContent(AddDataForContentEvent $event)
 {
     if (!$event->getModule() instanceof \ModuleEventReader && \Input::get('auto_item')) {
         return;
     }
     /*if (!\Input::get('auto_item')) {
           return;
       }*/
     $alias = \Input::get('auto_item');
     $model = \CalendarEventsModel::findByIdOrAlias($alias);
     if (!$model) {
         return;
     }
     global $objPage;
     //TODO test url by multi domains
     $event->setUrl(\Controller::generateFrontendUrl($objPage->row(), '/' . $model->alias, \Config::get('addLanguageToUrl'), $objPage->domain));
     $event->setTemplate('search_content_calendar');
     $event->setData($model);
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     parent::compile();
     if (FE_USER_LOGGED_IN) {
         // Get the current event
         $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias(\Input::get('events'), $this->cal_calendar);
         if ($objEvent === null) {
             return false;
         }
         // If current event isn't a registration event, don't go on
         if (!$objEvent->ser_register) {
             $this->blnParseRegistration = false;
         }
         // If registrations should not be shown
         if (!$objEvent->ser_show) {
             $this->blnShowList = false;
         }
         // Check, if the active user is in one of the usergroups
         $this->import('FrontendUser', 'User');
         $arrRegGroups = deserialize($objEvent->ser_groups);
         $arrShowGroups = deserialize($objEvent->ser_showgroups);
         if (is_array($arrRegGroups) && count(array_intersect($this->User->groups, $arrRegGroups)) < 1) {
             $this->blnParseRegistration = false;
         }
         if (is_array($arrShowGroups) && count(array_intersect($this->User->groups, $arrShowGroups)) < 1 || !is_array($arrShowGroups) && is_array($arrRegGroups) && count(array_intersect($this->User->groups, $arrRegGroups)) < 1) {
             $this->blnShowList = false;
         }
         $arrMessage = array();
         // If everything is OK, show the form and perform the registration
         if ($this->blnParseRegistration) {
             $this->Template->event .= $this->parseRegistration($objEvent);
         }
         // If everything is OK, show the list of all registered members
         if ($this->blnShowList) {
             $this->Template->event .= $this->parseList($objEvent);
         }
     }
 }
Esempio n. 8
0
 /**
  * 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);
 }
Esempio n. 9
0
 /**
  * Replace insert tags with their values
  * 
  * @param string  $strBuffer The text with the tags to be replaced
  * @param boolean $blnCache  If true, some tags will be preserved
  * 
  * @return string The text with the replaced tags
  */
 protected function replaceInsertTags($strBuffer, $blnCache = false)
 {
     global $objPage;
     // Preserve insert tags
     if ($GLOBALS['TL_CONFIG']['disableInsertTags']) {
         return $this->restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/\\{\\{([^\\}]+)\\}\\}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     $strBuffer = '';
     $arrCache = array();
     for ($_rit = 0; $_rit < count($tags); $_rit = $_rit + 2) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         // Load value from cache array
         if (isset($arrCache[$strTag])) {
             $strBuffer .= $arrCache[$strTag];
             continue;
         }
         $elements = explode('::', $strTag);
         // Skip certain elements if the output will be cached
         if ($blnCache) {
             if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || strncmp($elements[0], 'cache_', 6) === 0) {
                 $strBuffer .= '{{' . $strTag . '}}';
                 continue;
             }
         }
         $arrCache[$strTag] = '';
         // Replace the tag
         switch (strtolower($elements[0])) {
             // Date
             case 'date':
                 $arrCache[$strTag] = $this->parseDate($elements[1] ?: $GLOBALS['TL_CONFIG']['dateFormat']);
                 break;
                 // Accessibility tags
             // Accessibility tags
             case 'lang':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '</span>';
                 } elseif ($objPage->outputFormat == 'xhtml') {
                     $arrCache[$strTag] = '<span lang="' . $elements[1] . '" xml:lang="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \String::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">';
                         break;
                     case 'email_url':
                         $arrCache[$strTag] = $strEmail;
                         break;
                 }
                 break;
                 // Label tags
             // Label tags
             case 'label':
                 $keys = explode(':', $elements[1]);
                 if (count($keys) < 2) {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $this->loadLanguageFile($keys[0]);
                 if (count($keys) == 2) {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]];
                 } else {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]];
                 }
                 break;
                 // Front end user
             // Front end user
             case 'user':
                 if (FE_USER_LOGGED_IN) {
                     $this->import('FrontendUser', 'User');
                     $value = $this->User->{$elements}[1];
                     if ($value == '') {
                         $arrCache[$strTag] = $value;
                         break;
                     }
                     $this->loadDataContainer('tl_member');
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $value = deserialize($value);
                     $rgxp = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['rgxp'];
                     $opts = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['options'];
                     $rfrc = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['reference'];
                     if ($rgxp == 'date') {
                         $arrCache[$strTag] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $value);
                     } elseif ($rgxp == 'time') {
                         $arrCache[$strTag] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $value);
                     } elseif ($rgxp == 'datim') {
                         $arrCache[$strTag] = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $value);
                     } elseif (is_array($value)) {
                         $arrCache[$strTag] = implode(', ', $value);
                     } elseif (is_array($opts) && array_is_assoc($opts)) {
                         $arrCache[$strTag] = isset($opts[$value]) ? $opts[$value] : $value;
                     } elseif (is_array($rfrc)) {
                         $arrCache[$strTag] = isset($rfrc[$value]) ? is_array($rfrc[$value]) ? $rfrc[$value][0] : $rfrc[$value] : $value;
                     } else {
                         $arrCache[$strTag] = $value;
                     }
                     // Convert special characters (see #1890)
                     $arrCache[$strTag] = specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
                 // Back link
                 if ($elements[1] == 'back') {
                     $strUrl = 'javascript:history.go(-1)';
                     $strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
                     // No language files if the page is cached
                     if (!strlen($strTitle)) {
                         $strTitle = 'Go back';
                     }
                     $strName = $strTitle;
                 } elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
                     $strUrl = $elements[1];
                     $strTitle = $elements[1];
                     $strName = str_replace(array('http://', 'https://'), '', $elements[1]);
                 } else {
                     // User login page
                     if ($elements[1] == 'login') {
                         if (!FE_USER_LOGGED_IN) {
                             break;
                         }
                         $this->import('FrontendUser', 'User');
                         $elements[1] = $this->User->loginPage;
                     }
                     $objNextPage = \PageModel::findByIdOrAlias($elements[1]);
                     if ($objNextPage === null) {
                         break;
                     }
                     // Page type specific settings (thanks to Andreas Schempp)
                     switch ($objNextPage->type) {
                         case 'redirect':
                             $strUrl = $objNextPage->url;
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \String::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if (($objTarget = $objNextPage->getRelated('jumpTo')) !== null) {
                                 $strUrl = $this->generateFrontendUrl($objTarget->row());
                                 break;
                             } elseif (($objTarget = \PageModel::findFirstPublishedRegularByPid($objNextPage->id)) !== null) {
                                 if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                                     $objTarget = $this->getPageDetails($objTarget);
                                     // see #3983
                                     $strUrl = $this->generateFrontendUrl($objTarget->row(), null, $objTarget->language);
                                 } else {
                                     $strUrl = $this->generateFrontendUrl($objTarget->row());
                                 }
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                                 $objNextPage = $this->getPageDetails($objNextPage);
                                 // see #3983
                                 $strUrl = $this->generateFrontendUrl($objNextPage->row(), null, $objNextPage->language);
                             } else {
                                 $strUrl = $this->generateFrontendUrl($objNextPage->row());
                             }
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? $objPage->outputFormat == 'xhtml' ? LINK_NEW_WINDOW : ' target="_blank"' : '';
                     $strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'link':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, specialchars($strTitle), $strTarget, specialchars($strName));
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = $this->replaceInsertTags(ltrim($strOutput));
                 } else {
                     $arrCache[$strTag] = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $elements[1]) . '</p>';
                 }
                 break;
                 // Insert content element
             // Insert content element
             case 'insert_content':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getContentElement($elements[1]));
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getFrontendModule($elements[1]));
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getForm($elements[1]));
                 break;
                 // Article
             // Article
             case 'article':
             case 'article_open':
             case 'article_url':
             case 'article_title':
                 $objArticle = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objArticle === null) {
                     break;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objArticle->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->alias) ? $objArticle->alias : $objArticle->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $strLink = specialchars($objArticle->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // FAQ
             // FAQ
             case 'faq':
             case 'faq_open':
             case 'faq_url':
             case 'faq_title':
                 $objFaq = \FaqModel::findByIdOrAlias($elements[1]);
                 if ($objFaq === null) {
                     break;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objFaq->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objFaq->alias != '' ? $objFaq->alias : $objFaq->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'faq':
                         $strLink = specialchars($objFaq->question);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'faq_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objFaq->question));
                         break;
                     case 'faq_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'faq_title':
                         $arrCache[$strTag] = specialchars($objFaq->question);
                         break;
                 }
                 break;
                 // News
             // News
             case 'news':
             case 'news_open':
             case 'news_url':
             case 'news_title':
                 $objNews = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objNews === null) {
                     break;
                 } elseif ($objNews->source == 'internal') {
                     $strUrl = $this->generateFrontendUrl($objNews->getRelated('jumpTo')->row());
                 } elseif ($objNews->source == 'article') {
                     $objArticle = \ArticleModel::findByPk($objNews->articleId, array('eager' => true));
                     $strUrl = $this->generateFrontendUrl($objArticle->pid, '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                 } elseif ($objNews->source == 'external') {
                     $strUrl = $objNews->url;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objNews->pid, ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objNews->alias != '' ? $objNews->alias : $objNews->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'news':
                         $strLink = specialchars($objNews->headline);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'news_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objNews->headline));
                         break;
                     case 'news_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'news_title':
                         $arrCache[$strTag] = specialchars($objNews->headline);
                         break;
                 }
                 break;
                 // Events
             // Events
             case 'event':
             case 'event_open':
             case 'event_url':
             case 'event_title':
                 $objEvent = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objEvent === null) {
                     break;
                 } elseif ($objEvent->source == 'internal') {
                     $strUrl = $this->generateFrontendUrl($objEvent->getRelated('jumpTo')->row());
                 } elseif ($objEvent->source == 'article') {
                     $objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true));
                     $strUrl = $this->generateFrontendUrl($objArticle->pid, '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                 } elseif ($objEvent->source == 'external') {
                     $strUrl = $objEvent->url;
                 } else {
                     $strUrl = $this->generateFrontendUrl($objEvent->pid, ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/events/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id));
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'event':
                         $strLink = specialchars($objEvent->title);
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
                         break;
                     case 'event_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objEvent->title));
                         break;
                     case 'event_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'event_title':
                         $arrCache[$strTag] = specialchars($objEvent->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($this->replaceInsertTags($objTeaser->teaser));
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($this->replaceInsertTags($objTeaser->teaser));
                     }
                 }
                 break;
                 // News teaser
             // News teaser
             case 'news_teaser':
                 $objTeaser = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // Event teaser
             // Event teaser
             case 'event_teaser':
                 $objTeaser = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \String::toXhtml($objTeaser->teaser);
                     } else {
                         $arrCache[$strTag] = \String::toHtml5($objTeaser->teaser);
                     }
                 }
                 break;
                 // News feed URL
             // News feed URL
             case 'news_feed':
                 // FIXME: feeds are now in tl_calendar_feed
                 $objFeed = \NewsArchiveModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . $objFeed->alias . '.xml';
                 }
                 break;
                 // Calendar feed URL
             // Calendar feed URL
             case 'calendar_feed':
                 // FIXME: feeds are now in tl_calendar_feed
                 $objFeed = \CalendarModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . $objFeed->alias . '.xml';
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $objUpdate = \Database::getInstance()->execute("SELECT MAX(tstamp) AS tc, (SELECT MAX(tstamp) FROM tl_news) AS tn, (SELECT MAX(tstamp) FROM tl_calendar_events) AS te FROM tl_content");
                 if ($objUpdate->numRows) {
                     $arrCache[$strTag] = $this->parseDate($elements[1] ?: $GLOBALS['TL_CONFIG']['datimFormat'], max($objUpdate->tc, $objUpdate->tn, $objUpdate->te));
                 }
                 break;
                 // Version
             // Version
             case 'version':
                 $arrCache[$strTag] = VERSION . '.' . BUILD;
                 break;
                 // Request token
             // Request token
             case 'request_token':
                 $arrCache[$strTag] = REQUEST_TOKEN;
                 break;
                 // Conditional tags
             // Conditional tags
             case 'iflng':
                 if ($elements[1] != '' && $elements[1] != $objPage->language) {
                     for ($_rit; $_rit < count($tags); $_rit += 2) {
                         if ($tags[$_rit + 1] == 'iflng') {
                             break;
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
             case 'ifnlng':
                 if ($elements[1] != '') {
                     $langs = trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for ($_rit; $_rit < count($tags); $_rit += 2) {
                             if ($tags[$_rit + 1] == 'ifnlng') {
                                 break;
                             }
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Environment
             // Environment
             case 'env':
                 switch ($elements[1]) {
                     case 'host':
                         $arrCache[$strTag] = \Environment::get('host');
                         break;
                     case 'http_host':
                         $arrCache[$strTag] = \Environment::get('httpHost');
                         break;
                     case 'url':
                         $arrCache[$strTag] = \Environment::get('url');
                         break;
                     case 'path':
                         $arrCache[$strTag] = \Environment::get('base');
                         break;
                     case 'request':
                         $arrCache[$strTag] = $this->getIndexFreeRequest(true);
                         break;
                     case 'ip':
                         $arrCache[$strTag] = \Environment::get('ip');
                         break;
                     case 'referer':
                         $arrCache[$strTag] = $this->getReferer(true);
                         break;
                     case 'files_url':
                         $arrCache[$strTag] = TL_FILES_URL;
                         break;
                     case 'script_url':
                         $arrCache[$strTag] = TL_SCRIPT_URL;
                         break;
                     case 'plugins_url':
                         $arrCache[$strTag] = TL_PLUGINS_URL;
                         break;
                 }
                 break;
                 // Page
             // Page
             case 'page':
                 if ($elements[1] == 'pageTitle' && $objPage->pageTitle == '') {
                     $elements[1] = 'title';
                 } elseif ($elements[1] == 'parentPageTitle' && $objPage->parentPageTitle == '') {
                     $elements[1] = 'parentTitle';
                 } elseif ($elements[1] == 'mainPageTitle' && $objPage->mainPageTitle == '') {
                     $elements[1] = 'mainTitle';
                 }
                 $arrCache[$strTag] = specialchars($objPage->{$elements[1]});
                 break;
                 // User agent
             // User agent
             case 'ua':
                 $ua = \Environment::get('agent');
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = $ua->{$elements[1]};
                 } else {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Acronyms
             // Acronyms
             case 'acronym':
                 if ($objPage->outputFormat == 'xhtml') {
                     if ($elements[1] != '') {
                         $arrCache[$strTag] = '<acronym title="' . $elements[1] . '">';
                     } else {
                         $arrCache[$strTag] = '</acronym>';
                     }
                     break;
                 }
                 // NO break;
                 // Abbreviations
             // NO break;
             // Abbreviations
             case 'abbr':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \String::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         list($key, $value) = explode('=', $strParam);
                         switch ($key) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'alt':
                                 $alt = specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $value;
                                 break;
                         }
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Sanitize path
                 $strFile = str_replace('../', '', $strFile);
                 // Check maximum image width
                 if ($GLOBALS['TL_CONFIG']['maxImageWidth'] > 0 && $width > $GLOBALS['TL_CONFIG']['maxImageWidth']) {
                     $width = $GLOBALS['TL_CONFIG']['maxImageWidth'];
                     $height = null;
                 }
                 // Generate the thumbnail image
                 try {
                     $src = \Image::get($strFile, $width, $height, $mode);
                     $dimensions = '';
                     // Add the image dimensions
                     if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($src))) !== false) {
                         $dimensions = $imgSize[3];
                     }
                     // Generate the HTML markup
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0 || $objPage->outputFormat == 'xhtml') {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '><img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>') . '</a>';
                     } else {
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                     }
                 } catch (Exception $e) {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Files from the templates directory
             // Files from the templates directory
             case 'file':
                 $arrGet = $_GET;
                 \Input::resetCache();
                 $strFile = $elements[1];
                 // Take arguments and add them to the $_GET array
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]));
                     $strSource = \String::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         $arrParam = explode('=', $strParam);
                         $_GET[$arrParam[0]] = $arrParam[1];
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Sanitize path
                 $strFile = str_replace('../', '', $strFile);
                 // Include .php, .tpl, .xhtml and .html5 files
                 if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
                     ob_start();
                     include TL_ROOT . '/templates/' . $strFile;
                     $arrCache[$strTag] = ob_get_contents();
                     ob_end_clean();
                 }
                 $_GET = $arrGet;
                 \Input::resetCache();
                 break;
                 // HOOK: pass unknown tags to callback functions
             // HOOK: pass unknown tags to callback functions
             default:
                 if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
                     foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
                         $this->import($callback[0]);
                         $varValue = $this->{$callback}[0]->{$callback}[1]($strTag);
                         // Replace the tag and stop the loop
                         if ($varValue !== false) {
                             $arrCache[$strTag] = $varValue;
                             break;
                         }
                     }
                 }
                 break;
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return $this->restoreBasicEntities($strBuffer);
 }
Esempio n. 10
0
 public function generateUrl($arrPages)
 {
     $arrPages = array();
     $Event = \CalendarEventsModel::findAll();
     if (empty($Event)) {
         return array();
     }
     $arrEvent = array();
     while ($Event->next()) {
         $objCalendar = \CalendarModel::findByPk($Event->pid);
         if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) {
             $arrEvent[$Event->pid][] = $this->generateEventUrl($Event, $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s'));
         }
     }
     $InactiveArchives = \GlossarCalendarModel::findByPidsAndInactiveGlossar(array_keys($arrEvent));
     if (!empty($InactiveArchives)) {
         while ($InactiveArchives->next()) {
             unset($arrEvent[$InactiveArchives->id]);
         }
     }
     if (empty($arrEvent)) {
         return array();
     }
     $EventReader = \ModuleModel::findByType('eventreader');
     if (empty($EventReader)) {
         return array();
     }
     $arrReader = array();
     while ($EventReader->next()) {
         $arrReader[$EventReader->id] = deserialize($EventReader->cal_calendar);
     }
     $Content = \ContentModel::findBy(array("module IN ('" . implode("','", array_keys($arrReader)) . "')"), array());
     if (empty($Content)) {
         return array();
     }
     $arrContent = array();
     while ($Content->next()) {
         $arrContent[$Content->module] = $Content->pid;
     }
     $Article = \ArticleModel::findBy(array("tl_article.id IN ('" . implode("','", $arrContent) . "')"), array());
     if (empty($Article)) {
         return array();
     }
     $finishedIDs = $arrPages = array();
     while ($Article->next()) {
         // $root = $this->getRootPage($Article->pid);
         $domain = \Environment::get('base');
         $strLanguage = 'de';
         $objPages = $Article->getRelated('pid');
         $ReaderId = false;
         foreach ($arrContent as $module => $mid) {
             if ($mid == $Article->id) {
                 $ReaderId = $module;
             }
         }
         foreach ($arrReader[$ReaderId] as $event_id) {
             if (in_array($event_id, $finishedIDs)) {
                 continue;
             }
             if (!empty($arrEvent[$event_id])) {
                 foreach ($arrEvent[$event_id] as $event_domain) {
                     $event_domain = str_replace('.html', '', $event_domain);
                     $arrPages['de'][] = $domain . static::generateFrontendUrl($objPages->row(), substr($event_domain, strpos($event_domain, '/')), $strLanguage);
                 }
             }
             $finishedIDs[] = $event_id;
         }
     }
     return $arrPages;
 }
 /**
  * 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) . "&amp;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) . "&amp;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;
 }
Esempio n. 12
0
 /**
  * Export an event as iCalendar (ics)
  */
 public function generateIcal($eventID)
 {
     $ical = new \vcalendar();
     $ical->setConfig('ical_' . $this->id);
     $ical->setProperty('method', 'PUBLISH');
     $ical->setProperty("X-WR-TIMEZONE", $GLOBALS['TL_CONFIG']['timeZone']);
     $time = time();
     // Get event
     $objEvent = \CalendarEventsModel::findByPk($eventID);
     $vevent = new \vevent();
     if ($objEvent->addTime) {
         $vevent->setProperty('dtstart', array('year' => date('Y', $objEvent->startTime), 'month' => date('m', $objEvent->startTime), 'day' => date('d', $objEvent->startTime), 'hour' => date('H', $objEvent->startTime), 'min' => date('i', $objEvent->startTime), 'sec' => 0));
         $vevent->setProperty('dtend', array('year' => date('Y', $objEvent->endTime), 'month' => date('m', $objEvent->endTime), 'day' => date('d', $objEvent->endTime), 'hour' => date('H', $objEvent->endTime), 'min' => date('i', $objEvent->endTime), 'sec' => 0));
     } else {
         $vevent->setProperty('dtstart', date('Ymd', $objEvent->startDate), array('VALUE' => 'DATE'));
         if (!strlen($objEvent->endDate) || $objEvent->endDate == 0) {
             $vevent->setProperty('dtend', date('Ymd', $objEvent->startDate + 24 * 60 * 60), array('VALUE' => 'DATE'));
         } else {
             $vevent->setProperty('dtend', date('Ymd', $objEvent->endDate + 24 * 60 * 60), array('VALUE' => 'DATE'));
         }
     }
     $vevent->setProperty('summary', $objEvent->title, ENT_QUOTES, 'UTF-8');
     $vevent->setProperty('description', strip_tags($objEvent->details ? $objEvent->details : $objEvent->teaser));
     if ($objEvent->recurring) {
         $count = 0;
         $arrRepeat = deserialize($objEvent->repeatEach);
         $arg = $arrRepeat['value'];
         $unit = $arrRepeat['unit'];
         if ($arg == 1) {
             $unit = substr($unit, 0, -1);
         }
         $strtotime = '+ ' . $arg . ' ' . $unit;
         $newstart = strtotime($strtotime, $objEvent->startTime);
         $newend = strtotime($strtotime, $objEvent->endTime);
         $freq = 'YEARLY';
         switch ($arrRepeat['unit']) {
             case 'days':
                 $freq = 'DAILY';
                 break;
             case 'weeks':
                 $freq = 'WEEKLY';
                 break;
             case 'months':
                 $freq = 'MONTHLY';
                 break;
             case 'years':
                 $freq = 'YEARLY';
                 break;
         }
         $rrule = array('FREQ' => $freq);
         if ($objEvent->recurrences > 0) {
             $rrule['count'] = $objEvent->recurrences;
         }
         if ($arg > 1) {
             $rrule['INTERVAL'] = $arg;
         }
         $vevent->setProperty('rrule', $rrule);
     }
     /*
      * begin module event_recurrences handling
      */
     if ($objEvent->repeatExecptions) {
         $arrSkipDates = deserialize($objEvent->repeatExecptions);
         foreach ($arrSkipDates as $skipDate) {
             $exTStamp = strtotime($skipDate);
             $exdate = array(array(date('Y', $exTStamp), date('m', $exTStamp), date('d', $exTStamp), date('H', $objEvent->startTime), date('i', $objEvent->startTime), date('s', $objEvent->startTime)));
             $vevent->setProperty('exdate', $exdate);
         }
     }
     /*
      * end module event_recurrences handling
      */
     $ical->setComponent($vevent);
     $ical->setConfig("FILENAME", urlencode($objEvent->title) . ".ics");
     $ical->returnCalendar();
 }
 /**
  * Replace insert tags with their values
  *
  * @param string  $strBuffer The text with the tags to be replaced
  * @param boolean $blnCache  If false, non-cacheable tags will be replaced
  *
  * @return string The text with the replaced tags
  */
 public function replace($strBuffer, $blnCache = true)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Preserve insert tags
     if (\Config::get('disableInsertTags')) {
         return \StringUtil::restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/{{(([^{}]*|(?R))*)}}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     $strBuffer = '';
     // Create one cache per cache setting (see #7700)
     static $arrItCache;
     $arrCache =& $arrItCache[$blnCache];
     for ($_rit = 0, $_cnt = count($tags); $_rit < $_cnt; $_rit += 3) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         // Run the replacement again if there are more tags (see #4402)
         if (strpos($strTag, '{{') !== false) {
             $strTag = $this->replace($strTag, $blnCache);
         }
         $flags = explode('|', $strTag);
         $tag = array_shift($flags);
         $elements = explode('::', $tag);
         // Load the value from cache
         if (isset($arrCache[$strTag]) && !in_array('refresh', $flags)) {
             $strBuffer .= $arrCache[$strTag];
             continue;
         }
         // Skip certain elements if the output will be cached
         if ($blnCache) {
             if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'post' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || $elements[0] == 'toggle_view' || strncmp($elements[0], 'cache_', 6) === 0 || in_array('uncached', $flags)) {
                 $strBuffer .= '{{' . $strTag . '}}';
                 continue;
             }
         }
         $arrCache[$strTag] = '';
         // Replace the tag
         switch (strtolower($elements[0])) {
             // Date
             case 'date':
                 $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('dateFormat'));
                 break;
                 // Accessibility tags
             // Accessibility tags
             case 'lang':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '</span>';
                 } elseif ($objPage->outputFormat == 'xhtml') {
                     $arrCache[$strTag] = '<span lang="' . $elements[1] . '" xml:lang="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // Line break
             // Line break
             case 'br':
                 $arrCache[$strTag] = '<br' . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \StringUtil::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" title="' . $strEmail . '" class="email">';
                         break;
                     case 'email_url':
                         $arrCache[$strTag] = $strEmail;
                         break;
                 }
                 break;
                 // Label tags
             // Label tags
             case 'label':
                 $keys = explode(':', $elements[1]);
                 if (count($keys) < 2) {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $file = $keys[0];
                 // Map the key (see #7217)
                 switch ($file) {
                     case 'CNT':
                         $file = 'countries';
                         break;
                     case 'LNG':
                         $file = 'languages';
                         break;
                     case 'MOD':
                     case 'FMD':
                         $file = 'modules';
                         break;
                     case 'FFL':
                         $file = 'tl_form_field';
                         break;
                     case 'CACHE':
                         $file = 'tl_page';
                         break;
                     case 'XPL':
                         $file = 'explain';
                         break;
                     case 'XPT':
                         $file = 'exception';
                         break;
                     case 'MSC':
                     case 'ERR':
                     case 'CTE':
                     case 'PTY':
                     case 'FOP':
                     case 'CHMOD':
                     case 'DAYS':
                     case 'MONTHS':
                     case 'UNITS':
                     case 'CONFIRM':
                     case 'DP':
                     case 'COLS':
                         $file = 'default';
                         break;
                 }
                 \System::loadLanguageFile($file);
                 if (count($keys) == 2) {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]];
                 } else {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]];
                 }
                 break;
                 // Front end user
             // Front end user
             case 'user':
                 if (FE_USER_LOGGED_IN) {
                     $this->import('FrontendUser', 'User');
                     $value = $this->User->{$elements[1]};
                     if ($value == '') {
                         $arrCache[$strTag] = $value;
                         break;
                     }
                     $this->loadDataContainer('tl_member');
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $value = deserialize($value);
                     // Decrypt the value
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['encrypt']) {
                         $value = \Encryption::decrypt($value);
                     }
                     $rgxp = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['rgxp'];
                     $opts = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['options'];
                     $rfrc = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['reference'];
                     if ($rgxp == 'date') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('dateFormat'), $value);
                     } elseif ($rgxp == 'time') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('timeFormat'), $value);
                     } elseif ($rgxp == 'datim') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('datimFormat'), $value);
                     } elseif (is_array($value)) {
                         $arrCache[$strTag] = implode(', ', $value);
                     } elseif (is_array($opts) && array_is_assoc($opts)) {
                         $arrCache[$strTag] = isset($opts[$value]) ? $opts[$value] : $value;
                     } elseif (is_array($rfrc)) {
                         $arrCache[$strTag] = isset($rfrc[$value]) ? is_array($rfrc[$value]) ? $rfrc[$value][0] : $rfrc[$value] : $value;
                     } else {
                         $arrCache[$strTag] = $value;
                     }
                     // Convert special characters (see #1890)
                     $arrCache[$strTag] = specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
             case 'link_target':
             case 'link_name':
                 $strTarget = null;
                 // Back link
                 if ($elements[1] == 'back') {
                     $strUrl = 'javascript:history.go(-1)';
                     $strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
                     // No language files if the page is cached
                     if (!strlen($strTitle)) {
                         $strTitle = 'Go back';
                     }
                     $strName = $strTitle;
                 } elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
                     $strUrl = $elements[1];
                     $strTitle = $elements[1];
                     $strName = str_replace(array('http://', 'https://'), '', $elements[1]);
                 } else {
                     // User login page
                     if ($elements[1] == 'login') {
                         if (!FE_USER_LOGGED_IN) {
                             break;
                         }
                         $this->import('FrontendUser', 'User');
                         $elements[1] = $this->User->loginPage;
                     }
                     $objNextPage = \PageModel::findByIdOrAlias($elements[1]);
                     if ($objNextPage === null) {
                         break;
                     }
                     // Page type specific settings (thanks to Andreas Schempp)
                     switch ($objNextPage->type) {
                         case 'redirect':
                             $strUrl = $this->replaceInsertTags($objNextPage->url);
                             // see #6765
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \StringUtil::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if ($objNextPage->jumpTo) {
                                 /** @var \PageModel $objNext */
                                 $objNext = $objNextPage->getRelated('jumpTo');
                             } else {
                                 $objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
                             }
                             if ($objNext !== null) {
                                 $strForceLang = null;
                                 $objNext->loadDetails();
                                 // Check the target page language (see #4706)
                                 if (\Config::get('addLanguageToUrl')) {
                                     $strForceLang = $objNext->language;
                                 }
                                 $strUrl = $this->generateFrontendUrl($objNext->row(), null, $strForceLang, true);
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             $strForceLang = null;
                             $objNextPage->loadDetails();
                             // Check the target page language (see #4706, #5465)
                             if (\Config::get('addLanguageToUrl')) {
                                 $strForceLang = $objNextPage->language;
                             }
                             $strUrl = $this->generateFrontendUrl($objNextPage->row(), null, $strForceLang, true);
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? $objPage->outputFormat == 'xhtml' ? LINK_NEW_WINDOW : ' target="_blank"' : '';
                     $strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'link':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, specialchars($strTitle), $strTarget, $strName);
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                     case 'link_name':
                         $arrCache[$strTag] = $strName;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = $this->replaceInsertTags(ltrim($strOutput), $blnCache);
                 } else {
                     $arrCache[$strTag] = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $elements[1]) . '</p>';
                 }
                 break;
                 // Insert content element
             // Insert content element
             case 'insert_content':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getContentElement($elements[1]), $blnCache);
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getFrontendModule($elements[1]), $blnCache);
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->replaceInsertTags($this->getForm($elements[1]), $blnCache);
                 break;
                 // Article
             // Article
             case 'article':
             case 'article_open':
             case 'article_url':
             case 'article_title':
                 if (($objArticle = \ArticleModel::findByIdOrAlias($elements[1])) === null || ($objPid = $objArticle->getRelated('pid')) === null) {
                     break;
                 }
                 $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && strlen($objArticle->alias) ? $objArticle->alias : $objArticle->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objArticle->title), $objArticle->title);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // FAQ
             // FAQ
             case 'faq':
             case 'faq_open':
             case 'faq_url':
             case 'faq_title':
                 if (($objFaq = \FaqModel::findByIdOrAlias($elements[1])) === null || ($objPid = $objFaq->getRelated('pid')) === null || ($objJumpTo = $objPid->getRelated('jumpTo')) === null) {
                     break;
                 }
                 $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objFaq->alias != '' ? $objFaq->alias : $objFaq->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'faq':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objFaq->question), $objFaq->question);
                         break;
                     case 'faq_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objFaq->question));
                         break;
                     case 'faq_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'faq_title':
                         $arrCache[$strTag] = specialchars($objFaq->question);
                         break;
                 }
                 break;
                 // News
             // News
             case 'news':
             case 'news_open':
             case 'news_url':
             case 'news_title':
                 if (($objNews = \NewsModel::findByIdOrAlias($elements[1])) === null) {
                     break;
                 }
                 $strUrl = '';
                 if ($objNews->source == 'external') {
                     $strUrl = $objNews->url;
                 } elseif ($objNews->source == 'internal') {
                     if (($objJumpTo = $objNews->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row());
                     }
                 } elseif ($objNews->source == 'article') {
                     if (($objArticle = \ArticleModel::findByPk($objNews->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                     }
                 } else {
                     if (($objArchive = $objNews->getRelated('pid')) !== null && ($objJumpTo = $objArchive->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objNews->alias != '' ? $objNews->alias : $objNews->id));
                     }
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'news':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objNews->headline), $objNews->headline);
                         break;
                     case 'news_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objNews->headline));
                         break;
                     case 'news_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'news_title':
                         $arrCache[$strTag] = specialchars($objNews->headline);
                         break;
                 }
                 break;
                 // Events
             // Events
             case 'event':
             case 'event_open':
             case 'event_url':
             case 'event_title':
                 if (($objEvent = \CalendarEventsModel::findByIdOrAlias($elements[1])) === null) {
                     break;
                 }
                 $strUrl = '';
                 if ($objEvent->source == 'external') {
                     $strUrl = $objEvent->url;
                 } elseif ($objEvent->source == 'internal') {
                     if (($objJumpTo = $objEvent->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row());
                     }
                 } elseif ($objEvent->source == 'article') {
                     if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                     }
                 } else {
                     if (($objCalendar = $objEvent->getRelated('pid')) !== null && ($objJumpTo = $objCalendar->getRelated('jumpTo')) !== null) {
                         $strUrl = $this->generateFrontendUrl($objJumpTo->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/events/') . (!\Config::get('disableAlias') && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id));
                     }
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'event':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, specialchars($objEvent->title), $objEvent->title);
                         break;
                     case 'event_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objEvent->title));
                         break;
                     case 'event_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'event_title':
                         $arrCache[$strTag] = specialchars($objEvent->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::toHtml5($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     }
                 }
                 break;
                 // News teaser
             // News teaser
             case 'news_teaser':
                 $objTeaser = \NewsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::toHtml5($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     }
                 }
                 break;
                 // Event teaser
             // Event teaser
             case 'event_teaser':
                 $objTeaser = \CalendarEventsModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     if ($objPage->outputFormat == 'xhtml') {
                         $arrCache[$strTag] = \StringUtil::toXhtml($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     } else {
                         $arrCache[$strTag] = \StringUtil::toHtml5($this->replaceInsertTags($objTeaser->teaser, $blnCache));
                     }
                 }
                 break;
                 // News feed URL
             // News feed URL
             case 'news_feed':
                 $objFeed = \NewsFeedModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . 'share/' . $objFeed->alias . '.xml';
                 }
                 break;
                 // Calendar feed URL
             // Calendar feed URL
             case 'calendar_feed':
                 $objFeed = \CalendarFeedModel::findByPk($elements[1]);
                 if ($objFeed !== null) {
                     $arrCache[$strTag] = $objFeed->feedBase . 'share/' . $objFeed->alias . '.xml';
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $strQuery = "SELECT MAX(tstamp) AS tc";
                 if (in_array('news', \ModuleLoader::getActive())) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_news) AS tn";
                 }
                 if (in_array('calendar', \ModuleLoader::getActive())) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_calendar_events) AS te";
                 }
                 $strQuery .= " FROM tl_content";
                 $objUpdate = \Database::getInstance()->query($strQuery);
                 if ($objUpdate->numRows) {
                     $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('datimFormat'), max($objUpdate->tc, $objUpdate->tn, $objUpdate->te));
                 }
                 break;
                 // Version
             // Version
             case 'version':
                 $arrCache[$strTag] = VERSION . '.' . BUILD;
                 break;
                 // Request token
             // Request token
             case 'request_token':
                 $arrCache[$strTag] = REQUEST_TOKEN;
                 break;
                 // POST data
             // POST data
             case 'post':
                 $arrCache[$strTag] = \Input::post($elements[1]);
                 break;
                 // Mobile/desktop toggle (see #6469)
             // Mobile/desktop toggle (see #6469)
             case 'toggle_view':
                 $strUrl = ampersand(\Environment::get('request'));
                 $strGlue = strpos($strUrl, '?') === false ? '?' : '&amp;';
                 if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=desktop" class="toggle_desktop" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['toggleDesktop'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleDesktop'][0] . '</a>';
                 } else {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=mobile" class="toggle_mobile" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['toggleMobile'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleMobile'][0] . '</a>';
                 }
                 break;
                 // Conditional tags (if)
             // Conditional tags (if)
             case 'iflng':
                 if ($elements[1] != '' && $elements[1] != $objPage->language) {
                     for (; $_rit < $_cnt; $_rit += 3) {
                         if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) {
                             break;
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Conditional tags (if not)
             // Conditional tags (if not)
             case 'ifnlng':
                 if ($elements[1] != '') {
                     $langs = trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for (; $_rit < $_cnt; $_rit += 3) {
                             if ($tags[$_rit + 1] == 'ifnlng') {
                                 break;
                             }
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Environment
             // Environment
             case 'env':
                 switch ($elements[1]) {
                     case 'host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('host'));
                         break;
                     case 'http_host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost'));
                         break;
                     case 'url':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('url'));
                         break;
                     case 'path':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('base'));
                         break;
                     case 'request':
                         $arrCache[$strTag] = \Environment::get('indexFreeRequest');
                         break;
                     case 'ip':
                         $arrCache[$strTag] = \Environment::get('ip');
                         break;
                     case 'referer':
                         $arrCache[$strTag] = $this->getReferer(true);
                         break;
                     case 'files_url':
                         $arrCache[$strTag] = TL_FILES_URL;
                         break;
                     case 'assets_url':
                     case 'plugins_url':
                     case 'script_url':
                         $arrCache[$strTag] = TL_ASSETS_URL;
                         break;
                 }
                 break;
                 // Page
             // Page
             case 'page':
                 if ($elements[1] == 'pageTitle' && $objPage->pageTitle == '') {
                     $elements[1] = 'title';
                 } elseif ($elements[1] == 'parentPageTitle' && $objPage->parentPageTitle == '') {
                     $elements[1] = 'parentTitle';
                 } elseif ($elements[1] == 'mainPageTitle' && $objPage->mainPageTitle == '') {
                     $elements[1] = 'mainTitle';
                 }
                 // Do not use specialchars() here (see #4687)
                 $arrCache[$strTag] = $objPage->{$elements[1]};
                 break;
                 // User agent
             // User agent
             case 'ua':
                 $ua = \Environment::get('agent');
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = $ua->{$elements[1]};
                 } else {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Acronyms
             // Acronyms
             case 'acronym':
                 if ($objPage->outputFormat == 'xhtml') {
                     if ($elements[1] != '') {
                         $arrCache[$strTag] = '<acronym title="' . $elements[1] . '">';
                     } else {
                         $arrCache[$strTag] = '</acronym>';
                     }
                     break;
                 }
                 // NO break;
                 // Abbreviations
             // NO break;
             // Abbreviations
             case 'abbr':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
             case 'picture':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 $size = null;
                 $strTemplate = 'picture_default';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         list($key, $value) = explode('=', $strParam);
                         switch ($key) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'alt':
                                 $alt = specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $value;
                                 break;
                             case 'size':
                                 $size = (int) $value;
                                 break;
                             case 'template':
                                 $strTemplate = preg_replace('/[^a-z0-9_]/i', '', $value);
                                 break;
                         }
                     }
                     $strFile = $arrChunks[0];
                 }
                 if (\Validator::isUuid($strFile)) {
                     // Handle UUIDs
                     $objFile = \FilesModel::findByUuid($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } elseif (is_numeric($strFile)) {
                     // Handle numeric IDs (see #4805)
                     $objFile = \FilesModel::findByPk($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } else {
                     // Check the path
                     if (\Validator::isInsecurePath($strFile)) {
                         throw new \RuntimeException('Invalid path ' . $strFile);
                     }
                 }
                 // Check the maximum image width
                 if (\Config::get('maxImageWidth') > 0 && $width > \Config::get('maxImageWidth')) {
                     $width = \Config::get('maxImageWidth');
                     $height = null;
                 }
                 // Generate the thumbnail image
                 try {
                     // Image
                     if (strtolower($elements[0]) == 'image') {
                         $dimensions = '';
                         $imageObj = \Image::create($strFile, array($width, $height, $mode));
                         $src = $imageObj->executeResize()->getResizedPath();
                         $objFile = new \File(rawurldecode($src), true);
                         // Add the image dimensions
                         if (($imgSize = $objFile->imageSize) !== false) {
                             $dimensions = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"';
                         }
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . ($objPage->outputFormat == 'xhtml' ? ' />' : '>');
                     } else {
                         $picture = \Picture::create($strFile, array(0, 0, $size))->getTemplateData();
                         $picture['alt'] = $alt;
                         $picture['class'] = $class;
                         $pictureTemplate = new \FrontendTemplate($strTemplate);
                         $pictureTemplate->setData($picture);
                         $arrCache[$strTag] = $pictureTemplate->parse();
                     }
                     // Add a lightbox link
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0 || $objPage->outputFormat == 'xhtml') {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '>' . $arrCache[$strTag] . '</a>';
                     }
                 } catch (\Exception $e) {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Files (UUID or template path)
             // Files (UUID or template path)
             case 'file':
                 if (\Validator::isUuid($elements[1])) {
                     $objFile = \FilesModel::findByUuid($elements[1]);
                     if ($objFile !== null) {
                         $arrCache[$strTag] = $objFile->path;
                         break;
                     }
                 }
                 $arrGet = $_GET;
                 \Input::resetCache();
                 $strFile = $elements[1];
                 // Take arguments and add them to the $_GET array
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]));
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         $arrParam = explode('=', $strParam);
                         $_GET[$arrParam[0]] = $arrParam[1];
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Check the path
                 if (\Validator::isInsecurePath($strFile)) {
                     throw new \RuntimeException('Invalid path ' . $strFile);
                 }
                 // Include .php, .tpl, .xhtml and .html5 files
                 if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
                     ob_start();
                     include TL_ROOT . '/templates/' . $strFile;
                     $arrCache[$strTag] = ob_get_contents();
                     ob_end_clean();
                 }
                 $_GET = $arrGet;
                 \Input::resetCache();
                 break;
                 // HOOK: pass unknown tags to callback functions
             // HOOK: pass unknown tags to callback functions
             default:
                 if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
                     foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
                         $this->import($callback[0]);
                         $varValue = $this->{$callback[0]}->{$callback[1]}($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt);
                         // see #6672
                         // Replace the tag and stop the loop
                         if ($varValue !== false) {
                             $arrCache[$strTag] = $varValue;
                             break;
                         }
                     }
                 }
                 if (\Config::get('debugMode')) {
                     $GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag;
                 }
                 break;
         }
         // Handle the flags
         if (!empty($flags)) {
             foreach ($flags as $flag) {
                 switch ($flag) {
                     case 'addslashes':
                     case 'stripslashes':
                     case 'standardize':
                     case 'ampersand':
                     case 'specialchars':
                     case 'nl2br':
                     case 'nl2br_pre':
                     case 'strtolower':
                     case 'utf8_strtolower':
                     case 'strtoupper':
                     case 'utf8_strtoupper':
                     case 'ucfirst':
                     case 'lcfirst':
                     case 'ucwords':
                     case 'trim':
                     case 'rtrim':
                     case 'ltrim':
                     case 'utf8_romanize':
                     case 'strrev':
                     case 'urlencode':
                     case 'rawurlencode':
                         $arrCache[$strTag] = $flag($arrCache[$strTag]);
                         break;
                     case 'encodeEmail':
                     case 'decodeEntities':
                         $arrCache[$strTag] = \StringUtil::$flag($arrCache[$strTag]);
                         break;
                     case 'number_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
                         break;
                     case 'currency_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
                         break;
                     case 'readable_size':
                         $arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
                         break;
                     case 'flatten':
                         if (!is_array($arrCache[$strTag])) {
                             break;
                         }
                         $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag]));
                         $result = array();
                         foreach ($it as $leafValue) {
                             $keys = array();
                             foreach (range(0, $it->getDepth()) as $depth) {
                                 $keys[] = $it->getSubIterator($depth)->key();
                             }
                             $result[] = implode('.', $keys) . ': ' . $leafValue;
                         }
                         $arrCache[$strTag] = implode(', ', $result);
                         break;
                         // HOOK: pass unknown flags to callback functions
                     // HOOK: pass unknown flags to callback functions
                     default:
                         if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
                             foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
                                 $this->import($callback[0]);
                                 $varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
                                 // see #5806
                                 // Replace the tag and stop the loop
                                 if ($varValue !== false) {
                                     $arrCache[$strTag] = $varValue;
                                     break;
                                 }
                             }
                         }
                         if (\Config::get('debugMode')) {
                             $GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
                         }
                         break;
                 }
             }
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return \StringUtil::restoreBasicEntities($strBuffer);
 }
Esempio n. 14
0
 /**
  * Get all events of a certain period
  * @param array
  * @param integer
  * @param integer
  * @return array
  */
 protected function getAllEvents($arrCalendars, $intStart, $intEnd)
 {
     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 = \CalendarEventsModel::findCurrentByPid($id, $intStart, $intEnd);
         if ($objEvents === null) {
             continue;
         }
         while ($objEvents->next()) {
             $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $strUrl, $intStart, $intEnd, $id);
             // Recurring events
             if ($objEvents->recurring) {
                 $count = 0;
                 $arrRepeat = deserialize($objEvents->repeatEach);
                 $strtotime = '+ ' . $arrRepeat['value'] . ' ' . $arrRepeat['unit'];
                 if ($arrRepeat['value'] < 1) {
                     continue;
                 }
                 while ($objEvents->endTime < $intEnd) {
                     if ($objEvents->recurrences > 0 && $count++ >= $objEvents->recurrences) {
                         break;
                     }
                     $objEvents->startTime = strtotime($strtotime, $objEvents->startTime);
                     $objEvents->endTime = strtotime($strtotime, $objEvents->endTime);
                     // Skip events outside the scope
                     if ($objEvents->endTime < $intStart || $objEvents->startTime > $intEnd) {
                         continue;
                     }
                     $this->addEvent($objEvents, $objEvents->startTime, $objEvents->endTime, $strUrl, $intStart, $intEnd, $id);
                 }
             }
         }
     }
     // 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;
 }
 /**
  * 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);
 }
Esempio n. 16
0
 /**
  * Add events to the indexer
  * @param array
  * @param integer
  * @param boolean
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $time = time();
     $arrProcessed = array();
     // Get all calendars
     $objCalendar = \CalendarModel::findByProtected('');
     // Walk through each calendar
     if ($objCalendar !== null) {
         while ($objCalendar->next()) {
             // Skip calendars without target page
             if (!$objCalendar->jumpTo) {
                 continue;
             }
             // Skip calendars outside the root nodes
             if (!empty($arrRoot) && !in_array($objCalendar->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objCalendar->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objCalendar->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 // The target page has not been published (see #5520)
                 if (!$objParent->published || $objParent->start != '' && $objParent->start > $time || $objParent->stop != '' && $objParent->stop < $time) {
                     continue;
                 }
                 // The target page is exempt from the sitemap (see #6418)
                 if ($blnIsSitemap && $objParent->sitemap == 'map_never') {
                     continue;
                 }
                 // Set the domain (see #6421)
                 $domain = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . TL_PATH . '/';
                 // Generate the URL
                 $arrProcessed[$objCalendar->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objCalendar->jumpTo];
             // Get the items
             $objEvents = \CalendarEventsModel::findPublishedDefaultByPid($objCalendar->id);
             if ($objEvents !== null) {
                 while ($objEvents->next()) {
                     $arrPages[] = sprintf($strUrl, $objEvents->alias != '' && !\Config::get('disableAlias') ? $objEvents->alias : $objEvents->id);
                 }
             }
         }
     }
     return $arrPages;
 }
 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;
 }
Esempio n. 18
0
 protected function getEvent($id = false)
 {
     $tmpArr = array();
     $i = 0;
     $id = $id ? $id : \Input::get($this->request['id']) ? \Input::get($this->request['id']) : false;
     if ($id) {
         $result = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($id, array($this->settings['calendar']));
     } else {
         list($start, $end, $empty) = $this->getDatesFromFormat($this->settings['eventFormat']);
         $result = \CalendarEventsModel::findCurrentByPid($this->settings['calendar'], $start, $end);
     }
     if ($result) {
         if ($result instanceof \Model\Collection) {
             while ($result->next()) {
                 $tmpArr[] = $this->fillEventArray($result, ++$i);
             }
         } else {
             $tmpArr = $this->fillEventArray($result, 1);
         }
     } else {
         $tmpArr = false;
     }
     return $tmpArr;
 }
Esempio n. 19
0
 /**
  * Generate a URL and return it as string
  *
  * @param \CalendarEventsModel $objEvent
  * @param string               $strUrl
  *
  * @return string
  */
 protected function generateEventUrl($objEvent, $strUrl)
 {
     switch ($objEvent->source) {
         // Link to an external page
         case 'external':
             if (substr($objEvent->url, 0, 7) == 'mailto:') {
                 return \String::encodeEmail($objEvent->url);
             } else {
                 return ampersand($objEvent->url);
             }
             break;
             // Link to an internal page
         // Link to an internal page
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
                 return ampersand($this->generateFrontendUrl($objTarget->row()));
             }
             break;
             // Link to an article
         // Link to an article
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 return ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
             }
             break;
     }
     // Link to the default page
     return ampersand(sprintf($strUrl, !\Config::get('disableAlias') && $objEvent->alias != '' ? $objEvent->alias : $objEvent->id));
 }
Esempio n. 20
0
 public function getIncludeItems(\DataContainer $dc)
 {
     $arrReturn = array();
     $strTable = '';
     $strDateKey = '';
     $strTitleKeyArchive = '';
     $strTitleKeyItem = '';
     $strPatternArchiveUrl = '%s';
     $strPatternItemUrl = '%s';
     if (!$dc->activeRecord->type) {
         return $arrReturn;
     }
     switch ($dc->activeRecord->type) {
         case 'nl_news':
             $strTable = 'tl_news';
             $strDateKey = 'date';
             $strTitleKeyItem = 'headline';
             $strTitleKeyArchive = 'title';
             $strPatternArchiveUrl = 'contao/main.php?do=news&id=%s&act=edit&popup=1&nb=1&rt=%s';
             $strPatternItemUrl = 'contao/main.php?do=news&id=%s&act=edit&popup=1&nb=1&rt=%s&table=%s';
             $objItems = \NewsModel::findAll(array('order' => $strTable . '.' . $strDateKey));
             break;
         case 'nl_events':
             $strTable = 'tl_calendar_events';
             $strDateKey = 'startDate';
             $strTitleKeyItem = 'title';
             $strTitleKeyArchive = 'title';
             $strPatternArchiveUrl = 'contao/main.php?do=calendar&id=%s&act=edit&popup=1&nb=1&rt=%s';
             $strPatternItemUrl = 'contao/main.php?do=calendar&id=%s&act=edit&popup=1&nb=1&rt=%s&table=%s';
             $objItems = \CalendarEventsModel::findAll(array('order' => $strTable . '.' . $strDateKey));
             break;
         default:
             return $arrReturn;
             break;
     }
     if (!is_null($objItems)) {
         foreach ($objItems as $objItem) {
             $objArchive = $objItem->getRelated('pid');
             $strDoArchive = ampersand(sprintf($strPatternArchiveUrl, $objItem->pid, REQUEST_TOKEN));
             $strDoItem = ampersand(sprintf($strPatternItemUrl, $objItem->id, REQUEST_TOKEN, $strTable));
             $strDateField = \Date::parse(\Config::get('dateFormat') ?: 'd.m.Y', $objItem->{$strDateKey}) . ' - ';
             $time = time();
             //"($t.start='' OR $t.start<$time) AND ($t.stop='' OR $t.stop>$time) AND $t.published=1";
             $blnPublished = (!$objItem->start || $objItem->start < $time) && (!$objItem->stop || $objItem->stop > $time) && $objItem->published;
             $arrReturn[$objItem->id] = sprintf('%s<strong><a%s href="%s" title="%s" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false">%s</a></strong> (<a href="%s" title="%s" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false">%s</a>)', $strDateField, $blnPublished ? '' : ' style="color:#c33"', $strDoItem, sprintf(specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $objItem->id), sprintf(specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $objItem->id), $objItem->{$strTitleKeyItem}, $strDoArchive, sprintf(specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $objArchive->id), sprintf(specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $objArchive->id), $objArchive->{$strTitleKeyArchive});
         }
     }
     return $arrReturn;
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // Respond to month
     if (\Input::get('month')) {
         $this->Date = new \Date(\Input::get('month') . '01', 'Ymd');
     } elseif (\Input::get('week')) {
         $selYear = (int) substr(\Input::get('week'), 0, 4);
         $selWeek = (int) substr(\Input::get('week'), -2);
         $selDay = $selWeek == 1 ? 4 : 1;
         $dt = new \DateTime();
         $dt->setISODate($selYear, $selWeek, $selDay);
         $this->Date = new \Date($dt->format('Ymd'), 'Ymd');
         unset($dt);
     } elseif (\Input::get('day')) {
         $this->Date = new \Date(\Input::get('day'), 'Ymd');
     } else {
         $this->Date = new \Date();
     }
     // Get the Year and the week of the given date
     $intYear = (int) date('Y', $this->Date->tstamp);
     $intWeek = (int) date('W', $this->Date->tstamp);
     $dt = new \DateTime();
     // Set date to the first day of the given week
     $dt->setISODate($intYear, $intWeek, 1);
     $newDate = new Date($dt->format('Ymd'), 'Ymd');
     $newYear = date('Y', $newDate->tstamp);
     $newMonth = date('m', $newDate->tstamp);
     $newDay = (int) date('d', $newDate->tstamp);
     $this->weekBegin = mktime(0, 0, 0, $newMonth, $newDay, $newYear);
     // Set date to the last day of the given week
     $dt->setISODate($intYear, $intWeek, 7);
     $newDate = new Date($dt->format('Ymd'), 'Ymd');
     $newYear = date('Y', $newDate->tstamp);
     $newMonth = date('m', $newDate->tstamp);
     $newDay = (int) date('d', $newDate->tstamp);
     $this->weekEnd = mktime(23, 59, 59, $newMonth, $newDay, $newYear);
     unset($dt);
     // Get total count of weeks of the year
     if (($weeksTotal = date('W', mktime(0, 0, 0, 12, 31, $intYear))) == 1) {
         $weeksTotal = date('W', mktime(0, 0, 0, 12, 24, $intYear));
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('YW', $objMinMax->dateFrom);
     $intRightBoundary = date('YW', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     $objTemplate = new \FrontendTemplate($this->calext_ctemplate ? $this->calext_ctemplate : 'calext_timetable');
     $objTemplate->intYear = $intYear;
     $objTemplate->intWeek = $intWeek;
     $objTemplate->weekBegin = $this->weekBegin;
     $objTemplate->weekEnd = $this->weekEnd;
     $objTemplate->cal_times = $this->cal_times;
     $objTemplate->use_navigation = $this->use_navigation;
     $objTemplate->linkCurrent = $this->linkCurrent;
     // display the navigation if selected
     if ($this->use_navigation) {
         // Get the current year and the week
         if ($this->linkCurrent) {
             $currYear = date('Y');
             $currWeek = (int) date('W');
             $lblCurrent = $GLOBALS['TL_LANG']['MSC']['curr_week'];
             $objTemplate->currHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $currYear . str_pad($currWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->currTitle = specialchars($lblCurrent);
             $objTemplate->currLink = $lblCurrent;
             $objTemplate->currLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Previous week
         $prevWeek = $intWeek == 1 ? $weeksTotal : $intWeek - 1;
         $prevYear = $intWeek == 1 ? $intYear - 1 : $intYear;
         $lblPrevious = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $prevWeek . ' ' . $prevYear;
         $intPrevYm = intval($prevYear . str_pad($prevWeek, 2, 0, STR_PAD_LEFT));
         if ($intPrevYm >= $intLeftBoundary) {
             $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $prevYear . str_pad($prevWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->prevTitle = specialchars($lblPrevious);
             $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
             $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Current week
         $dateInfo = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $this->weekBegin) . ' - ' . $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $this->weekEnd);
         $objTemplate->current = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $intWeek . ' ' . $intYear;
         // Next month
         $nextWeek = $intWeek == $weeksTotal ? 1 : $intWeek + 1;
         $nextYear = $intWeek == $weeksTotal ? $intYear + 1 : $intYear;
         $lblNext = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $nextWeek . ' ' . $nextYear;
         $intNextYm = $nextYear . str_pad($nextWeek, 2, 0, STR_PAD_LEFT);
         // Only generate a link if there are events (see #4160)
         if ($intNextYm <= $intRightBoundary) {
             $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $nextYear . str_pad($nextWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->nextTitle = specialchars($lblNext);
             $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
             $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
         }
     }
     // Set week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     list($objTemplate->weekday, $objTemplate->times) = $this->compileDays();
     $this->Template->calendar = $objTemplate->parse();
 }
Esempio n. 22
0
 /**
  * Add an event to the array of active events
  *
  * @param CalendarEventsModel $objEvent
  * @param integer             $intStart
  * @param integer             $intEnd
  * @param string              $strUrl
  * @param string              $strBase
  */
 protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase = '')
 {
     if ($intEnd < time()) {
         return;
     }
     /** @var PageModel $objPage */
     global $objPage;
     // Called in the back end (see #4026)
     if ($objPage === null) {
         $objPage = new \stdClass();
         $objPage->dateFormat = \Config::get('dateFormat');
         $objPage->datimFormat = \Config::get('datimFormat');
         $objPage->timeFormat = \Config::get('timeFormat');
     }
     $intKey = date('Ymd', $intStart);
     $span = self::calculateSpan($intStart, $intEnd);
     $format = $objEvent->addTime ? 'datimFormat' : 'dateFormat';
     // Add date
     if ($span > 0) {
         $title = \Date::parse($objPage->{$format}, $intStart) . ' – ' . \Date::parse($objPage->{$format}, $intEnd);
     } else {
         $title = \Date::parse($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' – ' . \Date::parse($objPage->timeFormat, $intEnd) : '') . ')' : '');
     }
     // Add title and link
     $title .= ' ' . $objEvent->title;
     // Backwards compatibility (see #8329)
     if ($strBase != '' && !preg_match('#^https?://#', $strUrl)) {
         $strUrl = $strBase . $strUrl;
     }
     $link = '';
     switch ($objEvent->source) {
         case 'external':
             $link = $objEvent->url;
             break;
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) instanceof PageModel) {
                 /** @var PageModel $objTarget */
                 $link = $objTarget->getAbsoluteUrl();
             }
             break;
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) instanceof PageModel) {
                 /** @var PageModel $objPid */
                 $link = ampersand($objPid->getAbsoluteUrl('/articles/' . ($objArticle->alias ?: $objArticle->id)));
             }
             break;
         default:
             $link = sprintf($strUrl, $objEvent->alias ?: $objEvent->id);
             break;
     }
     // Store the whole row (see #5085)
     $arrEvent = $objEvent->row();
     // Override link and title
     $arrEvent['link'] = $link;
     $arrEvent['title'] = $title;
     // Clean the RTE output
     $arrEvent['teaser'] = \StringUtil::toHtml5($objEvent->teaser);
     // Reset the enclosures (see #5685)
     $arrEvent['enclosure'] = array();
     // Add the article image as enclosure
     if ($objEvent->addImage) {
         $objFile = \FilesModel::findByUuid($objEvent->singleSRC);
         if ($objFile !== null) {
             $arrEvent['enclosure'][] = $objFile->path;
         }
     }
     // Enclosures
     if ($objEvent->addEnclosure) {
         $arrEnclosure = \StringUtil::deserialize($objEvent->enclosure, true);
         if (is_array($arrEnclosure)) {
             $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
             if ($objFile !== null) {
                 while ($objFile->next()) {
                     $arrEvent['enclosure'][] = $objFile->path;
                 }
             }
         }
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
 }
 protected function generateArrowNavigation($objCurrentEvent, $strUrl)
 {
     $objT = new \FrontendTemplate('eventnavigation_arrows');
     $objT->setData($this->arrData);
     $arrIds = array();
     // get ids from EventsPlus::getAllEvents
     $session = \Session::getInstance()->getData();
     $arrIds = $session[CALENDARPLUS_SESSION_EVENT_IDS];
     // EventsPlus::getAllEvents did not run before the reader
     // TODO: run EventsPlus::getAllEvents before
     if (!is_array($arrIds) || empty($arrIds)) {
         return;
     }
     $prevID = null;
     $nextID = null;
     $currentIndex = array_search($objCurrentEvent->id, $arrIds);
     // prev only of not first item
     if (isset($arrIds[$currentIndex - 1])) {
         $prevID = $arrIds[$currentIndex - 1];
         $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($prevID, $this->cal_calendar);
         $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 ($objEvent !== null) {
             $objT->prev = $this->getEventDetails($objEvent, $intStartTime, $intEndTime, $strUrl, 0, $objEvent->pid);
             $objT->prevLink = $GLOBALS['TL_LANG']['event']['prevLink'];
         }
     }
     // next only of not last item
     if (isset($arrIds[$currentIndex + 1])) {
         $nextID = $arrIds[$currentIndex + 1];
         $objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($nextID, $this->cal_calendar);
         $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 ($objEvent !== null) {
             $objT->next = $this->getEventDetails($objEvent, $intStartTime, $intEndTime, $strUrl, 0, $objEvent->pid);
             $objT->nextLink = $GLOBALS['TL_LANG']['event']['nextLink'];
         }
     }
     return $objT->parse();
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     if (\Input::get('year')) {
         $intYear = \Input::get('year');
         $this->yearBegin = mktime(0, 0, 0, 1, 1, $intYear);
         $this->Date = new \Date($this->yearBegin);
     } else {
         $this->Date = new \Date();
     }
     // Get the Year and the week of the given date
     $intYear = date('Y', $this->Date->tstamp);
     $this->yearBegin = mktime(0, 0, 0, 1, 1, $intYear);
     $this->yearEnd = mktime(23, 59, 59, 12, 31, $intYear);
     // Get total count of weeks of the year
     if (($weeksTotal = date('W', mktime(0, 0, 0, 12, 31, $intYear))) == 1) {
         $weeksTotal = date('W', mktime(0, 0, 0, 12, 24, $intYear));
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('Y', $objMinMax->dateFrom);
     $intRightBoundary = date('Y', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     $objTemplate = new \FrontendTemplate($this->calext_ctemplate ? $this->calext_ctemplate : 'calext_yearview');
     $objTemplate->intYear = $intYear;
     $objTemplate->use_navigation = $this->use_navigation;
     $objTemplate->linkCurrent = $this->linkCurrent;
     // display the navigation if selected
     if ($this->use_navigation) {
         // Get the current year and the week
         if ($this->linkCurrent) {
             $currYear = date('Y', time());
             $lblCurrent = $GLOBALS['TL_LANG']['MSC']['curr_year'];
             $objTemplate->currHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $currYear;
             $objTemplate->currTitle = $currYear;
             $objTemplate->currLink = $lblCurrent;
             $objTemplate->currLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Previous week
         $prevYear = $intYear - 1;
         $lblPrevious = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $prevYear;
         // Only generate a link if there are events (see #4160)
         if ($prevYear >= $intLeftBoundary) {
             $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $prevYear;
             $objTemplate->prevTitle = $prevYear;
             $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
             $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Current week
         $objTemplate->current = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $intYear;
         // Next month
         $nextYear = $intYear + 1;
         $lblNext = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $nextYear;
         // Only generate a link if there are events (see #4160)
         if ($nextYear <= $intRightBoundary) {
             $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $nextYear;
             $objTemplate->nextTitle = $nextYear;
             $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
             $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
         }
     }
     // Set week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     $objTemplate->months = $this->compileMonths();
     $objTemplate->yeardays = $this->compileDays($intYear);
     $this->Template->calendar = $objTemplate->parse();
 }
Esempio n. 25
0
 /**
  * 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);
 }
Esempio n. 26
0
 /**
  * Add an event to the array of active events
  *
  * @param \CalendarEventsModel $objEvent
  * @param integer              $intStart
  * @param integer              $intEnd
  * @param string               $strUrl
  * @param string               $strBase
  */
 protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase)
 {
     if ($intEnd < time()) {
         return;
     }
     /** @var \PageModel $objPage */
     global $objPage;
     // Called in the back end (see #4026)
     if ($objPage === null) {
         $objPage = new \stdClass();
         $objPage->dateFormat = \Config::get('dateFormat');
         $objPage->datimFormat = \Config::get('datimFormat');
         $objPage->timeFormat = \Config::get('timeFormat');
     }
     $intKey = date('Ymd', $intStart);
     $span = self::calculateSpan($intStart, $intEnd);
     $format = $objEvent->addTime ? 'datimFormat' : 'dateFormat';
     // Add date
     if ($span > 0) {
         $title = \Date::parse($objPage->{$format}, $intStart) . ' – ' . \Date::parse($objPage->{$format}, $intEnd);
     } else {
         $title = \Date::parse($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' – ' . \Date::parse($objPage->timeFormat, $intEnd) : '') . ')' : '');
     }
     // Add title and link
     $title .= ' ' . $objEvent->title;
     $link = '';
     switch ($objEvent->source) {
         case 'external':
             $link = $objEvent->url;
             break;
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
                 $link = $strBase . $this->generateFrontendUrl($objTarget->row());
             }
             break;
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 $link = $strBase . ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
             }
             break;
     }
     // Link to the default page
     if ($link == '') {
         $link = $strBase . sprintf($strUrl, $objEvent->alias != '' && !\Config::get('disableAlias') ? $objEvent->alias : $objEvent->id);
     }
     // Store the whole row (see #5085)
     $arrEvent = $objEvent->row();
     // Override link and title
     $arrEvent['link'] = $link;
     $arrEvent['title'] = $title;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $arrEvent['teaser'] = \StringUtil::toXhtml($objEvent->teaser);
     } else {
         $arrEvent['teaser'] = \StringUtil::toHtml5($objEvent->teaser);
     }
     // Reset the enclosures (see #5685)
     $arrEvent['enclosure'] = array();
     // Add the article image as enclosure
     if ($objEvent->addImage) {
         $objFile = \FilesModel::findByUuid($objEvent->singleSRC);
         if ($objFile !== null) {
             $arrEvent['enclosure'][] = $objFile->path;
         }
     }
     // Enclosures
     if ($objEvent->addEnclosure) {
         $arrEnclosure = deserialize($objEvent->enclosure, true);
         if (is_array($arrEnclosure)) {
             $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
             if ($objFile !== null) {
                 while ($objFile->next()) {
                     $arrEvent['enclosure'][] = $objFile->path;
                 }
             }
         }
     }
     $this->arrEvents[$intKey][$intStart][] = $arrEvent;
 }
Esempio n. 27
0
 /**
  * Generate a URL and return it as string
  *
  * @param CalendarEventsModel $objEvent
  *
  * @return string
  */
 public static function generateEventUrl($objEvent)
 {
     $strCacheKey = 'id_' . $objEvent->id;
     // Load the URL from cache
     if (isset(self::$arrUrlCache[$strCacheKey])) {
         return self::$arrUrlCache[$strCacheKey];
     }
     // Initialize the cache
     self::$arrUrlCache[$strCacheKey] = null;
     switch ($objEvent->source) {
         // Link to an external page
         case 'external':
             if (substr($objEvent->url, 0, 7) == 'mailto:') {
                 self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objEvent->url);
             } else {
                 self::$arrUrlCache[$strCacheKey] = ampersand($objEvent->url);
             }
             break;
             // Link to an internal page
         // Link to an internal page
         case 'internal':
             if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
                 self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objTarget->row()));
             }
             break;
             // Link to an article
         // Link to an article
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPid->row(), '/articles/' . ($objArticle->alias ?: $objArticle->id)));
             }
             break;
     }
     // Link to the default page
     if (self::$arrUrlCache[$strCacheKey] === null) {
         $objPage = \PageModel::findByPk($objEvent->getRelated('pid')->jumpTo);
         if ($objPage === null) {
             self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
         } else {
             self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') ? '/' : '/events/') . ($objEvent->alias ?: $objEvent->id)));
         }
     }
     return self::$arrUrlCache[$strCacheKey];
 }
Esempio n. 28
0
 /**
  * Add events to the indexer
  * @param array
  * @param integer
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $arrProcessed = array();
     // Get all calendars
     $objCalendar = \CalendarModel::findByProtected('');
     // Walk through each calendar
     if ($objCalendar !== null) {
         while ($objCalendar->next()) {
             // Skip calendars without target page
             if (!$objCalendar->jumpTo) {
                 continue;
             }
             // Skip calendars outside the root nodes
             if (!empty($arrRoot) && !in_array($objCalendar->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objCalendar->jumpTo])) {
                 $domain = \Environment::get('base');
                 $objParent = $this->getPageDetails($objCalendar->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 if ($objParent->domain != '') {
                     $domain = (\Environment::get('ssl') ? 'https://' : 'http://') . $objParent->domain . TL_PATH . '/';
                 }
                 $arrProcessed[$objCalendar->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/events/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objCalendar->jumpTo];
             // Get the items
             $objEvents = \CalendarEventsModel::findPublishedDefaultByPid($objCalendar->id);
             if ($objEvents !== null) {
                 while ($objEvents->next()) {
                     $arrPages[] = sprintf($strUrl, $objEvents->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objEvents->alias : $objEvents->id);
                 }
             }
         }
     }
     return $arrPages;
 }