Fixed bug #1985: XSS vulnerability in wizard classes
[Packages/TYPO3.CMS.git] / typo3 / class.browse_links.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Displays the page/file tree for browsing database records or files.
29 * Used from TCEFORMS an other elements
30 * In other words: This is the ELEMENT BROWSER!
31 *
32 * $Id$
33 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
34 * XHTML compliant
35 *
36 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 */
38 /**
39 * [CLASS/FUNCTION INDEX of SCRIPT]
40 *
41 *
42 *
43 * 155: class TBE_browser_recordList extends localRecordList
44 * 163: function TBE_browser_recordList ()
45 * 175: function listURL($altId='',$table=-1,$exclList='')
46 * 194: function ext_addP()
47 * 211: function linkWrapItems($table,$uid,$code,$row)
48 * 244: function linkWrapTable($table,$code)
49 *
50 *
51 * 261: class localPageTree extends t3lib_browseTree
52 * 268: function localPageTree()
53 * 284: function wrapTitle($title,$v,$ext_pArrPages='')
54 * 299: function printTree($treeArr='')
55 * 350: function ext_isLinkable($doktype,$uid)
56 * 364: function PM_ATagWrap($icon,$cmd,$bMark='')
57 * 381: function wrapIcon($icon,$row)
58 *
59 *
60 * 400: class rtePageTree extends localPageTree
61 *
62 *
63 * 417: class TBE_PageTree extends localPageTree
64 * 426: function ext_isLinkable($doktype,$uid)
65 * 438: function wrapTitle($title,$v,$ext_pArrPages)
66 *
67 *
68 * 464: class localFolderTree extends t3lib_folderTree
69 * 473: function localFolderTree()
70 * 485: function wrapTitle($title,$v)
71 * 500: function ext_isLinkable($v)
72 * 517: function PM_ATagWrap($icon,$cmd,$bMark='')
73 * 532: function printTree($treeArr='')
74 *
75 *
76 * 599: class rteFolderTree extends localFolderTree
77 *
78 *
79 * 615: class TBE_FolderTree extends localFolderTree
80 * 624: function ext_isLinkable($v)
81 * 637: function wrapTitle($title,$v)
82 *
83 *
84 * 658: class browse_links
85 * 764: function init()
86 * 1034: function processSessionData($data)
87 *
88 * SECTION: Main functions
89 * 1077: function main_rte($wiz=0)
90 * 1379: function main_db()
91 * 1424: function main_file()
92 *
93 * SECTION: Record listing
94 * 1534: function expandPage()
95 * 1615: function TBE_expandPage($tables)
96 *
97 * SECTION: File listing
98 * 1708: function expandFolder($expandFolder=0,$extensionList='')
99 * 1778: function TBE_expandFolder($expandFolder=0,$extensionList='',$noThumbs=0)
100 * 1801: function fileList($files, $folderName='', $noThumbs=0)
101 * 1918: function TBE_dragNDrop($expandFolder=0,$extensionList='')
102 *
103 * SECTION: Miscellaneous functions
104 * 2046: function isWebFolder($folder)
105 * 2057: function checkFolder($folder)
106 * 2070: function barheader($str)
107 * 2087: function getMsgBox($in_msg,$icon='icon_note')
108 * 2111: function printCurrentUrl($str)
109 * 2131: function parseCurUrl($href,$siteUrl)
110 * 2193: function uploadForm($path)
111 * 2247: function createFolder($path)
112 *
113 * TOTAL FUNCTIONS: 39
114 * (This index is automatically created/updated by the extension "extdeveval")
115 *
116 */
117
118
119 // Include classes
120 require_once (PATH_typo3.'/class.db_list.inc');
121 require_once (PATH_typo3.'/class.db_list_extra.inc');
122
123
124
125
126 /**
127 * Local version of the record list.
128 *
129 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
130 * @package TYPO3
131 * @subpackage core
132 */
133 class TBE_browser_recordList extends localRecordList {
134 var $thisScript = 'browse_links.php';
135
136 /**
137 * Initializes the script path
138 *
139 * @return void
140 */
141 function TBE_browser_recordList () {
142 parent::__construct();
143 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
144 }
145
146 /**
147 * Creates the URL for links
148 *
149 * @param mixed If not blank string, this is used instead of $this->id as the id value.
150 * @param string If this is "-1" then $this->table is used, otherwise the value of the input variable.
151 * @param string Commalist of fields NOT to pass as parameters (currently "sortField" and "sortRev")
152 * @return string Query-string for URL
153 */
154 function listURL($altId='',$table=-1,$exclList='') {
155 return $this->thisScript.
156 '?id='.(strcmp($altId,'')?$altId:$this->id).
157 '&table='.rawurlencode($table==-1?$this->table:$table).
158 ($this->thumbs?'&imagemode='.$this->thumbs:'').
159 ($this->searchString?'&search_field='.rawurlencode($this->searchString):'').
160 ($this->searchLevels?'&search_levels='.rawurlencode($this->searchLevels):'').
161 ((!$exclList || !t3lib_div::inList($exclList,'sortField')) && $this->sortField?'&sortField='.rawurlencode($this->sortField):'').
162 ((!$exclList || !t3lib_div::inList($exclList,'sortRev')) && $this->sortRev?'&sortRev='.rawurlencode($this->sortRev):'').
163 // extra:
164 $this->ext_addP()
165 ;
166 }
167
168 /**
169 * Returns additional, local GET parameters to include in the links of the record list.
170 *
171 * @return string
172 */
173 function ext_addP() {
174 $str = '&act='.$GLOBALS['SOBE']->browser->act.
175 '&mode='.$GLOBALS['SOBE']->browser->mode.
176 '&expandPage='.$GLOBALS['SOBE']->browser->expandPage.
177 '&bparams='.rawurlencode($GLOBALS['SOBE']->browser->bparams);
178 return $str;
179 }
180
181 /**
182 * Returns the title (based on $code) of a record (from table $table) with the proper link around (that is for "pages"-records a link to the level of that record...)
183 *
184 * @param string Table name
185 * @param integer UID (not used here)
186 * @param string Title string
187 * @param array Records array (from table name)
188 * @return string
189 */
190 function linkWrapItems($table,$uid,$code,$row) {
191 global $TCA, $BACK_PATH;
192
193 if (!$code) {
194 $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i>';
195 } else {
196 $code = t3lib_BEfunc::getRecordTitlePrep($code, $this->fixedL);
197 }
198
199 $title = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
200 $ficon = t3lib_iconWorks::getIcon($table,$row);
201 $aOnClick = "return insertElement('".$table."', '".$row['uid']."', 'db', ".t3lib_div::quoteJSvalue($title).", '', '', '".$ficon."');";
202 $ATag = '<a href="#" onclick="'.$aOnClick.'">';
203 $ATag_alt = substr($ATag,0,-4).',\'\',1);">';
204 $ATag_e = '</a>';
205
206 return $ATag.
207 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('addToList',1).'" alt="" />'.
208 $ATag_e.
209 $ATag_alt.
210 $code.
211 $ATag_e;
212 }
213
214 /**
215 * Local version that sets allFields to true to support userFieldSelect
216 *
217 * @return void
218 * @see fieldSelectBox
219 */
220 function generateList() {
221 $this->allFields = true;
222 parent::generateList();
223 }
224 }
225
226
227
228
229
230
231 /**
232 * Class which generates the page tree
233 *
234 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
235 * @package TYPO3
236 * @subpackage core
237 */
238 class localPageTree extends t3lib_browseTree {
239
240 /**
241 * whether the page ID should be shown next to the title, activate through userTSconfig (options.pageTree.showPageIdWithTitle)
242 * @boolean
243 */
244 public $ext_showPageId = FALSE;
245
246 /**
247 * Constructor. Just calling init()
248 *
249 * @return void
250 */
251 function localPageTree() {
252 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
253
254 $this->init();
255
256 $this->clause = ' AND doktype!=255'.$this->clause;
257 }
258
259 /**
260 * Wrapping the title in a link, if applicable.
261 *
262 * @param string Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
263 * @param array The record
264 * @param boolean (Ignore)
265 * @return string Wrapping title string.
266 */
267 function wrapTitle($title,$v,$ext_pArrPages='') {
268 if ($this->ext_isLinkable($v['doktype'],$v['uid'])) {
269 $aOnClick = "return link_typo3Page('".$v['uid']."');";
270 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
271 } else {
272 return '<span style="color: #666666;">'.$title.'</span>';
273 }
274 }
275
276 /**
277 * Create the page navigation tree in HTML
278 *
279 * @param array Tree array
280 * @return string HTML output.
281 */
282 function printTree($treeArr='') {
283 global $BACK_PATH;
284 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
285 if (!is_array($treeArr)) $treeArr=$this->tree;
286
287 $out='';
288 $c=0;
289
290 foreach($treeArr as $k => $v) {
291 $c++;
292 $bgColorClass = ($c+1)%2 ? 'bgColor' : 'bgColor-10';
293 if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']==$v['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']) {
294 $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
295 $bgColorClass='bgColor4';
296 } else {
297 $arrCol='<td></td>';
298 }
299
300 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandPage='.$v['row']['uid'].'\');';
301 $cEbullet = $this->ext_isLinkable($v['row']['doktype'],$v['row']['uid']) ?
302 '<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/arrowbullet.gif','width="18" height="16"').' alt="" /></a>' :
303 '';
304 $out.='
305 <tr class="'.$bgColorClass.'">
306 <td nowrap="nowrap"'.($v['row']['_CSSCLASS'] ? ' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
307 $v['HTML'].
308 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$this->ext_pArrPages).
309 '</td>'.
310 $arrCol.
311 '<td>'.$cEbullet.'</td>
312 </tr>';
313 }
314 $out='
315
316
317 <!--
318 Navigation Page Tree:
319 -->
320 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tree">
321 '.$out.'
322 </table>';
323 return $out;
324 }
325
326 /**
327 * Returns true if a doktype can be linked.
328 *
329 * @param integer Doktype value to test
330 * @param integer uid to test.
331 * @return boolean
332 */
333 function ext_isLinkable($doktype,$uid) {
334 if ($uid && $doktype<199) {
335 return true;
336 }
337 }
338
339 /**
340 * Wrap the plus/minus icon in a link
341 *
342 * @param string HTML string to wrap, probably an image tag.
343 * @param string Command for 'PM' get var
344 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
345 * @return string Link-wrapped input string
346 */
347 function PM_ATagWrap($icon,$cmd,$bMark='') {
348 if ($bMark) {
349 $anchor = '#'.$bMark;
350 $name=' name="'.$bMark.'"';
351 }
352 $aOnClick = "return jumpToUrl('".$this->thisScript.'?PM='.$cmd."','".$anchor."');";
353
354 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
355 }
356
357 /**
358 * Wrapping the image tag, $icon, for the row, $row
359 *
360 * @param string The image tag for the icon
361 * @param array The row for the current element
362 * @return string The processed icon input value.
363 */
364 function wrapIcon($icon, $row) {
365 $content = $this->addTagAttributes($icon, ' title="id=' . $row['uid'] . '"');
366 if ($this->ext_showPageId) {
367 $content .= '[' . $row['uid'] . ']&nbsp;';
368 }
369 return $content;
370 }
371 }
372
373
374
375
376
377
378
379
380 /**
381 * Page tree for the RTE - totally the same, no changes needed. (Just for the sake of beauty - or confusion... :-)
382 *
383 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
384 * @package TYPO3
385 * @subpackage core
386 */
387 class rtePageTree extends localPageTree {
388 }
389
390
391
392
393
394
395
396
397 /**
398 * For TBE record browser
399 *
400 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
401 * @package TYPO3
402 * @subpackage core
403 */
404 class TBE_PageTree extends localPageTree {
405
406 /**
407 * Returns true if a doktype can be linked (which is always the case here).
408 *
409 * @param integer Doktype value to test
410 * @param integer uid to test.
411 * @return boolean
412 */
413 function ext_isLinkable($doktype,$uid) {
414 return true;
415 }
416
417 /**
418 * Wrapping the title in a link, if applicable.
419 *
420 * @param string Title, ready for output.
421 * @param array The record
422 * @param boolean If set, pages clicked will return immediately, otherwise reload page.
423 * @return string Wrapping title string.
424 */
425 function wrapTitle($title,$v,$ext_pArrPages) {
426 $title = htmlspecialchars($title);
427
428 if ($ext_pArrPages) {
429 $ficon=t3lib_iconWorks::getIcon('pages',$v);
430 $onClick = "return insertElement('pages', '".$v['uid']."', 'db', ".t3lib_div::quoteJSvalue($v['title']).", '', '', '".$ficon."','',1);";
431 } else {
432 $onClick = htmlspecialchars('return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandPage='.$v['uid'].'\');');
433 }
434 return '<a href="#" onclick="'.$onClick.'">'.$title.'</a>';
435 }
436 }
437
438
439
440
441
442
443
444
445 /**
446 * Base extension class which generates the folder tree.
447 * Used directly by the RTE.
448 *
449 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
450 * @package TYPO3
451 * @subpackage core
452 */
453 class localFolderTree extends t3lib_folderTree {
454 var $ext_IconMode=1;
455
456
457 /**
458 * Initializes the script path
459 *
460 * @return void
461 */
462 function localFolderTree() {
463 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
464 $this->t3lib_folderTree();
465 }
466
467 /**
468 * Wrapping the title in a link, if applicable.
469 *
470 * @param string Title, ready for output.
471 * @param array The "record"
472 * @return string Wrapping title string.
473 */
474 function wrapTitle($title,$v) {
475 $title = htmlspecialchars($title);
476
477 if ($this->ext_isLinkable($v)) {
478 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['path']).'\');';
479 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
480 } else {
481 return '<span class="typo3-dimmed">'.$title.'</span>';
482 }
483 }
484
485 /**
486 * Returns true if the input "record" contains a folder which can be linked.
487 *
488 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
489 * @return boolean True is returned if the path is found in the web-part of the server and is NOT a recycler or temp folder
490 */
491 function ext_isLinkable($v) {
492 $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']); // Checking, if the input path is a web-path.
493 if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web') {
494 return 0;
495 }
496 return 1;
497 }
498
499 /**
500 * Wrap the plus/minus icon in a link
501 *
502 * @param string HTML string to wrap, probably an image tag.
503 * @param string Command for 'PM' get var
504 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
505 * @return string Link-wrapped input string
506 * @access private
507 */
508 function PM_ATagWrap($icon,$cmd,$bMark='') {
509 if ($bMark) {
510 $anchor = '#'.$bMark;
511 $name=' name="'.$bMark.'"';
512 }
513 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?PM='.$cmd.'\',\''.$anchor.'\');';
514 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
515 }
516
517 /**
518 * Create the folder navigation tree in HTML
519 *
520 * @param mixed Input tree array. If not array, then $this->tree is used.
521 * @return string HTML output of the tree.
522 */
523 function printTree($treeArr='') {
524 global $BACK_PATH;
525 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
526
527 if (!is_array($treeArr)) $treeArr=$this->tree;
528
529 $out='';
530 $c=0;
531
532 // Preparing the current-path string (if found in the listing we will see a red blinking arrow).
533 if (!$GLOBALS['SOBE']->browser->curUrlInfo['value']) {
534 $cmpPath='';
535 } else if (substr(trim($GLOBALS['SOBE']->browser->curUrlInfo['info']),-1)!='/') {
536 $cmpPath=PATH_site.dirname($GLOBALS['SOBE']->browser->curUrlInfo['info']).'/';
537 } else {
538 $cmpPath=PATH_site.$GLOBALS['SOBE']->browser->curUrlInfo['info'];
539 }
540
541 // Traverse rows for the tree and print them into table rows:
542 foreach($treeArr as $k => $v) {
543 $c++;
544 $bgColorClass=($c+1)%2 ? 'bgColor' : 'bgColor-10';
545
546 // Creating blinking arrow, if applicable:
547 if (($GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'file' || $GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'folder') && $cmpPath == $v['row']['path']) {
548 $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
549 $bgColorClass='bgColor4';
550 } else {
551 $arrCol='<td></td>';
552 }
553 // Create arrow-bullet for file listing (if folder path is linkable):
554 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['row']['path']).'\');';
555 $cEbullet = $this->ext_isLinkable($v['row']) ? '<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/arrowbullet.gif','width="18" height="16"').' alt="" /></a>' : '';
556
557 // Put table row with folder together:
558 $out.='
559 <tr class="'.$bgColorClass.'">
560 <td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd_cs($v['row']['title'],$titleLen),$v['row']).'</td>
561 '.$arrCol.'
562 <td>'.$cEbullet.'</td>
563 </tr>';
564 }
565
566 $out='
567
568 <!--
569 Folder tree:
570 -->
571 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tree">
572 '.$out.'
573 </table>';
574 return $out;
575 }
576 }
577
578
579
580
581
582
583 /**
584 * Folder tree for the RTE - totally the same, no changes needed. (Just for the sake of beauty - or confusion... :-)
585 *
586 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
587 * @package TYPO3
588 * @subpackage core
589 */
590 class rteFolderTree extends localFolderTree {
591 }
592
593
594
595
596
597
598
599 /**
600 * For TBE File Browser
601 *
602 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
603 * @package TYPO3
604 * @subpackage core
605 */
606 class TBE_FolderTree extends localFolderTree {
607 var $ext_noTempRecyclerDirs=0; // If file-drag mode is set, temp and recycler folders are filtered out.
608
609 /**
610 * Returns true if the input "record" contains a folder which can be linked.
611 *
612 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
613 * @return boolean True is returned if the path is NOT a recycler or temp folder AND if ->ext_noTempRecyclerDirs is not set.
614 */
615 function ext_isLinkable($v) {
616 if ($this->ext_noTempRecyclerDirs && (substr($v['path'],-7)=='_temp_/' || substr($v['path'],-11)=='_recycler_/')) {
617 return 0;
618 } return 1;
619 }
620
621 /**
622 * Wrapping the title in a link, if applicable.
623 *
624 * @param string Title, ready for output.
625 * @param array The 'record'
626 * @return string Wrapping title string.
627 */
628 function wrapTitle($title,$v) {
629 $title = htmlspecialchars($title);
630
631 if ($this->ext_isLinkable($v)) {
632 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['path']).'\');';
633 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
634 } else {
635 return '<span class="typo3-dimmed">'.$title.'</span>';
636 }
637 }
638 }
639
640
641
642
643
644 /**
645 * class for the Element Browser window.
646 *
647 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
648 * @package TYPO3
649 * @subpackage core
650 */
651 class browse_links {
652
653 // Internal, static:
654 var $siteURL; // Current site URL (Frontend)
655 var $thisScript; // the script to link to
656 var $thisConfig; // RTE specific TSconfig
657 var $setTarget; // Target (RTE specific)
658 var $setClass; // CSS Class (RTE specific)
659 var $setTitle; // title (RTE specific)
660 var $doc; // Backend template object
661 var $elements = array(); // Holds information about files
662
663 // GPvars: (Input variables from outside)
664 /**
665 * The mode determines the main kind of output from the element browser.
666 * There are these options for values: rte, db, file, filedrag, wizard.
667 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
668 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
669 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
670 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
671 *
672 * @see main()
673 */
674 var $mode;
675
676 /**
677 * Link selector action.
678 * page,file,url,mail,spec are allowed values.
679 * These are only important with the link selector function and in that case they switch between the various menu options.
680 */
681 var $act;
682
683 /**
684 * When you click a page title/expand icon to see the content of a certain page, this value will contain that value (the ID of the expanded page). If the value is NOT set, then it will be restored from the module session data (see main(), mode="db")
685 */
686 var $expandPage;
687
688 /**
689 * When you click a folder name/expand icon to see the content of a certain file folder, this value will contain that value (the path of the expanded file folder). If the value is NOT set, then it will be restored from the module session data (see main(), mode="file"/"filedrag"). Example value: "/www/htdocs/typo3/32/3dsplm/fileadmin/css/"
690 */
691 var $expandFolder;
692
693
694
695 /**
696 * TYPO3 Element Browser, wizard mode parameters. There is a heap of parameters there, better debug() them out if you need something... :-)
697 */
698 var $P;
699
700 /**
701 * Active with TYPO3 Element Browser: Contains the name of the form field for which this window opens - thus allows us to make references back to the main window in which the form is.
702 * Example value: "data[pages][39][bodytext]|||tt_content|" or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
703 *
704 * Values:
705 * 0: form field name reference, eg. "data[tt_content][123][image]"
706 * 1: htlmArea RTE parameters: editorNo:contentTypo3Language:contentTypo3Charset
707 * 2: RTE config parameters: RTEtsConfigParams
708 * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
709 * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
710 * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
711 * 6: IRRE uniqueness: name of function in opener window that performs some additional(!) action, eg. "inline.setUniqueElement"
712 * 7: IRRE uniqueness: name of function in opener window that performs action instead of using addElement/insertElement, eg. "inline.importElement"
713 *
714 * $pArr = explode('|',$this->bparams);
715 * $formFieldName = $pArr[0];
716 * $allowedTablesOrFileTypes = $pArr[3];
717 */
718 var $bparams;
719
720 /**
721 * Used with the Rich Text Editor.
722 * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
723 */
724 var $RTEtsConfigParams;
725
726
727
728
729 /**
730 * Plus/Minus icon value. Used by the tree class to open/close notes on the trees.
731 */
732 var $PM;
733
734 /**
735 * Pointer, used when browsing a long list of records etc.
736 */
737 var $pointer;
738
739
740
741
742 /**
743 * Used with the link selector: Contains the GET input information about the CURRENT link in the RTE/TCEform field. This consists of "href", "target" and "title" keys. This information is passed around in links.
744 */
745 var $curUrlArray;
746
747 /**
748 * Used with the link selector: Contains a processed version of the input values from curUrlInfo. This is splitted into pageid, content element id, label value etc. This is used for the internal processing of that information.
749 */
750 var $curUrlInfo;
751
752 /**
753 * array which holds hook objects (initialised in init() )
754 */
755 protected $hookObjects = array();
756
757
758 /**
759 * object for t3lib_basicFileFunctions
760 */
761 public $fileProcessor;
762
763
764 /**
765 * Constructor:
766 * Initializes a lot of variables, setting JavaScript functions in header etc.
767 *
768 * @return void
769 */
770 function init() {
771 global $BE_USER,$BACK_PATH;
772
773 // Main GPvars:
774 $this->pointer = t3lib_div::_GP('pointer');
775 $this->bparams = t3lib_div::_GP('bparams');
776 $this->P = t3lib_div::_GP('P');
777 $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
778 $this->expandPage = t3lib_div::_GP('expandPage');
779 $this->expandFolder = t3lib_div::_GP('expandFolder');
780 $this->PM = t3lib_div::_GP('PM');
781
782 // Find "mode"
783 $this->mode = t3lib_div::_GP('mode');
784 if (!$this->mode) {
785 $this->mode = 'rte';
786 }
787 // Creating backend template object:
788 $this->doc = t3lib_div::makeInstance('template');
789 $this->doc->backPath = $GLOBALS['BACK_PATH'];
790 // Load the Prototype library and browse_links.js
791 $this->doc->getPageRenderer()->loadPrototype();
792 $this->doc->loadJavascriptLib('js/browse_links.js');
793
794 // init hook objects:
795 $this->hookObjects = array();
796 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
797 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
798 $processObject = t3lib_div::getUserObj($classData);
799
800 if(!($processObject instanceof t3lib_browseLinksHook)) {
801 throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195039394);
802 }
803
804 $parameters = array();
805 $processObject->init($this, $parameters);
806 $this->hookObjects[] = $processObject;
807 }
808 }
809
810 // Site URL
811 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
812
813 // the script to link to
814 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
815
816 // init fileProcessor
817 $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
818 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
819
820
821 // CurrentUrl - the current link url must be passed around if it exists
822 if ($this->mode == 'wizard') {
823 $currentLinkParts = t3lib_div::unQuoteFilenames($this->P['currentValue'], TRUE);
824 $initialCurUrlArray = array (
825 'href' => $currentLinkParts[0],
826 'target' => $currentLinkParts[1],
827 'class' => $currentLinkParts[2],
828 'title' => $currentLinkParts[3],
829 );
830 $this->curUrlArray = (is_array(t3lib_div::_GP('curUrl'))) ?
831 array_merge($initialCurUrlArray, t3lib_div::_GP('curUrl')) :
832 $initialCurUrlArray;
833 $this->curUrlInfo = $this->parseCurUrl($this->siteURL.'?id='.$this->curUrlArray['href'], $this->siteURL);
834 if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) { // pageid == 0 means that this is not an internal (page) link
835 if (file_exists(PATH_site.rawurldecode($this->curUrlArray['href']))) { // check if this is a link to a file
836 if (t3lib_div::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
837 $currentLinkParts[0] = substr($this->curUrlArray['href'], strlen(PATH_site));
838 }
839 $this->curUrlInfo = $this->parseCurUrl($this->siteURL.$this->curUrlArray['href'], $this->siteURL);
840 } elseif (strstr($this->curUrlArray['href'], '@')) { // check for email link
841 if (t3lib_div::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
842 $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
843 }
844 $this->curUrlInfo = $this->parseCurUrl('mailto:'.$this->curUrlArray['href'], $this->siteURL);
845 } else { // nothing of the above. this is an external link
846 if(strpos($this->curUrlArray['href'], '://') === false) {
847 $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
848 }
849 $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
850 }
851 } elseif (!$this->curUrlArray['href']) {
852 $this->curUrlInfo = array();
853 $this->act = 'page';
854 } else {
855 $this->curUrlInfo = $this->parseCurUrl($this->siteURL.'?id='.$this->curUrlArray['href'], $this->siteURL);
856 }
857 } else {
858 $this->curUrlArray = t3lib_div::_GP('curUrl');
859 if ($this->curUrlArray['all']) {
860 $this->curUrlArray=t3lib_div::get_tag_attributes($this->curUrlArray['all']);
861 }
862 $this->curUrlInfo=$this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
863 }
864
865 // Determine nature of current url:
866 $this->act=t3lib_div::_GP('act');
867 if (!$this->act) {
868 $this->act=$this->curUrlInfo['act'];
869 }
870
871 // Rich Text Editor specific configuration:
872 $addPassOnParams='';
873 if ((string)$this->mode == 'rte') {
874 $RTEtsConfigParts = explode(':',$this->RTEtsConfigParams);
875 $addPassOnParams.='&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams);
876 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
877 $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
878 }
879
880 // Initializing the target value (RTE)
881 $this->setTarget = ($this->curUrlArray['target'] != '-') ? $this->curUrlArray['target'] : '';
882 if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
883 $this->setTarget=$this->thisConfig['defaultLinkTarget'];
884 }
885
886 // Initializing the class value (RTE)
887 $this->setClass = ($this->curUrlArray['class'] != '-') ? $this->curUrlArray['class'] : '';
888
889 // Initializing the title value (RTE)
890 $this->setTitle = ($this->curUrlArray['title'] != '-') ? $this->curUrlArray['title'] : '';
891
892 // BEGIN accumulation of header JavaScript:
893 $JScode = '
894 // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
895 var add_href="'.($this->curUrlArray['href']?'&curUrl[href]='.rawurlencode($this->curUrlArray['href']):'').'";
896 var add_target="'.($this->setTarget?'&curUrl[target]='.rawurlencode($this->setTarget):'').'";
897 var add_class="'.($this->setClass ? '&curUrl[class]='.rawurlencode($this->setClass) : '').'";
898 var add_title="'.($this->setTitle?'&curUrl[title]='.rawurlencode($this->setTitle):'').'";
899 var add_params="'.($this->bparams?'&bparams='.rawurlencode($this->bparams):'').'";
900
901 var cur_href="'.($this->curUrlArray['href']?$this->curUrlArray['href']:'').'";
902 var cur_target="'.($this->setTarget?$this->setTarget:'').'";
903 var cur_class = "'.($this->setClass ? $this->setClass : '-').'";
904 var cur_title="'.($this->setTitle?$this->setTitle:'').'";
905
906 function browse_links_setTarget(target) { //
907 cur_target=target;
908 add_target="&curUrl[target]="+escape(target);
909 }
910 function browse_links_setClass(cssClass) { //
911 cur_class = cssClass;
912 add_class = "&curUrl[class]=" + escape(cssClass);
913 }
914 function browse_links_setTitle(title) { //
915 cur_title=title;
916 add_title="&curUrl[title]="+escape(title);
917 }
918 function browse_links_setValue(value) { //
919 cur_href=value;
920 add_href="&curUrl[href]="+value;
921 }
922 ';
923
924 if ($this->mode == 'wizard') { // Functions used, if the link selector is in wizard mode (= TCEforms fields)
925 if (!$this->areFieldChangeFunctionsValid()) {
926 $this->P['fieldChangeFunc'] = array();
927 }
928 unset($this->P['fieldChangeFunc']['alert']);
929 $update='';
930 foreach ($this->P['fieldChangeFunc'] as $k => $v) {
931 $update.= '
932 window.opener.'.$v;
933 }
934
935 $P2=array();
936 $P2['itemName']=$this->P['itemName'];
937 $P2['formName']=$this->P['formName'];
938 $P2['fieldChangeFunc']=$this->P['fieldChangeFunc'];
939 $P2['params']['allowedExtensions']=$this->P['params']['allowedExtensions'];
940 $P2['params']['blindLinkOptions']=$this->P['params']['blindLinkOptions'];
941 $addPassOnParams.=t3lib_div::implodeArrayForUrl('P',$P2);
942
943 $JScode.='
944 function link_typo3Page(id,anchor) { //
945 updateValueInMainForm(id + (anchor ? anchor : ""));
946 close();
947 return false;
948 }
949 function link_folder(folder) { //
950 updateValueInMainForm(folder);
951 close();
952 return false;
953 }
954 function link_current() { //
955 if (cur_href!="http://" && cur_href!="mailto:") {
956 returnBeforeCleaned = cur_href;
957 if (returnBeforeCleaned.substr(0, 7) == "http://") {
958 returnToMainFormValue = returnBeforeCleaned.substr(7);
959 } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
960 if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
961 returnToMainFormValue = returnBeforeCleaned.substr(14);
962 } else {
963 returnToMainFormValue = returnBeforeCleaned.substr(7);
964 }
965 } else {
966 returnToMainFormValue = returnBeforeCleaned;
967 }
968 updateValueInMainForm(returnToMainFormValue);
969 close();
970 }
971 return false;
972 }
973 function checkReference() { //
974 if (window.opener && window.opener.document && window.opener.document.'.$this->P['formName'].' && window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"] ) {
975 return window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"];
976 } else {
977 close();
978 }
979 }
980 function updateValueInMainForm(input) { //
981 var field = checkReference();
982 if (field) {
983 if (cur_target == "" && (cur_title != "" || cur_class != "-")) {
984 cur_target = "-";
985 }
986 if (cur_title == "" && cur_class == "-") {
987 cur_class = "";
988 }
989 cur_class = cur_class.replace(/[\'\"]/g, "");
990 if (cur_class.indexOf(" ") != -1) {
991 cur_class = "\"" + cur_class + "\"";
992 }
993 cur_title = cur_title.replace(/(^\")|(\"$)/g, "");
994 if (cur_title.indexOf(" ") != -1) {
995 cur_title = "\"" + cur_title + "\"";
996 }
997 input = input + " " + cur_target + " " + cur_class + " " + cur_title;
998 field.value = input;
999 '.$update.'
1000 }
1001 }
1002 ';
1003 } else { // Functions used, if the link selector is in RTE mode:
1004 $JScode.='
1005 function link_typo3Page(id,anchor) { //
1006 var theLink = \''.$this->siteURL.'?id=\'+id+(anchor?anchor:"");
1007 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
1008 return false;
1009 }
1010 function link_folder(folder) { //
1011 var theLink = \''.$this->siteURL.'\'+folder;
1012 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
1013 return false;
1014 }
1015 function link_spec(theLink) { //
1016 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
1017 return false;
1018 }
1019 function link_current() { //
1020 if (cur_href!="http://" && cur_href!="mailto:") {
1021 self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
1022 }
1023 return false;
1024 }
1025 ';
1026 }
1027
1028 // General "jumpToUrl" function:
1029 $JScode.='
1030 function jumpToUrl(URL,anchor) { //
1031 var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
1032 var add_mode = URL.indexOf("mode=")==-1 ? "&mode='.$this->mode.'" : "";
1033 var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'.($addPassOnParams?'+"'.$addPassOnParams.'"':'').'+(anchor?anchor:"");
1034 window.location.href = theLocation;
1035 return false;
1036 }
1037 ';
1038
1039
1040 /**
1041 * Splits parts of $this->bparams
1042 * @see $bparams
1043 */
1044 $pArr = explode('|',$this->bparams);
1045
1046 // This is JavaScript especially for the TBE Element Browser!
1047 $formFieldName = 'data['.$pArr[0].']['.$pArr[1].']['.$pArr[2].']';
1048
1049 // insertElement - Call check function (e.g. for uniqueness handling):
1050 if ($pArr[4] && $pArr[5]) {
1051 $JScodeCheck = '
1052 // Call a check function in the opener window (e.g. for uniqueness handling):
1053 if (parent.window.opener) {
1054 var res = parent.window.opener.'.$pArr[5].'("'.addslashes($pArr[4]).'",table,uid,type);
1055 if (!res.passed) {
1056 if (res.message) alert(res.message);
1057 performAction = false;
1058 }
1059 } else {
1060 alert("Error - reference to main window is not set properly!");
1061 parent.close();
1062 }
1063 ';
1064 }
1065 // insertElement - Call helper function:
1066 if ($pArr[4] && $pArr[6]) {
1067 $JScodeHelper = '
1068 // Call helper function to manage data in the opener window:
1069 if (parent.window.opener) {
1070 parent.window.opener.'.$pArr[6].'("'.addslashes($pArr[4]).'",table,uid,type,"'.addslashes($pArr[0]).'");
1071 } else {
1072 alert("Error - reference to main window is not set properly!");
1073 parent.close();
1074 }
1075 ';
1076 }
1077 // insertElement - perform action commands:
1078 if ($pArr[4] && $pArr[7]) {
1079 // Call user defined action function:
1080 $JScodeAction = '
1081 if (parent.window.opener) {
1082 parent.window.opener.'.$pArr[7].'("'.addslashes($pArr[4]).'",table,uid,type);
1083 focusOpenerAndClose(close);
1084 } else {
1085 alert("Error - reference to main window is not set properly!");
1086 parent.close();
1087 }
1088 ';
1089 } else if ($pArr[0] && !$pArr[1] && !$pArr[2]) {
1090 $JScodeAction = '
1091 addElement(filename,table+"_"+uid,fp,close);
1092 ';
1093 } else {
1094 $JScodeAction = '
1095 if (setReferences()) {
1096 parent.window.opener.group_change("add","'.$pArr[0].'","'.$pArr[1].'","'.$pArr[2].'",elRef,targetDoc);
1097 } else {
1098 alert("Error - reference to main window is not set properly!");
1099 }
1100 focusOpenerAndClose(close);
1101 ';
1102 }
1103
1104 $JScode.='
1105 var elRef="";
1106 var targetDoc="";
1107
1108 function launchView(url) { //
1109 var thePreviewWindow="";
1110 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");
1111 if (thePreviewWindow && thePreviewWindow.focus) {
1112 thePreviewWindow.focus();
1113 }
1114 }
1115 function setReferences() { //
1116 if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform && parent.window.opener.content.document.editform["'.$formFieldName.'"]) {
1117 targetDoc = parent.window.opener.content.document;
1118 elRef = targetDoc.editform["'.$formFieldName.'"];
1119 return true;
1120 } else {
1121 return false;
1122 }
1123 }
1124 function insertElement(table, uid, type, filename,fp,filetype,imagefile,action, close) { //
1125 var performAction = true;
1126 '.$JScodeCheck.'
1127 // Call performing function and finish this action:
1128 if (performAction) {
1129 '.$JScodeHelper.$JScodeAction.'
1130 }
1131 return false;
1132 }
1133 function addElement(elName,elValue,altElValue,close) { //
1134 if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
1135 parent.window.opener.setFormValueFromBrowseWin("'.$pArr[0].'",altElValue?altElValue:elValue,elName);
1136 focusOpenerAndClose(close);
1137 } else {
1138 alert("Error - reference to main window is not set properly!");
1139 parent.close();
1140 }
1141 }
1142 function focusOpenerAndClose(close) { //
1143 BrowseLinks.focusOpenerAndClose(close);
1144 }
1145 ';
1146
1147 // Finally, add the accumulated JavaScript to the template object:
1148 $this->doc->JScode.= $this->doc->wrapScriptTags($JScode);
1149
1150 // Debugging:
1151 if (FALSE) debug(array(
1152 'pointer' => $this->pointer,
1153 'act' => $this->act,
1154 'mode' => $this->mode,
1155 'curUrlInfo' => $this->curUrlInfo,
1156 'curUrlArray' => $this->curUrlArray,
1157 'P' => $this->P,
1158 'bparams' => $this->bparams,
1159 'RTEtsConfigParams' => $this->RTEtsConfigParams,
1160 'expandPage' => $this->expandPage,
1161 'expandFolder' => $this->expandFolder,
1162 'PM' => $this->PM,
1163 ),'Internal variables of Script Class:');
1164 }
1165
1166
1167 /**
1168 * Session data for this class can be set from outside with this method.
1169 * Call after init()
1170 *
1171 * @param array Session data array
1172 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
1173 */
1174 function processSessionData($data) {
1175 $store = false;
1176
1177 switch((string)$this->mode) {
1178 case 'db':
1179 if (isset($this->expandPage)) {
1180 $data['expandPage']=$this->expandPage;
1181 $store = true;
1182 } else {
1183 $this->expandPage=$data['expandPage'];
1184 }
1185 break;
1186 case 'file':
1187 case 'filedrag':
1188 case 'folder':
1189 if (isset($this->expandFolder)) {
1190 $data['expandFolder']=$this->expandFolder;
1191 $store = true;
1192 } else {
1193 $this->expandFolder=$data['expandFolder'];
1194 }
1195 break;
1196 }
1197
1198 return array($data, $store);
1199 }
1200
1201
1202
1203
1204 /******************************************************************
1205 *
1206 * Main functions
1207 *
1208 ******************************************************************/
1209
1210 /**
1211 * Rich Text Editor (RTE) link selector (MAIN function)
1212 * Generates the link selector for the Rich Text Editor.
1213 * Can also be used to select links for the TCEforms (see $wiz)
1214 *
1215 * @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
1216 * @return string Modified content variable.
1217 */
1218 function main_rte($wiz=0) {
1219 global $LANG, $BACK_PATH;
1220
1221 // Starting content:
1222 $content=$this->doc->startPage('RTE link');
1223
1224 // Initializing the action value, possibly removing blinded values etc:
1225 $allowedItems = array_diff(
1226 explode(',','page,file,folder,url,mail,spec'),
1227 t3lib_div::trimExplode(',',$this->thisConfig['blindLinkOptions'],1)
1228 );
1229 $allowedItems = array_diff(
1230 $allowedItems,
1231 t3lib_div::trimExplode(',',$this->P['params']['blindLinkOptions'])
1232 );
1233
1234 //call hook for extra options
1235 foreach($this->hookObjects as $hookObject) {
1236 $allowedItems = $hookObject->addAllowedItems($allowedItems);
1237 }
1238
1239 reset($allowedItems);
1240 if (!in_array($this->act,$allowedItems)) $this->act = current($allowedItems);
1241
1242 // Making menu in top:
1243 $menuDef = array();
1244 if (!$wiz) {
1245 $menuDef['removeLink']['isActive'] = $this->act=='removeLink';
1246 $menuDef['removeLink']['label'] = $LANG->getLL('removeLink',1);
1247 $menuDef['removeLink']['url'] = '#';
1248 $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
1249 }
1250 if (in_array('page',$allowedItems)) {
1251 $menuDef['page']['isActive'] = $this->act=='page';
1252 $menuDef['page']['label'] = $LANG->getLL('page',1);
1253 $menuDef['page']['url'] = '#';
1254 $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\'?act=page\');return false;"';
1255 }
1256 if (in_array('file',$allowedItems)){
1257 $menuDef['file']['isActive'] = $this->act=='file';
1258 $menuDef['file']['label'] = $LANG->getLL('file',1);
1259 $menuDef['file']['url'] = '#';
1260 $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\'?act=file\');return false;"';
1261 }
1262 if (in_array('folder',$allowedItems)){
1263 $menuDef['folder']['isActive'] = $this->act == 'folder';
1264 $menuDef['folder']['label'] = $LANG->getLL('folder', 1);
1265 $menuDef['folder']['url'] = '#';
1266 $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(\'?act=folder\');return false;"';
1267 }
1268 if (in_array('url',$allowedItems)) {
1269 $menuDef['url']['isActive'] = $this->act=='url';
1270 $menuDef['url']['label'] = $LANG->getLL('extUrl',1);
1271 $menuDef['url']['url'] = '#';
1272 $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\'?act=url\');return false;"';
1273 }
1274 if (in_array('mail',$allowedItems)) {
1275 $menuDef['mail']['isActive'] = $this->act=='mail';
1276 $menuDef['mail']['label'] = $LANG->getLL('email',1);
1277 $menuDef['mail']['url'] = '#';
1278 $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\'?act=mail\');return false;"';
1279 }
1280 if (is_array($this->thisConfig['userLinks.']) && in_array('spec',$allowedItems)) {
1281 $menuDef['spec']['isActive'] = $this->act=='spec';
1282 $menuDef['spec']['label'] = $LANG->getLL('special',1);
1283 $menuDef['spec']['url'] = '#';
1284 $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec\');return false;"';
1285 }
1286
1287 // call hook for extra options
1288 foreach($this->hookObjects as $hookObject) {
1289 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
1290 }
1291
1292 $content .= $this->doc->getTabMenuRaw($menuDef);
1293
1294 // Adding the menu and header to the top of page:
1295 $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
1296
1297 // Depending on the current action we will create the actual module content for selecting a link:
1298 switch($this->act) {
1299 case 'mail':
1300 $extUrl='
1301
1302 <!--
1303 Enter mail address:
1304 -->
1305 <form action="" name="lurlform" id="lurlform">
1306 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
1307 <tr>
1308 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', 1) . ':</td>
1309 <td><input type="text" name="lemail"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='mail'?$this->curUrlInfo['info']:'').'" /> '.
1310 '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
1311 </tr>
1312 </table>
1313 </form>';
1314 $content.=$extUrl;
1315 break;
1316 case 'url':
1317 $extUrl='
1318
1319 <!--
1320 Enter External URL:
1321 -->
1322 <form action="" name="lurlform" id="lurlform">
1323 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
1324 <tr>
1325 <td style="width: 96px;">URL:</td>
1326 <td><input type="text" name="lurl"'.$this->doc->formWidth(30).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
1327 '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
1328 </tr>
1329 </table>
1330 </form>';
1331 $content.=$extUrl;
1332 break;
1333 case 'file':
1334 case 'folder':
1335 $foldertree = t3lib_div::makeInstance('rteFolderTree');
1336 $foldertree->thisScript = $this->thisScript;
1337 $tree = $foldertree->getBrowsableTree();
1338
1339 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
1340 $cmpPath = '';
1341 } elseif (substr(trim($this->curUrlInfo['info']), -1) != '/') {
1342 $cmpPath = PATH_site.dirname($this->curUrlInfo['info']).'/';
1343 if (!isset($this->expandFolder)) {
1344 $this->expandFolder = $cmpPath;
1345 }
1346 } else {
1347 $cmpPath = PATH_site.$this->curUrlInfo['info'];
1348 if (!isset($this->expandFolder) && $this->curUrlInfo['act'] == 'folder') {
1349 $this->expandFolder = $cmpPath;
1350 }
1351 }
1352
1353 list(, , $specUid) = explode('_', $this->PM);
1354 $files = $this->expandFolder(
1355 $foldertree->specUIDmap[$specUid],
1356 $this->P['params']['allowedExtensions']
1357 );
1358 $content.= '
1359
1360 <!--
1361 Wrapper table for folder tree / file/folder list:
1362 -->
1363 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
1364 <tr>
1365 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('folderTree').':').$tree.'</td>
1366 <td class="c-wCell" valign="top">'.$files.'</td>
1367 </tr>
1368 </table>
1369 ';
1370 break;
1371 case 'spec':
1372 if (is_array($this->thisConfig['userLinks.'])) {
1373 $subcats=array();
1374 $v=$this->thisConfig['userLinks.'];
1375 foreach ($v as $k2 => $value) {
1376 $k2i = intval($k2);
1377 if (substr($k2,-1)=='.' && is_array($v[$k2i.'.'])) {
1378
1379 // Title:
1380 $title = trim($v[$k2i]);
1381 if (!$title) {
1382 $title=$v[$k2i.'.']['url'];
1383 } else {
1384 $title=$LANG->sL($title);
1385 }
1386 // Description:
1387 $description=$v[$k2i.'.']['description'] ? $LANG->sL($v[$k2i.'.']['description'],1).'<br />' : '';
1388
1389 // URL + onclick event:
1390 $onClickEvent='';
1391 if (isset($v[$k2i.'.']['target'])) $onClickEvent.="browse_links_setTarget('".$v[$k2i.'.']['target']."');";
1392 $v[$k2i.'.']['url'] = str_replace('###_URL###',$this->siteURL,$v[$k2i.'.']['url']);
1393 if (substr($v[$k2i.'.']['url'],0,7)=='http://' || substr($v[$k2i.'.']['url'],0,7)=='mailto:') {
1394 $onClickEvent.="cur_href=unescape('".rawurlencode($v[$k2i.'.']['url'])."');link_current();";
1395 } else {
1396 $onClickEvent.="link_spec(unescape('".$this->siteURL.rawurlencode($v[$k2i.'.']['url'])."'));";
1397 }
1398
1399 // Link:
1400 $A=array('<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">','</a>');
1401
1402 // Adding link to menu of user defined links:
1403 $subcats[$k2i]='
1404 <tr>
1405 <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>
1406 </tr>';
1407 }
1408 }
1409
1410 // Sort by keys:
1411 ksort($subcats);
1412
1413 // Add menu to content:
1414 $content.= '
1415
1416 <!--
1417 Special userdefined menu:
1418 -->
1419 <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
1420 <tr>
1421 <td class="bgColor5" class="c-wCell" valign="top"><strong>'.$LANG->getLL('special',1).'</strong></td>
1422 </tr>
1423 '.implode('',$subcats).'
1424 </table>
1425 ';
1426 }
1427 break;
1428 case 'page':
1429 $pagetree = t3lib_div::makeInstance('rtePageTree');
1430 $pagetree->thisScript = $this->thisScript;
1431 $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1432 $tree=$pagetree->getBrowsableTree();
1433 $cElements = $this->expandPage();
1434
1435 // Outputting Temporary DB mount notice:
1436 if (intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'))) {
1437 $link = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => 0))) . '">' .
1438 $LANG->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount', 1) .
1439 '</a>';
1440 $flashMessage = t3lib_div::makeInstance(
1441 't3lib_FlashMessage',
1442 $link,
1443 '',
1444 t3lib_FlashMessage::INFO
1445 );
1446 $dbmount = $flashMessage->render();
1447 }
1448
1449 $content.= '
1450
1451 <!--
1452 Wrapper table for page tree / record list:
1453 -->
1454 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
1455 <tr>
1456 <td class="c-wCell" valign="top">' . $this->barheader($GLOBALS['LANG']->getLL('pageTree') . ':') . $dbmount . $tree . '</td>
1457 <td class="c-wCell" valign="top">'.$cElements.'</td>
1458 </tr>
1459 </table>
1460 ';
1461 break;
1462 default:
1463 //call hook
1464 foreach($this->hookObjects as $hookObject) {
1465 $content .= $hookObject->getTab($this->act);
1466 }
1467 break;
1468 }
1469
1470 $content .= '
1471
1472 <!--
1473 Selecting class for link:
1474 -->
1475 <form action="" name="lclassform" id="lclassform">
1476 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
1477 <tr>
1478 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', 1) . '</td>
1479 <td><input type="text" name="lclass" onchange="browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass) . '"' . $this->doc->formWidth(10) . ' /></td>
1480 </tr>
1481 </table>
1482 </form>
1483
1484 <!--
1485 Selecting title for link:
1486 -->
1487 <form action="" name="ltitleform" id="ltitleform">
1488 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
1489 <tr>
1490 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', 1) . '</td>
1491 <td><input type="text" name="ltitle" onchange="browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle) . '"' . $this->doc->formWidth(10) . ' /></td>
1492 </tr>
1493 </table>
1494 </form>
1495 ';
1496
1497 // Target:
1498 if ($this->act!='mail') {
1499 $ltarget='
1500
1501
1502
1503 <!--
1504 Selecting target for link:
1505 -->
1506 <form action="" name="ltargetform" id="ltargetform">
1507 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1508 <tr>
1509 <td>'.$GLOBALS['LANG']->getLL('target',1).':</td>
1510 <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="' . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
1511 <td>
1512 <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;">
1513 <option></option>
1514 <option value="_top">'.$GLOBALS['LANG']->getLL('top',1).'</option>
1515 <option value="_blank">'.$GLOBALS['LANG']->getLL('newWindow',1).'</option>
1516 </select>
1517 </td>
1518 <td>';
1519 if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act) {
1520 $ltarget.='
1521 <input type="submit" value="'.$GLOBALS['LANG']->getLL('update',1).'" onclick="return link_current();" />';
1522 }
1523
1524 $selectJS = '
1525 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) {
1526 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;
1527 browse_links_setTarget(document.ltargetform.ltarget.value);
1528 browse_links_setClass(document.lclassform.lclass.value);
1529 browse_links_setTitle(document.ltitleform.ltitle.value);
1530 document.ltargetform.popup_width.selectedIndex=0;
1531 document.ltargetform.popup_height.selectedIndex=0;
1532 }
1533 ';
1534
1535 $ltarget.=' </td>
1536 </tr>
1537 <tr>
1538 <td>'.$GLOBALS['LANG']->getLL('target_popUpWindow',1).':</td>
1539 <td colspan="3">
1540 <select name="popup_width" onchange="'.htmlspecialchars($selectJS).'">
1541 <option value="0">'.$GLOBALS['LANG']->getLL('target_popUpWindow_width',1).'</option>
1542 <option value="300">300</option>
1543 <option value="400">400</option>
1544 <option value="500">500</option>
1545 <option value="600">600</option>
1546 <option value="700">700</option>
1547 <option value="800">800</option>
1548 </select>
1549 x
1550 <select name="popup_height" onchange="'.htmlspecialchars($selectJS).'">
1551 <option value="0">'.$GLOBALS['LANG']->getLL('target_popUpWindow_height',1).'</option>
1552 <option value="200">200</option>
1553 <option value="300">300</option>
1554 <option value="400">400</option>
1555 <option value="500">500</option>
1556 <option value="600">600</option>
1557 </select>
1558 </td>
1559 </tr>
1560 </table>
1561 </form>';
1562
1563 // Add "target selector" box to content:
1564 $content.=$ltarget;
1565
1566 // Add some space
1567 $content.='<br /><br />';
1568 }
1569
1570 // End page, return content:
1571 $content.= $this->doc->endPage();
1572 $content = $this->doc->insertStylesAndJS($content);
1573 return $content;
1574 }
1575
1576 /**
1577 * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1578 *
1579 * @return string HTML content for the module
1580 */
1581 function main_db() {
1582
1583 // Starting content:
1584 $content=$this->doc->startPage('TBE record selector');
1585
1586 // Init variable:
1587 $pArr = explode('|',$this->bparams);
1588
1589 // Making the browsable pagetree:
1590 $pagetree = t3lib_div::makeInstance('TBE_PageTree');
1591 $pagetree->thisScript=$this->thisScript;
1592 $pagetree->ext_pArrPages = !strcmp($pArr[3],'pages')?1:0;
1593 $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1594 $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1595 $pagetree->addField('nav_title');
1596 $tree=$pagetree->getBrowsableTree();
1597
1598 // Making the list of elements, if applicable:
1599 $cElements = $this->TBE_expandPage($pArr[3]);
1600
1601 // Putting the things together, side by side:
1602 $content.= '
1603
1604 <!--
1605 Wrapper table for page tree / record list:
1606 -->
1607 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1608 <tr>
1609 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('pageTree').':').$tree.'</td>
1610 <td class="c-wCell" valign="top">'.$cElements.'</td>
1611 </tr>
1612 </table>
1613 ';
1614
1615 // Add some space
1616 $content.='<br /><br />';
1617
1618 // End page, return content:
1619 $content.= $this->doc->endPage();
1620 $content = $this->doc->insertStylesAndJS($content);
1621 return $content;
1622 }
1623
1624 /**
1625 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1626 *
1627 * @return string HTML content for the module
1628 */
1629 function main_file() {
1630 global $BE_USER;
1631
1632 // Starting content:
1633 $content.=$this->doc->startPage('TBE file selector');
1634
1635 // Init variable:
1636 $pArr = explode('|',$this->bparams);
1637
1638 // Create upload/create folder forms, if a path is given:
1639 $path=$this->expandFolder;
1640 if (!$path || !@is_dir($path)) {
1641 // The closest TEMP-path is found
1642 $path = $this->fileProcessor->findTempFolder().'/';
1643 }
1644 if ($path!='/' && @is_dir($path)) {
1645 $uploadForm=$this->uploadForm($path);
1646 $createFolder=$this->createFolder($path);
1647 } else {
1648 $createFolder='';
1649 $uploadForm='';
1650 }
1651 if ($BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) $content.=$uploadForm;
1652
1653 // Getting flag for showing/not showing thumbnails:
1654 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1655
1656 if (!$noThumbs) {
1657 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1658 $_MOD_MENU = array('displayThumbs' => '');
1659 $_MCONF['name']='file_list';
1660 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
1661 $addParams = '&act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
1662 $thumbNailCheck = t3lib_BEfunc::getFuncCheck('','SET[displayThumbs]',$_MOD_SETTINGS['displayThumbs'],$this->thisScript,$addParams,'id="checkDisplayThumbs"').' <label for="checkDisplayThumbs">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs',1).'</label>';
1663 } else {
1664 $thumbNailCheck='';
1665 }
1666 $noThumbs = $noThumbs ? $noThumbs : !$_MOD_SETTINGS['displayThumbs'];
1667
1668 // Create folder tree:
1669 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
1670 $foldertree->thisScript=$this->thisScript;
1671 $foldertree->ext_noTempRecyclerDirs = ($this->mode == 'filedrag');
1672 $tree=$foldertree->getBrowsableTree();
1673
1674 list(,,$specUid) = explode('_',$this->PM);
1675
1676 if ($this->mode=='filedrag') {
1677 $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid],$pArr[3]);
1678 } else {
1679 $files = $this->TBE_expandFolder($foldertree->specUIDmap[$specUid],$pArr[3],$noThumbs);
1680 }
1681
1682 // Putting the parts together, side by side:
1683 $content.= '
1684
1685 <!--
1686 Wrapper table for folder tree / file list:
1687 -->
1688 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1689 <tr>
1690 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('folderTree').':').$tree.'</td>
1691 <td class="c-wCell" valign="top">'.$files.'</td>
1692 </tr>
1693 </table>
1694 ';
1695 $content.= $thumbNailCheck;
1696
1697 // Adding create folder + upload forms if applicable:
1698 if (!$BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) $content.=$uploadForm;
1699 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.createFoldersInEB')) $content.=$createFolder;
1700
1701 // Add some space
1702 $content.='<br /><br />';
1703
1704 // Setup indexed elements:
1705 $this->doc->JScode.= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1706 // Ending page, returning content:
1707 $content.= $this->doc->endPage();
1708 $content = $this->doc->insertStylesAndJS($content);
1709
1710 return $content;
1711 }
1712
1713 /**
1714 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1715 *
1716 * @return string HTML content for the module
1717 */
1718 function main_folder() {
1719 global $BE_USER;
1720
1721 // Starting content:
1722 $content = $this->doc->startPage('TBE folder selector');
1723
1724 // Init variable:
1725 $parameters = explode('|', $this->bparams);
1726
1727
1728 $path = $this->expandFolder;
1729 if (!$path || !@is_dir($path)) {
1730 // The closest TEMP-path is found
1731 $path = $this->fileProcessor->findTempFolder().'/';
1732 }
1733 if ($path != '/' && @is_dir($path)) {
1734 $createFolder = $this->createFolder($path);
1735 } else {
1736 $createFolder='';
1737 }
1738
1739 // Create folder tree:
1740 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
1741 $foldertree->thisScript = $this->thisScript;
1742 $foldertree->ext_noTempRecyclerDirs = ($this->mode == 'filedrag');
1743 $tree = $foldertree->getBrowsableTree(false);
1744
1745 list(, , $specUid) = explode('_', $this->PM);
1746
1747 if($this->mode == 'filedrag') {
1748 $folders = $this->TBE_dragNDrop(
1749 $foldertree->specUIDmap[$specUid],
1750 $parameters[3]
1751 );
1752 } else {
1753 $folders = $this->TBE_expandSubFolders($foldertree->specUIDmap[$specUid]);
1754 }
1755
1756 // Putting the parts together, side by side:
1757 $content.= '
1758
1759 <!--
1760 Wrapper table for folder tree / folder list:
1761 -->
1762 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1763 <tr>
1764 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('folderTree').':').$tree.'</td>
1765 <td class="c-wCell" valign="top">'.$folders.'</td>
1766 </tr>
1767 </table>
1768 ';
1769
1770 // Adding create folder if applicable:
1771 if($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.createFoldersInEB')) {
1772 $content .= $createFolder;
1773 }
1774
1775 // Add some space
1776 $content .= '<br /><br />';
1777
1778 // Ending page, returning content:
1779 $content.= $this->doc->endPage();
1780 $content = $this->doc->insertStylesAndJS($content);
1781
1782 return $content;
1783 }
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801 /******************************************************************
1802 *
1803 * Record listing
1804 *
1805 ******************************************************************/
1806 /**
1807 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1808 *
1809 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1810 */
1811 function expandPage() {
1812 global $BE_USER, $BACK_PATH;
1813
1814 $out='';
1815 $expPageId = $this->expandPage; // Set page id (if any) to expand
1816
1817 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1818 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1819 $expPageId = $this->curUrlInfo['pageid']; // Set to the current link page id.
1820 }
1821
1822 // Draw the record list IF there is a page id to expand:
1823 if ($expPageId && t3lib_div::testInt($expPageId) && $BE_USER->isInWebMount($expPageId)) {
1824
1825 // Set header:
1826 $out.=$this->barheader($GLOBALS['LANG']->getLL('contentElements').':');
1827
1828 // Create header for listing, showing the page title/icon:
1829 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1830 $mainPageRec = t3lib_BEfunc::getRecordWSOL('pages',$expPageId);
1831 $picon = t3lib_iconWorks::getSpriteIconForRecord('pages', $mainPageRec);
1832 $picon.= htmlspecialchars(t3lib_div::fixed_lgd_cs($mainPageRec['title'],$titleLen));
1833 $out.=$picon.'<br />';
1834
1835 // Look up tt_content elements from the expanded page:
1836 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1837 'uid,header,hidden,starttime,endtime,fe_group,CType,colpos,bodytext',
1838 'tt_content',
1839 'pid='.intval($expPageId).
1840 t3lib_BEfunc::deleteClause('tt_content').
1841 t3lib_BEfunc::versioningPlaceholderClause('tt_content'),
1842 '',
1843 'colpos,sorting'
1844 );
1845 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1846
1847 // Traverse list of records:
1848 $c=0;
1849 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1850 $c++;
1851 $icon = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $row);
1852 if ($this->curUrlInfo['act']=='page' && $this->curUrlInfo['cElement']==$row['uid']) {
1853 $arrCol='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="c-blinkArrowL" alt="" />';
1854 } else {
1855 $arrCol='';
1856 }
1857 // Putting list element HTML together:
1858 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($c==$cc?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
1859 $arrCol.
1860 '<a href="#" onclick="return link_typo3Page(\''.$expPageId.'\',\'#'.$row['uid'].'\');">'.
1861 $icon.
1862 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['header'],$titleLen)).
1863 '</a><br />';
1864
1865 // Finding internal anchor points:
1866 if (t3lib_div::inList('text,textpic', $row['CType'])) {
1867 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1868
1869 foreach($split as $skey => $sval) {
1870 if (($skey%3)==2) {
1871 // Putting list element HTML together:
1872 $sval = substr($sval,0,100);
1873 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
1874 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($skey+3>count($split)?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
1875 '<a href="#" onclick="return link_typo3Page(\''.$expPageId.'\',\'#'.rawurlencode($sval).'\');">'.
1876 htmlspecialchars(' <A> '.$sval).
1877 '</a><br />';
1878 }
1879 }
1880 }
1881 }
1882 }
1883 return $out;
1884 }
1885
1886 /**
1887 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1888 *
1889 * @param string Commalist of tables. Set to "*" if you want all tables.
1890 * @return string HTML output.
1891 */
1892 function TBE_expandPage($tables) {
1893 global $TCA,$BE_USER, $BACK_PATH;
1894
1895 $out='';
1896 if ($this->expandPage>=0 && t3lib_div::testInt($this->expandPage) && $BE_USER->isInWebMount($this->expandPage)) {
1897
1898 // Set array with table names to list:
1899 if (!strcmp(trim($tables),'*')) {
1900 $tablesArr = array_keys($TCA);
1901 } else {
1902 $tablesArr = t3lib_div::trimExplode(',',$tables,1);
1903 }
1904 reset($tablesArr);
1905
1906 // Headline for selecting records:
1907 $out.=$this->barheader($GLOBALS['LANG']->getLL('selectRecords').':');
1908
1909 // Create the header, showing the current page for which the listing is. Includes link to the page itself, if pages are amount allowed tables.
1910 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1911 $mainPageRec = t3lib_BEfunc::getRecordWSOL('pages',$this->expandPage);
1912 $ATag='';
1913 $ATag_e='';
1914 $ATag2='';
1915 if (in_array('pages',$tablesArr)) {
1916 $ficon=t3lib_iconWorks::getIcon('pages',$mainPageRec);
1917 $ATag="<a href=\"#\" onclick=\"return insertElement('pages', '".$mainPageRec['uid']."', 'db', ".t3lib_div::quoteJSvalue($mainPageRec['title']).", '', '', '".$ficon."','',1);\">";
1918 $ATag2="<a href=\"#\" onclick=\"return insertElement('pages', '".$mainPageRec['uid']."', 'db', ".t3lib_div::quoteJSvalue($mainPageRec['title']).", '', '', '".$ficon."','',0);\">";
1919 $ATag_alt=substr($ATag,0,-4).",'',1);\">";
1920 $ATag_e='</a>';
1921 }
1922 $picon=t3lib_iconWorks::getSpriteIconForRecord('pages', $mainPageRec);
1923 $pBicon=$ATag2?'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' alt="" />':'';
1924 $pText=htmlspecialchars(t3lib_div::fixed_lgd_cs($mainPageRec['title'],$titleLen));
1925 $out.=$picon.$ATag2.$pBicon.$ATag_e.$ATag.$pText.$ATag_e.'<br />';
1926
1927 // Initialize the record listing:
1928 $id = $this->expandPage;
1929 $pointer = t3lib_div::intInRange($this->pointer,0,100000);
1930 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1931 $pageinfo = t3lib_BEfunc::readPageAccess($id,$perms_clause);
1932 $table='';
1933
1934 // Generate the record list:
1935 $dblist = t3lib_div::makeInstance('TBE_browser_recordList');
1936 $dblist->thisScript=$this->thisScript;
1937 $dblist->backPath = $GLOBALS['BACK_PATH'];
1938 $dblist->thumbs = 0;
1939 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
1940 $dblist->noControlPanels=1;
1941 $dblist->clickMenuEnabled=0;
1942 $dblist->tableList=implode(',',$tablesArr);
1943
1944 $dblist->start($id,t3lib_div::_GP('table'),$pointer,
1945 t3lib_div::_GP('search_field'),
1946 t3lib_div::_GP('search_levels'),
1947 t3lib_div::_GP('showLimit')
1948 );
1949 $dblist->setDispFields();
1950 $dblist->generateList();
1951 $dblist->writeBottom();
1952
1953 // Add the HTML for the record list to output variable:
1954 $out.=$dblist->HTMLcode;
1955
1956 // Add support for fieldselectbox in singleTableMode
1957 if ($dblist->table) {
1958 $out.= $dblist->fieldSelectBox($dblist->table);
1959 }
1960
1961 $out.=$dblist->getSearchBox();
1962 }
1963
1964 // Return accumulated content:
1965 return $out;
1966 }
1967
1968
1969 /**
1970 * Render list of folders inside a folder.
1971 *
1972 * @param string string of the current folder
1973 * @return string HTML output
1974 */
1975 function TBE_expandSubFolders($expandFolder=0) {
1976 $content = '';
1977
1978 $expandFolder = $expandFolder ?
1979 $expandFolder :
1980 $this->expandFolder;
1981
1982 if($expandFolder && $this->checkFolder($expandFolder)) {
1983 if(t3lib_div::isFirstPartOfStr($expandFolder, PATH_site)) {
1984 $rootFolder = substr($expandFolder, strlen(PATH_site));
1985 }
1986
1987 $folders = array();
1988
1989 // Listing the folders:
1990 $folders = t3lib_div::get_dirs($expandFolder);
1991 if(count($folders) > 0) {
1992 foreach($folders as $index => $folder) {
1993 $folders[$index] = $rootFolder.$folder.'/';
1994 }
1995 }
1996 $content.= $this->folderList($rootFolder, $folders);
1997 }
1998
1999 // Return accumulated content for folderlisting:
2000 return $content;
2001 }
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013 /******************************************************************
2014 *
2015 * File listing
2016 *
2017 ******************************************************************/
2018 /**
2019 * For RTE: This displays all files from folder. No thumbnails shown
2020 *
2021 * @param string The folder path to expand
2022 * @param string List of fileextensions to show
2023 * @return string HTML output
2024 */
2025 function expandFolder($expandFolder=0,$extensionList='') {
2026 global $BACK_PATH;
2027
2028 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
2029 $out='';
2030 if ($expandFolder && $this->checkFolder($expandFolder)) {
2031
2032 // Create header for filelisting:
2033 $out.=$this->barheader($GLOBALS['LANG']->getLL('files').':');
2034
2035 // Prepare current path value for comparison (showing red arrow)
2036 if (!$this->curUrlInfo['value']) {
2037 $cmpPath='';
2038 } else {
2039 $cmpPath=PATH_site.$this->curUrlInfo['info'];
2040 }
2041
2042
2043 // Create header element; The folder from which files are listed.
2044 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
2045 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
2046 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
2047 $picon='<a href="#" onclick="return link_folder(\''.t3lib_div::rawUrlEncodeFP(substr($expandFolder,strlen(PATH_site))).'\');">'.$picon.'</a>';
2048 if ($this->curUrlInfo['act'] == 'folder' && $cmpPath == $expandFolder) {
2049 $out.= '<img'.t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
2050 }
2051 $out.=$picon.'<br />';
2052
2053 // Get files from the folder:
2054 if ($this->mode == 'wizard' && $this->act == 'folder') {
2055 $files = t3lib_div::get_dirs($expandFolder);
2056 } else {
2057 $files = t3lib_div::getFilesInDir($expandFolder, $extensionList, 1, 1); // $extensionList='', $prependPath=0, $order='')
2058 }
2059
2060 $c=0;
2061 $cc=count($files);
2062 if (is_array($files)) {
2063 foreach($files as $filepath) {
2064 $c++;
2065 $fI=pathinfo($filepath);
2066
2067 if ($this->mode == 'wizard' && $this->act == 'folder') {
2068 $filepath = $expandFolder.$filepath.'/';
2069 $icon = '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
2070 } else {
2071 // File icon:
2072 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
2073
2074 // Get size and icon:
2075 $size = ' (' . t3lib_div::formatSize(filesize($filepath)) . 'bytes)';
2076 $icon = '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/fileicons/' . $icon . '', 'width="18" height="16"') . ' title="' . htmlspecialchars($fI['basename'] . $size) . '" alt="" />';
2077 }
2078
2079 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
2080 if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $cmpPath == $filepath) {
2081 $arrCol='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="c-blinkArrowL" alt="" />';
2082 } else {
2083 $arrCol='';
2084 }
2085
2086 // Put it all together for the file element:
2087 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($c==$cc?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
2088 $arrCol.
2089 '<a href="#" onclick="return link_folder(\''.t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site))).'\');">'.
2090 $icon.
2091 htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).
2092 '</a><br />';
2093 }
2094 }
2095 }
2096 return $out;
2097 }
2098
2099 /**
2100 * For TYPO3 Element Browser: Expand folder of files.
2101 *
2102 * @param string The folder path to expand
2103 * @param string List of fileextensions to show
2104 * @param boolean Whether to show thumbnails or not. If set, no thumbnails are shown.
2105 * @return string HTML output
2106 */
2107 function TBE_expandFolder($expandFolder=0,$extensionList='',$noThumbs=0) {
2108 global $LANG;
2109
2110 $extensionList = ($extensionList == '*') ? '' : $extensionList;
2111 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
2112 $out='';
2113 if ($expandFolder && $this->checkFolder($expandFolder)) {
2114 // Listing the files:
2115 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
2116 $out.= $this->fileList($files, $expandFolder, $noThumbs);
2117 }
2118
2119 // Return accumulated content for filelisting:
2120 return $out;
2121 }
2122
2123 /**
2124 * Render list of files.
2125 *
2126 * @param array List of files. See t3lib_div::getFilesInDir
2127 * @param string If set a header with a folder icon and folder name are shown
2128 * @param boolean Whether to show thumbnails or not. If set, no thumbnails are shown.
2129 * @return string HTML output
2130 */
2131 function fileList($files, $folderName='', $noThumbs=0) {
2132 global $LANG, $BACK_PATH;
2133
2134 $out='';
2135
2136 // Listing the files:
2137 if (is_array($files)) {
2138
2139 // Create headline (showing number of files):
2140 $filesCount = count($files);
2141 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):', $filesCount));
2142 $out.=$this->getBulkSelector($filesCount);
2143
2144 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
2145
2146 // Create the header of current folder:
2147 if($folderName) {
2148 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
2149 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($folderName),$titleLen));
2150 $out.=$picon.'<br />';
2151 }
2152
2153 // Init graphic object for reading file dimensions:
2154 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
2155 $imgObj->init();
2156 $imgObj->mayScaleUp=0;
2157 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
2158
2159 // Traverse the file list:
2160 $lines=array();
2161 foreach($files as $filepath) {
2162 $fI=pathinfo($filepath);
2163
2164 // Thumbnail/size generation:
2165 if (t3lib_div::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),strtolower($fI['extension'])) && !$noThumbs) {
2166 $imgInfo = $imgObj->getImageDimensions($filepath);
2167 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
2168 $clickIcon = t3lib_BEfunc::getThumbNail($BACK_PATH.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"');
2169 } else {
2170 $clickIcon = '';
2171 $pDim = '';
2172 }
2173
2174 // Create file icon:
2175 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
2176 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
2177 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" class="absmiddle" alt="" />';
2178
2179 // Create links for adding the file:
2180 if (strstr($filepath,',') || strstr($filepath,'|')) { // In case an invalid character is in the filepath, display error message:
2181 $eMsg = $LANG->JScharCode(sprintf($LANG->getLL('invalidChar'),', |'));
2182 $ATag = $ATag_alt = "<a href=\"#\" onclick=\"alert(".$eMsg.");return false;\">";
2183 $bulkCheckBox = '';
2184 } else { // If filename is OK, just add it:
2185 $filesIndex = count($this->elements);
2186 $this->elements['file_'.$filesIndex] = array(
2187 'md5' => t3lib_div::shortMD5($filepath),
2188 'type' => 'file',
2189 'fileName' => $fI['basename'],
2190 'filePath' => $filepath,
2191 'fileExt' => $fI['extension'],
2192 'fileIcon' => $ficon,
2193 );
2194 $ATag = "<a href=\"#\" onclick=\"return BrowseLinks.File.insertElement('file_$filesIndex');\">";
2195 $ATag_alt = substr($ATag,0,-4).",1);\">";
2196 $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_'.$filesIndex.'" value="0" /> ';
2197 }
2198 $ATag_e='</a>';
2199
2200 // Create link to showing details about the file in a window:
2201 $Ahref = $BACK_PATH.'show_item.php?table='.rawurlencode($filepath).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
2202 $ATag2='<a href="'.htmlspecialchars($Ahref).'">';
2203 $ATag2_e='</a>';
2204
2205 // Combine the stuff:
2206 $filenameAndIcon=$bulkCheckBox.$ATag_alt.$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).$ATag_e;
2207
2208 // Show element:
2209 if ($pDim) { // Image...
2210 $lines[]='
2211 <tr class="bgColor4">
2212 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
2213 <td>'.$ATag.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$LANG->getLL('addToList',1).'" alt="" />'.$ATag_e.'</td>
2214 <td nowrap="nowrap">'.($ATag2.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/zoom2.gif','width="12" height="12"').' title="'.$LANG->getLL('info',1).'" alt="" /> '.$LANG->getLL('info',1).$ATag2_e).'</td>
2215 <td nowrap="nowrap">&nbsp;'.$pDim.'</td>
2216 </tr>';
2217 $lines[]='
2218 <tr>
2219 <td colspan="4">'.$ATag_alt.$clickIcon.$ATag_e.'</td>
2220 </tr>';
2221 } else {
2222 $lines[]='
2223 <tr class="bgColor4">
2224 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
2225 <td>'.$ATag.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$LANG->getLL('addToList',1).'" alt="" />'.$ATag_e.'</td>
2226 <td nowrap="nowrap">'.($ATag2.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/zoom2.gif','width="12" height="12"').' title="'.$LANG->getLL('info',1).'" alt="" /> '.$LANG->getLL('info',1).$ATag2_e).'</td>
2227 <td>&nbsp;</td>
2228 </tr>';
2229 }
2230 $lines[]='
2231 <tr>
2232 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
2233 </tr>';
2234 }
2235
2236 // Wrap all the rows in table tags:
2237 $out.='
2238
2239
2240
2241 <!--
2242 File listing
2243 -->
2244 <table cellpadding="0" cellspacing="0" id="typo3-fileList">
2245 '.implode('',$lines).'
2246 </table>';
2247 }
2248 // Return accumulated content for filelisting:
2249 return $out;
2250 }
2251
2252 /**
2253 * Render list of folders.
2254 *
2255 * @param array List of folders. See t3lib_div::get_dirs
2256 * @param string If set a header with a folder icon and folder name are shown
2257 * @return string HTML output
2258 */
2259 function folderList($baseFolder, $folders) {
2260 global $LANG, $BACK_PATH;
2261
2262 $content = '';
2263
2264 // Create headline (showing number of folders):
2265 $content.=$this->barheader(
2266 sprintf($GLOBALS['LANG']->getLL('folders').' (%s):',count($folders))
2267 );
2268
2269 $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
2270
2271 // Create the header of current folder:
2272 if($baseFolder) {
2273 if (strstr($baseFolder, ',') || strstr($baseFolder, '|')) {
2274 // In case an invalid character is in the filepath, display error message:
2275 $errorMessage = $LANG->JScharCode(sprintf($LANG->getLL('invalidChar'),', |'));
2276 $aTag = $aTag_alt = "<a href=\"#\" onclick=\"alert(".$errorMessage.");return false;\">";
2277 } else {
2278 // If foldername is OK, just add it:
2279 $aTag = "<a href=\"#\" onclick=\"return insertElement('','".rawurlencode($baseFolder)."', 'folder', '".rawurlencode($baseFolder)."', unescape('".rawurlencode($baseFolder)."'), '".$fI['extension']."', '".$ficon."');\">";
2280 $aTag_alt = substr($aTag,0,-4).",'',1);\">";
2281 }
2282 $aTag_e = '</a>';
2283
2284 // add the foder icon
2285 $folderIcon = $aTag_alt;
2286 $folderIcon.= '<img'.t3lib_iconWorks::skinImg(
2287 $BACK_PATH,
2288 'gfx/i/_icon_webfolders.gif','width="18" height="16"'
2289 ).' alt="" />';
2290 $folderIcon.= htmlspecialchars(
2291 t3lib_div::fixed_lgd_cs(basename($baseFolder),$titleLength)
2292 );
2293 $folderIcon.= $aTag_e;
2294
2295 $content.=$folderIcon.'<br />';
2296 }
2297
2298 // Listing the folders:
2299 if(is_array($folders)) {
2300 if(count($folders) > 0) {
2301 // Traverse the folder list:
2302 $lines = array();
2303 foreach($folders as $folderPath) {
2304 $pathInfo = pathinfo($folderPath);
2305
2306 // Create folder icon:
2307 $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img'.t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/i/_icon_webfolders.gif','width="16" height="16"').' title="'.htmlspecialchars($pathInfo['basename'].$size).'" class="absmiddle" alt="" />';
2308
2309 // Create links for adding the folder:
2310 if($this->P['itemName'] != '' && $this->P['formName'] != '') {
2311 $aTag = "<a href=\"#\" onclick=\"return set_folderpath(unescape('".rawurlencode($folderPath)."'));\">";
2312 } else {
2313 $aTag = "<a href=\"#\" onclick=\"return insertElement('','".rawurlencode($folderPath)."', 'folder', '".rawurlencode($folderPath)."', unescape('".rawurlencode($folderPath)."'), '".$pathInfo['extension']."', '".$ficon."');\">";
2314 }
2315
2316 if (strstr($folderPath,',') || strstr($folderPath,'|')) {
2317 // In case an invalid character is in the filepath, display error message:
2318 $errorMessage = $LANG->JScharCode(sprintf($LANG->getLL('invalidChar'),', |'));
2319 $aTag = $aTag_alt = "<a href=\"#\" onclick=\"alert(".$errorMessage.");return false;\">";
2320 } else {
2321 // If foldername is OK, just add it:
2322 $aTag_alt = substr($aTag,0,-4).",'',1);\">";
2323 }
2324 $aTag_e='</a>';
2325
2326 // Combine icon and folderpath:
2327 $foldernameAndIcon = $aTag_alt.$icon.htmlspecialchars(
2328 t3lib_div::fixed_lgd_cs(basename($folderPath),$titleLength)
2329 ).$aTag_e;
2330
2331 if($this->P['itemName'] != '') {
2332 $lines[] = '
2333 <tr class="bgColor4">
2334 <td nowrap="nowrap">'.$foldernameAndIcon.'&nbsp;</td>
2335 <td>&nbsp;</td>
2336 </tr>';
2337 } else {
2338 $lines[] = '
2339 <tr class="bgColor4">
2340 <td nowrap="nowrap">'.$foldernameAndIcon.'&nbsp;</td>
2341 <td>'.$aTag.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$LANG->getLL('addToList',1).'" alt="" />'.$aTag_e.'</td>
2342 <td>&nbsp;</td>
2343 </tr>';
2344 }
2345
2346 $lines[] = '
2347 <tr>
2348 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
2349 </tr>';
2350 }
2351 }
2352
2353 // Wrap all the rows in table tags:
2354 $content.='
2355
2356 <!--
2357 Folder listing
2358 -->
2359 <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
2360 '.implode('', $lines).'
2361 </table>';
2362 }
2363
2364 // Return accumulated content for folderlisting:
2365 return $content;
2366 }
2367
2368 /**
2369 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
2370 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
2371 *
2372 * @param string The folder path to expand
2373 * @param string List of fileextensions to show
2374 * @return string HTML output
2375 */
2376 function TBE_dragNDrop($expandFolder=0,$extensionList='') {
2377 global $BACK_PATH;
2378
2379 $extensionList = ($extensionList == '*') ? '' : $extensionList;
2380 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
2381 $out='';
2382 if ($expandFolder && $this->checkFolder($expandFolder)) {
2383 if ($this->isWebFolder($expandFolder)) {
2384
2385 // Read files from directory:
2386 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
2387 if (is_array($files)) {
2388 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
2389
2390 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
2391 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
2392 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
2393 $out.=$picon.'<br />';
2394
2395 // Init row-array:
2396 $lines=array();
2397
2398 // Add "drag-n-drop" message:
2399 $lines[]='
2400 <tr>
2401 <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
2402 </tr>';
2403
2404 // Traverse files:
2405 foreach ($files as $filepath) {
2406 $fI = pathinfo($filepath);
2407
2408 // URL of image:
2409 $iurl = $this->siteURL.t3lib_div::rawurlencodeFP(substr($filepath,strlen(PATH_site)));
2410
2411 // Show only web-images
2412 if (t3lib_div::inList('gif,jpeg,jpg,png',strtolower($fI['extension']))) {
2413 $imgInfo = @getimagesize($filepath);
2414 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
2415
2416 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
2417 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
2418 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
2419 $filenameAndIcon=$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen));
2420
2421 if (t3lib_div::_GP('noLimit')) {
2422 $maxW=10000;
2423 $maxH=10000;
2424 } else {
2425 $maxW=380;
2426 $maxH=500;
2427 }
2428 $IW = $imgInfo[0];
2429 $IH = $imgInfo[1];
2430 if ($IW>$maxW) {
2431 $IH=ceil($IH/$IW*$maxW);
2432 $IW=$maxW;
2433 }
2434 if ($IH>$maxH) {
2435 $IW=ceil($IW/$IH*$maxH);
2436 $IH=$maxH;
2437 }
2438
2439 // Make row:
2440 $lines[]='
2441 <tr class="bgColor4">
2442 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
2443 <td nowrap="nowrap">'.
2444 ($imgInfo[0]!=$IW ? '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('noLimit'=>'1'))).'">'.
2445 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/icon_warning2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('clickToRedrawFullSize',1).'" alt="" />'.
2446 '</a>':'').
2447 $pDim.'&nbsp;</td>
2448 </tr>';
2449
2450 $lines[]='
2451 <tr>
2452 <td colspan="2"><img src="'.$iurl.'" width="'.$IW.'" height="'.$IH.'" border="1" alt="" /></td>
2453 </tr>';
2454 $lines[]='
2455 <tr>
2456 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2457 </tr>';
2458 }
2459 }
2460
2461 // Finally, wrap all rows in a table tag:
2462 $out.='
2463
2464
2465 <!--
2466 File listing / Drag-n-drop
2467 -->
2468 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2469 '.implode('',$lines).'
2470 </table>';
2471 }
2472 } else {
2473 // Print this warning if the folder is NOT a web folder:
2474 $out.=$this->barheader($GLOBALS['LANG']->getLL('files'));
2475 $out.=$this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'),'icon_warning2');
2476 }
2477 }
2478 return $out;
2479 }
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492 /******************************************************************
2493 *
2494 * Miscellaneous functions
2495 *
2496 ******************************************************************/
2497
2498
2499 /**
2500 * Verifies that a path is a web-folder:
2501 *
2502 * @param string Absolute filepath
2503 * @return boolean If the input path is found in PATH_site then it returns true.
2504 */
2505 function isWebFolder($folder) {
2506 $folder = rtrim($folder, '/').'/';
2507 return t3lib_div::isFirstPartOfStr($folder,PATH_site) ? TRUE : FALSE;
2508 }
2509
2510 /**
2511 * Checks, if a path is within the mountpoints of the backend user
2512 *
2513 * @param string Absolute filepath
2514 * @return boolean If the input path is found in the backend users filemounts, then return true.
2515 */
2516 function checkFolder($folder) {
2517 return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? true : false;
2518 }
2519
2520 /**
2521 * Checks, if a path is within a read-only mountpoint of the backend user
2522 *
2523 * @param string Absolute filepath
2524 * @return boolean If the input path is found in the backend users filemounts and if the filemount is of type readonly, then return true.
2525 */
2526 function isReadOnlyFolder($folder) {
2527 return ($GLOBALS['FILEMOUNTS'][$this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/')]['type'] == 'readonly');
2528 }
2529
2530 /**
2531 * Prints a 'header' where string is in a tablecell
2532 *
2533 * @param string The string to print in the header. The value is htmlspecialchars()'ed before output.
2534 * @return string The header HTML (wrapped in a table)
2535 */
2536 function barheader($str) {
2537 return '
2538 <!-- Bar header: -->
2539 <h3>' . htmlspecialchars($str) . '</h3>
2540 ';
2541 }
2542
2543 /**
2544 * Displays a message box with the input message
2545 *
2546 * @param string Input message to show (will be htmlspecialchars()'ed inside of this function)
2547 * @param string Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
2548 * @return string HTML for the message (wrapped in a table).
2549 */
2550 function getMsgBox($in_msg,$icon='icon_note') {
2551 global $BACK_PATH;
2552
2553 $msg = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/'.$icon.'.gif','width="18" height="16"').' alt="" />'.htmlspecialchars($in_msg);
2554 $msg = '
2555
2556 <!--
2557 Message box:
2558 -->
2559 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2560 <tr>
2561 <td>'.$msg.'</td>
2562 </tr>
2563 </table>
2564 ';
2565 return $msg;
2566 }
2567
2568 /**
2569 * For RTE/link: This prints the 'currentUrl'
2570 *
2571 * @param string URL value. The value is htmlspecialchars()'ed before output.
2572 * @return string HTML content, wrapped in a table.
2573 */
2574 function printCurrentUrl($str) {
2575 if (strlen($str)) {
2576 return '
2577 <!-- Print current URL -->
2578 <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
2579 <tr>
2580 <td>' . $GLOBALS['LANG']->getLL('currentLink',1) . ': ' .htmlspecialchars(rawurldecode($str)) . '</td>
2581 </tr>
2582 </table>';
2583 } else {
2584 return '';
2585 }
2586 }
2587
2588 /**
2589 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2590 *
2591 * @param string HREF value tp analyse
2592 * @param string The URL of the current website (frontend)
2593 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2594 */
2595 function parseCurUrl($href,$siteUrl) {
2596 $href = trim($href);
2597 if ($href) {
2598 $info=array();
2599
2600 // Default is "url":
2601 $info['value']=$href;
2602 $info['act']='url';
2603
2604 $specialParts = explode('#_SPECIAL',$href);
2605 if (count($specialParts)==2) { // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2606 $info['value']='#_SPECIAL'.$specialParts[1];
2607 $info['act']='spec';
2608 } elseif (t3lib_div::isFirstPartOfStr($href,$siteUrl)) { // If URL is on the current frontend website:
2609 $rel = substr($href,strlen($siteUrl));
2610 if (file_exists(PATH_site.rawurldecode($rel))) { // URL is a file, which exists:
2611 $info['value']=rawurldecode($rel);
2612 if (@is_dir(PATH_site . $info['value'])) {
2613 $info['act'] = 'folder';
2614 } else {
2615 $info['act'] = 'file';
2616 }
2617 } else { // URL is a page (id parameter)
2618 $uP=parse_url($rel);
2619 if (!trim($uP['path'])) {
2620 $pp = preg_split('/^id=/', $uP['query']);
2621 $pp[1] = preg_replace( '/&id=[^&]*/', '', $pp[1]);
2622 $parameters = explode('&', $pp[1]);
2623 $id = array_shift($parameters);
2624 if ($id) {
2625 // Checking if the id-parameter is an alias.
2626 if (!t3lib_div::testInt($id)) {
2627 list($idPartR) = t3lib_BEfunc::getRecordsByField('pages','alias',$id);
2628 $id=intval($idPartR['uid']);
2629 }
2630
2631 $pageRow = t3lib_BEfunc::getRecordWSOL('pages',$id);
2632 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
2633 $info['value']=$GLOBALS['LANG']->getLL('page',1)." '".htmlspecialchars(t3lib_div::fixed_lgd_cs($pageRow['title'],$titleLen))."' (ID:".$id.($uP['fragment']?', #'.$uP['fragment']:'').')';
2634 $info['pageid']=$id;
2635 $info['cElement']=$uP['fragment'];
2636 $info['act']='page';
2637 $info['query'] = $parameters[0]?'&'.implode('&', $parameters):'';
2638 }
2639 }
2640 }
2641 } else { // Email link:
2642 if (strtolower(substr($href,0,7))=='mailto:') {
2643 $info['value']=trim(substr($href,7));
2644 $info['act']='mail';
2645 }
2646 }
2647 $info['info'] = $info['value'];
2648 } else { // NO value inputted:
2649 $info=array();
2650 $info['info']=$GLOBALS['LANG']->getLL('none');
2651 $info['value']='';
2652 $info['act']='page';
2653 }
2654
2655 // let the hook have a look
2656 foreach($this->hookObjects as $hookObject) {
2657 $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2658 }
2659
2660 return $info;
2661 }
2662
2663 /**
2664 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2665 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2666 *
2667 * @param string Absolute filepath on server to which to upload.
2668 * @return string HTML for an upload form.
2669 */
2670 function uploadForm($path) {
2671 global $BACK_PATH;
2672
2673 if ($this->isReadOnlyFolder($path)) return '';
2674
2675 // Read configuration of upload field count
2676 $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2677 $count = isset($userSetting) ? $userSetting : 3;
2678 if ($count === '0') {
2679 return '';
2680 }
2681 $count = intval($count) == 0 ? 3 : intval($count);
2682
2683 // Create header, showing upload path:
2684 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
2685 $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle',1).':');
2686 $code.='
2687
2688 <!--
2689 Form, for uploading files:
2690 -->
2691 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">
2692 <table border="0" cellpadding="0" cellspacing="3" id="typo3-uplFiles">
2693 <tr>
2694 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
2695 </tr>
2696 <tr>
2697 <td>';
2698
2699 // Traverse the number of upload fields (default is 3):
2700 for ($a=1;$a<=$count;$a++) {
2701 $code.='<input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" />
2702 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($path).'" />
2703 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />';
2704 }
2705
2706 // Make footer of upload form, including the submit button:
2707 $redirectValue = $this->thisScript.'?act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
2708 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
2709 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />';
2710
2711 $code.='
2712 <div id="c-override">
2713 <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:overwriteExistingFiles',1).'</label>
2714 </div>
2715 ';
2716
2717
2718 $code.='</td>
2719 </tr>
2720 </table>
2721 </form>';
2722
2723 return $code;
2724 }
2725
2726 /**
2727 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2728 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2729 *
2730 * @param string Absolute filepath on server in which to create the new folder.
2731 * @return string HTML for the create folder form.
2732 */
2733 function createFolder($path) {
2734 global $BACK_PATH;
2735
2736 if ($this->isReadOnlyFolder($path)) return '';
2737
2738 // Don't show Folder-create form if it's denied
2739 if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2740 return '';
2741 }
2742 // Create header, showing upload path:
2743 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
2744 $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle').':');
2745 $code.='
2746
2747 <!--
2748 Form, for creating new folders:
2749 -->
2750 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform2">
2751 <table border="0" cellpadding="0" cellspacing="3" id="typo3-crFolder">
2752 <tr>
2753 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
2754 </tr>
2755 <tr>
2756 <td>';
2757
2758 // Create the new-folder name field:
2759 $a=1;
2760 $code.='<input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" />'.
2761 '<input type="hidden" name="file[newfolder]['.$a.'][target]" value="'.htmlspecialchars($path).'" />';
2762
2763 // Make footer of upload form, including the submit button:
2764 $redirectValue = $this->thisScript.'?act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
2765 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
2766 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit',1).'" />';
2767
2768 $code.='</td>
2769 </tr>
2770 </table>
2771 </form>';
2772
2773 return $code;
2774 }
2775
2776 /**
2777 * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2778 *
2779 * @param integer $filesCount: Number of files currently displayed
2780 * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2781 */
2782 function getBulkSelector($filesCount) {
2783 if ($filesCount) {
2784 $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.php:toggleSelection',1);
2785 $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.php:importSelection',1);
2786
2787 $out = $this->doc->spacer(15).'<div>' .
2788 '<a href="#" onclick="BrowseLinks.Selector.toggle()">' .
2789 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/clip_select.gif','width="12" height="12"').' title="'.$labelToggleSelection.'" alt="" /> ' .
2790 $labelToggleSelection.'</a>'.$this->doc->spacer(5) .
2791 '<a href="#" onclick="BrowseLinks.Selector.handle()">' .
2792 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/import.gif','width="12" height="12"').' title="'.$labelImportSelection.'" alt="" /> ' .
2793 $labelImportSelection.'</a>' .
2794 '</div>'.$this->doc->spacer(15);
2795 }
2796 return $out;
2797 }
2798
2799 /**
2800 * Determines whether submitted field change functions are valid
2801 * and are coming from the system and not from an external abuse.
2802 *
2803 * @return boolean Whether the submitted field change functions are valid
2804 */
2805 protected function areFieldChangeFunctionsValid() {
2806 return (
2807 isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])
2808 && $this->P['fieldChangeFuncHash'] == t3lib_div::hmac(serialize($this->P['fieldChangeFunc']))
2809 );
2810 }
2811 }
2812
2813
2814 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php']) {
2815 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php']);
2816 }
2817
2818 ?>