Templatized the message board.
This commit is contained in:
parent
618f193482
commit
ee750a0471
2 changed files with 66 additions and 78 deletions
|
|
@ -962,3 +962,9 @@ insert into international (internationalId,languageId,namespace,message,lastUpda
|
|||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (818,1,'WebGUI','Deactivated', 1038431300);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (817,1,'WebGUI','Active', 1038431287);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (816,1,'WebGUI','Status', 1038431169);
|
||||
alter table MessageBoard add column templateId int not null default 1;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (72,1,'MessageBoard','Main Template', 1038678090);
|
||||
INSERT INTO template VALUES (1,'Default Message Board','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p/>\r\n</tmpl_if>\r\n\r\n<table width=\"100%\" cellpadding=2 cellspacing=1 border=0>\r\n<tr>\r\n <td align=\"right\" valign=\"bottom\" class=\"tableMenu\">\r\n <tmpl_if canPost>\r\n <a href=\"<tmpl_var post.url>\"><tmpl_var post.label></a> ·\r\n </tmpl_if>\r\n <a href=\"<tmpl_var search.url>\"><tmpl_var search.label></a>\r\n </td></tr></table>\r\n\r\n <table border=0 cellpadding=2 cellspacing=1 width=\"100%\">\r\n <tr>\r\n <td class=\"tableHeader\"><tmpl_var subject.label></td>\r\n <td class=\"tableHeader\"><tmpl_var user.label></td>\r\n <td class=\"tableHeader\"><tmpl_var date.label></td>\r\n <td class=\"tableHeader\"><tmpl_var views.label></td>\r\n <td class=\"tableHeader\"><tmpl_var replies.label></td>\r\n <td class=\"tableHeader\"><tmpl_var last.label></td>\r\n </tr>\r\n\r\n<tmpl_loop messages_loop>\r\n <tr><td class=\"tableData\">\r\n <a href=\"<tmpl_var message.url>\"><tmpl_var message.subject></a>\r\n <tmpl_if message.currentUser>\r\n (<tmpl_var message.status>)\r\n </tmpl_if> \r\n </td>\r\n <td class=\"tableData\"><a href=\"<tmpl_var message.userProfile>\"><tmpl_var message.username></a></td>\r\n <td class=\"tableData\"><tmpl_var message.date></td>\r\n <td class=\"tableData\"><tmpl_var message.views></td>\r\n <td class=\"tableData\"><tmpl_var message.replies></td>\r\n <td class=\"tableData\">\r\n <span style=\"font-size: 8pt;\">\r\n <a href=\"<tmpl_var last.url\"><tmpl_var last.subject></a>\r\n @ <tmpl_var last.date> \r\n by <a href=\"<tmpl_var last.userProfile>\"><tmpl_var last.username></a>\r\n </span>\r\n </td>\r\n </tr>\r\n</tmpl_loop>\r\n</table>\r\n\r\n\r\n<tmpl_if multiplePages>\r\n <div class=\"pagination\">\r\n <tmpl_var previousPage> · <tmpl_var pageList> · <tmpl_var nextPage>\r\n </div>\r\n</tmpl_if>\r\n\r\n','MessageBoard');
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,14 @@ sub duplicate {
|
|||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::MessageBoard->new({wobjectId=>$w,namespace=>$namespace});
|
||||
$w->set({
|
||||
messagesPerPage=>$_[0]->get("messagesPerPage")
|
||||
messagesPerPage=>$_[0]->get("messagesPerPage"),
|
||||
templateId=>$_[0]->get("templateId")
|
||||
});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub set {
|
||||
$_[0]->SUPER::set($_[1],[qw(messagesPerPage)]);
|
||||
$_[0]->SUPER::set($_[1],[qw(templateId messagesPerPage)]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -59,6 +60,13 @@ sub www_edit {
|
|||
$output .= '<h1>'.WebGUI::International::get(6,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->integer("messagesPerPage",WebGUI::International::get(4,$namespace),$messagesPerPage);
|
||||
$f->template(
|
||||
-name=>"templateId",
|
||||
-value=>$_[0]->get("templateId"),
|
||||
-namespace=>$namespace,
|
||||
-label=>WebGUI::International::get(72,$namespace),
|
||||
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
|
||||
);
|
||||
$f->raw($_[0]->SUPER::discussionProperties);
|
||||
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
|
||||
return $output;
|
||||
|
|
@ -68,7 +76,8 @@ sub www_edit {
|
|||
sub www_editSave {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->SUPER::www_editSave({
|
||||
messagesPerPage=>$session{form}{messagesPerPage}
|
||||
messagesPerPage=>$session{form}{messagesPerPage},
|
||||
templateId=>$session{form}{templateId}
|
||||
});
|
||||
return "";
|
||||
}
|
||||
|
|
@ -80,84 +89,57 @@ sub www_showMessage {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($sth, %data, $html, $i, $pn, $lastId, @last, $replies);
|
||||
tie %data, 'Tie::CPHash';
|
||||
if ($session{form}{pn} < 1) {
|
||||
$pn = 0;
|
||||
} else {
|
||||
$pn = $session{form}{pn};
|
||||
}
|
||||
$html = $_[0]->displayTitle;
|
||||
$html .= $_[0]->description;
|
||||
$html = $_[0]->processMacros($html);
|
||||
$html .= '<table width="100%" cellpadding=2 cellspacing=1 border=0><tr>'.
|
||||
'<td align="right" valign="bottom" class="tableMenu">';
|
||||
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"))) {
|
||||
$html .= '<a href="'.
|
||||
WebGUI::URL::page('func=post&mid=new&wid='.$_[0]->get("wobjectId")).'">'.
|
||||
WebGUI::International::get(17,$namespace).'</a> · ';
|
||||
}
|
||||
$html .= '<a href="'.WebGUI::URL::page('func=search&wid='.$_[0]->get("wobjectId")).'">'
|
||||
.WebGUI::International::get(364).'</a></td></tr></table>';
|
||||
$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(15,$namespace).'</td>
|
||||
<td class="tableHeader">'.WebGUI::International::get(18,$namespace).'</td>
|
||||
<td class="tableHeader">'.WebGUI::International::get(514).'</td>
|
||||
<td class="tableHeader">'.WebGUI::International::get(19,$namespace).'</td>
|
||||
<td class="tableHeader">'.WebGUI::International::get(20,$namespace).'</td></tr>';
|
||||
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views,status
|
||||
my ($data, $html, %var, @message_loop, $rows, $lastId, @last, $replies);
|
||||
$var{title} = $_[0]->processMacros($_[0]->get("title"));
|
||||
$var{description} = $_[0]->processMacros($_[0]->get("description"));
|
||||
$var{canPost} = WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"));
|
||||
$var{"post.url"} = WebGUI::URL::page('func=post&mid=new&wid='.$_[0]->get("wobjectId"));
|
||||
$var{"post.label"} = WebGUI::International::get(17,$namespace);
|
||||
$var{"search.url"} = WebGUI::URL::page('func=search&wid='.$_[0]->get("wobjectId"));
|
||||
$var{"search.label"} = WebGUI::International::get(364);
|
||||
$var{"subject.label"} = WebGUI::International::get(229);
|
||||
$var{"user.label"} = WebGUI::International::get(15,$namespace);
|
||||
$var{"date.label"} = WebGUI::International::get(18,$namespace);
|
||||
$var{"views.label"} = WebGUI::International::get(514);
|
||||
$var{"replies.label"} = WebGUI::International::get(19,$namespace);
|
||||
$var{"last.label"} = WebGUI::International::get(20,$namespace);
|
||||
$p = WebGUI::Paginator->new('wid='.$_[0]->get("wobjectId").'&func=view');
|
||||
$p->setDataByQuery("select messageId,subject,username,dateOfPost,userId,views,status
|
||||
from discussion where wobjectId=".$_[0]->get("wobjectId")." and pid=0
|
||||
and (status='Approved' or userId=$session{user}{userId}) order by dateOfPost desc");
|
||||
while (%data = $sth->hash) {
|
||||
if ($i >= ($_[0]->get("messagesPerPage")*$pn) && $i < ($_[0]->get("messagesPerPage")*($pn+1))) {
|
||||
@last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId
|
||||
from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data{messageId}
|
||||
and status='Approved' order by dateOfPost desc");
|
||||
$last[3] = WebGUI::HTML::filter($last[3],'all');
|
||||
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion
|
||||
where rid=$data{messageId} and status='Approved'");
|
||||
$replies--;
|
||||
$html .= '<tr><td class="tableData"><a
|
||||
href="'.WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$_[0]->get("wobjectId"))
|
||||
.'">'.substr($data{subject},0,30).'</a>';
|
||||
if ($data{userId} == $session{user}{userId}) {
|
||||
$html .= ' ('.$status{$data{status}}.')';
|
||||
}
|
||||
$html .= '</td>
|
||||
<td class="tableData"><a href="'.WebGUI::URL::page('op=viewProfile&uid='.$data{userId}).'">'
|
||||
.$data{username}.'</a></td>
|
||||
<td class="tableData">'.epochToHuman($data{dateOfPost},"%z %Z").'</td>
|
||||
<td class="tableData">'.$data{views}.'</td>
|
||||
<td class="tableData">'.$replies.'</td>
|
||||
<td class="tableData"><span style="font-size: 8pt;"><a
|
||||
href="'.WebGUI::URL::page('func=showMessage&mid='.$last[0].'&wid='.$_[0]->get("wobjectId")).'">'
|
||||
.substr($last[3],0,30).'</a>
|
||||
@ '.epochToHuman($last[1],"%z %Z").' by <a href="'
|
||||
.WebGUI::URL::page('op=viewProfile&uid='.$last[4]).'">'.$last[2].'</a>
|
||||
</span></td></tr>';
|
||||
}
|
||||
$i++;
|
||||
$rows = $p->getPageData;
|
||||
foreach $data (@$rows) {
|
||||
@last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId
|
||||
from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data->{messageId}
|
||||
and status='Approved' order by dateOfPost desc");
|
||||
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion
|
||||
where rid=$data->{messageId} and status='Approved'");
|
||||
$replies--;
|
||||
@message_loop = ({
|
||||
"last.url" => WebGUI::URL::page('func=showMessage&mid='.$last[0].'&wid='.$_[0]->get("wobjectId")),
|
||||
"last.subject" => substr(WebGUI::HTML::filter($last[3],'all'),0,30),
|
||||
"last.date" => epochToHuman($last[1]),
|
||||
"last.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$last[4]),
|
||||
"last.username" => $last[2],
|
||||
"message.replies" => $replies,
|
||||
"message.url" => WebGUI::URL::page('func=showMessage&mid='.$data->{messageId}.'&wid='.$_[0]->get("wobjectId")),
|
||||
"message.subject" => substr($data{subject},0,30),
|
||||
"message.currentUser" => ($data{userId} == $session{user}{userId}),
|
||||
"message.status" => $status{$data{status}},
|
||||
"message.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$data{userId}),
|
||||
"message.username" => $data{username},
|
||||
"message.date" => epochToHuman($data{dateOfPost}),
|
||||
"message.views" => $data{views}
|
||||
});
|
||||
}
|
||||
$html .= '</table>';
|
||||
if ($i > $_[0]->get("messagesPerPage")) {
|
||||
$html .= '<div class="pagination">';
|
||||
if ($pn > 0) {
|
||||
$html .= '<a href="'.WebGUI::URL::page('pn='.($pn-1)).'">«'.
|
||||
WebGUI::International::get(91).'</a>';
|
||||
} else {
|
||||
$html .= '«'.WebGUI::International::get(91);
|
||||
}
|
||||
$html .= ' · ';
|
||||
if (($pn+1) < round(($i/$_[0]->get("messagesPerPage")))) {
|
||||
$html .= '<a href="'.WebGUI::URL::page('pn='.($pn+1)).'">'.
|
||||
WebGUI::International::get(92).'»</a>';
|
||||
} else {
|
||||
$html .= WebGUI::International::get(92).'»';
|
||||
}
|
||||
$html .= '</div>';
|
||||
}
|
||||
return $html;
|
||||
$var{message_loop} = \@message_loop;
|
||||
$var{firstPage} = $p->getFirstPageLink;
|
||||
$var{lastPage} = $p->getLastPageLink;
|
||||
$var{nextPage} = $p->getNextPageLink;
|
||||
$var{pageList} = $p->getPageLinks;
|
||||
$var{previousPage} = $p->getPreviousPageLink;
|
||||
$var{multiplePages} = ($p->getNumberOfPages > 1);
|
||||
return $_[0]->processTemplate($_[0]->get("templateId"),\%var);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue