bulletmenu and sublist

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
marties
Forum Members
Forum Members
Posts: 34
Joined: Tue Jan 11, 2005 11:22 am

bulletmenu and sublist

Post by marties »

Hi,

i need some help to finish my menu using the bulletmenu plugin, it consists of one main list plus a submenu.

1 - if click on a submenu, i want the main menu and the submenu selected how do i do this ? I know it has something to do with $depth and maybe $curpos

2 - at the end of the lists there is a pipe, how do i know it is the last item to make it disappear ?  I created a class  #bulletmenu li.last {background-image:none;}  i just have make the   but i don't know how

Thanks in advance
Last edited by marties on Tue Dec 16, 2008 12:51 pm, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: bulletmenu and sublist

Post by Ted »

Try setting show_root_siblings=1 in your definition to solve #1.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: bulletmenu and sublist

Post by nils73 »

marties,

I almost had the same problem and did some modifications inside the bulletmenu-code so that the activated menu-items no longer remain links but plain-text. It's a hack but I can post the modifications here if wishy's instructions don't match what you've been looking for.

Regards
Nils
marties
Forum Members
Forum Members
Posts: 34
Joined: Tue Jan 11, 2005 11:22 am

Re: bulletmenu and sublist

Post by marties »

nils73 wrote: marties,

I almost had the same problem and did some modifications inside the bulletmenu-code so that the activated menu-items no longer remain links but plain-text. It's a hack but I can post the modifications here if wishy's instructions don't match what you've been looking for.

Regards
Nils
Thanks i'll check this out soon, for the point 2 i'm still interested with your bulletmenu-code hack ; i know a solution for the pipe menu  http://css.maxdesign.com.au/listamatic/horizontal32.htm but the pipe will be the same color as the text link :-(
marties
Forum Members
Forum Members
Posts: 34
Joined: Tue Jan 11, 2005 11:22 am

Re: bulletmenu and sublist

Post by marties »

wishy wrote: Try setting show_root_siblings=1 in your definition to solve #1.
Thanks for the answer.

show_root_siblings is not running on my bulletmenu version (1.0) , i run cms 0.9.2 version and my bulletmenu, after checking on the beta version (0.10beta3) it seems you upgraded the bulletmenu (you forgot to increment the version!) i'm gonna try the new bulletmenu with my old cms version since it's definetely not recommended to use the beta for a production site ? (even beta3 ???)

Thanks again for your helpfull
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: bulletmenu and sublist

Post by nils73 »

This hack is just for 0.10beta2 ... which I am using as a production version (but maybe I will upgrade to 0.10beta3 and then ... whatever). Hope it helps. I put most of the elements into comments since I prefer not to use them as they are not needed in most cases. Here's the code:

Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program 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.
#
#This program 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.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_bulletmenu($params, &$smarty) {

	global $gCms;
	global $db;
	global $config;

	# getting menu parameters
	$showadmin = isset($params['showadmin']) ? $params['showadmin'] : 0 ;
	$collapse = isset($params['collapse']) ? $params['collapse'] : 0 ;

	$allcontent = ContentManager::GetAllContent(false);

	# defining variables
	$menu = "";
	$last_level = 0;
	$count = 0;
	$in_hr = 0;

	# array to hold hierarchy postitions of disabled pages
	$disabled = array();

	if (count($allcontent))
	{
		$basedepth = 0;
		// $menu .= "<div class=\"bulletmenu\">\n";

		#Reset the base depth if necessary...
		if (isset($params['start_element']))
		{
			$basedepth = count(split('\.', (string)$params['start_element'])) - 1;
		}

		foreach ($allcontent as $onecontent)
		{
			#Handy little trick to figure out how deep in the tree we are
			#Remember, content comes to use in order of how it should be displayed in the tree already
			$depth = count(split('\.', $onecontent->Hierarchy()));

			#If hierarchy starts with the start_element (if it's set), then continue on
			if (isset($params['start_element']))
			{
				if ((strpos($onecontent->Hierarchy(), (string)$params['start_element']) === FALSE) || (strpos($onecontent->Hierarchy(), (string)$params['start_element']) != 0))
				{
					if (isset($params['show_root_siblings']) && $params['show_root_siblings'] == '1')
					{
						# Find direct parent of current item
						$curparent = substr($onecontent->Hierarchy(), 0, strrpos($onecontent->Hierarchy(), "."));
						if ($curparent != '')
						{
							$curparent = $curparent . ".";
						}

						# Find direct parent of start_element
						$otherparent = substr((string)$params['start_element'], 0, strpos((string)$params['start_element'], "."));
						if ($otherparent != '')
						{
							$otherparent = $otherparent . ".";
						}

						# Make sure the parents match
						if ($curparent != $otherparent)
						{
							continue;
						}
					}
					else
					{
						continue;
					}
				}
			}

			#Now check to make sure we're not too many levels deep if number_of_levels is set
			if (isset($params['number_of_levels']))
			{
				$number_of_levels = $params['number_of_levels'] - 1;

				#If this element's level is more than base_level + number_of_levels, then scratch it
				if ($basedepth + $number_of_levels < $depth)
				{
					continue;
				}
			}

			# Check for inactive items or items set not to show in the menu
			if (!$onecontent->Active() || !$onecontent->ShowInMenu())
			{
				# Stuff the hierarchy position into that array, so we can test for
				# children that shouldn't be showing.  Put the dot on the end
				# since it will only affect children anyway...  saves from a
				# .1 matching .11
				array_push($disabled, $onecontent->Hierarchy() . ".");
				continue;
			}

			$disableme = false;

			# Loop through disabled array to see if this is a child that
			# shouldn't be showing -- we check this by seeing if the current
			# hierarhcy postition starts with one of the disabled positions
			foreach ($disabled as $onepos)
			{
				# Why php doesn't have a starts_with function is beyond me...
				if (strstr($onecontent->Hierarchy(), $onepos) == $onecontent->Hierarchy())
				{
					$disableme = true;
					continue; # Break from THIS foreach
				}
			}

			if ($disableme)
			{
				continue; # Break from main foreach
			}

			# Set depth to be the relative position
			$depth = $depth - $basedepth;

			# Now try to remove items that shouldn't be shown, based on current location
			if ($collapse == 1)
			{
				if ($depth > 1) # All root level items should show 
				{
					$curpos = $gCms->variables['position'];
					$curdepth = count(split('\.', $curpos)) - $basedepth;
					$curparent = substr($gCms->variables['position'], 0, strrpos($gCms->variables['position'], "."));
					if ($curparent != '')
					{
						$curparent = $curparent . ".";
					}

					$skipme = true;

					# Are we the currently selected page?
					if ($onecontent->Hierarchy() == $curpos)
					{
						$skipme = false;
					}

					# First, are we a direct decendant of the current position?
					if (strstr($onecontent->Hierarchy(), $curpos) == $onecontent->Hierarchy() && $curdepth == ($depth - 1))
					{
						$skipme = false;
					}

					# Now for the nasty part...  loop through all parents and show them and direct siblings
					if ($skipme)
					{
						$blah = '';
						$count = 1;
						foreach (split('\.', $curpos) as $level)
						{
							$blah .= $level . '.';
							if (strstr($onecontent->Hierarchy(), $blah) == $onecontent->Hierarchy())
							{
								if ($depth == ($count + 1))
								{
									$skipme = false;
									continue;
								}
							}
							$count++;
						}
					}

					# Ok, so should we skip this thing already?
					if ($skipme)
					{
						continue;
					}
				}
			}

			if ($onecontent->Type() == 'sectionheader')
			{
				if ($in_hr == 1)
				{
					$menu .= "</ul>\n";
					$in_hr = 0;
				}

				$menu .= "<div class=\"sectionheader\">".$onecontent->MenuText()."</div>\n";

				if ($count > 0 && $in_hr == 0)
				{
					$menu .= "<ul>\n";
					$in_hr = 1;
				}
			}
			else
			{
				if ($depth < $last_level)
				{
					for ($i = $depth; $i < $last_level; $i++)
					{
						$menu .= "\n</li>\n</ul>\n";
					}

					if ($depth > 0)
					{
						$menu .= "</li>\n";
					}
				}

				if ($depth > $last_level)
				{
					for ($i = $depth; $i > $last_level; $i--)
					{
						if ($depth == 1)
						{
						  $menu .= "<ul>\n";
            }
            else 
            {
              $menu .= "\n<ul class=\"subNav0".($depth-1)."\">\n";
            }
					}
				}

				if ($depth == $last_level)
				{
					$menu .= "</li>\n";
				}

				if ($onecontent->Type() == 'separator')
				{
					$menu .= "<li style=\"list-style-type: none;\"><hr class=\"separator\"/>";
				}
				else
				{
				  $menu .= "<li";
					if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
					{
						$menu .= " class=\"active0".$depth."\"";
						$menu .= "><h4>".$gCms->variables['position'].$onecontent->MenuText()."</h4>";
					}
					else 
					{
					// a hack for first active point in hierarchy, maybe not needed
  				if ($onecontent->Hierarchy() == $curparent)
					  {
              $menu .= " class=\"activeCat\"";
            }
          // using the page_id to check, which page it is ...  
          elseif ((empty($curparent) && $gCms->variables['page_id'] == "2") || (empty($curparent) && $gCms->variables['page_id'] == "33"))
					  {
              $menu .= " class=\"activeCat\"";
            }
					$menu .= "><a href=\"".$onecontent->GetURL()."\">".$onecontent->Hierarchy().";
          $menu .= $onecontent->MenuText()."</a>";
          }
				}

				$in_hr = 1;
				$last_level = $depth;
			}
			$count++;
		}

		for ($i = 0; $i < $last_level; $i++) $menu .= "</li>\n</ul>\n";

		if ($showadmin == 1)
		{
			$menu .= "<ul><li><a href='".$config['admin_dir']."/'>Admin</a></li></ul>\n";
		}
		// $menu .= "</div>\n";
	}

	return $menu;

}

