Ejemplo n.º 1
0
 /**
  * Add specific attributes
  *
  * @param string $strKey   The attribute name
  * @param mixed  $varValue The attribute value
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'mandatory':
             if ($varValue) {
                 $this->arrAttributes['required'] = 'required';
             } else {
                 unset($this->arrAttributes['required']);
             }
             parent::__set($strKey, $varValue);
             break;
         case 'mSize':
             if ($this->multiple) {
                 $this->arrAttributes['size'] = $varValue;
             }
             break;
         case 'multiple':
             if ($varValue != '') {
                 $this->arrAttributes['multiple'] = 'multiple';
             }
             break;
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         case 'rgxp':
         case 'minlength':
         case 'maxlength':
             // Ignore
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * Parse the template
  *
  * @return string
  */
 public function generate()
 {
     $objElement = \ContentModel::findByPk($this->cteAlias);
     if ($objElement === null) {
         return '';
     }
     $strClass = static::findClass($objElement->type);
     if (!class_exists($strClass)) {
         return '';
     }
     $objElement->origId = $objElement->id;
     $objElement->id = $this->id;
     $objElement->typePrefix = 'ce_';
     /** @var ContentElement $objElement */
     $objElement = new $strClass($objElement);
     $cssID = \StringUtil::deserialize($objElement->cssID, true);
     // Override the CSS ID (see #305)
     if (!empty($this->cssID[0])) {
         $cssID[0] = $this->cssID[0];
     }
     // Merge the CSS classes (see #6011)
     if (!empty($this->cssID[1])) {
         $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]);
     }
     $objElement->cssID = $cssID;
     return $objElement->generate();
 }
Ejemplo n.º 3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->src = $this->singleSRC;
     $this->Template->href = $this->source == 'external' ? $this->url : $this->singleSRC;
     $this->Template->alt = $this->altContent;
     $this->Template->var = 'swf' . $this->id;
     $this->Template->transparent = $this->transparent ? true : false;
     $this->Template->interactive = $this->interactive ? true : false;
     $this->Template->flashId = $this->flashID ?: 'swf_' . $this->id;
     $this->Template->fsCommand = '  ' . preg_replace('/[\\n\\r]/', "\n  ", \StringUtil::decodeEntities($this->flashJS));
     $this->Template->flashvars = 'URL=' . \Environment::get('base');
     $this->Template->version = $this->version ?: '6.0.0';
     $size = \StringUtil::deserialize($this->size);
     $this->Template->width = $size[0];
     $this->Template->height = $size[1];
     $intMaxWidth = TL_MODE == 'BE' ? 320 : \Config::get('maxImageWidth');
     // Adjust movie size
     if ($intMaxWidth > 0 && $size[0] > $intMaxWidth) {
         $this->Template->width = $intMaxWidth;
         $this->Template->height = floor($intMaxWidth * $size[1] / $size[0]);
     }
     if (strlen($this->flashvars)) {
         $this->Template->flashvars .= '&' . \StringUtil::decodeEntities($this->flashvars);
     }
 }
Ejemplo n.º 4
0
 /**
  * Add specific attributes
  *
  * @param string $strKey
  * @param mixed  $varValue
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'maxlength':
             if ($varValue > 0) {
                 $this->arrAttributes['maxlength'] = $varValue;
             }
             break;
         case 'mandatory':
             if ($varValue) {
                 $this->arrAttributes['required'] = 'required';
             } else {
                 unset($this->arrAttributes['required']);
             }
             parent::__set($strKey, $varValue);
             break;
         case 'placeholder':
             $this->arrAttributes['placeholder'] = $varValue;
             break;
         case 'options':
             $this->arrUnits = \StringUtil::deserialize($varValue);
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns the image sizes for the given user suitable for widgets.
  *
  * @param BackendUser $user
  *
  * @return array
  */
 public function getOptionsForUser(BackendUser $user)
 {
     $this->loadOptions();
     $event = new ImageSizesEvent($user->isAdmin ? $this->options : $this->filterOptions(\StringUtil::deserialize($user->imageSizes, true)), $user);
     $this->eventDispatcher->dispatch(ContaoCoreEvents::IMAGE_SIZES_USER, $event);
     return $event->getImageSizes();
 }
