# Copyright (c) 2007 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Blog.pm,v 1.25 2012/01/12 21:20:17 andrews Exp $ package Bivio::UI::View::Blog; use strict; use Bivio::Base 'View.Base'; use Bivio::UI::ViewLanguageAUTOLOAD; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.25 $ =~ /\d+/g); my($_C) = b_use('IO.Config'); my($_FP) = b_use('Type.FilePath'); sub TEXT_AREA_COLS { return 80; } sub TEXT_AREA_ROWS { return 30; } sub edit { my($self) = @_; return shift->edit_wysiwyg(@_) if b_use('View.Wiki')->use_wysiwyg; return $self->internal_body(vs_simple_form(BlogEditForm => [ ['BlogEditForm.title', { size => 57, }], 'BlogEditForm.RealmFile.is_public', _edit($self, 'BlogEditForm', {editor => \&TextArea}), ])); } sub edit_wysiwyg { my($self) = @_; return $self->internal_body(vs_simple_form(BlogEditForm => [ ['BlogEditForm.title', { size => 57, }], 'BlogEditForm.RealmFile.is_public', _edit($self, 'BlogEditForm', {editor => \&CKEditor}), ])); } sub create { my($self) = @_; return shift->create_wysiwyg(@_) if b_use('View.Wiki')->use_wysiwyg; return $self->internal_body(vs_simple_form(BlogCreateForm => [ 'BlogCreateForm.title', 'BlogCreateForm.RealmFile.is_public', _edit($self, 'BlogCreateForm', {editor => \&TextArea}), ])); } sub create_wysiwyg { my($self) = @_; return $self->internal_body(vs_simple_form(BlogCreateForm => [ 'BlogCreateForm.title', 'BlogCreateForm.RealmFile.is_public', _edit($self, 'BlogCreateForm', {editor => \&CKEditor}), ])); } sub detail { return shift->internal_put_base_attr( menu => Join([ DIV_heading('Recent Entries'), UL(List('BlogRecentList', [ LI(vs_link(['title'], URI({ task_id => _access_mode('FORUM_BLOG_DETAIL'), path_info => ['path_info'], }))), ])), ]), topic => String([qw(Model.BlogList title)]), byline => Join([ 'posted on ', DateTime([qw(Model.BlogList ->get_creation_date_time)]), ' (', 'last edited by ', MailTo( [qw(Model.BlogList Email.email)], [qw(Model.BlogList RealmOwner.display_name)], ), ' on ', DateTime(['Model.BlogList', 'RealmFile.modified_date_time']), ')', ]), tools => TaskMenu([ { task_id => 'FORUM_BLOG_EDIT', path_info => [qw(Model.BlogList path_info)], }, 'FORUM_BLOG_CREATE', ]), body => vs_paged_detail( 'BlogList', [THIS_LIST => _access_mode('FORUM_BLOG_LIST')], #TODO: Replace with proper blog widget that *partially* reuses wiki markup DIV_blog( DIV(DIV_text(['Model.BlogList', '->render_html', undef, 'FORUM_WIKI_VIEW']), #TODO: multiple classes {class => If( ['Model.BlogList', 'RealmFile.is_public'], 'public', 'private')}, )), ), ); } sub list { return shift->internal_put_base_attr( #TODO: Fix this rss_task => _access_mode('FORUM_BLOG_RSS'), tools => TaskMenu(['FORUM_BLOG_CREATE']), menu => Join([ #TODO: Move to FacadeBase DIV_heading('Recent Entries'), UL(List('BlogRecentList', [ LI(vs_link(['title'], URI({ task_id => _access_mode('FORUM_BLOG_DETAIL'), path_info => ['path_info'], }))), ])), ]), body => DIV_blog(Join([ DIV_list(vs_paged_list(BlogList => List(BlogList => [ DIV(Join([ DIV_heading(Join([ vs_link(['title'], URI({ task_id => _access_mode('FORUM_BLOG_DETAIL'), path_info => ['path_info'], })), ])), DIV_text(Join([ DIV_excerpt(String(['->get_rss_summary'])), ' ... ', Link('[more]', URI({ task_id => _access_mode('FORUM_BLOG_DETAIL'), path_info => ['path_info'], }), 'more'), ])), DIV_menu(Link(vs_text('title.FORUM_BLOG_EDIT'), URI({ task_id => 'FORUM_BLOG_EDIT', path_info => ['path_info'], }), { control => Bivio::Agent::TaskId->FORUM_BLOG_EDIT, })), ]), {class => If(['RealmFile.is_public'], 'public', 'private')}, ), ]))), ]))); } sub list_rss { return shift->internal_body(AtomFeed('BlogList')); } sub _access_mode { my($task) = @_; return $_C->if_version(3, $task, sub { (my $p = $task) =~ s/(?<=^FORUM_)/PUBLIC_/; return [ sub { my($source, $private, $public) = @_; shift->req('Type.AccessMode')->eq_private ? $private : $public; }, $task, $p, ]; }, ); } sub _edit { my($self, $form, $options) = @_; return Join([ FormFieldError({ field => 'body', label => 'text', }), $options->{editor}->({ field => 'body', rows => $self->TEXT_AREA_ROWS, cols => $self->TEXT_AREA_COLS, %{b_use('View.Wiki')->get_image_folders}, use_public_image_folder => ["Model.$form", 'RealmFile.is_public'], }), ], { cell_class => 'blog_textarea', }); } 1;