PDA

View Full Version : Off-Topic Post Counter for Posts in Specified Forum(s)


kall
03-30-2005, 10:00 PM
/*================================================= =====================*\
|| ################################################## ################## ||
|| # Off-Topic Post Count for Specified Forums # ||
|| # ---------------------------------------------------------------- # ||
|| # An NZBoards Production! # ||
|| # Project Began: 0803 1 April 2005 (GMT) # ||
|| # Project Finished: 0818 1 April 2005 (GMT) # ||
|| # Version Released: 1.0 # ||
|| # Modification by: Kall # ||
|| # This may not be redistributed without NZBoards Consent # ||
|| # The above line applies to all you filthy pirates. # ||
|| # Copyright 2005 www.nzboards.com # ||
|| ################################################## ################## ||
\*================================================ ======================*/

As requested by rex of www.cruiselineforums.com:

What does this hack do?

Adds a new Post Counter, for off-topic posts.

It enables you to define a Forum (or Forums) as 'Off-Topic Forums'.
Any posts made by users in that Forum are not added to the Post count, they are added to the Off-Topic Post count instead.

As a bonus, OT posting won't be rewarded with promotions or points or anything linked to $bbuserinfo[posts].

Queries to run: One
Files to edit: One
Templates to edit: One (postbit or postbit_legacy).


########################### SQL EDITS START ###############################

Run this query: (change user to yourtableprefix_user if you use a table prefix).

ALTER TABLE `user` ADD `otposts` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL;

############################# SQL EDITS DONE ###############################



############################ FILE EDITS START ##############################

In includes/functions_newpost.php

Find:

$doposts = 'posts = posts + 1,';

Change to (make X equal to the forumid of your Off-topic forum):

if ($foruminfo['forumid'] == 'X')
{
$doposts = 'otposts = otposts + 1,';
}
else
{
$doposts = 'posts = posts + 1,';
}

Save and upload.

############################ FILE EDITS DONE ###############################


############################ TEMPLATE EDITS START ##########################

In postbit (or postbit_legacy) find:

$vbphrase[posts]: $post[posts]</div>

Under, add:

<div class="smallfont" name="Off-Topic Posts">OT Posts: $post[otposts]</div>


############################ TEMPLATE EDITS DONE ###########################


And you are done.

Rejoice!

Updates:
0850 1 April 2005 (GMT+12): Added name attribute to div tag for mouseover explanation.

1800 7 April 2005: Dan's AdminCP Update Offtopic Counter Addon: https://vborg.vbsupport.ru/showpost.php?p=636962&postcount=14

Lee
03-31-2005, 06:44 PM
Installed!

rex_b
03-31-2005, 06:44 PM
screeny at cruiselineforums.com

lasto
03-31-2005, 07:32 PM
cn this be setup so if we have a one section any posts in there (well threads as post are not needed) can be added up ?

kall
03-31-2005, 08:20 PM
cn this be setup so if we have a one section any posts in there (well threads as post are not needed) can be added up ?
I don't understand the question, sorry. :S

lasto
03-31-2005, 08:57 PM
is fine m8 it was way i worded it.

