/** * Generates a custom forum category menu. * This function generates a custom navigation with a HMENU. This function can be included * as special.userfunc in HMENUs in TypoScript in order to display the mm_forum category * tree as a navigation line. * * @param string $content The content variable * @param array $conf The configuration array * @return array An array containing a set of HMENU items */ function catMenu($content, $conf) { $this->init($conf); $this->menuInit($conf); $result = array(); $forumPid = $conf['forumPID'] ? $conf['forumPID'] : $this->getForumPID(); $categoryAction = $conf['categoryAction'] ? $conf['categoryAction'] : 'list_cat'; $boardAction = $conf['boardAction'] ? $conf['boardAction'] : 'list_topic'; $activeCategory = intval($this->piVars['cid']); $activeBoard = intval($this->piVars['fid']); $activeTopic = intval($this->piVars['tid']); if ($activeTopic && !$activeBoard) { $activeBoard = tx_mmforum_pi1::get_forum_id($activeTopic); } $res = $this->databaseHandle->exec_SELECTquery('uid, forum_name AS name, parentID', 'tx_mmforum_forums', 'deleted = 0 AND hidden = 0' . $this->getStoragePIDQuery(), '', 'parentID ASC, sorting ASC'); // compile every entry in the list while ($row = $this->databaseHandle->sql_fetch_assoc($res)) { // top level = categories if ($row['parentID'] == 0) { $linkParams = array('action' => $categoryAction, 'cid' => $row['uid']); $menuItem = array('id' => $row['uid'], 'title' => $row['name'], '_OVERRIDE_HREF' => $this->pi_linkTP_keepPIvars_url($linkParams, 1, 1, $forumPid), 'ITEM_STATE' => $row['uid'] == $activeCategory ? 'ACT' : 'NO'); $result[] = $menuItem; } else { // 2nd level == forums $linkParams = array('action' => $boardAction, 'fid' => $row['uid']); $menuItem = array('id' => $row['uid'], 'title' => $row['name'], '_OVERRIDE_HREF' => $this->pi_linkTP_keepPIvars_url($linkParams, 1, 1, $forumPid), 'ITEM_STATE' => $row['uid'] == $activeBoard ? 'ACT' : 'NO'); $forums[$row['parentID']][] = $menuItem; } } // if a "forum" (2nd level) is active, we need to find the parentID to highlight // the parentID as ACTIFSUB foreach ($forums as $parentID => $menuItems) { foreach ($menuItems as $menuItem) { if ($menuItem['ITEM_STATE'] == 'ACT') { $activeCategory = $parentID; break; } } } // unless we use special.expAll = 1, set the parentID to ACTIFSUB and add // the second level of the category menu foreach ($result as &$menuItem) { if (($menuItem['ITEM_STATE'] == 'ACT' || $menuItem['id'] == $activeCategory || $conf['expAll']) && is_array($forums[$menuItem['id']])) { $menuItem['_SUB_MENU'] = $forums[$menuItem['id']]; $menuItem['ITEM_STATE'] = $menuItem['ITEM_STATE'] == 'ACT' || $menuItem['id'] == $activeCategory ? 'ACTIFSUB' : 'IFSUB'; } } // we also need to have the option that the category automatically displays the first subcategory if ($conf['linkCatToFirstBoard']) { foreach ($result as &$menuItem) { if (is_array($forums[$menuItem['id']])) { $firstBoard = reset($forums[$menuItem['id']]); if (is_array($firstBoard)) { $menuItem['_OVERRIDE_HREF'] = $firstBoard['_OVERRIDE_HREF']; } } } } return $result; }