diff --git a/lib/WebGUI/Macro/M_currentMenuVertical.pm b/lib/WebGUI/Macro/M_currentMenuVertical.pm
index 79bfc2fcd..25b0bfe27 100644
--- a/lib/WebGUI/Macro/M_currentMenuVertical.pm
+++ b/lib/WebGUI/Macro/M_currentMenuVertical.pm
@@ -12,19 +12,20 @@ package WebGUI::Macro::M_currentMenuVertical;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
+use WebGUI::Navigation;
use WebGUI::Session;
#-------------------------------------------------------------------
sub _replacement {
- my ($output, $temp, @param);
+ my ($tree, $temp, @param);
@param = WebGUI::Macro::getParams($_[0]);
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/P_previousMenuVertical.pm b/lib/WebGUI/Macro/P_previousMenuVertical.pm
index 9b85ca4d3..99f196608 100644
--- a/lib/WebGUI/Macro/P_previousMenuVertical.pm
+++ b/lib/WebGUI/Macro/P_previousMenuVertical.pm
@@ -12,19 +12,20 @@ package WebGUI::Macro::P_previousMenuVertical;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
+use WebGUI::Navigation;
use WebGUI::Session;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @param);
+ my ($temp, @param, $tree);
@param = WebGUI::Macro::getParams($_[0]);
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/S_specificMenuVertical.pm b/lib/WebGUI/Macro/S_specificMenuVertical.pm
index e671ba541..eb666c50a 100644
--- a/lib/WebGUI/Macro/S_specificMenuVertical.pm
+++ b/lib/WebGUI/Macro/S_specificMenuVertical.pm
@@ -12,24 +12,25 @@ package WebGUI::Macro::S_specificMenuVertical;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
-use WebGUI::Privilege;
+use WebGUI::Navigation;
use WebGUI::Session;
use WebGUI::SQL;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @param, @data);
+ my ($temp, @param, $pageId, $tree);
@param = WebGUI::Macro::getParams($_[0]);
- if ($param[1] eq "") {
- $param[1] = 0;
+ ($pageId) = WebGUI::SQL->quickArray("select pageId from page where urlizedTitle='$param[0]'");
+ if (defined $pageId) {
+ $temp = '';
}
- @data = WebGUI::SQL->quickArray("select pageId from page where urlizedTitle='$param[0]'");
- $temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/Shared.pm b/lib/WebGUI/Macro/Shared.pm
deleted file mode 100644
index 19a60a32f..000000000
--- a/lib/WebGUI/Macro/Shared.pm
+++ /dev/null
@@ -1,59 +0,0 @@
-package WebGUI::Macro::Shared;
-
-#-------------------------------------------------------------------
-# WebGUI is Copyright 2001-2002 Plain Black LLC.
-#-------------------------------------------------------------------
-# Please read the legal notices (docs/legal.txt) and the license
-# (docs/license.txt) that came with this distribution before using
-# this software.
-#-------------------------------------------------------------------
-# http://www.plainblack.com info@plainblack.com
-#-------------------------------------------------------------------
-
-use Exporter;
-use Tie::CPHash;
-use WebGUI::Privilege;
-use WebGUI::Session;
-use WebGUI::SQL;
-use WebGUI::URL;
-
-our @ISA = qw(Exporter);
-our @EXPORT = qw(&traversePageTree);
-
-#-------------------------------------------------------------------
-sub process {
- return $_[0];
-}
-
-#-------------------------------------------------------------------
-sub traversePageTree {
- my ($sth, @data, $output, $depth, $i, $toLevel);
- if ($_[2] > 0) {
- $toLevel = $_[2];
- } else {
- $toLevel = 99;
- }
- for ($i=1;$i<=$_[1];$i++) {
- $depth .= " ";
- }
- if ($_[1] < $toLevel) {
- $sth = WebGUI::SQL->read("select urlizedTitle, menuTitle, pageId from page where parentId='$_[0]' order by sequenceNumber");
- while (@data = $sth->array) {
- if (WebGUI::Privilege::canViewPage($data[2])) {
- $output .= $depth.'
';
- $output .= traversePageTree($data[2],$_[1]+1,$toLevel);
- }
- }
- $sth->finish;
- }
- return $output;
-}
-
-
-1;
diff --git a/lib/WebGUI/Macro/T_topMenuVertical.pm b/lib/WebGUI/Macro/T_topMenuVertical.pm
index c7e0d7584..50492f8eb 100644
--- a/lib/WebGUI/Macro/T_topMenuVertical.pm
+++ b/lib/WebGUI/Macro/T_topMenuVertical.pm
@@ -12,20 +12,21 @@ package WebGUI::Macro::T_topMenuVertical;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
+use WebGUI::Navigation;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @param);
+ my ($temp, @param, $tree);
@param = WebGUI::Macro::getParams($_[0]);
$temp = '';
- return $temp;
+ return $temp;
}
#-------------------------------------------------------------------
diff --git a/lib/WebGUI/Macro/m_currentMenuHorizontal.pm b/lib/WebGUI/Macro/m_currentMenuHorizontal.pm
index 82dcdbbc2..12cc53fdf 100644
--- a/lib/WebGUI/Macro/m_currentMenuHorizontal.pm
+++ b/lib/WebGUI/Macro/m_currentMenuHorizontal.pm
@@ -12,35 +12,16 @@ package WebGUI::Macro::m_currentMenuHorizontal;
use strict;
use WebGUI::Macro;
-use WebGUI::Privilege;
+use WebGUI::Navigation;
use WebGUI::Session;
-use WebGUI::SQL;
-use WebGUI::URL;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @data, $sth, $first, @param, $delimeter);
+ my ($temp, @param, $tree);
@param = WebGUI::Macro::getParams($_[0]);
- if ($param[0] eq "") {
- $delimeter = " · ";
- } else {
- $delimeter = " ".$param[0]." ";
- }
+ $tree = WebGUI::Navigation::tree($session{page}{pageId},1);
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/p_previousMenuHorizontal.pm b/lib/WebGUI/Macro/p_previousMenuHorizontal.pm
index 731458e76..9305cc07f 100644
--- a/lib/WebGUI/Macro/p_previousMenuHorizontal.pm
+++ b/lib/WebGUI/Macro/p_previousMenuHorizontal.pm
@@ -12,40 +12,17 @@ package WebGUI::Macro::p_previousMenuHorizontal;
use strict;
use WebGUI::Macro;
-use WebGUI::Privilege;
+use WebGUI::Navigation;
use WebGUI::Session;
use WebGUI::SQL;
-use WebGUI::URL;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @data, $sth, $first, @param, $delimeter);
+ my ($temp, $tree, @param);
@param = WebGUI::Macro::getParams($_[0]);
- if ($param[0] eq "") {
- $delimeter = " · ";
- } else {
- $delimeter = " ".$param[0]." ";
- }
+ $tree = WebGUI::Navigation::tree($session{page}{parentId},1);
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/rootmenuHorizontal.pm b/lib/WebGUI/Macro/rootmenuHorizontal.pm
index 72ec3cf39..97a353ca5 100644
--- a/lib/WebGUI/Macro/rootmenuHorizontal.pm
+++ b/lib/WebGUI/Macro/rootmenuHorizontal.pm
@@ -12,7 +12,6 @@ package WebGUI::Macro::rootmenuHorizontal;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
diff --git a/lib/WebGUI/Macro/s_specificMenuHorizontal.pm b/lib/WebGUI/Macro/s_specificMenuHorizontal.pm
index d6e110a6b..60b1279ef 100644
--- a/lib/WebGUI/Macro/s_specificMenuHorizontal.pm
+++ b/lib/WebGUI/Macro/s_specificMenuHorizontal.pm
@@ -12,42 +12,17 @@ package WebGUI::Macro::s_specificMenuHorizontal;
use strict;
use WebGUI::Macro;
-use WebGUI::Macro::Shared;
-use WebGUI::Privilege;
+use WebGUI::Navigation;
use WebGUI::Session;
-use WebGUI::SQL;
-use WebGUI::URL;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @data, $pageTitle, $parentId, $sth, $first, @param, $delimeter);
+ my ($temp, $tree, $parentId, @param);
@param = WebGUI::Macro::getParams($_[0]);
- if ($param[1] eq "") {
- $delimeter = " · ";
- } else {
- $delimeter = " ".$param[1]." ";
- }
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Macro/t_topMenuHorizontal.pm b/lib/WebGUI/Macro/t_topMenuHorizontal.pm
index b45579f9e..c4a596008 100644
--- a/lib/WebGUI/Macro/t_topMenuHorizontal.pm
+++ b/lib/WebGUI/Macro/t_topMenuHorizontal.pm
@@ -12,39 +12,16 @@ package WebGUI::Macro::t_topMenuHorizontal;
use strict;
use WebGUI::Macro;
-use WebGUI::Privilege;
+use WebGUI::Navigation;
use WebGUI::Session;
-use WebGUI::SQL;
#-------------------------------------------------------------------
sub _replacement {
- my ($temp, @data, $sth, $first, @param, $delimeter);
+ my ($temp, $tree, @param);
@param = WebGUI::Macro::getParams($_[0]);
- if ($param[0] eq "") {
- $delimeter = " · ";
- } else {
- $delimeter = " ".$param[0]." ";
- }
+ $tree = WebGUI::Navigation::tree(1,1);
$temp = '';
return $temp;
}
diff --git a/lib/WebGUI/Navigation.pm b/lib/WebGUI/Navigation.pm
new file mode 100644
index 000000000..db51c0d5a
--- /dev/null
+++ b/lib/WebGUI/Navigation.pm
@@ -0,0 +1,196 @@
+package WebGUI::Navigation;
+
+=head1 LEGAL
+
+ -------------------------------------------------------------------
+ WebGUI is Copyright 2001-2002 Plain Black LLC.
+ -------------------------------------------------------------------
+ Please read the legal notices (docs/legal.txt) and the license
+ (docs/license.txt) that came with this distribution before using
+ this software.
+ -------------------------------------------------------------------
+ http://www.plainblack.com info@plainblack.com
+ -------------------------------------------------------------------
+
+=cut
+
+
+use strict;
+use Tie::CPHash;
+use Tie::IxHash;
+use WebGUI::Session;
+use WebGUI::SQL;
+use WebGUI::URL;
+
+
+=head1 NAME
+
+ Package WebGUI::Navigation
+
+=head1 SYNOPSIS
+
+ use WebGUI::Navigation;
+ $pageTree = WebGUI::Navigation::tree($pageParentId,$depthToTraverse);
+
+ $html = WebGUI::Navigation::drawHorizontal($tree);
+ $html = WebGUI::Navigation::drawVertical($tree);
+
+=head1 DESCRIPTION
+
+ A package used to generate navigation.
+
+=head1 METHODS
+
+ These methods are available from this package:
+
+=cut
+
+#-------------------------------------------------------------------
+
+=head2 drawHorizontal ( tree [ , seperator, class ] )
+
+ Draws a vertical navigation system. Returns HTML.
+
+=item tree
+
+ The hash reference created by the tree method in this package.
+
+=item seperator
+
+ A string containing HTML to seperate each navigation item. Defaults
+ to "·".
+
+=item class
+
+ A stylesheet class for each link in the navigation. Defaults to
+ "horizontalMenu".
+
+=cut
+
+sub drawHorizontal {
+ my ($output, $i, $pageId, $first);
+ my ($tree, $seperator, $class) = @_;
+ $class = "horizontalMenu" unless ($class);
+ $seperator = $seperator || '·';
+ $first = 1;
+ foreach $pageId (keys %{$tree}) {
+ if ($first) {
+ $first = 0;
+ } else {
+ $output .= ' '.$seperator.' ';
+ }
+ $output .= '';
+ }
+ return $output;
+}
+
+#-------------------------------------------------------------------
+
+=head2 drawVertical ( tree [, bullet, class, spacing, indent ] )
+
+ Draws a vertical navigation system. Returns HTML.
+
+=item tree
+
+ The hash reference created by the tree method in this package.
+
+=item bullet
+
+ A string containing HTML to generate a bullet that will be placed
+ in front of each tree item. Defaults to none.
+
+=item class
+
+ A stylesheet class for each link in the navigation. Defaults to
+ "verticalMenu".
+
+=item spacing
+
+ An integer with the linespacing for the navigation. Defaults to 1.
+
+=item indent
+
+ An integer with the about of indenting to start with. Defaults to 0.
+
+=cut
+
+sub drawVertical {
+ my ($output, $i, $padding, $leading, $pageId);
+ my ($tree, $bullet, $class, $spacing, $indent) = @_;
+ $class = "verticalMenu" unless ($class);
+ $spacing = 1 unless ($spacing);
+ for ($i=1;$i<=$indent;$i++) {
+ $padding .= " ";
+ }
+ for ($i=1;$i<=$spacing;$i++) {
+ $leading .= "
";
+ }
+ foreach $pageId (keys %{$tree}) {
+ $output .= $padding.$bullet.''.$leading;
+ $output .= drawVertical($tree->{$pageId}{sub}, $bullet, $class, $spacing, ($indent+1));
+ }
+ return $output;
+}
+
+#-------------------------------------------------------------------
+
+=head2 tree ( parentId [, toLevel ] )
+
+ Generates and returns a hash reference containing a page tree with
+ keys of "url", "title", and "sub" with orignating keys of page ids.
+ The tree looks like this:
+
+ root
+ |-pageId
+ | |-url
+ | |-title
+ | `-sub (pageId)
+ | |-url
+ | |-title
+ | `-sub (pageId)
+ | `-etc
+ `-pageId
+ `-etc
+
+=item parentId
+
+ The page id of where you'd like to start the tree.
+
+=item toLevel
+
+ The depth the tree should be traversed. Defaults to "0". If set to
+ "0" the entire tree will be traversed.
+
+=cut
+
+sub tree {
+ my ($sth, %data, %tree);
+ tie %tree, 'Tie::IxHash';
+ tie %data, 'Tie::CPHash';
+ my ($parentId, $toLevel, $depth) = @_;
+ $toLevel = 99 if ($toLevel > 100 || $toLevel < 1);
+ if ($depth < $toLevel) {
+ $sth = WebGUI::SQL->read("select urlizedTitle, menuTitle, pageId from page
+ where parentId='$parentId' order by sequenceNumber");
+ while (%data = $sth->hash) {
+ if (WebGUI::Privilege::canViewPage($data{pageId})) {
+ $tree{$data{pageId}}{url} = WebGUI::URL::gateway($data{urlizedTitle});
+ $tree{$data{pageId}}{title} = $data{menuTitle};
+ $tree{$data{pageId}}{sub} = tree($data{pageId},$toLevel,($depth+1));
+ }
+ }
+ $sth->finish;
+ }
+ return \%tree;
+}
+
+
+
+
+1;
+
+