<commit_before><?php
/**
 * The object manages the main CMS menu
 * 
 * @package cms
 * @subpackage content
 */
class CMSMenu extends Object implements Iterator
{

	protected static $menu_items = array();

	/**
	 * Generate CMS main menu items by collecting valid 
	 * subclasses of {@link LeftAndMain}
	 */
	public static function populate_menu() {
		$cmsClasses = self::get_cms_classes();
		foreach($cmsClasses as $cmsClass) {
			self::add_controller($cmsClass);
		}
		return true;
	}

	
	/**
	 * Add a LeftAndMain controller to the CMS menu.
	 *
	 * @param string $controllerClass The class name of the controller
	 * @return The result of the operation
	 * @todo A director rule is added when a controller link is added, but it won't be removed
	 *			when the item is removed. Functionality needed in {@link Director}.
	 */	
	public static function add_controller($controllerClass) {
		$controller = singleton($controllerClass);
		Director::addRules($controller->stat('url_priority', true), 
			array(Controller::join_links($controller->Link(), $controller->stat('url_rule', true)) => $controllerClass)
		);
		return self::add_menu_item(
			$controllerClass, 
			$controller->getMenuTitle(), 
			$controller->Link(), 
			$controllerClass,
			$controller->stat('menu_priority')
		);
	}
	
	/**
	 * Add an arbitrary URL to the CMS menu.
	 *
	 * @param string $code A unique identifier (used to create a CSS ID and as it's key in {@link $menu_items}
	 * @param string $menuTitle The link's title in the CMS menu
	 * @param string $url The url of the link
	 * @param integer $priority The menu priority (sorting order) of the menu item
	 * @return boolean The result of the operation.
	 */
	public static function add_link($code, $menuTitle, $url, $priority = -1) {
		return self::add_menu_item($code, $menuTitle, $url, null, $priority);
	}
	
	/**
	 * Add a navigation item to the main administration menu showing in the top bar.
	 *
	 * @uses {@link CMSMenu::$menu_items}<commit_msg>BUGFIX: Fixed bug with // placement in CMSMenu Director rule generation<commit_after><?php
/**
 * The object manages the main CMS menu
 * 
 * @package cms
 * @subpackage content
 */
class CMSMenu extends Object implements Iterator
{

	protected static $menu_items = array();

	/**
	 * Generate CMS main menu items by collecting valid 
	 * subclasses of {@link LeftAndMain}
	 */
	public static function populate_menu() {
		$cmsClasses = self::get_cms_classes();
		foreach($cmsClasses as $cmsClass) {
			self::add_controller($cmsClass);
		}
		return true;
	}

	
	/**
	 * Add a LeftAndMain controller to the CMS menu.
	 *
	 * @param string $controllerClass The class name of the controller
	 * @return The result of the operation
	 * @todo A director rule is added when a controller link is added, but it won't be removed
	 *			when the item is removed. Functionality needed in {@link Director}.
	 */	
	public static function add_controller($controllerClass) {
		$controller = singleton($controllerClass);

		$link = $controller->Link();
		if(substr($link,-1) == '/') $link = substr($link,0,-1);
		$subRule = $controller->stat('url_rule', true);
		if($subRule[0] == '/') $subRule = substr($subRule,1);
		$rule = $link . '//' . $subRule;
		
		Director::addRules($controller->stat('url_priority', true), array(
			$rule => $controllerClass
			
		));
		
		return self::add_menu_item(
			$controllerClass, 
			$controller->getMenuTitle(), 
			$controller->Link(), 
			$controllerClass,
			$controller->stat('menu_priority')
		);
	}
	
	/**
	 * Add an arbitrary URL to the CMS menu.
	 *
	 * @param string $code A unique identifier (used to create a CSS ID and as it's key in {@link $menu_items}
	 * @param string $menuTitle The link's title in the CMS menu
	 * @param string $url The url of the link
	 * @param integer $priority The menu priority (sorting order) of the menu item
	 * @return boolean The result of the operation.
	 */
	public static function add_link($code, $menuTitle, $url, $priority = -1) {
		return self::add_menu_item($code, $menuTitle, $url, null, $priority);
	}
	
	/**
	 * Add a navigation item to the main administration menu showing in the top bar.
	 *
	 * @uses {@link CMSMenu::$menu_items}
{'fraction_non_alphanumeric': 0.12124105011933174, 'fraction_numerical': 0.0016706443914081145, 'mean_word_length': 3.8960280373831777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2591109', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1197, 'n_words': 441}