Welcome, Guest. Please Login or Register.
October 09, 2024, 04:26:19 AM
Home Help Search Log in Register
News: If you are still using YaBB SE, please consider upgrading to SMF as soon as possible.

YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Word Count « previous next »
Pages: [1] Reply Ignore Print
Author Topic: Word Count  (Read 1856 times)
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Word Count
« on: October 30, 2003, 08:45:54 PM »
Reply with quote

Is there a mod out there that counts that number of words in each post?

Could I modify the censor function to also count words?
Please let me know.  Thank you!
Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
Spaceman-Spiff
Mod Team
YaBB God
*****
Posts: 3689


My $txt[228]

Re:Word Count
« Reply #1 on: October 30, 2003, 10:04:22 PM »
Reply with quote

why do you need something like this?
for stats puposes?
Logged

   My mods, ysePak, codes, tutorials
    Support question IMs = bad.
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #2 on: October 30, 2003, 10:07:33 PM »
Reply with quote

Well stat purposes would be nice for most people, but I actually want it for my RPG mod I'm making.  You get 1 gold for each word in each of your posts.

It's the only mechinism I can think of to earn 'money' to by equipment for my mod. :)

I would probably also modify it eventually to add spell checking capibilities.
« Last Edit: October 30, 2003, 10:09:21 PM by Ayeka » Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
Spaceman-Spiff
Mod Team
YaBB God
*****
Posts: 3689


My $txt[228]

Re:Word Count
« Reply #3 on: October 30, 2003, 10:13:30 PM »
Reply with quote

im not that sure how to count words, maybe it can be done using preg?
an easier way maybe is to count the characters
like 1 gold every 10 characters or something
use something like this in Post.php, inside function Post2():
$gold = floor(strlen($message)/10);
then store the value in the members table
Logged

   My mods, ysePak, codes, tutorials
    Support question IMs = bad.
Shadow's Pawn
Support Team
YaBB God
*****
Posts: 597


ich soll nicht toten

ICQ - 8039201shadowpawn@hotmail.com WWW
Re:Word Count
« Reply #4 on: October 30, 2003, 11:41:30 PM »
Reply with quote

Grudge made a mod that does this, but it was for a heavily modified board.. I think the thread where he showed me that was actually in the Mod Ideas board here somewhere.
He had a couple other mods that might be useful for your roleplay board also.  I'll dig up a link when I get a chance.
Logged

apologize \A*pol"o*gize\, v. i. - To lay the foundation for a future offense.
Shadow's Pawn
Support Team
YaBB God
*****
Posts: 597


ich soll nicht toten

ICQ - 8039201shadowpawn@hotmail.com WWW
Re:Word Count
« Reply #5 on: October 30, 2003, 11:58:41 PM »
Reply with quote

Look here

http://www.yabbse.org/community/index.php?thread=24514/0

Logged

apologize \A*pol"o*gize\, v. i. - To lay the foundation for a future offense.
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #6 on: October 31, 2003, 03:18:10 AM »
Reply with quote

Can somebody please look through my code, something isn't working right, and I'm not sure how to check it:

