- <?php
- /**
-  * Contao Open Source CMS
-  *
-  * Copyright (c) 2005-2015 Leo Feyer
-  *
-  * @package   SgElements
-  * @author    Sg-Medien GmbH <info@sg-medien.com>
-  * @license   EULA
-  * @copyright Sg-Medien GmbH 2015
-  */
- /**
-  * Palettes
-  */
- $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'addImage';
- $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'addTeaser';
- /**
-  * Modify exististing palettes
-  */
- foreach($GLOBALS['TL_DCA']['tl_page']['palettes'] AS $type => $palette)
- {
-     if ($type == 'regular')
-     {
-         $GLOBALS['TL_DCA']['tl_page']['palettes'][$type] = str_replace('{protected_legend', '{source_legend:hide},addImage;{teaser_legend:hide},addTeaser;{protected_legend', $GLOBALS['TL_DCA']['tl_page']['palettes'][$type]);
-     }
-     else if ($type == 'forward' OR $type == 'redirect')
-     {
-         $GLOBALS['TL_DCA']['tl_page']['palettes'][$type] = str_replace('{redirect_legend', '{source_legend:hide},addImage;{teaser_legend:hide},addTeaser;{redirect_legend', $GLOBALS['TL_DCA']['tl_page']['palettes'][$type]);
-     }
- }
- /**
-  * Subpalettes
-  */
- $GLOBALS['TL_DCA']['tl_page']['subpalettes']['addImage'] = 'singleSRC,alt,size';
- $GLOBALS['TL_DCA']['tl_page']['subpalettes']['addTeaser'] = 'teaser';
- /**
-  * Modify exististing fields
-  */
- $GLOBALS['TL_DCA']['tl_page']['fields']['cssClass']['eval']['maxlength'] = 255;
- $GLOBALS['TL_DCA']['tl_page']['fields']['cssClass']['sql'] = "varchar(255) NOT NULL default ''";  
-         
- /**
-  * Fields
-  */
- array_insert($GLOBALS['TL_DCA']['tl_page']['fields'], count($GLOBALS['TL_DCA']['tl_page']['fields']), array
- (
-     'addImage' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['addImage'],
-         'exclude' => true,
-         'inputType' => 'checkbox',
-         'eval' => array
-         (
-             'submitOnChange'=>true
-         ),
-         'sql' => "char(1) NOT NULL default ''"
-     ),
-     'singleSRC' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['singleSRC'],
-         'exclude' => true,
-         'inputType' => 'fileTree',
-         'eval' => array
-         (
-             'mandatory' => true,
-             'filesOnly' => true, 
-             'fieldType'=>'radio',
-             'tl_class' => 'clr',
-             'extensions' => \Config::get('validImageTypes')
-         ),
-         'sql' => "binary(16) NULL",
-         'save_callback' => array
-         (
-             array('sg_elements_tl_page', 'storeFileMetaInformation')
-         )
-     ),
-     'alt' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['alt'],
-         'exclude' => true,
-         'inputType' => 'text',
-         'eval' => array
-         (
-             'maxlength' => 255, 
-             'tl_class' => 'w50'
-         ),
-         'sql' => "varchar(255) NOT NULL default ''"
-     ),
-     'size' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['size'],
-         'exclude' => true,
-         'inputType' => 'imageSize',
-         'options' => \System::getImageSizes(),
-         'reference' => &$GLOBALS['TL_LANG']['MSC'],
-         'eval' => array
-         (
-             'rgxp' => 'natural',
-             'includeBlankOption' => true,
-             'nospace' => true,
-             'helpwizard' => true,
-             'tl_class' => 'w50'
-         ),
-         'sql' => "varchar(64) NOT NULL default ''"
-     ),
-     'addTeaser' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['addTeaser'],
-         'exclude' => true,
-         'inputType' => 'checkbox',
-         'eval' => array
-         (
-             'submitOnChange' => true,
-             'tl_class' => 'm12'
-         ),
-         'sql' => "char(1) NOT NULL default ''"
-     ),
-     'teaser' => array
-     (
-         'label' => &$GLOBALS['TL_LANG']['tl_page']['teaser'],
-         'exclude' => true,
-         'inputType' => 'textarea',
-         'search' => true,
-         'eval' => array
-         (
-             'mandatory' => true,
-             'rte' => 'tinyMCE',
-             'tl_class' => 'clr'
-         ),
-         'sql' => "text NULL"
-     )
- ));
- /**
-  * Class sg_elements_tl_page
-  *
-  * Extension for class "\tl_page".
-  * 
-  * @package   SgElements
-  * @author    Sg-Medien GmbH <info@sg-medien.com>
-  * @copyright Sg-Medien GmbH 2015
-  */
- class sg_elements_tl_page extends \tl_page
- {
-     
-     /**
-      * Pre-fill the "alt" and "caption" fields with the file meta data
-      * @param mixed
-      * @param \DataContainer
-      * @return mixed
-      */
-     public function storeFileMetaInformation($varValue, \DataContainer $dc)
-     {
-         if ($dc->activeRecord->singleSRC == $varValue)
-         {
-             return $varValue;
-         }
-         $objFile = \FilesModel::findByUuid($varValue);
-         if ($objFile !== null)
-         {
-             $arrMeta = deserialize($objFile->meta);
-             if (!empty($arrMeta))
-             {
-                 $objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")->execute($dc->activeRecord->id);
-                 if ($objPage->numRows)
-                 {
-                     $objModel = new PageModel();
-                     $objModel->setRow($objPage->row());
-                     $objModel->loadDetails();
-                     // Convert the language to a locale (see #5678)
-                     $strLanguage = str_replace('-', '_', $objModel->rootLanguage);
-                     if (isset($arrMeta[$strLanguage]))
-                     {
-                         \Input::setPost('alt', $arrMeta[$strLanguage]['title']);
-                         \Input::setPost('caption', $arrMeta[$strLanguage]['caption']);
-                     }
-                 }
-             }
-         }
-         return $varValue;
-     }
- }
-