git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4899 709f56b5-9817-0410-a4d7...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_positionmap.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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 * Contains class for creating a position map.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 * XHTML compliant (should be)
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 85: class t3lib_positionMap
42 *
43 * SECTION: Page position map:
44 * 132: function positionTree($id,$pageinfo,$perms_clause,$R_URI)
45 * 246: function JSimgFunc($prefix='')
46 * 276: function boldTitle($t_code,$dat,$id)
47 * 293: function onClickEvent($pid,$newPagePID)
48 * 312: function insertlabel()
49 * 324: function linkPageTitle($str,$rec)
50 * 335: function checkNewPageInPid($pid)
51 * 351: function getModConfig($pid)
52 * 366: function insertQuadLines($codes,$allBlank=0)
53 *
54 * SECTION: Content element positioning:
55 * 404: function printContentElementColumns($pid,$moveUid,$colPosList,$showHidden,$R_URI)
56 * 442: function printRecordMap($lines,$colPosArray)
57 * 480: function wrapColumnHeader($str,$vv)
58 * 494: function insertPositionIcon($row,$vv,$kk,$moveUid,$pid)
59 * 511: function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0)
60 * 531: function wrapRecordHeader($str,$row)
61 * 541: function getRecordHeader($row)
62 * 554: function wrapRecordTitle($str,$row)
63 *
64 * TOTAL FUNCTIONS: 17
65 * (This index is automatically created/updated by the extension "extdeveval")
66 *
67 */
68
69
70
71
72
73
74
75
76
77 /**
78 * Position map class - generating a page tree / content element list which links for inserting (copy/move) of records.
79 * Used for pages / tt_content element wizards of various kinds.
80 *
81 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
82 * @package TYPO3
83 * @subpackage t3lib
84 */
85 class t3lib_positionMap {
86
87 // EXTERNAL, static:
88 var $moveOrCopy='move';
89 var $dontPrintPageInsertIcons=0;
90 var $backPath='';
91 var $depth=2; // How deep the position page tree will go.
92 var $cur_sys_language; // Can be set to the sys_language uid to select content elements for.
93
94
95 // INTERNAL, dynamic:
96 var $R_URI=''; // Request uri
97 var $elUid=''; // Element id.
98 var $moveUid=''; // tt_content element uid to move.
99
100 // Caching arrays:
101 var $getModConfigCache=array();
102 var $checkNewPageCache=Array();
103
104 // Label keys:
105 var $l_insertNewPageHere = 'insertNewPageHere';
106 var $l_insertNewRecordHere = 'insertNewRecordHere';
107
108 var $modConfigStr='mod.web_list.newPageWiz';
109
110
111
112
113
114
115
116 /*************************************
117 *
118 * Page position map:
119 *
120 **************************************/
121
122 /**
123 * Creates a "position tree" based on the page tree.
124 * Notice: A class, "localPageTree" must exist and probably it is an extension class of the t3lib_pageTree class. See "db_new.php" in the core for an example.
125 *
126 * @param integer Current page id
127 * @param array Current page record.
128 * @param string Page selection permission clause.
129 * @param string Current REQUEST_URI
130 * @return string HTML code for the tree.
131 */
132 function positionTree($id,$pageinfo,$perms_clause,$R_URI) {
133 global $LANG, $BE_USER;
134
135 // Make page tree object:
136 $t3lib_pageTree = t3lib_div::makeInstance('localPageTree');
137 $t3lib_pageTree->init(' AND '.$perms_clause);
138 $t3lib_pageTree->addField('pid');
139
140 // Initialize variables:
141 $this->R_URI = $R_URI;
142 $this->elUid = $id;
143
144 // Create page tree, in $this->depth levels.
145 $t3lib_pageTree->getTree($pageinfo['pid'], $this->depth);
146 if (!$this->dontPrintPageInsertIcons) $code.=$this->JSimgFunc();
147
148 // Initialize variables:
149 $saveBlankLineState=array();
150 $saveLatestUid=array();
151 $latestInvDepth=$this->depth;
152
153 // Traverse the tree:
154 foreach($t3lib_pageTree->tree as $cc => $dat) {
155
156 // Make link + parameters.
157 $latestInvDepth=$dat['invertedDepth'];
158 $saveLatestUid[$latestInvDepth]=$dat;
159 if (isset($t3lib_pageTree->tree[$cc-1])) {
160 $prev_dat = $t3lib_pageTree->tree[$cc-1];
161
162 // If current page, subpage?
163 if ($prev_dat['row']['uid']==$id) {
164 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id) && !($prev_dat['invertedDepth']>$t3lib_pageTree->tree[$cc]['invertedDepth'])) { // 1) It must be allowed to create a new page and 2) If there are subpages there is no need to render a subpage icon here - it'll be done over the subpages...
165 $code.='<span class="nobr">'.
166 $this->insertQuadLines($dat['blankLineCode']).
167 '<img src="clear.gif" width="18" height="8" align="top" alt="" />'.
168 '<a href="#" onclick="'.htmlspecialchars($this->onClickEvent($id,$id,1)).'" onmouseover="'.htmlspecialchars('changeImg(\'mImgSubpage'.$cc.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImgSubpage'.$cc.'\',1);').'">'.
169 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord_marker_d.gif','width="281" height="8"').' name="mImgSubpage'.$cc.'" border="0" align="top" title="'.$this->insertlabel().'" alt="" />'.
170 '</a></span><br />';
171 }
172 }
173
174 if ($prev_dat['invertedDepth']>$t3lib_pageTree->tree[$cc]['invertedDepth']) { // If going down
175 $prevPid = $t3lib_pageTree->tree[$cc]['row']['pid'];
176 } elseif ($prev_dat['invertedDepth']<$t3lib_pageTree->tree[$cc]['invertedDepth']) { // If going up
177 // First of all the previous level should have an icon:
178 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($prev_dat['row']['pid'])) {
179 $prevPid = (-$prev_dat['row']['uid']);
180 $code.='<span class="nobr">'.
181 $this->insertQuadLines($dat['blankLineCode']).
182 '<img src="clear.gif" width="18" height="1" align="top" alt="" />'.
183 '<a href="#" onclick="'.htmlspecialchars($this->onClickEvent($prevPid,$prev_dat['row']['pid'],2)).'" onmouseover="'.htmlspecialchars('changeImg(\'mImgAfter'.$cc.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImgAfter'.$cc.'\',1);').'">'.
184 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord_marker_d.gif','width="281" height="8"').' name="mImgAfter'.$cc.'" border="0" align="top" title="'.$this->insertlabel().'" alt="" />'.
185 '</a></span><br />';
186 }
187
188 // Then set the current prevPid
189 $prevPid = -$prev_dat['row']['pid'];
190 } else {
191 $prevPid = -$prev_dat['row']['uid']; // In on the same level
192 }
193 } else {
194 $prevPid = $dat['row']['pid']; // First in the tree
195 }
196 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
197 $code.='<span class="nobr">'.
198 $this->insertQuadLines($dat['blankLineCode']).
199 '<a href="#" onclick="'.htmlspecialchars($this->onClickEvent($prevPid,$dat['row']['pid'],3)).'" onmouseover="'.htmlspecialchars('changeImg(\'mImg'.$cc.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImg'.$cc.'\',1);').'">'.
200 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord_marker_d.gif','width="281" height="8"').' name="mImg'.$cc.'" border="0" align="top" title="'.$this->insertlabel().'" alt="" />'.
201 '</a></span><br />';
202 }
203
204 // The line with the icon and title:
205 $t_code='<span class="nobr">'.
206 $dat['HTML'].
207 $this->linkPageTitle($this->boldTitle(htmlspecialchars(t3lib_div::fixed_lgd_cs($dat['row']['title'],$BE_USER->uc['titleLen'])),$dat,$id),$dat['row']).
208 '</span><br />';
209 $code.=$t_code;
210 }
211
212 // If the current page was the last in the tree:
213 $prev_dat = end($t3lib_pageTree->tree);
214 if ($prev_dat['row']['uid']==$id) {
215 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id)) {
216 $code.='<span class="nobr">'.
217 $this->insertQuadLines($saveLatestUid[$latestInvDepth]['blankLineCode'],1).
218 '<img src="clear.gif" width="18" height="8" align="top" alt="" />'.
219 '<a href="#" onclick="'.$this->onClickEvent($id,$id,4).'" onmouseover="'.htmlspecialchars('changeImg(\'mImgSubpage'.$cc.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImgSubpage'.$cc.'\',1);').'">'.
220 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord_marker_d.gif','width="281" height="8"').' name="mImgSubpage'.$cc.'" border="0" align="top" title="'.$this->insertlabel().'" alt="" />'.
221 '</a></span><br />';
222 }
223 }
224
225 for ($a=$latestInvDepth;$a<=$this->depth;$a++) {
226 $dat = $saveLatestUid[$a];
227 $prevPid = (-$dat['row']['uid']);
228 if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
229 $code.='<span class="nobr">'.
230 $this->insertQuadLines($dat['blankLineCode'],1).
231 '<a href="#" onclick="'.htmlspecialchars($this->onClickEvent($prevPid,$dat['row']['pid'],5)).'" onmouseover="'.htmlspecialchars('changeImg(\'mImgEnd'.$a.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImgEnd'.$a.'\',1);').'">'.
232 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord_marker_d.gif','width="281" height="8"').' name="mImgEnd'.$a.'" border="0" align="top" title="'.$this->insertlabel().'" alt="" />'.
233 '</a></span><br />';
234 }
235 }
236
237 return $code;
238 }
239
240 /**
241 * Creates the JavaScritp for insert new-record rollover image
242 *
243 * @param string Insert record image prefix.
244 * @return string <script> section
245 */
246 function JSimgFunc($prefix='') {
247 $code.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
248
249 var img_newrecord_marker=new Image();
250 img_newrecord_marker.src = "'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord'.$prefix.'_marker.gif','',1).'";
251
252 var img_newrecord_marker_d=new Image();
253 img_newrecord_marker_d.src = "'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord'.$prefix.'_marker_d.gif','',1).'";
254
255 function changeImg(name,d) { //
256 if (document[name]) {
257 if (d) {
258 document[name].src = img_newrecord_marker_d.src;
259 } else {
260 document[name].src = img_newrecord_marker.src;
261 }
262 }
263 }
264 ');
265 return $code;
266 }
267
268 /**
269 * Wrap $t_code in bold IF the $dat uid matches $id
270 *
271 * @param string Title string
272 * @param array Infomation array with record array inside.
273 * @param integer The current id.
274 * @return string The title string.
275 */
276 function boldTitle($t_code,$dat,$id) {
277 if ($dat['row']['uid']==$id) {
278 $t_code='<strong>'.$t_code.'</strong>';
279 }
280 return $t_code;
281 }
282
283 /**
284 * Creates the onclick event for the insert-icons.
285 *
286 * TSconfig mod.web_list.newPageWiz.overrideWithExtension may contain an extension which provides a module
287 * to be used instead of the normal create new page wizard.
288 *
289 * @param integer The pid.
290 * @param integer New page id.
291 * @return string Onclick attribute content
292 */
293 function onClickEvent($pid,$newPagePID) {
294 $TSconfigProp = $this->getModConfig($newPagePID);
295
296 if ($TSconfigProp['overrideWithExtension']) {
297 if (t3lib_extMgm::isLoaded($TSconfigProp['overrideWithExtension'])) {
298 $onclick = "window.location.href='".t3lib_extMgm::extRelPath($TSconfigProp['overrideWithExtension']).'mod1/index.php?cmd=crPage&positionPid='.$pid."';";
299 return $onclick;
300 }
301 }
302
303 $params='&edit[pages]['.$pid.']=new&returnNewPageId=1';
304 return t3lib_BEfunc::editOnClick($params,'',$this->R_URI);
305 }
306
307 /**
308 * Get label, htmlspecialchars()'ed
309 *
310 * @return string The localized label for "insert new page here"
311 */
312 function insertlabel() {
313 global $LANG;
314 return $LANG->getLL($this->l_insertNewPageHere,1);
315 }
316
317 /**
318 * Wrapping page title.
319 *
320 * @param string Page title.
321 * @param array Page record (?)
322 * @return string Wrapped title.
323 */
324 function linkPageTitle($str,$rec) {
325 return $str;
326 }
327
328 /**
329 * Checks if the user has permission to created pages inside of the $pid page.
330 * Uses caching so only one regular lookup is made - hence you can call the function multiple times without worrying about performance.
331 *
332 * @param integer Page id for which to test.
333 * @return boolean
334 */
335 function checkNewPageInPid($pid) {
336 global $BE_USER;
337 if (!isset($this->checkNewPageCache[$pid])) {
338 $pidInfo = t3lib_BEfunc::getRecord('pages',$pid);
339 $this->checkNewPageCache[$pid] = ($BE_USER->isAdmin() || $BE_USER->doesUserHaveAccess($pidInfo,8));
340 }
341 return $this->checkNewPageCache[$pid];
342 }
343
344 /**
345 * Returns module configuration for a pid.
346 *
347 * @param integer Page id for which to get the module configuration.
348 * @return array The properties of teh module configuration for the page id.
349 * @see onClickEvent()
350 */
351 function getModConfig($pid) {
352 if (!isset($this->getModConfigCache[$pid])) {
353 // Acquiring TSconfig for this PID:
354 $this->getModConfigCache[$pid] = t3lib_BEfunc::getModTSconfig($pid,$this->modConfigStr);
355 }
356 return $this->getModConfigCache[$pid]['properties'];
357 }
358
359 /**
360 * Insert half/quad lines.
361 *
362 * @param string keywords for which lines to insert.
363 * @param boolean If true all lines are just blank clear.gifs
364 * @return string HTML content.
365 */
366 function insertQuadLines($codes,$allBlank=0) {
367 $codeA = t3lib_div::trimExplode(',',$codes.",line",1);
368
369 $lines=array();
370 while(list(,$code)=each($codeA)) {
371 if ($code=="blank" || $allBlank) {
372 $lines[]='<img src="clear.gif" width="18" height="8" align="top" alt="" />';
373 } else {
374 $lines[]='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' align="top" alt="" />';
375 }
376 }
377 return implode('',$lines);
378 }
379
380
381
382
383
384
385
386
387
388 /*************************************
389 *
390 * Content element positioning:
391 *
392 **************************************/
393
394 /**
395 * Creates HTML for inserting/moving content elements.
396 *
397 * @param integer page id onto which to insert content element.
398 * @param integer Move-uid (tt_content element uid?)
399 * @param string List of columns to show
400 * @param boolean If not set, then hidden/starttime/endtime records are filtered out.
401 * @param string Request URI
402 * @return string HTML
403 */
404 function printContentElementColumns($pid,$moveUid,$colPosList,$showHidden,$R_URI) {
405 $this->R_URI = $R_URI;
406 $this->moveUid = $moveUid;
407 $colPosArray = t3lib_div::trimExplode(',',$colPosList,1);
408
409 $lines=array();
410 while(list($kk,$vv)=each($colPosArray)) {
411 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
412 '*',
413 'tt_content',
414 'pid='.intval($pid).
415 ($showHidden ? '' : t3lib_BEfunc::BEenableFields('tt_content')).
416 ' AND colPos='.intval($vv).
417 (strcmp($this->cur_sys_language,'') ? ' AND sys_language_uid='.intval($this->cur_sys_language) : '').
418 t3lib_BEfunc::deleteClause('tt_content').
419 t3lib_BEfunc::versioningPlaceholderClause('tt_content'),
420 '',
421 'sorting'
422 );
423 $lines[$kk]=array();
424 $lines[$kk][]=$this->insertPositionIcon('',$vv,$kk,$moveUid,$pid);
425 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
426 t3lib_BEfunc::workspaceOL('tt_content',$row);
427 if (is_array($row)) {
428 $lines[$kk][]=$this->wrapRecordHeader($this->getRecordHeader($row),$row);
429 $lines[$kk][]=$this->insertPositionIcon($row,$vv,$kk,$moveUid,$pid);
430 }
431 }
432 $GLOBALS['TYPO3_DB']->sql_free_result($res);
433 }
434 return $this->printRecordMap($lines,$colPosArray);
435 }
436
437 /**
438 * Creates the table with the content columns
439 *
440 * @param array Array with arrays of lines for each column
441 * @param array Column position array
442 * @return string HTML
443 */
444 function printRecordMap($lines,$colPosArray) {
445 $row1='';
446 $row2='';
447 $count = t3lib_div::intInRange(count($colPosArray),1);
448
449 // Traverse the columns here:
450 foreach($colPosArray as $kk => $vv) {
451 $row1.='<td align="center" width="'.round(100/$count).'%"><span class="uppercase"><strong>'.
452 $this->wrapColumnHeader($GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content','colPos',$vv),1),$vv).
453 '</strong></span></td>';
454 $row2.='<td valign="top" nowrap="nowrap">'.
455 implode('<br />',$lines[$kk]).
456 '</td>';
457 }
458
459 $table = '
460
461 <!--
462 Map of records in columns:
463 -->
464 <table border="0" cellpadding="0" cellspacing="1" id="typo3-ttContentList">
465 <tr class="bgColor5">'.$row1.'</tr>
466 <tr>'.$row2.'</tr>
467 </table>
468
469 ';
470
471 return $this->JSimgFunc('2').$table;
472 }
473
474 /**
475 * Wrapping the column header
476 *
477 * @param string Header value
478 * @param string Column info.
479 * @return string
480 * @see printRecordMap()
481 */
482 function wrapColumnHeader($str,$vv) {
483 return $str;
484 }
485
486 /**
487 * Creates a linked position icon.
488 *
489 * @param array Element row.
490 * @param string Column position value.
491 * @param integer Column key.
492 * @param integer Move uid
493 * @param integer PID value.
494 * @return string
495 */
496 function insertPositionIcon($row,$vv,$kk,$moveUid,$pid) {
497 $cc = hexdec(substr(md5($row['uid'].'-'.$vv.'-'.$kk),0,4));
498 return '<a href="#" onclick="'.htmlspecialchars($this->onClickInsertRecord($row,$vv,$moveUid,$pid,$this->cur_sys_language)).'" onmouseover="'.htmlspecialchars('changeImg(\'mImg'.$cc.'\',0);').'" onmouseout="'.htmlspecialchars('changeImg(\'mImg'.$cc.'\',1);').'">'.
499 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/newrecord2_marker_d.gif','width="100" height="8"').' name="mImg'.$cc.'" border="0" align="top" title="'.$GLOBALS['LANG']->getLL($this->l_insertNewRecordHere,1).'" alt="" />'.
500 '</a>';
501 }
502
503 /**
504 * Create on-click event value.
505 *
506 * @param array The record.
507 * @param string Column position value.
508 * @param integer Move uid
509 * @param integer PID value.
510 * @param integer System language (not used currently)
511 * @return string
512 */
513 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) {
514 $table='tt_content';
515 if (is_array($row)) {
516 $location='tce_db.php?cmd['.$table.']['.$moveUid.']['.$this->moveOrCopy.']=-'.$row['uid'].'&prErr=1&uPT=1&vC='.$GLOBALS['BE_USER']->veriCode();
517 } else {
518 $location='tce_db.php?cmd['.$table.']['.$moveUid.']['.$this->moveOrCopy.']='.$pid.'&data['.$table.']['.$moveUid.'][colPos]='.$vv.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode();
519 }
520 // $location.='&redirect='.rawurlencode($this->R_URI); // returns to prev. page
521 $location.='&uPT=1&redirect='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')); // This redraws screen
522
523 return 'window.location.href=\''.$location.'\';return false;';
524 }
525
526 /**
527 * Wrapping the record header (from getRecordHeader())
528 *
529 * @param string HTML content
530 * @param array Record array.
531 * @return string HTML content
532 */
533 function wrapRecordHeader($str,$row) {
534 return $str;
535 }
536
537 /**
538 * Create record header (includes teh record icon, record title etc.)
539 *
540 * @param array Record row.
541 * @return string HTML
542 */
543 function getRecordHeader($row) {
544 $line = t3lib_iconWorks::getIconImage('tt_content',$row,$this->backPath,' align="top" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($row,'tt_content')).'"');
545 $line.= t3lib_BEfunc::getRecordTitle('tt_content',$row,TRUE);
546 return $this->wrapRecordTitle($line,$row);
547 }
548
549 /**
550 * Wrapping the title of the record.
551 *
552 * @param string The title value.
553 * @param array The record row.
554 * @return string Wrapped title string.
555 */
556 function wrapRecordTitle($str,$row) {
557 return '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('uid'=>intval($row['uid']),'moveUid'=>''))).'">'.$str.'</a>';
558 }
559 }
560
561 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_positionmap.php']) {
562 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_positionmap.php']);
563 }
564 ?>