function smarty_cms_help_function_bulletmenu() {
	?>
	<h3>What does this do?</h3>
	<p>Prints a bullet menu.</p>
	<h3>How do I use it?</h3>
	<p>Just insert the tag into your template/page like: <code>{bulletmenu}</code></p>
	<h3>What parameters does it take?</h3>
	<p>
	<ul>
		<li><em>(optional)</em> <tt>showadmin</tt> - 1/0, whether you want to show or not the admin link.</li>
		<li><em>(optional)</em> <tt>collapse</tt> - 1/0, whether you want to collapse sub items that shouldn't be shown.  Defaults to 0.</li>
		<li><em>(optional)</em> <tt>start_element</tt> - the hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root node of the menu and only shows it and it's children.</li>
		<li><em>(optional)</em> <tt>show_root_siblings</tt> - 1/0, if start_element (above) is given, then show direct siblings of the give start_element as well.</li>
		<li><em>(optional)</em> <tt>number_of_levels</tt> - an integer, the number of levels you want to show in your menu.</li>
	</ul>
	</p>

	<?php
}

function smarty_cms_about_function_bulletmenu() {
	?>
	<p>Author: Julien Lancien<calexico@cmsmadesimple.org></p>
	<p>Version: 1.0</p>
	<p>
	Change History:<br/>
	None
	</p>
	<?php
}

# vim:ts=4 sw=4 noet
?>
Furthermore you will need to create CSS-entries (subNav01, subNav02, ...) that you are going to use. There are several great articles out there (try Listamatic maybe) that deal with unordered lists for navigation purpose and their styling.

Regards
Nils
iNSiPiD

Re: bulletmenu and sublist

Post by iNSiPiD »

For some reason the solution to my multiple menu problem has been under my nose the whole time. Why didn't anybody tell me that you could use multiple isntances of {bulletmenu}!! :)

Anyway, I have now locked my primary bulletmenu to 2 deep and then include the bulletmenu tag in pages deeper than 2 from root (e.g. 2.1.1) with the start_element set for that menu item.

The only problem is that it also displays the current page's link in the list. Can this be hidden any way?
jah
Forum Members
Forum Members
Posts: 147
Joined: Thu Dec 30, 2004 9:09 am

Re: bulletmenu and sublist

Post by jah »

Try:

.currentpage
{
display: none;
}
iNSiPiD

Re: bulletmenu and sublist

Post by iNSiPiD »

I've already given that class bold styling for the main side navigation.

Perhaps I can apply an li style to a new ID for that content area as the current page is in a parent list.

#menu2 li { display: none; }
#menu2 li { display: inline; }
Post Reply

Return to “CMSMS Core”