Added Article wobject.

This commit is contained in:
JT Smith 2002-05-24 02:05:41 +00:00
parent d7b626f8a4
commit e83b7215bc
4 changed files with 439 additions and 521 deletions

View file

@ -60,7 +60,7 @@ insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, desc
delete from widget where namespace='DownloadManager';
alter table DownloadManager change widgetId wobjectId int not null;
alter table DownloadManager_file change widgetId wobjectId int not null;
delete from International where helpId=13 and namespace='DownloadManager';
delete from International where internationalId=13 and namespace='DownloadManager';
INSERT INTO international VALUES (22,'DownloadManager','English','Proceed to add download?');
insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, startDate, endDate) select widgetId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, dateAdded, 1336444487 from widget where namespace='MessageBoard';
@ -72,7 +72,35 @@ insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, desc
delete from widget where namespace='ExtraColumn';
alter table ExtraColumn change widgetId wobjectId int not null;
alter table wobject change description description mediumtext;
insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, startDate, endDate) select widget.widgetId, widget.pageId, widget.title, widget.displayTitle, widget.processMacros, Article.body, widget.dateAdded, widget.addedBy, widget.namespace, widget.lastEdited, widget.editedBy, widget.templatePosition, widget.sequenceNumber, Article.startDate, Article.endDate from widget,Article where widget.widgetId=Article.widgetId;
delete from widget where namespace='Article';
alter table Article change widgetId wobjectId int not null;
alter table Article drop column startDate;
alter table Article drop column endDate;
alter table Article drop column body;
delete from international where internationalId=2 and namespace='Article';
delete from international where internationalId=5 and namespace='Article';
update international set message='(Select \"Yes\" only if you aren\'t adding <br> manually.)' where internationalId='11' and namespace='Article' and language='English';
delete from international where internationalId=1 and namespace='MessageBoard';
delete from international where internationalId=1 and namespace='SiteMap';
delete from international where internationalId=2 and namespace='Article';
delete from international where internationalId=2 and namespace='ExtraColumn';
delete from international where internationalId=2 and namespace='Poll';
delete from international where internationalId=2 and namespace='SQLReport';
delete from international where internationalId=3 and namespace='EventsCalendar';
delete from international where internationalId=3 and namespace='FAQ';
delete from international where internationalId=3 and namespace='SyndicatedContent';
delete from international where internationalId=4 and namespace='FAQ';
delete from international where internationalId=7 and namespace='EventsCalendar';
delete from international where internationalId=7 and namespace='LinkList';
delete from international where internationalId=11 and namespace='LinkList';
delete from international where internationalId=11 and namespace='UserSubmission';
delete from international where internationalId=30 and namespace='UserSubmission';
delete from international where internationalId=2 and namespace='DownloadManager';
delete from international where internationalId=4 and namespace='DownloadManager';
delete from international where language='Svenska';
INSERT INTO international VALUES (367,'WebGUI','Svenska','Bäst före');

View file

@ -40,16 +40,17 @@ use WebGUI::Utility;
use WebGUI::Attachment;
$attachment = WebGUI::Attachment->new("file.txt","100","20");
$html = $attachment->box;
$string = $attachment->getFilename;
$url = $attachment->getIcon;
$string = $attachment->getPath;
$integer = $attachment->getSize;
$url = $attachment->getThumbnail;
$string = $attachment->getType;
$url = $attachment->getURL;
$attachment->copy("files","10");
$attachment->delete;
$attachment->deleteNode;
$attachment->getFilename;
$attachment->getIcon;
$attachment->getPath;
$attachment->getSize;
$attachment->getThumbnail;
$attachment->getType;
$attachment->getURL;
$attachment->rename("thisfile.txt");
$attachment->save("formImage");
@ -85,6 +86,26 @@ sub _createThumbnail {
}
#-------------------------------------------------------------------
=head2 box ( )
Displays the attachment in WebGUI's standard "Attachment Box".
=cut
sub box {
my ($output);
$output = '<p><table cellpadding=3 cellspacing=0 border=1><tr><td class="tableHeader">'.
'<a href="'.$_[0]->getURL.'"><img src="'.$session{setting}{lib}.
'/attachment.gif" border=0 alt="'.
$_[0]->getFilename.'"></a></td><td><a href="'.$_[0]->getURL.
'"><img src="'.$_[0]->getIcon.
'" align="middle" width="16" height="16" border="0" alt="'.$_[0]->getFilename
.'">'.$_[0]->getFilename.'</a></td></tr></table>';
return $output;
}
#-------------------------------------------------------------------
=head2 copy ( newNode [, newNodeSub ] )

View file

@ -1,513 +0,0 @@
package WebGUI::Widget::Article;
our $namespace = "Article";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# 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 strict;
use Tie::CPHash;
use WebGUI::Attachment;
use WebGUI::DateTime;
use WebGUI::Discussion;
use WebGUI::HTML;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::Shortcut;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub _showReplies {
my ($sth, @data, $html, %board);
tie %board, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
$html .= '<table border=0 cellpadding=2 cellspacing=1 width="100%">';
$html .= '<tr><td class="tableHeader">'.WebGUI::International::get(229).'</td><td class="tableHeader">'.WebGUI::International::get(22,$namespace).'</td><td class="tableHeader">'.WebGUI::International::get(23,$namespace).'</td></tr>';
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId from discussion where widgetId=$session{form}{wid} and pid=0 order by messageId desc");
while (@data = $sth->array) {
$data[1] = WebGUI::HTML::filter($data[1],'all');
$html .= '<tr';
if ($data[0] == $session{form}{mid}) {
$html .= ' class="highlight"';
}
$html .= '><td class="tableData"><a href="'.WebGUI::URL::page('func=showMessage&mid='.
$data[0].'&wid='.$session{form}{wid}).'">'.substr($data[1],0,30).
'</a></td><td class="tableData"><a href="'.
WebGUI::URL::page('op=viewProfile&uid='.$data[4]).'">'.$data[2].
'</a></td><td class="tableData">'.epochToHuman($data[3],"%M/%D %H:%n%p").
'</td></tr>';
$html .= WebGUI::Discussion::traverseReplyTree($data[0],1);
}
$html .= '</table>';
return $html;
}
#-------------------------------------------------------------------
sub duplicate {
my (%data, $newWidgetId, $pageId, $file);
tie %data, 'Tie::CPHash';
%data = getProperties($namespace,$_[0]);
$pageId = $_[1] || $data{pageId};
$newWidgetId = create($pageId,$namespace,$data{title},$data{displayTitle},
$data{description},$data{processMacros},$data{templatePosition});
$file = WebGUI::Attachment->new($data{image},$_[0]);
$file->copy($newWidgetId);
$file = WebGUI::Attachment->new($data{attachment},$_[0]);
$file->copy($newWidgetId);
WebGUI::SQL->write("insert into Article values ($newWidgetId, $data{startDate}, $data{endDate}, ".
quote($data{body}).", ".quote($data{image}).", ".quote($data{linkTitle}).", ".
quote($data{linkURL}).", ".quote($data{attachment}).", '$data{convertCarriageReturns}', ".
quote($data{alignImage}).", '$data{allowDiscussion}', $data{groupToPost}, $data{groupToModerate}, $data{editTimeout})");
WebGUI::Discussion::duplicate($_[0],$newWidgetId);
}
#-------------------------------------------------------------------
sub purge {
purgeWidget($_[0],$_[1],$namespace);
WebGUI::Discussion::purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return WebGUI::International::get(1,$namespace);
}
#-------------------------------------------------------------------
sub www_add {
my ($output, %hash, @array);
tie %hash, "Tie::IxHash";
if (WebGUI::Privilege::canEditPage()) {
$output = helpLink(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(2,$namespace).'</h1>';
$output .= formHeader();
$output .= WebGUI::Form::hidden("widget",$namespace);
$output .= WebGUI::Form::hidden("func","addSave");
$output .= '<table>';
$output .= tableFormRow(WebGUI::International::get(99),WebGUI::Form::text("title",20,128,'Article'));
$output .= tableFormRow(WebGUI::International::get(174),WebGUI::Form::checkbox("displayTitle",1,1));
$output .= tableFormRow(WebGUI::International::get(175),WebGUI::Form::checkbox("processMacros",1,1));
%hash = WebGUI::Widget::getPositions();
$output .= tableFormRow(WebGUI::International::get(363),WebGUI::Form::selectList("templatePosition",\%hash));
$output .= tableFormRow(WebGUI::International::get(3,$namespace),WebGUI::Form::text("startDate",20,30,epochToSet(time()),1));
$output .= tableFormRow(WebGUI::International::get(4,$namespace),WebGUI::Form::text("endDate",20,30,'01/01/2037',1));
$output .= tableFormRow(WebGUI::International::get(5,$namespace),WebGUI::Form::textArea("body",'',50,10,1));
$output .= tableFormRow(WebGUI::International::get(6,$namespace),WebGUI::Form::file("image"));
%hash = (
right => WebGUI::International::get(15,$namespace),
left => WebGUI::International::get(16,$namespace),
center => WebGUI::International::get(17,$namespace)
);
$array[0] = "right";
$output .= tableFormRow(WebGUI::International::get(14,$namespace),
WebGUI::Form::selectList("alignImage",\%hash,\@array));
$output .= tableFormRow(WebGUI::International::get(7,$namespace),WebGUI::Form::text("linkTitle",20,128));
$output .= tableFormRow(WebGUI::International::get(8,$namespace),WebGUI::Form::text("linkURL",20,2048));
$output .= tableFormRow(WebGUI::International::get(9,$namespace),WebGUI::Form::file("attachment"));
$output .= tableFormRow(WebGUI::International::get(10,$namespace),WebGUI::Form::checkbox("convertCarriageReturns",1).' <span style="font-size: 8pt;">'.WebGUI::International::get(11,$namespace).'</span>');
$output .= tableFormRow(WebGUI::International::get(18,$namespace),
WebGUI::Form::checkbox("allowDiscussion",1));
$output .= tableFormRow(WebGUI::International::get(19,$namespace),
WebGUI::Form::groupList("groupToPost",2));
$output .= tableFormRow(WebGUI::International::get(20,$namespace),
WebGUI::Form::groupList("groupToModerate",4));
$output .= tableFormRow(WebGUI::International::get(21,$namespace),
WebGUI::Form::text("editTimeout",20,3,1));
$output .= formSave();
$output .= '</table></form>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_addSave {
my ($widgetId, $image, $attachment);
if (WebGUI::Privilege::canEditPage()) {
$widgetId = create($session{page}{pageId},$session{form}{widget},
$session{form}{title},$session{form}{displayTitle},
$session{form}{description},$session{form}{processMacros},
$session{form}{templatePosition});
$image = WebGUI::Attachment->new("",$widgetId);
$image->save("image");
$attachment = WebGUI::Attachment->new("",$widgetId);
$attachment->save("attachment");
WebGUI::SQL->write("insert into Article values ($widgetId, '".
setToEpoch($session{form}{startDate})."', '".
setToEpoch($session{form}{endDate})."', ".
quote($session{form}{body}).", ".
quote($image->getFilename).", ".
quote($session{form}{linkTitle}).", ".
quote($session{form}{linkURL}).", ".
quote($attachment->getFilename).
", '$session{form}{convertCarriageReturns}', ".
quote($session{form}{alignImage}).", ".
"'$session{form}{allowDiscussion}', ".
"'$session{form}{groupToPost}', ".
"'$session{form}{groupToModerate}', ".
"'$session{form}{editTimeout}' ".
")");
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
duplicate($session{form}{wid});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteAttachment {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("update Article set attachment='' where widgetId=$session{form}{wid}");
return www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteImage {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("update Article set image='' where widgetId=$session{form}{wid}");
return www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteMessage {
my (%board, %message);
tie %board, 'Tie::CPHash';
tie %message, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
%message = WebGUI::Discussion::getMessage($session{form}{mid});
if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} ||
WebGUI::Privilege::isInGroup($board{groupToModerate})) {
return WebGUI::Discussion::deleteMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteMessageConfirm {
my (%board,%message);
tie %board, 'Tie::CPHash';
tie %message, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
%message = WebGUI::Discussion::getMessage($session{form}{mid});
if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} ||
WebGUI::Privilege::isInGroup($board{groupToModerate})) {
return WebGUI::Discussion::deleteMessageConfirm();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($output, %data, %hash, @array);
tie %hash, 'Tie::IxHash';
tie %data, 'Tie::CPHash';
if (WebGUI::Privilege::canEditPage()) {
%data = getProperties($namespace,$session{form}{wid});
$output = helpLink(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(12,$namespace).'</h1>';
$output .= formHeader();
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
$output .= WebGUI::Form::hidden("func","editSave");
$output .= '<table>';
$output .= tableFormRow(WebGUI::International::get(99),
WebGUI::Form::text("title",20,128,$data{title}));
$output .= tableFormRow(WebGUI::International::get(174),
WebGUI::Form::checkbox("displayTitle","1",$data{displayTitle}));
$output .= tableFormRow(WebGUI::International::get(175),
WebGUI::Form::checkbox("processMacros","1",$data{processMacros}));
%hash = WebGUI::Widget::getPositions();
$array[0] = $data{templatePosition};
$output .= tableFormRow(WebGUI::International::get(363),
WebGUI::Form::selectList("templatePosition",\%hash,\@array));
$output .= tableFormRow(WebGUI::International::get(3,$namespace),
WebGUI::Form::text("startDate",20,30,epochToSet($data{startDate}),1));
$output .= tableFormRow(WebGUI::International::get(4,$namespace),
WebGUI::Form::text("endDate",20,30,epochToSet($data{endDate}),1));
$output .= tableFormRow(WebGUI::International::get(5,$namespace),
WebGUI::Form::textArea("body",$data{body},50,10,1));
if ($data{image} ne "") {
$output .= tableFormRow(WebGUI::International::get(6,$namespace),'<a href="'.
WebGUI::URL::page('func=deleteImage&wid='.$session{form}{wid})
.'">'.WebGUI::International::get(13,$namespace).'</a>');
} else {
$output .= tableFormRow(WebGUI::International::get(6,$namespace),WebGUI::Form::file("image"));
}
%hash = (
right => WebGUI::International::get(15,$namespace),
left => WebGUI::International::get(16,$namespace),
center => WebGUI::International::get(17,$namespace)
);
$array[0] = $data{alignImage};
$output .= tableFormRow(WebGUI::International::get(14,$namespace),
WebGUI::Form::selectList("alignImage",\%hash,\@array));
$output .= tableFormRow(WebGUI::International::get(7,$namespace),
WebGUI::Form::text("linkTitle",20,128,$data{linkTitle}));
$output .= tableFormRow(WebGUI::International::get(8,$namespace),
WebGUI::Form::text("linkURL",20,2048,$data{linkURL}));
if ($data{attachment} ne "") {
$output .= tableFormRow(WebGUI::International::get(9,$namespace),'<a href="'.
WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid})
.'">'.WebGUI::International::get(13,$namespace).'</a>');
} else {
$output .= tableFormRow(WebGUI::International::get(9,$namespace),
WebGUI::Form::file("attachment"));
}
$output .= tableFormRow(WebGUI::International::get(10,$namespace),
WebGUI::Form::checkbox("convertCarriageReturns",1,$data{convertCarriageReturns}).
' <span style="font-size: 8pt;">'.WebGUI::International::get(11,$namespace).'</span>');
$output .= tableFormRow(WebGUI::International::get(18,$namespace),
WebGUI::Form::checkbox("allowDiscussion","1",$data{allowDiscussion}));
$output .= tableFormRow(WebGUI::International::get(19,$namespace),
WebGUI::Form::groupList("groupToPost",$data{groupToPost}));
$output .= tableFormRow(WebGUI::International::get(20,$namespace),
WebGUI::Form::groupList("groupToModerate",$data{groupToModerate}));
$output .= tableFormRow(WebGUI::International::get(22,$namespace),
WebGUI::Form::text("editTimeout",20,2,$data{editTimeout}));
$output .= formSave();
$output .= '</table></form>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
my ($sqlAdd, $image, $attachment);
if (WebGUI::Privilege::canEditPage()) {
update();
$image = WebGUI::Attachment->new("",$session{form}{wid});
$image->save("image");
if ($image->getFilename ne "") {
$sqlAdd = ', image='.quote($image->getFilename);
}
$attachment = WebGUI::Attachment->new("",$session{form}{wid});
$attachment->save("attachment");
if ($attachment->getFilename ne "") {
$sqlAdd .= ', attachment='.quote($attachment->getFilename);
}
WebGUI::SQL->write("update Article set alignImage=".quote($session{form}{alignImage}).
", startDate='".setToEpoch($session{form}{startDate}).
"', endDate='".setToEpoch($session{form}{endDate}).
"', convertCarriageReturns='$session{form}{convertCarriageReturns}', body=".
quote($session{form}{body}).", linkTitle=".
quote($session{form}{linkTitle}).", linkURL=".
quote($session{form}{linkURL}).", allowDiscussion='$session{form}{allowDiscussion}',".
"groupToModerate='$session{form}{groupToModerate}', groupToPost='$session{form}{groupToPost}'".
", editTimeout='$session{form}{editTimeout}'".
$sqlAdd.
" where widgetId=$session{form}{wid}");
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editMessage {
my (%board,%message);
tie %board, 'Tie::CPHash';
tie %message, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
%message = WebGUI::Discussion::getMessage($session{form}{mid});
if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} ||
WebGUI::Privilege::isInGroup($board{groupToModerate})) {
return WebGUI::Discussion::editMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editMessageSave {
my (%board,%message);
tie %board, 'Tie::CPHash';
tie %message, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
%message = WebGUI::Discussion::getMessage($session{form}{mid});
if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} ||
WebGUI::Privilege::isInGroup($board{groupToModerate})) {
WebGUI::Discussion::editMessageSave();
return www_showMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postNewMessage {
my (%board);
tie %board, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) {
return WebGUI::Discussion::postNewMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postNewMessageSave {
my (%board);
tie %board, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) {
return WebGUI::Discussion::postNewMessageSave();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postReply {
my (%board);
tie %board, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) {
return WebGUI::Discussion::postReply();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postReplySave {
my (%board);
tie %board, 'Tie::CPHash';
%board = getProperties($namespace,$session{form}{wid});
if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) {
WebGUI::Discussion::postReplySave();
return www_showMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_showMessage {
my (@data, $html, %board, %message, $defaultMid);
tie %message, 'Tie::CPHash';
tie %board, 'Tie::CPHash';
($defaultMid) = WebGUI::SQL->quickArray("select min(messageId) from discussion where widgetId=$session{form}{wid}");
$session{form}{mid} = $defaultMid if ($session{form}{mid} eq "");
%message = WebGUI::Discussion::getMessage($session{form}{mid});
%board = getProperties($namespace,$session{form}{wid});
if ($message{messageId}) {
$html .= '<h1>'.$message{subject}.'</h1>';
$html .= '<table width="100%" cellpadding=3 cellspacing=1 border=0><tr><td class="tableHeader">';
$html .= '<b>'.WebGUI::International::get(22,$namespace).'</b> <a href="'.
WebGUI::URL::page('op=viewProfile&uid='.$message{userId}).'">'.$message{username}.'</a><br>';
$html .= "<b>".WebGUI::International::get(23,$namespace)."</b> ".
epochToHuman($message{dateOfPost},"%w, %c %D, %y at %H:%n%p")."<br>";
$html .= '</td>';
$html .= '<td rowspan=2 valign="top" class="tableMenu" nowrap>';
$html .= '<a href="'.WebGUI::URL::page('func=postReply&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid})
.'">'.WebGUI::International::get(24,$namespace).'</a><br>';
if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} &&
$message{userId} eq $session{user}{userId} ||
WebGUI::Privilege::isInGroup($board{groupToModerate})) {
$html .= '<a href="'.WebGUI::URL::page('func=editMessage&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid}).'">'.WebGUI::International::get(25,$namespace).'</a><br>';
$html .= '<a href="'.WebGUI::URL::page('func=deleteMessage&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid}).'">'.WebGUI::International::get(26,$namespace).'</a><br>';
}
$html .= '<a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(27,$namespace).'</a><br>';
$html .= '</tr><tr><td class="tableData">';
$html .= $message{message};
$html .= '</td></tr></table>';
$html .= _showReplies();
} else {
$html = WebGUI::International::get(402);
}
return $html;
}
#-------------------------------------------------------------------
sub www_view {
my (%data, @test, $output, $image, $replies);
tie %data, 'Tie::CPHash';
%data = getProperties($namespace,$_[0]);
if ($data{startDate}<time() && $data{endDate}>time()) {
$output = "";
if ($data{image} ne "") { # Images collide on successive articles if there is little text - prevent this.
$output .= '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>';
}
if ($data{displayTitle} == 1) {
$output .= "<h1>".$data{title}."</h1>";
}
if ($data{image} ne "") {
$image = WebGUI::Attachment->new($data{image},$_[0]);
$image = '<img src="'.$image->getURL.'"';
if ($data{alignImage} ne "center") {
$image .= ' align="'.$data{alignImage}.'"';
}
$image .= ' border="0">';
if ($data{alignImage} eq "center") {
$output .= '<div align="center">'.$image.'</div>';
} else {
$output .= $image;
}
}
if ($data{convertCarriageReturns}) {
$data{body} =~ s/\n/\<br\>/g;
}
$output .= $data{body};
if ($data{linkURL} ne "" && $data{linkTitle} ne "") {
$output .= '<p><a href="'.$data{linkURL}.'">'.$data{linkTitle}.'</a>';
}
if ($data{attachment} ne "") {
$output .= attachmentBox($data{attachment},$_[0]);
}
if ($data{image} ne "") {
$output .= "</td></tr></table>";
}
}
if ($data{processMacros}) {
$output = WebGUI::Macro::process($output);
}
if ($data{allowDiscussion}) {
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where widgetId=$_[0]");
$output .= '<p><table width="100%" cellspacing="2" cellpadding="1" border="0">';
$output .= '<tr><td align="center" width="50%" class="tableMenu"><a href="'.
WebGUI::URL::page('func=showMessage&wid='.$_[0]).'">'.
WebGUI::International::get(28,$namespace).' ('.$replies.')</a></td>';
$output .= '<td align="center" width="50%" class="tableMenu"><a href="'.
WebGUI::URL::page('func=postNewMessage&wid='.$_[0]).'">'.
WebGUI::International::get(24,$namespace).'</a></td></tr>';
$output .= '</table>';
}
return $output;
}
1;

View file

@ -0,0 +1,382 @@
package WebGUI::Wobject::Article;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# 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 strict;
use Tie::CPHash;
use WebGUI::Attachment;
use WebGUI::DateTime;
use WebGUI::Discussion;
use WebGUI::HTML;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
our $namespace = "Article";
our $name = WebGUI::International::get(1,$namespace);
#-------------------------------------------------------------------
sub _canEditMessage {
my (%message);
tie %message, 'Tie::CPHash';
%message = WebGUI::Discussion::getMessage($_[1]);
if (
(time()-$message{dateOfPost}) < 3600*$_[0]->get("editTimeout")
&& $message{userId} eq $session{user}{userId}
|| WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate"))
) {
return 1;
} else {
return 0;
}
}
#-------------------------------------------------------------------
sub _showReplies {
my ($sth, @data, $html);
$html .= '<table border=0 cellpadding=2 cellspacing=1 width="100%">';
$html .= '<tr><td class="tableHeader">'.WebGUI::International::get(229).'</td><td class="tableHeader">'.WebGUI::International::get(22,$namespace).'</td><td class="tableHeader">'.WebGUI::International::get(23,$namespace).'</td></tr>';
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId from discussion where wobjectId=$session{form}{wid} and pid=0 order by messageId desc");
while (@data = $sth->array) {
$data[1] = WebGUI::HTML::filter($data[1],'all');
$html .= '<tr';
if ($data[0] == $session{form}{mid}) {
$html .= ' class="highlight"';
}
$html .= '><td class="tableData"><a href="'.WebGUI::URL::page('func=showMessage&mid='.
$data[0].'&wid='.$session{form}{wid}).'">'.substr($data[1],0,30).
'</a></td><td class="tableData"><a href="'.
WebGUI::URL::page('op=viewProfile&uid='.$data[4]).'">'.$data[2].
'</a></td><td class="tableData">'.epochToHuman($data[3],"%M/%D %H:%n%p").
'</td></tr>';
$html .= WebGUI::Discussion::traverseReplyTree($data[0],1);
}
$html .= '</table>';
return $html;
}
#-------------------------------------------------------------------
sub duplicate {
my ($file, $w);
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::Article->new({wobjectId=>$w,namespace=>$namespace});
$file = WebGUI::Attachment->new($_[0]->get("image"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$w->set({
image=>$_[0]->get("image"),
linkTitle=>$_[0]->get("linkTitle"),
linkURL=>$_[0]->get("linkURL"),
attachment=>$_[0]->get("attachment"),
convertCarriageReturns=>$_[0]->get("convertCarriageReturns"),
alignImage=>$_[0]->get("alignImage"),
allowDiscussion=>$_[0]->get("allowDiscussion"),
groupToPost=>$_[0]->get("groupToPost"),
groupToModerate=>$_[0]->get("groupToModerate"),
editTimeout=>$_[0]->get("editTimeout")
});
WebGUI::Discussion::duplicate($_[0]->get("wobjectId"),$w->get("wobjectId"));
}
#-------------------------------------------------------------------
sub new {
my ($self, $class, $property);
$class = shift;
$property = shift;
$self = WebGUI::Wobject->new($property);
bless $self, $class;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::Discussion::purge($_[0]->get("wobjectId"));
$_[0]->SUPER::purge();
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],
[qw(image linkTitle linkURL attachment convertCarriageReturns alignImage allowDiscussion groupToPost groupToModerate editTimeout)]);
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->duplicate;
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteAttachment {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({attachment=>''});
return $_[0]->www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteImage {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({image=>''});
return $_[0]->www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteMessage {
if (_canEditMessage($_[0],$session{form}{mid})) {
return WebGUI::Discussion::deleteMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteMessageConfirm {
if (_canEditMessage($_[0],$session{form}{mid})) {
return WebGUI::Discussion::deleteMessageConfirm();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($output, $editTimeout, $groupToModerate, %hash, $f);
tie %hash, 'Tie::IxHash';
if (WebGUI::Privilege::canEditPage()) {
if ($_[0]->get("wobjectId") eq "new") {
$editTimeout = 1;
} else {
$editTimeout = $_[0]->get("editTimeout");
}
$groupToModerate = $_[0]->get("groupToModerate") || 4;
$output = helpIcon(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(12,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
if ($_[0]->get("image") ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteImage&wid='.$session{form}{wid}).'">'.
WebGUI::International::get(391).'</a>',WebGUI::International::get(6,$namespace));
} else {
$f->file("image",WebGUI::International::get(6,$namespace));
}
%hash = (
right => WebGUI::International::get(15,$namespace),
left => WebGUI::International::get(16,$namespace),
center => WebGUI::International::get(17,$namespace)
);
$f->select("alignImage",\%hash,WebGUI::International::get(14,$namespace),[$_[0]->get("alignImage")]);
if ($_[0]->get("attachment") ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid}).'">'.
WebGUI::International::get(391).'</a>',WebGUI::International::get(9,$namespace));
} else {
$f->file("attachment",WebGUI::International::get(9,$namespace));
}
$f->text("linkTitle",WebGUI::International::get(7,$namespace),$_[0]->get("linkTitle"));
$f->url("linkURL",WebGUI::International::get(8,$namespace),$_[0]->get("linkURL"));
$f->yesNo("convertCarriageReturns",WebGUI::International::get(10,$namespace),$_[0]->get("convertCarriageReturns")
,'',' &nbsp; <span style="font-size: 8pt;">'.WebGUI::International::get(11,$namespace).'</span>');
$f->yesNo("allowDiscussion",WebGUI::International::get(18,$namespace),$_[0]->get("allowDiscussion"));
$f->group("groupToPost",WebGUI::International::get(19,$namespace),[$_[0]->get("groupToPost")]);
$f->group("groupToModerate",WebGUI::International::get(20,$namespace),[$groupToModerate]);
$f->integer("editTimeout",WebGUI::International::get(21,$namespace),$editTimeout);
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
my ($image, $attachment, %property);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->SUPER::www_editSave();
$image = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$image->save("image");
$attachment = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$attachment->save("attachment");
$property{image} = $image->getFilename if ($image->getFilename ne "");
$property{attachment} = $attachment->getFilename if ($attachment->getFilename ne "");
$property{alignImage} = $session{form}{alignImage};
$property{convertCarriageReturns} = $session{form}{convertCarriageReturns};
$property{linkTitle} = $session{form}{linkTitle};
$property{linkURL} = $session{form}{linkURL};
$property{allowDiscussion} = $session{form}{allowDiscussion};
$property{groupToModerate} = $session{form}{groupToModerate};
$property{groupToPost} = $session{form}{groupToPost};
$property{editTimeout} = $session{form}{editTimeout};
$_[0]->set(\%property);
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editMessage {
if (_canEditMessage($_[0],$session{form}{mid})) {
return WebGUI::Discussion::editMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editMessageSave {
if (_canEditMessage($_[0],$session{form}{mid})) {
WebGUI::Discussion::editMessageSave();
return $_[0]->www_showMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postNewMessage {
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) {
return WebGUI::Discussion::postNewMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postNewMessageSave {
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) {
return WebGUI::Discussion::postNewMessageSave();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postReply {
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) {
return WebGUI::Discussion::postReply();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_postReplySave {
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) {
WebGUI::Discussion::postReplySave();
return $_[0]->www_showMessage();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_showMessage {
my (@data, $html, %message, $defaultMid);
tie %message, 'Tie::CPHash';
($defaultMid) = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$session{form}{wid}");
$session{form}{mid} = $defaultMid if ($session{form}{mid} eq "");
%message = WebGUI::Discussion::getMessage($session{form}{mid});
if ($message{messageId}) {
$html .= '<h1>'.$message{subject}.'</h1>';
$html .= '<table width="100%" cellpadding=3 cellspacing=1 border=0><tr><td class="tableHeader">';
$html .= '<b>'.WebGUI::International::get(22,$namespace).'</b> <a href="'.
WebGUI::URL::page('op=viewProfile&uid='.$message{userId}).'">'.$message{username}.'</a><br>';
$html .= "<b>".WebGUI::International::get(23,$namespace)."</b> ".
epochToHuman($message{dateOfPost},"%z %Z")."<br>";
$html .= '</td>';
$html .= '<td rowspan=2 valign="top" class="tableMenu" nowrap>';
$html .= '<a href="'.WebGUI::URL::page('func=postReply&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid})
.'">'.WebGUI::International::get(24,$namespace).'</a><br>';
if (_canEditMessage($_[0],$session{form}{mid})) {
$html .= '<a href="'.WebGUI::URL::page('func=editMessage&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid}).'">'.WebGUI::International::get(25,$namespace).'</a><br>';
$html .= '<a href="'.WebGUI::URL::page('func=deleteMessage&mid='.$session{form}{mid}.
'&wid='.$session{form}{wid}).'">'.WebGUI::International::get(26,$namespace).'</a><br>';
}
$html .= '<a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(27,$namespace).'</a><br>';
$html .= '</tr><tr><td class="tableData">';
$html .= $message{message};
$html .= '</td></tr></table>';
$html .= _showReplies();
} else {
$html = WebGUI::International::get(402);
}
return $html;
}
#-------------------------------------------------------------------
sub www_view {
my ($file, $output, $image, $replies, $body);
if ($_[0]->get("image") ne "") { # Images collide on successive articles if there is little text - prevent this.
$output = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>';
}
$output .= $_[0]->displayTitle;
if ($_[0]->get("image") ne "") {
$image = WebGUI::Attachment->new($_[0]->get("image"),$_[0]->get("wobjectId"));
$image = '<img src="'.$image->getURL.'"';
if ($_[0]->get("alignImage") ne "center") {
$image .= ' align="'.$_[0]->get("alignImage").'"';
}
$image .= ' border="0">';
if ($_[0]->get("alignImage") eq "center") {
$output .= '<div align="center">'.$image.'</div>';
} else {
$output .= $image;
}
}
$body = $_[0]->description;
if ($_[0]->get("convertCarriageReturns")) {
$body =~ s/\n/\<br\>/g;
}
$output .= $body;
if ($_[0]->get("linkURL") ne "" && $_[0]->get("linkTitle") ne "") {
$output .= '<p><a href="'.$_[0]->get("linkURL").'">'.$_[0]->get("linkTitle").'</a>';
}
if ($_[0]->get("attachment") ne "") {
$file = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
$output .= $file->box;
}
if ($_[0]->get("image") ne "") {
$output .= "</td></tr></table>";
}
$output = $_[0]->processMacros($output);
if ($_[0]->get("allowDiscussion")) {
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where wobjectId=".$_[0]->get("wobjectId"));
$output .= '<p><table width="100%" cellspacing="2" cellpadding="1" border="0">';
$output .= '<tr><td align="center" width="50%" class="tableMenu"><a href="'.
WebGUI::URL::page('func=showMessage&wid='.$_[0]->get("wobjectId")).'">'.
WebGUI::International::get(28,$namespace).' ('.$replies.')</a></td>';
$output .= '<td align="center" width="50%" class="tableMenu"><a href="'.
WebGUI::URL::page('func=postNewMessage&wid='.$_[0]->get("wobjectId")).'">'.
WebGUI::International::get(24,$namespace).'</a></td></tr>';
$output .= '</table>';
}
return $output;
}
1;