Zzed
04-08-2002, 10:00 PM
I wasn't able to find this hack anywhere. So I wrote this.
This hack will show the number of views per announcement.
Tables affected: announcement
Templates affected: forumdisplay_announcement
Files affected: forumdisplay.php and announcement.php
First we need to add a new field to announcement:
alter table announcement add visits smallint(5) unsigned DEFAULT 0 NOT NULL;
Then we need to modify forumdisplay_announcement template:
Look for the following:
<smallfont><br>($announcement[usertitle])</smallfont></td>
<td bgcolor="#F1F1F1"><normalfont>-</normalfont></td>
<td bgcolor="#DFDFDF"><normalfont>-</normalfont></td>
And replace it with the following:
<smallfont><br>($announcement[usertitle])</smallfont></td>
<td bgcolor="#F1F1F1"><normalfont>-</normalfont></td>
<td bgcolor="#DFDFDF"><normalfont>$announcement[visits]</normalfont></td>
In forumdisplay.php:
Look for the following:
if ($announcement=$DB_site->query_first("SELECT announcementid,startdate,title,user.username,user. userid,user.usertitle,user.customtitle
FROM announcement
LEFT JOIN user
ON user.userid=announcement.userid
WHERE startdate<=$datenow AND enddate>=$datenow
AND $forumlist
ORDER BY startdate DESC
LIMIT 1")) {
if ($foruminfo[allowratings]) {
$thread[rating]='clear.gif';
eval("\$threadrating = \"".gettemplate('forumdisplaybit_threadrate')."\";");
$backcolor = '#DFDFDF';
$bgclass = "alt2";
} else {
unset($threadrating);
$backcolor = '#F1F1F1';
$bgclass = "alt1";
}
if ($announcement[customtitle]==2)
$announcement[usertitle] = htmlspecialchars($announcement[usertitle]);
$announcement[postdate]=vbdate($dateformat,$announcement[startdate]);
if ($announcement[startdate]>$bbuserinfo[lastvisit]) {
$announcement[icon]='newannounce.gif';
} else {
$announcement[icon]='announce.gif';
}
eval("\$announcement = \"".gettemplate('forumdisplay_announcement')."\";");
$doneannouncements = 1;
}
And replace it with the following:
if ($announcement=$DB_site->query_first("SELECT announcementid,startdate,title,user.username,user. userid,user.usertitle,user.customtitle,visits
FROM announcement
LEFT JOIN user
ON user.userid=announcement.userid
WHERE startdate<=$datenow AND enddate>=$datenow
AND $forumlist
ORDER BY startdate DESC
LIMIT 1")) {
if ($foruminfo[allowratings]) {
$thread[rating]='clear.gif';
eval("\$threadrating = \"".gettemplate('forumdisplaybit_threadrate')."\";");
$backcolor = '#DFDFDF';
$bgclass = "alt2";
} else {
unset($threadrating);
$backcolor = '#F1F1F1';
$bgclass = "alt1";
}
if ($announcement[customtitle]==2) {
$announcement[usertitle] = htmlspecialchars($announcement[usertitle]);
}
$announcement[postdate]=vbdate($dateformat,$announcement[startdate]);
if ($announcement[startdate]>$bbuserinfo[lastvisit]) {
$announcement[icon]='newannounce.gif';
} else {
$announcement[icon]='announce.gif';
}
eval("\$announcement = \"".gettemplate('forumdisplay_announcement')."\";");
$doneannouncements = 1;
}
In announcement.php
Look for the following:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.titl e,pagetext,user.*,userfield.*
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM announcement
LEFT JOIN user ON user.userid=announcement.userid
LEFT JOIN userfield ON userfield.userid=announcement.userid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid LEFT JOIN customavatar ON customavatar.userid=announcement.userid","")\
."
WHERE startdate<='$datenow' AND enddate>='$datenow' AND $forumlist ORDER BY startdate DESC");
And replace it with the following:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.titl e,pagetext,visits,user.*,userfield.*
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM announcement
LEFT JOIN user ON user.userid=announcement.userid
LEFT JOIN userfield ON userfield.userid=announcement.userid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid LEFT JOIN customavatar ON customavatar.userid=announcement.userid","")\
."
WHERE startdate<='$datenow' AND enddate>='$datenow' AND $forumlist ORDER BY startdate DESC");
In announcement.php
Look for the following:
$counter++;
//$allowhtml = 1;
//$announcebits .= getpostbit($post);
And annd the following directly below it:
$DB_site->query("UPDATE announcement set visits=visits+1 where announcementid=$post[announcementid];");
That's it. :)
This hack will show the number of views per announcement.
Tables affected: announcement
Templates affected: forumdisplay_announcement
Files affected: forumdisplay.php and announcement.php
First we need to add a new field to announcement:
alter table announcement add visits smallint(5) unsigned DEFAULT 0 NOT NULL;
Then we need to modify forumdisplay_announcement template:
Look for the following:
<smallfont><br>($announcement[usertitle])</smallfont></td>
<td bgcolor="#F1F1F1"><normalfont>-</normalfont></td>
<td bgcolor="#DFDFDF"><normalfont>-</normalfont></td>
And replace it with the following:
<smallfont><br>($announcement[usertitle])</smallfont></td>
<td bgcolor="#F1F1F1"><normalfont>-</normalfont></td>
<td bgcolor="#DFDFDF"><normalfont>$announcement[visits]</normalfont></td>
In forumdisplay.php:
Look for the following:
if ($announcement=$DB_site->query_first("SELECT announcementid,startdate,title,user.username,user. userid,user.usertitle,user.customtitle
FROM announcement
LEFT JOIN user
ON user.userid=announcement.userid
WHERE startdate<=$datenow AND enddate>=$datenow
AND $forumlist
ORDER BY startdate DESC
LIMIT 1")) {
if ($foruminfo[allowratings]) {
$thread[rating]='clear.gif';
eval("\$threadrating = \"".gettemplate('forumdisplaybit_threadrate')."\";");
$backcolor = '#DFDFDF';
$bgclass = "alt2";
} else {
unset($threadrating);
$backcolor = '#F1F1F1';
$bgclass = "alt1";
}
if ($announcement[customtitle]==2)
$announcement[usertitle] = htmlspecialchars($announcement[usertitle]);
$announcement[postdate]=vbdate($dateformat,$announcement[startdate]);
if ($announcement[startdate]>$bbuserinfo[lastvisit]) {
$announcement[icon]='newannounce.gif';
} else {
$announcement[icon]='announce.gif';
}
eval("\$announcement = \"".gettemplate('forumdisplay_announcement')."\";");
$doneannouncements = 1;
}
And replace it with the following:
if ($announcement=$DB_site->query_first("SELECT announcementid,startdate,title,user.username,user. userid,user.usertitle,user.customtitle,visits
FROM announcement
LEFT JOIN user
ON user.userid=announcement.userid
WHERE startdate<=$datenow AND enddate>=$datenow
AND $forumlist
ORDER BY startdate DESC
LIMIT 1")) {
if ($foruminfo[allowratings]) {
$thread[rating]='clear.gif';
eval("\$threadrating = \"".gettemplate('forumdisplaybit_threadrate')."\";");
$backcolor = '#DFDFDF';
$bgclass = "alt2";
} else {
unset($threadrating);
$backcolor = '#F1F1F1';
$bgclass = "alt1";
}
if ($announcement[customtitle]==2) {
$announcement[usertitle] = htmlspecialchars($announcement[usertitle]);
}
$announcement[postdate]=vbdate($dateformat,$announcement[startdate]);
if ($announcement[startdate]>$bbuserinfo[lastvisit]) {
$announcement[icon]='newannounce.gif';
} else {
$announcement[icon]='announce.gif';
}
eval("\$announcement = \"".gettemplate('forumdisplay_announcement')."\";");
$doneannouncements = 1;
}
In announcement.php
Look for the following:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.titl e,pagetext,user.*,userfield.*
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM announcement
LEFT JOIN user ON user.userid=announcement.userid
LEFT JOIN userfield ON userfield.userid=announcement.userid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid LEFT JOIN customavatar ON customavatar.userid=announcement.userid","")\
."
WHERE startdate<='$datenow' AND enddate>='$datenow' AND $forumlist ORDER BY startdate DESC");
And replace it with the following:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.titl e,pagetext,visits,user.*,userfield.*
".iif($avatarenabled,",avatar.avatarpath,NOT ISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline","")."
FROM announcement
LEFT JOIN user ON user.userid=announcement.userid
LEFT JOIN userfield ON userfield.userid=announcement.userid
".iif ($avatarenabled,"LEFT JOIN avatar ON avatar.avatarid=user.avatarid LEFT JOIN customavatar ON customavatar.userid=announcement.userid","")\
."
WHERE startdate<='$datenow' AND enddate>='$datenow' AND $forumlist ORDER BY startdate DESC");
In announcement.php
Look for the following:
$counter++;
//$allowhtml = 1;
//$announcebits .= getpostbit($post);
And annd the following directly below it:
$DB_site->query("UPDATE announcement set visits=visits+1 where announcementid=$post[announcementid];");
That's it. :)