コード例 #1
0
 public function run()
 {
     try {
         $objChildLayouts = LayoutModel::findBy(array('isChild=1', 'specificFields<>\'\'', 'specificLegends=\'\''), array());
     } catch (Exception $e) {
         return;
     }
     while (null !== $objChildLayouts && $objChildLayouts->next()) {
         $arrFields = deserialize($objChildLayouts->specificFields);
         $arrLegends = array();
         foreach ($arrFields as $section) {
             preg_match('/\\{([^\\}]+?)\\}/', $section, $matches);
             $arrLegends[] = strstr($matches[1], ':', true) ?: $matches[1];
         }
         $objChildLayouts->specificLegends = implode(',', $arrLegends);
         $objChildLayouts->save();
     }
 }
コード例 #2
0
 /**
  * Update all child layouts belonging to parent layout
  * @category onsubmit_callback
  *
  * @param \DataContainer $dc
  */
 public function updateChildLayouts(\DataContainer $dc)
 {
     if ($dc->activeRecord->isChild) {
         /** @type \Model $objParentLayout */
         $objParentLayout = \LayoutModel::findByPk($dc->activeRecord->parentLayout);
         $arrData = $objParentLayout->row();
         // Delete columns that must not be overridden
         foreach (self::getColumnsToPersist() as $v) {
             unset($arrData[$v]);
         }
         // Delete columns specific for this child layout
         if ($dc->activeRecord->specificLegends) {
             $this->deleteSpecificColumns($dc->activeRecord->specificLegends, $arrData, $dc->activeRecord->row());
         }
         // Save parent data in database
         // Do not use the LayoutModel here
         \Database::getInstance()->prepare("UPDATE tl_layout %s WHERE id=?")->set($arrData)->execute($dc->id);
     } else {
         $objChildLayouts = \LayoutModel::findBy(array('tl_layout.isChild=1', 'tl_layout.id IN (SELECT tl_layout.id FROM tl_layout WHERE tl_layout.parentLayout=?)'), array($dc->id));
         if (null !== $objChildLayouts) {
             $arrData = $dc->activeRecord->row();
             // Delete columns specific for each layout
             foreach (self::getColumnsToPersist() as $v) {
                 unset($arrData[$v]);
             }
             while ($objChildLayouts->next()) {
                 if ($objChildLayouts->specificLegends) {
                     $this->deleteSpecificColumns($objChildLayouts->specificLegends, $arrData, $objChildLayouts->row());
                 }
                 // Update child layout row
                 // Do not use the LayoutModel here
                 \Database::getInstance()->prepare("UPDATE tl_layout %s WHERE id=?")->set($arrData)->execute($objChildLayouts->id);
             }
         }
     }
 }
コード例 #3
0
 public function buildArticleSections(CreateOptionsEvent $event)
 {
     $options = $event->getOptions();
     $sections = $options->getArrayCopy();
     $sections['header'] = 'header';
     $sections['left'] = 'left';
     $sections['right'] = 'right';
     $sections['main'] = 'main';
     $sections['footer'] = 'footer';
     $layouts = \LayoutModel::findBy(array('sections!=?'), array(''));
     if ($layouts) {
         foreach ($layouts as $layout) {
             $temp = trimsplit(',', $layout->sections);
             foreach ($temp as $section) {
                 if (!in_array($section, $sections)) {
                     $sections[$section] = $section;
                 }
             }
         }
     }
     $options->exchangeArray($sections);
 }
コード例 #4
0
ファイル: File.php プロジェクト: bit3/contao-theme-plus
 /**
  * List an file
  *
  * @param array
  *
  * @return string
  */
 public function listFileFor($row, $layoutField = false)
 {
     switch ($row['type']) {
         case 'code':
             $label = $row['code_snippet_title'];
             break;
         case 'url':
             $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $row['url']);
             break;
         case 'file':
             if ($row['filesource'] == $GLOBALS['TL_CONFIG']['uploadPath'] && version_compare(VERSION, '3', '>=')) {
                 $file = version_compare(VERSION, '3.2', '>=') ? \FilesModel::findByUuid($row['file']) : \FilesModel::findByPk($row['file']);
                 if ($file) {
                     $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $file->path);
                     break;
                 }
             } else {
                 $label = preg_replace('#([^/]+)$#', '<strong>$1</strong>', $row['file']);
                 break;
             }
         default:
             $label = '?';
     }
     if ($row['inline']) {
         \Controller::loadLanguageFile('tl_theme_plus_file');
         $label = sprintf('<span title="%s">&lsaquo;&rsaquo;</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['inline'], ENT_QUOTES, 'UTF-8'), $label);
     } else {
         if ($row['standalone']) {
             \Controller::loadLanguageFile('tl_theme_plus_file');
             $label = sprintf('<span title="%s">&times;</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['standalone'], ENT_QUOTES, 'UTF-8'), $label);
         }
     }
     if (strlen($row['position'])) {
         $label = '[' . strtoupper($row['position']) . '] ' . $label;
     }
     if (strlen($row['cc'])) {
         $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">[' . $row['cc'] . ']</span>';
     }
     $filterRules = static::renderFilterRules($row);
     if ($filterRules) {
         $label .= sprintf('<br><span style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">[%s]</span>', $filterRules);
     }
     if ($layoutField) {
         $assignedLayouts = [];
         $themes = \ThemeModel::findAll(['order' => 'name']);
         foreach ($themes as $theme) {
             $assignedThemeLayouts = [];
             $layouts = \LayoutModel::findBy('pid', $theme->id, ['order' => 'name']);
             foreach ($layouts as $layout) {
                 $files = deserialize($layout->{$layoutField}, true);
                 if (in_array($row['id'], $files)) {
                     $assignedThemeLayouts[$layout->id] = $layout->name;
                 }
             }
             if (count($assignedThemeLayouts)) {
                 $assignedLayouts[$theme->name] = $assignedThemeLayouts;
             }
         }
         if (count($assignedLayouts)) {
             $label .= '<ul style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">';
             foreach ($assignedLayouts as $theme => $layouts) {
                 $label .= '<li>';
                 $label .= sprintf('<strong>%s</strong>', $theme);
                 $label .= '<ul>';
                 foreach ($layouts as $id => $layout) {
                     $label .= sprintf('<li>&nbsp;&rdsh; <a href="%s">%s</a></li>', \Backend::addToUrl('table=tl_layout&act=edit&id=' . $id), $layout);
                 }
                 $label .= '</ul>';
                 $label .= '</li>';
             }
             $label .= '</ul>';
         }
     }
     $image = 'assets/theme-plus/images/' . $row['type'] . '.png';
     return '<div>' . ($image ? $this->generateImage($image, $label, 'style="vertical-align:-3px"') . ' ' : '') . $label . "</div>\n";
 }