Fixed bug #9331: htmlArea RTE Acronym feature: List of unabridged terms shows wrong...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / Acronym / class.tx_rtehtmlarea_acronym.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 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 * TYPO3 SVN ID: $Id$
30 *
31 */
32
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_acronym extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'Acronym'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = ''; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/Acronym/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir
41 protected $htmlAreaRTE; // Reference to the invoking object
42 protected $thisConfig; // Reference to RTE PageTSConfig
43 protected $toolbar; // Reference to RTE toolbar array
44 protected $LOCAL_LANG; // Frontend language array
45
46 protected $pluginButtons = 'acronym';
47 protected $convertToolbarForHtmlAreaArray = array (
48 'acronym' => 'Acronym',
49 );
50 protected $acronymIndex = 0;
51 protected $abbraviationIndex = 0;
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 .'.pathAcronymModule = "../../mod2/acronym.php";
93 RTEarea['.$RTEcounter.'].buttons.'. $button .'.acronymUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', 'acronym_'.$this->htmlAreaRTE->contentLanguageUid, 'js', $this->buildJSAcronymArray($this->htmlAreaRTE->contentLanguageUid)) . '";';
94
95 // <abbr> was not supported by IE before version 7
96 if ($this->htmlAreaRTE->client['BROWSER'] == 'msie' && $this->htmlAreaRTE->client['VERSION'] < 7) {
97 $this->AbbreviationIndex = 0;
98 }
99 $registerRTEinJavascriptString .= '
100 RTEarea['.$RTEcounter.'].buttons.'. $button .'.noAcronym = ' . ($this->acronymIndex ? 'false' : 'true') . ';
101 RTEarea['.$RTEcounter.'].buttons.'. $button .'.noAbbr = ' . ($this->AbbreviationIndex ? 'false' : 'true') . ';';
102 }
103
104 return $registerRTEinJavascriptString;
105 }
106
107 /**
108 * Return an acronym array for the Acronym plugin
109 *
110 * @return string acronym Javascript array
111 */
112 function buildJSAcronymArray($languageUid) {
113 global $TYPO3_CONF_VARS, $TYPO3_DB;
114
115 $button = 'acronym';
116 $PIDList = 0;
117 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$button.'.']) && trim($this->thisConfig['buttons.'][$button.'.']['PIDList'])) {
118 $PIDList = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['buttons.'][$button.'.']['PIDList']));
119 }
120 $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->htmlAreaRTE->ID]['enableCompressedScripts'] ? '' : chr(10);
121 $JSAcronymArray .= 'acronyms = { ' . $linebreak;
122 $JSAbbreviationArray .= 'abbreviations = { ' . $linebreak;
123 $table = 'tx_rtehtmlarea_acronym';
124 if ($languageUid > -1) {
125 $whereClause = '(sys_language_uid=' . $languageUid . ' OR sys_language_uid=-1) ';
126 } else {
127 $whereClause = '1 = 1 ';
128 }
129 $whereClause .= ($PIDList ? ' AND '. $table . '.pid IN (' . $TYPO3_DB->fullQuoteStr($PIDList, $table) . ') ' : '');
130 $whereClause .= t3lib_BEfunc::BEenableFields($table);
131 $whereClause .= t3lib_BEfunc::deleteClause($table);
132 $res = $TYPO3_DB->exec_SELECTquery('type,term,acronym', $table, $whereClause);
133 while($acronymRow = $TYPO3_DB->sql_fetch_assoc($res)) {
134 if( $acronymRow['type'] == 1) $JSAcronymArray .= (($this->acronymIndex++)?',':'') . '"' . $acronymRow['term'] . '":"' . $acronymRow['acronym'] . '"' . $linebreak;
135 if ($acronymRow['type'] == 2) $JSAbbreviationArray .= (($this->AbbreviationIndex++)?',':'') . '"' . $acronymRow['term'] . '":"' . $acronymRow['acronym'] . '"' . $linebreak;
136 }
137 $JSAcronymArray .= '};' . $linebreak;
138 $JSAbbreviationArray .= '};' . $linebreak;
139
140 return $JSAcronymArray . $JSAbbreviationArray;
141 }
142
143 } // end of class
144
145 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Acronym/class.tx_rtehtmlarea_acronym.php']) {
146 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Acronym/class.tx_rtehtmlarea_acronym.php']);
147 }
148
149 ?>