diff --git a/docs/upgrades/upgrade_3.7.0-3.8.0.sql b/docs/upgrades/upgrade_3.7.0-3.8.0.sql index 89bb3178c..e5f090f9f 100644 --- a/docs/upgrades/upgrade_3.7.0-3.8.0.sql +++ b/docs/upgrades/upgrade_3.7.0-3.8.0.sql @@ -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'); diff --git a/lib/WebGUI/Attachment.pm b/lib/WebGUI/Attachment.pm index 8febd4b9f..2dbd9ba3d 100644 --- a/lib/WebGUI/Attachment.pm +++ b/lib/WebGUI/Attachment.pm @@ -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 = '

'. + ''.
+                $_[0]->getFilename.''.$_[0]->getFilename
+                .''.$_[0]->getFilename.'
'; + return $output; +} + #------------------------------------------------------------------- =head2 copy ( newNode [, newNodeSub ] ) diff --git a/lib/WebGUI/Widget/Article.pm b/lib/WebGUI/Widget/Article.pm deleted file mode 100644 index 66dd0c3e5..000000000 --- a/lib/WebGUI/Widget/Article.pm +++ /dev/null @@ -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 .= ''; - $html .= ''; - $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 .= ''.substr($data[1],0,30). - ''; - $html .= WebGUI::Discussion::traverseReplyTree($data[0],1); - } - $html .= '
'.WebGUI::International::get(229).''.WebGUI::International::get(22,$namespace).''.WebGUI::International::get(23,$namespace).'
'.$data[2]. - ''.epochToHuman($data[3],"%M/%D %H:%n%p"). - '
'; - 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 .= '

'.WebGUI::International::get(2,$namespace).'

'; - $output .= formHeader(); - $output .= WebGUI::Form::hidden("widget",$namespace); - $output .= WebGUI::Form::hidden("func","addSave"); - $output .= ''; - $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).' '.WebGUI::International::get(11,$namespace).''); - $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 .= '
'; - 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 .= '

'.WebGUI::International::get(12,$namespace).'

'; - $output .= formHeader(); - $output .= WebGUI::Form::hidden("wid",$session{form}{wid}); - $output .= WebGUI::Form::hidden("func","editSave"); - $output .= ''; - $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),''.WebGUI::International::get(13,$namespace).''); - } 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),''.WebGUI::International::get(13,$namespace).''); - } 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}). - ' '.WebGUI::International::get(11,$namespace).''); - $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 .= '
'; - 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 .= '

'.$message{subject}.'

'; - $html .= ''; - $html .= '
'; - $html .= ''.WebGUI::International::get(22,$namespace).' '.$message{username}.'
'; - $html .= "".WebGUI::International::get(23,$namespace)." ". - epochToHuman($message{dateOfPost},"%w, %c %D, %y at %H:%n%p")."
"; - $html .= '
'; - $html .= ''.WebGUI::International::get(24,$namespace).'
'; - if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && - $message{userId} eq $session{user}{userId} || - WebGUI::Privilege::isInGroup($board{groupToModerate})) { - $html .= ''.WebGUI::International::get(25,$namespace).'
'; - $html .= ''.WebGUI::International::get(26,$namespace).'
'; - } - $html .= ''.WebGUI::International::get(27,$namespace).'
'; - $html .= '
'; - $html .= $message{message}; - $html .= '
'; - $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()) { - $output = ""; - if ($data{image} ne "") { # Images collide on successive articles if there is little text - prevent this. - $output .= '
'; - } - if ($data{displayTitle} == 1) { - $output .= "

".$data{title}."

"; - } - if ($data{image} ne "") { - $image = WebGUI::Attachment->new($data{image},$_[0]); - $image = ''; - } else { - $output .= $image; - } - } - if ($data{convertCarriageReturns}) { - $data{body} =~ s/\n/\/g; - } - $output .= $data{body}; - if ($data{linkURL} ne "" && $data{linkTitle} ne "") { - $output .= '

