From: <de...@de...> - 2006-07-26 18:43:09
|
Author: MichaelDaum Date: 2006-07-26 09:00:52 -0500 (Wed, 26 Jul 2006) New Revision: 11197 Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListExamples.txt twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListPlugin.txt twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin.pm twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/Core.pm twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/DEPENDENCIES twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/MANIFEST twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/build.pl Log: Item2685: * initial release of a FlexWebListPlugin * partially solves Item2242, Item2240, Item2566 Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListExamples.txt =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListExamples.txt 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListExamples.txt 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,192 @@ +%META:TOPICINFO{author="TWikiContributor" date="1153920883" format="1.1" reprev="1.1" version="1.1"}% +%META:TOPICPARENT{name="FlexWebListPlugin"}% +---+!! %TOPIC% + +These are some simple examples to show how to use the basic features +of the FlexWebListPlugin. Please create some subwebs in the Sandbox web +for a better illustration of the examples below. Some of the examples +are displayed using the "glue" syntax of the TWiki:Plugins.GluePlugin +to ease reading multiline TML expressions and arguments. + +%TOC% + +---++ No params +<verbatim> +%FLEXWEBLIST% +</verbatim> +%FLEXWEBLIST% + +---++ Influencing order +<verbatim> +%FLEXWEBLIST{webs="%MAINWEB%,public,%TWIKIWEB%"}% +</verbatim> +%FLEXWEBLIST{webs="%MAINWEB%,public,%TWIKIWEB%"}% + +---++ Controlling subwebs +---+++ No subwebs +<verbatim> +%FLEXWEBLIST{subwebs="none"}% +</verbatim> +%FLEXWEBLIST{subwebs="none"}% + +---+++ Only subwebs +<verbatim> +%FLEXWEBLIST{subwebs="only"}% +</verbatim> +%FLEXWEBLIST{subwebs="only"}% + +---+++ Subwebs of "Sandbox" +<verbatim> +%FLEXWEBLIST{subwebs="Sandbox"}% +</verbatim> +%FLEXWEBLIST{subwebs="Sandbox"}% + +---++ Using include and exclude + +---+++ Exclude <nop>TestCases and Trash webs +<verbatim> +%FLEXWEBLIST{exclude="TestCases|Trash" subwebs="none"}% +</verbatim> +%FLEXWEBLIST{exclude="TestCases|Trash" subwebs="none"}% + +---+++ Include Sandbox web and all of its subwebs +<verbatim> +%FLEXWEBLIST{include="Sandbox(/\w+)?"}% +</verbatim> +%FLEXWEBLIST{include="Sandbox(/\w+)?"}% + +---++ Creating lists +---+++ Simple nested list +<verbatim> +%FLEXWEBLIST{format="$indent* [[$web.WebHome][$name]]$n"}% +</verbatim> +%FLEXWEBLIST{format="$indent* [[$web.WebHome][$name]]$n"}% + +---+++ Nested list using HTML +<verbatim> +%~~ FLEXWEBLIST{ +~~~ header="<ul>" +~~~ format="<li>[[$web.WebHome][$name]]" +~~~ separator="</li>" +~~~ footer="</li></ul>" +~~~ }% +</verbatim> +%FLEXWEBLIST{header="<ul>" format="<li>[[$web.WebHome][$name]]" separator="</li>" footer="</li></ul>"}% + +---+++ Nested calls to FLEXWEBLIST +<verbatim> +%~~ FLEXWEBLIST{ +~~~ exclude="TestCases|Trash" +~~~ subwebs="none" +~~~ selection="Sandbox" +~~~ format="$indent* [[$web.WebHome][$name]]$n" +~~~ markerformat="$percntFLEXWEBLIST{ +~~~ webs=\"$web\" +~~~ format=\"$dollarindent* [[$dollarweb.WebHome][$dollarname]]$dollarn\" +~~~ }$percnt" +~~~ }% +</verbatim> +%FLEXWEBLIST{exclude="TestCases|Trash" subwebs="none" selection="Sandbox" format="$indent* [[$web.WebHome][$name]]$n" markerformat="$percntFLEXWEBLIST{ webs=\"$web\" format=\"$dollarindent* [[$dollarweb.WebHome][$dollarname]]$dollarn\" }$percnt"}% + +---+++ Twisty weblist +needs the TWiki:Plugins/TwistyPlugin +%~~ FLEXWEBLIST{ +~~~ header="<ul>" +~~~ format="<li> +~~~ $percntTWISTYBUTTON{ +~~~ id=\"twisty_weblist_$web\" +~~~ link=\"$name ($nrsubwebs)\" +~~~ }$percnt" +~~~ separator="</li>" +~~~ subheader="$percntTWISTYTOGGLE{id=\"twisty_weblist_$web\" mode=\"div\"}$percnt<ul>" +~~~ subfooter="</li></ul>$percntENDTWISTY$percnt" +~~~ footer="</li></ul>" +~~~ }% + + +---++ Twisty navigation +needs the TWiki:Plugins/TwistyPlugin and the TWiki:Plugins/IfDefinedPlugin + +<verbatim> +%~~ FLEXWEBLIST{ +~~~ webs="%MAINWEB%,public,%TWIKIWEB%" +~~~ exclude="TestCases|Trash" +~~~ header="<ul>" +~~~ format="<li>[[$web.WebHome][$name]] +~~~ $percntIFDEFINEDTHEN{\"$nrsubwebs \" as=\"0 \"}$percnt +~~~ $percntELSEDEFINED$percnt +~~~ $percntTWISTYBUTTON{ +~~~ id=\"sitemap_$web\" +~~~ buttonmode=\"span\" +~~~ showimg=\"$percntICONURLPATH{\"toggleopenleft\"}$percnt\" +~~~ hideimg=\"$percntICONURLPATH{\"toggleclose\"}$percnt\" +~~~ }$percnt +~~~ $percntFIDEFINED$percnt" +~~~ separator="</li>$n" +~~~ subheader="$percntTWISTYTOGGLE{id=\"sitemap_$web\"}$percnt<ul>" +~~~ subfooter="</li></ul>$percntENDTWISTY$percnt" +~~~ footer="</ul>" +~~~ }% +</verbatim> +%FLEXWEBLIST{webs="%MAINWEB%,public,%TWIKIWEB%" exclude="TestCases|Trash" header="<ul>" format="<li>[[$web.WebHome][$name]] $percntIFDEFINEDTHEN{\"$nrsubwebs \" as=\"0 \"}$percnt $percntELSEDEFINED$percnt $percntTWISTYBUTTON{id=\"sitemap_$web\" buttonmode=\"span\" showimg=\"$percntICONURLPATH{\"toggleopenleft\"}$percnt\" hideimg=\"$percntICONURLPATH{\"toggleclose\"}$percnt\" }$percnt $percntFIDEFINED$percnt" separator="</li>$n" subheader="$percntTWISTYTOGGLE{id=\"sitemap_$web\" mode=\"div\"}$percnt<ul>" subfooter="</li></ul>$percntENDTWISTY$percnt" footer="</ul>"}% + +---++ Sitemap +%~~ FLEXWEBLIST{ +~~~ webs="%MAINWEB%,public,%TWIKIWEB%" +~~~ header="<div class=\"header\">" +~~~ format="<div class=\"web\"> +~~~ [[$web.WebHome][$name]] $percntVAR{\"SITEMAPWHAT\" web=\"$web\"}$percnt +~~~ </div>" +~~~ footer="</div>" +~~~ }% +<style type="text/css"> +.web, +.header { + margin:5px 50px; + padding:5px; + border:1px solid #f3a; +} +.web { + margin:5px; +} +.header a:visited, +.header a:hover, +.header a { + font-weight:bold; +} +</style> + +---++ Mapping names +<verbatim> +%~~ FLEXWEBLIST{ +~~~ map="TestCases=Tests,%TWIKIWEB%=System,%MAINWEB%=Home" +~~~ format="$indent* [[$web.WebHome][$name]]$n" +~~~ }% +</verbatim> +%FLEXWEBLIST{map="TestCases=Tests,%TWIKIWEB%=System,%MAINWEB%=Home" format="$indent* [[$web.WebHome][$name]]$n"}% + +---++ Marking a selection + +---+++ Using marker +<verbatim> +%~~ FLEXWEBLIST{ +~~~ exclude="TestCases|Trash" +~~~ format="$indent* <span class=\"$marker\"> $web </span>$n" +~~~ marker="twikiAlert" +~~~ selection="%BASEWEB%" +~~~ }% +</verbatim> +%FLEXWEBLIST{exclude="TestCases|Trash" format="$indent* <span class=\"$marker\"> $web </span>$n" marker="twikiAlert" selection="%BASEWEB%"}% + +---+++ Using markerformat +<verbatim> +%~~ FLEXWEBLIST{ +~~~ exclude="TestCases|Trash" +~~~ format="$indent* [[$web.WebHome][$name]]$n" +~~~ markerformat="$indent* +~~~ [[$web.WebHome][<span class=\"twikiAlert\">$name</span>]]$n" +~~~ selection="%BASEWEB%" +~~~ }% +</verbatim> +%FLEXWEBLIST{exclude="TestCases|Trash" format="$indent* [[$web.WebHome][$name]]$n" markerformat="$indent* [[$web.WebHome][<span class=\"twikiAlert\">$name</span>]]$n" selection="%BASEWEB%"}% + Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListPlugin.txt =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListPlugin.txt 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/data/TWiki/FlexWebListPlugin.txt 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,152 @@ +%META:TOPICINFO{author="TWikiContributor" date="1023947640" format="1.0" version="1.1"}% +<!-- + + PLEASE DO NOT EDIT THIS TOPIC + + It is automatically generated from the subversion repository, and any changes + you make will simply be overwritten the next time a release is generated. + + Instead, you could check your fix in, raise a bug in the Bugs web, or mail the author. +--> +---+!! <nop>%TOPIC% +This is a replacement for TWiki's standard [[%TWIKIWEB%.VarWEBLIST][WEBLIST]] variable. +It is extended to improve the display of hierarchical web structures, +a feature added to TWiki4 and adds more flexibility when used in +<nop>TWikiApplications. The FLEXWEBLIST can be used for example +to generate a hierarchical navigatio scheme or a nested sitemap. + +---++ Syntax +=%<nop>FLEXWEBLIST{...}%= + +This tag iterates over all specified webs and all of their subwebs recursively +while using the specified format strings to produce the output. + +Parameters: + * =webs=: a list of webs to be displayed and/or + "public" - a list of all non-hidden webs, + "webtemplate" - a list of all template webs; + (defaults to "public") + * =format=: format string to render one item + (defaults to "$web ") + * =header=: format string prepended to the output result + * =footer=: format string appended to the result; if the list + of webs is empty neither header nor footer are added. + * =separator=: text to be put between webs + * =subformat=: format string to be used to format subwebs + (defaults to =format=) + * =subheader=: format string preceding the output of any subweb + (defaults to =header=) + * =subfooter=: format string following the output of any subweb; + subheader and subfooter are only added if the list of subwebs of the + current web is not empty + (defaults to =footer=) + * =subseparator=: text to be put between subwebs + (defaults to =separator=) + * =selection=: selected items in the list of webs + * =marker=: text for =$marker= if the item maches the selection + (see pseudo variables below) + * =markerformat=: format string used instead of (sub)format string + for selected items + * =exclude=: regular expression of items excluded from the output + * =include=: regular expressions of items that must match in order to be + included in the output + * =map=: list of =key=value= pairs to map the name of a web to a different value + (e.g. map="TWiki=System,Main=Home" will expand the variable =$name= as "System" instead of TWiki + and as "Home" instead "Main") + +Parameters default to the emtpy string if not mentioned otherwise. Note, that some +of them although similar to WEBLIST have different default values. + +*Pseudo-variables*: Each of the above format strings (format, header, footer, +subformat, subheader, subfooter and markerformat) may contain special variables +that are replaced with a current value: + * =$web=: the full name of the web, e.g. =Main/Foo/Bar= + * =$qname=: the full name of the web in quotes, e.g. ="Main/Foo/Bar"= (deprecated) + * =$name=: the name of the web without the leading parent webs, e.g. =Bar= + * =$origname=: the original name of the web despite any name mapping + * =$parent=: the name of the parent web of a sub web or the empty string if there's none + * =$marker=: marker text (see above) if the current item is selected, empty otherwise + * =$depth=: level of embedding of a subweb; main level web have depth 0 etc. + * =$nrsubwebs=: number of subwebs a current web has + * =$indent=: expands to three spaces for each level a web is embeded; main level + webs get three spaces, subwebs on first level six spaces and so on. + * =$indent(string)=: same as =$indent= but using =string= instead of three spaces + +The following picture illustrates when which format strings are used +<div class="box"> + <div class="header">header</div> + <div class="format">format</div> + <div class="separator">separator</div> + <div class="format">format</div> + <div class="box"> + <div class="header">subheader</div> + <div class="format">subformat</div> + <div class="box"> + <div class="header">subheader</div> + <div class="format">subformat</div> + <div class="footer">subfooter</div> + </div> + <div class="separator">subseparator</div> + ... + <div class="separator">subseparator</div> + <div class="format">subformat</div> + <div class="footer">subfooter</div> + </div> + <div class="separator">separator</div> + ... + <div class="separator">subseparator</div> + <div class="format">format</div> + <div class="footer">footer</div> +</div> +<style type="text/css"> +.box { + border:1px solid blue; + padding:10px; + margin:10px; +} +.format, +.separator, +.header, +.footer { + margin:5px; + padding:5px; +} +.header, .footer {border:1px solid green; } +.format {border:1px solid red; } +.separator {border:1px solid yellow;} +</style> + +---++ Examples +See the FlexWebListExamples. + +---++ Plugin Settings + + * Set SHORTDESCRIPTION = Flexible way to display hierarchical weblists + +---++ Plugin Installation Instructions + + + * [[%ATTACHURL%/%TOPIC%.zip][Download]] the ZIP file + * Unzip ==%TOPIC%.zip== in your twiki installation directory. Content: + | *File:* | *Description:* | +%$MANIFEST% + * (Dakar) Visit =configure= in your TWiki installation, and enable the plugin in the {Plugins} section. + +---++ Plugin Info + +| Plugin Author: | TWiki:Main.MichaelDaum | +| Copyright ©: | 2006, Michael Daum | +| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | +| Plugin Version: | v0.01 | +| Change History: | | +| 26 Jul 2006: | first release | +| 05 Jul 2006: | initial version | +| CPAN Dependencies: | none | +| Other Dependencies: | none | +| Perl Version: | 5.8 | +| TWiki:Plugins/Benchmark: | %TWIKIWEB%.GoodStyle nn%, %TWIKIWEB%.FormattedSearch nn%, %TOPIC% nn% | +| Plugin Home: | TWiki:Plugins/%TOPIC% | +| Feedback: | TWiki:Plugins/%TOPIC%Dev | +| Appraisal: | TWiki:Plugins/%TOPIC%Appraisal | + +-- TWiki:Main/MichaelDaum - 27 Jul 2006 Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/Core.pm =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/Core.pm 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/Core.pm 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,298 @@ +# Plugin for TWiki Collaboration Platform, http://TWiki.org/ +# +# Copyright (C) 2006 MichaelDaum@WikiRing.com +# +# 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. For +# more details read LICENSE in the root of this distribution. +# +# 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. + +package TWiki::Plugins::FlexWebListPlugin::Core; + +use strict; +use vars qw($debug); + +$debug = 0; # toggle me + +############################################################################### +# static +sub writeDebug { + &TWiki::Func::writeDebug('- FlexWebListPlugin - '.$_[0]) if $debug; + #print STDERR '- FlexWebListPlugin - '.$_[0]."\n" if $debug; +} + +############################################################################### +# constructor +sub new { + my $class = shift; + my $this = bless({}, $class); + + $this->{isDakar} = (defined $TWiki::RELEASE)?1:0; # we could do better + $this->{webCache} = (); + + return $this; +} + +############################################################################### +sub handler { + my ($this, $args, $currentWeb, $currentTopic) = @_; + + writeDebug("*** called hander($args)"); + + # extract parameters + $this->{webs} = + TWiki::Func::extractNameValuePair($args) || + TWiki::Func::extractNameValuePair($args, 'webs') || 'public'; + + $this->{header} = TWiki::Func::extractNameValuePair($args, 'header') || ''; + $this->{format} = TWiki::Func::extractNameValuePair($args, 'format') || '$web '; + $this->{footer} = TWiki::Func::extractNameValuePair($args, 'footer') || ''; + $this->{separator} = TWiki::Func::extractNameValuePair($args, 'separator') || ''; + $this->{separator} = '' if $this->{separator} eq 'none'; + + $this->{subHeader} = TWiki::Func::extractNameValuePair($args, 'subheader') || $this->{header}; + $this->{subFormat} = TWiki::Func::extractNameValuePair($args, 'subformat') || $this->{format}; + $this->{subFooter} = TWiki::Func::extractNameValuePair($args, 'subfooter') || $this->{footer}; + $this->{subSeparator} = TWiki::Func::extractNameValuePair($args, 'subseparator') || $this->{separator}; + $this->{subSeparator} = '' if $this->{subSeparator} eq 'none'; + + $this->{markerFormat} = TWiki::Func::extractNameValuePair($args, 'markerformat') || $this->{format}; + $this->{selection} = TWiki::Func::extractNameValuePair($args, 'selection') || ''; + $this->{marker} = TWiki::Func::extractNameValuePair($args, 'marker') || ''; + $this->{exclude} = TWiki::Func::extractNameValuePair($args, 'exclude') || ''; + $this->{include} = TWiki::Func::extractNameValuePair($args, 'include') || ''; + $this->{subWebs} = TWiki::Func::extractNameValuePair($args, 'subwebs') || 'all'; + + $this->{selection} =~ s/\,/ /go; + $this->{selection} = ' '.$this->{selection}.' '; + $this->{currentWeb} = $currentWeb; + $this->{currentTopic} = $currentTopic; + writeDebug("include filter=/^($this->{include})\$/") if $this->{include}; + writeDebug("exclude filter=/^($this->{exclude})\$/") if $this->{exclude}; + + # compute map + my $theMap = TWiki::Func::extractNameValuePair($args, 'map') || ''; + $this->{map} = (); + foreach my $entry (split(/,\s*/, $theMap)) { + if ($entry =~ /^(.*)=(.*)$/) { + $this->{map}{$1} = $2; + } + } + + # compute list + my %seen; + my @list = (); + my @websList = split(/,\s*/, $this->{webs}); + my $allWebs = $this->getWebs(); + + # collect the list in preserving the given order in webs parameter + foreach my $aweb (@websList) { + if ($aweb eq 'public' || $aweb eq 'webtemplate') { + foreach my $bweb (sort keys %{$this->getWebs($aweb)}) { + next if $seen{$bweb}; + $seen{$bweb} = 1; + push @list, $bweb; + } + } else { + next if $seen{$aweb}; + $seen{$aweb} = 1; + push @list, $aweb if defined $allWebs->{$aweb}; # only add if it exists + } + } + + # format result + my @result; + foreach my $aweb (@list) { + writeDebug("aweb=$aweb"); + my $web = $allWebs->{$aweb}; + + # filter explicite subwebs + next if $this->{subWebs} !~ /^(all|none|only)$/ && $web->{key} !~ /$this->{subWebs}\/[^\/]*$/; + + # start recursion + my $line = $this->formatWeb($web, $this->{format}); + push @result, $line if $line; + } + + # reset 'done' flag + foreach my $aweb (keys %$allWebs) { + $allWebs->{$aweb}{done} = 0; + } + + return '' unless @result; + + my $result = join($this->{separator},@result); + $result =~ s/\$marker//g; + $result = $this->{header}.$result.$this->{footer}; + escapeParameter($result); + #writeDebug("result=$result"); + $result = TWiki::Func::expandCommonVariables($result, $currentTopic, $currentWeb); + + writeDebug("*** hander done"); + + return $result; +} + +############################################################################### +sub formatWeb { + my ($this, $web, $format) = @_; + + # check conditions to format this web + return '' if $web->{done}; + return '' + if $web->{isSubWeb} && $this->{subWebs} eq 'none' && # skip subwebs + $this->{webs} !~ /\b$web->{key}\b/; # but only if they are not explicit + return '' if $this->{exclude} ne '' && $web->{key} =~ /^($this->{exclude})$/; + return '' if $this->{include} ne '' && $web->{key} !~ /^($this->{include})$/; + + $web->{done} = 1; + writeDebug("formatWeb($web->{key})"); + + # format all subwebs recursively + my $subWebResult = ''; + my @lines; + foreach my $subWeb (@{$web->{children}}) { + next if $this->{webs} =~ /\b$subWeb->{key}\b/; + my $line = $this->formatWeb($subWeb, $this->{subFormat}); # recurse + push @lines, $line if $line; + } + if (@lines) { + $subWebResult = $this->{subHeader}.join($this->{subSeparator},@lines).$this->{subFooter}; + } + + my $result = ''; + if (!$web->{isSubWeb} && $this->{subWebs} eq 'only' && $this->{webs} !~ /\b$web->{key}\b/) { + $result = $subWebResult; + } else { + if ($this->{selection} =~ / \Q$web->{key}\E /) { + $format = $this->{markerFormat}; + $format =~ s/\$marker/$this->{marker}/g; + } + $result = $format.$subWebResult; + } + my $nrSubWebs = @{$web->{children}}; + my $name = $this->{map}{$web->{name}} || $web->{name}; + $result =~ s/\$parent/$web->{parentName}/go; + $result =~ s/\$name/$name/go; + $result =~ s/\$origname/$web->{name}/go; + $result =~ s/\$qname/"$web->{key}"/g;# historical + $result =~ s/\$web/$web->{key}/go; + $result =~ s/\$depth/$web->{depth}/go; + $result =~ s/\$indent\((.+?)\)/$1 x (($web->{depth}+1)*3)/ge; + $result =~ s/\$indent/' ' x (($web->{depth}+1)*3)/ge; + $result =~ s/\$nrsubwebs/$nrSubWebs/g; + + #writeDebug("result=$result"); + writeDebug("done formatWeb($web->{key})"); + + return $result; +} + +############################################################################### +# get a hash of all webs, each web points to its subwebs, each subweb points +# to its parent +sub getWebs { + my ($this,$filter) = @_; + + $filter ||= ''; + + #writeDebug("getWebs($filter)"); + + # lookup cache + return $this->{webCache}{$filter} if defined $this->{webCache}{$filter}; + + my @webs = (); + + # dakar + if ($this->{isDakar}) { + if ($filter eq 'public') { + @webs = TWiki::Func::getListOfWebs('user,public,allowed'); + } elsif ($filter eq 'webtemplate') { + @webs = TWiki::Func::getListOfWebs('template,allowed'); + } else { + @webs = TWiki::Func::getListOfWebs($filter); + } + } else { + + # cairo, beijing + if ($filter eq 'public') { + @webs = TWiki::Func::getPublicWebList(); + } elsif ($filter eq 'webtemplate') { + @webs = grep { /^\_/o } &TWiki::Store::getAllWebs(''); # no Func API available + } else { + @webs = &TWiki::Store::getAllWebs(''); # no Func API available + } + } + my $webs = $this->hashWebs(@webs); + + # cache weblist + $this->{webCache}{$filter} = $webs; + + #writeDebug("result=".join(',',@webs)); + return $webs; +} + +############################################################################### +# convert a flat list of webs to a structured parent-child structure; +# the returned hash contains elements of the form +# { +# key => the full webname (e.g. Main/Foo/Bar) +# name => the tail of the webname (e.g. Bar) +# isSubWeb => 1 if the web is a subweb, 0 if it is a top-level web +# parentName => only defined for subwebs +# parent => pointer to parent web structure +# children => list of pointers to subwebs +# } +sub hashWebs { + my $this = shift; + my @webs = @_; + + #writeDebug("hashWebs(".join(',',@webs)); + + my %webs; + # collect all webs + foreach my $key (@webs) { + $webs{$key}{key} = $key; + if ($key =~ /^(.*)\/(.*?)$/) { + $webs{$key}{isSubWeb} = 1; + $webs{$key}{parentName} = $1; + $webs{$key}{name} = $2; + } else { + $webs{$key}{name} = $key; + $webs{$key}{isSubWeb} = 0; + $webs{$key}{parentName} = ''; + } + $webs{$key}{depth} = ($key =~ tr/\///); + } + + # establish parent-child relation + foreach my $key (@webs) { + my $parentName = $webs{$key}{parentName}; + if ($parentName) { + $webs{$key}{parent} = $webs{$parentName}; + push @{$webs{$parentName}{children}}, $webs{$key}; + } + } + + return \%webs; +} + +############################################################################### +sub escapeParameter { + return '' unless $_[0]; + + $_[0] =~ s/\$n/\n/g; + $_[0] =~ s/\$nop//g; + $_[0] =~ s/\$percnt/%/g; + $_[0] =~ s/\$dollar/\$/g; +} + + + +############################################################################### +1; Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/DEPENDENCIES =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/DEPENDENCIES 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/DEPENDENCIES 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1 @@ +TWiki::Plugins::GluePlugin,>=1.5,perl,Recommended; Download from TWiki:Plugins/GluePlugin Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/MANIFEST =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/MANIFEST 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/MANIFEST 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,4 @@ +data/TWiki/FlexWebListExamples.txt 0644 +data/TWiki/FlexWebListPlugin.txt 0644 +lib/TWiki/Plugins/FlexWebListPlugin/Core.pm 0644 +lib/TWiki/Plugins/FlexWebListPlugin.pm 0644 Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/build.pl =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/build.pl 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin/build.pl 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w +BEGIN { + foreach my $pc (split(/:/, $ENV{TWIKI_LIBS})) { + unshift @INC, $pc; + } +} + +use TWiki::Contrib::Build; + +# Create the build object +$build = new TWiki::Contrib::Build( 'FlexWebListPlugin' ); + +# Build the target on the command line, or the default target +$build->build($build->{target}); + Added: twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin.pm =================================================================== --- twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin.pm 2006-07-26 13:20:24 UTC (rev 11196) +++ twiki/branches/TWikiRelease04x00/twikiplugins/FlexWebListPlugin/lib/TWiki/Plugins/FlexWebListPlugin.pm 2006-07-26 14:00:52 UTC (rev 11197) @@ -0,0 +1,51 @@ +# Plugin for TWiki Collaboration Platform, http://TWiki.org/ +# +# Copyright (C) 2006 MichaelDaum@WikiRing.com +# +# 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. For +# more details read LICENSE in the root of this distribution. +# +# 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. + +package TWiki::Plugins::FlexWebListPlugin; + +use strict; +use vars qw( $VERSION $RELEASE $core); + +$VERSION = '$Rev$'; +$RELEASE = 'v0.01'; + +############################################################################### +sub initPlugin { + $core = undef; + return 1; +} + +############################################################################### +sub commonTagsHandler { + $_[0] =~ s/%FLEXWEBLIST%/&renderFlexWebList('', $_[2], $_[1])/geo; + $_[0] =~ s/%FLEXWEBLIST{(.*?)}%/&renderFlexWebList($1, $_[2], $_[1])/geo; +} + +############################################################################### +sub newCore { + + return $core if $core; + eval 'use TWiki::Plugins::FlexWebListPlugin::Core;'; + die $@ if $@; + $core = new TWiki::Plugins::FlexWebListPlugin::Core; + return $core; +} + +############################################################################### +sub renderFlexWebList { + return newCore()->handler(@_); +} + +############################################################################### +1; |