TYPO3 CMS  TYPO3_6-2
Acronym.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
26  protected $extensionKey = 'rtehtmlarea';
27 
28  // The key of the extension that is extending htmlArea RTE
29  protected $pluginName = 'Acronym';
30 
31  // The name of the plugin registered by the extension
33 
34  // Path to this main locallang file of the extension relative to the extension dir.
35  protected $relativePathToSkin = 'extensions/Acronym/skin/htmlarea.css';
36 
37  // Path to the skin (css) file relative to the extension dir
38  protected $htmlAreaRTE;
39 
40  // Reference to the invoking object
41  protected $thisConfig;
42 
43  // Reference to RTE PageTSConfig
44  protected $toolbar;
45 
46  // Reference to RTE toolbar array
47  protected $LOCAL_LANG;
48 
49  // Frontend language array
50  protected $pluginButtons = 'acronym';
51 
53  'acronym' => 'Acronym'
54  );
55 
56  protected $acronymIndex = 0;
57 
58  protected $abbreviationIndex = 0;
59 
60  public function main($parentObject) {
61  return parent::main($parentObject) && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables');
62  }
63 
70  public function transformContent($content) {
71  // <abbr> was not supported by IE before verison 7
72  if ($this->htmlAreaRTE->client['browser'] == 'msie' && $this->htmlAreaRTE->client['version'] < 7) {
73  // change <abbr> to <acronym>
74  $content = preg_replace('/<(\\/?)abbr/i', '<$1acronym', $content);
75  }
76  return $content;
77  }
78 
85  public function buildJavascriptConfiguration($RTEcounter) {
86  $registerRTEinJavascriptString = '';
87  $button = 'acronym';
88  if (in_array($button, $this->toolbar)) {
89  if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
90  $registerRTEinJavascriptString .= '
91  RTEarea[' . $RTEcounter . ']["buttons"]["' . $button . '"] = new Object();';
92  }
93  $registerRTEinJavascriptString .= '
94  RTEarea[' . $RTEcounter . '].buttons.' . $button . '.acronymUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', ('acronym_' . $this->htmlAreaRTE->contentLanguageUid), 'js', $this->buildJSAcronymArray($this->htmlAreaRTE->contentLanguageUid)) . '";';
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  return $registerRTEinJavascriptString;
104  }
105 
112  public function buildJSAcronymArray($languageUid) {
113  $button = 'acronym';
114  $acronymArray = array();
115  $abbrArray = array();
116  $tableA = 'tx_rtehtmlarea_acronym';
117  $tableB = 'static_languages';
118  $fields = $tableA . '.type,' . $tableA . '.term,' . $tableA . '.acronym,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2';
119  $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
120  $whereClause = '1=1';
121  $loadRecordsFromDatabase = TRUE;
122  // Get all abbreviations 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(\TYPO3\CMS\Core\Utility\GeneralUtility::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']) ? (int)$this->thisConfig['buttons.'][$button . '.']['recursive'] : 0;
135  if (trim($this->thisConfig['buttons.'][$button . '.']['pages'])) {
136  $pids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->thisConfig['buttons.'][$button . '.']['pages'], TRUE);
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 = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
151  $pageTree = '';
152  $pageTreePrefix = '';
153  foreach ($pids as $key => $val) {
154  if ($pageTree) {
155  $pageTreePrefix = ',';
156  }
157  $pageTree .= $pageTreePrefix . $queryGenerator->getTreeList($val, $recursive, ($begin = 0), $perms_clause);
158  }
159 
160  if ($pageTree !== '') {
161  $whereClause .= ' AND ' . $tableA . '.pid IN (' . $pageTree . ')';
162  } else {
163  // If page tree is empty the user does not have access to any pages / acronyms.
164  // This is why we do not try do read any records from the database.
165  $loadRecordsFromDatabase = FALSE;
166  }
167  }
168 
169  if ($loadRecordsFromDatabase) {
170  // Restrict to abbreviations applicable to the language of current content element
171  if ($this->htmlAreaRTE->contentLanguageUid > -1) {
172  $whereClause .= ' AND (' . $tableA . '.sys_language_uid=' . $this->htmlAreaRTE->contentLanguageUid . ' OR ' . $tableA . '.sys_language_uid=-1) ';
173  }
174  // Restrict to abbreviations in certain languages
175  if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
176  $languageList = implode('\',\'', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $tableB)));
177  $whereClause .= ' AND ' . $tableB . '.lg_iso_2 IN (' . $languageList . ') ';
178  }
179  $whereClause .= BackendUtility::BEenableFields($tableA);
180  $whereClause .= BackendUtility::deleteClause($tableA);
181  $whereClause .= BackendUtility::BEenableFields($tableB);
182  $whereClause .= BackendUtility::deleteClause($tableB);
183  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $tableAB, $whereClause);
184  while ($abbreviationRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
185  $item = array('term' => $abbreviationRow['term'], 'abbr' => $abbreviationRow['acronym'], 'language' => strtolower($abbreviationRow['lg_iso_2']) . ($abbreviationRow['lg_country_iso_2'] ? '-' . $abbreviationRow['lg_country_iso_2'] : ''));
186  if ($abbreviationRow['type'] == 1) {
187  $acronymArray[] = $item;
188  } elseif ($abbreviationRow['type'] == 2) {
189  $abbrArray[] = $item;
190  }
191  }
192  }
193 
194  $this->acronymIndex = count($acronymArray);
195  $this->abbreviationIndex = count($abbrArray);
196  return json_encode(array('abbr' => $abbrArray, 'acronym' => $acronymArray));
197  }
198 
199 }
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
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'][]
static deleteClause($table, $tableAlias='')