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