Inheritance: extends Model
コード例 #1
0
 public function getPageLayout(PageModel $objPage, LayoutModel &$objLayout, PageRegular $objPageRegular)
 {
     // layout must use ajax layout
     if (!$objLayout->useAjaxLayout) {
         return;
     }
     // request must be ajax
     if (!Environment::get('isAjaxRequest')) {
         return;
     }
     // set custom or default ajax layout
     if ($objLayout->customAjaxLayout) {
         // load custom layout
         if (($objAjaxLayout = LayoutModel::findById($objLayout->customAjaxLayout)) !== null) {
             $objLayout = $objAjaxLayout;
         }
     } else {
         // create default layout
         $pid = $objLayout->pid;
         $objLayout = new LayoutModel();
         $objLayout->pid = $pid;
         $objLayout->rows = '1rw';
         $objLayout->cols = '1cl';
         $objLayout->orderExt = '';
         $objLayout->modules = 'a:1:{i:0;a:3:{s:3:"mod";s:1:"0";s:3:"col";s:4:"main";s:6:"enable";s:1:"1";}}';
         $objLayout->template = 'fe_page_ajax';
         $objLayout->doctype = $objLayout->doctype;
     }
 }
コード例 #2
0
 /**
  * Generate the page title with ##title## as placeholder for dynamic title
  *
  * @param PageModel $pageModel
  *
  * @return string
  */
 protected function generatePageTitle(PageModel $pageModel)
 {
     $pageModel->loadDetails();
     $layoutModel = LayoutModel::findByPk($pageModel->layout);
     if ($layoutModel === null) {
         return '##title##';
     }
     $title = $layoutModel->titleTag ?: '{{page::pageTitle}} - {{page::rootPageTitle}}';
     $title = str_replace('{{page::pageTitle}}', '##title##', $title);
     // Fake the global page object
     $GLOBALS['objPage'] = $pageModel;
     // Replace the insert tags
     $title = Controller::replaceInsertTags($title, false);
     // Remove the faked global page object
     unset($GLOBALS['objPage']);
     return $title;
 }
コード例 #3
0
 /**
  * Get a page layout and return it as database result object
  *
  * @param \PageModel $objPage
  *
  * @return \LayoutModel
  */
 protected function getPageLayout($objPage)
 {
     $blnMobile = $objPage->mobileLayout && \Environment::get('agent')->mobile;
     // Override the autodetected value
     if (\Input::cookie('TL_VIEW') == 'mobile') {
         $blnMobile = true;
     } elseif (\Input::cookie('TL_VIEW') == 'desktop') {
         $blnMobile = false;
     }
     $intId = $blnMobile && $objPage->mobileLayout ? $objPage->mobileLayout : $objPage->layout;
     $objLayout = \LayoutModel::findByPk($intId);
     // Die if there is no layout
     if (null === $objLayout) {
         $this->log('Could not find layout ID "' . $intId . '"', __METHOD__, TL_ERROR);
         throw new NoLayoutSpecifiedException('No layout specified');
     }
     $objPage->hasJQuery = $objLayout->addJQuery;
     $objPage->hasMooTools = $objLayout->addMooTools;
     $objPage->isMobile = $blnMobile;
     return $objLayout;
 }
