/**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     if (is_null($objPage) || TL_MODE == 'BE') {
         $objPage = \PageModel::findFirstPublishedRootByHostAndLanguage(\Environment::get('host'), 'de');
     }
     // Limit the total number of items (see #2652)
     if ($this->numberOfItems > 0) {
         $this->arrImages = array_slice($this->arrImages, 0, $this->numberOfItems);
     }
     $offset = 0;
     $total = count($this->arrImages);
     $limit = $total;
     $rowcount = 0;
     $colwidth = floor(100 / $this->perRow);
     $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $this->perRow) : floor(\Config::get('maxImageWidth') / $this->perRow);
     $body = array();
     // Rows
     for ($i = $offset; $i < $limit; $i = $i + $this->perRow) {
         $class_tr = '';
         if ($rowcount == 0) {
             $class_tr .= ' row_first';
         }
         if ($i + $this->perRow >= $limit) {
             $class_tr .= ' row_last';
         }
         $class_eo = $rowcount % 2 == 0 ? ' even' : ' odd';
         // Columns
         for ($j = 0; $j < $this->perRow; $j++) {
             $class_td = '';
             if ($j == 0) {
                 $class_td .= ' col_first';
             }
             if ($j == $this->perRow - 1) {
                 $class_td .= ' col_last';
             }
             $objCell = new \stdClass();
             $key = 'row_' . $rowcount . $class_tr . $class_eo;
             // Empty cell
             if (!is_array($this->arrImages[$i + $j]) || $j + $i >= $limit) {
                 $objCell->colWidth = $colwidth . '%';
                 $objCell->class = 'col_' . $j . $class_td;
             } else {
                 $this->addImageToTemplate($objCell, $this->arrImages[$i + $j], $intMaxWidth, $strLightboxId);
                 // Add column width and class
                 $objCell->href = $this->arrImages[$i + $j]['imageUrl'];
                 $objCell->colWidth = $colwidth . '%';
                 $objCell->class = 'col_' . $j . $class_td;
             }
             $body[$key][$j] = $objCell;
         }
         ++$rowcount;
     }
     $this->Template->body = $body;
 }
예제 #2
0
 /**
  * Modify the cached key
  *
  * @param string $key
  *
  * @return string
  */
 public function modifyCacheKey($key)
 {
     if ($GLOBALS['objPage']->rootId) {
         // The page is being cached
         $rootPage = \PageModel::findByPk($GLOBALS['objPage']->rootId);
     } else {
         // Page loaded from cache, global $objPage not available
         $rootPage = \PageModel::findFirstPublishedRootByHostAndLanguage(\Environment::get('host'), $GLOBALS['TL_LANGUAGE']);
     }
     if ($rootPage !== null) {
         $key .= $this->isCookiebarEnabled($rootPage) ? '_cookiebar' : '';
     }
     return $key;
 }
예제 #3
0
파일: Frontend.php 프로젝트: rburch/core
 /**
  * Try to find a root page based on language and URL
  * @return \Model
  */
 public static function getRootPageFromUrl()
 {
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getRootPageFromUrl']) && is_array($GLOBALS['TL_HOOKS']['getRootPageFromUrl'])) {
         foreach ($GLOBALS['TL_HOOKS']['getRootPageFromUrl'] as $callback) {
             if (is_object($objRootPage = static::importStatic($callback[0])->{$callback}[1]())) {
                 return $objRootPage;
             }
         }
     }
     $host = \Environment::get('host');
     // The language is set in the URL
     if ($GLOBALS['TL_CONFIG']['addLanguageToUrl'] && !empty($_GET['language'])) {
         $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, \Input::get('language'));
         // No matching root page found
         if ($objRootPage === null) {
             header('HTTP/1.1 404 Not Found');
             \System::log('No root page found (host "' . $host . '", language "' . \Input::get('language') . '"', 'Frontend getRootPageFromUrl()', TL_ERROR);
             die('No root page found');
         }
     } else {
         $accept_language = \Environment::get('httpAcceptLanguage');
         // Find the matching root pages (thanks to Andreas Schempp)
         $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, $accept_language);
         // No matching root page found
         if ($objRootPage === null) {
             header('HTTP/1.1 404 Not Found');
             \System::log('No root page found (host "' . \Environment::get('host') . '", languages "' . implode(', ', \Environment::get('httpAcceptLanguage')) . '")', 'Frontend getRootPageFromUrl()', TL_ERROR);
             die('No root page found');
         }
         // Redirect to the language root (e.g. en/)
         if ($GLOBALS['TL_CONFIG']['addLanguageToUrl'] && !$GLOBALS['TL_CONFIG']['doNotRedirectEmpty'] && \Environment::get('request') == '') {
             static::redirect((!$GLOBALS['TL_CONFIG']['rewriteURL'] ? 'index.php/' : '') . $objRootPage->language . '/', 302);
         }
     }
     return $objRootPage;
 }