Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Number of views per announcement Details »»
Number of views per announcement
Version: 1.00, by Zzed Zzed is offline
Developer Last Online: Feb 2012 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 04-08-2002 Last Update: Never Installs: 7
 
No support by the author.

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:
Code:
<smallfont><br>($announcement[usertitle])</smallfont></td>
	<td bgcolor="#F1F1F1"><normalfont>-</normalfont></td>
	<td bgcolor="#DFDFDF"><normalfont>-</normalfont></td>
And replace it with the following:
Code:
<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:
PHP Code:
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:
PHP Code:
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:
PHP Code:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.title,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:
PHP Code:
$announcements=$DB_site->query("
SELECT
announcementid,startdate,enddate,announcement.title,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:
PHP Code:
  $counter++;
  
//$allowhtml = 1;
  //$announcebits .= getpostbit($post); 
And annd the following directly below it:
PHP Code:
  $DB_site->query("UPDATE announcement set visits=visits+1 where announcementid=$post[announcementid];"); 
That's it.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 04-09-2002, 09:18 PM
MarkB's Avatar
MarkB MarkB is offline
 
Join Date: Oct 2001
Location: London, UK
Posts: 324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

YES!! Been wanting something like this for ages Thanks! Works great
Reply With Quote
  #3  
Old 04-10-2002, 10:09 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great, now we can prove that no one, but no one, reads the announcements.

Two things:
a) Instead of updating the counter for every announcement, you could just run a query that goes more or less like this:
Code:
UPDATE announcement SET visits = visits+1 WHERE forumid IN ($forumlist);
(generate $forumlist if needed). That way you only add one query instead of one per announcement.

b) Use the shutdown queries of vBulletin. An example can be found in showthread.php:
Code:
if ($noshutdownfunc) {
  $DB_site->query("UPDATE thread SET views=views+1 WHERE threadid='$threadid'");
} else {
  $shutdownqueries[]="UPDATE LOW_PRIORITY thread SET views=views+1 WHERE threadid='$threadid'";
}
Reply With Quote
  #4  
Old 04-10-2002, 10:49 AM
Zzed's Avatar
Zzed Zzed is offline
 
Join Date: Feb 2002
Location: Glendale, CA, USA
Posts: 463
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As always, I am most grateful for the wonderful advice.

Thank you.
Reply With Quote
  #5  
Old 04-10-2002, 07:42 PM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very nice....
Should we wait for a upgrade, so ?
Thnx
Reply With Quote
  #6  
Old 04-10-2002, 08:01 PM
Zzed's Avatar
Zzed Zzed is offline
 
Join Date: Feb 2002
Location: Glendale, CA, USA
Posts: 463
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sure.

I'll post an update later tonite.
Reply With Quote
  #7  
Old 04-10-2002, 09:00 PM
Xelation's Avatar
Xelation Xelation is offline
 
Join Date: Jan 2002
Location: Buffalo, New York
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

also for the forumdisplay.php file, when your trying to find the first part it should be....

PHP Code:
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 '#1C5780';
          
$bgclass "alt2";
    } else {
            unset(
$threadrating);
      
$backcolor '#13486D';
          
$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 not

PHP Code:
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 '#1C5780';
          
$bgclass "alt2";
    } else {
                        unset(
$threadrating);
      
$backcolor '#13486D';
          
$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;

you forgot to add 2 brackets, just thought I would let you know... it could be confusing for newbies.
Reply With Quote
  #8  
Old 04-16-2002, 01:53 AM
Crazy Mofo Crazy Mofo is offline
 
Join Date: Nov 2001
Location: Newcastle,UK
Posts: 91
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so any updates for this?

coz i get this error

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/domain/domain119/web/forum/announcement.php on line 34
Reply With Quote
  #9  
Old 04-16-2002, 06:10 PM
inetd inetd is offline
 
Join Date: Nov 2001
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ZZed, pleaser release update this wonderful hack!
Reply With Quote
  #10  
Old 04-16-2002, 07:57 PM
Zzed's Avatar
Zzed Zzed is offline
 
Join Date: Feb 2002
Location: Glendale, CA, USA
Posts: 463
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, I updated it.

It is all in the original post. And I updated the attachment.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04607 seconds
  • Memory Usage 2,381KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete