TYPO3 CMS  TYPO3_6-2
SelectFont.php
Go to the documentation of this file.
1 <?php
3 
22 
23  protected $extensionKey = 'rtehtmlarea';
24 
25  // The key of the extension that is extending htmlArea RTE
26  protected $pluginName = 'SelectFont';
27 
28  // The name of the plugin registered by the extension
29  protected $relativePathToLocallangFile = 'extensions/SelectFont/locallang.xlf';
30 
31  // Path to this main locallang file of the extension relative to the extension dir.
32  protected $relativePathToSkin = '';
33 
34  // Path to the skin (css) file relative to the extension dir.
35  protected $htmlAreaRTE;
36 
37  // Reference to the invoking object
38  protected $thisConfig;
39 
40  // Reference to RTE PageTSConfig
41  protected $toolbar;
42 
43  // Reference to RTE toolbar array
44  protected $LOCAL_LANG;
45 
46  // Frontend language array
47  protected $pluginButtons = 'fontstyle,fontsize';
48 
50  'fontstyle' => 'FontName',
51  'fontsize' => 'FontSize'
52  );
53 
54  protected $defaultFont = array(
55  'fontstyle' => array(
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' => array(
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 
77  protected $RTEProperties;
78 
79  public function main($parentObject) {
80  $enabled = parent::main($parentObject) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['allowStyleAttribute'];
81  if ($this->htmlAreaRTE->is_FE()) {
82  $this->RTEProperties = $this->htmlAreaRTE->RTEsetup;
83  } else {
84  $this->RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
85  }
86  return $enabled;
87  }
88 
95  public function buildJavascriptConfiguration($RTEcounter) {
96  $registerRTEinJavascriptString = '';
97  $pluginButtonsArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pluginButtons);
98  // Process Page TSConfig configuration for each button
99  foreach ($pluginButtonsArray as $buttonId) {
100  if (in_array($buttonId, $this->toolbar)) {
101  $registerRTEinJavascriptString .= $this->buildJSFontItemsConfig($RTEcounter, $buttonId);
102  }
103  }
104  return $registerRTEinJavascriptString;
105  }
106 
114  protected function buildJSFontItemsConfig($RTEcounter, $buttonId) {
115  $configureRTEInJavascriptString = '';
116  $hideItems = '';
117  $addItems = array();
118  // Getting removal and addition configuration
119  if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
120  if ($this->thisConfig['buttons.'][$buttonId . '.']['removeItems']) {
121  $hideItems = $this->thisConfig['buttons.'][$buttonId . '.']['removeItems'];
122  }
123  if ($this->thisConfig['buttons.'][$buttonId . '.']['addItems']) {
124  $addItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.'][$buttonId . '.']['addItems']), TRUE);
125  }
126  }
127  // Initializing the items array
128  $items = array();
129  if ($this->htmlAreaRTE->is_FE()) {
130  $items['none'] = array($GLOBALS['TSFE']->getLLL($buttonId == 'fontstyle' ? 'Default font' : 'Default size', $this->LOCAL_LANG), 'none');
131  } else {
132  $items['none'] = array($GLOBALS['LANG']->getLL($buttonId == 'fontstyle' ? 'Default font' : 'Default size'), 'none');
133  }
134  // Inserting and localizing default items
135  if ($hideItems != '*') {
136  $index = 0;
137  foreach ($this->defaultFont[$buttonId] as $name => $value) {
138  if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($hideItems, strval(($index + 1)))) {
139  if ($this->htmlAreaRTE->is_FE()) {
140  $label = $GLOBALS['TSFE']->getLLL($name, $this->LOCAL_LANG);
141  } else {
142  $label = $GLOBALS['LANG']->getLL($name);
143  if (!$label) {
144  $label = $name;
145  }
146  }
147  $items[$name] = array($label, $this->htmlAreaRTE->cleanList($value));
148  }
149  $index++;
150  }
151  }
152  // Adding configured items
153  if (is_array($this->RTEProperties[$buttonId == 'fontstyle' ? 'fonts.' : 'fontSizes.'])) {
154  foreach ($this->RTEProperties[$buttonId == 'fontstyle' ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
155  $name = substr($name, 0, -1);
156  if (in_array($name, $addItems)) {
157  $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'], 0);
158  $items[$name] = array($label, $this->htmlAreaRTE->cleanList($conf['value']));
159  }
160  }
161  }
162  // Seting default item
163  if ($this->thisConfig['buttons.'][$buttonId . '.']['defaultItem'] && $items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]) {
164  $items['none'] = array($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']][0], 'none');
165  unset($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]);
166  }
167  // Setting the JS list of options
168  $itemsJSArray = array();
169  foreach ($items as $name => $option) {
170  $itemsJSArray[] = array('text' => $option[0], 'value' => $option[1]);
171  }
172  if ($this->htmlAreaRTE->is_FE()) {
173  $GLOBALS['TSFE']->csConvObj->convArray($itemsJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8');
174  }
175  $itemsJSArray = json_encode(array('options' => $itemsJSArray));
176  // Adding to button JS configuration
177  if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($buttonId . '.')])) {
178  $configureRTEInJavascriptString .= '
179  RTEarea[' . $RTEcounter . '].buttons.' . $buttonId . ' = new Object();';
180  }
181  $configureRTEInJavascriptString .= '
182  RTEarea[' . $RTEcounter . '].buttons.' . $buttonId . '.dataUrl = "' . ($this->htmlAreaRTE->is_FE() && $GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . $this->htmlAreaRTE->writeTemporaryFile('', ($buttonId . '_' . $this->htmlAreaRTE->contentLanguageUid), 'js', $itemsJSArray) . '";';
183  return $configureRTEInJavascriptString;
184  }
185 
186 }
buildJSFontItemsConfig($RTEcounter, $buttonId)
Definition: SelectFont.php:114
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]