Added the new Navigation core component and updated the navigation macros.
This commit is contained in:
parent
afcad66b68
commit
1c3094af19
11 changed files with 240 additions and 190 deletions
|
|
@ -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 = '<span class="verticalMenu">';
|
||||
if ($param[0] ne "") {
|
||||
$temp .= traversePageTree($session{page}{pageId},0,$param[0]);
|
||||
$tree = WebGUI::Navigation::tree($session{page}{pageId},$param[0]);
|
||||
} else {
|
||||
$temp .= traversePageTree($session{page}{pageId},0,1);
|
||||
$tree = WebGUI::Navigation::tree($session{page}{pageId},1);
|
||||
}
|
||||
$temp .= WebGUI::Navigation::drawVertical($tree);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="verticalMenu">';
|
||||
if ($param[0] ne "") {
|
||||
$temp .= traversePageTree($session{page}{parentId},0,$param[0]);
|
||||
$tree = WebGUI::Navigation::tree($session{page}{parentId},$param[0]);
|
||||
} else {
|
||||
$temp .= traversePageTree($session{page}{parentId},0,1);
|
||||
$tree = WebGUI::Navigation::tree($session{page}{parentId},1);
|
||||
}
|
||||
$temp .= WebGUI::Navigation::drawVertical($tree);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="verticalMenu">';
|
||||
if ($param[1] ne "") {
|
||||
$tree = WebGUI::Navigation::tree($pageId,$param[1]);
|
||||
} else {
|
||||
$tree = WebGUI::Navigation::tree($pageId,1);
|
||||
}
|
||||
$temp .= WebGUI::Navigation::drawVertical($tree);
|
||||
$temp .= '</span>';
|
||||
}
|
||||
@data = WebGUI::SQL->quickArray("select pageId from page where urlizedTitle='$param[0]'");
|
||||
$temp = '<span class="verticalMenu">';
|
||||
if (defined $data[0] && WebGUI::Privilege::canViewPage($data[0])) {
|
||||
$temp .= traversePageTree($data[0],1,$param[1]);
|
||||
}
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.'<a class="verticalMenu" href="'.WebGUI::URL::gateway($data[0]).'">';
|
||||
if ($session{page}{pageId} == $data[2]) {
|
||||
$output .= '<span class="selectedMenuItem">'.$data[1].'</span>';
|
||||
} else {
|
||||
$output .= $data[1];
|
||||
}
|
||||
$output .= '</a><br>';
|
||||
$output .= traversePageTree($data[2],$_[1]+1,$toLevel);
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
@ -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 = '<span class="verticalMenu">';
|
||||
if ($param[0] ne "") {
|
||||
$temp .= traversePageTree(1,0,$param[0]);
|
||||
$tree = WebGUI::Navigation::tree(1,$param[0]);
|
||||
} else {
|
||||
$temp .= traversePageTree(1,0,1);
|
||||
$tree = WebGUI::Navigation::tree(1,1);
|
||||
}
|
||||
$temp .= WebGUI::Navigation::drawVertical($tree);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
return $temp;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="horizontalMenu">';
|
||||
$first = 1;
|
||||
$sth = WebGUI::SQL->read("select menuTitle,urlizedTitle,pageId from page where parentId=$session{page}{pageId} order by sequenceNumber");
|
||||
while (@data = $sth->array) {
|
||||
if (WebGUI::Privilege::canViewPage($data[2])) {
|
||||
if ($first) {
|
||||
$first = 0;
|
||||
} else {
|
||||
$temp .= $delimeter;
|
||||
}
|
||||
$temp .= '<a class="horizontalMenu" href="'.WebGUI::URL::gateway($data[1]).
|
||||
'">'.$data[0].'</a>';
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$temp .= WebGUI::Navigation::drawHorizontal($tree,$param[0]);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="horizontalMenu">';
|
||||
$first = 1;
|
||||
$sth = WebGUI::SQL->read("select menuTitle,urlizedTitle,pageId from page where parentId=$session{page}{parentId} order by sequenceNumber");
|
||||
while (@data = $sth->array) {
|
||||
if (WebGUI::Privilege::canViewPage($data[2])) {
|
||||
if ($first) {
|
||||
$first = 0;
|
||||
} else {
|
||||
$temp .= $delimeter;
|
||||
}
|
||||
$temp .= '<a class="horizontalMenu" href="'.WebGUI::URL::gateway($data[1]).'">';
|
||||
if ($session{page}{pageId} == $data[2]) {
|
||||
$temp .= '<span class="selectedMenuItem">'.$data[0].'</span>';
|
||||
} else {
|
||||
$temp .= $data[0];
|
||||
}
|
||||
$temp .= '</a>';
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$temp .= WebGUI::Navigation::drawHorizontal($tree,$param[0]);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="horizontalMenu">';
|
||||
$first = 1;
|
||||
($parentId) = WebGUI::SQL->quickArray("select pageId from page where urlizedTitle='$param[0]'");
|
||||
$sth = WebGUI::SQL->read("select menuTitle,urlizedTitle,pageId from page where parentId='$parentId' order by sequenceNumber");
|
||||
while (@data = $sth->array) {
|
||||
if (WebGUI::Privilege::canViewPage($data[2])) {
|
||||
if ($first) {
|
||||
$first = 0;
|
||||
} else {
|
||||
$temp .= $delimeter;
|
||||
}
|
||||
$temp .= '<a class="horizontalMenu" href="'.WebGUI::URL::gateway($data[1]).'">';
|
||||
if ($session{page}{pageId} == $data[2]) {
|
||||
$temp .= '<span class="selectedMenuItem">'.$data[0].'</span>';
|
||||
} else {
|
||||
$temp .= $data[0];
|
||||
}
|
||||
$temp .= '</a>';
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$tree = WebGUI::Navigation::tree($parentId,1);
|
||||
$temp .= WebGUI::Navigation::drawHorizontal($tree,$param[1]);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = '<span class="horizontalMenu">';
|
||||
$first = 1;
|
||||
$sth = WebGUI::SQL->read("select menuTitle,urlizedTitle,pageId from page where parentId=1 order by sequenceNumber");
|
||||
while (@data = $sth->array) {
|
||||
if (WebGUI::Privilege::canViewPage($data[2])) {
|
||||
if ($first) {
|
||||
$first = 0;
|
||||
} else {
|
||||
$temp .= $delimeter;
|
||||
}
|
||||
$temp .= '<a class="horizontalMenu" href="'.WebGUI::URL::gateway($data[1]).'">';
|
||||
if ($session{page}{pageId} == $data[2]) {
|
||||
$temp .= '<span class="selectedMenuItem">'.$data[0].'</span>';
|
||||
} else {
|
||||
$temp .= $data[0];
|
||||
}
|
||||
$temp .= '</a>';
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$temp .= WebGUI::Navigation::drawHorizontal($tree,$param[0]);
|
||||
$temp .= '</span>';
|
||||
return $temp;
|
||||
}
|
||||
|
|
|
|||
196
lib/WebGUI/Navigation.pm
Normal file
196
lib/WebGUI/Navigation.pm
Normal file
|
|
@ -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 .= '<a class="'.$class.'" href="'.$tree->{$pageId}{url}
|
||||
.'"><span class="selectedMenuItem">'
|
||||
.$tree->{$pageId}{title}.'</span></a>';
|
||||
}
|
||||
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 .= "<br>";
|
||||
}
|
||||
foreach $pageId (keys %{$tree}) {
|
||||
$output .= $padding.$bullet.'<a class="'.$class.'" href="'.$tree->{$pageId}{url}
|
||||
.'"><span class="selectedMenuItem">'
|
||||
.$tree->{$pageId}{title}.'</span></a>'.$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;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue