findWithDetails() public static method

Find a page by its ID and return it with the inherited details
public static findWithDetails ( integer $intId ) : PageModel | null
$intId integer The page's ID
return PageModel | null The model or null if there is no matching page
 private function validateLanguageMainForPage($pageId)
 {
     $page = PageModel::findWithDetails($pageId);
     // Moving a root page does not affect language assignments
     if (null === $page || !$page->languageMain || 'root' === $page->type) {
         return;
     }
     $duplicates = PageModel::countBy(['id IN (' . implode(',', Database::getInstance()->getChildRecords($page->rootId, 'tl_page')) . ')', 'languageMain=?', 'id!=?'], [$page->languageMain, $page->id]);
     // Reset languageMain if another page in the new page tree has the same languageMain
     if ($duplicates > 0) {
         $this->resetPageAndChildren($page->id);
         return;
     }
     $pageFinder = new PageFinder();
     $masterRoot = $pageFinder->findMasterRootForPage($page);
     // Reset languageMain if current tree has no master or if it's the master tree
     if (null === $masterRoot || $masterRoot->id === $page->rootId) {
         $this->resetPageAndChildren($page->id);
         return;
     }
     // Reset languageMain if the current value is not a valid ID of the master tree
     if (!in_array($page->id, Database::getInstance()->getChildRecords($masterRoot->id, 'tl_page'), false)) {
         $this->resetPageAndChildren($page->id);
     }
 }
Ejemplo n.º 2
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     // Set the trail and level
     if ($this->defineRoot && $this->rootPage > 0) {
         $trail = array($this->rootPage);
         $level = 0;
     } else {
         $trail = $objPage->trail;
         $level = $this->levelOffset > 0 ? $this->levelOffset : 0;
     }
     $lang = null;
     $host = null;
     // Overwrite the domain and language if the reference page belongs to a differnt root page (see #3765)
     if ($this->defineRoot && $this->rootPage > 0) {
         $objRootPage = \PageModel::findWithDetails($this->rootPage);
         // Set the language
         if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
             $lang = $objRootPage->rootLanguage;
         }
         // Set the domain
         if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
             $host = $objRootPage->domain;
         }
     }
     $this->Template->request = ampersand(\Environment::get('indexFreeRequest'));
     $this->Template->skipId = 'skipNavigation' . $this->id;
     $this->Template->skipNavigation = specialchars($GLOBALS['TL_LANG']['MSC']['skipNavigation']);
     $this->Template->items = $this->renderNavigation($trail[$level], 1, $host, $lang);
 }
Ejemplo n.º 3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $lang = null;
     $host = null;
     // Start from the website root if there is no reference page
     if (!$this->rootPage) {
         $this->rootPage = $objPage->rootId;
     } else {
         $objRootPage = \PageModel::findWithDetails($this->rootPage);
         // Set the language
         if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
             $lang = $objRootPage->rootLanguage;
         }
         // Set the domain
         if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
             $host = $objRootPage->domain;
         }
     }
     $this->Template->formId = 'tl_quicknav_' . $this->id;
     $this->Template->targetPage = $GLOBALS['TL_LANG']['MSC']['targetPage'];
     $this->Template->button = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['go']);
     $this->Template->title = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['quicknav'];
     $this->Template->request = ampersand(\Environment::get('request'), true);
     $this->Template->items = $this->getQuicknavPages($this->rootPage, 1, $host, $lang);
 }
