bullet menu... without the bullets

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
jptechnical
Forum Members
Forum Members
Posts: 131
Joined: Wed Jan 12, 2005 12:18 am

bullet menu... without the bullets

Post by jptechnical »

Can someone take my hack and slash job done to the bullet menu plugin and make it compliant.

The goal is to make the bullet menu so that it does the following:

1. no bullets, instead
2. specific css style applied to the topmost item or to all parents in the tree
3. optionally (but much desired), remove the parent altogether... i.e. start with 1 but not actually show 1, show 1.1, 1.2, 1.3 etc.

Here is my current result. I made an html_blob and put in 3 html_blobs (I love the nested blobs, so glad you can do that now) each displaying nothing but a single bulletmenu reference for a single content tree. This is the only way I could figure out how do make it look like it does here http://www.web-cre8or.com/index.php?pag ... _Info_Home.

Here is the code, which I tried to comment for my own sanity...

Again... forgive my hack job... I am no coder!

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=\"sectionheader\">\n<div>";//jp changed the div from <div class=\"bulletmenu\"> to sectionheader

		#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 .= "<br>\n";
					$in_hr = 0;
				}

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

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

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

				if ($depth > $last_level)
				{
					for ($i = $depth; $i > $last_level; $i--)
					{
						$menu .= "</div>\n\n";//jp added the /div
					}
				}

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

				if ($onecontent->Type() == 'separator')
				{
					$menu .= "<li style=\"list-style-type: none;\"><hr class=\"separator\" />";
				}
				else
				{
					$menu .= "<a href=\"".$onecontent->GetURL()."\"";
					if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
					{
						$menu .= " class=\"currentpage\"";
					}
					$menu .= ">".$onecontent->MenuText()."</a>";
				}

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

		for ($i = 0; $i < $last_level; $i++) $menu .= "";// <br> here adds line at end of menu

		if ($showadmin == 1)
		{
			$menu .= "<br><a href='".$config['admin_dir']."/'>Admin</a><br>\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>
	<br>
		<br><em>(optional)</em> <tt>showadmin</tt> - 1/0, whether you want to show or not the admin link.<br>
		<br><em>(optional)</em> <tt>collapse</tt> - 1/0, whether you want to collapse sub items that shouldn't be shown.  Defaults to 0.<br>
		<br><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.<br>
		<br><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.<br>
		<br><em>(optional)</em> <tt>number_of_levels</tt> - an integer, the number of levels you want to show in your menu.<br>
	<br>
	</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
?>

nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: bullet menu... without the bullets

Post by nils73 »

erm ... all you need is normal bulletmenu and set the css for elements inside bulletmenu to the following:

.bulletmenu li {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 0;
}

That's the trick. Even Netscape 4 understands it. :)
jptechnical
Forum Members
Forum Members
Posts: 131
Joined: Wed Jan 12, 2005 12:18 am

Re: bullet menu... without the bullets

Post by jptechnical »

I have done this... but the result is still a list and the left margin of the child is way too big. I can't get them to align without indenting the children from the parent.

Again, I want them to just be line breaks between each one so they can be in a row without any list elements.

Like this

parent
(it's own css style)
child1
child2
child3
child4

and not this

parent
      child1
      child2
      child3
      child4

Thanks.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: bullet menu... without the bullets

Post by nils73 »

Could you please copy & paste HTML and CSS for the part you are talking about or - even better thouhg - let me have a glance at the project? Seems that the child inherits something from the parent causing the indent.

Regards,
Nils
jptechnical
Forum Members
Forum Members
Posts: 131
Joined: Wed Jan 12, 2005 12:18 am

Re: bullet menu... without the bullets

Post by jptechnical »

Ok, here is an example. This is an 8.2 stable install and I put the unmodified bulletmenu at the bottom of the first page. So far as I can tell there has been no significant change in the bulletmenu pertaining to my needs since then and in 10rc4

http://boscoconstruction.com/index.php

the call to bulletmenu is

Code: Select all

{bulletmenu start_element="1" showadmin="0"}
I have not modified the css.

first problem is the indent that comes with a list... I haven't found a way to get rid of that indent with css (though I am sure there is a way to do it... I just havent found it yet). With your css selector I can indeed remove the bullets but it does not effect the indent. I have tried negative margins and the like but it just ends up skewing the rest of the table it is in.

The second problem is that I need to format the first line (in this case 'Home") differently. I need to make it a block element with a solid background and light color text centered. This willl be inside a table that will have a complimentary color as seen in the examples I have shown earlier at web-cre8or.com The use is a left side navigation generated by the bulletmenu (or another method for that matter) since I can only use phplayers once in a single page. Eventually each main page off the homepage will have it's own template with the only real differentiation is only the corresponding bulletmenu for that section.

Does that make sense?

Thanks.
piratos

Re: bullet menu... without the bullets

Post by piratos »

Youe have another little problem - your pages are declared as but the cms makes xhtml.
piratos

Re: bullet menu... without the bullets

Post by piratos »

Here is my code of bulletmenu without bullet.

Each link has his own class. Class is bm1, bm2 and so on.
Perhaps you can use it.

This is the html - output:

Code: Select all

<div class="sectionheader">Home</div>
<a class="bm1" href="http://localhost/beta4/index.php?page=cms-install-successful-">Home Page</a>
<a class="bm2" href="http://localhost/beta4/index.php?page=frequently-asked-questions">FAQ</a>
<a class="bm3" href="http://localhost/beta4/index.php?page=contact-us">Contact Us</a>
<hr class="separator" />
<a class="bm4" href="http://localhost/beta4/index.php?page=svn-cvs-" class="currentpage">SVN (cvs)</a>
</div>

it is easy to change the code by yourself.

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;
        $m = 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 .= "<br />\n";
					$in_hr = 0;
				}

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

				if ($count > 0 && $in_hr == 0)
				{
					$menu .= "<br />\n";
					$in_hr = 1;
				}
			}
			else
			{

				if ($onecontent->Type() == 'separator')
				{
					$menu .= "<hr class=\"separator\" />"."\n";
				}
				else
				{       $m++;
					$menu .= "<a class=\"bm".$m."\" href=\"".$onecontent->GetURL()."\"";
					if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
					{
						$menu .= " class=\"currentpage\"";
					}
					$menu .= ">".$onecontent->MenuText()."</a>"."\n";
				}

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



		if ($showadmin == 1)
		{       $m++;
			$menu .= "<a class=\"bm".$m."\" href=\"'".$config['admin_dir']."/'>Admin</a>"."\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
?>

jptechnical
Forum Members
Forum Members
Posts: 131
Joined: Wed Jan 12, 2005 12:18 am

Re: bullet menu... without the bullets

Post by jptechnical »

Ooh... I think I like... I will give it a try.

Just a question, is it good for the new API?
piratos

Re: bullet menu... without the bullets

Post by piratos »

I have several versions of menus based on bulletmenu - it is the question of design i will use.

Normaly all of the  menus works as a sequence. But they need additional parameters  as example to showonly one sectionheader and the links and showsectionheader itself (=true or false).

A complex design as your website need to split the content to display with 2 menusystems (or more). With this cms you can use a tag with difference parameters in the same content, and this is the way to create a complex design.
Post Reply

Return to “Developers Discussion”