Ejemplo n.º 6
0
 /**
  * Parse the template
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'FE' && !BE_USER_LOGGED_IN && ($this->invisible || $this->start != '' && $this->start > time() || $this->stop != '' && $this->stop < time())) {
         return '';
     }
     $objModule = \ModuleModel::findByPk($this->module);
     if ($objModule === null) {
         return '';
     }
     $strClass = \Module::findClass($objModule->type);
     if (!class_exists($strClass)) {
         return '';
     }
     $objModule->typePrefix = 'ce_';
     /** @var Module $objModule */
     $objModule = new $strClass($objModule, $this->strColumn);
     $cssID = \StringUtil::deserialize($objModule->cssID, true);
     // Override the CSS ID (see #305)
     if (!empty($this->cssID[0])) {
         $cssID[0] = $this->cssID[0];
     }
     // Merge the CSS classes (see #6011)
     if (!empty($this->cssID[1])) {
         $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]);
     }
     $objModule->cssID = $cssID;
     return $objModule->generate();
 }
Ejemplo n.º 7
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) : '&nbsp;');
         }
         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;
 }
Ejemplo n.º 8
0
 /**
  * Add specific attributes
  *
  * @param string $strKey
  * @param mixed  $varValue
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 9
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $arrItems = array();
     $items = \StringUtil::deserialize($this->listitems);
     $limit = count($items) - 1;
     for ($i = 0, $c = count($items); $i < $c; $i++) {
         $arrItems[] = array('class' => $i == 0 ? 'first' : ($i == $limit ? 'last' : ''), 'content' => $items[$i]);
     }
     $this->Template->items = $arrItems;
     $this->Template->tag = $this->listtype == 'ordered' ? 'ol' : 'ul';
 }
Ejemplo n.º 10
0
 /**
  * Check the source folder
  *
  * @return string
  */
 public function generate()
 {
     $this->multiSRC = \StringUtil::deserialize($this->multiSRC);
     if (!is_array($this->multiSRC) || empty($this->multiSRC)) {
         return '';
     }
     $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
     if ($this->objFiles === null) {
         return '';
     }
     return parent::generate();
 }
Ejemplo n.º 11
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $size = \StringUtil::deserialize($this->playerSize);
     if (!is_array($size) || empty($size[0]) || empty($size[1])) {
         $this->Template->size = ' width="640" height="360"';
     } else {
         $this->Template->size = ' width="' . $size[0] . '" height="' . $size[1] . '"';
     }
     $url = 'https://www.youtube.com/embed/' . $this->youtube;
     if ($this->autoplay) {
         $url .= '?autoplay=1';
     }
     $this->Template->src = $url;
 }
Ejemplo n.º 12
0
 /**
  * Load the database object
  *
  * @param array $arrAttributes
  */
 public function __construct($arrAttributes = null)
 {
     $this->import('Database');
     parent::__construct($arrAttributes);
     // Prepare the order field
     if ($this->orderField != '') {
         $this->strOrderId = $this->orderField . str_replace($this->strField, '', $this->strId);
         $this->strOrderName = $this->orderField . str_replace($this->strField, '', $this->strName);
         // Retrieve the order value
         $objRow = $this->Database->prepare("SELECT {$this->orderField} FROM {$this->strTable} WHERE id=?")->limit(1)->execute($this->activeRecord->id);
         $tmp = \StringUtil::deserialize($objRow->{$this->orderField});
         $this->{$this->orderField} = !empty($tmp) && is_array($tmp) ? array_filter($tmp) : array();
     }
 }
Ejemplo n.º 13
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     if (TL_MODE == 'BE') {
         $this->strTemplate = 'be_wildcard';
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate($this->strTemplate);
         $this->Template = $objTemplate;
         $this->Template->title = $this->mooHeadline;
     }
     $classes = \StringUtil::deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Ejemplo n.º 14
0
 /**
  * Add specific attributes
  *
  * @param string $strKey
  * @param mixed  $varValue
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'maxlength':
             if ($varValue > 0) {
                 $this->arrAttributes['maxlength'] = $varValue;
             }
             break;
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 15
0
 /**
  * Add specific attributes
  *
  * @param string $strKey   The attribute name
  * @param mixed  $varValue The attribute value
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         case 'rgxp':
         case 'minlength':
         case 'maxlength':
             // Ignore
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $statement = $this->connection->query("SELECT id, framework FROM tl_layout WHERE framework!=''");
     while (false !== ($layout = $statement->fetch(\PDO::FETCH_OBJ))) {
         $framework = '';
         $tmp = \StringUtil::deserialize($layout->framework);
         if (!empty($tmp) && is_array($tmp)) {
             if (false !== ($key = array_search('layout.css', $tmp))) {
                 array_insert($tmp, $key + 1, 'responsive.css');
             }
             $framework = serialize(array_values(array_unique($tmp)));
         }
         $stmt = $this->connection->prepare('UPDATE tl_layout SET framework=:framework WHERE id=:id');
         $stmt->execute([':framework' => $framework, ':id' => $layout->id]);
     }
     // Add the "viewport" field (triggers the version 3.3 update)
     $this->connection->query("ALTER TABLE `tl_layout` ADD `viewport` varchar(255) NOT NULL default ''");
 }
Ejemplo n.º 17
0
 /**
  * Add specific attributes
  *
  * @param string $strKey
  * @param mixed  $varValue
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'mandatory':
             if ($varValue) {
                 $this->arrAttributes['required'] = 'required';
             } else {
                 unset($this->arrAttributes['required']);
             }
             parent::__set($strKey, $varValue);
             break;
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Ejemplo n.º 18
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     // Clean the RTE output
     $this->text = \StringUtil::toHtml5($this->text);
     $this->Template->text = \StringUtil::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
     $classes = \StringUtil::deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Ejemplo n.º 19
0
 /**
  * List a style sheet
  *
  * @param array $row
  *
  * @return string
  */
 public function listStyleSheet($row)
 {
     $cc = '';
     $media = StringUtil::deserialize($row['media']);
     if ($row['cc'] != '') {
         $cc = ' &lt;!--[' . $row['cc'] . ']&gt;';
     }
     if ($row['mediaQuery'] != '') {
         return '<div class="tl_content_left">' . $row['name'] . ' <span style="color:#999;padding-left:3px">@media ' . $row['mediaQuery'] . $cc . '</span>' . "</div>\n";
     } elseif (!empty($media) && is_array($media)) {
         return '<div class="tl_content_left">' . $row['name'] . ' <span style="color:#999;padding-left:3px">@media ' . implode(', ', $media) . $cc . '</span>' . "</div>\n";
     } else {
         return '<div class="tl_content_left">' . $row['name'] . $cc . "</div>\n";
     }
 }
Ejemplo n.º 20
0
 /**
  * Set all user properties from a database record
  */
 protected function setUserFromDb()
 {
     $this->intId = $this->id;
     // Unserialize values
     foreach ($this->arrData as $k => $v) {
         if (!is_numeric($v)) {
             $this->{$k} = \StringUtil::deserialize($v);
         }
     }
     // Set language
     if ($this->language != '') {
         \System::getContainer()->get('request_stack')->getCurrentRequest()->setLocale($this->language);
         \System::getContainer()->get('translator')->setLocale($this->language);
         // Deprecated since Contao 4.0, to be removed in Contao 5.0
         $GLOBALS['TL_LANGUAGE'] = str_replace('_', '-', $this->language);
     }
     $GLOBALS['TL_USERNAME'] = $this->username;
     // Make sure that groups is an array
     if (!is_array($this->groups)) {
         $this->groups = $this->groups != '' ? array($this->groups) : array();
     }
     // Skip inactive groups
     if (($objGroups = \MemberGroupModel::findAllActive()) !== null) {
         $this->groups = array_intersect($this->groups, $objGroups->fetchEach('id'));
     }
     // Get the group login page
     if ($this->groups[0] > 0) {
         $objGroup = \MemberGroupModel::findPublishedById($this->groups[0]);
         if ($objGroup !== null && $objGroup->redirect && $objGroup->jumpTo) {
             $this->strLoginPage = $objGroup->jumpTo;
         }
     }
 }
Ejemplo n.º 21
0
 /**
  * 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);
 }
Ejemplo n.º 22
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);
 }
Ejemplo n.º 23
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() : '';
 }
Ejemplo n.º 24
0
 /**
  * Adjust start end end time of the event based on date, span, startTime and endTime
  *
  * @param DataContainer $dc
  */
 public function adjustTime(DataContainer $dc)
 {
     // Return if there is no active record (override all)
     if (!$dc->activeRecord) {
         return;
     }
     $arrSet['startTime'] = $dc->activeRecord->startDate;
     $arrSet['endTime'] = $dc->activeRecord->startDate;
     // Set end date
     if (strlen($dc->activeRecord->endDate)) {
         if ($dc->activeRecord->endDate > $dc->activeRecord->startDate) {
             $arrSet['endDate'] = $dc->activeRecord->endDate;
             $arrSet['endTime'] = $dc->activeRecord->endDate;
         } else {
             $arrSet['endDate'] = $dc->activeRecord->startDate;
             $arrSet['endTime'] = $dc->activeRecord->startDate;
         }
     }
     // Add time
     if ($dc->activeRecord->addTime) {
         $arrSet['startTime'] = strtotime(date('Y-m-d', $arrSet['startTime']) . ' ' . date('H:i:s', $dc->activeRecord->startTime));
         $arrSet['endTime'] = strtotime(date('Y-m-d', $arrSet['endTime']) . ' ' . date('H:i:s', $dc->activeRecord->endTime));
     } elseif (strlen($dc->activeRecord->endDate) && $arrSet['endDate'] == $arrSet['endTime'] || $arrSet['startTime'] == $arrSet['endTime']) {
         $arrSet['endTime'] = strtotime('+ 1 day', $arrSet['endTime']) - 1;
     }
     $arrSet['repeatEnd'] = 0;
     // Recurring events
     if ($dc->activeRecord->recurring) {
         // Unlimited recurrences end on 2038-01-01 00:00:00 (see #4862)
         if ($dc->activeRecord->recurrences == 0) {
             $arrSet['repeatEnd'] = 2145913200;
         } else {
             $arrRange = StringUtil::deserialize($dc->activeRecord->repeatEach);
             if (is_array($arrRange) && isset($arrRange['unit']) && isset($arrRange['value'])) {
                 $arg = $arrRange['value'] * $dc->activeRecord->recurrences;
                 $unit = $arrRange['unit'];
                 $strtotime = '+ ' . $arg . ' ' . $unit;
                 $arrSet['repeatEnd'] = strtotime($strtotime, $arrSet['endTime']);
             }
         }
     }
     $this->Database->prepare("UPDATE tl_calendar_events %s WHERE id=?")->set($arrSet)->execute($dc->id);
 }
Ejemplo n.º 25
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);
         }
     }
 }
Ejemplo n.º 26
0
 /**
  * Return the meta fields of a news article as array
  *
  * @param NewsModel $objArticle
  *
  * @return array
  */
 protected function getMetaFields($objArticle)
 {
     $meta = \StringUtil::deserialize($this->news_metaFields);
     if (!is_array($meta)) {
         return array();
     }
     /** @var PageModel $objPage */
     global $objPage;
     $return = array();
     foreach ($meta as $field) {
         switch ($field) {
             case 'date':
                 $return['date'] = \Date::parse($objPage->datimFormat, $objArticle->date);
                 break;
             case 'author':
                 /** @var UserModel $objAuthor */
                 if (($objAuthor = $objArticle->getRelated('author')) instanceof UserModel) {
                     $return['author'] = $GLOBALS['TL_LANG']['MSC']['by'] . ' ' . $objAuthor->name;
                 }
                 break;
             case 'comments':
                 if ($objArticle->noComments || !in_array('comments', \ModuleLoader::getActive()) || $objArticle->source != 'default') {
                     break;
                 }
                 $intTotal = \CommentsModel::countPublishedBySourceAndParent('tl_news', $objArticle->id);
                 $return['ccount'] = $intTotal;
                 $return['comments'] = sprintf($GLOBALS['TL_LANG']['MSC']['commentCount'], $intTotal);
                 break;
         }
     }
     return $return;
 }
Ejemplo n.º 27
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>';
   }
Ejemplo n.º 28
0
 /**
  * Convert a multi source field to UUIDs
  *
  * @param string $table The table name
  * @param string $field The field name
  */
 public static function convertMultiField($table, $field)
 {
     $objDatabase = \Database::getInstance();
     // Get the non-empty rows
     $objRow = $objDatabase->query("SELECT id, {$field} FROM {$table} WHERE {$field}!=''");
     // Check the column type
     $objDesc = $objDatabase->query("DESC {$table} {$field}");
     // Change the column type
     if ($objDesc->Type != 'blob') {
         $objDatabase->query("ALTER TABLE `{$table}` CHANGE `{$field}` `{$field}` blob NULL");
         $objDatabase->query("UPDATE `{$table}` SET `{$field}`=NULL WHERE `{$field}`=''");
     }
     while ($objRow->next()) {
         $arrValues = \StringUtil::deserialize($objRow->{$field}, true);
         if (empty($arrValues)) {
             continue;
         }
         $objHelper = static::generateHelperObject($arrValues);
         // UUID already
         if ($objHelper->isUuid) {
             continue;
         }
         foreach ($arrValues as $k => $v) {
             // Numeric ID to UUID
             if ($objHelper->isNumeric) {
                 $objFile = \FilesModel::findByPk($objHelper->value[$k]);
                 $arrValues[$k] = $objFile->uuid;
             } else {
                 $objFile = \FilesModel::findByPath($objHelper->value[$k]);
                 $arrValues[$k] = $objFile->uuid;
             }
         }
         $objDatabase->prepare("UPDATE {$table} SET {$field}=? WHERE id=?")->execute(serialize($arrValues), $objRow->id);
     }
 }
Ejemplo n.º 29
0
 /**
  * Initialize the object
  *
  * @param ContentModel|ModuleModel|FormModel $objElement
  * @param string                             $strColumn
  */
 public function __construct($objElement, $strColumn = 'main')
 {
     parent::__construct();
     // Store the parent element (see #4556)
     if ($objElement instanceof Model || $objElement instanceof Model\Collection) {
         /** @var ContentModel|ModuleModel|FormModel $objModel */
         $objModel = $objElement;
         if ($objModel instanceof Model\Collection) {
             $objModel = $objModel->current();
         }
         $this->objParent = $objModel;
     }
     if ($this->strKey == '' || $this->strTable == '') {
         return;
     }
     /** @var Model $strModelClass */
     $strModelClass = \Model::getClassFromTable($this->strTable);
     // Load the model
     if (class_exists($strModelClass)) {
         $objHybrid = $strModelClass::findByPk($objElement->{$this->strKey});
         if ($objHybrid === null) {
             return;
         }
         $this->objModel = $objHybrid;
     } else {
         $objHybrid = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($objElement->{$this->strKey});
         if ($objHybrid->numRows < 1) {
             return;
         }
     }
     $cssID = array();
     $this->arrData = $objHybrid->row();
     // Get the CSS ID from the parent element (!)
     $this->cssID = \StringUtil::deserialize($objElement->cssID, true);
     if (isset($objHybrid->attributes)) {
         $cssID = \StringUtil::deserialize($objHybrid->attributes, true);
     }
     // Override the CSS ID (see #305)
     if (!empty($this->cssID[0])) {
         $cssID[0] = $this->cssID[0];
     }
     // Merge the CSS classes (see #6011)
     if (!empty($this->cssID[1])) {
         $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]);
     }
     $this->cssID = $cssID;
     $this->typePrefix = $objElement->typePrefix;
     $arrHeadline = \StringUtil::deserialize($objElement->headline);
     $this->headline = is_array($arrHeadline) ? $arrHeadline['value'] : $arrHeadline;
     $this->hl = is_array($arrHeadline) ? $arrHeadline['unit'] : 'h1';
     $this->strColumn = $strColumn;
 }
