[MKDoc-commit] [1.6] New sitemap plugin shows hidden docs, only available to editors

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Thu Aug 18 12:31:44 BST 2005


Log Message:
-----------
[1.6] New sitemap plugin shows hidden docs, only available to editors

Tags:
----
mkdoc-1-6

Modified Files:
--------------
    mkd/conf:
        users.conf

Added Files:
-----------
    mkd/flo/plugin:
        SitemapFull.pm
    mkd/templates/sitemap-full:
        en.html
        nesting.html

-------------- next part --------------
--- /dev/null
+++ flo/plugin/SitemapFull.pm
@@ -0,0 +1,165 @@
+# -------------------------------------------------------------------------------------
+# flo::plugin::SitemapFull
+# -------------------------------------------------------------------------------------
+# Author : Jean-Michel Hiver.
+# Copyright : (c) MKDoc Holdings Ltd, 2003.
+#
+# This file is part of MKDoc. 
+# 
+# MKDoc 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.
+# 
+# MKDoc 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 MKDoc; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# -------------------------------------------------------------------------------------
+package flo::plugin::SitemapFull;
+use flo::Standard;
+use strict;
+use base qw /flo::Plugin/;
+use Encode;
+
+our $Level = 0;
+
+
+sub _name_default { '.sitemap-full.html' }
+
+
+sub run
+{
+    my $self = shift;
+    $| = 1;
+    $self->render_http (
+	self       => $self,
+	root       => _structure (_results()),
+	__input__  => 'XML',
+	__output__ => 'XHTML',
+       );
+    return 'TERMINATE';
+}
+
+
+sub template_path { '/sitemap-full' }
+
+
+sub activate
+{
+    my $self = shift;
+    return 0 unless ($self->SUPER::activate(@_));
+    return 0 unless ($self->user);
+    return 0 unless ($self->user->is_editor);
+    return $self;
+}
+
+
+sub _structure
+{
+    my $results = shift;
+    local $Level = 0;
+    
+    my $res = _structure_recurse ($results);
+    _reorder ($res->[0]);
+    return shift (@{$res});
+}
+
+
+sub _reorder
+{
+    my $node = shift;
+    return unless (defined $node->{Children} && scalar @{$node->{Children}});
+    
+    my $sort_on = $node->{Sort_By};
+    my $desc    = $node->{Order_By};
+    
+    if ($sort_on eq 'Sibling_Position')
+    {
+	$node->{Children} = ($desc) ?
+	[ sort { $b->{$sort_on} <=> $a->{$sort_on} } @{$node->{Children}} ] :
+	[ sort { $a->{$sort_on} <=> $b->{$sort_on} } @{$node->{Children}} ];
+    }
+    else
+    {
+	$node->{Children} = ($desc) ?
+	[ sort { $b->{$sort_on} cmp $a->{$sort_on} } @{$node->{Children}} ] :
+	[ sort { $a->{$sort_on} cmp $b->{$sort_on} } @{$node->{Children}} ];
+    }
+    
+    _reorder ($_) for (@{$node->{Children}});
+}
+
+
+sub _structure_recurse
+{
+    $Level++;
+
+    my $flat = shift;
+    scalar @{$flat} <= 1 and return [ shift @{$flat} ];
+
+    my @res = shift @{$flat};
+    while ( scalar @{$flat} )
+    {   
+        my $next_lvl = $flat->[0]->{Full_Path} =~ tr/\//\//;
+        ($Level == $next_lvl) and do {
+            push @res, shift @{$flat};
+            next;
+        };
+
+        ($Level < $next_lvl)  and do {
+            $res[-1]->{Children} = _structure_recurse ($flat);
+        };
+
+        ($Level > $next_lvl) and last;
+    }
+
+    $Level--;
+    return [ @res ];
+}
+
+
+sub _results
+{
+    my $sql  = <<EOF;
+SELECT Description, Full_Path, Title, Lang, Sort_By, Order_By, Date_Created, Date_Last_Modified, Sibling_Position
+FROM Document
+ORDER BY Full_Path ASC
+EOF
+    
+    my $dbh = lib::sql::DBH->get();
+    my $sth = $dbh->prepare_cached ($sql);
+    $sth->execute();
+    
+    my @res = ();
+    while (my $h = $sth->fetchrow_hashref())
+    {
+	Encode::_utf8_on ($h->{Description});
+	Encode::_utf8_on ($h->{Title});
+	
+	# stick stuff in the sitemap only if it's showable
+	my $o = bless $h, 'flo::Record::Document';
+        if ($o->is_showable())
+        {
+            $h->{Class} = "showable";
+        }
+        else
+        {
+            $h->{Class} = "not-showable";
+        }
+use Data::Dumper; warn Dumper $h;
+	push @res, $h;
+    }
+    return \@res;
+}
+
+
+1;
+
+
+__END__
--- /dev/null
+++ templates/sitemap-full/nesting.html
@@ -0,0 +1,22 @@
+<li xmlns:petal="http://purl.org/petal/1.0/"
+  petal:attributes="class child/Class"
+  >
+  <a 
+    href="#"
+    hreflang="en"
+    lang="en"
+    xml:lang="en"
+    petal:attributes="href child/Full_Path; 
+                      hreflang child/Lang; 
+                      lang child/Lang;
+                      xml:lang child/Lang"
+    petal:content="child/Title"
+  >Child Document Title</a>
+  <ul 
+    petal:define="children child/Children"
+    petal:condition="children"
+    petal:repeat="child children"
+  >
+  <?include file="/sitemap-full/nesting.html"?>
+  </ul>
+</li>
--- /dev/null
+++ templates/sitemap-full/en.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC
+  "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+>
+<!--?
+
+
+This template is used for rendering the sitemap page.  
+
+?-->
+<html  
+  lang="en"
+  xml:lang="en"
+  dir="ltr"
+  petal:define="
+    here                  self;
+    uri                   self/uri;
+    title                 string:Sitemap;
+    lang                  self/lang;
+    dir                   self/direction;
+    align                 self/align;
+    align_opposite        self/align_opposite;
+    root_uri              self/root/uri;
+    root_title            self/root/title;
+    root_lang             self/root/lang;
+    parent_uri            self/parent/uri;
+    parent_lang           self/parent/lang;
+    parent_title          self/parent/title;
+    sitemap               plugin: flo::plugin::Sitemap;
+    search                plugin: flo::plugin::Search;
+    search_uri            search/uri;
+            "
+  petal:attributes="lang lang; xml:lang lang; dir dir;"
+  xmlns:petal="http://purl.org/petal/1.0/"
+  xmlns="http://www.w3.org/1999/xhtml"
+>
+
+<!--? This is the <head> for public documents ?-->
+<?include file="/fragments/head_public/"?>
+
+  <body 
+    lang="en"
+    xml:lang="en"
+    dir="ltr"
+    petal:attributes="lang lang; xml:lang lang; dir dir;"
+    petal:set="child root"
+  >
+
+<!--? This is the header it contains the navigational elements at the top of the page. ?-->
+<?include file="/fragments/header/"?>
+
+    <div class="content">
+
+          <h1 
+            lang="en"
+            xml:lang="en"
+            dir="ltr"
+            align="left"
+            petal:attributes="align align"
+          >
+            <a
+              id="page_content"
+              name="page_content"
+              petal:content="title"
+            >Sitemap</a>
+          </h1>
+           
+          <ul>
+            <?include file="/sitemap-full/nesting.html"?>
+          </ul>
+
+    </div>
+
+    <div class="sidebar">
+
+        <!--? This is the list of link components. ?-->
+        <?include file="/fragments/menu_quick_links/"?>
+
+    </div>
+  </body>
+</html>
Index: users.conf
===================================================================
RCS file: /var/spool/cvs/mkd/conf/Attic/users.conf,v
retrieving revision 1.1.2.39
retrieving revision 1.1.2.40
diff -Lconf/users.conf -Lconf/users.conf -u -r1.1.2.39 -r1.1.2.40
--- conf/users.conf
+++ conf/users.conf
@@ -11,6 +11,7 @@
 flo::plugin::File
 flo::plugin::Search
 flo::plugin::Sitemap
+flo::plugin::SitemapFull
 flo::plugin::DynamicSitemap
 flo::plugin::Print
 flo::plugin::Poll


More information about the MKDoc-commit mailing list