PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/rtehtmlarea/mod3/class.tx_rtehtmlarea_dam_browse_links.php

https://github.com/foxsoft/typo3v4core
PHP | 944 lines | 709 code | 85 blank | 150 comment | 118 complexity | 21624f3a0037323003e4bc6db82c3d85 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * (c) 2005-2010 Stanislas Rolland <typo3(arobas)sjbr.ca>
  7. * All rights reserved
  8. *
  9. * This script is part of the TYPO3 project. The TYPO3 project is
  10. * free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * The GNU General Public License can be found at
  16. * http://www.gnu.org/copyleft/gpl.html.
  17. * A copy is found in the textfile GPL.txt and important notices to the license
  18. * from the author is found in LICENSE.txt distributed with these scripts.
  19. *
  20. *
  21. * This script is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * This copyright notice MUST APPEAR in all copies of the script!
  27. ***************************************************************/
  28. /**
  29. * Displays the page/file tree for browsing database records or files.
  30. * Used from TCEFORMS an other elements
  31. * In other words: This is the ELEMENT BROWSER!
  32. *
  33. * Adapted for htmlArea RTE by Stanislas Rolland
  34. *
  35. * TYPO3 SVN ID: $Id$
  36. *
  37. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  38. * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
  39. */
  40. require_once(t3lib_extMgm::extPath('dam').'class.tx_dam_browse_media.php');
  41. /**
  42. * Script class for the Element Browser window.
  43. *
  44. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  45. * @package TYPO3
  46. * @subpackage core
  47. */
  48. class tx_rtehtmlarea_dam_browse_links extends tx_dam_browse_media {
  49. // Internal, static:
  50. var $setTarget; // Target (RTE specific)
  51. var $setClass; // Class (RTE specific)
  52. var $setTitle; // Title (RTE specific)
  53. var $contentTypo3Language;
  54. var $contentTypo3Charset;
  55. var $editorNo;
  56. var $buttonConfig = array();
  57. protected $classesAnchorDefault = array();
  58. protected $classesAnchorDefaultTitle = array();
  59. protected $classesAnchorDefaultTarget = array();
  60. protected $classesAnchorJSOptions = array();
  61. public $allowedItems;
  62. /**
  63. * Check if this object should be rendered.
  64. *
  65. * @param string $type Type: "file", ...
  66. * @param object $pObj Parent object.
  67. * @return boolean
  68. * @see SC_browse_links::main()
  69. */
  70. function isValid($type, $pObj) {
  71. $isValid = false;
  72. $pArr = explode('|', t3lib_div::_GP('bparams'));
  73. if ($type=='rte' && $pObj->button == 'link') {
  74. $isValid = true;
  75. }
  76. return $isValid;
  77. }
  78. /**
  79. * Rendering
  80. * Called in SC_browse_links::main() when isValid() returns true;
  81. *
  82. * @param string $type Type: "file", ...
  83. * @param object $pObj Parent object.
  84. * @return string Rendered content
  85. * @see SC_browse_links::main()
  86. */
  87. function render($type, $pObj) {
  88. global $LANG, $BE_USER, $BACK_PATH;
  89. $this->pObj = $pObj;
  90. // init class browse_links
  91. $this->init();
  92. switch((string)$this->mode) {
  93. case 'rte':
  94. $content = $this->main_rte();
  95. break;
  96. default:
  97. $content = '';
  98. break;
  99. }
  100. return $content;
  101. }
  102. /**
  103. * Constructor:
  104. * Initializes a lot of variables, setting JavaScript functions in header etc.
  105. *
  106. * @return void
  107. */
  108. function init() {
  109. global $BE_USER,$BACK_PATH,$LANG,$TYPO3_CONF_VARS;
  110. // Main GPvars:
  111. $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
  112. $this->act = t3lib_div::_GP('act');
  113. $this->expandPage = t3lib_div::_GP('expandPage');
  114. $this->expandFolder = t3lib_div::_GP('expandFolder');
  115. $this->pointer = t3lib_div::_GP('pointer');
  116. $this->P = t3lib_div::_GP('P');
  117. $this->PM = t3lib_div::_GP('PM');
  118. // Find RTE parameters
  119. $this->bparams = t3lib_div::_GP('bparams');
  120. $this->contentTypo3Language = t3lib_div::_GP('contentTypo3Language');
  121. $this->contentTypo3Charset = t3lib_div::_GP('contentTypo3Charset');
  122. $this->editorNo = t3lib_div::_GP('editorNo');
  123. $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
  124. $pArr = explode('|', $this->bparams);
  125. $pRteArr = explode(':', $pArr[1]);
  126. $this->editorNo = $this->editorNo ? $this->editorNo : $pRteArr[0];
  127. $this->contentTypo3Language = $this->contentTypo3Language ? $this->contentTypo3Language : $pRteArr[1];
  128. $this->contentTypo3Charset = $this->contentTypo3Charset ? $this->contentTypo3Charset : $pRteArr[2];
  129. $this->RTEtsConfigParams = $this->RTEtsConfigParams ? $this->RTEtsConfigParams : $pArr[2];
  130. // Find "mode"
  131. $this->mode=t3lib_div::_GP('mode');
  132. if (!$this->mode) {
  133. $this->mode='rte';
  134. }
  135. // init fileProcessor
  136. $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
  137. $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
  138. // init hook objects:
  139. $this->hookObjects = array();
  140. if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
  141. foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
  142. $processObject = t3lib_div::getUserObj($classData);
  143. if(!($processObject instanceof t3lib_browseLinksHook)) {
  144. throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
  145. }
  146. $parameters = array();
  147. $processObject->init($this, $parameters);
  148. $this->hookObjects[] = $processObject;
  149. }
  150. }
  151. // Site URL
  152. $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
  153. // the script to link to
  154. $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
  155. // CurrentUrl - the current link url must be passed around if it exists
  156. if ($this->mode=='wizard') {
  157. $currentLinkParts = t3lib_div::trimExplode(' ',$this->P['currentValue']);
  158. $this->curUrlArray = array(
  159. 'target' => $currentLinkParts[1]
  160. );
  161. $this->curUrlInfo=$this->parseCurUrl($this->siteURL.'?id='.$currentLinkParts[0],$this->siteURL);
  162. } else {
  163. $this->curUrlArray = t3lib_div::_GP('curUrl');
  164. if ($this->curUrlArray['all']) {
  165. $this->curUrlArray=t3lib_div::get_tag_attributes($this->curUrlArray['all']);
  166. }
  167. $this->curUrlInfo=$this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
  168. }
  169. // Determine nature of current url:
  170. $this->act=t3lib_div::_GP('act');
  171. if (!$this->act) {
  172. $this->act=$this->curUrlInfo['act'];
  173. }
  174. // Initializing the titlevalue
  175. $this->setTitle = $LANG->csConvObj->conv($this->curUrlArray['title'], 'utf-8', $LANG->charSet);
  176. // Rich Text Editor specific configuration:
  177. $addPassOnParams='';
  178. $classSelected = array();
  179. if ((string)$this->mode=='rte') {
  180. $RTEtsConfigParts = explode(':',$this->RTEtsConfigParams);
  181. $addPassOnParams .= '&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams);
  182. $addPassOnParams .= ($this->contentTypo3Language ? '&contentTypo3Language=' . rawurlencode($this->contentTypo3Language) : '');
  183. $addPassOnParams .= ($this->contentTypo3Charset ? '&contentTypo3Charset=' . rawurlencode($this->contentTypo3Charset) : '');
  184. $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
  185. $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
  186. if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['link.'])) {
  187. $this->buttonConfig = $this->thisConfig['buttons.']['link.'];
  188. }
  189. if ($this->thisConfig['classesAnchor'] || $this->thisConfig['classesLinks']) {
  190. $this->setClass = $this->curUrlArray['class'];
  191. if ($this->thisConfig['classesAnchor']) {
  192. $classesAnchorArray = t3lib_div::trimExplode(',',$this->thisConfig['classesAnchor'], 1);
  193. } else {
  194. $classesAnchorArray = t3lib_div::trimExplode(',',$this->thisConfig['classesLinks'], 1);
  195. }
  196. $anchorTypes = array( 'page', 'url', 'file', 'mail', 'spec');
  197. $classesAnchor = array();
  198. $classesAnchor['all'] = array();
  199. if (is_array($RTEsetup['properties']['classesAnchor.'])) {
  200. foreach ($RTEsetup['properties']['classesAnchor.'] as $label => $conf) {
  201. if (in_array($conf['class'], $classesAnchorArray)) {
  202. $classesAnchor['all'][] = $conf['class'];
  203. if (in_array($conf['type'], $anchorTypes)) {
  204. $classesAnchor[$conf['type']][] = $conf['class'];
  205. if (is_array($this->thisConfig['classesAnchor.']) && is_array($this->thisConfig['classesAnchor.']['default.']) && $this->thisConfig['classesAnchor.']['default.'][$conf['type']] == $conf['class']) {
  206. $this->classesAnchorDefault[$conf['type']] = $conf['class'];
  207. if ($conf['titleText']) {
  208. $this->classesAnchorDefaultTitle[$conf['type']] = $this->getLLContent(trim($conf['titleText']));
  209. }
  210. if ($conf['target']) {
  211. $this->classesAnchorDefaultTarget[$conf['type']] = trim($conf['target']);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. foreach ($anchorTypes as $anchorType) {
  219. foreach ($classesAnchorArray as $class) {
  220. if (!in_array($class, $classesAnchor['all']) || (in_array($class, $classesAnchor['all']) && is_array($classesAnchor[$anchorType]) && in_array($class, $classesAnchor[$anchorType]))) {
  221. $selected = '';
  222. if ($this->setClass == $class || (!$this->setClass && $this->classesAnchorDefault[$anchorType] == $class)) {
  223. $selected = 'selected="selected"';
  224. $classSelected[$anchorType] = true;
  225. }
  226. $classLabel = (is_array($RTEsetup['properties']['classes.']) && is_array($RTEsetup['properties']['classes.'][$class.'.']) && $RTEsetup['properties']['classes.'][$class.'.']['name']) ? $this->getPageConfigLabel($RTEsetup['properties']['classes.'][$class.'.']['name'], 0) : $class;
  227. $classStyle = (is_array($RTEsetup['properties']['classes.']) && is_array($RTEsetup['properties']['classes.'][$class.'.']) && $RTEsetup['properties']['classes.'][$class.'.']['value']) ? $RTEsetup['properties']['classes.'][$class.'.']['value'] : '';
  228. $this->classesAnchorJSOptions[$anchorType] .= '<option ' . $selected . ' value="' .$class . '"' . ($classStyle?' style="'.$classStyle.'"':'') . '>' . $classLabel . '</option>';
  229. }
  230. }
  231. if ($this->classesAnchorJSOptions[$anchorType]) {
  232. $selected = '';
  233. if (!$this->setClass && !$this->classesAnchorDefault[$anchorType]) $selected = 'selected="selected"';
  234. $this->classesAnchorJSOptions[$anchorType] = '<option ' . $selected . ' value=""></option>' . $this->classesAnchorJSOptions[$anchorType];
  235. }
  236. }
  237. }
  238. }
  239. // Initializing the target value (RTE)
  240. // 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
  241. // In other words, do not forward the target if we changed tab and the target field is not displayed
  242. $this->setTarget = (isset($this->curUrlArray['target'])
  243. && !(
  244. ($this->curUrlArray['target'] != $this->thisConfig['defaultLinkTarget'])
  245. && !$classSelected[$this->act]
  246. && is_array($this->buttonConfig['targetSelector.']) && $this->buttonConfig['targetSelector.']['disabled'] && is_array($this->buttonConfig['popupSelector.']) && $this->buttonConfig['popupSelector.']['disabled'])
  247. ) ? $this->curUrlArray['target'] : '';
  248. if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
  249. $this->setTarget=$this->thisConfig['defaultLinkTarget'];
  250. }
  251. // init the DAM object
  252. $this->initDAM();
  253. $this->getModSettings();
  254. $this->processParams();
  255. // Creating backend template object:
  256. $this->doc = t3lib_div::makeInstance('template');
  257. $this->doc->backPath = $BACK_PATH;
  258. }
  259. function reinitParams() {
  260. if ($this->editorNo) {
  261. $pArr = explode('|', $this->bparams);
  262. $pArr[1] = implode(':', array($this->editorNo, $this->contentTypo3Language, $this->contentTypo3Charset));
  263. $pArr[2] = $this->RTEtsConfigParams;
  264. $this->bparams = implode('|', $pArr);
  265. }
  266. parent::reinitParams();
  267. }
  268. /**
  269. * [Describe function...]
  270. *
  271. * @return [type] ...
  272. */
  273. function getJSCode() {
  274. global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
  275. // BEGIN accumulation of header JavaScript:
  276. $JScode = '';
  277. $JScode.= '
  278. var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("TYPO3Link");
  279. var HTMLArea = window.parent.HTMLArea;
  280. // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
  281. var add_href="'.($this->curUrlArray['href']?'&curUrl[href]='.rawurlencode($this->curUrlArray['href']):'').'";
  282. var add_target="'.($this->setTarget?'&curUrl[target]='.rawurlencode($this->setTarget):'').'";
  283. var add_class="'.($this->setClass?'&curUrl[class]='.rawurlencode($this->setClass):'').'";
  284. var add_title="'.($this->setTitle?'&curUrl[title]='.rawurlencode($this->setTitle):'').'";
  285. var add_params="'.($this->bparams?'&bparams='.rawurlencode($this->bparams):'').'";
  286. var cur_href="'.($this->curUrlArray['href']?$this->curUrlArray['href']:'').'";
  287. var cur_target="'.($this->setTarget?$this->setTarget:'').'";
  288. var cur_class="'.($this->setClass?$this->setClass:'').'";
  289. var cur_title="'.($this->setTitle?$this->setTitle:'').'";
  290. function setTarget(value) {
  291. cur_target=value;
  292. add_target="&curUrl[target]="+encodeURIComponent(value);
  293. }
  294. function setClass(value) {
  295. cur_class=value;
  296. add_class="&curUrl[class]="+encodeURIComponent(value);
  297. }
  298. function setTitle(value) {
  299. cur_title=value;
  300. add_title="&curUrl[title]="+encodeURIComponent(value);
  301. }
  302. function setValue(value) {
  303. cur_href=value;
  304. add_href="&curUrl[href]="+value;
  305. }';
  306. // Functions used, if the link selector is in RTE mode:
  307. $JScode.='
  308. function link_typo3Page(id,anchor) {
  309. var theLink = \''.$this->siteURL.'?id=\'+id+(anchor?anchor:"");
  310. if (document.ltargetform.anchor_title) setTitle(document.ltargetform.anchor_title.value);
  311. if (document.ltargetform.anchor_class) setClass(document.ltargetform.anchor_class.value);
  312. if (document.ltargetform.ltarget) setTarget(document.ltargetform.ltarget.value);
  313. plugin.createLink(theLink,cur_target,cur_class,cur_title);
  314. return false;
  315. }
  316. function link_folder(folder) { //
  317. var theLink = \''.$this->siteURL.'\'+folder;
  318. if (document.ltargetform.anchor_title) setTitle(document.ltargetform.anchor_title.value);
  319. if (document.ltargetform.anchor_class) setClass(document.ltargetform.anchor_class.value);
  320. if (document.ltargetform.ltarget) setTarget(document.ltargetform.ltarget.value);
  321. plugin.createLink(theLink,cur_target,cur_class,cur_title);
  322. return false;
  323. }
  324. function link_spec(theLink) { //
  325. if (document.ltargetform.anchor_title) setTitle(document.ltargetform.anchor_title.value);
  326. if (document.ltargetform.anchor_class) setClass(document.ltargetform.anchor_class.value);
  327. if (document.ltargetform.ltarget) setTarget(document.ltargetform.ltarget.value);
  328. plugin.createLink(theLink,cur_target,cur_class,cur_title);
  329. return false;
  330. }
  331. function link_current() { //
  332. if (document.ltargetform.anchor_title) setTitle(document.ltargetform.anchor_title.value);
  333. if (document.ltargetform.anchor_class) setClass(document.ltargetform.anchor_class.value);
  334. if (document.ltargetform.ltarget) setTarget(document.ltargetform.ltarget.value);
  335. if (cur_href!="http://" && cur_href!="mailto:") {
  336. plugin.createLink(cur_href,cur_target,cur_class,cur_title);
  337. }
  338. return false;
  339. }
  340. ';
  341. // General "jumpToUrl" function:
  342. $JScode.='
  343. function jumpToUrl(URL,anchor) { //
  344. var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo='.$this->editorNo.'" : "";
  345. var add_contentTypo3Language = URL.indexOf("contentTypo3Language=")==-1 ? "&contentTypo3Language='.$this->contentTypo3Language.'" : "";
  346. var add_contentTypo3Charset = URL.indexOf("contentTypo3Charset=")==-1 ? "&contentTypo3Charset='.$this->contentTypo3Charset.'" : "";
  347. var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
  348. var add_mode = URL.indexOf("mode=")==-1 ? "&mode='.$this->mode.'" : "";
  349. var theLocation = URL+add_act+add_editorNo+add_contentTypo3Language+add_contentTypo3Charset+add_mode+add_href+add_target+add_class+add_title+add_params'.($addPassOnParams?'+"'.$addPassOnParams.'"':'').'+(anchor?anchor:"");
  350. window.location.href = theLocation;
  351. return false
  352. }
  353. ';
  354. // This is JavaScript especially for the TBE Element Browser!
  355. $pArr = explode('|',$this->bparams);
  356. $formFieldName = 'data['.$pArr[0].']['.$pArr[1].']['.$pArr[2].']';
  357. $JScode.='
  358. var elRef="";
  359. var targetDoc="";
  360. function launchView(url) { //
  361. var thePreviewWindow="";
  362. thePreviewWindow = window.open("' . $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");
  363. if (thePreviewWindow && thePreviewWindow.focus) {
  364. thePreviewWindow.focus();
  365. }
  366. }
  367. function setReferences() { //
  368. if (parent.window.opener
  369. && parent.window.opener.content
  370. && parent.window.opener.content.document.editform
  371. && parent.window.opener.content.document.editform["'.$formFieldName.'"]
  372. ) {
  373. targetDoc = parent.window.opener.content.document;
  374. elRef = targetDoc.editform["'.$formFieldName.'"];
  375. return true;
  376. } else {
  377. return false;
  378. }
  379. }
  380. function insertElement(table, uid, type, filename, fp, filetype, imagefile, action, close) { //
  381. link_folder(fp.substring('.strlen(PATH_site).'));
  382. return false;
  383. }
  384. function addElement(elName,elValue,altElValue,close) { //
  385. if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
  386. parent.window.opener.setFormValueFromBrowseWin("'.$pArr[0].'",altElValue?altElValue:elValue,elName);
  387. if (close) {
  388. parent.window.opener.focus();
  389. parent.close();
  390. }
  391. } else {
  392. alert("Error - reference to main window is not set properly!");
  393. parent.close();
  394. }
  395. }
  396. ';
  397. // Finally, add the accumulated JavaScript to the template object:
  398. $this->doc->JScodeArray['rtehtmlarea'] = $JScode;
  399. }
  400. /**
  401. * Return true or false whether thumbs should be displayed or not
  402. *
  403. * @return boolean
  404. */
  405. function displayThumbs() {
  406. global $BE_USER;
  407. return parent::displayThumbs() && !$BE_USER->getTSConfigVal('options.noThumbsInRTEimageSelect') && ($this->act != 'dragdrop');
  408. }
  409. /**
  410. * Create HTML checkbox to enable/disable thumbnail display
  411. *
  412. * @return string HTML code
  413. */
  414. function addDisplayOptions() {
  415. global $BE_USER;
  416. // Getting flag for showing/not showing thumbnails:
  417. $noThumbs = $BE_USER->getTSConfigVal('options.noThumbsInEB') || ($this->mode == 'rte' && $BE_USER->getTSConfigVal('options.noThumbsInRTEimageSelect')) || ($this->act == 'dragdrop');
  418. if ($noThumbs) {
  419. $thumbNailCheckbox = '';
  420. } else {
  421. $thumbNailCheckbox = t3lib_BEfunc::getFuncCheck('', 'SET[displayThumbs]',$this->displayThumbs(), $this->thisScript, t3lib_div::implodeArrayForUrl('',$this->addParams));
  422. $description = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:displayThumbs',1);
  423. $id = 'l'.uniqid('tx_dam_scbase');
  424. $idAttr = ' id="'.$id.'"';
  425. $thumbNailCheckbox = str_replace('<input', '<input'.$idAttr, $thumbNailCheckbox);
  426. $thumbNailCheckbox .= ' <label for="'.$id.'">'.$description.'</label>';
  427. $this->damSC->addOption('html', 'thumbnailCheckbox', $thumbNailCheckbox);
  428. }
  429. $this->damSC->addOption('funcCheck', 'extendedInfo', $GLOBALS['LANG']->getLL('displayExtendedInfo',1));
  430. }
  431. /******************************************************************
  432. *
  433. * Main functions
  434. *
  435. ******************************************************************/
  436. /**
  437. * Rich Text Editor (RTE) link selector (MAIN function)
  438. * Generates the link selector for the Rich Text Editor.
  439. * Can also be used to select links for the TCEforms (see $wiz)
  440. *
  441. * @param boolean If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
  442. * @return string Modified content variable.
  443. */
  444. function main_rte($wiz=0) {
  445. global $LANG, $BE_USER, $BACK_PATH;
  446. // Starting content:
  447. $content=$this->doc->startPage($LANG->getLL('Insert/Modify Link',1));
  448. $this->reinitParams();
  449. // Initializing the action value, possibly removing blinded values etc:
  450. $this->allowedItems = explode(',','page,file,url,mail,spec,upload');
  451. // Remove upload tab if filemount is readonly
  452. if ($this->isReadOnlyFolder(tx_dam::path_makeAbsolute($this->damSC->path))) {
  453. $this->allowedItems = array_diff($this->allowedItems, array('upload'));
  454. }
  455. //call hook for extra options
  456. foreach($this->hookObjects as $hookObject) {
  457. $this->allowedItems = $hookObject->addAllowedItems($this->allowedItems);
  458. }
  459. if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
  460. $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->buttonConfig['options.']['removeItems'],1));
  461. } else {
  462. $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->thisConfig['blindLinkOptions'],1));
  463. }
  464. reset($this->allowedItems);
  465. if (!in_array($this->act,$this->allowedItems)) {
  466. $this->act = current($this->allowedItems);
  467. }
  468. // Making menu in top:
  469. $menuDef = array();
  470. if (!$wiz && $this->curUrlArray['href']) {
  471. $menuDef['removeLink']['isActive'] = $this->act=='removeLink';
  472. $menuDef['removeLink']['label'] = $LANG->getLL('removeLink',1);
  473. $menuDef['removeLink']['url'] = '#';
  474. $menuDef['removeLink']['addParams'] = 'onclick="plugin.unLink();return false;"';
  475. }
  476. if (in_array('page',$this->allowedItems)) {
  477. $menuDef['page']['isActive'] = $this->act=='page';
  478. $menuDef['page']['label'] = $LANG->getLL('page',1);
  479. $menuDef['page']['url'] = '#';
  480. $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=page&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  481. }
  482. if (in_array('file',$this->allowedItems)){
  483. $menuDef['file']['isActive'] = $this->act=='file';
  484. $menuDef['file']['label'] = $LANG->sL('LLL:EXT:dam/mod_main/locallang_mod.xml:mlang_tabs_tab',1);
  485. $menuDef['file']['url'] = '#';
  486. $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=file&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  487. }
  488. if (in_array('url',$this->allowedItems)) {
  489. $menuDef['url']['isActive'] = $this->act=='url';
  490. $menuDef['url']['label'] = $LANG->getLL('extUrl',1);
  491. $menuDef['url']['url'] = '#';
  492. $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=url&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  493. }
  494. if (in_array('mail',$this->allowedItems)) {
  495. $menuDef['mail']['isActive'] = $this->act=='mail';
  496. $menuDef['mail']['label'] = $LANG->getLL('email',1);
  497. $menuDef['mail']['url'] = '#';
  498. $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=mail&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  499. }
  500. if (is_array($this->thisConfig['userLinks.']) && in_array('spec',$this->allowedItems)) {
  501. $menuDef['spec']['isActive'] = $this->act=='spec';
  502. $menuDef['spec']['label'] = $LANG->getLL('special',1);
  503. $menuDef['spec']['url'] = '#';
  504. $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=spec&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  505. }
  506. if (in_array('upload', $this->allowedItems)) {
  507. $menuDef['upload']['isActive'] = ($this->act === 'upload');
  508. $menuDef['upload']['label'] = $LANG->getLL('tx_dam_file_upload.title',1);
  509. $menuDef['upload']['url'] = '#';
  510. $menuDef['upload']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=upload&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
  511. }
  512. // call hook for extra options
  513. foreach($this->hookObjects as $hookObject) {
  514. $menuDef = $hookObject->modifyMenuDefinition($menuDef);
  515. }
  516. $content .= $this->doc->getTabMenuRaw($menuDef);
  517. // Adding the menu and header to the top of page:
  518. $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
  519. // Depending on the current action we will create the actual module content for selecting a link:
  520. switch($this->act) {
  521. case 'mail':
  522. $extUrl='
  523. <!--
  524. Enter mail address:
  525. -->
  526. <form action="" name="lurlform" id="lurlform">
  527. <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
  528. <tr>
  529. <td>'.$LANG->getLL('emailAddress',1).':</td>
  530. <td><input type="text" name="lemail"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='mail'?$this->curUrlInfo['info']:'').'" /> '.
  531. '<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="setTarget(\'\');setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
  532. </tr>
  533. </table>
  534. </form>';
  535. $content.=$extUrl;
  536. $content.=$this->addAttributesForm();
  537. break;
  538. case 'url':
  539. $extUrl='
  540. <!--
  541. Enter External URL:
  542. -->
  543. <form action="" name="lurlform" id="lurlform">
  544. <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
  545. <tr>
  546. <td>URL:</td>
  547. <td><input type="text" name="lurl"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
  548. '<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="if (/^[A-Za-z0-9_+]{1,8}:/i.test(document.lurlform.lurl.value)) { setValue(document.lurlform.lurl.value); } else { setValue(\'http://\'+document.lurlform.lurl.value); }; return link_current();" /></td>
  549. </tr>
  550. </table>
  551. </form>';
  552. $content.=$extUrl;
  553. $content.=$this->addAttributesForm();
  554. break;
  555. case 'file':
  556. $this->addDisplayOptions();
  557. $content.=$this->addAttributesForm();
  558. $content.= $this->dam_select($this->allowedFileTypes, $this->disallowedFileTypes);
  559. $content.= $this->damSC->getOptions();
  560. break;
  561. case 'spec':
  562. if (is_array($this->thisConfig['userLinks.'])) {
  563. $subcats=array();
  564. $v=$this->thisConfig['userLinks.'];
  565. foreach ($v as $k2 => $dummyValue) {
  566. $k2i = intval($k2);
  567. if (substr($k2,-1)=='.' && is_array($v[$k2i.'.'])) {
  568. // Title:
  569. $title = trim($v[$k2i]);
  570. if (!$title) {
  571. $title=$v[$k2i.'.']['url'];
  572. } else {
  573. $title=$LANG->sL($title);
  574. }
  575. // Description:
  576. $description=$v[$k2i.'.']['description'] ? $LANG->sL($v[$k2i.'.']['description'],1).'<br />' : '';
  577. // URL + onclick event:
  578. $onClickEvent='';
  579. if (isset($v[$k2i.'.']['target'])) $onClickEvent.="setTarget('".$v[$k2i.'.']['target']."');";
  580. $v[$k2i.'.']['url'] = str_replace('###_URL###',$this->siteURL,$v[$k2i.'.']['url']);
  581. if (substr($v[$k2i.'.']['url'],0,7)=="http://" || substr($v[$k2i.'.']['url'],0,7)=='mailto:') {
  582. $onClickEvent.="cur_href=unescape('".rawurlencode($v[$k2i.'.']['url'])."');link_current();";
  583. } else {
  584. $onClickEvent.="link_spec(unescape('".$this->siteURL.rawurlencode($v[$k2i.'.']['url'])."'));";
  585. }
  586. // Link:
  587. $A=array('<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">','</a>');
  588. // Adding link to menu of user defined links:
  589. $subcats[$k2i]='
  590. <tr>
  591. <td class="bgColor4">'.$A[0].'<strong>'.htmlspecialchars($title).($this->curUrlInfo['info']==$v[$k2i.'.']['url']?'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" />':'').'</strong><br />'.$description.$A[1].'</td>
  592. </tr>';
  593. }
  594. }
  595. // Sort by keys:
  596. ksort($subcats);
  597. // Add menu to content:
  598. $content.= '
  599. <!--
  600. Special userdefined menu:
  601. -->
  602. <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
  603. <tr>
  604. <td class="bgColor5" class="c-wCell" valign="top"><strong>'.$LANG->getLL('special',1).'</strong></td>
  605. </tr>
  606. '.implode('',$subcats).'
  607. </table>
  608. ';
  609. }
  610. break;
  611. case 'page':
  612. $content.=$this->addAttributesForm();
  613. $pagetree = t3lib_div::makeInstance('tx_rtehtmlarea_pageTree');
  614. $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
  615. $pagetree->addField('nav_title');
  616. $tree=$pagetree->getBrowsableTree();
  617. $cElements = $this->expandPage();
  618. $content.= '
  619. <!--
  620. Wrapper table for page tree / record list:
  621. -->
  622. <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
  623. <tr>
  624. <td class="c-wCell" valign="top">'.$this->barheader($LANG->getLL('pageTree').':').$tree.'</td>
  625. <td class="c-wCell" valign="top">'.$cElements.'</td>
  626. </tr>
  627. </table>
  628. ';
  629. break;
  630. case 'upload':
  631. $content.= $this->dam_upload($this->allowedFileTypes, $this->disallowedFileTypes);
  632. $content.= $this->damSC->getOptions();
  633. $content.='<br /><br />';
  634. if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.createFoldersInEB')) {
  635. $content.= $this->createFolder(tx_dam::path_makeAbsolute($this->damSC->path));
  636. }
  637. break;
  638. default:
  639. // call hook
  640. foreach($this->hookObjects as $hookObject) {
  641. $content .= $hookObject->getTab($this->act);
  642. }
  643. break;
  644. }
  645. // End page, return content:
  646. $content.= $this->doc->endPage();
  647. $this->getJSCode();
  648. $content = $this->damSC->doc->insertStylesAndJS($content);
  649. return $content;
  650. }
  651. function addAttributesForm() {
  652. $ltargetForm = '';
  653. // Add page id, target, class selector box and title field:
  654. $lpageId = $this->addPageIdSelector();
  655. $ltarget = $this->addTargetSelector();
  656. $lclass = $this->addClassSelector();
  657. $ltitle = $this->addTitleSelector();
  658. if ($lpageId || $ltarget || $lclass || $ltitle) {
  659. $ltargetForm = $this->wrapInForm($lpageId.$ltarget.$lclass.$ltitle);
  660. }
  661. return $ltargetForm;
  662. }
  663. function wrapInForm($string) {
  664. global $LANG;
  665. $form = '
  666. <!--
  667. Selecting target for link:
  668. -->
  669. <form action="" name="ltargetform" id="ltargetform">
  670. <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">'. $string;
  671. if ((($this->act == 'page' && $this->curUrlInfo['act']=='page') || ($this->act == 'file' && $this->curUrlInfo['act']=='file') || ($this->act == 'url' && $this->curUrlInfo['act']!='page')) && $this->curUrlArray['href']) {
  672. $form .='
  673. <tr>
  674. <td>
  675. </td>
  676. <td colspan="3">
  677. <input type="submit" value="'.$LANG->getLL('update',1).'" onclick="return link_current();" />
  678. </td>
  679. </tr>';
  680. }
  681. $form .= '
  682. </table>
  683. </form>';
  684. return $form;
  685. }
  686. function addPageIdSelector() {
  687. global $LANG;
  688. return ($this->act == 'page' && $this->buttonConfig && is_array($this->buttonConfig['pageIdSelector.']) && $this->buttonConfig['pageIdSelector.']['enabled'])?'
  689. <tr>
  690. <td>'.$LANG->getLL('page_id',1).':</td>
  691. <td colspan="3">
  692. <input type="text" size="6" name="luid" />&nbsp;<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="return link_typo3Page(document.ltargetform.luid.value);" />
  693. </td>
  694. </tr>':'';
  695. }
  696. function addTargetSelector() {
  697. global $LANG;
  698. $targetSelectorConfig = array();
  699. $popupSelectorConfig = array();
  700. if (is_array($this->buttonConfig['targetSelector.'])) {
  701. $targetSelectorConfig = $this->buttonConfig['targetSelector.'];
  702. }
  703. if (is_array($this->buttonConfig['popupSelector.'])) {
  704. $popupSelectorConfig = $this->buttonConfig['popupSelector.'];
  705. }
  706. $ltarget = '';
  707. if ($this->act != 'mail') {
  708. $ltarget .= '
  709. <tr id="ltargetrow"'. (($targetSelectorConfig['disabled'] && $popupSelectorConfig['disabled']) ? ' style="display: none;"' : '') . '>
  710. <td>'.$LANG->getLL('target',1).':</td>
  711. <td><input type="text" name="ltarget" onchange="setTarget(this.value);" value="'.htmlspecialchars($this->setTarget?$this->setTarget:(($this->setClass || !$this->classesAnchorDefault[$this->act])?'':$this->classesAnchorDefaultTarget[$this->act])).'"'.$this->doc->formWidth(10).' /></td>';
  712. $ltarget .= '
  713. <td colspan="2">';
  714. if (!$targetSelectorConfig['disabled']) {
  715. $ltarget .= '
  716. <select name="ltarget_type" onchange="setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
  717. <option></option>
  718. <option value="_top">'.$LANG->getLL('top',1).'</option>
  719. <option value="_blank">'.$LANG->getLL('newWindow',1).'</option>
  720. </select>';
  721. }
  722. $ltarget .= '
  723. </td>
  724. </tr>';
  725. if (!$popupSelectorConfig['disabled']) {
  726. $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) {
  727. 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;
  728. setTarget(document.ltargetform.ltarget.value);
  729. document.ltargetform.popup_width.selectedIndex=0;
  730. document.ltargetform.popup_height.selectedIndex=0;
  731. }';
  732. $ltarget.='
  733. <tr>
  734. <td>'.$LANG->getLL('target_popUpWindow',1).':</td>
  735. <td colspan="3">
  736. <select name="popup_width" onchange="'.$selectJS.'">
  737. <option value="0">'.$LANG->getLL('target_popUpWindow_width',1).'</option>
  738. <option value="300">300</option>
  739. <option value="400">400</option>
  740. <option value="500">500</option>
  741. <option value="600">600</option>
  742. <option value="700">700</option>
  743. <option value="800">800</option>
  744. </select>
  745. x
  746. <select name="popup_height" onchange="'.$selectJS.'">
  747. <option value="0">'.$LANG->getLL('target_popUpWindow_height',1).'</option>
  748. <option value="200">200</option>
  749. <option value="300">300</option>
  750. <option value="400">400</option>
  751. <option value="500">500</option>
  752. <option value="600">600</option>
  753. </select>
  754. </td>
  755. </tr>';
  756. }
  757. }
  758. return $ltarget;
  759. }
  760. function addClassSelector() {
  761. global $LANG;
  762. $selectClass = '';
  763. if ($this->classesAnchorJSOptions[$this->act]) {
  764. $selectClassJS = '
  765. if (document.ltargetform.anchor_class) {
  766. document.ltargetform.anchor_class.value = document.ltargetform.anchor_class.options[document.ltargetform.anchor_class.selectedIndex].value;
  767. if (document.ltargetform.anchor_class.value && HTMLArea.classesAnchorSetup) {
  768. for (var i = HTMLArea.classesAnchorSetup.length; --i >= 0;) {
  769. var anchorClass = HTMLArea.classesAnchorSetup[i];
  770. if (anchorClass[\'name\'] == document.ltargetform.anchor_class.value) {
  771. if (anchorClass[\'titleText\'] && document.ltargetform.anchor_title) {
  772. document.ltargetform.anchor_title.value = anchorClass[\'titleText\'];
  773. setTitle(anchorClass[\'titleText\']);
  774. }
  775. if (anchorClass[\'target\']) {
  776. if (document.ltargetform.ltarget) {
  777. document.ltargetform.ltarget.value = anchorClass[\'target\'];
  778. }
  779. setTarget(anchorClass[\'target\']);
  780. } else if (document.ltargetform.ltarget && document.getElementById(\'ltargetrow\').style.display == \'none\') {
  781. // Reset target to default if field is not displayed and class has no configured target
  782. document.ltargetform.ltarget.value = \''. ($this->thisConfig['defaultLinkTarget']?$this->thisConfig['defaultLinkTarget']:'') .'\';
  783. setTarget(document.ltargetform.ltarget.value);
  784. }
  785. break;
  786. }
  787. }
  788. }
  789. setClass(document.ltargetform.anchor_class.value);
  790. }
  791. ';
  792. $selectClass ='
  793. <tr>
  794. <td>'.$LANG->getLL('anchor_class',1).':</td>
  795. <td colspan="3">
  796. <select name="anchor_class" onchange="'.$selectClassJS.'">
  797. ' . $this->classesAnchorJSOptions[$this->act] . '
  798. </select>
  799. </td>
  800. </tr>';
  801. }
  802. return $selectClass;
  803. }
  804. function addTitleSelector() {
  805. global $LANG;
  806. return '
  807. <tr>
  808. <td>'.$LANG->getLL('anchor_title',1).':</td>
  809. <td colspan="3">
  810. <input type="text" name="anchor_title" value="' . ($this->setTitle?$this->setTitle:(($this->setClass || !$this->classesAnchorDefault[$this->act])?'':$this->classesAnchorDefaultTitle[$this->act])) . '" ' . $this->doc->formWidth(30) . ' />
  811. </td>
  812. </tr>';
  813. }
  814. /**
  815. * Localize a string using the language of the content element rather than the language of the BE interface
  816. *
  817. * @param string $string: the label to be localized
  818. * @return string Localized string.
  819. */
  820. public function getLLContent($string) {
  821. global $LANG;
  822. $BE_lang = $LANG->lang;
  823. $BE_origCharSet = $LANG->origCharSet;
  824. $BE_charSet = $LANG->charSet;
  825. $LANG->lang = $this->contentTypo3Language;
  826. $LANG->origCharSet = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
  827. $LANG->origCharSet = $LANG->origCharSet ? $LANG->origCharSet : 'iso-8859-1';
  828. $LANG->charSet = $this->contentTypo3Charset;
  829. $LLString = $LANG->sL($string);
  830. $LANG->lang = $BE_lang;
  831. $LANG->origCharSet = $BE_origCharSet;
  832. $LANG->charSet = $BE_charSet;
  833. return $LLString;
  834. }
  835. /**
  836. * Localize a label obtained from Page TSConfig
  837. *
  838. * @param string string: the label to be localized
  839. * @return string Localized string.
  840. */
  841. public function getPageConfigLabel($string,$JScharCode=1) {
  842. global $LANG;
  843. if (strcmp(substr($string,0,4),'LLL:')) {
  844. $label = $string;
  845. } else {
  846. $label = $LANG->sL(trim($string));
  847. }
  848. $label = str_replace('"', '\"', str_replace('\\\'', '\'', $label));
  849. $label = $JScharCode ? $LANG->JScharCode($label): $label;
  850. return $label;
  851. }
  852. }
  853. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_dam_browse_links.php']) {
  854. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_dam_browse_links.php']);
  855. }
  856. ?>