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