// If no thread specified, this is a new thread.
   // Find a valid random ID for it.
   $newtopic = ($threadid == '') ? true : false;
   $time = time();
   $se = ($ns ? 0 : 1);

   if (get_magic_quotes_gpc() == 0)
   {
      $subject = mysql_escape_string($subject);
      $message = mysql_escape_string($message);
   }
   
   WordCount($message);
   if ($newtopic)        // This is a new topic. Save it.
   {
      if ($isAnnouncement && $settings[7] != 'Administrator' && $settings[7] != 'Global Moderator' && !in_array($username, $moderators))
         fatal_error($txt['announcement1']);

      $tmpname = ($HTTP_POST_FILES['attachment']['name'] == 'NULL') ? 'NULL' : "'" . mysql_escape_string($HTTP_POST_FILES['attachment']['name']) . "'";
      $request = mysql_query("
         INSERT INTO {$db_prefix}messages (ID_MEMBER, subject, posterName, posterEmail, posterTime, posterIP, smiliesEnabled, body, icon, attachmentSize, attachmentFilename)
         VALUES ($ID_MEMBER, '$subject', '$name', '$email', $time, '$REMOTE_ADDR', $se, '$message', '$icon', '$attachment_size', $tmpname)") or database_error(__FILE__, __LINE__);

      $ID_MSG = mysql_insert_id();
      if ($ID_MSG > 0)
      {
         $request = mysql_query("
            INSERT INTO {$db_prefix}topics (ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, locked, numViews)
            VALUES ($board, $ID_MEMBER, $ID_MEMBER, $ID_MSG, $ID_MSG, $locked, 0)") or database_error(__FILE__, __LINE__);


HERE IS MY WORD COUNT FUNCION:

function WordCount ($string)
{
global $db_prefix, $ID_MEMBER;
$word_count = str_word_count ($string);

$request = mysql_query("
   SELECT Money
   FROM {$db_prefix}members
   WHERE (ID_MEMBER = $ID_MEMBER)") or database_error(__FILE__, __LINE__);

$newtotal = $request + $word_count;

$request = mysql_query("
   UPDATE {$db_prefix}members
   SET Money = $newtotal
   WHERE (ID_MEMBER = $ID_MEMBER)") or database_error(__FILE__, __LINE__);

}

I placed my WordCount call inside Post2 right before the message gets INSERTED/ UPDATED in the database.  and I added a column to my MEMBERS table called 'Money'.  

Any help would be very appriceiated!  Thanks!
« Last Edit: October 31, 2003, 04:02:24 PM by Ayeka » Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
[Unknown]
Global Moderator
YaBB God
*****
Posts: 7830


ICQ - 179721867unknownbrackets@hotmail.com WWW
Re:Word Count
« Reply #7 on: October 31, 2003, 03:35:21 AM »
Reply with quote

I would replace this:

$word_count = 0;
global $db_prefix, $ID_MEMBER;
str_word_count ($string);

With this:

global $db_prefix, $ID_MEMBER;
$word_count = str_word_count($string);

-[Unknown]
Logged
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #8 on: October 31, 2003, 11:40:28 AM »
Reply with quote

Okay, It's doing something but I don't know what!  My number is fluctuating between 16, then 21, then 19...  Are my SQL queries constructed correctly?

Thank you!

For example, the following screen shot is what I typed:  I started out with 29 words in my database count.  I have typed 12 words, yet when I save the message, my new word count is not 41, it is 28!  What is happening?

« Last Edit: October 31, 2003, 04:09:20 PM by Ayeka » Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #9 on: October 31, 2003, 05:54:12 PM »
Reply with quote

Okay, I've narrowed the problem down and needs some SQL help.  I've searched on the web and can not find how to do this.  Here is my statement as is:

$request = mysql_query("
  SELECT Money
  FROM {$db_prefix}members
  WHERE (ID_MEMBER = $ID_MEMBER)") or database_error(__FILE__, __LINE__);

My question is, How do I grab one cell (row/column) of data and use it for computations?  The above syntax isn't working.  I can not use $request as a variable to compute from.  What do I need to do to get the value 'Money' out of my database?

Thank you!
Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #10 on: October 31, 2003, 08:49:14 PM »
Reply with quote

Okay, I figured it out.  You need to have a 'mysql_retch_assoc($request); command after the SELECT statement!

Now for my next puzzle that has me totally stumped.  I wrote a small function to calculate the total amount of money a person would have after installing my mod.  However, it doesn't seem to be doing anything.  I did the following:

<font size="2">
                           <a href="' . $scripturl . '?action=RecalculateMoney">' . $txt[newadmin1] . '</a><br />
                           <a href="' . $scripturl . '?action=repairboards">' . $txt[610] . '</a><br />

and this is my new function:

// verify the user is an administrator
is_admin();

function ReCalculateMoney()
{
   global $db_prefix;
   $request = mysql_query("SELECT ID_MEMBER, body
            FROM {$db_prefix}messages") or database_error(__FILE__, __LINE__);

   while ($data = mysql_fetch_assoc($request))
   {
      $message = $data['body'];
      $id = $data['ID_MEMBER'];
      $word_count = str_word_count($message);
      $request2 = mysql_query("SELECT Money
                FROM {$db_prefix}members
                WHERE (ID_MEMBER = '$id')") or database_error(__FILE__, __LINE__);
      $data2 = mysql_fetch_assoc($request2);
      $oldmoney = $data2['Money'];
      $total = $oldmoney + $word_count;

      $request3 = mysql_query("UPDATE {$db_prefix}members
               SET Money = $total
               WHERE (ID_MEMBER = '$id')") or database_error(__FILE__, __LINE__);
   }
}


function Admin()
{


The same type of code worked wonderful on my Post2 function, but now it seems like it is doing nothing!  I'm sure I missed something!

BTW, sorry about all the posts.

Thank you.
Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
Ayeka
Jr. Member
**
Posts: 80


Good & Evil, there is never one without the other.

WWW
Re:Word Count
« Reply #11 on: October 31, 2003, 10:00:35 PM »
Reply with quote

Okay, I figured this one out too.  Didn't know you had to add an action to the action array inside INDEX.PHP!

Well, that feature now works!  WOOT!  thank you everybody for all your help!
Logged

--Ayeka
Master of the purple!
HAHAhahahahahaha!
[Unknown]
Global Moderator
YaBB God
*****
Posts: 7830


ICQ - 179721867unknownbrackets@hotmail.com WWW
Re:Word Count
« Reply #12 on: November 01, 2003, 12:45:48 AM »
Reply with quote

Sorry... was away...

Glad you got it working.

-[Unknown]
Logged
Pages: [1] Reply Ignore Print 
YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Word Count « previous - next »
 


Powered by MySQL Powered by PHP YaBB SE Community | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
SMF 2.1.4 © 2023, Simple Machines
Valid XHTML 1.0! Valid CSS

Page created in 0.048 seconds with 21 queries.