Hallo zusammen,
erstmal danke für die vielen Anregungen im umgang mit dem nsb_cat2menu plugin.
Irgendwie gefiel mir das verhalten der daraus resultierenden menüs so gar nicht.
Es funktionierte einfach nicht so wie ich es von dem normalen menüs gewohnt war.
Darum habe ich die PHP Datei class.tx_nbscat2menu_pi1.php nocheinmal etwas überarbeitet so das jetzt ein "Aufklappbarer Kategorien Baum" möglich ist bei dem auch zwischen dem Menüstatus CUR und ACT unterschieden wird. Und das ganze noch, weil es so schön ist, als "Unsorted List" im TS Template konfiguriert.
Ich habe diese Anpassung bis jetzt nur ganz grob getestet und auch erst einmal im Einsatz. Naja und besonders ordentlich ist der Quellcode auch noch nicht.
hier für die Interessierten mein Template und die PHP Datei
lib.nsbcat2menu = HMENU
lib.nsbcat2menu.special = userfunction
lib.nsbcat2menu.special.userFunc = tx_nsbcat2menu_pi1->main
lib.nsbcat2menu.special.catList=0
lib.nsbcat2menu.special.pidlist=246
lib.nsbcat2menu.special.catTable=tt_products_cat
lib.nsbcat2menu.special.parentEntry=parent_category
lib.nsbcat2menu.special.extTrigger=tx_ttproducts_pi1
lib.nsbcat2menu.special.varCat=cat
lib.nsbcat2menu.special.targetId = 213
lib.nsbcat2menu.special.recSel = 0 #Funktionalität im PHP ausgeschaltet
lib.nsbcat2menu.1 = TMENU
lib.nsbcat2menu.1 {
noBlur = 1
expAll = 0
NO = 1
NO {
ATagTitle.field = title
ATagParams = id="main-menu"
wrapItemAndSub = <li>|</li>|*|<li>|</li>|*|<li class="last">|</li>
}
ACT < .NO
ACT.ATagParams = id="main-menu{elementUid}" class="active"
}
lib.nsbcat2menu.2 = TMENU
lib.nsbcat2menu.2 {
wrap= <ul>|</ul>
noBlur = 1
expAll = 0
NO = 1
NO {
ATagTitle.field = title
ATagParams = id="main-menu"
wrapItemAndSub = <li>|</li>|*|<li>|</li>|*|<li class="last">|</li>
}
CUR < .NO
CUR.ATagParams = id="main-menu{elementUid}" class="active"
}
lib.nsbcat2menu.3 = TMENU
lib.nsbcat2menu.3 < lib.nsbcat2menu.2
lib.nsbcat2menu.4 = TMENU
lib.nsbcat2menu.4 < lib.nsbcat2menu.2
<?php
/***************************************************************
* Copyright notice
*
* (c) 2005 Sami Ben-yahia (sittinggoat@hotmail.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Plugin 'cat2menu' for the 'nsb_cat2menu' extension.
*
* @author Sami Ben-yahia <sittinggoat@hotmail.com>
*/
// modified by Nico Thomaier <nthomaier@creatible.com>
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_nsbcat2menu_pi1 extends tslib_pibase {
// var $prefixId = 'tx_nsbcat2menu_pi1'; // Same as class name (used only by pivars ?)
var $scriptRelPath = 'pi1/class.tx_nsbcat2menu_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'nsb_cat2menu'; // The extension key.
//i must think
var $pi_checkCHash = TRUE;
var $internal = Array( // Used internally for general storage of values between methods
'catArr' => Array(), //Current category table from pi_getCategoryTableContents
'recSelReg' => '' //Used only if the recursive select option is on (recursiveSelectionRegistry)
);
function main($content,$conf){
$this->conf=$conf;
//i don't expect side effects
$this->prefixId = $this->conf['extTrigger'];
$my_vars = $GLOBALS["TSFE"]->fe_user->getKey('ses','nsb_cat2menu');
$tmpAct = t3lib_div::_GET($this->prefixId);
$tmpAct = t3lib_div::intExplode(",",$tmpAct['cat']);
$this->conf['targetId']=$this->conf['targetId']?$this->conf['targetId']:0;
$table=$this->conf['catTable'];
$pid=$this->conf['pidlist'];
//get the whole autorized category table, the tree will be constructed later in php with makeMenuArray($rootLine)
$whereClause='';
$orderBy='';
$limit='';
$this->internal['catArr']=$this->pi_getCategoryTableContents($table,$pid,$whereClause,$groupBy,$orderBy,$limit);
//mark active or current for no cookie client config
while(current($tmpAct)){
$this->internal['catArr'][current($tmpAct)]['ITEM_STATE']='ACT';
$this->internal['catArr'][]['ITEM_STATE']='ACT';
$parent = $this->internal['catArr'][current($tmpAct)]['parent_category'];
array_push($tmpAct,$parent);
if ($tmpAct[0]==current($tmpAct)) $this->internal['catArr'][current($tmpAct)]['ITEM_STATE']='CUR';
next($tmpAct);
}
$menuArray=$this->makeMenuArray(t3lib_div::intExplode(",",$this->conf['catList']));
//this session storage alows different multiple instances only if the triggered extension is different
$my_vars[$this->prefixId]=$menuArray;
$GLOBALS["TSFE"]->fe_user->setKey('ses','nsb_cat2menu',$my_vars);
$retvar1 = $this->lightenMenu($menuArray);
return $retvar1;
}
//currently will get all the branches from the category 'rootline' no recursive level option
function makeMenuArray($rootLine){
//autodetect catList
if($rootLine[0] == 0) {
$i=0;
foreach($this->internal['catArr'] as $t){
if($t['parent_category'] == '0') {
$rootLine[$i] = $t['uid'] + 0;
$i++;
}
}
}
foreach($rootLine as $k => $v){
$menuArray[$k]=$this->internal['catArr'][$v];
$this->getHref($menuArray[$k]);
$act = 0;
if ($menuArray[$k]['ITEM_STATE']=="ACT" || $menuArray[$k]['ITEM_STATE']=="CUR" ) $act = 1;
$this->makeSubMenu($menuArray[$k], $act);
}
return $menuArray;
}
function makeSubMenu(&$menuArray,$act){
foreach($this->internal['catArr'] as $v){
if($menuArray['uid']==$v[$this->conf['parentEntry']]){
$this->getHref($v);
if($v['ITEM_STATE'] == 'ACT' || $v['ITEM_STATE'] == 'CUR') {
$v['ROOTLINE'] = TRUE;
$ret = '1';
}
else {
$ret = '0';
}
$retc = $this->makeSubMenu($v, $ret);
if($retc) {
$v['ROOTLINE'] = TRUE;
}
if($retc OR $ret OR ($act=='1')) {
$menuArray['_SUB_MENU'][]=$v;
}
}
}
return $ret;
}
function getHref(&$menuArray){
if(0) {
// if($this->conf['recSel']){
$this->internal['recSelreg']=$menuArray['uid'];
$this->getRecHref($menuArray);
// TODO this->conf['varHasCHash']
$menuArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array($this->conf['varCat'] => $this->internal['recSelreg']),0,0,$this->conf['targetId']);
}else{
$menuArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array($this->conf['varCat'] => $menuArray['uid']),0,0,$this->conf['targetId']);
}
}
function getRecHref($menuArray){
foreach($this->internal['catArr'] as $v){
if($menuArray['uid']==$v[$this->conf['parentEntry']]){
$this->internal['recSelreg'].=','.$v['uid'];
$this->getRecHref($v);
}
}
}
//used to avoid side effects by removing unecessary keys
function lightenMenu($menuArray){
$root = FALSE;
while (list($key, $val) = each($menuArray)) {
$lightMenuArray[$key]['title']=$menuArray[$key]['title'];
$lightMenuArray[$key]['_OVERRIDE_HREF']=$menuArray[$key]['_OVERRIDE_HREF'];
$lightMenuArray[$key]['ITEM_STATE']=$menuArray[$key]['ITEM_STATE'];
if($menuArray[$key]['_SUB_MENU']){
$this->lightenSubMenu($lightMenuArray[$key]['_SUB_MENU'],$menuArray[$key]['_SUB_MENU']);
}
}
return $lightMenuArray;
}
function lightenSubMenu(&$lightMenuArray,$menuArray){
while (list($key, $val) = each($menuArray)) {
$lightMenuArray[$key]['title']=$menuArray[$key]['title'];
$lightMenuArray[$key]['_OVERRIDE_HREF']=$menuArray[$key]['_OVERRIDE_HREF'];
$lightMenuArray[$key]['ITEM_STATE']=$menuArray[$key]['ITEM_STATE'];
if($menuArray[$key]['_SUB_MENU']){
$this->lightenSubMenu($lightMenuArray[$key]['_SUB_MENU'],$menuArray[$key]['_SUB_MENU']);
}
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nsb_cat2menu/pi1/class.tx_nsbcat2menu_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nsb_cat2menu/pi1/class.tx_nsbcat2menu_pi1.php']);
}
?>
Ein live beispiel wird folgen sobald ich das mit meinem gewissen vereinen kann 😉
Gruß Semidark