[TASK] RTE: Remove unused css files
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / Typo3Link.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Extension;
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
20 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase;
21
22 /**
23 * TYPO3Link plugin for htmlArea RTE
24 *
25 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
26 */
27 class Typo3Link extends RteHtmlAreaApi {
28
29 /**
30 * The name of the plugin registered by the extension
31 *
32 * @var string
33 */
34 protected $pluginName = 'TYPO3Link';
35
36 /**
37 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
38 *
39 * @var string
40 */
41 protected $pluginButtons = 'link, unlink';
42
43 /**
44 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
45 *
46 * @var array
47 */
48 protected $convertToolbarForHtmlAreaArray = array(
49 'link' => 'CreateLink',
50 'unlink' => 'UnLink'
51 );
52
53 /**
54 * Returns TRUE if the plugin is available and correctly initialized
55 *
56 * @param RteHtmlAreaBase $parentObject parent object
57 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
58 */
59 public function main($parentObject) {
60 $enabled = parent::main($parentObject);
61 // Check if this should be enabled based on Page TSConfig
62 return $enabled && !$this->thisConfig['buttons.']['link.']['TYPO3Browser.']['disabled'];
63 }
64
65 /**
66 * Return JS configuration of the htmlArea plugins registered by the extension
67 *
68 * @param string $rteNumberPlaceholder A dummy string for JS arrays
69 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
70 */
71 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
72 $registerRTEinJavascriptString = '';
73 $button = 'link';
74 if (in_array($button, $this->toolbar)) {
75 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
76 $registerRTEinJavascriptString .= '
77 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
78 }
79 $registerRTEinJavascriptString .= '
80 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . '.pathLinkModule = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('rtehtmlarea_wizard_browse_links')) . ';';
81 if ($this->htmlAreaRTE->is_FE()) {
82 $RTEProperties = $this->htmlAreaRTE->RTEsetup;
83 } else {
84 $RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
85 }
86 if (is_array($RTEProperties['classesAnchor.'])) {
87 $registerRTEinJavascriptString .= '
88 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . '.classesAnchorUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', ('classesAnchor_' . $this->htmlAreaRTE->contentLanguageUid), 'js', $this->buildJSClassesAnchorArray(), TRUE) . '";';
89 }
90 $registerRTEinJavascriptString .= '
91 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . '.additionalAttributes = "data-htmlarea-external' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey]['plugins'][$this->pluginName]['additionalAttributes'] ? ',' . $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey]['plugins'][$this->pluginName]['additionalAttributes'] : '') . '";';
92 }
93 return $registerRTEinJavascriptString;
94 }
95
96 /**
97 * Return a JS array for special anchor classes
98 *
99 * @return string classesAnchor array definition
100 */
101 public function buildJSClassesAnchorArray() {
102 $JSClassesAnchorArray .= 'HTMLArea.classesAnchorSetup = [ ' . LF;
103 $classesAnchorIndex = 0;
104 foreach ($this->htmlAreaRTE->RTEsetup['properties']['classesAnchor.'] as $label => $conf) {
105 if (is_array($conf) && $conf['class']) {
106 $JSClassesAnchorArray .= ($classesAnchorIndex++ ? ',' : '') . ' { ' . LF;
107 $index = 0;
108 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'name : "' . str_replace('"', '', str_replace('\'', '', $conf['class'])) . '"' . LF;
109 if ($conf['type']) {
110 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'type : "' . str_replace('"', '', str_replace('\'', '', $conf['type'])) . '"' . LF;
111 }
112 if (trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))) {
113 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'image : "' . $this->htmlAreaRTE->siteURL . GeneralUtility::resolveBackPath((TYPO3_mainDir . $this->htmlAreaRTE->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))))) . '"' . LF;
114 }
115 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'addIconAfterLink : ' . ($conf['addIconAfterLink'] ? 'true' : 'false') . LF;
116 if (trim($conf['altText'])) {
117 $string = $this->htmlAreaRTE->getLLContent(trim($conf['altText']));
118 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'altText : ' . str_replace('"', '\\"', str_replace('\\\'', '\'', $string)) . LF;
119 }
120 if (trim($conf['titleText'])) {
121 $string = $this->htmlAreaRTE->getLLContent(trim($conf['titleText']));
122 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'titleText : ' . str_replace('"', '\\"', str_replace('\\\'', '\'', $string)) . LF;
123 }
124 if (trim($conf['target'])) {
125 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'target : "' . trim($conf['target']) . '"' . LF;
126 }
127 $JSClassesAnchorArray .= '}' . LF;
128 }
129 }
130 $JSClassesAnchorArray .= '];' . LF;
131 return $JSClassesAnchorArray;
132 }
133
134 /**
135 * Return an updated array of toolbar enabled buttons
136 *
137 * @param array $show: array of toolbar elements that will be enabled, unless modified here
138 * @return array toolbar button array, possibly updated
139 */
140 public function applyToolbarConstraints($show) {
141 // We will not allow unlink if link is not enabled
142 if (!in_array('link', $show)) {
143 return array_diff($show, GeneralUtility::trimExplode(',', $this->pluginButtons));
144 } else {
145 return $show;
146 }
147 }
148
149 }