'.$data{linkTitle}.''; - } - if ($data{attachment} ne "") { - $output .= attachmentBox($data{attachment},$_[0]); - } - if ($data{image} ne "") { - $output .= "

"; - } - } - if ($data{processMacros}) { - $output = WebGUI::Macro::process($output); - } - if ($data{allowDiscussion}) { - ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where widgetId=$_[0]"); - $output .= '

'; - $output .= ''; - $output .= ''; - $output .= '
'. - WebGUI::International::get(28,$namespace).' ('.$replies.')'. - WebGUI::International::get(24,$namespace).'
'; - } - return $output; -} - -1; - diff --git a/lib/WebGUI/Wobject/Article.pm b/lib/WebGUI/Wobject/Article.pm new file mode 100644 index 000000000..cfec1c1e3 --- /dev/null +++ b/lib/WebGUI/Wobject/Article.pm @@ -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 .= ''; + $html .= ''; + $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 .= ''.substr($data[1],0,30). + ''; + $html .= WebGUI::Discussion::traverseReplyTree($data[0],1); + } + $html .= '
'.WebGUI::International::get(229).''.WebGUI::International::get(22,$namespace).''.WebGUI::International::get(23,$namespace).'
'.$data[2]. + ''.epochToHuman($data[3],"%M/%D %H:%n%p"). + '
'; + 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 .= '

'.WebGUI::International::get(12,$namespace).'

'; + $f = WebGUI::HTMLForm->new; + if ($_[0]->get("image") ne "") { + $f->readOnly(''. + WebGUI::International::get(391).'',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(''. + WebGUI::International::get(391).'',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") + ,'','   '.WebGUI::International::get(11,$namespace).''); + $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 .= '

'.$message{subject}.'

'; + $html .= ''; + $html .= '
'; + $html .= ''.WebGUI::International::get(22,$namespace).' '.$message{username}.'
'; + $html .= "".WebGUI::International::get(23,$namespace)." ". + epochToHuman($message{dateOfPost},"%z %Z")."
"; + $html .= '
'; + $html .= ''.WebGUI::International::get(24,$namespace).'
'; + if (_canEditMessage($_[0],$session{form}{mid})) { + $html .= ''.WebGUI::International::get(25,$namespace).'
'; + $html .= ''.WebGUI::International::get(26,$namespace).'
'; + } + $html .= ''.WebGUI::International::get(27,$namespace).'
'; + $html .= '
'; + $html .= $message{message}; + $html .= '
'; + $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 = '
'; + } + $output .= $_[0]->displayTitle; + if ($_[0]->get("image") ne "") { + $image = WebGUI::Attachment->new($_[0]->get("image"),$_[0]->get("wobjectId")); + $image = 'get("alignImage") ne "center") { + $image .= ' align="'.$_[0]->get("alignImage").'"'; + } + $image .= ' border="0">'; + if ($_[0]->get("alignImage") eq "center") { + $output .= '
'.$image.'
'; + } else { + $output .= $image; + } + } + $body = $_[0]->description; + if ($_[0]->get("convertCarriageReturns")) { + $body =~ s/\n/\/g; + } + $output .= $body; + if ($_[0]->get("linkURL") ne "" && $_[0]->get("linkTitle") ne "") { + $output .= '

'.$_[0]->get("linkTitle").''; + } + if ($_[0]->get("attachment") ne "") { + $file = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId")); + $output .= $file->box; + } + if ($_[0]->get("image") ne "") { + $output .= "

"; + } + $output = $_[0]->processMacros($output); + if ($_[0]->get("allowDiscussion")) { + ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where wobjectId=".$_[0]->get("wobjectId")); + $output .= '

'; + $output .= ''; + $output .= ''; + $output .= '
'. + WebGUI::International::get(28,$namespace).' ('.$replies.')'. + WebGUI::International::get(24,$namespace).'
'; + } + return $output; +} + +1; +