TYPO3 CMS  TYPO3_7-6
SelectFont.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
30  protected $pluginName = 'SelectFont';
31 
37  protected $pluginButtons = 'fontstyle,fontsize';
38 
45  'fontstyle' => 'FontName',
46  'fontsize' => 'FontSize'
47  ];
48 
54  protected $defaultFont = [
55  'fontstyle' => [
56  'Arial' => 'Arial,sans-serif',
57  'Arial Black' => '\'Arial Black\',sans-serif',
58  'Verdana' => 'Verdana,Arial,sans-serif',
59  'Times New Roman' => '\'Times New Roman\',Times,serif',
60  'Garamond' => 'Garamond',
61  'Lucida Handwriting' => '\'Lucida Handwriting\'',
62  'Courier' => 'Courier',
63  'Webdings' => 'Webdings',
64  'Wingdings' => 'Wingdings'
65  ],
66  'fontsize' => [
67  'Extra small' => '8px',
68  'Very small' => '9px',
69  'Small' => '10px',
70  'Medium' => '12px',
71  'Large' => '16px',
72  'Very large' => '24px',
73  'Extra large' => '32px'
74  ]
75  ];
76 
82  protected $RTEProperties;
83 
90  public function main(array $configuration)
91  {
92  $enabled = parent::main($configuration) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['allowStyleAttribute'];
93  $this->RTEProperties = $this->configuration['RTEsetup']['properties'];
94  return $enabled;
95  }
96 
103  {
104  $jsArray = [];
105  $pluginButtonsArray = GeneralUtility::trimExplode(',', $this->pluginButtons);
106  // Process Page TSConfig configuration for each button
107  foreach ($pluginButtonsArray as $buttonId) {
108  if (in_array($buttonId, $this->toolbar)) {
109  $jsArray[] = $this->buildJSFontItemsConfig($buttonId);
110  }
111  }
112  return implode(LF, $jsArray);
113  }
114 
121  protected function buildJSFontItemsConfig($buttonId)
122  {
123  $jsArray = [];
124  $hideItems = '';
125  $addItems = [];
126  // Getting removal and addition configuration
127  if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.'][$buttonId . '.'])) {
128  if ($this->configuration['thisConfig']['buttons.'][$buttonId . '.']['removeItems']) {
129  $hideItems = $this->configuration['thisConfig']['buttons.'][$buttonId . '.']['removeItems'];
130  }
131  if ($this->configuration['thisConfig']['buttons.'][$buttonId . '.']['addItems']) {
132  $addItems = GeneralUtility::trimExplode(',', $this->cleanList($this->configuration['thisConfig']['buttons.'][$buttonId . '.']['addItems']), true);
133  }
134  }
135  $languageService = $this->getLanguageService();
136  // Initializing the items array
137  $languageKey = $buttonId == 'fontstyle' ? 'Default font' : 'Default size';
138  $items = [
139  'none' => [
140  $languageService->sL(
141  'LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/SelectFont/locallang.xlf:' . $languageKey
142  ),
143  'none'
144  ],
145  ];
146  // Inserting and localizing default items
147  if ($hideItems != '*') {
148  $index = 0;
149  foreach ($this->defaultFont[$buttonId] as $name => $value) {
150  if (!GeneralUtility::inList($hideItems, strval(($index + 1)))) {
151  $label = $languageService->sL('LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/SelectFont/locallang.xlf:' . $name) ?: $name;
152  $items[$name] = [$label, $this->cleanList($value)];
153  }
154  $index++;
155  }
156  }
157  // Adding configured items
158  if (is_array($this->RTEProperties[$buttonId == 'fontstyle' ? 'fonts.' : 'fontSizes.'])) {
159  foreach ($this->RTEProperties[$buttonId == 'fontstyle' ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
160  $name = substr($name, 0, -1);
161  if (in_array($name, $addItems)) {
162  $label = $this->getPageConfigLabel($conf['name']);
163  $items[$name] = [$label, $this->cleanList($conf['value'])];
164  }
165  }
166  }
167  // Seting default item
168  if ($this->configuration['thisConfig']['buttons.'][$buttonId . '.']['defaultItem'] && $items[$this->configuration['thisConfig']['buttons.'][$buttonId . '.']['defaultItem']]) {
169  $items['none'] = [$items[$this->configuration['thisConfig']['buttons.'][$buttonId . '.']['defaultItem']][0], 'none'];
170  unset($items[$this->configuration['thisConfig']['buttons.'][$buttonId . '.']['defaultItem']]);
171  }
172  // Setting the JS list of options
173  $itemsJSArray = [];
174  foreach ($items as $name => $option) {
175  $itemsJSArray[] = ['text' => $option[0], 'value' => $option[1]];
176  }
177  $itemsJSArray = json_encode(['options' => $itemsJSArray]);
178  // Adding to button JS configuration
179  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][$buttonId . '.'])) {
180  $jsArray[] = 'RTEarea[editornumber].buttons.' . $buttonId . ' = new Object();';
181  }
182  $jsArray[] = 'RTEarea[editornumber].buttons.' . $buttonId . '.dataUrl = "' . $this->writeTemporaryFile($buttonId . '_' . $this->configuration['contentLanguageUid'], 'js', $itemsJSArray) . '";';
183  return implode(LF, $jsArray);
184  }
185 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
writeTemporaryFile($label, $fileExtension='js', $contents='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']