Added a "views" counter to discussions and user submissions.

This commit is contained in:
JT Smith 2002-05-29 02:13:42 +00:00
parent 30999c9982
commit 057b523210
4 changed files with 37 additions and 23 deletions

View file

@ -90,6 +90,10 @@ INSERT INTO international VALUES (513,'WebGUI','English','Previous Thread');
delete from international where internationalId=10 and namespace='MessageBoard';
delete from international where internationalId=14 and namespace='MessageBoard';
INSERT INTO settings VALUES ('addEditStampToPosts','1');
alter table discussion add column views int not null default 0;
INSERT INTO international VALUES (514,'WebGUI','English','Views');
INSERT INTO international VALUES (515,'WebGUI','English','Add edit stamp to posts?');
alter table UserSubmission_submission add column views int not null default 0

View file

@ -87,10 +87,11 @@ sub deleteMessageConfirm {
#-------------------------------------------------------------------
sub formatHeader {
my $output;
$output = '<b>'.WebGUI::International::get(237).'</b> '.formatSubject($_[0]).'<br>';
$output = '<b>'.WebGUI::International::get(237).'</b> '.formatSubject($_[0]).'<br>' if ($_[0] ne "");
$output .= '<b>'.WebGUI::International::get(238).'</b>
<a href="'.WebGUI::URL::page('op=viewProfile&uid='.$_[1]).'">'.$_[2].'</a><br>';
$output .= "<b>".WebGUI::International::get(239)."</b> ".epochToHuman($_[3],"%z %Z")."<br>";
<a href="'.WebGUI::URL::page('op=viewProfile&uid='.$_[1]).'">'.$_[2].'</a><br>' if ($_[1] && $_[2] ne "");
$output .= "<b>".WebGUI::International::get(239)."</b> ".epochToHuman($_[3],"%z %Z")."<br>" if ($_[3]);
$output .= "<b>".WebGUI::International::get(514).":</b> ".$_[4]."<br>" if ($_[4]);
return $output;
}
@ -129,7 +130,8 @@ sub post {
if ($session{form}{replyTo} ne "") { # is a reply
$header = WebGUI::International::get(234);
%message = getMessage($session{form}{replyTo});
$footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost}).'<p>'.formatMessage($message{message});
$footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views})
.'<p>'.formatMessage($message{message});
$message{message} = "";
$message{subject} = formatSubject("Re: ".$message{subject});
$session{form}{mid} = "new";
@ -145,7 +147,8 @@ sub post {
} else { # is editing an existing message
$header = WebGUI::International::get(228);
%message = getMessage($session{form}{mid});
$footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost}).'<p>'.formatMessage($message{message});
$footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views})
.'<p>'.formatMessage($message{message});
$message{subject} = formatSubject($message{subject});
}
$f->hidden("func","postSave");
@ -208,18 +211,20 @@ sub purge {
#-------------------------------------------------------------------
sub showMessage {
my (@data, $html, %message, $defaultMid, $sqlAdd);
my (@data, $html, %message, $sqlAdd);
tie %message, 'Tie::CPHash';
if ($session{form}{sid}) {
$sqlAdd = " and subId=$session{form}{sid}";
}
($defaultMid) = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$session{form}{wid}".$sqlAdd);
$session{form}{mid} = $defaultMid if ($session{form}{mid} eq "");
if ($session{form}{mid} eq "") {
($session{form}{mid}) = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$session{form}{wid}".$sqlAdd);
}
WebGUI::SQL->write("update discussion set views=views+1 where messageId=$session{form}{mid}");
%message = 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 .= formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost});
$html .= formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views});
$html .= '</td>';
$html .= '<td rowspan=2 valign="top" class="tableMenu" nowrap>';
$html .= $_[0];
@ -284,7 +289,7 @@ sub showThreads {
if ($session{user}{discussionLayout} eq "flat") {
while (%data = $sth->hash) {
$html .= '<tr><td class="tableHeader">';
$html .= formatHeader($data{subject},$data{userId},$data{username},$data{dateOfPost});
$html .= formatHeader($data{subject},$data{userId},$data{username},$data{dateOfPost},$data{views});
$html .= '</td></tr>';
$html .= '<tr><td class="tableData">'.formatMessage($data{message}).'</td></tr>';
}

View file

@ -187,7 +187,7 @@ sub www_showMessage {
#-------------------------------------------------------------------
sub www_view {
my ($sth, @data, $html, $i, $pn, $lastId, @last, $replies);
my ($sth, %data, $html, $i, $pn, $lastId, @last, $replies);
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
@ -204,26 +204,29 @@ sub www_view {
$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
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views
from discussion where wobjectId=".$_[0]->get("wobjectId")." and pid=0 order by messageId desc");
while (@data = $sth->array) {
$data[1] = WebGUI::HTML::filter($data[1],'all');
while (%data = $sth->hash) {
$data{subject} = WebGUI::Discussion::formatSubject($data{subject});
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[0] order by dateOfPost desc");
from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data{messageId} order by dateOfPost desc");
$last[3] = WebGUI::HTML::filter($last[3],'all');
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where rid=$data[0]");
$replies -= 1;
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where rid=$data{messageId}");
$replies--;
$html .= '<tr><td class="tableData"><a
href="'.WebGUI::URL::page('func=showMessage&mid='.$data[0].'&wid='.$_[0]->get("wobjectId"))
.'">'.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],"%z %Z").'</td>
href="'.WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$_[0]->get("wobjectId"))
.'">'.substr($data{subject},0,30).'</a></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>
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>';
}

View file

@ -559,6 +559,7 @@ sub www_view {
sub www_viewSubmission {
my ($output, %submission, $file, $replies);
tie %submission, 'Tie::CPHash';
WebGUI::SQL->write("update UserSubmission_submission set views=views+1 where submissionId=$session{form}{sid}");
%submission = WebGUI::SQL->quickHash("select * from UserSubmission_submission where submissionId=$session{form}{sid}");
$submission{title} = WebGUI::HTML::filter($submission{title},'all');
$submission{content} = WebGUI::HTML::filter($submission{content},$session{setting}{filterContributedHTML});
@ -570,7 +571,8 @@ sub www_viewSubmission {
$output .= '<b>'.WebGUI::International::get(22,$namespace).'</b> <a href="'.
WebGUI::URL::page('op=viewProfile&uid='.$submission{userId}).'">'.$submission{username}.'</a><br>';
$output .= '<b>'.WebGUI::International::get(23,$namespace).'</b> '.epochToHuman($submission{dateSubmitted},"%z %Z")."<br>";
$output .= '<b>'.WebGUI::International::get(14,$namespace).':</b> '.$submissionStatus{$submission{status}};
$output .= '<b>'.WebGUI::International::get(14,$namespace).':</b> '.$submissionStatus{$submission{status}}.'<br>';
$output .= '<b>'.WebGUI::International::get(514).':</b> '.$submission{views}.'<br>';
$output .= '</td><td rowspan="2" class="tableMenu" nowrap valign="top">';
#---menu
if ($submission{userId} == $session{user}{userId} && WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) {