[MKDoc-commit] [1.6] Comment component and optional plugin for any
user to append
bruno at mkdoc.demon.co.uk
bruno at mkdoc.demon.co.uk
Fri Aug 19 18:19:06 BST 2005
Log Message:
-----------
[1.6] Comment component and optional plugin for any user to append comments
Tags:
----
mkdoc-1-6
Modified Files:
--------------
mkd/MKDoc/Site/ConfigWriter:
Httpd_Conf.pm
mkd/conf:
users.conf
mkd/skin:
admin.css
admin.ltr.css
admin.rtl.css
colours.css
public.css
mkd/templates/document/default:
en.html
mkd/templates/editor/box:
en.html
Added Files:
-----------
mkd/flo/editor:
Comment.pm
mkd/flo/plugin:
Comment.pm
mkd/templates/comment:
en.html
mkd/templates/component/comment:
en.html
mkd/templates/editor/comment:
en.html
-------------- next part --------------
--- /dev/null
+++ flo/plugin/Comment.pm
@@ -0,0 +1,128 @@
+# ------------------------------------------------------------------------
+# flo::plugin::Comment
+# ------------------------------------------------------------------------
+# Author : Bruno Postle.
+# Copyright : (c) MKDoc Ltd, 2005.
+#
+# 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::Comment;
+use flo::Standard;
+use flo::Plugin;
+use flo::editor::Comment;
+use strict;
+use warnings;
+use 5.008_000;
+use utf8;
+
+use vars qw /@ISA/;
+ at ISA = qw /flo::Plugin/;
+
+=head1 NAME
+
+flo::plugin::Comment - ability for any authenticated user to add comments
+
+=head1 SYNOPSIS
+
+Access this plugin like this:
+
+ http://www.example.com/.comment.html
+ http://www.example.com/foo/.comment.html
+
+=head1 DESCRIPTION
+
+This plugin implements a simple form that accepts plain text. When submitted,
+and so long as it isn't empty, this text gets appended to to the end of the
+document as the content of a L<flo::editor::Comment> component.
+
+This plugin doesn't control the later display or any other usage that the
+component may be put to.
+
+Once the form is POSTed, the user is redirected back to the parent document
+(which may or may not display the commment itself).
+
+=cut
+
+sub template_path { return '/comment' };
+
+sub _name_default { '.comment.html' }
+
+sub http_get
+{
+ my $self = shift;
+ my $cgi = flo::Standard::cgi();
+ $self->render_http (
+ self => $self,
+ object => $self->parent,
+ __input__ => 'XML',
+ __output__ => 'XHTML',
+ );
+ return 'TERMINATE';
+}
+
+sub http_post
+{
+ my $self = shift;
+ my $cgi = $self->cgi();
+
+ $self->_update_document_from_cgi();
+
+ print $cgi->redirect ($self->parent->uri);
+ return 'TERMINATE';
+}
+
+sub _update_document_from_cgi
+{
+ my $self = shift;
+ my $user = $self->user;
+ my $cgi = $self->cgi;
+
+ return unless ($cgi->param ('comment') =~ /[[:alnum:]]/);
+
+ my $text_obj = new flo::editor::Comment (
+ param_name => 'comment',
+ cgi => $cgi
+ );
+
+ my $editor = new flo::Editor();
+ my $document = $self->parent;
+ $editor->parse_xml ($document->{Body});
+ $editor->add_component ($document, $text_obj);
+
+ $document->{Body} = $editor->generate_xml();
+ $document->save();
+}
+
+=pod
+
+The plugin only activates if enabled in the plugin list and if the user is
+authenticated.
+
+=cut
+
+sub activate
+{
+ my $self = shift;
+ return 0 unless ($self->SUPER::activate(@_));
+ return 0 unless ($self->user);
+ return $self;
+}
+
+1;
+
+__END__
Index: colours.css
===================================================================
RCS file: /var/spool/cvs/mkd/skin/Attic/colours.css,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -Lskin/colours.css -Lskin/colours.css -u -r1.1.2.7 -r1.1.2.8
--- skin/colours.css
+++ skin/colours.css
@@ -14,6 +14,14 @@
border-color: #333 #333 #333 #333;
}
+div.comment {
+ background: #EEF;
+}
+
+div.comment-header {
+ background: #DDE;
+}
+
/* IE 6 on XP need the legend text colour setting */
legend {
background: transparent;
Index: admin.css
===================================================================
RCS file: /var/spool/cvs/mkd/skin/Attic/admin.css,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -Lskin/admin.css -Lskin/admin.css -u -r1.1.2.18 -r1.1.2.19
--- skin/admin.css
+++ skin/admin.css
@@ -169,6 +169,10 @@
color: #000;
background-color: #9C6;
}
+.comment-component {
+ color: #000;
+ background-color: #9CC;
+}
.image-component {
color: #000;
background-color: #69C;
Index: public.css
===================================================================
RCS file: /var/spool/cvs/mkd/skin/Attic/public.css,v
retrieving revision 1.1.2.39
retrieving revision 1.1.2.40
diff -Lskin/public.css -Lskin/public.css -u -r1.1.2.39 -r1.1.2.40
--- skin/public.css
+++ skin/public.css
@@ -266,4 +266,14 @@
padding-bottom: 0em;
padding-top: 0em;
}
+div.comment {
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+}
+div.comment-header, div.comment-body {
+ padding-left: 0.5em;
+ padding-right: 0.5em;
+ font-size: smaller;
+ overflow: hidden;
+}
Index: admin.rtl.css
===================================================================
RCS file: /var/spool/cvs/mkd/skin/Attic/admin.rtl.css,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -Lskin/admin.rtl.css -Lskin/admin.rtl.css -u -r1.1.2.4 -r1.1.2.5
--- skin/admin.rtl.css
+++ skin/admin.rtl.css
@@ -27,11 +27,11 @@
float: right;
}
/* this is for text and html components */
-fieldset.html-component em.help, fieldset.text-component em.help {
+fieldset.html-component em.help,, fieldset.text-component em.help fieldset.comment-component em.help {
float: left;
width: 10%;
}
-fieldset.html-component textarea.adminform, fieldset.text-component textarea.adminform {
+fieldset.html-component textarea.adminform, fieldset.text-component textarea.adminform, fieldset.comment-component textarea.adminform {
float: right;
width: 85%;
}
Index: admin.ltr.css
===================================================================
RCS file: /var/spool/cvs/mkd/skin/Attic/admin.ltr.css,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -Lskin/admin.ltr.css -Lskin/admin.ltr.css -u -r1.1.2.3 -r1.1.2.4
--- skin/admin.ltr.css
+++ skin/admin.ltr.css
@@ -27,11 +27,11 @@
float: left;
}
/* this is for text and html components */
-fieldset.html-component em.help, fieldset.text-component em.help {
+fieldset.html-component em.help, fieldset.text-component em.help, fieldset.comment-component em.help {
float: right;
width: 10%;
}
-fieldset.html-component textarea.adminform, fieldset.text-component textarea.adminform {
+fieldset.html-component textarea.adminform, fieldset.text-component textarea.adminform, fieldset.comment-component textarea.adminform {
float: left;
width: 85%;
}
--- /dev/null
+++ templates/comment/en.html
@@ -0,0 +1,168 @@
+<!DOCTYPE html PUBLIC
+ "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+>
+<!--?
+
+This template lets the user post a comment
+
+?-->
+<html
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ petal:set="
+ uri self/uri;
+ title string:Comment on ${self/parent/title};
+ user self/user;
+ lang self/lang;
+ dir self/direction;
+ align self/align;
+ align_opposite self/align_opposite;
+ sitemap plugin: flo::plugin::Sitemap;
+ sitemap_uri sitemap/uri;
+ search plugin: flo::plugin::Search;
+ search_uri search/uri;
+ "
+ petal:attributes="lang lang; xml:lang lang; dir dir;"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:petal="http://purl.org/petal/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+>
+
+<!--? 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;"
+ >
+
+<!--? 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"
+ >
+ Title of this page
+ </a>
+ </h1>
+
+ <xi:include href="/error/" />
+
+ <p
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ align="left"
+ petal:attributes="align align"
+ >
+
+ The editors of this site are encouraged to trim or remove duplicate
+ and off-topic material, so anything you contribute to this document
+ may be edited to improve readability. Your name and the date (but
+ <em>not</em> your email address) will appear alongside.
+
+ </p>
+
+ <form
+ action="#"
+ method="post"
+ accept-charset="UTF-8"
+ enctype="application/x-www-form-urlencoded"
+ petal:attributes="action uri"
+ >
+
+ <fieldset
+ class="login-details"
+ >
+
+ <legend
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ >
+ <a
+ id="login-details"
+ name="login-details"
+ >Your comment</a>
+ </legend>
+
+ <p
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ align="left"
+ class="help"
+ petal:attributes="align align"
+ >
+
+ Use plain text, start a new paragraph with two carriage
+ returns. Links like <em>http://example.com/</em> or
+ <em>mailto:info at example.com</em> will be made clickable.
+ </p>
+
+ <p
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ align="left"
+ petal:attributes="align align"
+ >
+ <label
+ for="comment"
+ >Type Comment</label>
+ <br />
+ <textarea
+ name="comment"
+ id="comment"
+ rows="12"
+ cols="45"
+ title="Enter Comment here."
+ class="adminform"
+ ></textarea>
+ </p>
+
+ </fieldset>
+
+ <p
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ align="left"
+ petal:attributes="align align"
+ >
+ <input
+ type="submit"
+ name="submit"
+ value="Add Comment"
+ class="input-submit"
+ title="Add this comment to this page"
+ />
+ </p>
+
+ </form>
+
+ </div>
+
+ <div class="sidebar">
+
+ <!--? This is the list of link components. ?-->
+ <?include file="/fragments/menu_quick_links/"?>
+
+ </div>
+ </body>
+</html>
--- /dev/null
+++ templates/component/comment/en.html
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--?
+
+This template is used for rendering the comment component in documents.
+
+?-->
+
+<div
+ class="comment"
+ xmlns:petal="http://purl.org/petal/1.0/"
+>
+ <div class="comment-header">
+ <span
+ class="comment-poster"
+ petal:content="self/poster"
+ >John Milton</span>
+ <span
+ class="comment-date"
+ petal:content="self/date_posted"
+ >1652-05-05 17:37:21</span>
+ </div>
+ <div
+ class="comment-body"
+ petal:content="structure self/comment"
+ >
+ <p>This comment component is <strong>super cool</strong>.</p>
+ </div>
+ </div>
Index: en.html
===================================================================
RCS file: /var/spool/cvs/mkd/templates/document/default/Attic/en.html,v
retrieving revision 1.6.2.53
retrieving revision 1.6.2.54
diff -Ltemplates/document/default/en.html -Ltemplates/document/default/en.html -u -r1.6.2.53 -r1.6.2.54
--- templates/document/default/en.html
+++ templates/document/default/en.html
@@ -33,10 +33,13 @@
headlines_uri headlines/uri;
meta plugin: flo::plugin::DC;
meta_uri meta/uri;
+ comment plugin: flo::plugin::Comment;
+ comment_uri comment/uri;
children_id string:children;
Link_Loop self/components_list --link;
File_Loop self/components_list --file;
Body_Loop self/components_list --text --html --image --photo --file --poll --discussion --headlines --rss --timerange;
+ Comment_Loop self/components_list --comment;
"
petal:attributes="lang lang; xml:lang lang; dir dir"
xmlns:petal="http://purl.org/petal/1.0/"
@@ -92,6 +95,27 @@
Page Content Goes Here
</div>
</div>
+
+ <div
+ class="comments"
+ petal:condition="true: Comment_Loop"
+ >
+ <h2>Comments</h2>
+ <div
+ petal:repeat="component Comment_Loop"
+ petal:omit-tag=""
+ >
+ <div
+ petal:replace="structure component/as_xhtml"
+ >
+ Comments Go Here
+ </div>
+ </div>
+ </div>
+ <p
+ class="add-a-comment"
+ petal:condition="true: comment/would_activate"
+ >You may <a petal:attributes="href comment/uri" href="../../comment/en.html">add a comment</a> to this document.</p>
</div>
<!--? This is the next and previous menu. ?-->
Index: en.html
===================================================================
RCS file: /var/spool/cvs/mkd/templates/editor/box/Attic/en.html,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -Ltemplates/editor/box/en.html -Ltemplates/editor/box/en.html -u -r1.1.2.6 -r1.1.2.7
--- templates/editor/box/en.html
+++ templates/editor/box/en.html
@@ -180,6 +180,17 @@
>
<option
value="foo"
+ petal:condition="option/type/comment"
+ petal:attributes="value option/name"
+ >Comment</option>
+ </span>
+
+ <span
+ petal:omit-tag=""
+ petal:repeat="option option_list"
+ >
+ <option
+ value="foo"
petal:condition="option/type/poll"
petal:attributes="value option/name"
>User Poll</option>
@@ -210,6 +221,7 @@
false: option/type/link;
false: option/type/photo;
false: option/type/poll;
+ false: option/type/comment;
false: option/type/rss;
false: option/type/text;
false: option/type/timerange;"
Index: Httpd_Conf.pm
===================================================================
RCS file: /var/spool/cvs/mkd/MKDoc/Site/ConfigWriter/Httpd_Conf.pm,v
retrieving revision 1.1.2.40
retrieving revision 1.1.2.41
diff -LMKDoc/Site/ConfigWriter/Httpd_Conf.pm -LMKDoc/Site/ConfigWriter/Httpd_Conf.pm -u -r1.1.2.40 -r1.1.2.41
--- MKDoc/Site/ConfigWriter/Httpd_Conf.pm
+++ MKDoc/Site/ConfigWriter/Httpd_Conf.pm
@@ -259,7 +259,7 @@
AuthType Basic
require valid-user
</LocationMatch>
-<LocationMatch ^\/\.(account|admin|sitemap|print|headlines|meta|search)>
+<LocationMatch ^\/\.(comment|account|admin|sitemap|print|headlines|meta|search)>
PerlAuthenHandler MKDoc::Handler::Authenticate
PerlAuthzHandler MKDoc::Handler::GroupAuthz
AuthName "Please enter your user credentials"
Index: users.conf
===================================================================
RCS file: /var/spool/cvs/mkd/conf/Attic/users.conf,v
retrieving revision 1.1.2.41
retrieving revision 1.1.2.42
diff -Lconf/users.conf -Lconf/users.conf -u -r1.1.2.41 -r1.1.2.42
--- conf/users.conf
+++ conf/users.conf
@@ -15,6 +15,7 @@
flo::plugin::Print
flo::plugin::Poll
flo::plugin::Photo
+#flo::plugin::Comment
# metadata
flo::plugin::DC
--- /dev/null
+++ flo/editor/Comment.pm
@@ -0,0 +1,100 @@
+# -------------------------------------------------------------------------------------
+# flo::editor::Comment
+# -------------------------------------------------------------------------------------
+# Author : Bruno Postle
+# Copyright : (c) MKDoc Ltd, 2005
+#
+# 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::editor::Comment;
+
+=head1 NAME
+
+flo::editor::Comment - an editor for comments
+
+=head1 DESCRIPTION
+
+The module provides an editor for Comment components. A Comment component has
+information about the time and the poster as well as the comment text itself.
+
+By default, only a valid editor for a particular document can add, delete or
+modify Comment components, enable the L<flo::plugin::Comment> plugin to allow
+any user to append Comment components.
+
+=head1 INTERFACE
+
+=over 4
+
+This module is a simple subclass of the L<flo::editor::Text> module.
+
+=cut
+
+use strict;
+
+use flo::editor::Text;
+use base qw /flo::editor::Text/;
+
+=item C<< $self->as_xhtml() >>
+
+Renders the comment via petal. Essentially the same as the Text component
+except that external links are given an 'untrusted' rel="nofollow" attribute
+and the comment, date_posted, poster, email & login fields are available for
+the template designer.
+
+=cut
+
+sub as_xhtml
+{
+ my $self = shift;
+ my $data = $self->{'data'};
+ local $MKDoc::Text::Structured::Inline::NoFollow = 1;
+ $data = MKDoc::Text::Structured::process ($data);
+
+ my @newl = $self->links_for_tagger();
+ $self->{'comment'} = MKDoc::XML::Tagger::Preserve->process_data (['a'], $data, @newl);
+
+ my $type = $self->type();
+ my $template = new Petal (
+ file => "component/$type",
+ lang => $self->language(),
+ input => 'XML',
+ output => 'XHTML'
+ );
+
+ my $res = $template->process (self => $self);
+ Encode::_utf8_on ($res);
+
+ return $res;
+}
+
+sub _initialize
+{
+ my $self = shift;
+ my $cgi = $self->{cgi};
+ my $param_name = $self->{param_name};
+
+ if (defined $cgi)
+ {
+ $self->{date_posted} = $cgi->param ($param_name . "_date_posted") || flo::Standard::current_document()->now_iso();
+ $self->{poster} = $cgi->param ($param_name . "_poster") || flo::Standard::current_user()->real_name();
+ $self->{email} = $cgi->param ($param_name . "_email") || flo::Standard::current_user()->email();
+ $self->{login} = $cgi->param ($param_name . "_login") || flo::Standard::current_user()->login();
+ }
+}
+
+1;
--- /dev/null
+++ templates/editor/comment/en.html
@@ -0,0 +1,115 @@
+<!--?
+
+
+This template is used for the editor interface of a
+comment component.
+
+?-->
+<fieldset
+ class="comment-component"
+ xmlns:petal="http://purl.org/petal/1.0/"
+ petal:define="align self/align;
+ align_opposite self/align_opposite;
+ dir self/direction;
+ name_delete string:${self/block_name}_delete;
+ name_poster string:${self/block_name}_poster;
+ name_date_posted string:${self/block_name}_date_posted"
+>
+
+ <legend
+ xml:lang="en"
+ lang="en"
+ dir="ltr"
+ >Comment component</legend>
+
+ <?include file="/fragments/move_control/"?>
+
+ <p>
+ <a
+ petal:attributes="href string:mailto:${self/email}"
+ href="mailto:fred at example.com"
+ ><span petal:content="self/poster">Fred Flintstone</span></a>
+ (<span petal:content="self/login">fred</span>)
+ <span petal:content="self/date_posted">2005-08-02 12:23:45</span>
+ </p>
+ <p>
+ <em
+ class="help"
+ xml:lang="en"
+ lang="en"
+ dir="ltr"
+ >
+ You can enter plain text into this form, a blank line will result in a paragraph
+ break. See also the
+ <a href="http://www.mkdoc.org/docs/specs/structured-txt/">text formatting rules</a>.
+ Please use link components for hyperlinks.
+ </em>
+ <label
+ for="comment_id"
+ lang="en"
+ xml:lang="en"
+ dir="ltr"
+ petal:attributes="for self/block_name"
+ >Comment</label>
+ <br />
+ <textarea
+ name="comment"
+ id="comment"
+ rows="12"
+ cols="45"
+ title="Edit Comment here."
+ class="adminform"
+ petal:attributes="name self/block_name; id self/block_name"
+ petal:content="self/data"
+ >Plain text.</textarea>
+
+ <input
+ type="hidden"
+ name="date_posted"
+ id="date_posted"
+ value="2005-08-05 12:34:56"
+ petal:attributes="name name_date_posted; id name_date_posted; value self/date_posted"
+ />
+ <input
+ type="hidden"
+ name="poster"
+ id="poster"
+ value="Fred Flintstone"
+ petal:attributes="name name_poster; id name_poster; value self/poster"
+ />
+
+ </p>
+
+ <p>
+
+ <input
+ type="submit"
+ name="comment_delete"
+ id="comment_delete"
+ value="Delete Component"
+ xml:lang="en"
+ lang="en"
+ dir="ltr"
+ title="Delete this component."
+ petal:attributes="name name_delete; id name_delete"
+ />
+ |
+ <a
+ href="#"
+ xml:lang="en"
+ lang="en"
+ dir="ltr"
+ petal:attributes="href string:${self/mkdoc_uri},copy"
+ >Copy to another document</a>
+ |
+ <a
+ href="#"
+ xml:lang="en"
+ lang="en"
+ dir="ltr"
+ petal:attributes="href string:${self/mkdoc_uri},move"
+ >Move to another document</a>
+ </p>
+
+</fieldset>
+
More information about the MKDoc-commit
mailing list