コード例 #4
0
ファイル: Controller.php プロジェクト: contao/core-bundle
 /**
  * Replace the dynamic script tags (see #4203)
  *
  * @param string $strBuffer The string with the tags to be replaced
  *
  * @return string The string with the replaced tags
  */
 public static function replaceDynamicScriptTags($strBuffer)
 {
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags']) && is_array($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'])) {
         foreach ($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'] as $callback) {
             $strBuffer = static::importStatic($callback[0])->{$callback[1]}($strBuffer);
         }
     }
     $arrReplace = array();
     $strScripts = '';
     // Add the internal jQuery scripts
     if (!empty($GLOBALS['TL_JQUERY']) && is_array($GLOBALS['TL_JQUERY'])) {
         foreach (array_unique($GLOBALS['TL_JQUERY']) as $script) {
             $strScripts .= "\n" . trim($script) . "\n";
         }
     }
     $arrReplace['[[TL_JQUERY]]'] = $strScripts;
     $strScripts = '';
     // Add the internal MooTools scripts
     if (!empty($GLOBALS['TL_MOOTOOLS']) && is_array($GLOBALS['TL_MOOTOOLS'])) {
         foreach (array_unique($GLOBALS['TL_MOOTOOLS']) as $script) {
             $strScripts .= "\n" . trim($script) . "\n";
         }
     }
     $arrReplace['[[TL_MOOTOOLS]]'] = $strScripts;
     $strScripts = '';
     // Add the internal <body> tags
     if (!empty($GLOBALS['TL_BODY']) && is_array($GLOBALS['TL_BODY'])) {
         foreach (array_unique($GLOBALS['TL_BODY']) as $script) {
             $strScripts .= trim($script) . "\n";
         }
     }
     global $objPage;
     $objLayout = \LayoutModel::findByPk($objPage->layoutId);
     $blnCombineScripts = $objLayout === null ? false : $objLayout->combineScripts;
     $arrReplace['[[TL_BODY]]'] = $strScripts;
     $strScripts = '';
     $objCombiner = new \Combiner();
     // Add the CSS framework style sheets
     if (!empty($GLOBALS['TL_FRAMEWORK_CSS']) && is_array($GLOBALS['TL_FRAMEWORK_CSS'])) {
         foreach (array_unique($GLOBALS['TL_FRAMEWORK_CSS']) as $stylesheet) {
             $objCombiner->add($stylesheet);
         }
     }
     // Add the internal style sheets
     if (!empty($GLOBALS['TL_CSS']) && is_array($GLOBALS['TL_CSS'])) {
         foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) {
             $options = \StringUtil::resolveFlaggedUrl($stylesheet);
             if ($options->static) {
                 if ($options->mtime === null) {
                     $options->mtime = filemtime(TL_ROOT . '/' . $stylesheet);
                 }
                 $objCombiner->add($stylesheet, $options->mtime, $options->media);
             } else {
                 $strScripts .= \Template::generateStyleTag(static::addStaticUrlTo($stylesheet), $options->media) . "\n";
             }
         }
     }
     // Add the user style sheets
     if (!empty($GLOBALS['TL_USER_CSS']) && is_array($GLOBALS['TL_USER_CSS'])) {
         foreach (array_unique($GLOBALS['TL_USER_CSS']) as $stylesheet) {
             $options = \StringUtil::resolveFlaggedUrl($stylesheet);
             if ($options->static) {
                 $objCombiner->add($stylesheet, $options->mtime, $options->media);
             } else {
                 $strScripts .= \Template::generateStyleTag(static::addStaticUrlTo($stylesheet), $options->media) . "\n";
             }
         }
     }
     // Create the aggregated style sheet
     if ($objCombiner->hasEntries()) {
         if ($blnCombineScripts) {
             $strScripts .= \Template::generateStyleTag($objCombiner->getCombinedFile(), 'all') . "\n";
         } else {
             foreach ($objCombiner->getFileUrls() as $strUrl) {
                 $strScripts .= \Template::generateStyleTag($strUrl, 'all') . "\n";
             }
         }
     }
     $arrReplace['[[TL_CSS]]'] = $strScripts;
     $strScripts = '';
     // Add the internal scripts
     if (!empty($GLOBALS['TL_JAVASCRIPT']) && is_array($GLOBALS['TL_JAVASCRIPT'])) {
         $objCombiner = new \Combiner();
         $objCombinerAsync = new \Combiner();
         foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) {
             $options = \StringUtil::resolveFlaggedUrl($javascript);
             if ($options->static) {
                 if ($options->mtime === null) {
                     $options->mtime = filemtime(TL_ROOT . '/' . $javascript);
                 }
                 $options->async ? $objCombinerAsync->add($javascript, $options->mtime) : $objCombiner->add($javascript, $options->mtime);
             } else {
                 $strScripts .= \Template::generateScriptTag(static::addStaticUrlTo($javascript), $options->async) . "\n";
             }
         }
         // Create the aggregated script and add it before the non-static scripts (see #4890)
         if ($objCombiner->hasEntries()) {
             if ($blnCombineScripts) {
                 $strScripts = \Template::generateScriptTag($objCombiner->getCombinedFile()) . "\n" . $strScripts;
             } else {
                 $arrReversed = array_reverse($objCombiner->getFileUrls());
                 foreach ($arrReversed as $strUrl) {
                     $strScripts = \Template::generateScriptTag($strUrl) . "\n" . $strScripts;
                 }
             }
         }
         if ($objCombinerAsync->hasEntries()) {
             if ($blnCombineScripts) {
                 $strScripts = \Template::generateScriptTag($objCombinerAsync->getCombinedFile(), true) . "\n" . $strScripts;
             } else {
                 $arrReversed = array_reverse($objCombinerAsync->getFileUrls());
                 foreach ($arrReversed as $strUrl) {
                     $strScripts = \Template::generateScriptTag($strUrl, true) . "\n" . $strScripts;
                 }
             }
         }
     }
     // Add the internal <head> tags
     if (!empty($GLOBALS['TL_HEAD']) && is_array($GLOBALS['TL_HEAD'])) {
         foreach (array_unique($GLOBALS['TL_HEAD']) as $head) {
             $strScripts .= trim($head) . "\n";
         }
     }
     $arrReplace['[[TL_HEAD]]'] = $strScripts;
     return str_replace(array_keys($arrReplace), array_values($arrReplace), $strBuffer);
 }