Ejemplo n.º 4
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $lang = null;
     $host = null;
     // Start from the website root if there is no reference page
     if (!$this->rootPage) {
         $this->rootPage = $objPage->rootId;
     } else {
         $objRootPage = \PageModel::findWithDetails($this->rootPage);
         // Set the language
         if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
             $lang = $objRootPage->rootLanguage;
         }
         // Set the domain
         if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
             $host = $objRootPage->domain;
         }
     }
     $this->showLevel = 0;
     $this->hardLimit = false;
     $this->levelOffset = 0;
     $this->Template->items = $this->renderNavigation($this->rootPage, 1, $host, $lang);
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     if (false === $this->currentArticle) {
         $this->currentArticle = ArticleModel::findByPk($this->dataContainer->id);
     }
     if (null === $this->currentArticle) {
         return null;
     }
     return PageModel::findWithDetails($this->currentArticle->pid);
 }
 /**
  * Limits the available pages in page picker to the fallback page tree.
  *
  * @param int $pageId
  */
 private function setRootNodesForPage($pageId)
 {
     $page = PageModel::findWithDetails($pageId);
     $root = PageModel::findByPk($page->rootId);
     if ($root->fallback && (!$root->languageRoot || ($languageRoot = PageModel::findByPk($root->languageRoot)) === null)) {
         return;
     }
     $pageFinder = new PageFinder();
     $masterRoot = $pageFinder->findMasterRootForPage($page);
     if (null !== $masterRoot) {
         $GLOBALS['TL_DCA']['tl_page']['fields']['languageMain']['eval']['rootNodes'] = Database::getInstance()->prepare('SELECT id FROM tl_page WHERE pid=?')->execute($masterRoot->id)->fetchEach('id');
     }
 }
 /**
  * Adds missing translation warning to article tree.
  *
  * @param array $args
  * @param mixed $previousResult
  *
  * @return string
  */
 public function onArticleLabel(array $args, $previousResult = null)
 {
     list($row, $label) = $args;
     if ($previousResult) {
         $label = $previousResult;
     }
     $page = PageModel::findWithDetails($row['pid']);
     $root = PageModel::findByPk($page->rootId);
     if ((!$root->fallback || $root->languageRoot > 0) && $page->languageMain > 0 && null !== PageModel::findByPk($page->languageMain) && (!$row['languageMain'] || null === ArticleModel::findByPk($row['languageMain']))) {
         return $this->generateLabelWithWarning($label);
     }
     return $label;
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     /** @var Model $class */
     $class = $this->getModelClass();
     if (false === $this->current) {
         $this->current = $class::findByPk($this->dataContainer->id);
     }
     if (null === $this->current) {
         return null;
     }
     $pageId = $this->current->pid ? $this->current->getRelated('pid')->jumpTo : $this->current->jumpTo;
     return PageModel::findWithDetails($pageId);
 }
 /**
  * Validate input value when saving tl_page.languageMain field.
  *
  * @param mixed         $value
  * @param DataContainer $dc
  *
  * @return mixed
  *
  * @throws \RuntimeException
  */
 public function onSaveLanguageMain($value, DataContainer $dc)
 {
     // Validate that there is no other page in the current page tree with the same languageMain assigned
     if ($value > 0) {
         $currentPage = PageModel::findWithDetails($dc->id);
         $childIds = \Database::getInstance()->getChildRecords($currentPage->rootId, 'tl_page');
         $duplicates = PageModel::countBy(['tl_page.id IN (' . implode(',', $childIds) . ')', 'tl_page.languageMain=?', 'tl_page.id!=?'], [$value, $dc->id]);
         if ($duplicates > 0) {
             throw new \RuntimeException($GLOBALS['TL_LANG']['MSC']['duplicateMainLanguage']);
         }
     }
     return $value;
 }
Ejemplo n.º 10
0
 /**
  * Get all allowed pages and return them as string
  *
  * @return string
  */
 public function createPageList()
 {
     $this->import('BackendUser', 'User');
     if ($this->User->isAdmin) {
         return $this->doCreatePageList();
     }
     $return = '';
     $processed = array();
     foreach ($this->eliminateNestedPages($this->User->pagemounts) as $page) {
         $objPage = \PageModel::findWithDetails($page);
         // Root page mounted
         if ($objPage->type == 'root') {
             $title = $objPage->title;
             $start = $objPage->id;
         } else {
             $title = $objPage->rootTitle;
             $start = $objPage->rootId;
         }
         // Do not process twice
         if (in_array($start, $processed)) {
             continue;
         }
         // Skip websites that run under a different domain (see #2387)
         if ($objPage->domain && $objPage->domain != \Environment::get('host')) {
             continue;
         }
         $processed[] = $start;
         $return .= '<optgroup label="' . $title . '">' . $this->doCreatePageList($start) . '</optgroup>';
     }
     return $return;
 }
Ejemplo n.º 11
0
 /**
  * Add newsletters to the indexer
  *
  * @param array   $arrPages
  * @param integer $intRoot
  * @param boolean $blnIsSitemap
  *
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $arrProcessed = array();
     $time = \Date::floorToMinute();
     // Get all channels
     $objNewsletter = \NewsletterChannelModel::findAll();
     // Walk through each channel
     if ($objNewsletter !== null) {
         while ($objNewsletter->next()) {
             if (!$objNewsletter->jumpTo) {
                 continue;
             }
             // Skip channels outside the root nodes
             if (!empty($arrRoot) && !in_array($objNewsletter->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objNewsletter->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objNewsletter->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 + 60) {
                     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')) . \Environment::get('path') . '/';
                 // Generate the URL
                 $arrProcessed[$objNewsletter->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') ? '/%s' : '/items/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objNewsletter->jumpTo];
             // Get the items
             $objItem = \NewsletterModel::findSentByPid($objNewsletter->id);
             if ($objItem !== null) {
                 while ($objItem->next()) {
                     $arrPages[] = sprintf($strUrl, $objItem->alias ?: $objItem->id);
                 }
             }
         }
     }
     return $arrPages;
 }
 /**
  * Render a news.
  *
  * @param GetNewsEvent             $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 handleNews(GetNewsEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     if ($event->getNewsHtml()) {
         return;
     }
     $newsArchiveCollection = NewsArchiveModel::findAll();
     $newsArchiveIds = $newsArchiveCollection ? $newsArchiveCollection->fetchEach('id') : array();
     $newsModel = NewsModel::findPublishedByParentAndIdOrAlias($event->getNewsId(), $newsArchiveIds);
     if (!$newsModel) {
         return;
     }
     $newsModel = $newsModel->current();
     $newsArchiveModel = $newsModel->getRelated('pid');
     $objPage = PageModel::findWithDetails($newsArchiveModel->jumpTo);
     $objTemplate = new FrontendTemplate($event->getTemplate());
     $objTemplate->setData($newsModel->row());
     $objTemplate->class = $newsModel->cssClass != '' ? ' ' . $newsModel->cssClass : '';
     $objTemplate->newsHeadline = $newsModel->headline;
     $objTemplate->subHeadline = $newsModel->subheadline;
     $objTemplate->hasSubHeadline = $newsModel->subheadline ? true : false;
     $objTemplate->linkHeadline = $this->generateLink($eventDispatcher, $newsModel->headline, $newsModel);
     $objTemplate->more = $this->generateLink($eventDispatcher, $GLOBALS['TL_LANG']['MSC']['more'], $newsModel, false, true);
     $objTemplate->link = $this->generateNewsUrl($eventDispatcher, $newsModel);
     $objTemplate->archive = $newsModel->getRelated('pid');
     $objTemplate->count = 0;
     $objTemplate->text = '';
     // Clean the RTE output.
     if ($newsModel->teaser != '') {
         if ($objPage->outputFormat == 'xhtml') {
             $objTemplate->teaser = StringHelper::toXhtml($newsModel->teaser);
         } else {
             $objTemplate->teaser = StringHelper::toHtml5($newsModel->teaser);
         }
         $objTemplate->teaser = StringHelper::encodeEmail($objTemplate->teaser);
     }
     // Display the "read more" button for external/article links.
     if ($newsModel->source != 'default') {
         $objTemplate->text = true;
     } else {
         // Compile the news text.
         $objElement = ContentModel::findPublishedByPidAndTable($newsModel->id, 'tl_news');
         if ($objElement !== null) {
             while ($objElement->next()) {
                 $getContentElementEvent = new GetContentElementEvent($objElement->id);
                 $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_CONTENT_ELEMENT, $getContentElementEvent);
                 $objTemplate->text .= $getContentElementEvent->getContentElementHtml();
             }
         }
     }
     $arrMeta = $this->getMetaFields($newsModel);
     // Add the meta information.
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->numberOfComments = $arrMeta['ccount'];
     $objTemplate->commentCount = $arrMeta['comments'];
     $objTemplate->timestamp = $newsModel->date;
     $objTemplate->author = $arrMeta['author'];
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $newsModel->date);
     $objTemplate->addImage = false;
     // Add an image.
     if ($newsModel->addImage && $newsModel->singleSRC != '') {
         $objModel = FilesModel::findByUuid($newsModel->singleSRC);
         if ($objModel === null) {
             if (!Validator::isUuid($newsModel->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).
             $arrArticle = $newsModel->row();
             // Override the default image size.
             // This is always false!
             if ($this->imgSize != '') {
                 $size = deserialize($this->imgSize);
                 if ($size[0] > 0 || $size[1] > 0) {
                     $arrArticle['size'] = $this->imgSize;
                 }
             }
             $arrArticle['singleSRC'] = $objModel->path;
             $addImageToTemplateEvent = new AddImageToTemplateEvent($arrArticle, $objTemplate);
             $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_ADD_IMAGE_TO_TEMPLATE, $addImageToTemplateEvent);
         }
     }
     $objTemplate->enclosure = array();
     // Add enclosures.
     if ($newsModel->addEnclosure) {
         $addEnclosureToTemplateEvent = new AddEnclosureToTemplateEvent($newsModel->row(), $objTemplate);
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_ADD_ENCLOSURE_TO_TEMPLATE, $addEnclosureToTemplateEvent);
     }
     $news = $objTemplate->parse();
     $event->setNewsHtml($news);
 }
Ejemplo n.º 13
0
 /**
  * Get the details of a page including inherited parameters
  *
  * @param mixed $intId A page ID or a Model object
  *
  * @return \PageModel The page model or null
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use PageModel::findWithDetails() or PageModel->loadDetails() instead.
  */
 public static function getPageDetails($intId)
 {
     trigger_error('Using Controller::getPageDetails() has been deprecated and will no longer work in Contao 5.0. Use PageModel::findWithDetails() or PageModel->loadDetails() instead.', E_USER_DEPRECATED);
     if ($intId instanceof \PageModel) {
         return $intId->loadDetails();
     } elseif ($intId instanceof \Model\Collection) {
         /** @var \PageModel $objPage */
         $objPage = $intId->current();
         return $objPage->loadDetails();
     } elseif (is_object($intId)) {
         $strKey = __METHOD__ . '-' . $intId->id;
         // Try to load from cache
         if (\Cache::has($strKey)) {
             return \Cache::get($strKey);
         }
         // Create a model from the database result
         $objPage = new \PageModel();
         $objPage->setRow($intId->row());
         $objPage->loadDetails();
         \Cache::set($strKey, $objPage);
         return $objPage;
     } else {
         // Invalid ID
         if (!strlen($intId) || $intId < 1) {
             return null;
         }
         $strKey = __METHOD__ . '-' . $intId;
         // Try to load from cache
         if (\Cache::has($strKey)) {
             return \Cache::get($strKey);
         }
         $objPage = \PageModel::findWithDetails($intId);
         \Cache::set($strKey, $objPage);
         return $objPage;
     }
 }
Ejemplo n.º 14
0
 /**
  * @param $objItem
  * @param $strUrl
  * @param string $strBase
  * @return string
  * @throws \Exception
  */
 public static function getLink($objItem, $strUrl, $strBase = '')
 {
     // switch
     switch ($objItem->source) {
         // Link to an external page
         case 'external':
             return $objItem->url;
             break;
             // Link to an internal page
         // Link to an internal page
         case 'internal':
             if ($objItem->jumpTo) {
                 $objPage = PageModel::findWithDetails($objItem->jumpTo);
                 $domain = ($objPage->rootUseSSL ? 'https://' : 'http://') . ($objPage->domain ?: \Environment::get('host')) . TL_PATH . '/';
                 return $domain . \Controller::generateFrontendUrl($objPage->row(), '', $objPage->language);
             }
             break;
             // Link to an article
         // Link to an article
         case 'article':
             if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 return $strBase . ampersand(\Controller::generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
             }
             break;
     }
     // handle encoded characters %D9%86
     $strUrl = rawurldecode($strUrl);
     // Link to the default page
     return $strBase . sprintf($strUrl, $objItem->alias != '' && !\Config::get('disableAlias') ? $objItem->alias : $objItem->id);
 }
 /**
  * Collect details for a page.
  *
  * @param GetPageDetailsEvent $event The event.
  *
  * @return void
  */
 public function handleGetPageDetails(GetPageDetailsEvent $event)
 {
     $page = PageModel::findWithDetails($event->getPageId());
     if ($page) {
         $event->setPageDetails($page->row());
     }
 }
Ejemplo n.º 16
0
 /**
  * @param $arrFeed
  * @return null
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['wrappers']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return null;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = $this->findPublishedByPids($arrArchives, $arrFeed['maxItems'], $arrFeed['fmodule'] . '_data');
     } else {
         $objArticle = $this->findPublishedByPids($arrArchives, 0, $arrFeed['fmodule'] . '_data');
     }
     if ($objArticle !== null) {
         $arrUrls = array();
         $strUrl = '';
         while ($objArticle->next()) {
             $pid = $objArticle->pid;
             $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $arrFeed['fmodule'] . ' WHERE id = ?')->execute($pid)->row();
             if ($wrapperDB['addDetailPage'] == '1') {
                 $rootPage = $wrapperDB['rootPage'];
                 if (!isset($arrUrls[$rootPage])) {
                     $objParent = PageModel::findWithDetails($rootPage);
                     if ($objParent === null) {
                         $arrUrls[$rootPage] = false;
                     } else {
                         $arrUrls[$rootPage] = $this->generateFrontendUrl($objParent->row(), Config::get('useAutoItem') && !Config::get('disableAlias') ? '/%s' : '/items/%s', $objParent->language);
                     }
                 }
                 $strUrl = $arrUrls[$rootPage];
             }
             $authorName = '';
             if ($objArticle->author) {
                 $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($objArticle->author)->row();
                 $authorName = $authorDB['name'];
             }
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->title;
             $objItem->link = HelperModel::getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date ? $objArticle->date : $arrFeed['tstamp'];
             $objItem->author = $authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'detail'));
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = Environment::get('request');
                     Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     Environment::set('request', $strRequest);
                 }
             } else {
                 $strDescription = '';
                 $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'list'));
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = Environment::get('request');
                     Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     Environment::set('request', $strRequest);
                 }
                 if (!$strDescription) {
                     $strDescription = $objArticle->description;
                 }
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Ejemplo n.º 17
0
 /**
  * Generate a particular subpart of the tree and return it as HTML string
  *
  * @param integer $id
  * @param integer $level
  *
  * @return string
  */
 public function ajaxTreeView($id, $level)
 {
     if (!\Environment::get('isAjaxRequest')) {
         return '';
     }
     $return = '';
     $table = $this->strTable;
     $blnPtable = false;
     // Load parent table
     if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) {
         $table = $this->ptable;
         \System::loadLanguageFile($table);
         $this->loadDataContainer($table);
         $blnPtable = true;
     }
     $blnProtected = false;
     // Check protected pages
     if ($table == 'tl_page') {
         $objParent = \PageModel::findWithDetails($id);
         $blnProtected = $objParent->protected ? true : false;
     }
     $margin = $level * 20;
     $hasSorting = $this->Database->fieldExists('sorting', $table);
     $arrIds = array();
     // Get records
     $objRows = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?" . ($hasSorting ? " ORDER BY sorting" : ""))->execute($id);
     while ($objRows->next()) {
         $arrIds[] = $objRows->id;
     }
     /** @var SessionInterface $objSession */
     $objSession = \System::getContainer()->get('session');
     $blnClipboard = false;
     $arrClipboard = $objSession->get('CLIPBOARD');
     // Check clipboard
     if (!empty($arrClipboard[$this->strTable])) {
         $blnClipboard = true;
         $arrClipboard = $arrClipboard[$this->strTable];
     }
     for ($i = 0, $c = count($arrIds); $i < $c; $i++) {
         $return .= ' ' . trim($this->generateTree($table, $arrIds[$i], array('p' => $arrIds[$i - 1], 'n' => $arrIds[$i + 1]), $hasSorting, $margin, $blnClipboard ? $arrClipboard : false, $id == $arrClipboard['id'] || is_array($arrClipboard['id']) && in_array($id, $arrClipboard['id']) || !$blnPtable && !is_array($arrClipboard['id']) && in_array($id, $this->Database->getChildRecords($arrClipboard['id'], $table)), $blnProtected));
     }
     return $return;
 }
 /**
  * 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->hasDetails = true;
     }
     $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);
 }