Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / statictemplates / media / scripts / example_itemArrayProcFunc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * This is an example of how to manipulate menu item arrays.
29 * Used in the "testsite" package
30 *
31 * $Id: example_itemArrayProcFunc.php 5165 2009-03-09 18:28:59Z ohader $
32 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
33 * XHTML compliant
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37
38
39
40
41
42
43
44
45
46
47 /**
48 * This function basically adds the parent page to the sublevel but only if the sublevel is empty!
49 * It is also used to demonstrate the menu state items
50 *
51 * Example can be found in the testsite package at the page-path "/Intro/TypoScript examples/Menu object examples/Fake menu items/" and "/Intro/TypoScript examples/Menu object examples/Menu state test/"
52 * This TypoScript configuration will also demonstrate it ("fake menu items"):
53 *
54 * includeLibs.fakemenuitems = media/scripts/example_itemArrayProcFunc.php
55 * page = PAGE
56 * page.10 = HMENU
57 * page.10.1 = TMENU
58 * page.10.1.expAll = 1
59 * page.10.1.NO {
60 * allWrap = | <br />
61 * linkWrap = <b>|</b>
62 * }
63 * page.10.2 = TMENU
64 * page.10.2.itemArrayProcFunc = user_itemArrayProcFuncTest
65 * page.10.2.NO {
66 * allWrap = | <br />
67 * linkWrap = <b> - |</b>
68 * }
69 *
70 * @param array The $menuArr array which simply is a num-array of page records which goes into the menu.
71 * @param array TypoScript configuration for the function. Notice that the property "parentObj" is a reference to the parent (calling) object (the tslib_Xmenu class instantiated)
72 * @return array The modified $menuArr array
73 */
74 function user_itemArrayProcFuncTest($menuArr,$conf) {
75 if ($conf['demoItemStates']) { // Used in the example of item states
76 $c=0;
77 $teststates=explode(',','NO,ACT,IFSUB,CUR,USR,SPC,USERDEF1,USERDEF2');
78 foreach ($menuArr as $k => $v) {
79 $menuArr[$k]['ITEM_STATE']=$teststates[$c];
80 $menuArr[$k]['title'].= ($teststates[$c] ? ' ['.$teststates[$c].']' : '');
81 $c++;
82 }
83 } else { // used in the fake menu item example!
84 if (!count($menuArr)) { // There must be no menu items if we add the parent page to the submenu:
85 $parentPageId = $conf['parentObj']->id; // id of the parent page
86 $parentPageRow = $GLOBALS['TSFE']->sys_page->getPage($parentPageId); // ... and get the record...
87 if (is_array($parentPageRow)) { // ... and if that page existed (a row was returned) then add it!
88 $menuArr[]=$parentPageRow;
89 }
90 }
91 }
92 return $menuArr;
93 }
94
95 /**
96 * Used in the menu item state example of the "testsite" package at page-path "/Intro/TypoScript examples/Menu object examples/Menu state test/"
97 *
98 * @param array The menu item array, $this->I (in the parent object)
99 * @param array TypoScript configuration for the function. Notice that the property "parentObj" is a reference to the parent (calling) object (the tslib_Xmenu class instantiated)
100 * @return array The processed $I array returned (and stored in $this->I of the parent object again)
101 * @see tslib_menu::userProcess(), tslib_tmenu::writeMenu(), tslib_gmenu::writeMenu()
102 */
103 function user_IProcFuncTest($I,$conf) {
104 $itemRow = $conf['parentObj']->menuArr[$I['key']];
105
106 // Setting the document status content to the value of the page title on mouse over
107 $I['linkHREF']['onMouseover'].='extraRollover(\''.rawurlencode($itemRow['title']).'\');';
108 $conf['parentObj']->I = $I;
109 $conf['parentObj']->setATagParts();
110 $I = $conf['parentObj']->I;
111 if ($I['parts']['ATag_begin']) $I['parts']['ATag_begin']=$I['A1'];
112
113 if ($conf['debug']) {
114 // Outputting for debug example:
115 echo 'ITEM: <h2>'.htmlspecialchars($itemRow['uid'].': '.$itemRow['title']).'</h2>';
116 t3lib_utility_Debug::debug($itemRow);
117 t3lib_utility_Debug::debug($I);
118 echo '<hr />';
119 }
120 // Returns:
121 return $I;
122 }
123
124
125 ?>