/** * Generate a front end module and return it as string * * @param mixed $intId A module ID or a Model object * @param string $strColumn The name of the column * * @return string The module HTML markup */ protected function getFrontendModule($intId, $strColumn = 'main') { if (!is_object($intId) && !strlen($intId)) { return ''; } global $objPage; // Articles if ($intId == 0) { // Show a particular article only if (\Input::get('articles') && $objPage->type == 'regular') { list($strSection, $strArticle) = explode(':', \Input::get('articles')); if ($strArticle === null) { $strArticle = $strSection; $strSection = 'main'; } if ($strSection == $strColumn) { $strBuffer = $this->getArticle($strArticle); // Send a 404 header if the article does not exist if ($strBuffer === false) { // Do not index the page $objPage->noSearch = 1; $objPage->cache = 0; header('HTTP/1.1 404 Not Found'); return '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $strArticle) . '</p>'; } return $strBuffer; } } elseif (in_array('article_raster_designer', $this->Config->getActiveModules())) { return \RasterDesigner::load($objPage->id, $strColumn); } else { $objArticles = \ArticleModel::findPublishedByPidAndColumn($objPage->id, $strColumn); if ($objArticles === null) { return ''; } $return = ''; $blnMultiMode = $objArticles->count() > 1; while ($objArticles->next()) { $return .= $this->getArticle($objArticles, $blnMultiMode, false, $strColumn); } return $return; } } else { if (is_object($intId)) { $objRow = $intId; } else { $objRow = \ModuleModel::findByPk($intId); } if ($objRow === null) { return ''; } // Show to guests only if ($objRow->guests && FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN && !$objRow->protected) { return ''; } // Protected element if (!BE_USER_LOGGED_IN && $objRow->protected) { if (!FE_USER_LOGGED_IN) { return ''; } $this->import('FrontendUser', 'User'); $groups = deserialize($objRow->groups); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) { return ''; } } $strClass = $this->findFrontendModule($objRow->type); // Return if the class does not exist if (!$this->classFileExists($strClass)) { $this->log('Module class "' . $GLOBALS['FE_MOD'][$objRow->type] . '" (module "' . $objRow->type . '") does not exist', 'Controller getFrontendModule()', TL_ERROR); return ''; } $objRow->typePrefix = 'mod_'; $objModule = new $strClass($objRow, $strColumn); $strBuffer = $objModule->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getFrontendModule']) && is_array($GLOBALS['TL_HOOKS']['getFrontendModule'])) { foreach ($GLOBALS['TL_HOOKS']['getFrontendModule'] as $callback) { $this->import($callback[0]); $strBuffer = $this->{$callback}[0]->{$callback}[1]($objRow, $strBuffer); } } // Disable indexing if protected if ($objModule->protected && !preg_match('/^\\s*<!-- indexer::stop/i', $strBuffer)) { $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n"; } return $strBuffer; } return ''; }
/** * Generate a front end module and return it as string * * @param mixed $intId A module ID or a Model object * @param string $strColumn The name of the column * * @return string The module HTML markup */ public static function getFrontendModule($intId, $strColumn = 'main') { if (!is_object($intId) && !strlen($intId)) { return ''; } /** @var \PageModel $objPage */ global $objPage; // Articles if (!is_object($intId) && $intId == 0) { // Show a particular article only if ($objPage->type == 'regular' && \Input::get('articles')) { list($strSection, $strArticle) = explode(':', \Input::get('articles')); if ($strArticle === null) { $strArticle = $strSection; $strSection = 'main'; } if ($strSection == $strColumn) { $objArticle = \ArticleModel::findByIdOrAliasAndPid($strArticle, $objPage->id); // Send a 404 header if the article does not exist if (null === $objArticle) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Add the "first" and "last" classes (see #2583) $objArticle->classes = array('first', 'last'); return static::getArticle($objArticle); } } // HOOK: trigger the article_raster_designer extension if (in_array('article_raster_designer', \ModuleLoader::getActive())) { return \RasterDesigner::load($objPage->id, $strColumn); } // Show all articles (no else block here, see #4740) $objArticles = \ArticleModel::findPublishedByPidAndColumn($objPage->id, $strColumn); if ($objArticles === null) { return ''; } $return = ''; $intCount = 0; $blnMultiMode = $objArticles->count() > 1; $intLast = $objArticles->count() - 1; while ($objArticles->next()) { /** @var \ArticleModel $objRow */ $objRow = $objArticles->current(); // Add the "first" and "last" classes (see #2583) if ($intCount == 0 || $intCount == $intLast) { $arrCss = array(); if ($intCount == 0) { $arrCss[] = 'first'; } if ($intCount == $intLast) { $arrCss[] = 'last'; } $objRow->classes = $arrCss; } $return .= static::getArticle($objRow, $blnMultiMode, false, $strColumn); ++$intCount; } return $return; } else { if (is_object($intId)) { $objRow = $intId; } else { $objRow = \ModuleModel::findByPk($intId); if ($objRow === null) { return ''; } } // Check the visibility (see #6311) if (!static::isVisibleElement($objRow)) { return ''; } $strClass = \Module::findClass($objRow->type); // Return if the class does not exist if (!class_exists($strClass)) { static::log('Module class "' . $strClass . '" (module "' . $objRow->type . '") does not exist', __METHOD__, TL_ERROR); return ''; } $objRow->typePrefix = 'mod_'; /** @var \Module $objModule */ $objModule = new $strClass($objRow, $strColumn); $strBuffer = $objModule->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getFrontendModule']) && is_array($GLOBALS['TL_HOOKS']['getFrontendModule'])) { foreach ($GLOBALS['TL_HOOKS']['getFrontendModule'] as $callback) { $strBuffer = static::importStatic($callback[0])->{$callback[1]}($objRow, $strBuffer, $objModule); } } // Disable indexing if protected if ($objModule->protected && !preg_match('/^\\s*<!-- indexer::stop/', $strBuffer)) { $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n"; } return $strBuffer; } }
/** * Generate a front end module and return it as HTML string * @param integer * @param string * @return string */ protected function getFrontendModule($intId, $strColumn = 'main') { global $objPage; $this->import('Database'); if (!strlen($intId)) { return ''; } // Articles if ($intId == 0) { // Show a particular article only if ($this->Input->get('articles') && $objPage->type == 'regular') { list($strSection, $strArticle) = explode(':', $this->Input->get('articles')); if (is_null($strArticle)) { $strArticle = $strSection; $strSection = 'main'; } if ($strSection == $strColumn) { return $this->getArticle($strArticle); } } elseif (in_array('article_raster_designer', $this->Config->getActiveModules())) { return RasterDesigner::load($objPage->id, $strColumn); } $time = time(); // Show all articles of the current column $objArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid=? AND inColumn=?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1" : "") . " ORDER BY sorting")->execute($objPage->id, $strColumn); if (($count = $objArticles->numRows) < 1) { return ''; } $return = ''; while ($objArticles->next()) { $return .= $this->getArticle($objArticles->id, $count > 1 ? true : false, false, $strColumn); } return $return; } // Other modules $objModule = $this->Database->prepare("SELECT * FROM tl_module WHERE id=?")->limit(1)->execute($intId); if ($objModule->numRows < 1) { return ''; } // Show to guests only if ($objModule->guests && FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN && !$objModule->protected) { return ''; } // Protected element if (!BE_USER_LOGGED_IN && $objModule->protected) { if (!FE_USER_LOGGED_IN) { return ''; } $this->import('FrontendUser', 'User'); $groups = deserialize($objModule->groups); if (!is_array($groups) || count($groups) < 1 || count(array_intersect($groups, $this->User->groups)) < 1) { return ''; } } $strClass = $this->findFrontendModule($objModule->type); // Return if the class does not exist if (!$this->classFileExists($strClass)) { $this->log('Module class "' . $GLOBALS['FE_MOD'][$objModule->type] . '" (module "' . $objModule->type . '") does not exist', 'Controller getFrontendModule()', TL_ERROR); return ''; } $objModule->typePrefix = 'mod_'; $objModule = new $strClass($objModule, $strColumn); $strBuffer = $objModule->generate(); // Disable indexing if protected if ($objModule->protected && !preg_match('/^\\s*<!-- indexer::stop/i', $strBuffer)) { $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n"; } return $strBuffer; }
/** * Generate a front end module and return it as HTML string. * * @param int * @param string * * @return string */ protected function getPageFrontendModule($page, $moduleId, $columnName = 'main', $inheritableOnly = false) { if (!is_object($moduleId) && !strlen($moduleId)) { return ''; } // Articles if ($moduleId == 0) { // Show a particular article only if ($page->type == 'regular' && \Input::get('articles')) { list($sectionName, $articleName) = explode(':', \Input::get('articles')); if ($articleName === null) { $articleName = $sectionName; $sectionName = 'main'; } if ($sectionName == $columnName) { $article = \ArticleModel::findByIdOrAliasAndPid($articleName, $page->id); // Send a 404 header if the article does not exist if ($article === null) { // Do not index the page $page->noSearch = 1; $page->cache = 0; header('HTTP/1.1 404 Not Found'); return '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $articleName) . '</p>'; } if (!$inheritableOnly || $article->inheritable) { // Add the "first" and "last" classes (see #2583) $article->classes = array('first', 'last'); return $this->getArticle($article); } return ''; } } // HOOK: trigger the article_raster_designer extension if (in_array('article_raster_designer', \ModuleLoader::getActive())) { return \RasterDesigner::load($page->id, $columnName); } // Show all articles (no else block here, see #4740) $articleCollection = \ArticleModel::findPublishedByPidAndColumn($page->id, $columnName); if ($articleCollection === null) { return ''; } $return = ''; $intCount = 0; $blnMultiMode = $articleCollection->count() > 1; $intLast = $articleCollection->count() - 1; while ($articleCollection->next()) { if ($inheritableOnly && !$articleCollection->inheritable) { continue; } $articleRow = $articleCollection->current(); // Add the "first" and "last" classes (see #2583) if ($intCount == 0 || $intCount == $intLast) { $cssClasses = array(); if ($intCount == 0) { $cssClasses[] = 'first'; } if ($intCount == $intLast) { $cssClasses[] = 'last'; } $articleRow->classes = $cssClasses; } $return .= $this->getArticle($articleRow, $blnMultiMode, false, $columnName); ++$intCount; } return $return; } else { if (is_object($moduleId)) { $articleRow = $moduleId; } else { $articleRow = \ModuleModel::findByPk($moduleId); if ($articleRow === null) { return ''; } } // Check the visibility (see #6311) if (!static::isVisibleElement($articleRow)) { return ''; } $moduleClassName = \Module::findClass($articleRow->type); // Return if the class does not exist if (!class_exists($moduleClassName)) { $this->log('Module class "' . $moduleClassName . '" (module "' . $articleRow->type . '") does not exist', __METHOD__, TL_ERROR); return ''; } $articleRow->typePrefix = 'mod_'; /** @var \Module $module */ $module = new $moduleClassName($articleRow, $columnName); $buffer = $module->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getFrontendModule']) && is_array($GLOBALS['TL_HOOKS']['getFrontendModule'])) { foreach ($GLOBALS['TL_HOOKS']['getFrontendModule'] as $callback) { $this->import($callback[0]); $buffer = $this->{$callback}[0]->{$callback}[1]($articleRow, $buffer, $module); } } // Disable indexing if protected if ($module->protected && !preg_match('/^\\s*<!-- indexer::stop/', $buffer)) { $buffer = "\n<!-- indexer::stop -->" . $buffer . "<!-- indexer::continue -->\n"; } return $buffer; } }
/** * Generate a front end module and return it as HTML string * @param integer * @param string * @return string */ protected function getFrontendModule($intId, $strColumn = 'main') { if (!strlen($intId)) { return ''; } global $objPage; $this->import('Database'); // Articles if ($intId == 0) { // Show a particular article only if ($this->Input->get('articles') && $objPage->type == 'regular') { list($strSection, $strArticle) = explode(':', $this->Input->get('articles')); if ($strArticle === null) { $strArticle = $strSection; $strSection = 'main'; } if ($strSection == $strColumn) { $strBuffer = $this->getArticle($strArticle); // Send a 404 header if the article does not exist if ($strBuffer === false) { // Do not index the page $objPage->noSearch = 1; $objPage->cache = 0; header('HTTP/1.1 404 Not Found'); return '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $strArticle) . '</p>'; } return $strBuffer; } } elseif (in_array('article_raster_designer', $this->Config->getActiveModules())) { return RasterDesigner::load($objPage->id, $strColumn); } $time = time(); // Show all articles of the current column $objArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid=? AND inColumn=?" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND published=1" : "") . " ORDER BY sorting")->execute($objPage->id, $strColumn); if (($count = $objArticles->numRows) < 1) { return ''; } $return = ''; while ($objArticles->next()) { $return .= $this->getArticle($objArticles->id, $count > 1, false, $strColumn); } return $return; } else { $objRow = $this->Database->prepare("SELECT * FROM tl_module WHERE id=?")->limit(1)->execute($intId); if ($objRow->numRows < 1) { return ''; } // Show to guests only if ($objRow->guests && FE_USER_LOGGED_IN && !BE_USER_LOGGED_IN && !$objRow->protected) { return ''; } // Protected element if (!BE_USER_LOGGED_IN && $objRow->protected) { if (!FE_USER_LOGGED_IN) { return ''; } $this->import('FrontendUser', 'User'); $groups = deserialize($objRow->groups); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) { return ''; } } $strClass = $this->findFrontendModule($objRow->type); // Return if the class does not exist if (!$this->classFileExists($strClass)) { $this->log('Module class "' . $GLOBALS['FE_MOD'][$objRow->type] . '" (module "' . $objRow->type . '") does not exist', 'Controller getFrontendModule()', TL_ERROR); return ''; } $objRow->typePrefix = 'mod_'; $objModule = new $strClass($objRow, $strColumn); $strBuffer = $objModule->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getFrontendModule']) && is_array($GLOBALS['TL_HOOKS']['getFrontendModule'])) { foreach ($GLOBALS['TL_HOOKS']['getFrontendModule'] as $callback) { $this->import($callback[0]); $strBuffer = $this->{$callback}[0]->{$callback}[1]($objRow, $strBuffer); } } // Disable indexing if protected if ($objModule->protected && !preg_match('/^\\s*<!-- indexer::stop/i', $strBuffer)) { $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n"; } return $strBuffer; } }