PDA

View Full Version : Post counts never drop


N9ne
07-28-2002, 12:51 PM
Ok i have 2.2.6 and the code in my functions.php has changed a lot. The prune doesn't reduce post count hack will not work, as my code has changed so much. So it's a simple request i'm sure, but can someone tell me what to do to my functions.php to make it so when a post or thread is deleted, post counts remain the same, and also when there's a prune.

Xenon
07-28-2002, 08:36 PM
you're not allowed to post full vb-files!!!

normally you have to take out this part in a unhacked functions.php: if ($countposts) {
$DB_site->query("UPDATE user SET posts=posts-1 WHERE userid='$postinfo[userid]'");
}

N9ne
07-28-2002, 10:10 PM
I didn't know, I thought it'd be ok since only license holders can download attachments?

Neo
07-28-2002, 11:31 PM
Its still a rule since by some mishap a un-athorized person might be able to download it.

N9ne
07-28-2002, 11:47 PM
Ok I removed the attachment, below is the code from the file functions.php which needs editing.

// ###################### Start update thread count #######################
function updatethreadcount($threadid) {
global $DB_site,$threadcache;

$replies=$DB_site->query_first("SELECT COUNT(*)-1 AS replies, SUM(attachment.visible) AS attachsum
FROM post
LEFT JOIN attachment ON attachment.attachmentid=post.attachmentid
WHERE threadid='$threadid'");

$lastposts=$DB_site->query_first("SELECT user.username,post.username AS postuser,post.dateline
FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.threadid='$threadid' AND visible>0
ORDER BY dateline DESC
LIMIT 1");
$lastposter=iif($lastposts['username']=="",$lastposts['postuser'],$lastposts['username']);
$lastposttime=$lastposts['dateline'];

$firstposts=$DB_site->query_first("SELECT post.userid,user.username,post.username AS postuser,post.dateline
FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.threadid='$threadid' AND visible>0
ORDER BY dateline
LIMIT 1");
$firstposter=iif($firstposts['username']=="",$firstposts['postuser'],$firstposts['username']);
$firstposterid=$firstposts['userid'];

$DB_site->query("UPDATE thread SET postusername='".addslashes($firstposter)."',postuserid='$firstposterid',lastpost='$lastpostt ime',replycount='$replies[replies]',attach='$replies[attachsum]', lastposter='".addslashes($lastposter)."' WHERE threadid='$threadid'");

}

// ###################### Start delete thread #######################
function deletethread($threadid,$countposts=1) {
global $DB_site;

// decrement users post counts
if ($threadinfo=getthreadinfo($threadid)) {
$postids="";
$attachmentids="";

$posts=$DB_site->query("SELECT userid,attachmentid,postid FROM post WHERE threadid='$threadid'");
while ($post=$DB_site->fetch_array($posts)) {
if ($countposts) {
if (!isset($userpostcount["$post[userid]"])) {
$userpostcount["$post[userid]"] = -1;
} else {
$userpostcount["$post[userid]"]--;
}
}
$postids.=$post['postid'].",";
if ($post['attachmentid'] != 0) {
$attachmentids .= $post['attachmentid'].",";
}
unindexpost($post['postid']);
}

if ($attachmentids != '' ) {
// make sure you don't remove attachments that are already in use!
$checkattachments=$DB_site->query("SELECT DISTINCT attachmentid FROM post WHERE attachmentid IN ($attachmentids"."0) AND threadid<>'$threadid'");
$omitattachmentids="";
while ($omitattach=$DB_site->fetch_array($checkattachments)) {
$omitattachmentids.=$omitattach['attachmentid'].",";
}
$DB_site->query("DELETE FROM attachment WHERE attachmentid IN ($attachmentids"."0) AND NOT attachmentid IN ($omitattachmentids"."0)");
}

$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storemin=$storeadmin[newthread];
$DB_site->query("UPDATE user SET storep=storep-'$storemin' WHERE userid='$postuserid'");


if ($postids!="") {
$DB_site->query("DELETE FROM post WHERE postid IN ($postids"."0)");
}
if ($threadinfo['pollid']!=0) {
$DB_site->query("DELETE FROM poll WHERE pollid='$threadinfo[pollid]'");
$DB_site->query("DELETE FROM pollvote WHERE pollid='$threadinfo[pollid]'");
}
$DB_site->query("DELETE FROM thread WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM thread WHERE open=10 AND pollid='$threadid'"); // delete redirects
$DB_site->query("DELETE FROM threadrate WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM subscribethread WHERE threadid='$threadid'");
}
}

// ###################### Start delete post #######################
function deletepost($postid,$countposts=1,$threadid=0) {
global $DB_site;

// decrement user post count
if ($postinfo=getpostinfo($postid)) {
$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storem=$storeadmin[newreply];
$DB_site->query("UPDATE user SET storep=storep-'$storem' WHERE userid='$postinfo[userid]'");

if ($postinfo['attachmentid']) {
// make sure you don't remove attachments still in use
$otherattachs=$DB_site->query("SELECT attachmentid FROM post WHERE attachmentid=$postinfo[attachmentid] AND threadid<>'$postinfo[threadid]'");
if ($DB_site->num_rows($otherattachs)==0) {
$DB_site->query("DELETE FROM attachment WHERE attachmentid=$postinfo[attachmentid]");
$DB_site->query("UPDATE thread SET attach = attach - 1 WHERE threadid = '$threadid'");
}
}

$DB_site->query("DELETE FROM post WHERE postid='$postid'");
}
}

// ###################### Start make login code #######################
function makelogincode() {
global $DB_site,$bbuserinfo,$session;

if ($bbuserinfo['userid']==0) {
eval("\$logincode = \"".gettemplate("username_loggedout")."\";");
} else {
eval("\$logincode = \"".gettemplate("username_loggedin")."\";");
}

return $logincode;
}

// ###################### Start un htmlspecialchars #######################

N9ne
07-29-2002, 12:44 PM
bump, anyone? pwease

N9ne
07-29-2002, 07:44 PM
bump :(

Xenon
07-29-2002, 07:46 PM
it's a problem because i don't know the hack, but i think this should do it:
// ###################### Start update thread count #######################
function updatethreadcount($threadid) {
global $DB_site,$threadcache;

$replies=$DB_site->query_first("SELECT COUNT(*)-1 AS replies, SUM(attachment.visible) AS attachsum
FROM post
LEFT JOIN attachment ON attachment.attachmentid=post.attachmentid
WHERE threadid='$threadid'");

$lastposts=$DB_site->query_first("SELECT user.username,post.username AS postuser,post.dateline
FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.threadid='$threadid' AND visible>0
ORDER BY dateline DESC
LIMIT 1");
$lastposter=iif($lastposts['username']=="",$lastposts['postuser'],$lastposts['username']);
$lastposttime=$lastposts['dateline'];

$firstposts=$DB_site->query_first("SELECT post.userid,user.username,post.username AS postuser,post.dateline
FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.threadid='$threadid' AND visible>0
ORDER BY dateline
LIMIT 1");
$firstposter=iif($firstposts['username']=="",$firstposts['postuser'],$firstposts['username']);
$firstposterid=$firstposts['userid'];

$DB_site->query("UPDATE thread SET postusername='".addslashes($firstposter)."',postuserid='$firstposterid',lastpost='$lastpostt ime',replycount='$replies[replies]',attach='$replies[attachsum]', lastposter='".addslashes($lastposter)."' WHERE threadid='$threadid'");

}

// ###################### Start delete thread #######################
function deletethread($threadid,$countposts=1) {
global $DB_site;

// decrement users post counts
if ($threadinfo=getthreadinfo($threadid)) {
$postids="";
$attachmentids="";

$posts=$DB_site->query("SELECT userid,attachmentid,postid FROM post WHERE threadid='$threadid'");
while ($post=$DB_site->fetch_array($posts)) {
if ($countposts) {
if (!isset($userpostcount["$post[userid]"])) {
$userpostcount["$post[userid]"] = -1;
} else {
$userpostcount["$post[userid]"]--;
}
}
$postids.=$post['postid'].",";
if ($post['attachmentid'] != 0) {
$attachmentids .= $post['attachmentid'].",";
}
unindexpost($post['postid']);
}

if ($attachmentids != '' ) {
// make sure you don't remove attachments that are already in use!
$checkattachments=$DB_site->query("SELECT DISTINCT attachmentid FROM post WHERE attachmentid IN ($attachmentids"."0) AND threadid<>'$threadid'");
$omitattachmentids="";
while ($omitattach=$DB_site->fetch_array($checkattachments)) {
$omitattachmentids.=$omitattach['attachmentid'].",";
}
$DB_site->query("DELETE FROM attachment WHERE attachmentid IN ($attachmentids"."0) AND NOT attachmentid IN ($omitattachmentids"."0)");
}

$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storemin=$storeadmin[newthread];



if ($postids!="") {
$DB_site->query("DELETE FROM post WHERE postid IN ($postids"."0)");
}
if ($threadinfo['pollid']!=0) {
$DB_site->query("DELETE FROM poll WHERE pollid='$threadinfo[pollid]'");
$DB_site->query("DELETE FROM pollvote WHERE pollid='$threadinfo[pollid]'");
}
$DB_site->query("DELETE FROM thread WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM thread WHERE open=10 AND pollid='$threadid'"); // delete redirects
$DB_site->query("DELETE FROM threadrate WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM subscribethread WHERE threadid='$threadid'");
}
}

// ###################### Start delete post #######################
function deletepost($postid,$countposts=1,$threadid=0) {
global $DB_site;

// decrement user post count
if ($postinfo=getpostinfo($postid)) {
$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storem=$storeadmin[newreply];


if ($postinfo['attachmentid']) {
// make sure you don't remove attachments still in use
$otherattachs=$DB_site->query("SELECT attachmentid FROM post WHERE attachmentid=$postinfo[attachmentid] AND threadid<>'$postinfo[threadid]'");
if ($DB_site->num_rows($otherattachs)==0) {
$DB_site->query("DELETE FROM attachment WHERE attachmentid=$postinfo[attachmentid]");
$DB_site->query("UPDATE thread SET attach = attach - 1 WHERE threadid = '$threadid'");
}
}

$DB_site->query("DELETE FROM post WHERE postid='$postid'");
}
}

// ###################### Start make login code #######################
function makelogincode() {
global $DB_site,$bbuserinfo,$session;

if ($bbuserinfo['userid']==0) {
eval("\$logincode = \"".gettemplate("username_loggedout")."\";");
} else {
eval("\$logincode = \"".gettemplate("username_loggedin")."\";");
}

return $logincode;
}

// ###################### Start un htmlspecialchars #######################

N9ne
07-29-2002, 09:46 PM
I have the store hack installed, so there were a few queries etc for that and I noticed some have been removed from your version?

N9ne
07-30-2002, 02:21 PM
bump

N9ne
07-31-2002, 09:50 AM
anyone?

Xenon
07-31-2002, 10:28 AM
yes, i have removed the updatequeries which reduce the counter by one ;)

N9ne
07-31-2002, 06:28 PM
But some of the queries had some parts from the store hack, if these are removed, the store hack will not function properly?

N9ne
08-01-2002, 05:40 PM
bump

bonnmac
09-08-2002, 01:55 PM
I see g-force has posted how to do it in this thread...

https://vborg.vbsupport.ru/showthread.php?s=&threadid=43308&highlight=prune

g-force2k2
09-08-2002, 03:35 PM
lol... thanks bonnmac ;)

btw Tha Rock don't forget to make sure not to update the counters (for members) else you'll just distort your entire postcount... regards...

g-force2k2