TYPO3 API  SVNRelease
example_itemArrayProcFunc.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * This is an example of how to manipulate menu item arrays.
00029  * Used in the "testsite" package
00030  *
00031  * $Id: example_itemArrayProcFunc.php 5165 2009-03-09 18:28:59Z ohader $
00032  * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
00033  * XHTML compliant
00034  *
00035  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00036  */
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 /**
00048  * This function basically adds the parent page to the sublevel but only if the sublevel is empty!
00049  * It is also used to demonstrate the menu state items
00050  *
00051  * 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/"
00052  * This TypoScript configuration will also demonstrate it ("fake menu items"):
00053  *
00054  * includeLibs.fakemenuitems = media/scripts/example_itemArrayProcFunc.php
00055  * page = PAGE
00056  * page.10 = HMENU
00057  * page.10.1 = TMENU
00058  * page.10.1.expAll = 1
00059  * page.10.1.NO {
00060  *   allWrap = | <br />
00061  *   linkWrap = <b>|</b>
00062  * }
00063  * page.10.2 = TMENU
00064  * page.10.2.itemArrayProcFunc = user_itemArrayProcFuncTest
00065  * page.10.2.NO {
00066  *   allWrap = | <br />
00067  *   linkWrap = <b> - |</b>
00068  * }
00069  *
00070  * @param   array       The $menuArr array which simply is a num-array of page records which goes into the menu.
00071  * @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)
00072  * @return  array       The modified $menuArr array
00073  */
00074 function user_itemArrayProcFuncTest($menuArr,$conf) {
00075     if ($conf['demoItemStates'])    {       // Used in the example of item states
00076         $c=0;
00077         $teststates=explode(',','NO,ACT,IFSUB,CUR,USR,SPC,USERDEF1,USERDEF2');
00078         foreach ($menuArr as $k => $v) {
00079             $menuArr[$k]['ITEM_STATE']=$teststates[$c];
00080             $menuArr[$k]['title'].= ($teststates[$c] ? ' ['.$teststates[$c].']' : '');
00081             $c++;
00082         }
00083     } else {    // used in the fake menu item example!
00084         if (!count($menuArr))   {       // There must be no menu items if we add the parent page to the submenu:
00085             $parentPageId = $conf['parentObj']->id; // id of the parent page
00086             $parentPageRow = $GLOBALS['TSFE']->sys_page->getPage($parentPageId);    // ... and get the record...
00087             if (is_array($parentPageRow))   {   // ... and if that page existed (a row was returned) then add it!
00088                 $menuArr[]=$parentPageRow;
00089             }
00090         }
00091     }
00092     return $menuArr;
00093 }
00094 
00095 /**
00096  * Used in the menu item state example of the "testsite" package at page-path "/Intro/TypoScript examples/Menu object examples/Menu state test/"
00097  *
00098  * @param   array       The menu item array, $this->I (in the parent object)
00099  * @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)
00100  * @return  array       The processed $I array returned (and stored in $this->I of the parent object again)
00101  * @see tslib_menu::userProcess(), tslib_tmenu::writeMenu(), tslib_gmenu::writeMenu()
00102  */
00103 function user_IProcFuncTest($I,$conf)   {
00104     $itemRow = $conf['parentObj']->menuArr[$I['key']];
00105 
00106         // Setting the document status content to the value of the page title on mouse over
00107     $I['linkHREF']['onMouseover'].='extraRollover(\''.rawurlencode($itemRow['title']).'\');';
00108     $conf['parentObj']->I = $I;
00109     $conf['parentObj']->setATagParts();
00110     $I = $conf['parentObj']->I;
00111     if ($I['parts']['ATag_begin'])  $I['parts']['ATag_begin']=$I['A1'];
00112 
00113     if ($conf['debug']) {
00114             // Outputting for debug example:
00115         echo 'ITEM: <h2>'.htmlspecialchars($itemRow['uid'].': '.$itemRow['title']).'</h2>';
00116         t3lib_utility_Debug::debug($itemRow);
00117         t3lib_utility_Debug::debug($I);
00118         echo '<hr />';
00119     }
00120         // Returns:
00121     return $I;
00122 }
00123 
00124 
00125 ?>