PDA

View Full Version : Letter counter


Sho
09-19-2002, 03:15 PM
First of all, I want to apologize for my horrible English.

Now, my request. Alongside the post counter, I want a letter counter for my postbit template. Well, I'm not good at this stuff, that's why I'm posting a request, but I believe it shouldn't be too hard to do. A new column in the post table, one in the user table, some changes to newreply.php, newthread.php, showthread.php and probably member.php. Hm. It's probably hard to count the letters in existing posts, but maybe someone can come up with an addition to the "Update Counters" thingie.

Anyone interested? :)

Xenon
09-19-2002, 03:27 PM
you can try that:

open functions.php find: // do posts from ignored users
if (($ignore[$post[userid]] and $post[userid] != 0)) {
eval("\$retval = \"".gettemplate("postbit_ignore")."\";");

before that add:
$post[numchars]=strlen($post[pagetext]);

then add $post[numchars] in your postbit template

Sho
09-19-2002, 03:33 PM
Hmm. Haven't tried it yet, but it seems surprisingly simple.

My explanation was probably too inaccurate. I want a letter counter for all posts a member has written, not just the current one.

Well, going to try that now. :)

Sho
09-19-2002, 03:37 PM
Nope, that's not what I'm looking for. Amazing nonetheless. :)

Xenon
09-19-2002, 03:50 PM
ah ok, missunderstood...

yes you're right then you have to add a field to user-table called letters

then open newreply.php and newthread.php
find: $DB_site->query("UPDATE user SET
".iif ($foruminfo[countposts],"posts=posts+1,","")."


change it to:
$DB_site->query("UPDATE user SET letters=letters+".strlen($message).",
".iif ($foruminfo[countposts],"posts=posts+1,","")."

Sho
09-19-2002, 04:06 PM
Hmm ... and editpost.php? :rolleyes:

Xenon
09-19-2002, 04:19 PM
that's a bit more complicated...

also if you want to get all old posts involved...

at first open editpost find this:
$postinfo[message]=htmlspecialchars($postinfo[pagetext]);
below add: $postinfo[len]=strlen($postinfo[pagetext])

then you have to edit your editpost template add(twice):
<input type="hidden" name="postlen" value="$postinfo[len]">

<input type="hidden" name="postid" value="$postid">

then back in editpost.php
after $DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($title))."',pagetext='".addslashes($message)."',allowsmilie='$allowsmilie',showsignature='$signa ture',iconid='$iconid'$editedbysql$attachmentsql WHERE postid='$postid'");

add this:
$DB_site->query("UPDATE user SET letters=".($bbuserinfo[letters]-$postlen+strlen($message))." WHERE userid=".$buserinfo[userid]);

then find:
eval("standardredirect(\"".gettemplate("redirect_deletepost")."\",\"showthread.php?s=$session[sessionhash]&threadid=$threadinfo[threadid]\");");

before add:$DB_site->query("UPDATE user SET letters=".($bbuserinfo[letters]-$postlen)." WHERE userid=".$buserinfo[userid]);

should be all

Sho
09-19-2002, 06:00 PM
*starts implementing*

Dean C
10-01-2002, 06:26 PM
this is interesting...

*bookmarks thread*

- miSt

Logician
10-02-2002, 08:17 AM
If you are trying to calculate the total number of characters a user posted to your board, maybe you can find this easier to adopt. Basically 1 SQL query can calculate it easily:

SELECT SUM(LENGTH(pagetext)) FROM `post` WHERE userid=X

You can integrate it to vb like:


$charcount=$DB_site->query_first("SELECT SUM(LENGTH(pagetext)) as char FROM `post` WHERE userid='$bbuserinfo[userid]'");
$bbuserinfo['charcount']=$charcount['char'];


by adding this at the end of say, global.php. Then you can use the variable $bbuserinfo['charcount'] in any template you want (like getinfo etc.). This might not work for postbit, but there is also a solution for this if you are tying to implement it into postbit..

One obvious advantage of making a dynamic query is that the number returned will be always up to date after message editing, deleting etc.

Enjoy..

Xenon
10-02-2002, 09:05 AM
thanks pal ;)

i found out the same way yesterday night, after reading a book about mysql functions....

Dean C
10-02-2002, 03:34 PM
haha cool... so that is all it takes logician?

- miSt

Logician
10-02-2002, 04:44 PM
Originally posted by Mist
haha cool... so that is all it takes logician?

well I didnt test it myself but it seems ok so yes, it is all it takes..

Dean C
10-02-2002, 06:33 PM
does it add any extra queries on any of the pages??

- miSt

Logician
10-02-2002, 08:16 PM
Originally posted by Mist
does it add any extra queries on any of the pages??
- miSt
Yes it adds 1 query.. (Whenever you see a "..$DB_site->query..." term in a hack code, automatically add 1 query) ;)

If you add the hack to global.php, the variable will be accessible in the entire vb scripts and 1 extra query will be added to all vb pages.

On the other hand you might want to consider adding the line to the relevant script if you only want to use it in a particular place like getinfo template(= User Info Page). Then 1 query will be added only when that particular page is loaded..

Your call..

Dean C
10-03-2002, 03:37 PM
yes i'll probably use it in member.php :)

Thanks a lot Logician

- miSt

Charles_1
09-11-2007, 11:16 PM
you can try that:

open functions.php find: // do posts from ignored users
if (($ignore[$post[userid]] and $post[userid] != 0)) {
eval("\$retval = \"".gettemplate("postbit_ignore")."\";");

before that add:
$post[numchars]=strlen($post[pagetext]);

then add $post[numchars] in your postbit template
Hi Xenon,

I did my search here, but I found only old topics regarding my need. I need counting of characters for each post in one specific forum, but solution that you wrote, is not applicable to present version of vBulletin (3.6.x). I tried to look for mentioned lines in file functions.php, but without success (which is not surprise after 5 years of modifications of vB). So could you please provide to me solution for actual version of vB? I just need that posts in one specific forum would have information about number of characters included in them. Nothing more :-).

Taragon
03-22-2008, 05:48 PM
If you are trying to calculate the total number of characters a user posted to your board, maybe you can find this easier to adopt. Basically 1 SQL query can calculate it easily:

SELECT SUM(LENGTH(pagetext)) FROM `post` WHERE userid=X

You can integrate it to vb like:


$charcount=$DB_site->query_first("SELECT SUM(LENGTH(pagetext)) as char FROM `post` WHERE userid='$bbuserinfo[userid]'");
$bbuserinfo['charcount']=$charcount['char'];


by adding this at the end of say, global.php. Then you can use the variable $bbuserinfo['charcount'] in any template you want (like getinfo etc.). This might not work for postbit, but there is also a solution for this if you are tying to implement it into postbit..

One obvious advantage of making a dynamic query is that the number returned will be always up to date after message editing, deleting etc.

Enjoy..

Very sorry for bumping this old request :o, but would this still work with vb 3.6/3.7?

Currently I'm running into this db error:

Database error in vBulletin 3.7.0 Release Candidate 1:

Invalid SQL:
SELECT SUM(LENGTH(pagetext)) as char FROM `post` WHERE userid='';

MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'char FROM `post` WHERE userid=''' at line 1
Error Number : 1064
Date : Saturday, March 22nd 2008 @ 01:46:55 PM
Script : http://www.letsgather.net/demo/
Referrer :
IP Address : 62.166.43.206
Username : Taragon
Classname : vB_Database
MySQL Version : 4.1.22-standard

Logician
03-22-2008, 06:43 PM
Wow.. A bump after 6 years! :D

Code for 3.6-3.7 must be:

$charcount=$db->query_first("SELECT SUM(LENGTH(pagetext)) as char FROM `post` WHERE userid='".$vbulletin->userinfo[userid]."'");
$vbulletin->userinfo['charcount'] = $charcount['char'];

However this adds 1 query to each page load and I don't suggest using it in a heavy traffic/busy board or forum with a lot of posts. It is neither optimized, nor a clean hack!

Taragon
03-22-2008, 08:45 PM
Thanks! And sorry again for the bump.
I was looking for something, and this was the only similar thing I could find.

voter
01-26-2009, 03:11 PM
Logician, nice job.
But what about to just release a mod, that defines a calculation say once per day as a scheduled task and writes an extra table for each user called say "posts size"

I am thinking about to have statistic for user profile with amount of letters in posts or size in kilobytes.

Wondering, that nobody still make such a mod?