Does this work on posts only - would prefer one that actually worked on threads
so if i had a section for posting say pics etc evertime someone made a thread in that section it would increase the counter by 1,but people replying to the same thread would`nt get an increase as its based on threads only.

kall
03-31-2005, 09:30 PM
Ahh, right.

Well, as vB is by default, I believe that this hack would achieve what you want. (ie: as far as the $postcount variable is concerned, it increases regardless of whether it was a reply or a post.)

Therefore, new replies OR new threads in the specified OT forum would not add to Post count, but would add to OT Post count. That's why I called it 'OT Posts Hack' and not 'OT new replies Hack'. :)

Carnage
04-01-2005, 04:00 PM
you need to add an update counters thing for it. else it'll only apply to posts made after the hack is installed.

kall
04-01-2005, 08:01 PM
you need to add an update counters thing for it. else it'll only apply to posts made after the hack is installed.
Well, duh.

If *you* want to make an Update Counters thing for it, go ahead.

I can't find where it is I claim that it works retrospectively anywhere in this thread, so I don't 'need to add' anything.

Carnage
04-01-2005, 10:01 PM
Well, duh.

If *you* want to make an Update Counters thing for it, go ahead.

I can't find where it is I claim that it works retrospectively anywhere in this thread, so I don't 'need to add' anything.
mmm true...

i think it should be easy to do thou, just copy the update posts code and change this query:


$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE (forum.options & $_FORUMOPTIONS[countposts])
");


i think the following should do it:


$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE !(forum.options & $_FORUMOPTIONS[countposts])
");


alternativly you could try manually setting the folowing variable:

$gotforums = '';

to
$gotforums = '1,2,3';

where 1,2 and 3 are the forum ids of the forums you wish to count

kall
04-01-2005, 11:51 PM
mmm true...

i think it should be easy to do thou, just copy the update posts code and change this query:


$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE (forum.options & $_FORUMOPTIONS[countposts])
");


i think the following should do it:


$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE !(forum.options & $_FORUMOPTIONS[countposts])
");


alternativly you could try manually setting the folowing variable:

$gotforums = '';

to
$gotforums = '1,2,3';

where 1,2 and 3 are the forum ids of the forums you wish to count
Good stuff..thanks for that.

I don't really feel comfortable playing around with those things, but if anyone wnats to add this and see if it works for them... :)

Carnage
04-03-2005, 10:39 AM
when i've got more time, ie when i'm not about to go on holiday :P i'll have a play arround and get something fully working.

Snow
04-03-2005, 11:10 AM
If we wanted to include a number of forums as off-topic forums, how would we do this? I've replaced x with the forumids which I want to count in the off-topic post count and seperated them with a comma but it doesn't seem to be working.
if ($foruminfo['forumid'] == '39,63,64,51')

Dan
04-07-2005, 12:07 AM
Nevermind I figured it out xD

To Update Forum Posts Easily I created a easy modifcation!

Find in /admincp/misc.php

define('CP_REDIRECT', 'misc.php');
print_stop_message('updated_post_counts_successful ly');
}
}


Add Below:


// ###################### Start update Off Topic Post Counts ################
if ($_REQUEST['do'] == 'updatespam')
{
if (empty($perpage))
{
$perpage = 1000;
}
echo '<p>' . $vbphrase['updating_post_counts'] . '</p>';
$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE !(forum.options & $_FORUMOPTIONS[countposts])
");
$gootforums = 'X';
while ($forum = $DB_site->fetch_array($forums))
{
$gootforums .= ',' . $forum['forumid'];
}
$users = $DB_site->query("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $startat AND userid < $finishat ORDER BY userid DESC");
while ($user = $DB_site->fetch_array($users))
{
$totalposts = $DB_site->query_first("
SELECT COUNT(*) AS posts FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread USING (threadid)
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_t ON (deletionlog_t.primaryid = thread.threadid AND deletionlog_t.type = 'thread')
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_p ON (deletionlog_p.primaryid = post.postid AND deletionlog_p.type = 'post')
WHERE post.userid = $user[userid] AND
thread.forumid IN (0$gootforums) AND
deletionlog_t.primaryid IS NULL AND
deletionlog_p.primaryid IS NULL
");
$DB_site->query("UPDATE " . TABLE_PREFIX . "user SET otposts=$totalposts[posts] WHERE userid = $user[userid]");
echo construct_phrase($vbphrase['processing_x'], $user['userid']) . "<br />\n";
flush();
}

if ($checkmore = $DB_site->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $finishat LIMIT 1"))
{
print_cp_redirect("misc.php?$session[sessionurl]do=updateposts&startat=$finishat&perpage=$perpage");
echo "<p><a href=\"misc.php?$session[sessionurl]do=updateposts&amp;startat=$finishat&amp;perpage=$perpage\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
}
else
{
define('CP_REDIRECT', 'misc.php');
print_stop_message('updated_post_counts_successful ly');
}
}


Remember to change X in the above code

$gootforums = 'X';


To whatever your off topic forums are.


Now Find:


print_submit_row($vbphrase['update_post_counts']);


Add Below:


print_form_header('misc', 'updatespam');
print_table_header("Update Off Topic Posts", 2, 0);
print_description_row("This will update the Off Topic Post Count");
print_input_row($vbphrase['number_of_users_to_process_per_cycle'], 'perpage', 1000);
print_submit_row("Update Off Topic Posts");


And there you go! Now you can up date it easily!

kall
04-07-2005, 05:00 AM
Good stuff Dan, I'll reference it in the first post.

Thanks. :)

Snow
04-07-2005, 09:53 AM
Nevermind I figured it out xD

To Update Forum Posts Easily I created a easy modifcation!

Find in /admincp/misc.php

define('CP_REDIRECT', 'misc.php');
print_stop_message('updated_post_counts_successful ly');
}
}


Add Below:


// ###################### Start update Off Topic Post Counts ################
if ($_REQUEST['do'] == 'updatespam')
{
if (empty($perpage))
{
$perpage = 1000;
}
echo '<p>' . $vbphrase['updating_post_counts'] . '</p>';
$forums = $DB_site->query("
SELECT forumid
FROM " . TABLE_PREFIX . "forum AS forum
WHERE !(forum.options & $_FORUMOPTIONS[countposts])
");
$gootforums = 'X';
while ($forum = $DB_site->fetch_array($forums))
{
$gootforums .= ',' . $forum['forumid'];
}
$users = $DB_site->query("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $startat AND userid < $finishat ORDER BY userid DESC");
while ($user = $DB_site->fetch_array($users))
{
$totalposts = $DB_site->query_first("
SELECT COUNT(*) AS posts FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread USING (threadid)
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_t ON (deletionlog_t.primaryid = thread.threadid AND deletionlog_t.type = 'thread')
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog_p ON (deletionlog_p.primaryid = post.postid AND deletionlog_p.type = 'post')
WHERE post.userid = $user[userid] AND
thread.forumid IN (0$gootforums) AND
deletionlog_t.primaryid IS NULL AND
deletionlog_p.primaryid IS NULL
");
$DB_site->query("UPDATE " . TABLE_PREFIX . "user SET otposts=$totalposts[posts] WHERE userid = $user[userid]");
echo construct_phrase($vbphrase['processing_x'], $user['userid']) . "<br />\n";
flush();
}

if ($checkmore = $DB_site->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $finishat LIMIT 1"))
{
print_cp_redirect("misc.php?$session[sessionurl]do=updateposts&startat=$finishat&perpage=$perpage");
echo "<p><a href=\"misc.php?$session[sessionurl]do=updateposts&amp;startat=$finishat&amp;perpage=$perpage\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
}
else
{
define('CP_REDIRECT', 'misc.php');
print_stop_message('updated_post_counts_successful ly');
}
}


Remember to change X in the above code

$gootforums = 'X';


To whatever your off topic forums are.


Now Find:


print_submit_row($vbphrase['update_post_counts']);


Add Below:


print_form_header('misc', 'updatespam');
print_table_header("Update Off Topic Posts", 2, 0);
print_description_row("This will update the Off Topic Post Count");
print_input_row($vbphrase['number_of_users_to_process_per_cycle'], 'perpage', 1000);
print_submit_row("Update Off Topic Posts");


And there you go! Now you can up date it easily!
Thank you works great at updating OT posts. Only one point, it doesn't seem to update the normal posts count though, that stays the same as before so if a member had a total of 50 posts, 25 of which are OT posts, before adding this hack and updating OT posts, they find themselves with posts 50 PLUS OT posts 25 giving a total of 75 posts. I've tried updating post counts but it doesn't work. Anyone know how to get round this problem?

Dan
04-07-2005, 11:27 AM
Thank you works great at updating OT posts. Only one point, it doesn't seem to update the normal posts count though, that stays the same as before so if a member had a total of 50 posts, 25 of which are OT posts, before adding this hack and updating OT posts, they find themselves with posts 50 PLUS OT posts 25 giving a total of 75 posts. I've tried updating post counts but it doesn't work. Anyone know how to get round this problem?
We need the hack to include forums that don't have counting enabled which I can't figure out how to do. :(

Snow
04-07-2005, 12:20 PM
We need the hack to include forums that don't have counting enabled which I can't figure out how to do. :(
hmm, you just given me an idea..... far from ideal, but setting the OT forum in question to not count posts and then updating post counts brings the post count down, then resetting it to count posts and updating OT post counts seems to count all the OT posts..... it looks like it's worked. :D

quachvu
06-19-2005, 02:37 PM
how can man fix this script, so that it just count new threads in a forum for Off Topic, and dont count post reply of that thread?