* Merging all changes from TYPO3_4-0 branch back into HEAD
[Packages/TYPO3.CMS.git] / typo3 / class.browse_links.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 require_once (PATH_t3lib.'class.t3lib_browsetree.php');
119 require_once (PATH_t3lib.'class.t3lib_foldertree.php');
120 require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
121 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
122
123
124 // Include classes
125 require_once (PATH_t3lib.'class.t3lib_page.php');
126 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
127 require_once (PATH_typo3.'/class.db_list.inc');
128 require_once (PATH_typo3.'/class.db_list_extra.inc');
129 require_once (PATH_t3lib.'/class.t3lib_pagetree.php');
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 /**
150 * Local version of the record list.
151 *
152 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
153 * @package TYPO3
154 * @subpackage core
155 */
156 class TBE_browser_recordList extends localRecordList {
157 var $thisScript = 'browse_links.php';
158
159 /**
160 * Initializes the script path
161 *
162 * @return void
163 */
164 function TBE_browser_recordList () {
165 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
166 }
167
168 /**
169 * Creates the URL for links
170 *
171 * @param mixed If not blank string, this is used instead of $this->id as the id value.
172 * @param string If this is "-1" then $this->table is used, otherwise the value of the input variable.
173 * @param string Commalist of fields NOT to pass as parameters (currently "sortField" and "sortRev")
174 * @return string Query-string for URL
175 */
176 function listURL($altId='',$table=-1,$exclList='') {
177 return $this->thisScript.
178 '?id='.(strcmp($altId,'')?$altId:$this->id).
179 '&table='.rawurlencode($table==-1?$this->table:$table).
180 ($this->thumbs?'&imagemode='.$this->thumbs:'').
181 ($this->searchString?'&search_field='.rawurlencode($this->searchString):'').
182 ($this->searchLevels?'&search_levels='.rawurlencode($this->searchLevels):'').
183 ((!$exclList || !t3lib_div::inList($exclList,'sortField')) && $this->sortField?'&sortField='.rawurlencode($this->sortField):'').
184 ((!$exclList || !t3lib_div::inList($exclList,'sortRev')) && $this->sortRev?'&sortRev='.rawurlencode($this->sortRev):'').
185 // extra:
186 $this->ext_addP()
187 ;
188 }
189
190 /**
191 * Returns additional, local GET parameters to include in the links of the record list.
192 *
193 * @return string
194 */
195 function ext_addP() {
196 $str = '&act='.$GLOBALS['SOBE']->browser->act.
197 '&mode='.$GLOBALS['SOBE']->browser->mode.
198 '&expandPage='.$GLOBALS['SOBE']->browser->expandPage.
199 '&bparams='.rawurlencode($GLOBALS['SOBE']->browser->bparams);
200 return $str;
201 }
202
203 /**
204 * 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...)
205 *
206 * @param string Table name
207 * @param integer UID (not used here)
208 * @param string Title string
209 * @param array Records array (from table name)
210 * @return string
211 */
212 function linkWrapItems($table,$uid,$code,$row) {
213 global $TCA, $BACK_PATH;
214
215 if (!$code) {
216 $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i>';
217 } else {
218 $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL));
219 }
220
221 $titleCol = $TCA[$table]['ctrl']['label'];
222 $title = $row[$titleCol];
223
224 $ficon = t3lib_iconWorks::getIcon($table,$row);
225 $aOnClick = "return insertElement('".$table."', '".$row['uid']."', 'db', ".t3lib_div::quoteJSvalue($title).", '', '', '".$ficon."');";
226 $ATag = '<a href="#" onclick="'.$aOnClick.'">';
227 $ATag_alt = substr($ATag,0,-4).',\'\',1);">';
228 $ATag_e = '</a>';
229
230 return $ATag.
231 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('addToList',1).'" alt="" />'.
232 $ATag_e.
233 $ATag_alt.
234 $code.
235 $ATag_e;
236 }
237
238 /**
239 * Returns the title (based on $code) of a table ($table) without a link
240 *
241 * @param string Table name
242 * @param string Table label
243 * @return string The linked table label
244 */
245 function linkWrapTable($table,$code) {
246 return $code;
247 }
248 }
249
250
251
252
253
254
255 /**
256 * Class which generates the page tree
257 *
258 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
259 * @package TYPO3
260 * @subpackage core
261 */
262 class localPageTree extends t3lib_browseTree {
263
264 /**
265 * Constructor. Just calling init()
266 *
267 * @return void
268 */
269 function localPageTree() {
270 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
271
272 $this->init();
273
274 $this->clause = ' AND doktype!=255'.$this->clause;
275 }
276
277 /**
278 * Wrapping the title in a link, if applicable.
279 *
280 * @param string Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
281 * @param array The record
282 * @param boolean (Ignore)
283 * @return string Wrapping title string.
284 */
285 function wrapTitle($title,$v,$ext_pArrPages='') {
286 if ($this->ext_isLinkable($v['doktype'],$v['uid'])) {
287 $aOnClick = "return link_typo3Page('".$v['uid']."');";
288 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
289 } else {
290 return '<span style="color: #666666;">'.$title.'</span>';
291 }
292 }
293
294 /**
295 * Create the page navigation tree in HTML
296 *
297 * @param array Tree array
298 * @return string HTML output.
299 */
300 function printTree($treeArr='') {
301 global $BACK_PATH;
302 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
303 if (!is_array($treeArr)) $treeArr=$this->tree;
304
305 $out='';
306 $c=0;
307
308 foreach($treeArr as $k => $v) {
309 $c++;
310 $bgColorClass = ($c+1)%2 ? 'bgColor' : 'bgColor-10';
311 if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']==$v['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']) {
312 $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
313 $bgColorClass='bgColor4';
314 } else {
315 $arrCol='<td></td>';
316 }
317
318 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandPage='.$v['row']['uid'].'\');';
319 $cEbullet = $this->ext_isLinkable($v['row']['doktype'],$v['row']['uid']) ?
320 '<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/arrowbullet.gif','width="18" height="16"').' alt="" /></a>' :
321 '';
322 $out.='
323 <tr class="'.$bgColorClass.'">
324 <td nowrap="nowrap"'.($v['row']['_CSSCLASS'] ? ' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
325 $v['HTML'].
326 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$this->ext_pArrPages).
327 '</td>'.
328 $arrCol.
329 '<td>'.$cEbullet.'</td>
330 </tr>';
331 }
332 $out='
333
334
335 <!--
336 Navigation Page Tree:
337 -->
338 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tree">
339 '.$out.'
340 </table>';
341 return $out;
342 }
343
344 /**
345 * Returns true if a doktype can be linked.
346 *
347 * @param integer Doktype value to test
348 * @param integer uid to test.
349 * @return boolean
350 */
351 function ext_isLinkable($doktype,$uid) {
352 if ($uid && $doktype<199) {
353 return true;
354 }
355 }
356
357 /**
358 * Wrap the plus/minus icon in a link
359 *
360 * @param string HTML string to wrap, probably an image tag.
361 * @param string Command for 'PM' get var
362 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
363 * @return string Link-wrapped input string
364 */
365 function PM_ATagWrap($icon,$cmd,$bMark='') {
366 if ($bMark) {
367 $anchor = '#'.$bMark;
368 $name=' name="'.$bMark.'"';
369 }
370 $aOnClick = "return jumpToUrl('".$this->thisScript.'?PM='.$cmd."','".$anchor."');";
371
372 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
373 }
374
375 /**
376 * Wrapping the image tag, $icon, for the row, $row
377 *
378 * @param string The image tag for the icon
379 * @param array The row for the current element
380 * @return string The processed icon input value.
381 */
382 function wrapIcon($icon,$row) {
383 return $this->addTagAttributes($icon,' title="id='.$row['uid'].'"');
384 }
385 }
386
387
388
389
390
391
392
393
394 /**
395 * Page tree for the RTE - totally the same, no changes needed. (Just for the sake of beauty - or confusion... :-)
396 *
397 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
398 * @package TYPO3
399 * @subpackage core
400 */
401 class rtePageTree extends localPageTree {
402 }
403
404
405
406
407
408
409
410
411 /**
412 * For TBE record browser
413 *
414 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
415 * @package TYPO3
416 * @subpackage core
417 */
418 class TBE_PageTree extends localPageTree {
419
420 /**
421 * Returns true if a doktype can be linked (which is always the case here).
422 *
423 * @param integer Doktype value to test
424 * @param integer uid to test.
425 * @return boolean
426 */
427 function ext_isLinkable($doktype,$uid) {
428 return true;
429 }
430
431 /**
432 * Wrapping the title in a link, if applicable.
433 *
434 * @param string Title, ready for output.
435 * @param array The record
436 * @param boolean If set, pages clicked will return immediately, otherwise reload page.
437 * @return string Wrapping title string.
438 */
439 function wrapTitle($title,$v,$ext_pArrPages) {
440 if ($ext_pArrPages) {
441 $ficon=t3lib_iconWorks::getIcon('pages',$v);
442 $onClick = "return insertElement('pages', '".$v['uid']."', 'db', ".t3lib_div::quoteJSvalue($v['title']).", '', '', '".$ficon."','',1);";
443 } else {
444 $onClick = htmlspecialchars('return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandPage='.$v['uid'].'\');');
445 }
446 return '<a href="#" onclick="'.$onClick.'">'.$title.'</a>';
447 }
448 }
449
450
451
452
453
454
455
456
457 /**
458 * Base extension class which generates the folder tree.
459 * Used directly by the RTE.
460 *
461 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
462 * @package TYPO3
463 * @subpackage core
464 */
465 class localFolderTree extends t3lib_folderTree {
466 var $ext_IconMode=1;
467
468
469 /**
470 * Initializes the script path
471 *
472 * @return void
473 */
474 function localFolderTree() {
475 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
476 $this->t3lib_folderTree();
477 }
478
479 /**
480 * Wrapping the title in a link, if applicable.
481 *
482 * @param string Title, ready for output.
483 * @param array The "record"
484 * @return string Wrapping title string.
485 */
486 function wrapTitle($title,$v) {
487 if ($this->ext_isLinkable($v)) {
488 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['path']).'\');';
489 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
490 } else {
491 return '<span class="typo3-dimmed">'.$title.'</span>';
492 }
493 }
494
495 /**
496 * Returns true if the input "record" contains a folder which can be linked.
497 *
498 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
499 * @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
500 */
501 function ext_isLinkable($v) {
502 $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']); // Checking, if the input path is a web-path.
503 if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web') {
504 return 0;
505 }
506 return 1;
507 }
508
509 /**
510 * Wrap the plus/minus icon in a link
511 *
512 * @param string HTML string to wrap, probably an image tag.
513 * @param string Command for 'PM' get var
514 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
515 * @return string Link-wrapped input string
516 * @access private
517 */
518 function PM_ATagWrap($icon,$cmd,$bMark='') {
519 if ($bMark) {
520 $anchor = '#'.$bMark;
521 $name=' name="'.$bMark.'"';
522 }
523 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?PM='.$cmd.'\',\''.$anchor.'\');';
524 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
525 }
526
527 /**
528 * Create the folder navigation tree in HTML
529 *
530 * @param mixed Input tree array. If not array, then $this->tree is used.
531 * @return string HTML output of the tree.
532 */
533 function printTree($treeArr='') {
534 global $BACK_PATH;
535 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
536
537 if (!is_array($treeArr)) $treeArr=$this->tree;
538
539 $out='';
540 $c=0;
541
542 // Preparing the current-path string (if found in the listing we will see a red blinking arrow).
543 if (!$GLOBALS['SOBE']->browser->curUrlInfo['value']) {
544 $cmpPath='';
545 } else if (substr(trim($GLOBALS['SOBE']->browser->curUrlInfo['info']),-1)!='/') {
546 $cmpPath=PATH_site.dirname($GLOBALS['SOBE']->browser->curUrlInfo['info']).'/';
547 } else {
548 $cmpPath=PATH_site.$GLOBALS['SOBE']->browser->curUrlInfo['info'];
549 }
550
551 // Traverse rows for the tree and print them into table rows:
552 foreach($treeArr as $k => $v) {
553 $c++;
554 $bgColorClass=($c+1)%2 ? 'bgColor' : 'bgColor-10';
555
556 // Creating blinking arrow, if applicable:
557 if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='file' && $cmpPath==$v['row']['path']) {
558 $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
559 $bgColorClass='bgColor4';
560 } else {
561 $arrCol='<td></td>';
562 }
563 // Create arrow-bullet for file listing (if folder path is linkable):
564 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['row']['path']).'\');';
565 $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>' : '';
566
567 // Put table row with folder together:
568 $out.='
569 <tr class="'.$bgColorClass.'">
570 <td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd_cs($v['row']['title'],$titleLen),$v['row']).'</td>
571 '.$arrCol.'
572 <td>'.$cEbullet.'</td>
573 </tr>';
574 }
575
576 $out='
577
578 <!--
579 Folder tree:
580 -->
581 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tree">
582 '.$out.'
583 </table>';
584 return $out;
585 }
586 }
587
588
589
590
591
592
593 /**
594 * Folder tree for the RTE - totally the same, no changes needed. (Just for the sake of beauty - or confusion... :-)
595 *
596 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
597 * @package TYPO3
598 * @subpackage core
599 */
600 class rteFolderTree extends localFolderTree {
601 }
602
603
604
605
606
607
608
609 /**
610 * For TBE File Browser
611 *
612 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
613 * @package TYPO3
614 * @subpackage core
615 */
616 class TBE_FolderTree extends localFolderTree {
617 var $ext_noTempRecyclerDirs=0; // If file-drag mode is set, temp and recycler folders are filtered out.
618
619 /**
620 * Returns true if the input "record" contains a folder which can be linked.
621 *
622 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
623 * @return boolean True is returned if the path is NOT a recycler or temp folder AND if ->ext_noTempRecyclerDirs is not set.
624 */
625 function ext_isLinkable($v) {
626 if ($this->ext_noTempRecyclerDirs && (substr($v['path'],-7)=='_temp_/' || substr($v['path'],-11)=='_recycler_/')) {
627 return 0;
628 } return 1;
629 }
630
631 /**
632 * Wrapping the title in a link, if applicable.
633 *
634 * @param string Title, ready for output.
635 * @param array The 'record'
636 * @return string Wrapping title string.
637 */
638 function wrapTitle($title,$v) {
639 if ($this->ext_isLinkable($v)) {
640 $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['path']).'\');';
641 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
642 } else {
643 return '<span class="typo3-dimmed">'.$title.'</span>';
644 }
645 }
646 }
647
648
649
650
651
652 /**
653 * class for the Element Browser window.
654 *
655 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
656 * @package TYPO3
657 * @subpackage core
658 */
659 class browse_links {
660
661 // Internal, static:
662 var $siteURL; // Current site URL (Frontend)
663 var $thisScript; // the script to link to
664 var $thisConfig; // RTE specific TSconfig
665 var $setTarget; // Target (RTE specific)
666 var $setTitle; // title (RTE specific)
667 var $doc; // Backend template object
668
669 // GPvars: (Input variables from outside)
670 /**
671 * The mode determines the main kind of output from the element browser.
672 * There are these options for values: rte, db, file, filedrag, wizard.
673 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
674 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
675 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
676 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
677 *
678 * @see main()
679 */
680 var $mode;
681
682 /**
683 * Link selector action.
684 * page,file,url,mail,spec are allowed values.
685 * These are only important with the link selector function and in that case they switch between the various menu options.
686 */
687 var $act;
688
689 /**
690 * 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")
691 */
692 var $expandPage;
693
694 /**
695 * 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/"
696 */
697 var $expandFolder;
698
699
700
701 /**
702 * TYPO3 Element Browser, wizard mode parameters. There is a heap of parameters there, better debug() them out if you need something... :-)
703 */
704 var $P;
705
706 /**
707 * 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.
708 * Example value: "data[pages][39][bodytext]|||tt_content|" or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
709 *
710 * Values:
711 * 0: form field name reference
712 * 1: old/unused?
713 * 2: old/unused?
714 * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
715 *
716 * $pArr = explode('|',$this->bparams);
717 * $formFieldName = $pArr[0];
718 * $allowedTablesOrFileTypes = $pArr[3];
719 */
720 var $bparams;
721
722 /**
723 * Used with the Rich Text Editor.
724 * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
725 */
726 var $RTEtsConfigParams;
727
728
729
730
731 /**
732 * Plus/Minus icon value. Used by the tree class to open/close notes on the trees.
733 */
734 var $PM;
735
736 /**
737 * Pointer, used when browsing a long list of records etc.
738 */
739 var $pointer;
740
741
742
743
744 /**
745 * 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.
746 */
747 var $curUrlArray;
748
749 /**
750 * 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.
751 */
752 var $curUrlInfo;
753
754
755
756
757
758
759 /**
760 * Constructor:
761 * Initializes a lot of variables, setting JavaScript functions in header etc.
762 *
763 * @return void
764 */
765 function init() {
766 global $BE_USER,$BACK_PATH;
767
768 // Main GPvars:
769 $this->pointer = t3lib_div::_GP('pointer');
770 $this->bparams = t3lib_div::_GP('bparams');
771 $this->P = t3lib_div::_GP('P');
772 $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
773 $this->expandPage = t3lib_div::_GP('expandPage');
774 $this->expandFolder = t3lib_div::_GP('expandFolder');
775 $this->PM = t3lib_div::_GP('PM');
776
777 // Find "mode"
778 $this->mode=t3lib_div::_GP('mode');
779 if (!$this->mode) {
780 $this->mode='rte';
781 }
782
783 // Site URL
784 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
785
786 // the script to link to
787 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
788
789 // CurrentUrl - the current link url must be passed around if it exists
790 if ($this->mode=='wizard') {
791 $currentLinkParts = t3lib_div::trimExplode(' ',$this->P['currentValue']);
792 $this->curUrlArray = array(
793 'target' => $currentLinkParts[1]
794 );
795 $this->curUrlInfo=$this->parseCurUrl($this->siteURL.'?id='.$currentLinkParts[0],$this->siteURL);
796 } else {
797 $this->curUrlArray = t3lib_div::_GP('curUrl');
798 if ($this->curUrlArray['all']) {
799 $this->curUrlArray=t3lib_div::get_tag_attributes($this->curUrlArray['all']);
800 }
801 $this->curUrlInfo=$this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
802 }
803
804 // Determine nature of current url:
805 $this->act=t3lib_div::_GP('act');
806 if (!$this->act) {
807 $this->act=$this->curUrlInfo['act'];
808 }
809
810 // Rich Text Editor specific configuration:
811 $addPassOnParams='';
812 if ((string)$this->mode=='rte') {
813 $RTEtsConfigParts = explode(':',$this->RTEtsConfigParams);
814 $addPassOnParams.='&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams);
815 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
816 $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
817 }
818
819 // Initializing the target value (RTE)
820 $this->setTarget = $this->curUrlArray['target'];
821 if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
822 $this->setTarget=$this->thisConfig['defaultLinkTarget'];
823 }
824
825 // Initializing the title value (RTE)
826 $this->setTitle = $this->curUrlArray['title'];
827
828
829
830 // Creating backend template object:
831 $this->doc = t3lib_div::makeInstance('template');
832 $this->doc->docType= 'xhtml_trans';
833 $this->doc->backPath = $BACK_PATH;
834
835 // BEGIN accumulation of header JavaScript:
836 $JScode = '';
837 $JScode.= '
838 // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
839 var add_href="'.($this->curUrlArray['href']?'&curUrl[href]='.rawurlencode($this->curUrlArray['href']):'').'";
840 var add_target="'.($this->setTarget?'&curUrl[target]='.rawurlencode($this->setTarget):'').'";
841 var add_title="'.($this->setTitle?'&curUrl[title]='.rawurlencode($this->setTitle):'').'";
842 var add_params="'.($this->bparams?'&bparams='.rawurlencode($this->bparams):'').'";
843
844 var cur_href="'.($this->curUrlArray['href']?$this->curUrlArray['href']:'').'";
845 var cur_target="'.($this->setTarget?$this->setTarget:'').'";
846 var cur_title="'.($this->setTitle?$this->setTitle:'').'";
847
848 function setTarget(target) { //
849 cur_target=target;
850 add_target="&curUrl[target]="+escape(target);
851 }
852 function setTitle(title) { //
853 cur_title=title;
854 add_title="&curUrl[title]="+escape(title);
855 }
856 function setValue(value) { //
857 cur_href=value;
858 add_href="&curUrl[href]="+value;
859 }
860 ';
861
862
863 if ($this->mode=='wizard') { // Functions used, if the link selector is in wizard mode (= TCEforms fields)
864 unset($this->P['fieldChangeFunc']['alert']);
865 reset($this->P['fieldChangeFunc']);
866 $update='';
867 while(list($k,$v)=each($this->P['fieldChangeFunc'])) {
868 $update.= '
869 window.opener.'.$v;
870 }
871
872 $P2=array();
873 $P2['itemName']=$this->P['itemName'];
874 $P2['formName']=$this->P['formName'];
875 $P2['fieldChangeFunc']=$this->P['fieldChangeFunc'];
876 $addPassOnParams.=t3lib_div::implodeArrayForUrl('P',$P2);
877
878 $JScode.='
879 function link_typo3Page(id,anchor) { //
880 updateValueInMainForm(id+(anchor?anchor:"")+" "+cur_target);
881 close();
882 return false;
883 }
884 function link_folder(folder) { //
885 updateValueInMainForm(folder+" "+cur_target);
886 close();
887 return false;
888 }
889 function link_current() { //
890 if (cur_href!="http://" && cur_href!="mailto:") {
891 var setValue = cur_href+" "+cur_target+" "+cur_title;
892 if (setValue.substr(0,7)=="http://") setValue = setValue.substr(7);
893 if (setValue.substr(0,7)=="mailto:") setValue = setValue.substr(7);
894 updateValueInMainForm(setValue);
895 close();
896 }
897 return false;
898 }
899 function checkReference() { //
900 if (window.opener && window.opener.document && window.opener.document.'.$this->P['formName'].' && window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"] ) {
901 return window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"];
902 } else {
903 close();
904 }
905 }
906 function updateValueInMainForm(input) { //
907 var field = checkReference();
908 if (field) {
909 field.value = input;
910 '.$update.'
911 }
912 }
913 ';
914 } else { // Functions used, if the link selector is in RTE mode:
915 $JScode.='
916 function link_typo3Page(id,anchor) { //
917 var theLink = \''.$this->siteURL.'?id=\'+id+(anchor?anchor:"");
918 self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
919 return false;
920 }
921 function link_folder(folder) { //
922 var theLink = \''.$this->siteURL.'\'+folder;
923 self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
924 return false;
925 }
926 function link_spec(theLink) { //
927 self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
928 return false;
929 }
930 function link_current() { //
931 if (cur_href!="http://" && cur_href!="mailto:") {
932 self.parent.parent.renderPopup_addLink(cur_href,cur_target,cur_title);
933 }
934 return false;
935 }
936 ';
937 }
938
939 // General "jumpToUrl" function:
940 $JScode.='
941 function jumpToUrl(URL,anchor) { //
942 var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
943 var add_mode = URL.indexOf("mode=")==-1 ? "&mode='.$this->mode.'" : "";
944 var theLocation = URL+add_act+add_mode+add_href+add_target+add_title+add_params'.($addPassOnParams?'+"'.$addPassOnParams.'"':'').'+(anchor?anchor:"");
945 window.location.href = theLocation;
946 return false;
947 }
948 ';
949
950
951 // This is JavaScript especially for the TBE Element Browser!
952 $pArr = explode('|',$this->bparams);
953 $formFieldName = 'data['.$pArr[0].']['.$pArr[1].']['.$pArr[2].']';
954 $JScode.='
955 var elRef="";
956 var targetDoc="";
957
958 function launchView(url) { //
959 var thePreviewWindow="";
960 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");
961 if (thePreviewWindow && thePreviewWindow.focus) {
962 thePreviewWindow.focus();
963 }
964 }
965 function setReferences() { //
966 if (parent.window.opener
967 && parent.window.opener.content
968 && parent.window.opener.content.document.editform
969 && parent.window.opener.content.document.editform["'.$formFieldName.'"]
970 ) {
971 targetDoc = parent.window.opener.content.document;
972 elRef = targetDoc.editform["'.$formFieldName.'"];
973 return true;
974 } else {
975 return false;
976 }
977 }
978 function insertElement(table, uid, type, filename,fp,filetype,imagefile,action, close) { //
979 if (1=='.($pArr[0]&&!$pArr[1]&&!$pArr[2] ? 1 : 0).') {
980 addElement(filename,table+"_"+uid,fp,close);
981 } else {
982 if (setReferences()) {
983 parent.window.opener.group_change("add","'.$pArr[0].'","'.$pArr[1].'","'.$pArr[2].'",elRef,targetDoc);
984 } else {
985 alert("Error - reference to main window is not set properly!");
986 }
987 if (close) {
988 parent.window.opener.focus();
989 parent.close();
990 }
991 }
992 return false;
993 }
994 function addElement(elName,elValue,altElValue,close) { //
995 if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
996 parent.window.opener.setFormValueFromBrowseWin("'.$pArr[0].'",altElValue?altElValue:elValue,elName);
997 if (close) {
998 parent.window.opener.focus();
999 parent.close();
1000 }
1001 } else {
1002 alert("Error - reference to main window is not set properly!");
1003 parent.close();
1004 }
1005 }
1006 ';
1007
1008 // Finally, add the accumulated JavaScript to the template object:
1009 $this->doc->JScode = $this->doc->wrapScriptTags($JScode);
1010
1011 // Debugging:
1012 if (FALSE) debug(array(
1013 'pointer' => $this->pointer,
1014 'act' => $this->act,
1015 'mode' => $this->mode,
1016 'curUrlInfo' => $this->curUrlInfo,
1017 'curUrlArray' => $this->curUrlArray,
1018 'P' => $this->P,
1019 'bparams' => $this->bparams,
1020 'RTEtsConfigParams' => $this->RTEtsConfigParams,
1021 'expandPage' => $this->expandPage,
1022 'expandFolder' => $this->expandFolder,
1023 'PM' => $this->PM,
1024 ),'Internal variables of Script Class:');
1025 }
1026
1027
1028 /**
1029 * Session data for this class can be set from outside with this method.
1030 * Call after init()
1031 *
1032 * @param array Session data array
1033 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
1034 */
1035 function processSessionData($data) {
1036 $store = false;
1037
1038 switch((string)$this->mode) {
1039 case 'db':
1040 if (isset($this->expandPage)) {
1041 $data['expandPage']=$this->expandPage;
1042 $store = true;
1043 } else {
1044 $this->expandPage=$data['expandPage'];
1045 }
1046 break;
1047 case 'file':
1048 case 'filedrag':
1049 if (isset($this->expandFolder)) {
1050 $data['expandFolder']=$this->expandFolder;
1051 $store = true;
1052 } else {
1053 $this->expandFolder=$data['expandFolder'];
1054 }
1055 break;
1056 }
1057
1058 return array($data, $store);
1059 }
1060
1061
1062
1063
1064 /******************************************************************
1065 *
1066 * Main functions
1067 *
1068 ******************************************************************/
1069
1070 /**
1071 * Rich Text Editor (RTE) link selector (MAIN function)
1072 * Generates the link selector for the Rich Text Editor.
1073 * Can also be used to select links for the TCEforms (see $wiz)
1074 *
1075 * @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
1076 * @return string Modified content variable.
1077 */
1078 function main_rte($wiz=0) {
1079 global $LANG, $BACK_PATH;
1080
1081 // Starting content:
1082 $content=$this->doc->startPage('RTE link');
1083
1084 // Initializing the action value, possibly removing blinded values etc:
1085 $allowedItems = array_diff(explode(',','page,file,url,mail,spec'),t3lib_div::trimExplode(',',$this->thisConfig['blindLinkOptions'],1));
1086 reset($allowedItems);
1087 if (!in_array($this->act,$allowedItems)) $this->act = current($allowedItems);
1088
1089 // Making menu in top:
1090 $menuDef = array();
1091 if (!$wiz) {
1092 $menuDef['removeLink']['isActive'] = $this->act=='removeLink';
1093 $menuDef['removeLink']['label'] = $LANG->getLL('removeLink',1);
1094 $menuDef['removeLink']['url'] = '#';
1095 $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
1096 }
1097 if (in_array('page',$allowedItems)) {
1098 $menuDef['page']['isActive'] = $this->act=='page';
1099 $menuDef['page']['label'] = $LANG->getLL('page',1);
1100 $menuDef['page']['url'] = '#';
1101 $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\'?act=page\');return false;"';
1102 }
1103 if (in_array('file',$allowedItems)){
1104 $menuDef['file']['isActive'] = $this->act=='file';
1105 $menuDef['file']['label'] = $LANG->getLL('file',1);
1106 $menuDef['file']['url'] = '#';
1107 $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\'?act=file\');return false;"';
1108 }
1109 if (in_array('url',$allowedItems)) {
1110 $menuDef['url']['isActive'] = $this->act=='url';
1111 $menuDef['url']['label'] = $LANG->getLL('extUrl',1);
1112 $menuDef['url']['url'] = '#';
1113 $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\'?act=url\');return false;"';
1114 }
1115 if (in_array('mail',$allowedItems)) {
1116 $menuDef['mail']['isActive'] = $this->act=='mail';
1117 $menuDef['mail']['label'] = $LANG->getLL('email',1);
1118 $menuDef['mail']['url'] = '#';
1119 $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\'?act=mail\');return false;"';
1120 }
1121 if (is_array($this->thisConfig['userLinks.']) && in_array('spec',$allowedItems)) {
1122 $menuDef['spec']['isActive'] = $this->act=='spec';
1123 $menuDef['spec']['label'] = $LANG->getLL('special',1);
1124 $menuDef['spec']['url'] = '#';
1125 $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec\');return false;"';
1126 }
1127 $content .= $this->doc->getTabMenuRaw($menuDef);
1128
1129 // Adding the menu and header to the top of page:
1130 $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
1131
1132
1133 // Depending on the current action we will create the actual module content for selecting a link:
1134 switch($this->act) {
1135 case 'mail':
1136 $extUrl='
1137
1138 <!--
1139 Enter mail address:
1140 -->
1141 <form action="" name="lurlform" id="lurlform">
1142 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
1143 <tr>
1144 <td>'.$GLOBALS['LANG']->getLL('emailAddress',1).':</td>
1145 <td><input type="text" name="lemail"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='mail'?$this->curUrlInfo['info']:'').'" /> '.
1146 '<input type="submit" value="'.$GLOBALS['LANG']->getLL('setLink',1).'" onclick="setTarget(\'\');setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
1147 </tr>
1148 </table>
1149 </form>';
1150 $content.=$extUrl;
1151 break;
1152 case 'url':
1153 $extUrl='
1154
1155 <!--
1156 Enter External URL:
1157 -->
1158 <form action="" name="lurlform" id="lurlform">
1159 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
1160 <tr>
1161 <td>URL:</td>
1162 <td><input type="text" name="lurl"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
1163 '<input type="submit" value="'.$GLOBALS['LANG']->getLL('setLink',1).'" onclick="setValue(document.lurlform.lurl.value); return link_current();" /></td>
1164 </tr>
1165 </table>
1166 </form>';
1167 $content.=$extUrl;
1168 break;
1169 case 'file':
1170 $foldertree = t3lib_div::makeInstance('rteFolderTree');
1171 $foldertree->thisScript = $this->thisScript;
1172 $tree=$foldertree->getBrowsableTree();
1173
1174 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act']!='file') {
1175 $cmpPath='';
1176 } elseif (substr(trim($this->curUrlInfo['info']),-1)!='/') {
1177 $cmpPath=PATH_site.dirname($this->curUrlInfo['info']).'/';
1178 if (!isset($this->expandFolder)) $this->expandFolder = $cmpPath;
1179 } else {
1180 $cmpPath=PATH_site.$this->curUrlInfo['info'];
1181 }
1182
1183 list(,,$specUid) = explode('_',$this->PM);
1184 $files = $this->expandFolder($foldertree->specUIDmap[$specUid]);
1185
1186 $content.= '
1187
1188 <!--
1189 Wrapper table for folder tree / file list:
1190 -->
1191 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
1192 <tr>
1193 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('folderTree').':').$tree.'</td>
1194 <td class="c-wCell" valign="top">'.$files.'</td>
1195 </tr>
1196 </table>
1197 ';
1198 break;
1199 case 'spec':
1200 if (is_array($this->thisConfig['userLinks.'])) {
1201 $subcats=array();
1202 $v=$this->thisConfig['userLinks.'];
1203 reset($v);
1204 while(list($k2)=each($v)) {
1205 $k2i = intval($k2);
1206 if (substr($k2,-1)=='.' && is_array($v[$k2i.'.'])) {
1207
1208 // Title:
1209 $title = trim($v[$k2i]);
1210 if (!$title) {
1211 $title=$v[$k2i.'.']['url'];
1212 } else {
1213 $title=$LANG->sL($title);
1214 }
1215 // Description:
1216 $description=$v[$k2i.'.']['description'] ? $LANG->sL($v[$k2i.'.']['description'],1).'<br />' : '';
1217
1218 // URL + onclick event:
1219 $onClickEvent='';
1220 if (isset($v[$k2i.'.']['target'])) $onClickEvent.="setTarget('".$v[$k2i.'.']['target']."');";
1221 $v[$k2i.'.']['url'] = str_replace('###_URL###',$this->siteURL,$v[$k2i.'.']['url']);
1222 if (substr($v[$k2i.'.']['url'],0,7)=='http://' || substr($v[$k2i.'.']['url'],0,7)=='mailto:') {
1223 $onClickEvent.="cur_href=unescape('".rawurlencode($v[$k2i.'.']['url'])."');link_current();";
1224 } else {
1225 $onClickEvent.="link_spec(unescape('".$this->siteURL.rawurlencode($v[$k2i.'.']['url'])."'));";
1226 }
1227
1228 // Link:
1229 $A=array('<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">','</a>');
1230
1231 // Adding link to menu of user defined links:
1232 $subcats[$k2i]='
1233 <tr>
1234 <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>
1235 </tr>';
1236 }
1237 }
1238
1239 // Sort by keys:
1240 ksort($subcats);
1241
1242 // Add menu to content:
1243 $content.= '
1244
1245 <!--
1246 Special userdefined menu:
1247 -->
1248 <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
1249 <tr>
1250 <td class="bgColor5" class="c-wCell" valign="top"><strong>'.$LANG->getLL('special',1).'</strong></td>
1251 </tr>
1252 '.implode('',$subcats).'
1253 </table>
1254 ';
1255 }
1256 break;
1257 case 'page':
1258 default:
1259 $pagetree = t3lib_div::makeInstance('rtePageTree');
1260 $pagetree->thisScript = $this->thisScript;
1261 $tree=$pagetree->getBrowsableTree();
1262 $cElements = $this->expandPage();
1263 $content.= '
1264
1265 <!--
1266 Wrapper table for page tree / record list:
1267 -->
1268 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
1269 <tr>
1270 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('pageTree').':').$tree.'</td>
1271 <td class="c-wCell" valign="top">'.$cElements.'</td>
1272 </tr>
1273 </table>
1274 ';
1275 break;
1276 }
1277
1278 $content .= '
1279
1280
1281
1282 <!--
1283 Selecting title for link:
1284 -->
1285 <form action="" name="ltitleform" id="ltargetform">
1286 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1287 <tr>
1288 <td>'.$GLOBALS['LANG']->getLL('title',1).'</td>
1289 <td><input type="text" name="ltitle" onchange="setTitle(this.value);" value="'.htmlspecialchars($this->setTitle).'"'.$this->doc->formWidth(10).' /></td>
1290 <td><input type="submit" value="'.$GLOBALS['LANG']->getLL('update',1).'" onclick="return link_current();" /></td>
1291 </tr>
1292 </table>
1293 </form>
1294 ';
1295
1296 // Target:
1297 if ($this->act!='mail') {
1298 $ltarget='
1299
1300
1301
1302 <!--
1303 Selecting target for link:
1304 -->
1305 <form action="" name="ltargetform" id="ltargetform">
1306 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1307 <tr>
1308 <td>'.$GLOBALS['LANG']->getLL('target',1).':</td>
1309 <td><input type="text" name="ltarget" onchange="setTarget(this.value);" value="'.htmlspecialchars($this->setTarget).'"'.$this->doc->formWidth(10).' /></td>
1310 <td>
1311 <select name="ltarget_type" onchange="setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
1312 <option></option>
1313 <option value="_top">'.$GLOBALS['LANG']->getLL('top',1).'</option>
1314 <option value="_blank">'.$GLOBALS['LANG']->getLL('newWindow',1).'</option>
1315 </select>
1316 </td>
1317 <td>';
1318
1319 if (($this->curUrlInfo['act']=="page" || $this->curUrlInfo['act']=='file') && $this->curUrlArray['href']) {
1320 $ltarget.='
1321 <input type="submit" value="'.$GLOBALS['LANG']->getLL('update',1).'" onclick="return link_current();" />';
1322 }
1323
1324 $selectJS = '
1325 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) {
1326 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;
1327 setTarget(document.ltargetform.ltarget.value);
1328 setTitle(document.ltitleform.ltitle.value);
1329 document.ltargetform.popup_width.selectedIndex=0;
1330 document.ltargetform.popup_height.selectedIndex=0;
1331 }
1332 ';
1333
1334 $ltarget.=' </td>
1335 </tr>
1336 <tr>
1337 <td>'.$GLOBALS['LANG']->getLL('target_popUpWindow',1).':</td>
1338 <td colspan="3">
1339 <select name="popup_width" onchange="'.htmlspecialchars($selectJS).'">
1340 <option value="0">'.$GLOBALS['LANG']->getLL('target_popUpWindow_width',1).'</option>
1341 <option value="300">300</option>
1342 <option value="400">400</option>
1343 <option value="500">500</option>
1344 <option value="600">600</option>
1345 <option value="700">700</option>
1346 <option value="800">800</option>
1347 </select>
1348 x
1349 <select name="popup_height" onchange="'.htmlspecialchars($selectJS).'">
1350 <option value="0">'.$GLOBALS['LANG']->getLL('target_popUpWindow_height',1).'</option>
1351 <option value="200">200</option>
1352 <option value="300">300</option>
1353 <option value="400">400</option>
1354 <option value="500">500</option>
1355 <option value="600">600</option>
1356 </select>
1357 </td>
1358 </tr>
1359 </table>
1360 </form>';
1361
1362 // Add "target selector" box to content:
1363 $content.=$ltarget;
1364
1365 // Add some space
1366 $content.='<br /><br />';
1367 }
1368
1369 // End page, return content:
1370 $content.= $this->doc->endPage();
1371 $content = $this->doc->insertStylesAndJS($content);
1372 return $content;
1373 }
1374
1375 /**
1376 * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1377 *
1378 * @return string HTML content for the module
1379 */
1380 function main_db() {
1381
1382 // Starting content:
1383 $content=$this->doc->startPage('TBE file selector');
1384
1385 // Init variable:
1386 $pArr = explode('|',$this->bparams);
1387
1388 // Making the browsable pagetree:
1389 $pagetree = t3lib_div::makeInstance('TBE_PageTree');
1390 $pagetree->thisScript=$this->thisScript;
1391 $pagetree->ext_pArrPages = !strcmp($pArr[3],'pages')?1:0;
1392 $tree=$pagetree->getBrowsableTree();
1393
1394 // Making the list of elements, if applicable:
1395 $cElements = $this->TBE_expandPage($pArr[3]);
1396
1397 // Putting the things together, side by side:
1398 $content.= '
1399
1400 <!--
1401 Wrapper table for page tree / record list:
1402 -->
1403 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1404 <tr>
1405 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('pageTree').':').$tree.'</td>
1406 <td class="c-wCell" valign="top">'.$cElements.'</td>
1407 </tr>
1408 </table>
1409 ';
1410
1411 // Add some space
1412 $content.='<br /><br />';
1413
1414 // End page, return content:
1415 $content.= $this->doc->endPage();
1416 $content = $this->doc->insertStylesAndJS($content);
1417 return $content;
1418 }
1419
1420 /**
1421 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1422 *
1423 * @return string HTML content for the module
1424 */
1425 function main_file() {
1426 global $BE_USER;
1427
1428 // Starting content:
1429 $content.=$this->doc->startPage('TBE file selector');
1430
1431 // Init variable:
1432 $pArr = explode('|',$this->bparams);
1433
1434 // Create upload/create folder forms, if a path is given:
1435 $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
1436 $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
1437 $path=$this->expandFolder;
1438 if (!$path || !@is_dir($path)) {
1439 $path = $fileProcessor->findTempFolder().'/'; // The closest TEMP-path is found
1440 }
1441 if ($path!='/' && @is_dir($path)) {
1442 $uploadForm=$this->uploadForm($path);
1443 $createFolder=$this->createFolder($path);
1444 } else {
1445 $createFolder='';
1446 $uploadForm='';
1447 }
1448 if ($BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) $content.=$uploadForm;
1449
1450 // Getting flag for showing/not showing thumbnails:
1451 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1452
1453 if (!$noThumbs) {
1454 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1455 $_MOD_MENU = array('displayThumbs' => '');
1456 $_MCONF['name']='file_list';
1457 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
1458 $addParams = '&act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
1459 $thumbNailCheck = t3lib_BEfunc::getFuncCheck('','SET[displayThumbs]',$_MOD_SETTINGS['displayThumbs'],$this->thisScript,$addParams).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs',1);
1460 } else {
1461 $thumbNailCheck='';
1462 }
1463 $noThumbs = $noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs'];
1464
1465 // Create folder tree:
1466 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
1467 $foldertree->thisScript=$this->thisScript;
1468 $foldertree->ext_noTempRecyclerDirs = ($this->mode == 'filedrag');
1469 $tree=$foldertree->getBrowsableTree();
1470
1471 list(,,$specUid) = explode('_',$this->PM);
1472
1473 if ($this->mode=='filedrag') {
1474 $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid],$pArr[3]);
1475 } else {
1476 $files = $this->TBE_expandFolder($foldertree->specUIDmap[$specUid],$pArr[3],$noThumbs);
1477 }
1478
1479 // Putting the parts together, side by side:
1480 $content.= '
1481
1482 <!--
1483 Wrapper table for folder tree / file list:
1484 -->
1485 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1486 <tr>
1487 <td class="c-wCell" valign="top">'.$this->barheader($GLOBALS['LANG']->getLL('folderTree').':').$tree.'</td>
1488 <td class="c-wCell" valign="top">'.$files.'</td>
1489 </tr>
1490 </table>
1491 ';
1492 $content.=$thumbNailCheck;
1493
1494 // Adding create folder + upload forms if applicable:
1495 if (!$BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) $content.=$uploadForm;
1496 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.createFoldersInEB')) $content.=$createFolder;
1497
1498 // Add some space
1499 $content.='<br /><br />';
1500
1501 // Ending page, returning content:
1502 $content.= $this->doc->endPage();
1503 $content = $this->doc->insertStylesAndJS($content);
1504 return $content;
1505 }
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525 /******************************************************************
1526 *
1527 * Record listing
1528 *
1529 ******************************************************************/
1530 /**
1531 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1532 *
1533 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1534 */
1535 function expandPage() {
1536 global $BE_USER, $BACK_PATH;
1537
1538 $out='';
1539 $expPageId = $this->expandPage; // Set page id (if any) to expand
1540
1541 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1542 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1543 $expPageId = $this->curUrlInfo['pageid']; // Set to the current link page id.
1544 }
1545
1546 // Draw the record list IF there is a page id to expand:
1547 if ($expPageId && t3lib_div::testInt($expPageId) && $BE_USER->isInWebMount($expPageId)) {
1548
1549 // Set header:
1550 $out.=$this->barheader($GLOBALS['LANG']->getLL('contentElements').':');
1551
1552 // Create header for listing, showing the page title/icon:
1553 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1554 $mainPageRec = t3lib_BEfunc::getRecordWSOL('pages',$expPageId);
1555 $picon=t3lib_iconWorks::getIconImage('pages',$mainPageRec,'','');
1556 $picon.= htmlspecialchars(t3lib_div::fixed_lgd_cs($mainPageRec['title'],$titleLen));
1557 $out.=$picon.'<br />';
1558
1559 // Look up tt_content elements from the expanded page:
1560 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1561 'uid,header,hidden,starttime,endtime,fe_group,CType,colpos,bodytext',
1562 'tt_content',
1563 'pid='.intval($expPageId).
1564 t3lib_BEfunc::deleteClause('tt_content').
1565 t3lib_BEfunc::versioningPlaceholderClause('tt_content'),
1566 '',
1567 'colpos,sorting'
1568 );
1569 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1570
1571 // Traverse list of records:
1572 $c=0;
1573 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1574 $c++;
1575 $icon=t3lib_iconWorks::getIconImage('tt_content',$row,$BACK_PATH,'');
1576 if ($this->curUrlInfo['act']=='page' && $this->curUrlInfo['cElement']==$row['uid']) {
1577 $arrCol='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="c-blinkArrowL" alt="" />';
1578 } else {
1579 $arrCol='';
1580 }
1581 // Putting list element HTML together:
1582 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($c==$cc?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
1583 $arrCol.
1584 '<a href="#" onclick="return link_typo3Page(\''.$expPageId.'\',\'#'.$row['uid'].'\');">'.
1585 $icon.
1586 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['header'],$titleLen)).
1587 '</a><br />';
1588
1589 // Finding internal anchor points:
1590 if (t3lib_div::inList('text,textpic', $row['CType'])) {
1591 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1592
1593 foreach($split as $skey => $sval) {
1594 if (($skey%3)==2) {
1595 // Putting list element HTML together:
1596 $sval = substr($sval,0,100);
1597 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
1598 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($skey+3>count($split)?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
1599 '<a href="#" onclick="return link_typo3Page(\''.$expPageId.'\',\'#'.rawurlencode($sval).'\');">'.
1600 htmlspecialchars(' <A> '.$sval).
1601 '</a><br />';
1602 }
1603 }
1604 }
1605 }
1606 }
1607 return $out;
1608 }
1609
1610 /**
1611 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1612 *
1613 * @param string Commalist of tables. Set to "*" if you want all tables.
1614 * @return string HTML output.
1615 */
1616 function TBE_expandPage($tables) {
1617 global $TCA,$BE_USER, $BACK_PATH;
1618
1619 $out='';
1620 if ($this->expandPage>=0 && t3lib_div::testInt($this->expandPage) && $BE_USER->isInWebMount($this->expandPage)) {
1621
1622 // Set array with table names to list:
1623 if (!strcmp(trim($tables),'*')) {
1624 $tablesArr = array_keys($TCA);
1625 } else {
1626 $tablesArr = t3lib_div::trimExplode(',',$tables,1);
1627 }
1628 reset($tablesArr);
1629
1630 // Headline for selecting records:
1631 $out.=$this->barheader($GLOBALS['LANG']->getLL('selectRecords').':');
1632
1633 // Create the header, showing the current page for which the listing is. Includes link to the page itself, if pages are amount allowed tables.
1634 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1635 $mainPageRec = t3lib_BEfunc::getRecordWSOL('pages',$this->expandPage);
1636 $ATag='';
1637 $ATag_e='';
1638 $ATag2='';
1639 if (in_array('pages',$tablesArr)) {
1640 $ficon=t3lib_iconWorks::getIcon('pages',$mainPageRec);
1641 $ATag="<a href=\"#\" onclick=\"return insertElement('pages', '".$mainPageRec['uid']."', 'db', ".t3lib_div::quoteJSvalue($mainPageRec['title']).", '', '', '".$ficon."','',1);\">";
1642 $ATag2="<a href=\"#\" onclick=\"return insertElement('pages', '".$mainPageRec['uid']."', 'db', ".t3lib_div::quoteJSvalue($mainPageRec['title']).", '', '', '".$ficon."','',0);\">";
1643 $ATag_alt=substr($ATag,0,-4).",'',1);\">";
1644 $ATag_e='</a>';
1645 }
1646 $picon=t3lib_iconWorks::getIconImage('pages',$mainPageRec,$BACK_PATH,'');
1647 $pBicon=$ATag2?'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' alt="" />':'';
1648 $pText=htmlspecialchars(t3lib_div::fixed_lgd_cs($mainPageRec['title'],$titleLen));
1649 $out.=$picon.$ATag2.$pBicon.$ATag_e.$ATag.$pText.$ATag_e.'<br />';
1650
1651 // Initialize the record listing:
1652 $id = $this->expandPage;
1653 $pointer = t3lib_div::intInRange($this->pointer,0,100000);
1654 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1655 $pageinfo = t3lib_BEfunc::readPageAccess($id,$perms_clause);
1656 $table='';
1657
1658 // Generate the record list:
1659 $dblist = t3lib_div::makeInstance('TBE_browser_recordList');
1660 $dblist->thisScript=$this->thisScript;
1661 $dblist->backPath = $GLOBALS['BACK_PATH'];
1662 $dblist->thumbs = 0;
1663 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
1664 $dblist->noControlPanels=1;
1665 $dblist->clickMenuEnabled=0;
1666 $dblist->tableList=implode(',',$tablesArr);
1667
1668 $dblist->start($id,t3lib_div::_GP('table'),$pointer,
1669 t3lib_div::_GP('search_field'),
1670 t3lib_div::_GP('search_levels'),
1671 t3lib_div::_GP('showLimit')
1672 );
1673 $dblist->setDispFields();
1674 $dblist->generateList();
1675 $dblist->writeBottom();
1676
1677 // Add the HTML for the record list to output variable:
1678 $out.=$dblist->HTMLcode;
1679 $out.=$dblist->getSearchBox();
1680 }
1681
1682 // Return accumulated content:
1683 return $out;
1684 }
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697 /******************************************************************
1698 *
1699 * File listing
1700 *
1701 ******************************************************************/
1702 /**
1703 * For RTE: This displays all files from folder. No thumbnails shown
1704 *
1705 * @param string The folder path to expand
1706 * @param string List of fileextensions to show
1707 * @return string HTML output
1708 */
1709 function expandFolder($expandFolder=0,$extensionList='') {
1710 global $BACK_PATH;
1711
1712 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
1713 $out='';
1714 if ($expandFolder && $this->checkFolder($expandFolder)) {
1715
1716 // Create header for filelisting:
1717 $out.=$this->barheader($GLOBALS['LANG']->getLL('files').':');
1718
1719 // Prepare current path value for comparison (showing red arrow)
1720 if (!$this->curUrlInfo['value']) {
1721 $cmpPath='';
1722 } else {
1723 $cmpPath=PATH_site.$this->curUrlInfo['info'];
1724 }
1725
1726
1727 // Create header element; The folder from which files are listed.
1728 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1729 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
1730 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
1731 $picon='<a href="#" onclick="return link_folder(\''.t3lib_div::rawUrlEncodeFP(substr($expandFolder,strlen(PATH_site))).'\');">'.$picon.'</a>';
1732 $out.=$picon.'<br />';
1733
1734 // Get files from the folder:
1735 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
1736 $c=0;
1737 $cc=count($files);
1738
1739 if (is_array($files)) {
1740 foreach($files as $filepath) {
1741 $c++;
1742 $fI=pathinfo($filepath);
1743
1744 // File icon:
1745 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1746
1747 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1748 if ($this->curUrlInfo['act']=="file" && $cmpPath==$filepath) {
1749 $arrCol='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="c-blinkArrowL" alt="" />';
1750 } else {
1751 $arrCol='';
1752 }
1753
1754 // Get size and icon:
1755 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes)';
1756 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
1757
1758 // Put it all together for the file element:
1759 $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($c==$cc?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
1760 $arrCol.
1761 '<a href="#" onclick="return link_folder(\''.t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site))).'\');">'.
1762 $icon.
1763 htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).
1764 '</a><br />';
1765 }
1766 }
1767 }
1768 return $out;
1769 }
1770
1771 /**
1772 * For TYPO3 Element Browser: Expand folder of files.
1773 *
1774 * @param string The folder path to expand
1775 * @param string List of fileextensions to show
1776 * @param boolean Whether to show thumbnails or not. If set, no thumbnails are shown.
1777 * @return string HTML output
1778 */
1779 function TBE_expandFolder($expandFolder=0,$extensionList='',$noThumbs=0) {
1780 global $LANG;
1781
1782 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
1783 $out='';
1784 if ($expandFolder && $this->checkFolder($expandFolder)) {
1785 // Listing the files:
1786 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
1787 $out.= $this->fileList($files, $expandFolder, $noThumbs);
1788 }
1789
1790 // Return accumulated content for filelisting:
1791 return $out;
1792 }
1793
1794 /**
1795 * Render list of files.
1796 *
1797 * @param array List of files. See t3lib_div::getFilesInDir
1798 * @param string If set a header with a folder icon and folder name are shown
1799 * @param boolean Whether to show thumbnails or not. If set, no thumbnails are shown.
1800 * @return string HTML output
1801 */
1802 function fileList($files, $folderName='', $noThumbs=0) {
1803 global $LANG, $BACK_PATH;
1804
1805 $out='';
1806
1807 // Listing the files:
1808 if (is_array($files)) {
1809
1810 // Create headline (showing number of files):
1811 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
1812
1813 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1814
1815 // Create the header of current folder:
1816 if($folderName) {
1817 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
1818 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($folderName),$titleLen));
1819 $out.=$picon.'<br />';
1820 }
1821
1822 // Init graphic object for reading file dimensions:
1823 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
1824 $imgObj->init();
1825 $imgObj->mayScaleUp=0;
1826 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
1827
1828 // Traverse the file list:
1829 $lines=array();
1830 foreach($files as $filepath) {
1831 $fI=pathinfo($filepath);
1832
1833 // Thumbnail/size generation:
1834 if (t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$fI['extension']) && !$noThumbs) {
1835 $imgInfo = $imgObj->getImageDimensions($filepath);
1836 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
1837 $clickIcon = t3lib_BEfunc::getThumbNail($BACK_PATH.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"');
1838 } else {
1839 $clickIcon = '';
1840 $pDim = '';
1841 }
1842
1843 // Create file icon:
1844 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1845 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
1846 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" class="absmiddle" alt="" />';
1847
1848 // Create links for adding the file:
1849 if (strstr($filepath,',') || strstr($filepath,'|')) { // In case an invalid character is in the filepath, display error message:
1850 $eMsg = $LANG->JScharCode(sprintf($LANG->getLL('invalidChar'),', |'));
1851 $ATag = $ATag_alt = "<a href=\"#\" onclick=\"alert(".$eMsg.");return false;\">";
1852 } else { // If filename is OK, just add it:
1853 $ATag = "<a href=\"#\" onclick=\"return insertElement('','".t3lib_div::shortMD5($filepath)."', 'file', '".rawurlencode($fI['basename'])."', unescape('".rawurlencode($filepath)."'), '".$fI['extension']."', '".$ficon."');\">";
1854 $ATag_alt = substr($ATag,0,-4).",'',1);\">";
1855 }
1856 $ATag_e='</a>';
1857
1858 // Create link to showing details about the file in a window:
1859 $Ahref = $BACK_PATH.'show_item.php?table='.rawurlencode($filepath).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
1860 $ATag2='<a href="'.htmlspecialchars($Ahref).'">';
1861 $ATag2_e='</a>';
1862
1863 // Combine the stuff:
1864 $filenameAndIcon=$ATag_alt.$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).$ATag_e;
1865
1866 // Show element:
1867 if ($pDim) { // Image...
1868 $lines[]='
1869 <tr class="bgColor4">
1870 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
1871 <td>'.$ATag.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$LANG->getLL('addToList',1).'" alt="" />'.$ATag_e.'</td>
1872 <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>
1873 <td nowrap="nowrap">&nbsp;'.$pDim.'</td>
1874 </tr>';
1875 $lines[]='
1876 <tr>
1877 <td colspan="4">'.$ATag_alt.$clickIcon.$ATag_e.'</td>
1878 </tr>';
1879 } else {
1880 $lines[]='
1881 <tr class="bgColor4">
1882 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
1883 <td>'.$ATag.'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$LANG->getLL('addToList',1).'" alt="" />'.$ATag_e.'</td>
1884 <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>
1885 <td>&nbsp;</td>
1886 </tr>';
1887 }
1888 $lines[]='
1889 <tr>
1890 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
1891 </tr>';
1892 }
1893
1894 // Wrap all the rows in table tags:
1895 $out.='
1896
1897
1898
1899 <!--
1900 File listing
1901 -->
1902 <table border="0" cellpadding="0" cellspacing="1" id="typo3-fileList">
1903 '.implode('',$lines).'
1904 </table>';
1905 }
1906
1907 // Return accumulated content for filelisting:
1908 return $out;
1909 }
1910
1911 /**
1912 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
1913 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
1914 *
1915 * @param string The folder path to expand
1916 * @param string List of fileextensions to show
1917 * @return string HTML output
1918 */
1919 function TBE_dragNDrop($expandFolder=0,$extensionList='') {
1920 global $BACK_PATH;
1921
1922 $expandFolder = $expandFolder ? $expandFolder : $this->expandFolder;
1923 $out='';
1924 if ($expandFolder && $this->checkFolder($expandFolder)) {
1925 if ($this->isWebFolder($expandFolder)) {
1926
1927 // Read files from directory:
1928 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
1929 if (is_array($files)) {
1930 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
1931
1932 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1933 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
1934 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
1935 $out.=$picon.'<br />';
1936
1937 // Init row-array:
1938 $lines=array();
1939
1940 // Add "drag-n-drop" message:
1941 $lines[]='
1942 <tr>
1943 <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
1944 </tr>';
1945
1946 // Fraverse files:
1947 while(list(,$filepath)=each($files)) {
1948 $fI=pathinfo($filepath);
1949
1950 // URL of image:
1951 $iurl = $this->siteURL.t3lib_div::rawurlencodeFP(substr($filepath,strlen(PATH_site)));
1952
1953 // Show only web-images
1954 if (t3lib_div::inList('gif,jpeg,jpg,png',$fI['extension'])) {
1955 $imgInfo = @getimagesize($filepath);
1956 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
1957
1958 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1959 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
1960 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
1961 $filenameAndIcon=$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen));
1962
1963 if (t3lib_div::_GP('noLimit')) {
1964 $maxW=10000;
1965 $maxH=10000;
1966 } else {
1967 $maxW=380;
1968 $maxH=500;
1969 }
1970 $IW = $imgInfo[0];
1971 $IH = $imgInfo[1];
1972 if ($IW>$maxW) {
1973 $IH=ceil($IH/$IW*$maxW);
1974 $IW=$maxW;
1975 }
1976 if ($IH>$maxH) {
1977 $IW=ceil($IW/$IH*$maxH);
1978 $IH=$maxH;
1979 }
1980
1981 // Make row:
1982 $lines[]='
1983 <tr class="bgColor4">
1984 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
1985 <td nowrap="nowrap">'.
1986 ($imgInfo[0]!=$IW ? '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('noLimit'=>'1'))).'">'.
1987 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/icon_warning2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('clickToRedrawFullSize',1).'" alt="" />'.
1988 '</a>':'').
1989 $pDim.'&nbsp;</td>
1990 </tr>';
1991
1992 $lines[]='
1993 <tr>
1994 <td colspan="2"><img src="'.$iurl.'" width="'.$IW.'" height="'.$IH.'" border="1" alt="" /></td>
1995 </tr>';
1996 $lines[]='
1997 <tr>
1998 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
1999 </tr>';
2000 }
2001 }
2002
2003 // Finally, wrap all rows in a table tag:
2004 $out.='
2005
2006
2007 <!--
2008 File listing / Drag-n-drop
2009 -->
2010 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2011 '.implode('',$lines).'
2012 </table>';
2013 }
2014 } else {
2015 // Print this warning if the folder is NOT a web folder:
2016 $out.=$this->barheader($GLOBALS['LANG']->getLL('files'));
2017 $out.=$this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'),'icon_warning2');
2018 }
2019 }
2020 return $out;
2021 }
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034 /******************************************************************
2035 *
2036 * Miscellaneous functions
2037 *
2038 ******************************************************************/
2039
2040
2041 /**
2042 * Verifies that a path is a web-folder:
2043 *
2044 * @param string Absolute filepath
2045 * @return boolean If the input path is found in PATH_site then it returns true.
2046 */
2047 function isWebFolder($folder) {
2048 $folder = ereg_replace('\/$','',$folder).'/';
2049 return t3lib_div::isFirstPartOfStr($folder,PATH_site) ? TRUE : FALSE;
2050 }
2051
2052 /**
2053 * Checks, if a path is within the mountpoints of the backend user
2054 *
2055 * @param string Absolute filepath
2056 * @return boolean If the input path is found in the backend users filemounts, then return true.
2057 */
2058 function checkFolder($folder) {
2059 $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
2060 $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
2061
2062 return $fileProcessor->checkPathAgainstMounts(ereg_replace('\/$','',$folder).'/') ? TRUE : FALSE;
2063 }
2064
2065 /**
2066 * Prints a 'header' where string is in a tablecell
2067 *
2068 * @param string The string to print in the header. The value is htmlspecialchars()'ed before output.
2069 * @return string The header HTML (wrapped in a table)
2070 */
2071 function barheader($str) {
2072 return '
2073
2074 <!--
2075 Bar header:
2076 -->
2077 <h3 class="bgColor5">'.htmlspecialchars($str).'</h3>
2078 ';
2079 }
2080
2081 /**
2082 * Displays a message box with the input message
2083 *
2084 * @param string Input message to show (will be htmlspecialchars()'ed inside of this function)
2085 * @param string Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
2086 * @return string HTML for the message (wrapped in a table).
2087 */
2088 function getMsgBox($in_msg,$icon='icon_note') {
2089 global $BACK_PATH;
2090
2091 $msg = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/'.$icon.'.gif','width="18" height="16"').' alt="" />'.htmlspecialchars($in_msg);
2092 $msg = '
2093
2094 <!--
2095 Message box:
2096 -->
2097 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2098 <tr>
2099 <td>'.$msg.'</td>
2100 </tr>
2101 </table>
2102 ';
2103 return $msg;
2104 }
2105
2106 /**
2107 * For RTE/link: This prints the 'currentUrl'
2108 *
2109 * @param string URL value. The value is htmlspecialchars()'ed before output.
2110 * @return string HTML content, wrapped in a table.
2111 */
2112 function printCurrentUrl($str) {
2113 return '
2114
2115 <!--
2116 Print current URL
2117 -->
2118 <table border="0" cellpadding="0" cellspacing="0" class="bgColor5" id="typo3-curUrl">
2119 <tr>
2120 <td>'.$GLOBALS['LANG']->getLL('currentLink',1).': '.htmlspecialchars(rawurldecode($str)).'</td>
2121 </tr>
2122 </table>';
2123 }
2124
2125 /**
2126 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2127 *
2128 * @param string HREF value tp analyse
2129 * @param string The URL of the current website (frontend)
2130 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2131 */
2132 function parseCurUrl($href,$siteUrl) {
2133 $href = trim($href);
2134 if ($href) {
2135 $info=array();
2136
2137 // Default is "url":
2138 $info['value']=$href;
2139 $info['act']='url';
2140
2141 $specialParts = explode('#_SPECIAL',$href);
2142 if (count($specialParts)==2) { // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2143 $info['value']='#_SPECIAL'.$specialParts[1];
2144 $info['act']='spec';
2145 } elseif (t3lib_div::isFirstPartOfStr($href,$siteUrl)) { // If URL is on the current frontend website:
2146 $rel = substr($href,strlen($siteUrl));
2147 if (@file_exists(PATH_site.rawurldecode($rel))) { // URL is a file, which exists:
2148 $info['value']=rawurldecode($rel);
2149 $info['act']='file';
2150 } else { // URL is a page (id parameter)
2151 $uP=parse_url($rel);
2152 if (!trim($uP['path'])) {
2153 $pp = explode('id=',$uP['query']);
2154 $id = $pp[1];
2155 if ($id) {
2156 // Checking if the id-parameter is an alias.
2157 if (!t3lib_div::testInt($id)) {
2158 list($idPartR) = t3lib_BEfunc::getRecordsByField('pages','alias',$id);
2159 $id=intval($idPartR['uid']);
2160 }
2161
2162 $pageRow = t3lib_BEfunc::getRecordWSOL('pages',$id);
2163 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
2164 $info['value']=$GLOBALS['LANG']->getLL('page',1)." '".htmlspecialchars(t3lib_div::fixed_lgd_cs($pageRow['title'],$titleLen))."' (ID:".$id.($uP['fragment']?', #'.$uP['fragment']:'').')';
2165 $info['pageid']=$id;
2166 $info['cElement']=$uP['fragment'];
2167 $info['act']='page';
2168 }
2169 }
2170 }
2171 } else { // Email link:
2172 if (strtolower(substr($href,0,7))=='mailto:') {
2173 $info['value']=trim(substr($href,7));
2174 $info['act']='mail';
2175 }
2176 }
2177 $info['info'] = $info['value'];
2178 } else { // NO value inputted:
2179 $info=array();
2180 $info['info']=$GLOBALS['LANG']->getLL('none');
2181 $info['value']='';
2182 $info['act']='page';
2183 }
2184 return $info;
2185 }
2186
2187 /**
2188 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2189 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2190 *
2191 * @param string Absolute filepath on server to which to upload.
2192 * @return string HTML for an upload form.
2193 */
2194 function uploadForm($path) {
2195 global $BACK_PATH;
2196 $count=3;
2197
2198 // Create header, showing upload path:
2199 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
2200 $code=$this->barheader($GLOBALS['LANG']->getLL('uploadImage').':');
2201 $code.='
2202
2203 <!--
2204 Form, for uploading files:
2205 -->
2206 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">
2207 <table border="0" cellpadding="0" cellspacing="3" id="typo3-uplFiles">
2208 <tr>
2209 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
2210 </tr>
2211 <tr>
2212 <td>';
2213
2214 // Traverse the number of upload fields (default is 3):
2215 for ($a=1;$a<=$count;$a++) {
2216 $code.='<input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" />
2217 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($path).'" />
2218 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />';
2219 }
2220
2221 // Make footer of upload form, including the submit button:
2222 $redirectValue = $this->thisScript.'?act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
2223 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
2224 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />';
2225
2226 $code.='
2227 <div id="c-override">
2228 <input type="checkbox" name="overwriteExistingFiles" value="1" /> '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:overwriteExistingFiles',1).'
2229 </div>
2230 ';
2231
2232
2233 $code.='</td>
2234 </tr>
2235 </table>
2236 </form>';
2237
2238 return $code;
2239 }
2240
2241 /**
2242 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2243 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2244 *
2245 * @param string Absolute filepath on server in which to create the new folder.
2246 * @return string HTML for the create folder form.
2247 */
2248 function createFolder($path) {
2249 global $BACK_PATH;
2250 // Create header, showing upload path:
2251 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
2252 $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle').':');
2253 $code.='
2254
2255 <!--
2256 Form, for creating new folders:
2257 -->
2258 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform2">
2259 <table border="0" cellpadding="0" cellspacing="3" id="typo3-crFolder">
2260 <tr>
2261 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
2262 </tr>
2263 <tr>
2264 <td>';
2265
2266 // Create the new-folder name field:
2267 $a=1;
2268 $code.='<input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" />'.
2269 '<input type="hidden" name="file[newfolder]['.$a.'][target]" value="'.htmlspecialchars($path).'" />';
2270
2271 // Make footer of upload form, including the submit button:
2272 $redirectValue = $this->thisScript.'?act='.$this->act.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
2273 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
2274 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit',1).'" />';
2275
2276 $code.='</td>
2277 </tr>
2278 </table>
2279 </form>';
2280
2281 return $code;
2282 }
2283 }
2284
2285 // Include extension?
2286 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php']) {
2287 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php']);
2288 }
2289
2290
2291 ?>