TYPO3 CMS  TYPO3_6-2
BrowseLinks.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  public $editorNo;
32 
33  public $contentTypo3Charset = 'utf-8';
38 
39  public $additionalAttributes = array();
40 
41  public $buttonConfig = array();
42 
43  public $RTEProperties = array();
44 
45  public $anchorTypes = array('page', 'url', 'file', 'mail', 'spec');
46 
47  public $classesAnchorDefault = array();
48 
49  public $classesAnchorDefaultTitle = array();
50 
51  public $classesAnchorClassTitle = array();
52 
53  public $classesAnchorDefaultTarget = array();
54 
55  public $classesAnchorJSOptions = array();
56 
57  protected $defaultLinkTarget;
58 
59  public $allowedItems;
60 
68  public function init() {
69  $this->initVariables();
70  // Create content language service
71  $this->contentLanguageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
72  $this->contentLanguageService->init($this->contentTypo3Language);
73  $this->initConfiguration();
74 
75  $this->initDocumentTemplate();
76 
77  // Initializing hooking browsers
78  $this->initHookObjects('ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php');
79  $this->initCurrentUrl();
80  // Determine nature of current url:
81  $this->act = GeneralUtility::_GP('act');
82  if (!$this->act) {
83  $this->act = $this->curUrlInfo['act'];
84  }
85  // Setting initial values for link attributes
86  $this->initLinkAttributes();
87 
88  // Adding RTE JS code
89  // also unset the default jumpToUrl() function before
90  unset($this->doc->JScodeArray['jumpToUrl']);
91  $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode();
92  }
93 
99  public function initVariables() {
100  parent::initVariables();
101 
102  // Process bparams
103  $pArr = explode('|', $this->bparams);
104  $pRteArr = explode(':', $pArr[1]);
105  $this->editorNo = $pRteArr[0];
106  $this->contentTypo3Language = $pRteArr[1];
107  $this->RTEtsConfigParams = $pArr[2];
108  if (!$this->editorNo) {
109  $this->editorNo = GeneralUtility::_GP('editorNo');
110  $this->contentTypo3Language = GeneralUtility::_GP('contentTypo3Language');
111  $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
112  }
113  $pArr[1] = implode(':', array($this->editorNo, $this->contentTypo3Language, $this->contentTypo3Charset));
114  $pArr[2] = $this->RTEtsConfigParams;
115  $this->bparams = implode('|', $pArr);
116  }
117 
123  public function initConfiguration() {
124  $this->thisConfig = $this->getRTEConfig();
125  $this->buttonConfig = $this->getButtonConfig('link');
126  }
127 
133  protected function initDocumentTemplate() {
134  parent::initDocumentTemplate();
135  $this->doc->getContextMenuCode();
136  // Apply the same styles as those of the base script
137  $this->doc->bodyTagId = 'typo3-browse-links-php';
138  $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
139  // Add attributes to body tag. Note: getBodyTagAdditions will invoke the hooks
140  $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
141  }
142 
148  protected function initCurrentUrl() {
149  // CurrentUrl - the current link url must be passed around if it exists
150  $this->curUrlArray = GeneralUtility::_GP('curUrl');
151  if ($this->curUrlArray['all']) {
152  $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
153  $this->curUrlArray['href'] = htmlspecialchars_decode($this->curUrlArray['href']);
154  }
155  // Note: parseCurUrl will invoke the hooks
156  $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
157  if (isset($this->curUrlArray['data-htmlarea-external']) && $this->curUrlInfo['act'] != 'mail') {
158  $this->curUrlInfo['act'] = 'url';
159  $this->curUrlInfo['info'] = $this->curUrlArray['href'];
160  }
161  }
162 
168  protected function getRTEConfig() {
169  $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
170  $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
171  $this->RTEProperties = $RTEsetup['properties'];
172  return BackendUtility::RTEsetup($this->RTEProperties, $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
173  }
174 
181  protected function getButtonConfig($buttonName) {
182  return is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonName . '.'])
183  ? $this->thisConfig['buttons.'][$buttonName . '.']
184  : array();
185  }
186 
192  protected function initLinkAttributes() {
193  // Initializing the title value
194  $this->setTitle = $this->curUrlArray['title'];
195  // Processing the classes configuration
196  $classSelected = array();
197  if ($this->buttonConfig['properties.']['class.']['allowedClasses']) {
198  $this->setClass = $this->curUrlArray['class'];
199  $classesAnchorArray = GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['class.']['allowedClasses'], TRUE);
200  $classesAnchorConfigArray = array();
201  // Collecting allowed classes and configured default values
202  $classesAnchor = array();
203  $classesAnchor['all'] = array();
204  $titleReadOnly = $this->buttonConfig['properties.']['title.']['readOnly'] || $this->buttonConfig[$this->act . '.']['properties.']['title.']['readOnly'];
205  if (is_array($this->RTEProperties['classesAnchor.'])) {
206  foreach ($this->RTEProperties['classesAnchor.'] as $label => $conf) {
207  if (in_array($conf['class'], $classesAnchorArray)) {
208  $classesAnchor['all'][] = $conf['class'];
209  if (in_array($conf['type'], $this->anchorTypes)) {
210  $classesAnchor[$conf['type']][] = $conf['class'];
211  if ($this->buttonConfig[$conf['type'] . '.']['properties.']['class.']['default'] == $conf['class']) {
212  $this->classesAnchorDefault[$conf['type']] = $conf['class'];
213  if ($conf['titleText']) {
214  $this->classesAnchorDefaultTitle[$conf['type']] = $this->getLLContent(trim($conf['titleText']));
215  }
216  if ($conf['target']) {
217  $this->classesAnchorDefaultTarget[$conf['type']] = trim($conf['target']);
218  }
219  }
220  }
221  if ($titleReadOnly && $conf['titleText']) {
222  $this->classesAnchorClassTitle[$conf['class']] = ($this->classesAnchorDefaultTitle[$conf['type']] = $this->getLLContent(trim($conf['titleText'])));
223  }
224  }
225  }
226  }
227  // Constructing the class selector options
228  foreach ($this->anchorTypes as $anchorType) {
229  foreach ($classesAnchorArray as $class) {
230  if (!in_array($class, $classesAnchor['all']) || in_array($class, $classesAnchor['all']) && is_array($classesAnchor[$anchorType]) && in_array($class, $classesAnchor[$anchorType])) {
231  $selected = '';
232  if ($this->setClass == $class || !$this->setClass && $this->classesAnchorDefault[$anchorType] == $class) {
233  $selected = 'selected="selected"';
234  $classSelected[$anchorType] = TRUE;
235  }
236  $classLabel = is_array($this->RTEProperties['classes.']) && is_array($this->RTEProperties['classes.'][$class . '.']) && $this->RTEProperties['classes.'][$class . '.']['name'] ? $this->getPageConfigLabel($this->RTEProperties['classes.'][$class . '.']['name'], 0) : $class;
237  $classStyle = is_array($this->RTEProperties['classes.']) && is_array($this->RTEProperties['classes.'][$class . '.']) && $this->RTEProperties['classes.'][$class . '.']['value'] ? $this->RTEProperties['classes.'][$class . '.']['value'] : '';
238  $this->classesAnchorJSOptions[$anchorType] .= '<option ' . $selected . ' value="' . htmlspecialchars($class) . '"' . ($classStyle ? ' style="' . htmlspecialchars($classStyle) . '"' : '') . '>' . htmlspecialchars($classLabel) . '</option>';
239  }
240  }
241  if ($this->classesAnchorJSOptions[$anchorType] && !($this->buttonConfig['properties.']['class.']['required'] || $this->buttonConfig[$this->act . '.']['properties.']['class.']['required'])) {
242  $selected = '';
243  if (!$this->setClass && !$this->classesAnchorDefault[$anchorType]) {
244  $selected = 'selected="selected"';
245  }
246  $this->classesAnchorJSOptions[$anchorType] = '<option ' . $selected . ' value=""></option>' . $this->classesAnchorJSOptions[$anchorType];
247  }
248  }
249  }
250  // Initializing the target value
251  // Unset the target if it is set to a value different than default and if no class is selected and the target field is not displayed
252  // In other words, do not forward the target if we changed tab and the target field is not displayed
253  $this->defaultLinkTarget = isset($this->buttonConfig['properties.']['target.']['default']) ? $this->buttonConfig['properties.']['target.']['default'] : '';
254  $this->setTarget = '';
255  if (isset($this->curUrlArray['target']) && !($this->curUrlArray['target'] != $this->defaultLinkTarget && !$classSelected[$this->act] && is_array($this->buttonConfig['targetSelector.']) && $this->buttonConfig['targetSelector.']['disabled'] && is_array($this->buttonConfig['popupSelector.']) && $this->buttonConfig['popupSelector.']['disabled'])) {
256  $this->setTarget = $this->curUrlArray['target'];
257  }
258  if ($this->defaultLinkTarget && !isset($this->curUrlArray['target'])) {
259  $this->setTarget = $this->defaultLinkTarget;
260  }
261  // Initializing additional attributes
262  if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes']) {
263  $addAttributes = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes'], TRUE);
264  foreach ($addAttributes as $attribute) {
265  $this->additionalAttributes[$attribute] = isset($this->curUrlArray[$attribute]) ? $this->curUrlArray[$attribute] : '';
266  }
267  }
268  }
269 
275  public function getBodyTagAdditions() {
276  $bodyTagAdditions = array();
277  // call hook for extra additions
278  foreach ($this->hookObjects as $hookObject) {
279  if (method_exists($hookObject, 'addBodyTagAdditions')) {
280  $bodyTagAdditions = $hookObject->addBodyTagAdditions($bodyTagAdditions);
281  }
282  }
283  return GeneralUtility::implodeAttributes($bodyTagAdditions, TRUE);
284  }
285 
292  public function getJSCode() {
293  // BEGIN accumulation of header JavaScript:
294  $JScode = '';
295  $JScode .= '
296  var plugin = window.parent.RTEarea[' . GeneralUtility::quoteJSvalue($this->editorNo) . '].editor.getPlugin("TYPO3Link");
297  var HTMLArea = window.parent.HTMLArea;
298  var add_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ? '&curUrl[href]=' . rawurlencode($this->curUrlArray['href']) : '') . ';
299  var add_target=' . GeneralUtility::quoteJSvalue($this->setTarget ? '&curUrl[target]=' . rawurlencode($this->setTarget) : '') . ';
300  var add_class=' . GeneralUtility::quoteJSvalue($this->setClass ? '&curUrl[class]=' . rawurlencode($this->setClass) : '') . ';
301  var add_title=' . GeneralUtility::quoteJSvalue($this->setTitle ? '&curUrl[title]=' . rawurlencode($this->setTitle) : '') . ';
302  var add_params=' . GeneralUtility::quoteJSvalue($this->bparams ? '&bparams=' . rawurlencode($this->bparams) : '') . ';
303  var additionalValues = ' . (count($this->additionalAttributes) ? json_encode($this->additionalAttributes, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) : '{}') . ';';
304  // Attributes setting functions
305  $JScode .= '
306  var cur_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ? ($this->curUrlInfo['query'] ? substr($this->curUrlArray['href'], 0, -strlen($this->curUrlInfo['query'])) : $this->curUrlArray['href']) : '') . ';
307  var cur_target=' . GeneralUtility::quoteJSvalue($this->setTarget ?: '') . ';
308  var cur_class=' . GeneralUtility::quoteJSvalue($this->setClass ?: '') . ';
309  var cur_title=' . GeneralUtility::quoteJSvalue($this->setTitle ?: '') . ';
310 
311  function browse_links_setTarget(value) {
312  cur_target=value;
313  add_target="&curUrl[target]="+encodeURIComponent(value);
314  }
315  function browse_links_setClass(value) {
316  cur_class=value;
317  add_class="&curUrl[class]="+encodeURIComponent(value);
318  }
319  function browse_links_setTitle(value) {
320  cur_title=value;
321  add_title="&curUrl[title]="+encodeURIComponent(value);
322  }
323  function browse_links_setHref(value) {
324  cur_href=value;
325  add_href="&curUrl[href]="+value;
326  }
327  function browse_links_setAdditionalValue(name, value) {
328  additionalValues[name] = value;
329  }
330  ';
331  // Link setting functions
332  $JScode .= '
333  function link_typo3Page(id,anchor) {
334  var parameters = (document.ltargetform.query_parameters && document.ltargetform.query_parameters.value) ? (document.ltargetform.query_parameters.value.charAt(0) == "&" ? "" : "&") + document.ltargetform.query_parameters.value : "";
335  var theLink = ' . GeneralUtility::quoteJSvalue($this->siteURL . '?id=') . ' + id + parameters + (anchor ? anchor : "");
336  if (document.ltargetform.anchor_title) browse_links_setTitle(document.ltargetform.anchor_title.value);
337  if (document.ltargetform.anchor_class) browse_links_setClass(document.ltargetform.anchor_class.value);
338  if (document.ltargetform.ltarget) browse_links_setTarget(document.ltargetform.ltarget.value);
339  if (document.ltargetform.lrel) browse_links_setAdditionalValue("rel", document.ltargetform.lrel.value);
340  browse_links_setAdditionalValue("data-htmlarea-external", "");
341  plugin.createLink(theLink,cur_target,cur_class,cur_title,additionalValues);
342  return false;
343  }
344  function link_folder(folder) {
345  if (folder && folder.substr(0, 5) == "file:") {
346  var theLink = ' . GeneralUtility::quoteJSvalue($this->siteURL . '?file:') . ' + encodeURIComponent(folder.substr(5));
347  } else {
348  var theLink = ' . GeneralUtility::quoteJSvalue($this->siteURL . '?') . ' + folder;
349  }
350  if (document.ltargetform.anchor_title) browse_links_setTitle(document.ltargetform.anchor_title.value);
351  if (document.ltargetform.anchor_class) browse_links_setClass(document.ltargetform.anchor_class.value);
352  if (document.ltargetform.ltarget) browse_links_setTarget(document.ltargetform.ltarget.value);
353  if (document.ltargetform.lrel) browse_links_setAdditionalValue("rel", document.ltargetform.lrel.value);
354  browse_links_setAdditionalValue("data-htmlarea-external", "");
355  plugin.createLink(theLink,cur_target,cur_class,cur_title,additionalValues);
356  return false;
357  }
358  function link_spec(theLink) {
359  if (document.ltargetform.anchor_title) browse_links_setTitle(document.ltargetform.anchor_title.value);
360  if (document.ltargetform.anchor_class) browse_links_setClass(document.ltargetform.anchor_class.value);
361  if (document.ltargetform.ltarget) browse_links_setTarget(document.ltargetform.ltarget.value);
362  browse_links_setAdditionalValue("data-htmlarea-external", "");
363  plugin.createLink(theLink,cur_target,cur_class,cur_title,additionalValues);
364  return false;
365  }
366  function link_current() {
367  var parameters = (document.ltargetform.query_parameters && document.ltargetform.query_parameters.value) ? (document.ltargetform.query_parameters.value.charAt(0) == "&" ? "" : "&") + document.ltargetform.query_parameters.value : "";
368  if (document.ltargetform.anchor_title) browse_links_setTitle(document.ltargetform.anchor_title.value);
369  if (document.ltargetform.anchor_class) browse_links_setClass(document.ltargetform.anchor_class.value);
370  if (document.ltargetform.ltarget) browse_links_setTarget(document.ltargetform.ltarget.value);
371  if (document.ltargetform.lrel) browse_links_setAdditionalValue("rel", document.ltargetform.lrel.value);
372  if (cur_href!="http://" && cur_href!="mailto:") {
373  plugin.createLink(cur_href + parameters,cur_target,cur_class,cur_title,additionalValues);
374  }
375  return false;
376  }
377  ';
378  // General "jumpToUrl" and launchView functions:
379  $JScode .= '
380  function jumpToUrl(URL,anchor) {
381  if (URL.charAt(0) === \'?\') {
382  URL = ' . GeneralUtility::quoteJSvalue($this->getThisScript()) . ' + URL.substring(1);
383  }
384  var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo=" + ' . GeneralUtility::quoteJSvalue(rawurlencode($this->editorNo)) . ' : "";
385  var add_contentTypo3Language = URL.indexOf("contentTypo3Language=")==-1 ? "&contentTypo3Language=" + ' . GeneralUtility::quoteJSvalue(rawurlencode($this->contentTypo3Language)) . ' : "";
386  var add_act = URL.indexOf("act=")==-1 ? "&act=" + ' . GeneralUtility::quoteJSvalue(rawurlencode($this->act)) . ' : "";
387  var add_mode = URL.indexOf("mode=")==-1 ? "&mode=" + ' . GeneralUtility::quoteJSvalue(rawurlencode($this->mode)) . ' : "";
388  var add_additionalValues = "";
389  if (plugin.pageTSConfiguration && plugin.pageTSConfiguration.additionalAttributes) {
390  var additionalAttributes = plugin.pageTSConfiguration.additionalAttributes.split(",");
391  for (var i = additionalAttributes.length; --i >= 0;) {
392  if (additionalValues[additionalAttributes[i]] != "") {
393  add_additionalValues += "&curUrl[" + additionalAttributes[i] + "]=" + encodeURIComponent(additionalValues[additionalAttributes[i]]);
394  }
395  }
396  }
397  var theLocation = URL+add_act+add_editorNo+add_contentTypo3Language+add_mode+add_href+add_target+add_class+add_title+add_additionalValues+add_params+(anchor?anchor:"");
398  window.location.href = theLocation;
399  return false;
400  }
401  function launchView(url) {
402  var thePreviewWindow="";
403  thePreviewWindow = window.open("' . $GLOBALS['BACK_PATH'] . 'show_item.php?table="+url,"ShowItem","height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
404  if (thePreviewWindow && thePreviewWindow.focus) {
405  thePreviewWindow.focus();
406  }
407  }
408  ';
409  // Hook to overwrite or extend javascript functions
410  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['extendJScode']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['extendJScode'])) {
411  $conf = array();
412  $_params = array(
413  'conf' => &$conf
414  );
415  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['extendJScode'] as $objRef) {
416  $processor =& GeneralUtility::getUserObj($objRef);
417  $JScode .= $processor->extendJScode($_params, $this);
418  }
419  }
420  return $JScode;
421  }
422 
423  /******************************************************************
424  *
425  * Main functions
426  *
427  ******************************************************************/
437  public function main_rte($wiz = 0) {
438  // Starting content:
439  $content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert/Modify Link', TRUE));
440  // Default allowed values
441  $this->allowedItems = explode(',', 'page,file,folder,url,mail,spec');
442  // Calling hook for extra options
443  foreach ($this->hookObjects as $hookObject) {
444  $this->allowedItems = $hookObject->addAllowedItems($this->allowedItems);
445  }
446  // Removing items as per configuration
447  if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
448  $this->allowedItems = array_diff($this->allowedItems, GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['removeItems'], TRUE));
449  }
450  reset($this->allowedItems);
451  if (!in_array($this->act, $this->allowedItems)) {
452  $this->act = current($this->allowedItems);
453  }
454  // Making menu in top:
455  $menuDef = array();
456  if (!$wiz && $this->curUrlArray['href']) {
457  $menuDef['removeLink']['isActive'] = $this->act == 'removeLink';
458  $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink', TRUE);
459  $menuDef['removeLink']['url'] = '#';
460  $menuDef['removeLink']['addParams'] = 'onclick="plugin.unLink();return false;"';
461  }
462  if (in_array('page', $this->allowedItems)) {
463  $menuDef['page']['isActive'] = $this->act == 'page';
464  $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
465  $menuDef['page']['url'] = '#';
466  $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=page&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
467  }
468  if (in_array('file', $this->allowedItems)) {
469  $menuDef['file']['isActive'] = $this->act == 'file';
470  $menuDef['file']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:file', TRUE);
471  $menuDef['file']['url'] = '#';
472  $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=file&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
473  }
474  if (in_array('folder', $this->allowedItems)) {
475  $menuDef['folder']['isActive'] = $this->act == 'folder';
476  $menuDef['folder']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:folder', TRUE);
477  $menuDef['folder']['url'] = '#';
478  $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=folder&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
479  }
480  if (in_array('url', $this->allowedItems)) {
481  $menuDef['url']['isActive'] = $this->act == 'url';
482  $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
483  $menuDef['url']['url'] = '#';
484  $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=url&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
485  }
486  if (in_array('mail', $this->allowedItems)) {
487  $menuDef['mail']['isActive'] = $this->act == 'mail';
488  $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
489  $menuDef['mail']['url'] = '#';
490  $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=mail&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
491  }
492  if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $this->allowedItems)) {
493  $menuDef['spec']['isActive'] = $this->act == 'spec';
494  $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
495  $menuDef['spec']['url'] = '#';
496  $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=spec&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
497  }
498  // call hook for extra options
499  foreach ($this->hookObjects as $hookObject) {
500  $menuDef = $hookObject->modifyMenuDefinition($menuDef);
501  }
502  $content .= $this->doc->getTabMenuRaw($menuDef);
503  // Adding the menu and header to the top of page:
504  $content .= $this->printCurrentUrl($this->curUrlInfo['info']) . '<br />';
505  // Depending on the current action we will create the actual module content for selecting a link:
506  switch ($this->act) {
507  case 'mail':
508  $extUrl = '
509  <!--
510  Enter mail address:
511  -->
512  <tr>
513  <td><label>' . $GLOBALS['LANG']->getLL('emailAddress', TRUE) . ':</label></td>
514  <td><input type="text" name="lemail"' . $this->doc->formWidth(20) . ' value="' . htmlspecialchars(($this->curUrlInfo['act'] == 'mail' ? $this->curUrlInfo['info'] : '')) . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE) . '" onclick="browse_links_setTarget(\'\');browse_links_setHref(\'mailto:\'+document.ltargetform.lemail.value);browse_links_setAdditionalValue(\'data-htmlarea-external\', \'\');return link_current();" /></td>
515  </tr>';
516  //$content .= $extUrl;
517  $content .= $this->addAttributesForm($extUrl);
518  break;
519  case 'url':
520  $extUrl = '
521  <!--
522  Enter External URL:
523  -->
524  <tr>
525  <td><label>URL:</label></td>
526  <td colspan="3"><input type="text" name="lurl"' . $this->doc->formWidth(20) . ' value="' . htmlspecialchars(($this->curUrlInfo['act'] == 'url' ? $this->curUrlInfo['info'] : 'http://')) . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE) . '" onclick="if (/^[A-Za-z0-9_+]{1,8}:/.test(document.ltargetform.lurl.value)) { browse_links_setHref(document.ltargetform.lurl.value); } else { browse_links_setHref(\'http://\'+document.ltargetform.lurl.value); }; browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); return link_current();" /></td>
527  </tr>';
528  $content .= $this->addAttributesForm($extUrl);
529  break;
530  case 'file':
531  case 'folder':
532  $content .= $this->addAttributesForm();
533  // Create folder tree:
534  $this->doc->JScode .= $this->doc->wrapScriptTags('
535  Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
536  ');
537  $foldertree = GeneralUtility::makeInstance('TYPO3\\CMS\\Rtehtmlarea\\FolderTree');
538  $foldertree->thisScript = $this->thisScript;
539  $tree = $foldertree->getBrowsableTree();
540  if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
541  $cmpPath = '';
542  } else {
543  $cmpPath = $this->curUrlInfo['value'];
544  if (!isset($this->expandFolder)) {
545  $this->expandFolder = $cmpPath;
546  }
547  }
548  // Get the selected folder
549  $selectedFolder = FALSE;
550  if ($this->expandFolder) {
551  try {
552  $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
553  } catch (\Exception $e) {
554  // No path is selected
555  }
556  if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
557  // It's a folder
558  $selectedFolder = $fileOrFolderObject;
559  } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
560  // It's a file
561  try {
562  $selectedFolder = $fileOrFolderObject->getParentFolder();
563  } catch (\Exception $e) {
564  // Accessing the parent folder failed for some reason. e.g. permissions
565  }
566  }
567  }
568  // If no folder is selected, get the user's default upload folder
569  if (!$selectedFolder) {
570  try {
571  $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
572  } catch (\Exception $e) {
573  // The configured default user folder does not exist
574  }
575  }
576  // Build the file upload and folder creation forms
577  $uploadForm = '';
578  $createFolder = '';
579  if ($selectedFolder) {
580  $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
581  $createFolder = $this->createFolder($selectedFolder);
582  }
583  // Insert the upload form on top, if so configured
584  if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
585  $content .= $uploadForm;
586  }
587  // Render the filelist if there is a folder selected
588  if ($selectedFolder) {
589  $files = $this->expandFolder($selectedFolder, $this->P['params']['allowedExtensions']);
590  }
591  $content .= '
592 
593  <!--
594  Wrapper table for folder tree / file/folder list:
595  -->
596  <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
597  <tr>
598  <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
599  <td class="c-wCell" valign="top">' . $files . '</td>
600  </tr>
601  </table>
602  ';
603  // Adding create folder + upload form if applicable
604  if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
605  $content .= $uploadForm;
606  }
607  $content .= '<br />';
608  $content .= $createFolder;
609  $content .= '<br />';
610  break;
611  case 'spec':
612  if (is_array($this->thisConfig['userLinks.'])) {
613  $subcats = array();
614  $v = $this->thisConfig['userLinks.'];
615  foreach ($v as $k2 => $dummyValue) {
616  $k2i = (int)$k2;
617  if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
618  // Title:
619  $title = trim($v[$k2i]);
620  if (!$title) {
621  $title = $v[$k2i . '.']['url'];
622  } else {
623  $title = $GLOBALS['LANG']->sL($title);
624  }
625  // Description:
626  $description = $v[$k2i . '.']['description'] ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />' : '';
627  // URL + onclick event:
628  $onClickEvent = '';
629  if (isset($v[$k2i . '.']['target'])) {
630  $onClickEvent .= 'browse_links_setTarget(' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['target']) . ');';
631  }
632  $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
633  if (substr($v[$k2i . '.']['url'], 0, 7) == 'http://' || substr($v[$k2i . '.']['url'], 0, 7) == 'mailto:') {
634  $onClickEvent .= 'cur_href=' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['url']) . ';link_current();';
635  } else {
636  $onClickEvent .= 'link_spec(' . GeneralUtility::quoteJSvalue($this->siteURL . $v[($k2i . '.')]['url']) . ');';
637  }
638  // Link:
639  $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
640  // Adding link to menu of user defined links:
641  $subcats[$k2i] = '
642  <tr>
643  <td class="bgColor4">' . $A[0] . '<strong>' . htmlspecialchars($title) . ($this->curUrlInfo['info'] == $v[$k2i . '.']['url'] ? '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_right.gif', 'width="5" height="9"') . ' class="c-blinkArrowR" alt="" />' : '') . '</strong><br />' . $description . $A[1] . '</td>
644  </tr>';
645  }
646  }
647  // Sort by keys:
648  ksort($subcats);
649  // Add menu to content:
650  $content .= '
651  <!--
652  Special userdefined menu:
653  -->
654  <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
655  <tr>
656  <td class="bgColor5 c-wCell" valign="top"><strong>' . $GLOBALS['LANG']->getLL('special', TRUE) . '</strong></td>
657  </tr>
658  ' . implode('', $subcats) . '
659  </table>
660  ';
661  }
662  break;
663  case 'page':
664  $content .= $this->addAttributesForm();
665  $pagetree = GeneralUtility::makeInstance('TYPO3\\CMS\\Rtehtmlarea\\PageTree');
666  $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
667  $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
668  $pagetree->addField('nav_title');
669  $tree = $pagetree->getBrowsableTree();
670  $cElements = $this->expandPage();
671  $dbmount = $this->getTemporaryTreeMountCancelNotice();
672  $content .= '
673  <!--
674  Wrapper table for page tree / record list:
675  -->
676  <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
677  <tr>
678  <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $dbmount . $tree . '</td>
679  <td class="c-wCell" valign="top">' . $cElements . '</td>
680  </tr>
681  </table>
682  ';
683  break;
684  default:
685  // call hook
686  foreach ($this->hookObjects as $hookObject) {
687  $content .= $hookObject->getTab($this->act);
688  }
689  }
690  // End page, return content:
691  $content .= $this->doc->endPage();
692  $content = $this->doc->insertStylesAndJS($content);
693  return $content;
694  }
695 
702  public function addAttributesForm($rows = '') {
703  $ltargetForm = '';
704  $additionalAttributeFields = '';
705  // Add page id, target, class selector box, title and parameters fields:
706  $lpageId = $this->addPageIdSelector();
707  $queryParameters = $this->addQueryParametersSelector();
708  $ltarget = $this->addTargetSelector();
709  $lclass = $this->addClassSelector();
710  $ltitle = $this->addTitleSelector();
711  $rel = $this->addRelField();
712  // additional fields for links
713  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['addAttributeFields']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['addAttributeFields'])) {
714  $conf = array();
715  $_params = array(
716  'conf' => &$conf
717  );
718  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['addAttributeFields'] as $objRef) {
719  $processor =& GeneralUtility::getUserObj($objRef);
720  $additionalAttributeFields .= $processor->getAttributefields($_params, $this);
721  }
722  }
723  if ($rows || $lpageId || $queryParameters || $lclass || $ltitle || $ltarget || $rel) {
724  $ltargetForm = $this->wrapInForm($rows . $lpageId . $queryParameters . $lclass . $ltitle . $ltarget . $rel . $additionalAttributeFields);
725  }
726  return $ltargetForm;
727  }
728 
732  public function wrapInForm($string) {
733  $form = '
734  <!--
735  Selecting target for link:
736  -->
737  <form action="" name="ltargetform" id="ltargetform">
738  <table id="typo3-linkTarget" class="htmlarea-window-table">' . $string;
739  if ($this->act == $this->curUrlInfo['act'] && $this->act != 'mail' && $this->curUrlArray['href']) {
740  $form .= '
741  <tr>
742  <td>
743  </td>
744  <td colspan="3">
745  <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', TRUE) . '" onclick="' . ($this->act == 'url' ? 'browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); ' : '') . 'return link_current();" />
746  </td>
747  </tr>';
748  }
749  $form .= '
750  </table>
751  </form>';
752  return $form;
753  }
754 
758  public function addPageIdSelector() {
759  return $this->act == 'page' && $this->buttonConfig && is_array($this->buttonConfig['pageIdSelector.']) && $this->buttonConfig['pageIdSelector.']['enabled'] ? '
760  <tr>
761  <td><label>' . $GLOBALS['LANG']->getLL('page_id', TRUE) . ':</label></td>
762  <td colspan="3">
763  <input type="text" size="6" name="luid" />&nbsp;<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE) . '" onclick="return link_typo3Page(document.ltargetform.luid.value);" />
764  </td>
765  </tr>' : '';
766  }
767 
771  public function addRelField() {
772  return ($this->act == 'page' || $this->act == 'url' || $this->act == 'file') && $this->buttonConfig && is_array($this->buttonConfig['relAttribute.']) && $this->buttonConfig['relAttribute.']['enabled'] ? '
773  <tr>
774  <td><label>' . $GLOBALS['LANG']->getLL('linkRelationship', TRUE) . ':</label></td>
775  <td colspan="3">
776  <input type="text" name="lrel" value="' . htmlspecialchars($this->additionalAttributes['rel']) . '" ' . $this->doc->formWidth(30) . ' />
777  </td>
778  </tr>' : '';
779  }
780 
784  public function addQueryParametersSelector() {
785  return $this->act == 'page' && $this->buttonConfig && is_array($this->buttonConfig['queryParametersSelector.']) && $this->buttonConfig['queryParametersSelector.']['enabled'] ? '
786  <tr>
787  <td><label>' . $GLOBALS['LANG']->getLL('query_parameters', TRUE) . ':</label></td>
788  <td colspan="3">
789  <input type="text" name="query_parameters" value="' . ($this->curUrlInfo['query'] ? htmlspecialchars($this->curUrlInfo['query']) : '') . '" ' . $this->doc->formWidth(30) . ' />
790  </td>
791  </tr>' : '';
792  }
793 
797  public function addTargetSelector() {
798  $targetSelectorConfig = array();
799  $popupSelectorConfig = array();
800  if (is_array($this->buttonConfig['targetSelector.'])) {
801  $targetSelectorConfig = $this->buttonConfig['targetSelector.'];
802  }
803  if (is_array($this->buttonConfig['popupSelector.'])) {
804  $popupSelectorConfig = $this->buttonConfig['popupSelector.'];
805  }
806  $ltarget = '';
807  if ($this->act != 'mail') {
808  $ltarget .= '
809  <tr id="ltargetrow"' . ($targetSelectorConfig['disabled'] && $popupSelectorConfig['disabled'] ? ' style="display: none;"' : '') . '>
810  <td><label>' . $GLOBALS['LANG']->getLL('target', TRUE) . ':</label></td>
811  <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="' . htmlspecialchars(($this->setTarget ? $this->setTarget : ($this->setClass || !$this->classesAnchorDefault[$this->act] ? '' : $this->classesAnchorDefaultTarget[$this->act]))) . '"' . $this->doc->formWidth(10) . ' /></td>';
812  $ltarget .= '
813  <td colspan="2">';
814  if (!$targetSelectorConfig['disabled']) {
815  $ltarget .= '
816  <select name="ltarget_type" onchange="browse_links_setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
817  <option></option>
818  <option value="_top">' . $GLOBALS['LANG']->getLL('top', TRUE) . '</option>
819  <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', TRUE) . '</option>
820  </select>';
821  }
822  $ltarget .= '
823  </td>
824  </tr>';
825  if (!$popupSelectorConfig['disabled']) {
826  $selectJS = 'if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0 && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0) {
827  document.ltargetform.ltarget.value = document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value+\'x\'+document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value;
828  browse_links_setTarget(document.ltargetform.ltarget.value);
829  document.ltargetform.popup_width.selectedIndex=0;
830  document.ltargetform.popup_height.selectedIndex=0;
831  }';
832  $ltarget .= '
833  <tr>
834  <td><label>' . $GLOBALS['LANG']->getLL('target_popUpWindow', TRUE) . ':</label></td>
835  <td colspan="3">
836  <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
837  <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', TRUE) . '</option>
838  <option value="300">300</option>
839  <option value="400">400</option>
840  <option value="500">500</option>
841  <option value="600">600</option>
842  <option value="700">700</option>
843  <option value="800">800</option>
844  </select>
845  x
846  <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
847  <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', TRUE) . '</option>
848  <option value="200">200</option>
849  <option value="300">300</option>
850  <option value="400">400</option>
851  <option value="500">500</option>
852  <option value="600">600</option>
853  </select>
854  </td>
855  </tr>';
856  }
857  }
858  return $ltarget;
859  }
860 
866  public function addClassSelector() {
867  $selectClass = '';
868  if ($this->classesAnchorJSOptions[$this->act]) {
869  $selectClass = '
870  <tr>
871  <td><label>' . $GLOBALS['LANG']->getLL('anchor_class', TRUE) . ':</label></td>
872  <td colspan="3">
873  <select name="anchor_class" onchange="' . htmlspecialchars($this->getClassOnChangeJS()) . '">
874  ' . $this->classesAnchorJSOptions[$this->act] . '
875  </select>
876  </td>
877  </tr>';
878  }
879  return $selectClass;
880  }
881 
887  public function getClassOnChangeJS() {
888  return '
889  if (document.ltargetform.anchor_class) {
890  document.ltargetform.anchor_class.value = document.ltargetform.anchor_class.options[document.ltargetform.anchor_class.selectedIndex].value;
891  if (document.ltargetform.anchor_class.value && HTMLArea.classesAnchorSetup) {
892  for (var i = HTMLArea.classesAnchorSetup.length; --i >= 0;) {
893  var anchorClass = HTMLArea.classesAnchorSetup[i];
894  if (anchorClass[\'name\'] == document.ltargetform.anchor_class.value) {
895  if (anchorClass[\'titleText\'] && document.ltargetform.anchor_title) {
896  document.ltargetform.anchor_title.value = anchorClass[\'titleText\'];
897  document.getElementById(\'rtehtmlarea-browse-links-title-readonly\').innerHTML = anchorClass[\'titleText\'];
898  browse_links_setTitle(anchorClass[\'titleText\']);
899  }
900  if (anchorClass[\'target\']) {
901  if (document.ltargetform.ltarget) {
902  document.ltargetform.ltarget.value = anchorClass[\'target\'];
903  }
904  browse_links_setTarget(anchorClass[\'target\']);
905  } else if (document.ltargetform.ltarget && document.getElementById(\'ltargetrow\').style.display == \'none\') {
906  // Reset target to default if field is not displayed and class has no configured target
907  document.ltargetform.ltarget.value = ' . ($this->defaultLinkTarget ? GeneralUtility::quoteJSvalue($this->defaultLinkTarget) : '""') . ';
908  browse_links_setTarget(document.ltargetform.ltarget.value);
909  }
910  break;
911  }
912  }
913  }
914  browse_links_setClass(document.ltargetform.anchor_class.value);
915  }
916  ';
917  }
918 
922  public function addTitleSelector() {
923  $title = $this->setTitle ?: ($this->setClass || !$this->classesAnchorDefault[$this->act] ? '' : $this->classesAnchorDefaultTitle[$this->act]);
924  $readOnly = $this->buttonConfig['properties.']['title.']['readOnly'] || $this->buttonConfig[$this->act . '.']['properties.']['title.']['readOnly'];
925  if ($readOnly) {
926  $title = $this->setClass ? $this->classesAnchorClassTitle[$this->setClass] : $this->classesAnchorDefaultTitle[$this->act];
927  }
928  return '
929  <tr>
930  <td><label for="rtehtmlarea-browse-links-anchor_title" id="rtehtmlarea-browse-links-title-label">' . $GLOBALS['LANG']->getLL('anchor_title', TRUE) . ':</label></td>
931  <td colspan="3">
932  <span id="rtehtmlarea-browse-links-title-input" style="display: ' . ($readOnly ? 'none' : 'inline') . ';">
933  <input type="text" id="rtehtmlarea-browse-links-anchor_title" name="anchor_title" value="' . htmlspecialchars($title) . '" ' . $this->doc->formWidth(30) . ' />
934  </span>
935  <span id="rtehtmlarea-browse-links-title-readonly" style="display: ' . ($readOnly ? 'inline' : 'none') . ';">' . htmlspecialchars($title) . '</span>
936  </td>
937  </tr>';
938  }
939 
946  public function getLLContent($string) {
947  return $this->contentLanguageService->sL($string);
948  }
949 
957  public function getPageConfigLabel($string, $JScharCode = 1) {
958  if (substr($string, 0, 4) !== 'LLL:') {
959  $label = $string;
960  } else {
961  $label = $GLOBALS['LANG']->sL(trim($string));
962  }
963  $label = str_replace('"', '\\"', str_replace('\\\'', '\'', $label));
964  $label = $JScharCode ? GeneralUtility::quoteJSvalue($label) : $label;
965  return $label;
966  }
967 
968 }
static implodeAttributes(array $arr, $xhtmlSafe=FALSE, $dontOmitBlankAttribs=FALSE)
static skinImg($backPath, $src, $wHattribs='', $outputMode=0)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static RTEsetup($RTEprop, $table, $field, $type='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getPagesTSconfig($id, $rootLine=NULL, $returnPartArray=FALSE)
expandFolder(Folder $folder, $extensionList='')