Ejemplo n.º 30
0
 /**
  * Check permissions to edit table tl_form
  *
  * @throws Contao\CoreBundle\Exception\AccessDeniedException
  */
 public function checkPermission()
 {
     if ($this->User->isAdmin) {
         return;
     }
     // Set root IDs
     if (!is_array($this->User->forms) || empty($this->User->forms)) {
         $root = array(0);
     } else {
         $root = $this->User->forms;
     }
     $GLOBALS['TL_DCA']['tl_form']['list']['sorting']['root'] = $root;
     // Check permissions to add forms
     if (!$this->User->hasAccess('create', 'formp')) {
         $GLOBALS['TL_DCA']['tl_form']['config']['closed'] = true;
     }
     /** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
     $objSession = System::getContainer()->get('session');
     // Check current action
     switch (Input::get('act')) {
         case 'create':
         case 'select':
             // Allow
             break;
         case 'edit':
             // Dynamically add the record to the user profile
             if (!in_array(Input::get('id'), $root)) {
                 /** @var Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface $objSessionBag */
                 $objSessionBag = $objSession->getBag('contao_backend');
                 $arrNew = $objSessionBag->get('new_records');
                 if (is_array($arrNew['tl_form']) && in_array(Input::get('id'), $arrNew['tl_form'])) {
                     // Add permissions on user level
                     if ($this->User->inherit == 'custom' || !$this->User->groups[0]) {
                         $objUser = $this->Database->prepare("SELECT forms, formp FROM tl_user WHERE id=?")->limit(1)->execute($this->User->id);
                         $arrFormp = StringUtil::deserialize($objUser->formp);
                         if (is_array($arrFormp) && in_array('create', $arrFormp)) {
                             $arrForms = StringUtil::deserialize($objUser->forms);
                             $arrForms[] = Input::get('id');
                             $this->Database->prepare("UPDATE tl_user SET forms=? WHERE id=?")->execute(serialize($arrForms), $this->User->id);
                         }
                     } elseif ($this->User->groups[0] > 0) {
                         $objGroup = $this->Database->prepare("SELECT forms, formp FROM tl_user_group WHERE id=?")->limit(1)->execute($this->User->groups[0]);
                         $arrFormp = StringUtil::deserialize($objGroup->formp);
                         if (is_array($arrFormp) && in_array('create', $arrFormp)) {
                             $arrForms = StringUtil::deserialize($objGroup->forms);
                             $arrForms[] = Input::get('id');
                             $this->Database->prepare("UPDATE tl_user_group SET forms=? WHERE id=?")->execute(serialize($arrForms), $this->User->groups[0]);
                         }
                     }
                     // Add new element to the user object
                     $root[] = Input::get('id');
                     $this->User->forms = $root;
                 }
             }
             // No break;
         // No break;
         case 'copy':
         case 'delete':
         case 'show':
             if (!in_array(Input::get('id'), $root) || Input::get('act') == 'delete' && !$this->User->hasAccess('delete', 'formp')) {
                 throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to ' . Input::get('act') . ' form ID ' . Input::get('id') . '.');
             }
             break;
         case 'editAll':
         case 'deleteAll':
         case 'overrideAll':
             $session = $objSession->all();
             if (Input::get('act') == 'deleteAll' && !$this->User->hasAccess('delete', 'formp')) {
                 $session['CURRENT']['IDS'] = array();
             } else {
                 $session['CURRENT']['IDS'] = array_intersect($session['CURRENT']['IDS'], $root);
             }
             $objSession->replace($session);
             break;
         default:
             if (strlen(Input::get('act'))) {
                 throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to ' . Input::get('act') . ' forms.');
             }
             break;
     }
 }