<commit_before><?php

function smarty_function_menu(array $params, Smarty_Internal_Template $template) {
	/** @var CM_Render $render */
	$render = $template->smarty->getTemplateVars('render');
	/** @var CM_Model_User $viewer */
	$viewer = $template->smarty->getTemplateVars('viewer');
	/** @var CM_Page_Abstract $page */
	$page = $render->getStackLast('pages');
	$request = $page ? $page->getRequest() : new CM_Request_Get($render->getSite()->getUrl(), array(), $viewer);

	$userId = $viewer ? $viewer->getId() : 0;


	$menu = null;
	if (isset($params['name'])) {
		$name = $params['name'];
		$cacheKey = CM_CacheConst::Menu . '_name:' . $name . '_siteId:' . $render->getSite()->getId() . '_userId:' . $userId;
		if (($menu = CM_Cache_Runtime::get($cacheKey)) === false) {
			$menuArr = include $render->getLayoutPath('menu.php', null, true);
			if (isset($menuArr[$name])) {
				$menu = new CM_Menu($menuArr[$name], $request);
			}
			CM_Cache_Runtime::set($cacheKey, $menu);
		}
	} elseif (isset($params['data'])) {
		$menu = new CM_Menu($params['data'], $request);
	}
	if (!$menu) {
		return '';
	}

	$menuEntries = null;

	$depth = isset($params['depth']) ? (int) $params['depth'] : null;

	if (!empty($params['breadcrumb'])) {
		/** @var CM_MenuEntry $entry */
		$entry = $menu->findEntry($page, $depth, $depth);
		if ($entry) {
			$menuEntries = $entry->getParents();
			// Also add current entry
			$menuEntries[] = $entry;
		}
	} elseif (!empty($params['submenu'])) {
		$entry = $menu->findEntry($page, $depth, $depth);
		if ($entry && $entry->hasChildren()) {
			$menu = $entry->getChildren();
			$menuEntries = $menu->getEntries();
		}
	} elseif (!is_null($depth)) {
		if ($entry = $menu->findEntry($page, $depth)) {
			$parents = $entry->getParents();
			$parents[] = $entry;
			$menuEntries = $parents[$depth]->getSiblings()->getEntries();
		}
	} else {
		$menuEntries = $menu->getEntries();
	}

	if (empty($menuEntries)) {
		return '';
	}

	$class = 'menu ' . $params['name'];
	if (isset($params['class'])) {
		$class .= ' ' . $params['class'];
	}

	$tplName = 'default';
	if (isset($params['template'])) {
		$tplName = $params['template'];
	}

	$tplPath = $render->getLayoutPath('menu/' . $tplName . '.tpl');
	$assign = array('menu_entries' => $menuEntries, 'menu_class' => $class);
	return $render->renderTemplate($tplPath, $assign, true);
}<commit_msg>t236: Fix: Only append menu name to css class if given<commit_after><?php

function smarty_function_menu(array $params, Smarty_Internal_Template $template) {
	/** @var CM_Render $render */
	$render = $template->smarty->getTemplateVars('render');
	/** @var CM_Model_User $viewer */
	$viewer = $template->smarty->getTemplateVars('viewer');
	/** @var CM_Page_Abstract $page */
	$page = $render->getStackLast('pages');
	$request = $page ? $page->getRequest() : new CM_Request_Get($render->getSite()->getUrl(), array(), $viewer);

	$userId = $viewer ? $viewer->getId() : 0;


	$menu = null;
	if (isset($params['name'])) {
		$name = $params['name'];
		$cacheKey = CM_CacheConst::Menu . '_name:' . $name . '_siteId:' . $render->getSite()->getId() . '_userId:' . $userId;
		if (($menu = CM_Cache_Runtime::get($cacheKey)) === false) {
			$menuArr = include $render->getLayoutPath('menu.php', null, true);
			if (isset($menuArr[$name])) {
				$menu = new CM_Menu($menuArr[$name], $request);
			}
			CM_Cache_Runtime::set($cacheKey, $menu);
		}
	} elseif (isset($params['data'])) {
		$menu = new CM_Menu($params['data'], $request);
	}
	if (!$menu) {
		return '';
	}

	$menuEntries = null;

	$depth = isset($params['depth']) ? (int) $params['depth'] : null;

	if (!empty($params['breadcrumb'])) {
		/** @var CM_MenuEntry $entry */
		$entry = $menu->findEntry($page, $depth, $depth);
		if ($entry) {
			$menuEntries = $entry->getParents();
			// Also add current entry
			$menuEntries[] = $entry;
		}
	} elseif (!empty($params['submenu'])) {
		$entry = $menu->findEntry($page, $depth, $depth);
		if ($entry && $entry->hasChildren()) {
			$menu = $entry->getChildren();
			$menuEntries = $menu->getEntries();
		}
	} elseif (!is_null($depth)) {
		if ($entry = $menu->findEntry($page, $depth)) {
			$parents = $entry->getParents();
			$parents[] = $entry;
			$menuEntries = $parents[$depth]->getSiblings()->getEntries();
		}
	} else {
		$menuEntries = $menu->getEntries();
	}

	if (empty($menuEntries)) {
		return '';
	}

	$class = 'menu';
	if (isset($params['name'])) {
		$class .= ' ' . $params['name'];
	}
	if (isset($params['class'])) {
		$class .= ' ' . $params['class'];
	}

	$tplName = 'default';
	if (isset($params['template'])) {
		$tplName = $params['template'];
	}

	$tplPath = $render->getLayoutPath('menu/' . $tplName . '.tpl');
	$assign = array('menu_entries' => $menuEntries, 'menu_class' => $class);
	return $render->renderTemplate($tplPath, $assign, true);
}
{'fraction_non_alphanumeric': 0.23099233478350942, 'fraction_numerical': 0.0010358400662937642, 'mean_word_length': 4.58150289017341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4147287', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1719, 'n_words': 323}