3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace TravelBlog\Element; use Contao\FrontendTemplate; use Contao\PageModel; class ContentArticlePreview extends \ContentElement { protected $strTemplate = "mod_articlepreview"; protected $idLevels = array(); protected function getFileFromSingleSRC($singleSRC) { if ($singleSRC == '') { return ''; } if (!\Validator::isUuid($singleSRC)) { return '<p class="error">'.$GLOBALS['TL_LANG']['ERR']['version2format'].'</p>'; } $objFile = \FilesModel::findByUuid($singleSRC); if ($objFile === null || !is_file(TL_ROOT . '/' . $objFile->path)) { return ''; } return $objFile->path; } /** * Generate content element */ protected function compile() { global $objPage; $query = ''; $pages = array(); $selectedPages = deserialize($this->article_list_pages); if (is_array($selectedPages)) { $articleListPages = $selectedPages; } elseif (!empty($selectedPages)) { $articleListPages = array($selectedPages); } else { $articleListPages = array(); } if (TL_MODE == 'FE') { $pageId = $objPage->id; } else { $objArticle = $this->Database->prepare("SELECT `pid` FROM `tl_article` WHERE `id`=?") ->execute($this->pid); if ($objArticle->next()) { $pageId = $objArticle->pid; } } if ($this->article_list_childrens) { array_splice($articleListPages, 0, 0, $this->getChildPages($pageId, false)); } if ($this->article_list_recursive) { for ($i=count($articleListPages)-1; $i>=0; $i--) { array_splice($articleListPages, $i+1, 0, $this->getChildPages($articleListPages[$i], true, $this->idLevels[$articleListPages[$i]]+1)); } } if (count($articleListPages)) { $objPages = $this->Database->prepare(" SELECT `id`, `alias`, `title`, `pageTitle`, `type`, `hide`, `protected`, `groups`, `titelimage`, `sorting` FROM tl_page WHERE " . (!$this->Input->cookie('FE_PREVIEW') ? "`published`='1' AND " : "") . " `id` IN (" . implode(',', $articleListPages) . ") ORDER BY `sorting` ") ->execute(); if ($objPages->numRows > 0) { $arrInactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']); $sql = " SELECT * FROM tl_article WHERE " . (!$this->Input->cookie('FE_PREVIEW') ? "`published`='1' AND " : "") . " `pid`=? ORDER BY `destinationdate`"; $this->import('FrontendUser', 'User'); while ($objPages->next()) { if ($this->article_list_hidden || ($objPages->hide != '1') || in_array($objPages->id, $selectedPages)) { $protectedPage = false; // Protected element if (!BE_USER_LOGGED_IN && $objPages->protected) { if (!FE_USER_LOGGED_IN) { $protectedPage = true; } else { $groups = deserialize($objPages->groups); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) { $protectedPage = true; } } } $objArticles = $this->Database->prepare($sql)->execute($objPages->id); if ($objArticles->numRows > 0) { $articles = array(); while ($objArticles->next()) { if ($this->article_list_page_link && ($objArticles->numRows == 1)) { $link = ''; } else { $link = '/articles/'; if ($objArticles->inColumn != 'main') { $link .= $objArticles->inColumn . ':'; } $link .= (strlen($objArticles->alias) && !$GLOBALS['TL_CONFIG']['disableAlias']) ? $objArticles->alias : $objArticles->id; } $arrTeaserCssID = deserialize($objArticles->teaserCssID); $isProtected = $protectedPage; // Protected element if (!$protectedPage && !BE_USER_LOGGED_IN && $objArticles->protected) { if (!FE_USER_LOGGED_IN) { $isProtected = true; } else { $groups = deserialize($objArticles->groups); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) { $isProtected = true; } } } $objFile = $this->getFileFromSingleSRC($objArticles->image); $articles[] = array ( 'id' => $objArticles->id, 'alias' => $objArticles->alias, 'active' => ($this->pid == $objArticles->id), 'class' => ($this->pid == $objArticles->id ? 'active'.($isProtected ? ' protected' : '') : ($isProtected ? 'protected' : '')), 'title' => $objArticles->title, 'teaser' => ($this->article_list_teaser ? $objArticles->teaser : ''), 'teaser_cssID' => $arrTeaserCssID[0], 'teaser_class' => $arrTeaserCssID[1], 'link' => $this->generateFrontendUrl($objPages->row(), $link), 'subheadline' => $objArticles->subheadline, 'destinationdate' => $objArticles->destinationdate, 'column' => $objArticles->inColumn, 'showPost' => $objArticles->showPost, 'image' => $objFile, 'protected' => $isProtected ); } $objFile = $this->getFileFromSingleSRC($objPages->titelimage); $pages[] = array ( 'name' => $objPages->title, 'title' => ($objPages->pageTitle != '' ? $objPages->pageTitle : $objPages->title), 'link' => $this->generateFrontendUrl($objPages->row()), 'protected' => $protectedPage, 'articles' => $articles, 'level' => (isset($this->idLevels[$objPages->id]) ? $this->idLevels[$objPages->id] : 0), 'active' => ($pageId == $objPages->id), 'class' => ($pageId == $objPages->id ? 'active'.($protectedPage ? ' protected' : '') : ($protectedPage ? 'protected' : '')), 'titelimage' => $objFile, 'sort' => (array_search($objPages->id, $articleListPages) !== FALSE ? array_search($objPages->id, $articleListPages) + 9000000 : $objPages->sorting) ); } } } } } elseif (TL_MODE == 'FE') { $this->log(sprintf('No articles for ID %d (%s) found.', $objPage->id, $objPage->title), 'ArticleList', TL_NOTICE); } if ((count($pages) > 0) && (count($articleListPages) > 0)) { usort($pages, array($this, 'pageSort')); } $this->Template->pages = $pages; if ($this->article_list_page_headline) { $hlNext = array('h1'=>'h2','h2'=>'h3','h3'=>'h4','h4'=>'h5','h5'=>'h6','h6'=>'p'); $this->Template->hlPage = (isset($hlNext[$this->hl]) ? $hlNext[$this->hl] : 'p'); } else { $this->Template->hlPage = false; } } /** * Helper function for usort */ protected function pageSort($a, $b) { if ($a['sort'] == $b['sort']) { return 0; } return ($a['sort'] < $b['sort']) ? -1 : 1; } /** * Gets all child pages if article_list_recursive is set */ protected function getChildPages($pageId, $recursive = true, $level=0) { $pageArray = array(); $objPages = $this->Database->prepare(" SELECT `id` FROM `tl_page` WHERE `pid`=? AND `type`='regular' ".(!$this->Input->cookie('FE_PREVIEW') ? " AND `published`='1' " : "")." ORDER BY `sorting` ")->execute($pageId); while ($objPages->next()) { $pageArray[] = $objPages->id; $this->idLevels[$objPages->id] = $level; if ($recursive) { $pageArray = array_merge($pageArray, $this->getChildPages($objPages->id, $recursive, $level+1)); } } return $pageArray; } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Class "ContentElement" not found in /in/osTTJ:8 Stack trace: #0 {main} thrown in /in/osTTJ on line 8
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'ContentElement' not found in /in/osTTJ:8 Stack trace: #0 {main} thrown in /in/osTTJ on line 8
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
Fatal error: Class 'ContentElement' not found in /in/osTTJ on line 8
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Class 'ContentElement' not found in /in/osTTJ on line 9
Process exited with code 255.

preferences:
301.56 ms | 402 KiB | 376 Q