[TASK] Replace Space Indent into Tab indent (CGL Cleanup)
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / Acronym / class.tx_rtehtmlarea_acronym.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Acronym extension for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 */
30 class tx_rtehtmlarea_acronym extends tx_rtehtmlarea_api {
31
32 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
33 protected $pluginName = 'Acronym'; // The name of the plugin registered by the extension
34 protected $relativePathToLocallangFile = ''; // Path to this main locallang file of the extension relative to the extension dir.
35 protected $relativePathToSkin = 'extensions/Acronym/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir
36 protected $htmlAreaRTE; // Reference to the invoking object
37 protected $thisConfig; // Reference to RTE PageTSConfig
38 protected $toolbar; // Reference to RTE toolbar array
39 protected $LOCAL_LANG; // Frontend language array
40
41 protected $pluginButtons = 'acronym';
42 protected $convertToolbarForHtmlAreaArray = array (
43 'acronym' => 'Acronym',
44 );
45 protected $acronymIndex = 0;
46 protected $abbreviationIndex = 0;
47
48 public function main($parentObject) {
49
50 return parent::main($parentObject) && t3lib_extMgm::isLoaded('static_info_tables');
51 }
52
53 /**
54 * Return tranformed content
55 *
56 * @param string $content: The content that is about to be sent to the RTE
57 *
58 * @return string the transformed content
59 */
60 public function transformContent($content) {
61
62 // <abbr> was not supported by IE before verison 7
63 if ($this->htmlAreaRTE->client['browser'] == 'msie' && $this->htmlAreaRTE->client['version'] < 7) {
64 // change <abbr> to <acronym>
65 $content = preg_replace('/<(\/?)abbr/i', "<$1acronym", $content);
66 }
67
68 return $content;
69 }
70
71 /**
72 * Return JS configuration of the htmlArea plugins registered by the extension
73 *
74 * @param integer Relative id of the RTE editing area in the form
75 *
76 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
77 *
78 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
79 * Each of the instructions should be of the form:
80 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
81 */
82 public function buildJavascriptConfiguration($RTEcounter) {
83
84 $registerRTEinJavascriptString = '';
85 $button = 'acronym';
86 if (in_array($button, $this->toolbar)) {
87 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$button.'.'])) {
88 $registerRTEinJavascriptString .= '
89 RTEarea['.$RTEcounter.']["buttons"]["'. $button .'"] = new Object();';
90 }
91 $registerRTEinJavascriptString .= '
92 RTEarea['.$RTEcounter.'].buttons.'. $button .'.acronymUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', 'acronym_'.$this->htmlAreaRTE->contentLanguageUid, 'js', $this->buildJSAcronymArray($this->htmlAreaRTE->contentLanguageUid)) . '";';
93
94 // <abbr> was not supported by IE before version 7
95 if ($this->htmlAreaRTE->client['browser'] == 'msie' && $this->htmlAreaRTE->client['version'] < 7) {
96 $this->abbreviationIndex = 0;
97 }
98 $registerRTEinJavascriptString .= '
99 RTEarea['.$RTEcounter.'].buttons.'. $button .'.noAcronym = ' . ($this->acronymIndex ? 'false' : 'true') . ';
100 RTEarea['.$RTEcounter.'].buttons.'. $button .'.noAbbr = ' . ($this->abbreviationIndex ? 'false' : 'true') . ';';
101 }
102
103 return $registerRTEinJavascriptString;
104 }
105
106 /**
107 * Return an acronym array for the Acronym plugin
108 *
109 * @return string acronym Javascript array
110 */
111 function buildJSAcronymArray($languageUid) {
112
113 $button = 'acronym';
114 $acronymArray = array();
115 $abbrArray = array();
116
117 $tableA = 'tx_rtehtmlarea_acronym';
118 $tableB = 'static_languages';
119 $fields = $tableA.'.type,' . $tableA . '.term,' . $tableA . '.acronym,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2';
120 $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
121 $whereClause = '1=1';
122 // Get all acronyms on pages to which the user has access
123 $lockBeUserToDBmounts = isset($this->thisConfig['buttons.'][$button.'.']['lockBeUserToDBmounts']) ? $this->thisConfig['buttons.'][$button.'.']['lockBeUserToDBmounts'] : $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'];
124 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] && $lockBeUserToDBmounts) {
125 // Temporarily setting alternative web browsing mounts
126 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
127 if ($altMountPoints) {
128 $savedGroupDataWebmounts = $GLOBALS['BE_USER']->groupData['webmounts'];
129 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(t3lib_div::intExplode(',', $altMountPoints)));
130 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
131 }
132 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
133 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
134 $recursive = isset($this->thisConfig['buttons.'][$button.'.']['recursive']) ? intval($this->thisConfig['buttons.'][$button.'.']['recursive']) : 0 ;
135 if (trim($this->thisConfig['buttons.'][$button.'.']['pages'])) {
136 $pids = t3lib_div::trimExplode(',', $this->thisConfig['buttons.'][$button.'.']['pages'], 1);
137 foreach ($pids as $key => $val) {
138 if (!$GLOBALS['BE_USER']->isInWebMount($val, $perms_clause)) {
139 unset($pids[$key]);
140 }
141 }
142 } else {
143 $pids = $webMounts;
144 }
145 // Restoring webmounts
146 if ($altMountPoints) {
147 $GLOBALS['BE_USER']->groupData['webmounts'] = $savedGroupDataWebmounts;
148 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
149 }
150 $queryGenerator = t3lib_div::makeInstance('t3lib_queryGenerator');
151 foreach ($pids as $key => $val) {
152 if ($pageTree) {
153 $pageTreePrefix = ',';
154 }
155 $pageTree .= $pageTreePrefix . $queryGenerator->getTreeList($val, $recursive, $begin = 0, $perms_clause);
156 }
157 $whereClause .= ' AND '. $tableA . '.pid IN (' . $GLOBALS['TYPO3_DB']->fullQuoteStr(($pageTree ? $pageTree : ''), $tableA) . ')';
158 }
159 // Restrict to acronyms applicable to the language of current content element
160 if ($this->htmlAreaRTE->contentLanguageUid > -1) {
161 $whereClause .= ' AND (' . $tableA . '.sys_language_uid=' . $this->htmlAreaRTE->contentLanguageUid . ' OR ' . $tableA . '.sys_language_uid=-1) ';
162 }
163 // Restrict to acronyms in certain languages
164 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
165 $languageList = implode("','", t3lib_div::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $tableB)));
166 $whereClause .= ' AND '. $tableB . '.lg_iso_2 IN (' . $languageList . ') ';
167 }
168 $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
169 $whereClause .= t3lib_BEfunc::deleteClause($tableA);
170 $whereClause .= t3lib_BEfunc::BEenableFields($tableB);
171 $whereClause .= t3lib_BEfunc::deleteClause($tableB);
172 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $tableAB, $whereClause);
173 while ($acronymRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
174 $item = array('term' => $acronymRow['term'], 'abbr' => $acronymRow['acronym'], 'language' => strtolower($acronymRow['lg_iso_2']) . ($acronymRow['lg_country_iso_2'] ? ('-' . $acronymRow['lg_country_iso_2']) : ''));
175 if ($acronymRow['type'] == 1) {
176 $acronymArray[] = $item;
177 } elseif ($acronymRow['type'] == 2) {
178 $abbrArray[] = $item;
179 }
180 }
181 $this->acronymIndex = count($acronymArray);
182 $this->abbreviationIndex = count($abbrArray);
183 return json_encode(array('abbr' => $abbrArray, 'acronym' => $acronymArray));
184 }
185 }
186 ?>