/** * 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; } }
/** * Add the file meta information to the request * * @param string $strUuid * @param string $strPtable * @param integer $intPid */ public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { $objFile = \FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = \StringUtil::deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; $db = \Database::getInstance(); if ($strPtable == 'tl_article') { $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_article WHERE id=?)")->execute($intPid); } else { // HOOK: support custom modules if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) { foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) { if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) { $objPage = $val; } } } } if ($objPage === null || $objPage->numRows < 1) { return; } $objModel = new \PageModel(); $objModel->setRow($objPage->row()); $objModel->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objModel->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['title'])) { \Input::setPost('alt', $arrMeta[$strLanguage]['title']); } if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) { \Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }