Beispiel #1
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $rows = \StringUtil::deserialize($this->tableitems);
     $this->Template->id = 'table_' . $this->id;
     $this->Template->summary = \StringUtil::specialchars($this->summary);
     $this->Template->useHeader = $this->thead ? true : false;
     $this->Template->useFooter = $this->tfoot ? true : false;
     $this->Template->useLeftTh = $this->tleft ? true : false;
     $this->Template->sortable = $this->sortable ? true : false;
     $arrHeader = array();
     $arrBody = array();
     $arrFooter = array();
     // Table header
     if ($this->thead) {
         foreach ($rows[0] as $i => $v) {
             // Set table sort cookie
             if ($this->sortable && $i == $this->sortIndex) {
                 $co = 'TS_TABLE_' . $this->id;
                 $so = $this->sortOrder == 'descending' ? 'desc' : 'asc';
                 if (\Input::cookie($co) == '') {
                     \System::setCookie($co, $i . '|' . $so, 0);
                 }
             }
             // Add cell
             $arrHeader[] = array('class' => 'head_' . $i . ($i == 0 ? ' col_first' : '') . ($i == count($rows[0]) - 1 ? ' col_last' : '') . ($i == 0 && $this->tleft ? ' unsortable' : ''), 'content' => $v != '' ? nl2br_html5($v) : ' ');
         }
         array_shift($rows);
     }
     $this->Template->header = $arrHeader;
     $limit = $this->tfoot ? count($rows) - 1 : count($rows);
     // Table body
     for ($j = 0; $j < $limit; $j++) {
         $class_tr = '';
         if ($j == 0) {
             $class_tr .= ' row_first';
         }
         if ($j == $limit - 1) {
             $class_tr .= ' row_last';
         }
         $class_eo = $j % 2 == 0 ? ' odd' : ' even';
         foreach ($rows[$j] as $i => $v) {
             $class_td = '';
             if ($i == 0) {
                 $class_td .= ' col_first';
             }
             if ($i == count($rows[$j]) - 1) {
                 $class_td .= ' col_last';
             }
             $arrBody['row_' . $j . $class_tr . $class_eo][] = array('class' => 'col_' . $i . $class_td, 'content' => $v != '' ? nl2br_html5($v) : '&nbsp;');
         }
     }
     $this->Template->body = $arrBody;
     // Table footer
     if ($this->tfoot) {
         foreach ($rows[count($rows) - 1] as $i => $v) {
             $arrFooter[] = array('class' => 'foot_' . $i . ($i == 0 ? ' col_first' : '') . ($i == count($rows[count($rows) - 1]) - 1 ? ' col_last' : ''), 'content' => $v != '' ? nl2br_html5($v) : '&nbsp;');
         }
     }
     $this->Template->footer = $arrFooter;
 }
Beispiel #2
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrObjects = array('u' => 'cuser', 'g' => 'cgroup', 'w' => 'cworld');
       $return = '  <table id="ctrl_defaultChmod" class="tl_chmod">
   <tr>
     <th></th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['editpage'] . '</th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['editnavigation'] . '</th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['deletepage'] . '</th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['editarticles'] . '</th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['movearticles'] . '</th>
     <th scope="col">' . $GLOBALS['TL_LANG']['CHMOD']['deletearticles'] . '</th>
   </tr>';
       // Build rows for user, group and world
       foreach ($arrObjects as $k => $v) {
           $return .= '
   <tr>
     <th scope="row">' . $GLOBALS['TL_LANG']['CHMOD'][$v] . '</th>';
           // Add checkboxes
           for ($j = 1; $j <= 6; $j++) {
               $return .= '
     <td><input type="checkbox" name="' . $this->strName . '[]" value="' . \StringUtil::specialchars($k . $j) . '"' . static::optionChecked($k . $j, $this->varValue) . ' onfocus="Backend.getScrollOffset()"></td>';
           }
           $return .= '
   </tr>';
       }
       return $return . '
 </table>';
   }
Beispiel #3
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     if ($this->linkTitle == '') {
         $this->linkTitle = $GLOBALS['TL_LANG']['MSC']['backToTop'];
     }
     $this->Template->label = $this->linkTitle;
     $this->Template->title = \StringUtil::specialchars($this->linkTitle);
     $this->Template->request = ampersand(\Environment::get('request'), true);
 }
Beispiel #4
0
 /**
  * Generate the widget and return it as string
  *
  * @return string
  */
 public function generate()
 {
     $arrOptions = array();
     foreach ($this->arrOptions as $i => $arrOption) {
         $arrOptions[] = sprintf('<input type="radio" name="%s" id="opt_%s" class="tl_radio" value="%s"%s%s onfocus="Backend.getScrollOffset()"> <label for="opt_%s">%s</label>', $this->strName, $this->strId . '_' . $i, \StringUtil::specialchars($arrOption['value']), $this->isChecked($arrOption), $this->getAttributes(), $this->strId . '_' . $i, $arrOption['label']);
     }
     // Add a "no entries found" message if there are no options
     if (empty($arrOptions)) {
         $arrOptions[] = '<p class="tl_noopt">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
     }
     return sprintf('<fieldset id="ctrl_%s" class="tl_radio_container%s"><legend>%s%s%s%s</legend>%s</fieldset>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->mandatory ? '<span class="invisible">' . $GLOBALS['TL_LANG']['MSC']['mandatory'] . ' </span>' : '', $this->strLabel, $this->mandatory ? '<span class="mandatory">*</span>' : '', $this->xlabel, implode('<br>', $arrOptions), $this->wizard);
 }
Beispiel #5
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $link = '/articles/';
     $objArticle = $this->objArticle;
     if ($objArticle->inColumn != 'main') {
         $link .= $objArticle->inColumn . ':';
     }
     $link .= $objArticle->alias ?: $objArticle->id;
     $this->Template->href = $this->objParent->getFrontendUrl($link);
     // Clean the RTE output
     $this->Template->text = \StringUtil::toHtml5($objArticle->teaser);
     $this->Template->headline = $objArticle->title;
     $this->Template->readMore = \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->title));
     $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
 }
Beispiel #6
0
 /**
  * Return the "toggle visibility" button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
 {
     if (strlen(Input::get('tid'))) {
         $this->toggleVisibility(Input::get('tid'), Input::get('state') == 1, @func_get_arg(12) ?: null);
         $this->redirect($this->getReferer());
     }
     // Check permissions AFTER checking the tid, so hacking attempts are logged
     if (!$this->User->hasAccess('tl_member_group::disable', 'alexf')) {
         return '';
     }
     $href .= '&amp;tid=' . $row['id'] . '&amp;state=' . $row['disable'];
     if ($row['disable']) {
         $icon = 'invisible.svg';
     }
     return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['disable'] ? 0 : 1) . '"') . '</a> ';
 }
 /**
  * Generate the module
  *
  * @throws \Exception
  */
 protected function compile()
 {
     \System::loadLanguageFile('tl_maintenance');
     $this->Template->content = '';
     $this->Template->href = $this->getReferer(true);
     $this->Template->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']);
     $this->Template->button = $GLOBALS['TL_LANG']['MSC']['backBT'];
     foreach ($GLOBALS['TL_MAINTENANCE'] as $callback) {
         $this->import($callback);
         if (!$this->{$callback} instanceof \executable) {
             throw new \Exception("{$callback} is not an executable class");
         }
         $buffer = $this->{$callback}->run();
         if ($this->{$callback}->isActive()) {
             $this->Template->content = $buffer;
             break;
         } else {
             $this->Template->content .= $buffer;
         }
     }
 }
Beispiel #8
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $objFile = new \File($this->singleSRC);
     if ($this->linkTitle == '') {
         $this->linkTitle = \StringUtil::specialchars($objFile->basename);
     }
     $strHref = \Environment::get('request');
     // Remove an existing file parameter (see #5683)
     if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
         $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
     }
     $strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objFile->value);
     $this->Template->link = $this->linkTitle;
     $this->Template->title = \StringUtil::specialchars($this->titleText ?: sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename));
     $this->Template->href = $strHref;
     $this->Template->filesize = $this->getReadableSize($objFile->filesize, 1);
     $this->Template->icon = \Image::getPath($objFile->icon);
     $this->Template->mime = $objFile->mime;
     $this->Template->extension = $objFile->extension;
     $this->Template->path = $objFile->dirname;
 }
Beispiel #9
0
 /**
  * Generate a link and return it as string
  *
  * @param string    $strLink
  * @param NewsModel $objArticle
  * @param boolean   $blnAddArchive
  * @param boolean   $blnIsReadMore
  *
  * @return string
  */
 protected function generateLink($strLink, $objArticle, $blnAddArchive = false, $blnIsReadMore = false)
 {
     // Internal link
     if ($objArticle->source != 'external') {
         return sprintf('<a href="%s" title="%s" itemprop="url">%s%s</a>', \News::generateNewsUrl($objArticle, $blnAddArchive), \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true), $strLink, $blnIsReadMore ? '<span class="invisible"> ' . $objArticle->headline . '</span>' : '');
     }
     // Encode e-mail addresses
     if (substr($objArticle->url, 0, 7) == 'mailto:') {
         $strArticleUrl = \StringUtil::encodeEmail($objArticle->url);
     } else {
         $strArticleUrl = ampersand($objArticle->url);
     }
     // External link
     return sprintf('<a href="%s" title="%s"%s itemprop="url">%s</a>', $strArticleUrl, \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $strArticleUrl)), $objArticle->target ? ' target="_blank"' : '', $strLink);
 }
Beispiel #10
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $this->import('Database');
       $arrButtons = array('edit', 'copy', 'delete', 'enable', 'drag');
       // Get all modules of the current theme
       $objModules = $this->Database->prepare("SELECT id, name, type FROM tl_module WHERE pid=(SELECT pid FROM " . $this->strTable . " WHERE id=?) ORDER BY name")->execute($this->currentRecord);
       // Add the articles module
       $modules[] = array('id' => 0, 'name' => $GLOBALS['TL_LANG']['MOD']['article'][0], 'type' => 'article');
       if ($objModules->numRows) {
           $modules = array_merge($modules, $objModules->fetchAllAssoc());
       }
       $GLOBALS['TL_LANG']['FMD']['article'] = $GLOBALS['TL_LANG']['MOD']['article'];
       // Add the module type (see #3835)
       foreach ($modules as $k => $v) {
           $v['type'] = $GLOBALS['TL_LANG']['FMD'][$v['type']][0];
           $modules[$k] = $v;
       }
       $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->currentRecord);
       // Show all columns and filter in PageRegular (see #3273)
       $cols = array('header', 'left', 'right', 'main', 'footer');
       // Add custom layout sections
       if ($objRow->sections != '') {
           $arrSections = \StringUtil::deserialize($objRow->sections);
           if (!empty($arrSections) && is_array($arrSections)) {
               foreach ($arrSections as $v) {
                   $cols[$v['id']] = $v['id'];
                   $GLOBALS['TL_LANG']['COLS'][$v['id']] = $v['title'];
               }
           }
       }
       // Get the new value
       if (\Input::post('FORM_SUBMIT') == $this->strTable) {
           $this->varValue = \Input::post($this->strId);
       }
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || !$this->varValue[0]) {
           $this->varValue = array('');
       } else {
           $arrCols = array();
           // Initialize the sorting order
           foreach ($cols as $col) {
               $arrCols[$col] = array();
           }
           foreach ($this->varValue as $v) {
               $arrCols[$v['col']][] = $v;
           }
           $this->varValue = array();
           foreach ($arrCols as $arrCol) {
               $this->varValue = array_merge($this->varValue, $arrCol);
           }
       }
       // Add the label and the return wizard
       $return = '<table id="ctrl_' . $this->strId . '" class="tl_modulewizard">
 <thead>
 <tr>
   <th>' . $GLOBALS['TL_LANG']['MSC']['mw_module'] . '</th>
   <th>' . $GLOBALS['TL_LANG']['MSC']['mw_column'] . '</th>
   <th></th>
 </tr>
 </thead>
 <tbody class="sortable">';
       // Add the input fields
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $options = '';
           // Add modules
           foreach ($modules as $v) {
               $options .= '<option value="' . \StringUtil::specialchars($v['id']) . '"' . static::optionSelected($v['id'], $this->varValue[$i]['mod']) . '>' . $v['name'] . ' [' . $v['type'] . ']</option>';
           }
           $return .= '
 <tr>
   <td><select name="' . $this->strId . '[' . $i . '][mod]" class="tl_select tl_chosen" onfocus="Backend.getScrollOffset()" onchange="Backend.updateModuleLink(this)">' . $options . '</select></td>';
           $options = '';
           // Add columns
           foreach ($cols as $v) {
               $options .= '<option value="' . \StringUtil::specialchars($v) . '"' . static::optionSelected($v, $this->varValue[$i]['col']) . '>' . $GLOBALS['TL_LANG']['COLS'][$v] . '</option>';
           }
           $return .= '
   <td><select name="' . $this->strId . '[' . $i . '][col]" class="tl_select_column" onfocus="Backend.getScrollOffset()">' . $options . '</select></td>
   <td>';
           // Add buttons
           foreach ($arrButtons as $button) {
               if ($button == 'edit') {
                   $return .= ' <a href="contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->varValue[$i]['mod'] . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['tl_layout']['edit_module']) . '" class="module_link" ' . ($this->varValue[$i]['mod'] > 0 ? '' : ' style="display:none"') . ' onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . \StringUtil::specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_layout']['edit_module'])) . '\',\'url\':this.href});return false">' . \Image::getHtml('edit.svg') . '</a>' . \Image::getHtml('edit_.svg', '', 'class="module_image"' . ($this->varValue[$i]['mod'] > 0 ? ' style="display:none"' : ''));
               } elseif ($button == 'drag') {
                   $return .= ' <button type="button" class="drag-handle" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['move']) . '">' . \Image::getHtml('drag.svg') . '</button>';
               } elseif ($button == 'enable') {
                   $return .= ' <button type="button" data-command="enable" class="mw_enable" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['mw_enable']) . '">' . \Image::getHtml($this->varValue[$i]['enable'] ? 'visible.svg' : 'invisible.svg') . '</button><input name="' . $this->strId . '[' . $i . '][enable]" type="checkbox" class="tl_checkbox mw_enable" value="1" onfocus="Backend.getScrollOffset()"' . ($this->varValue[$i]['enable'] ? ' checked' : '') . '>';
               } else {
                   $return .= ' <button type="button" data-command="' . $button . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['mw_' . $button]) . '">' . \Image::getHtml($button . '.svg') . '</button>';
               }
           }
           $return .= '</td>
 </tr>';
       }
       return $return . '
 </tbody>
 </table>
 <script>Backend.moduleWizard("ctrl_' . $this->strId . '")</script>';
   }
Beispiel #11
0
 /**
  * Generate an image tag and return it as string
  *
  * @param string $src        The image path
  * @param string $alt        An optional alt attribute
  * @param string $attributes A string of other attributes
  *
  * @return string The image HTML tag
  */
 public static function getHtml($src, $alt = '', $attributes = '')
 {
     $src = static::getPath($src);
     if ($src == '') {
         return '';
     }
     if (!is_file(TL_ROOT . '/' . $src)) {
         // Handle public bundle resources
         if (file_exists(TL_ROOT . '/web/' . $src)) {
             $src = 'web/' . $src;
         } else {
             return '';
         }
     }
     $objFile = new \File($src);
     // Strip the web/ prefix (see #337)
     if (strncmp($src, 'web/', 4) === 0) {
         $src = substr($src, 4);
     }
     $static = strncmp($src, 'assets/', 7) === 0 ? TL_ASSETS_URL : TL_FILES_URL;
     return '<img src="' . $static . \System::urlEncode($src) . '" width="' . $objFile->width . '" height="' . $objFile->height . '" alt="' . \StringUtil::specialchars($alt) . '"' . ($attributes != '' ? ' ' . $attributes : '') . '>';
 }
Beispiel #12
0
 /**
  * Return the edit header button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function editHeader($row, $href, $label, $title, $icon, $attributes)
 {
     return $this->User->canEditFieldsOf('tl_style_sheet') ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $row['id']) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ' : Image::getHtml(preg_replace('/\\.svg$/i', '_.svg', $icon)) . ' ';
 }
Beispiel #13
0
 /**
  * Generate all page links and return them as array
  *
  * @return array The page links as array
  */
 public function getItemsAsArray()
 {
     $arrLinks = array();
     $intNumberOfLinks = floor($this->intNumberOfLinks / 2);
     $intFirstOffset = $this->intPage - $intNumberOfLinks - 1;
     if ($intFirstOffset > 0) {
         $intFirstOffset = 0;
     }
     $intLastOffset = $this->intPage + $intNumberOfLinks - $this->intTotalPages;
     if ($intLastOffset < 0) {
         $intLastOffset = 0;
     }
     $intFirstLink = $this->intPage - $intNumberOfLinks - $intLastOffset;
     if ($intFirstLink < 1) {
         $intFirstLink = 1;
     }
     $intLastLink = $this->intPage + $intNumberOfLinks - $intFirstOffset;
     if ($intLastLink > $this->intTotalPages) {
         $intLastLink = $this->intTotalPages;
     }
     for ($i = $intFirstLink; $i <= $intLastLink; $i++) {
         if ($i == $this->intPage) {
             $arrLinks[] = array('page' => $i, 'href' => null, 'title' => null);
         } else {
             $arrLinks[] = array('page' => $i, 'href' => $this->linkToPage($i), 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['goToPage'], $i)));
         }
     }
     return $arrLinks;
 }
 /**
  * Generate the widget and return it as string
  *
  * @return string The widget markup
  */
 public function generate()
 {
     $strOptions = '';
     $blnHasGroups = false;
     if ($this->multiple) {
         $this->strName .= '[]';
     } elseif (is_array($this->varValue)) {
         $this->varValue = $this->varValue[0];
     }
     // Add empty option if there are none
     if (empty($this->arrOptions)) {
         $this->arrOptions = array(array('value' => '', 'label' => '-'));
     }
     foreach ($this->arrOptions as $arrOption) {
         if ($arrOption['group']) {
             if ($blnHasGroups) {
                 $strOptions .= '</optgroup>';
             }
             $strOptions .= sprintf('<optgroup label="%s">', \StringUtil::specialchars($arrOption['label']));
             $blnHasGroups = true;
             continue;
         }
         $strOptions .= sprintf('<option value="%s"%s>%s</option>', $arrOption['value'], $this->isSelected($arrOption), $arrOption['label']);
     }
     if ($blnHasGroups) {
         $strOptions .= '</optgroup>';
     }
     return sprintf('<select name="%s" id="ctrl_%s" class="%s"%s>%s</select>', $this->strName, $this->strId, $this->class, $this->getAttributes(), $strOptions);
 }
Beispiel #15
0
 /**
  * Return the show file button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function showFile($row, $href, $label, $title, $icon, $attributes)
 {
     return '<a href="contao/popup.php?src=' . base64_encode($row['id']) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . ' onclick="Backend.openModalIframe({\'width\':' . $row['popupWidth'] . ',\'title\':\'' . str_replace("'", "\\'", StringUtil::specialchars($row['fileNameEncoded'])) . '\',\'url\':this.href,\'height\':' . $row['popupHeight'] . '});return false">' . Image::getHtml($icon, $label) . '</a> ';
 }
Beispiel #16
0
 /**
  * Replace insert tags with their values
  *
  * @param string  $strBuffer The text with the tags to be replaced
  * @param boolean $blnCache  If false, non-cacheable tags will be replaced
  *
  * @return string The text with the replaced tags
  */
 protected function doReplace($strBuffer, $blnCache)
 {
     /** @var PageModel $objPage */
     global $objPage;
     // Preserve insert tags
     if (\Config::get('disableInsertTags')) {
         return \StringUtil::restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/{{([^{}]+)}}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     if (count($tags) < 2) {
         return \StringUtil::restoreBasicEntities($strBuffer);
     }
     $strBuffer = '';
     // Create one cache per cache setting (see #7700)
     static $arrItCache;
     $arrCache =& $arrItCache[$blnCache];
     for ($_rit = 0, $_cnt = count($tags); $_rit < $_cnt; $_rit += 2) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         $flags = explode('|', $strTag);
         $tag = array_shift($flags);
         $elements = explode('::', $tag);
         // Load the value from cache
         if (isset($arrCache[$strTag]) && !in_array('refresh', $flags)) {
             $strBuffer .= $arrCache[$strTag];
             continue;
         }
         // Skip certain elements if the output will be cached
         if ($blnCache) {
             if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'post' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || $elements[0] == 'toggle_view' || strncmp($elements[0], 'cache_', 6) === 0 || in_array('uncached', $flags)) {
                 $strBuffer .= '{{' . $strTag . '}}';
                 continue;
             }
         }
         $arrCache[$strTag] = '';
         // Replace the tag
         switch (strtolower($elements[0])) {
             // Date
             case 'date':
                 $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('dateFormat'));
                 break;
                 // Accessibility tags
             // Accessibility tags
             case 'lang':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '</span>';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // Line break
             // Line break
             case 'br':
                 $arrCache[$strTag] = '<br>';
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \StringUtil::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" title="' . $strEmail . '" class="email">';
                         break;
                     case 'email_url':
                         $arrCache[$strTag] = $strEmail;
                         break;
                 }
                 break;
                 // Label tags
             // Label tags
             case 'label':
                 $keys = explode(':', $elements[1]);
                 if (count($keys) < 2) {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $file = $keys[0];
                 // Map the key (see #7217)
                 switch ($file) {
                     case 'CNT':
                         $file = 'countries';
                         break;
                     case 'LNG':
                         $file = 'languages';
                         break;
                     case 'MOD':
                     case 'FMD':
                         $file = 'modules';
                         break;
                     case 'FFL':
                         $file = 'tl_form_field';
                         break;
                     case 'CACHE':
                         $file = 'tl_page';
                         break;
                     case 'XPL':
                         $file = 'explain';
                         break;
                     case 'XPT':
                         $file = 'exception';
                         break;
                     case 'MSC':
                     case 'ERR':
                     case 'CTE':
                     case 'PTY':
                     case 'FOP':
                     case 'CHMOD':
                     case 'DAYS':
                     case 'MONTHS':
                     case 'UNITS':
                     case 'CONFIRM':
                     case 'DP':
                     case 'COLS':
                         $file = 'default';
                         break;
                 }
                 \System::loadLanguageFile($file);
                 if (count($keys) == 2) {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]];
                 } else {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]];
                 }
                 break;
                 // Front end user
             // Front end user
             case 'user':
                 if (FE_USER_LOGGED_IN) {
                     $this->import('FrontendUser', 'User');
                     $value = $this->User->{$elements[1]};
                     if ($value == '') {
                         $arrCache[$strTag] = $value;
                         break;
                     }
                     $this->loadDataContainer('tl_member');
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $value = \StringUtil::deserialize($value);
                     // Decrypt the value
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['encrypt']) {
                         $value = \Encryption::decrypt($value);
                     }
                     $rgxp = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['rgxp'];
                     $opts = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['options'];
                     $rfrc = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['reference'];
                     if ($rgxp == 'date') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('dateFormat'), $value);
                     } elseif ($rgxp == 'time') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('timeFormat'), $value);
                     } elseif ($rgxp == 'datim') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('datimFormat'), $value);
                     } elseif (is_array($value)) {
                         $arrCache[$strTag] = implode(', ', $value);
                     } elseif (is_array($opts) && array_is_assoc($opts)) {
                         $arrCache[$strTag] = isset($opts[$value]) ? $opts[$value] : $value;
                     } elseif (is_array($rfrc)) {
                         $arrCache[$strTag] = isset($rfrc[$value]) ? is_array($rfrc[$value]) ? $rfrc[$value][0] : $rfrc[$value] : $value;
                     } else {
                         $arrCache[$strTag] = $value;
                     }
                     // Convert special characters (see #1890)
                     $arrCache[$strTag] = \StringUtil::specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
             case 'link_target':
             case 'link_name':
                 $strTarget = null;
                 // Back link
                 if ($elements[1] == 'back') {
                     $strUrl = 'javascript:history.go(-1)';
                     $strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
                     // No language files if the page is cached
                     if (!strlen($strTitle)) {
                         $strTitle = 'Go back';
                     }
                     $strName = $strTitle;
                 } elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
                     $strUrl = $elements[1];
                     $strTitle = $elements[1];
                     $strName = str_replace(array('http://', 'https://'), '', $elements[1]);
                 } else {
                     // User login page
                     if ($elements[1] == 'login') {
                         if (!FE_USER_LOGGED_IN) {
                             break;
                         }
                         $this->import('FrontendUser', 'User');
                         $elements[1] = $this->User->loginPage;
                     }
                     $objNextPage = \PageModel::findByIdOrAlias($elements[1]);
                     if ($objNextPage === null) {
                         break;
                     }
                     // Page type specific settings (thanks to Andreas Schempp)
                     switch ($objNextPage->type) {
                         case 'redirect':
                             $strUrl = $objNextPage->url;
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \StringUtil::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if ($objNextPage->jumpTo) {
                                 /** @var PageModel $objNext */
                                 $objNext = $objNextPage->getRelated('jumpTo');
                             } else {
                                 $objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
                             }
                             if ($objNext instanceof PageModel) {
                                 $strUrl = $objNext->getFrontendUrl();
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             $strUrl = $objNextPage->getFrontendUrl();
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? ' target="_blank"' : '';
                     $strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'link':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget, $strName);
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = \StringUtil::specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                     case 'link_name':
                         $arrCache[$strTag] = $strName;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
             case 'email_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = ltrim($strOutput);
                 } else {
                     $arrCache[$strTag] = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $elements[1]) . '</p>';
                 }
                 break;
                 // Insert content element
             // Insert content element
             case 'insert_content':
                 $arrCache[$strTag] = $this->getContentElement($elements[1]);
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->getFrontendModule($elements[1]);
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->getForm($elements[1]);
                 break;
                 // Article
             // Article
             case 'article':
             case 'article_open':
             case 'article_url':
             case 'article_title':
                 if (($objArticle = \ArticleModel::findByIdOrAlias($elements[1])) === null || !($objPid = $objArticle->getRelated('pid')) instanceof PageModel) {
                     break;
                 }
                 /** @var PageModel $objPid */
                 $strUrl = $objPid->getFrontendUrl('/articles/' . ($objArticle->alias ?: $objArticle->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, \StringUtil::specialchars($objArticle->title), $objArticle->title);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, \StringUtil::specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = \StringUtil::specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     $arrCache[$strTag] = \StringUtil::toHtml5($objTeaser->teaser);
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $strQuery = "SELECT MAX(tstamp) AS tc";
                 $bundles = \System::getContainer()->getParameter('kernel.bundles');
                 if (isset($bundles['ContaoNewsBundle'])) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_news) AS tn";
                 }
                 if (isset($bundles['ContaoCalendarBundle'])) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_calendar_events) AS te";
                 }
                 $strQuery .= " FROM tl_content";
                 $objUpdate = \Database::getInstance()->query($strQuery);
                 if ($objUpdate->numRows) {
                     $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('datimFormat'), max($objUpdate->tc, $objUpdate->tn, $objUpdate->te));
                 }
                 break;
                 // Version
             // Version
             case 'version':
                 $arrCache[$strTag] = VERSION . '.' . BUILD;
                 break;
                 // Request token
             // Request token
             case 'request_token':
                 $arrCache[$strTag] = REQUEST_TOKEN;
                 break;
                 // POST data
             // POST data
             case 'post':
                 $arrCache[$strTag] = \Input::post($elements[1]);
                 break;
                 // Mobile/desktop toggle (see #6469)
             // Mobile/desktop toggle (see #6469)
             case 'toggle_view':
                 $strUrl = ampersand(\Environment::get('request'));
                 $strGlue = strpos($strUrl, '?') === false ? '?' : '&amp;';
                 if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=desktop" class="toggle_desktop" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleDesktop'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleDesktop'][0] . '</a>';
                 } else {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=mobile" class="toggle_mobile" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleMobile'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleMobile'][0] . '</a>';
                 }
                 break;
                 // Conditional tags (if)
             // Conditional tags (if)
             case 'iflng':
                 if ($elements[1] != '' && $elements[1] != $objPage->language) {
                     for (; $_rit < $_cnt; $_rit += 2) {
                         if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) {
                             break;
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Conditional tags (if not)
             // Conditional tags (if not)
             case 'ifnlng':
                 if ($elements[1] != '') {
                     $langs = \StringUtil::trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for (; $_rit < $_cnt; $_rit += 2) {
                             if ($tags[$_rit + 1] == 'ifnlng') {
                                 break;
                             }
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Environment
             // Environment
             case 'env':
                 switch ($elements[1]) {
                     case 'host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('host'));
                         break;
                     case 'http_host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost'));
                         break;
                     case 'url':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('url'));
                         break;
                     case 'path':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('base'));
                         break;
                     case 'request':
                         $arrCache[$strTag] = \Environment::get('indexFreeRequest');
                         break;
                     case 'ip':
                         $arrCache[$strTag] = \Environment::get('ip');
                         break;
                     case 'referer':
                         $arrCache[$strTag] = $this->getReferer(true);
                         break;
                     case 'files_url':
                         $arrCache[$strTag] = TL_FILES_URL;
                         break;
                     case 'assets_url':
                     case 'plugins_url':
                     case 'script_url':
                         $arrCache[$strTag] = TL_ASSETS_URL;
                         break;
                     case 'base_url':
                         $arrCache[$strTag] = \System::getContainer()->get('request_stack')->getCurrentRequest()->getBaseUrl();
                         break;
                 }
                 break;
                 // Page
             // Page
             case 'page':
                 if ($elements[1] == 'pageTitle' && $objPage->pageTitle == '') {
                     $elements[1] = 'title';
                 } elseif ($elements[1] == 'parentPageTitle' && $objPage->parentPageTitle == '') {
                     $elements[1] = 'parentTitle';
                 } elseif ($elements[1] == 'mainPageTitle' && $objPage->mainPageTitle == '') {
                     $elements[1] = 'mainTitle';
                 }
                 // Do not use \StringUtil::specialchars() here (see #4687)
                 $arrCache[$strTag] = $objPage->{$elements[1]};
                 break;
                 // User agent
             // User agent
             case 'ua':
                 $ua = \Environment::get('agent');
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = $ua->{$elements[1]};
                 } else {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Abbreviations
             // Abbreviations
             case 'abbr':
             case 'acronym':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
             case 'picture':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 $size = null;
                 $strTemplate = 'picture_default';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         list($key, $value) = explode('=', $strParam);
                         switch ($key) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'alt':
                                 $alt = \StringUtil::specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $value;
                                 break;
                             case 'size':
                                 $size = (int) $value;
                                 break;
                             case 'template':
                                 $strTemplate = preg_replace('/[^a-z0-9_]/i', '', $value);
                                 break;
                         }
                     }
                     $strFile = $arrChunks[0];
                 }
                 if (\Validator::isUuid($strFile)) {
                     // Handle UUIDs
                     $objFile = \FilesModel::findByUuid($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } elseif (is_numeric($strFile)) {
                     // Handle numeric IDs (see #4805)
                     $objFile = \FilesModel::findByPk($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } else {
                     // Check the path
                     if (\Validator::isInsecurePath($strFile)) {
                         throw new \RuntimeException('Invalid path ' . $strFile);
                     }
                 }
                 // Check the maximum image width
                 if (\Config::get('maxImageWidth') > 0 && $width > \Config::get('maxImageWidth')) {
                     $width = \Config::get('maxImageWidth');
                     $height = null;
                 }
                 // Generate the thumbnail image
                 try {
                     // Image
                     if (strtolower($elements[0]) == 'image') {
                         $dimensions = '';
                         $imageObj = \Image::create($strFile, array($width, $height, $mode));
                         $src = $imageObj->executeResize()->getResizedPath();
                         $objFile = new \File(rawurldecode($src));
                         // Add the image dimensions
                         if (($imgSize = $objFile->imageSize) !== false) {
                             $dimensions = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"';
                         }
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . '>';
                     } else {
                         $picture = \Picture::create($strFile, array(0, 0, $size))->getTemplateData();
                         $picture['alt'] = $alt;
                         $picture['class'] = $class;
                         $pictureTemplate = new \FrontendTemplate($strTemplate);
                         $pictureTemplate->setData($picture);
                         $arrCache[$strTag] = $pictureTemplate->parse();
                     }
                     // Add a lightbox link
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0) {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '>' . $arrCache[$strTag] . '</a>';
                     }
                 } catch (\Exception $e) {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Files (UUID or template path)
             // Files (UUID or template path)
             case 'file':
                 if (\Validator::isUuid($elements[1])) {
                     $objFile = \FilesModel::findByUuid($elements[1]);
                     if ($objFile !== null) {
                         $arrCache[$strTag] = $objFile->path;
                         break;
                     }
                 }
                 $arrGet = $_GET;
                 \Input::resetCache();
                 $strFile = $elements[1];
                 // Take arguments and add them to the $_GET array
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]));
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         $arrParam = explode('=', $strParam);
                         $_GET[$arrParam[0]] = $arrParam[1];
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Check the path
                 if (\Validator::isInsecurePath($strFile)) {
                     throw new \RuntimeException('Invalid path ' . $strFile);
                 }
                 // Include .php, .tpl, .xhtml and .html5 files
                 if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
                     ob_start();
                     include TL_ROOT . '/templates/' . $strFile;
                     $arrCache[$strTag] = ob_get_clean();
                 }
                 $_GET = $arrGet;
                 \Input::resetCache();
                 break;
                 // HOOK: pass unknown tags to callback functions
             // HOOK: pass unknown tags to callback functions
             default:
                 if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
                     foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
                         $this->import($callback[0]);
                         $varValue = $this->{$callback[0]}->{$callback[1]}($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt);
                         // see #6672
                         // Replace the tag and stop the loop
                         if ($varValue !== false) {
                             $arrCache[$strTag] = $varValue;
                             break;
                         }
                     }
                 }
                 if (\Config::get('debugMode')) {
                     $GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag;
                 }
                 break;
         }
         // Handle the flags
         if (!empty($flags)) {
             foreach ($flags as $flag) {
                 switch ($flag) {
                     case 'addslashes':
                     case 'stripslashes':
                     case 'standardize':
                     case 'ampersand':
                     case 'specialchars':
                     case 'nl2br':
                     case 'nl2br_pre':
                     case 'strtolower':
                     case 'utf8_strtolower':
                     case 'strtoupper':
                     case 'utf8_strtoupper':
                     case 'ucfirst':
                     case 'lcfirst':
                     case 'ucwords':
                     case 'trim':
                     case 'rtrim':
                     case 'ltrim':
                     case 'utf8_romanize':
                     case 'strrev':
                     case 'urlencode':
                     case 'rawurlencode':
                         $arrCache[$strTag] = $flag($arrCache[$strTag]);
                         break;
                     case 'encodeEmail':
                     case 'decodeEntities':
                         $arrCache[$strTag] = \StringUtil::$flag($arrCache[$strTag]);
                         break;
                     case 'number_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
                         break;
                     case 'currency_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
                         break;
                     case 'readable_size':
                         $arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
                         break;
                     case 'flatten':
                         if (!is_array($arrCache[$strTag])) {
                             break;
                         }
                         $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag]));
                         $result = array();
                         foreach ($it as $leafValue) {
                             $keys = array();
                             foreach (range(0, $it->getDepth()) as $depth) {
                                 $keys[] = $it->getSubIterator($depth)->key();
                             }
                             $result[] = implode('.', $keys) . ': ' . $leafValue;
                         }
                         $arrCache[$strTag] = implode(', ', $result);
                         break;
                         // HOOK: pass unknown flags to callback functions
                     // HOOK: pass unknown flags to callback functions
                     default:
                         if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
                             foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
                                 $this->import($callback[0]);
                                 $varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
                                 // see #5806
                                 // Replace the tag and stop the loop
                                 if ($varValue !== false) {
                                     $arrCache[$strTag] = $varValue;
                                     break;
                                 }
                             }
                         }
                         if (\Config::get('debugMode')) {
                             $GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
                         }
                         break;
                 }
             }
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return \StringUtil::restoreBasicEntities($strBuffer);
 }
 /**
  * Return the edit file source button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function editSource($row, $href, $label, $title, $icon, $attributes)
 {
     return is_file(TL_ROOT . '/' . $row['id']) ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $row['id']) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ' : Image::getHtml(preg_replace('/\\.svg$/i', '_.svg', $icon)) . ' ';
 }
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrSet = array();
       $arrValues = array();
       $blnHasOrder = $this->orderField != '' && is_array($this->{$this->orderField});
       if (!empty($this->varValue)) {
           $objFiles = \FilesModel::findMultipleByUuids((array) $this->varValue);
           $allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
           if ($objFiles !== null) {
               while ($objFiles->next()) {
                   // File system and database seem not in sync
                   if (!file_exists(TL_ROOT . '/' . $objFiles->path)) {
                       continue;
                   }
                   $arrSet[$objFiles->id] = $objFiles->uuid;
                   // Show files and folders
                   if (!$this->isGallery && !$this->isDownloads) {
                       if ($objFiles->type == 'folder') {
                           $arrValues[$objFiles->uuid] = \Image::getHtml('folderC.svg') . ' ' . $objFiles->path;
                       } else {
                           $objFile = new \File($objFiles->path);
                           $strInfo = $objFiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                           if ($objFile->isImage) {
                               $image = \Image::getPath('placeholder.svg');
                               if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                   $image = \Image::get($objFiles->path, 80, 60, 'center_center');
                               }
                               $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . \StringUtil::specialchars($strInfo) . '"');
                           } else {
                               $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                           }
                       }
                   } else {
                       if ($objFiles->type == 'folder') {
                           $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                           if ($objSubfiles === null) {
                               continue;
                           }
                           while ($objSubfiles->next()) {
                               // Skip subfolders
                               if ($objSubfiles->type == 'folder') {
                                   continue;
                               }
                               $objFile = new \File($objSubfiles->path);
                               $strInfo = '<span class="dirname">' . dirname($objSubfiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                               if ($this->isGallery) {
                                   // Only show images
                                   if ($objFile->isImage) {
                                       $image = \Image::getPath('placeholder.svg');
                                       if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                           $image = \Image::get($objSubfiles->path, 80, 60, 'center_center');
                                       }
                                       $arrValues[$objSubfiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . \StringUtil::specialchars($strInfo) . '"');
                                   }
                               } else {
                                   // Only show allowed download types
                                   if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                       $arrValues[$objSubfiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                                   }
                               }
                           }
                       } else {
                           $objFile = new \File($objFiles->path);
                           $strInfo = '<span class="dirname">' . dirname($objFiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                           if ($this->isGallery) {
                               // Only show images
                               if ($objFile->isImage) {
                                   $image = \Image::getPath('placeholder.svg');
                                   if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                       $image = \Image::get($objFiles->path, 80, 60, 'center_center');
                                   }
                                   $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage removable" title="' . \StringUtil::specialchars($strInfo) . '"');
                               }
                           } else {
                               // Only show allowed download types
                               if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                   $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                               }
                           }
                       }
                   }
               }
           }
           // Apply a custom sort order
           if ($blnHasOrder) {
               $arrNew = array();
               foreach ((array) $this->{$this->orderField} as $i) {
                   if (isset($arrValues[$i])) {
                       $arrNew[$i] = $arrValues[$i];
                       unset($arrValues[$i]);
                   }
               }
               if (!empty($arrValues)) {
                   foreach ($arrValues as $k => $v) {
                       $arrNew[$k] = $v;
                   }
               }
               $arrValues = $arrNew;
               unset($arrNew);
           }
       }
       // Convert the binary UUIDs
       $strSet = implode(',', array_map('StringUtil::binToUuid', $arrSet));
       $strOrder = $blnHasOrder ? implode(',', array_map('StringUtil::binToUuid', $this->{$this->orderField})) : '';
       $return = '<input type="hidden" name="' . $this->strName . '" id="ctrl_' . $this->strId . '" value="' . $strSet . '">' . ($blnHasOrder ? '
 <input type="hidden" name="' . $this->strOrderName . '" id="ctrl_' . $this->strOrderId . '" value="' . $strOrder . '">' : '') . '
 <div class="selector_container">' . ($blnHasOrder && count($arrValues) > 1 ? '
   <p class="sort_hint">' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>' : '') . '
   <ul id="sort_' . $this->strId . '" class="' . trim(($blnHasOrder ? 'sortable ' : '') . ($this->isGallery ? 'sgallery' : '')) . '">';
       foreach ($arrValues as $k => $v) {
           $return .= '<li data-id="' . \StringUtil::binToUuid($k) . '">' . $v . '</li>';
       }
       $return .= '</ul>
   <p><a href="contao/file.php?do=' . \Input::get('do') . '&amp;table=' . $this->strTable . '&amp;field=' . $this->strField . '&amp;act=show&amp;id=' . $this->activeRecord->id . '&amp;value=' . implode(',', array_keys($arrSet)) . '&amp;rt=' . REQUEST_TOKEN . '" class="tl_submit" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . \StringUtil::specialchars(str_replace("'", "\\'", $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][0])) . '\',\'url\':this.href,\'id\':\'' . $this->strId . '\'});return false">' . $GLOBALS['TL_LANG']['MSC']['changeSelection'] . '</a></p>' . ($blnHasOrder ? '
   <script>Backend.makeMultiSrcSortable("sort_' . $this->strId . '", "ctrl_' . $this->strOrderId . '", "ctrl_' . $this->strId . '")</script>' : '') . '
 </div>';
       if (!\Environment::get('isAjaxRequest')) {
           $return = '<div>' . $return . '</div>';
       }
       return $return;
   }
Beispiel #19
0
 /**
  * Generate the widget and return it as string
  *
  * @return string The widget markup
  */
 public function generate()
 {
     return sprintf('<input type="hidden" name="%s" value="%s"%s', $this->strName, \StringUtil::specialchars($this->varValue), $this->strTagEnding);
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $images = array();
     $objFiles = $this->objFiles;
     // Get all images
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path);
             if (!$objFile->isImage) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
             }
             // Add the image
             $images[$objFiles->path] = array('id' => $objFiles->id, 'name' => $objFile->basename, 'singleSRC' => $objFiles->path, 'title' => \StringUtil::specialchars($arrMeta['title']), 'alt' => \StringUtil::specialchars($arrMeta['alt']), 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path);
                 if (!$objFile->isImage) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
                 }
                 // Add the image
                 $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'name' => $objFile->basename, 'singleSRC' => $objSubfiles->path, 'title' => \StringUtil::specialchars($arrMeta['title']), 'alt' => \StringUtil::specialchars($arrMeta['alt']), 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
             }
         }
     }
     $images = array_values($images);
     if (empty($images)) {
         return;
     }
     $i = mt_rand(0, count($images) - 1);
     $arrImage = $images[$i];
     $arrImage['size'] = $this->imgSize;
     $arrImage['fullsize'] = $this->fullsize;
     if (!$this->useCaption) {
         $arrImage['caption'] = null;
     } elseif ($arrImage['caption'] == '') {
         $arrImage['caption'] = $arrImage['title'];
     }
     $this->addImageToTemplate($this->Template, $arrImage);
 }
Beispiel #21
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $id = 'article-' . $this->id;
     // Generate the CSS ID if it is not set
     if (empty($this->cssID[0])) {
         $this->cssID = array($id, $this->cssID[1]);
     }
     $this->Template->column = $this->inColumn;
     $this->Template->noMarkup = $this->blnNoMarkup;
     // Add the modification date
     $this->Template->timestamp = $this->tstamp;
     $this->Template->date = \Date::parse($objPage->datimFormat, $this->tstamp);
     // Clean the RTE output
     $this->teaser = \StringUtil::toHtml5($this->teaser);
     // Show the teaser only
     if ($this->multiMode && $this->showTeaser) {
         $this->cssID = array($id, '');
         $arrCss = \StringUtil::deserialize($this->teaserCssID);
         // Override the CSS ID and class
         if (is_array($arrCss) && count($arrCss) == 2) {
             if ($arrCss[0] == '') {
                 $arrCss[0] = $id;
             }
             $this->cssID = $arrCss;
         }
         $article = $this->alias ?: $this->id;
         $href = '/articles/' . ($this->inColumn != 'main' ? $this->inColumn . ':' : '') . $article;
         $this->Template->teaserOnly = true;
         $this->Template->headline = $this->headline;
         $this->Template->href = $objPage->getFrontendUrl($href);
         $this->Template->teaser = $this->teaser;
         $this->Template->readMore = \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $this->headline), true);
         $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more'];
         return;
     }
     // Get section and article alias
     list($strSection, $strArticle) = explode(':', \Input::get('articles'));
     if ($strArticle === null) {
         $strArticle = $strSection;
     }
     // Overwrite the page title (see #2853 and #4955)
     if (!$this->blnNoMarkup && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title != '') {
         $objPage->pageTitle = strip_tags(\StringUtil::stripInsertTags($this->title));
         if ($this->teaser != '') {
             $objPage->description = $this->prepareMetaDescription($this->teaser);
         }
     }
     $this->Template->printable = false;
     $this->Template->backlink = false;
     // Back link
     if (!$this->multiMode && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias)) {
         $this->Template->backlink = 'javascript:history.go(-1)';
         // see #6955
         $this->Template->back = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goBack']);
     }
     $arrElements = array();
     $objCte = \ContentModel::findPublishedByPidAndTable($this->id, 'tl_article');
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             /** @var ContentModel $objRow */
             $objRow = $objCte->current();
             // Add the "first" and "last" classes (see #2583)
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
             ++$intCount;
         }
     }
     $this->Template->teaser = $this->teaser;
     $this->Template->elements = $arrElements;
     if ($this->keywords != '') {
         $GLOBALS['TL_KEYWORDS'] .= ($GLOBALS['TL_KEYWORDS'] != '' ? ', ' : '') . $this->keywords;
     }
     // Deprecated since Contao 4.0, to be removed in Contao 5.0
     if ($this->printable == 1) {
         @trigger_error('Setting tl_article.printable to "1" has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
         $this->Template->printable = true;
         $this->Template->pdfButton = true;
     } elseif ($this->printable != '') {
         $options = \StringUtil::deserialize($this->printable);
         if (!empty($options) && is_array($options)) {
             $this->Template->printable = true;
             $this->Template->printButton = in_array('print', $options);
             $this->Template->pdfButton = in_array('pdf', $options);
             $this->Template->facebookButton = in_array('facebook', $options);
             $this->Template->twitterButton = in_array('twitter', $options);
             $this->Template->gplusButton = in_array('gplus', $options);
         }
     }
     // Add syndication variables
     if ($this->Template->printable) {
         $request = \Environment::get('indexFreeRequest');
         // URL encoding will be handled by the Symfony router, so do not apply rawurlencode() here anymore
         $this->Template->print = '#';
         $this->Template->encUrl = \Environment::get('base') . \Environment::get('request');
         $this->Template->encTitle = $objPage->pageTitle;
         $this->Template->href = $request . (strpos($request, '?') !== false ? '&amp;' : '?') . 'pdf=' . $this->id;
         $this->Template->printTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['printPage']);
         $this->Template->pdfTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['printAsPdf']);
         $this->Template->facebookTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['facebookShare']);
         $this->Template->twitterTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['twitterShare']);
         $this->Template->gplusTitle = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['gplusShare']);
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['compileArticle']) && is_array($GLOBALS['TL_HOOKS']['compileArticle'])) {
         foreach ($GLOBALS['TL_HOOKS']['compileArticle'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback[0]}->{$callback[1]}($this->Template, $this->arrData, $this);
         }
     }
 }
Beispiel #22
0
 /**
  * Generate a checkbox and return it as string
  *
  * @param array   $arrOption
  * @param integer $i
  * @param string  $strButtons
  *
  * @return string
  */
 protected function generateCheckbox($arrOption, $i, $strButtons)
 {
     return sprintf('<span><input type="checkbox" name="%s" id="opt_%s" class="tl_checkbox" value="%s"%s%s onfocus="Backend.getScrollOffset()"> %s<label for="opt_%s">%s</label></span>', $this->strName . ($this->multiple ? '[]' : ''), $this->strId . '_' . $i, $this->multiple ? \StringUtil::specialchars($arrOption['value']) : 1, is_array($this->varValue) && in_array($arrOption['value'], $this->varValue) || $this->varValue == $arrOption['value'] ? ' checked="checked"' : '', $this->getAttributes(), $strButtons, $this->strId . '_' . $i, $arrOption['label']);
 }
Beispiel #23
0
 /**
  * Generate the widget and return it as string
  *
  * @return string
  */
 public function generate()
 {
     if (!is_array($this->varValue)) {
         $this->varValue = array($this->varValue);
     }
     $arrFields = array();
     $arrOptions = array();
     foreach ($this->arrOptions as $strKey => $arrOption) {
         if (isset($arrOption['value'])) {
             $arrOptions[] = sprintf('<option value="%s"%s>%s</option>', \StringUtil::specialchars($arrOption['value']), $this->isSelected($arrOption), $arrOption['label']);
         } else {
             $arrOptgroups = array();
             foreach ($arrOption as $arrOptgroup) {
                 $arrOptgroups[] = sprintf('<option value="%s"%s>%s</option>', \StringUtil::specialchars($arrOptgroup['value']), $this->isSelected($arrOptgroup), $arrOptgroup['label']);
             }
             $arrOptions[] = sprintf('<optgroup label="&nbsp;%s">%s</optgroup>', \StringUtil::specialchars($strKey), implode('', $arrOptgroups));
         }
     }
     $arrFields[] = sprintf('<select name="%s[2]" id="ctrl_%s" class="tl_select_interval" onfocus="Backend.getScrollOffset()"%s>%s</select>', $this->strName, $this->strId . '_3', $this->getAttribute('disabled'), implode(' ', $arrOptions));
     for ($i = 0; $i < 2; $i++) {
         $arrFields[] = sprintf('<input type="text" name="%s[%s]" id="ctrl_%s" class="tl_text_4 tl_imageSize_%s" value="%s"%s onfocus="Backend.getScrollOffset()">', $this->strName, $i, $this->strId . '_' . $i, $i, \StringUtil::specialchars(@$this->varValue[$i]), $this->getAttributes());
     }
     return sprintf('<div id="ctrl_%s" class="tl_image_size%s">%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', implode(' ', $arrFields), $this->wizard);
 }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $files = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     $allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
     // Get all files
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path);
             if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta)) {
                 if ($this->metaIgnore) {
                     continue;
                 } elseif ($objPage->rootFallbackLanguage !== null) {
                     $arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
                 }
             }
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
             }
             $strHref = \Environment::get('request');
             // Remove an existing file parameter (see #5683)
             if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                 $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
             }
             $strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objFiles->path);
             // Add the image
             $files[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
             $auxDate[] = $objFile->mtime;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path);
                 if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 if (empty($arrMeta)) {
                     if ($this->metaIgnore) {
                         continue;
                     } elseif ($objPage->rootFallbackLanguage !== null) {
                         $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->rootFallbackLanguage);
                     }
                 }
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
                 }
                 $strHref = \Environment::get('request');
                 // Remove an existing file parameter (see #5683)
                 if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                     $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
                 }
                 $strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objSubfiles->path);
                 // Add the image
                 $files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
                 $auxDate[] = $objFile->mtime;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         default:
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
             // Deprecated since Contao 4.0, to be removed in Contao 5.0
         // Deprecated since Contao 4.0, to be removed in Contao 5.0
         case 'meta':
             @trigger_error('The "meta" key in ContentDownloads::compile() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
             // no break;
         // no break;
         case 'custom':
             if ($this->orderSRC != '') {
                 $tmp = \StringUtil::deserialize($this->orderSRC);
                 if (!empty($tmp) && is_array($tmp)) {
                     // Remove all values
                     $arrOrder = array_map(function () {
                     }, array_flip($tmp));
                     // Move the matching elements to their position in $arrOrder
                     foreach ($files as $k => $v) {
                         if (array_key_exists($v['uuid'], $arrOrder)) {
                             $arrOrder[$v['uuid']] = $v;
                             unset($files[$k]);
                         }
                     }
                     // Append the left-over files at the end
                     if (!empty($files)) {
                         $arrOrder = array_merge($arrOrder, array_values($files));
                     }
                     // Remove empty (unreplaced) entries
                     $files = array_values(array_filter($arrOrder));
                     unset($arrOrder);
                 }
             }
             break;
         case 'random':
             shuffle($files);
             break;
     }
     $this->Template->files = array_values($files);
 }
Beispiel #25
0
 /**
  * Return the "toggle visibility" button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
 {
     if (strlen(Input::get('tid'))) {
         $this->toggleVisibility(Input::get('tid'), Input::get('state') == 1, @func_get_arg(12) ?: null);
         $this->redirect($this->getReferer());
     }
     $href .= '&amp;tid=' . $row['id'] . '&amp;state=' . $row['invisible'];
     if ($row['invisible']) {
         $icon = 'invisible.svg';
     }
     return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['invisible'] ? 0 : 1) . '"') . '</a> ';
 }
    /**
     * Return a form to choose a CSV file and import it
     *
     * @param DataContainer $dc
     *
     * @return string
     */
    public function importTable(DataContainer $dc)
    {
        if (\Input::get('key') != 'table') {
            return '';
        }
        /** @var FileUpload $objUploader */
        $objUploader = new \FileUpload();
        // Import CSS
        if (\Input::post('FORM_SUBMIT') == 'tl_table_import') {
            $arrUploaded = $objUploader->uploadTo('system/tmp');
            if (empty($arrUploaded)) {
                \Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']);
                $this->reload();
            }
            $this->import('Database');
            $arrTable = array();
            foreach ($arrUploaded as $strCsvFile) {
                $objFile = new \File($strCsvFile);
                if ($objFile->extension != 'csv') {
                    \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
                    continue;
                }
                // Get separator
                switch (\Input::post('separator')) {
                    case 'semicolon':
                        $strSeparator = ';';
                        break;
                    case 'tabulator':
                        $strSeparator = "\t";
                        break;
                    default:
                        $strSeparator = ',';
                        break;
                }
                $resFile = $objFile->handle;
                while (($arrRow = @fgetcsv($resFile, null, $strSeparator)) !== false) {
                    $arrTable[] = $arrRow;
                }
            }
            $objVersions = new \Versions($dc->table, \Input::get('id'));
            $objVersions->create();
            $this->Database->prepare("UPDATE " . $dc->table . " SET tableitems=? WHERE id=?")->execute(serialize($arrTable), \Input::get('id'));
            \System::setCookie('BE_PAGE_OFFSET', 0, 0);
            $this->redirect(str_replace('&key=table', '', \Environment::get('request')));
        }
        // Return form
        return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=table', '', \Environment::get('request'))) . '" class="header_back" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_table_import" class="tl_form" method="post" enctype="multipart/form-data">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_table_import">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">

<fieldset class="tl_tbox nolegend">
<div>
  <h3><label for="separator">' . $GLOBALS['TL_LANG']['MSC']['separator'][0] . '</label></h3>
  <select name="separator" id="separator" class="tl_select" onfocus="Backend.getScrollOffset()">
    <option value="comma">' . $GLOBALS['TL_LANG']['MSC']['comma'] . '</option>
    <option value="semicolon">' . $GLOBALS['TL_LANG']['MSC']['semicolon'] . '</option>
    <option value="tabulator">' . $GLOBALS['TL_LANG']['MSC']['tabulator'] . '</option>
  </select>' . ($GLOBALS['TL_LANG']['MSC']['separator'][1] != '' ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['separator'][1] . '</p>' : '') . '
  <h3>' . $GLOBALS['TL_LANG']['MSC']['source'][0] . '</h3>' . $objUploader->generateMarkup() . (isset($GLOBALS['TL_LANG']['MSC']['source'][1]) ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['source'][1] . '</p>' : '') . '
</div>
</fieldset>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  <button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['tw_import'][0] . '</button>
</div>

</div>
</form>';
    }
Beispiel #27
0
 /**
  * Recursively compile the navigation menu and return it as HTML string
  *
  * @param integer $pid
  * @param integer $level
  * @param string  $host
  * @param string  $language
  *
  * @return string
  */
 protected function renderNavigation($pid, $level = 1, $host = null, $language = null)
 {
     // Get all active subpages
     $objSubpages = \PageModel::findPublishedSubpagesWithoutGuestsByPid($pid, $this->showHidden, $this instanceof ModuleSitemap);
     if ($objSubpages === null) {
         return '';
     }
     $items = array();
     $groups = array();
     // Get all groups of the current front end user
     if (FE_USER_LOGGED_IN) {
         $this->import('FrontendUser', 'User');
         $groups = $this->User->groups;
     }
     // Layout template fallback
     if ($this->navigationTpl == '') {
         $this->navigationTpl = 'nav_default';
     }
     /** @var FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->navigationTpl);
     $objTemplate->pid = $pid;
     $objTemplate->type = get_class($this);
     $objTemplate->cssID = $this->cssID;
     // see #4897
     $objTemplate->level = 'level_' . $level++;
     /** @var PageModel $objPage */
     global $objPage;
     // Browse subpages
     foreach ($objSubpages as $objSubpage) {
         // Skip hidden sitemap pages
         if ($this instanceof ModuleSitemap && $objSubpages->sitemap == 'map_never') {
             continue;
         }
         $subitems = '';
         $_groups = \StringUtil::deserialize($objSubpage->groups);
         // Override the domain (see #3765)
         if ($host !== null) {
             $objSubpage->domain = $host;
         }
         // Do not show protected pages unless a front end user is logged in
         if (!$objSubpage->protected || is_array($_groups) && count(array_intersect($_groups, $groups)) || $this->showProtected || $this instanceof ModuleSitemap && $objSubpage->sitemap == 'map_always') {
             // Check whether there will be subpages
             if ($objSubpage->subpages > 0 && (!$this->showLevel || $this->showLevel >= $level || !$this->hardLimit && ($objPage->id == $objSubpage->id || in_array($objPage->id, $this->Database->getChildRecords($objSubpage->id, 'tl_page'))))) {
                 $subitems = $this->renderNavigation($objSubpage->id, $level, $host, $language);
             }
             $href = null;
             // Get href
             switch ($objSubpage->type) {
                 case 'redirect':
                     $href = $objSubpage->url;
                     if (strncasecmp($href, 'mailto:', 7) === 0) {
                         $href = \StringUtil::encodeEmail($href);
                     }
                     break;
                 case 'forward':
                     if ($objSubpage->jumpTo) {
                         /** @var PageModel $objNext */
                         $objNext = $objSubpage->getRelated('jumpTo');
                     } else {
                         $objNext = \PageModel::findFirstPublishedRegularByPid($objSubpage->id);
                     }
                     // Hide the link if the target page is invisible
                     if (!$objNext instanceof PageModel || !$objNext->published || $objNext->start != '' && $objNext->start > time() || $objNext->stop != '' && $objNext->stop < time()) {
                         continue 2;
                     }
                     $href = $objNext->getFrontendUrl();
                     break;
                 default:
                     $href = $objSubpage->getFrontendUrl();
                     break;
             }
             $row = $objSubpage->row();
             $trail = in_array($objSubpage->id, $objPage->trail);
             // Active page
             if (($objPage->id == $objSubpage->id || $objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo) && !$this instanceof ModuleSitemap && $href == \Environment::get('request')) {
                 // Mark active forward pages (see #4822)
                 $strClass = ($objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo ? 'forward' . ($trail ? ' trail' : '') : 'active') . ($subitems != '' ? ' submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($objSubpage->cssClass != '' ? ' ' . $objSubpage->cssClass : '');
                 $row['isActive'] = true;
                 $row['isTrail'] = false;
             } else {
                 $strClass = ($subitems != '' ? 'submenu' : '') . ($objSubpage->protected ? ' protected' : '') . ($trail ? ' trail' : '') . ($objSubpage->cssClass != '' ? ' ' . $objSubpage->cssClass : '');
                 // Mark pages on the same level (see #2419)
                 if ($objSubpage->pid == $objPage->pid) {
                     $strClass .= ' sibling';
                 }
                 $row['isActive'] = false;
                 $row['isTrail'] = $trail;
             }
             $row['subitems'] = $subitems;
             $row['class'] = trim($strClass);
             $row['title'] = \StringUtil::specialchars($objSubpage->title, true);
             $row['pageTitle'] = \StringUtil::specialchars($objSubpage->pageTitle, true);
             $row['link'] = $objSubpage->title;
             $row['href'] = $href;
             $row['nofollow'] = strncmp($objSubpage->robots, 'noindex,nofollow', 16) === 0;
             $row['target'] = '';
             $row['description'] = str_replace(array("\n", "\r"), array(' ', ''), $objSubpage->description);
             // Override the link target
             if ($objSubpage->type == 'redirect' && $objSubpage->target) {
                 $row['target'] = ' target="_blank"';
             }
             $items[] = $row;
         }
     }
     // Add classes first and last
     if (!empty($items)) {
         $last = count($items) - 1;
         $items[0]['class'] = trim($items[0]['class'] . ' first');
         $items[$last]['class'] = trim($items[$last]['class'] . ' last');
     }
     $objTemplate->items = $items;
     return !empty($items) ? $objTemplate->parse() : '';
 }
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $count = 0;
       $languages = $this->getLanguages();
       $return = '';
       $taken = array();
       $this->import('Database');
       // Only show the root page languages (see #7112, #7667)
       $objRootLangs = $this->Database->query("SELECT REPLACE(language, '-', '_') AS language FROM tl_page WHERE type='root'");
       $languages = array_intersect_key($languages, array_flip($objRootLangs->fetchEach('language')));
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || empty($this->varValue)) {
           if (count($languages) > 0) {
               $this->varValue = array(key($languages) => array());
               // see #4188
           } else {
               return '<p class="tl_info">' . $GLOBALS['TL_LANG']['MSC']['metaNoLanguages'] . '</p>';
           }
       }
       // Add the existing entries
       if (!empty($this->varValue)) {
           $return = '<ul id="ctrl_' . $this->strId . '" class="tl_metawizard">';
           // Add the input fields
           foreach ($this->varValue as $lang => $meta) {
               $return .= '
   <li class="' . ($count % 2 == 0 ? 'even' : 'odd') . '" data-language="' . $lang . '">';
               $return .= '<span class="lang">' . (isset($languages[$lang]) ? $languages[$lang] : $lang) . ' ' . \Image::getHtml('delete.svg', '', 'class="tl_metawizard_img" onclick="Backend.metaDelete(this)"') . '</span>';
               // Take the fields from the DCA (see #4327)
               foreach ($this->metaFields as $field => $attributes) {
                   $return .= '<label for="ctrl_' . $field . '_' . $count . '">' . $GLOBALS['TL_LANG']['MSC']['aw_' . $field] . '</label> <input type="text" name="' . $this->strId . '[' . $lang . '][' . $field . ']" id="ctrl_' . $field . '_' . $count . '" class="tl_text" value="' . \StringUtil::specialchars($meta[$field]) . '"' . (!empty($attributes) ? ' ' . $attributes : '') . '><br>';
               }
               $return .= '
   </li>';
               $taken[] = $lang;
               ++$count;
           }
           $return .= '
 </ul>';
       }
       $options = array('<option value="">-</option>');
       // Add the remaining languages
       foreach ($languages as $k => $v) {
           $options[] = '<option value="' . $k . '"' . (in_array($k, $taken) ? ' disabled' : '') . '>' . $v . '</option>';
       }
       $return .= '
 <div class="tl_metawizard_new">
   <select name="' . $this->strId . '[language]" class="tl_select tl_chosen" onchange="Backend.toggleAddLanguageButton(this)">' . implode('', $options) . '</select> <input type="button" class="tl_submit" disabled value="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['aw_new']) . '" onclick="Backend.metaWizard(this,\'ctrl_' . $this->strId . '\')">
 </div>';
       return $return;
   }
 /**
  * Generate the options
  *
  * @return array The options array
  */
 protected function getOptions()
 {
     $arrOptions = array();
     $blnHasGroups = false;
     foreach ($this->arrOptions as $i => $arrOption) {
         if ($arrOption['group']) {
             if ($blnHasGroups) {
                 $arrOptions[] = array('type' => 'group_end');
             }
             $arrOptions[] = array('type' => 'group_start', 'label' => \StringUtil::specialchars($arrOption['label']));
             $blnHasGroups = true;
         } else {
             $arrOptions[] = array('type' => 'option', 'name' => $this->strName . (count($this->arrOptions) > 1 ? '[]' : ''), 'id' => $this->strId . '_' . $i, 'value' => $arrOption['value'], 'checked' => $this->isChecked($arrOption), 'attributes' => $this->getAttributes(), 'label' => $arrOption['label']);
         }
     }
     if ($blnHasGroups) {
         $arrOptions[] = array('type' => 'group_end');
     }
     return $arrOptions;
 }
Beispiel #30
0
 /**
  * Return the delete form button
  *
  * @param array  $row
  * @param string $href
  * @param string $label
  * @param string $title
  * @param string $icon
  * @param string $attributes
  *
  * @return string
  */
 public function deleteForm($row, $href, $label, $title, $icon, $attributes)
 {
     return $this->User->hasAccess('delete', 'formp') ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $row['id']) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ' : Image::getHtml(preg_replace('/\\.svg$/i', '_.svg', $icon)) . ' ';
 }