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
?>