Exemple #1
0
	static function _findTag($needles, &$data)
	{
		if ( !$needles ) return false;
		
		// Get language, item, current (matched) category menu item
		$language = $data['language'];
		
		// Set language menu items if not already done
		if ( !isset(self::$menuitems[$language]) ) {
			FlexicontentHelperRoute::_setMenuitems($language);
		}
		$component_menuitems = & self::$menuitems[$language];
		
		
		// *****************************************************************************************************************
		// Done ONCE per language: Iterate through menu items pointing to FLEXIcontent component, to create a reverse lookup
		// table for the given language, not if given language is missing the an '*' menu item will be allowed in its place
		// *****************************************************************************************************************
		if ( !isset(self::$lookup[$language]) ) {
			FlexicontentHelperRoute::populateLookupTable($language);
		}
		
		
		// Get current menu item, we will prefer current menu if it points to given category,
		// thus maintaining current menu item if multiple menu items to same category exist !!
		static $active = null;
		if ($active == null) {
			$menus = JFactory::getApplication()->getMenu('site', array());   // this will work in J1.5 backend too !!!
			$active = $menus->getActive();
			if ($active && @ $active->query['option']!='com_flexicontent') $active=false;
		}
		
		
		// Now find menu item for given needles
		$matched_menu = false;
		
		foreach ($needles as $view => $ids)
		{
			if ( is_object($ids) ) return $ids;  // done, this an already appropriate menu item object
			
			// Lookup if then given ids for the given view exists for the given language
			if ( !isset(self::$lookup[$language][$view]) ) continue;
			
			foreach($ids as $id)
			{
				if ( !isset(self::$lookup[$language][$view][(int)$id]) ) continue;  // not found
				
				//echo "$language $view $id : ". self::$lookup[$language][$view][(int)$id] ."<br/>";
				$menuid = self::$lookup[$language][$view][(int)$id];
				$menuitem = $component_menuitems[$menuid];
				
				// menu item matched, break out
				$matched_menu = $menuitem;
				break;
			}
			if ($matched_menu) break;
		}
		
		// Prefer current tags menu item if also appropriate
		if ($matched_menu && $active && @ $matched_menu->query['view'] == 'tags' &&
			@ $matched_menu->query['view'] == @ $active->query['view'] &&
			@ $matched_menu->query['id'] == @ $active->query['id']
		) {
			$matched_menu = $active;
		}
		
		return $matched_menu;
	}