News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Shoutbox!

Started by LancelowDowell, July 26, 2004, 07:48:41 PM

Previous topic - Next topic

LancelowDowell

Not sure where this should go, since there really isn't a hack forum anywhere....  but anyways...

Well, I have most of my shoutbox coding done..  It's now functional, just has a few minor tweaks to make it fit on the board better.  You can check it out at http://www.cursedlegacy.net/smf.  I'll be doing a quick write up on how to set it up.  Let me know what you think!

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Peter Duggan

Did you know that Grudge has already done a shoutbox mod, but the SMF mod site hasn't been fully implemented yet?

LancelowDowell

eh, actually i wasn't aware of that....  i still had fun doing in though! :-)

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Grudge

Quote from: LancelowDowell on July 26, 2004, 10:43:11 PM
eh, actually i wasn't aware of that.... i still had fun doing in though! :-)
Heh - always space for more than one mod of the same type ;) Feel free to download my version from my package server if it helps you. Besides - my shoutbox is more a port of Greg Haase's than my own work!
I'm only a half geek really...

[Unknown]

(and who knows, they might be completely different?)

-[Unknown]

LancelowDowell

#5
Ok, finally got around to putting this together enough to post....  if you have any questions please let me know!  Also, feel free to hack out the comments I put in, those were just in there for my records.


Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

Quote from: LancelowDowell on August 01, 2004, 12:19:50 AM
you'll just have to put a copy of shoutbox.php in the template folders

Actually, you don't even have to do that ^_^.  Just put it in default and it should work for all themes - assuming you edit index.template.php for each.

Hmm, okay.  In your header for shout.php, you use tabs... which doesn't align the *'s properly in my editor.

include('Settings.php');
require('SSI.php');
include($sourcedir . '/Subs-Post.php');
include_once($sourcedir . '/Security.php');


Only the second and third should be necessary. (Security and Settings are loaded by SSI.php...)

redirectexit('');
Nitpick: I'd recommend just redirectexit();...

'$currentDate[0]'
I recommend replacing that with " . time() . ".

if($user['id']=="")
{
//do nothing since it's a guest.
}
else

I recommend using instead:
if(!$user_info['is_guest'])

And instead of using:
$user = ssi_welcome('array');
I would just say:
global $user_info, $ID_MEMBER;
And replace:
{$user['id']}
With:
$ID_MEMBER

And, shoutbox.php might be more efficient if you made this:
SELECT userid, shoutDate, pageText
FROM {$db_prefix}shout
order by id desc
limit 10", __FILE__, __LINE__);

Read instead:
SELECT s.userid, s.shoutDate, s.pageText, mem.realName
FROM {$db_prefix}shout AS s
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = s.userid)
ORDER BY id DESC
LIMIT 10", __FILE__, __LINE__);


And then remove:
$shoutUser = db_query("
SELECT realName
FROM {$db_prefix}members
WHERE ID_MEMBER=" . $row["userid"] . "
limit 1", __FILE__, __LINE__);

$row2 = mysql_fetch_array($shoutUser);


And make:
$row2['realName']
Instead:
$row['realName']

I know I nitpick a lot, but I do it equally to everyone - just ask Grudge ^_^.

-[Unknown]

LancelowDowell

#7
actually for some reason I had to run the include on settings and security...  I didn't play with it a whole lot, but I couldn't get it to work unless I included those files...

Thanks for the comments though.  Most of that stuff I didn't know about, like the user id and such.  I'll have to change the sql statement as well...  not a big deal having 2 statements vs 1, but every little bit helps.


Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

Quote from: LancelowDowell on August 01, 2004, 12:41:49 AM
Thanks for the comments though.  Most of that stuff I didn't know about, like the user id and such.  I'll have to change the sql statement as well...  not a big deal having 2 statements vs 1, but every little bit helps.

Actually, it's 1 + n where n is the number of shouts.... that's a bit more, isn't it?

You need to include Security.php, really?  Strange, I'll see if I can look into that.

-[Unknown]

LancelowDowell

hmm, I just commeted that out, and it's working fine now....  I can't recall what was excatly happening that cause me to add that, but if it's working fine now....

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

I do need settings though... I get this error when I comment out settings.  Looks like it can't find subs-post since it doesn't have the sourcedir from settings.

Notice: Undefined variable: sourcedir in /u/htdocs/ribcra/smf/Sources/shout.php on line 19
Warning: shoutbox(/Subs-Post.php) [function.shoutbox]: failed to create stream: No such file or directory in /u/htdocs/ribcra/smf/Sources/shout.php on line 19
Warning: shoutbox() [function.shoutbox]: Failed opening '/Subs-Post.php' for inclusion (include_path='.:/usr/local/lib/php') in /u/htdocs/ribcra/smf/Sources/shout.php on line 19

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

Try this instead:

global $sourcedir;

-[Unknown]

LancelowDowell

Hmm, I also tried your change for the guest thing, but it didn't pick up that I was a guest.  It still posted the shout with no user name.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

eh, nm, i think i see what i did wrong....

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

Okay, well, interesting.  Here, try the attached - does it work?

-[Unknown]

LancelowDowell

worked for a normal insert, but when I was logged in as a guest, it didn't run redirectexit(); because of the return command.  So it just hung the page...  so I replaced the return; with a redirectexit(); and looks a bit better now.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

also, just a question since I couldn't find it on my digging through code...  where is the text processor for output?  It runs the preparse and sets up the user's text, but I couldn't find any of the functions to do the reverse...

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

For output?  You mean the one that parses smileys and bbc?

It's doUBBC() in Subs.php, use it like so:

echo doUBBC($string, $useSmileys);

Where $string is the string to parse, and $parseSmileys is true or false, whether you want them parsed or not.

-[Unknown]

LancelowDowell


Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

Just a few updates I did to it....  I cleaned up the html a little bit, I had a small type that was causing some screwy things.  I also fixed it up so that when a guest is logged in, it won't display the text box.  Next in line will be an archive and basic stats....

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

Ok, I did quite a few updates to the shoutbox...  it has a working archive now along with some basic stats.  I also moved it from the index template to the board index template.  The link again...

http://www.cursedlegacy.net/davestuff/shoutbox.zip

You can check it out at http://www.cursedlegacy.net

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

[Unknown]

Looking pretty good, I'd say..

I recommend you change this:
//update shout counter in user profile...
$result = db_query("
SELECT shouts
FROM {$db_prefix}members
WHERE ID_MEMBER=$ID_MEMBER", __FILE__, __LINE__);

$row = mysql_fetch_array($result);
$shouts = $row['shouts']+1;

db_query("
UPDATE {$db_prefix}members
SET shouts = $shouts
WHERE ID_MEMBER=$ID_MEMBER", __FILE__, __LINE__);


To this:
//update shout counter in user profile...
$result = db_query("
UPDATE {$db_prefix}members
SET shouts = shouts + 1
WHERE ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);


As it's much faster... or, actually: (for reasons of later versions possibly requiring this...)
//update shout counter in user profile...
updateMemberData($ID_MEMBER, array('shouts' => '+'));


$shoutPage = $_REQUEST['shoutPage'];
$shoutResults = db_query("
SELECT s.userid, s.shoutDate, s.pageText, mem.realName
FROM {$db_prefix}shout AS s
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = s.userid)
ORDER BY id DESC", __FILE__, __LINE__);

$i = $pageSize * ($shoutPage-1);
//cycles through records till gets to first record of that page
while($i != 0 AND $row=mysql_fetch_array($shoutResults))
{
$i--;
}
$context['shouts']['currentPage'] = $shoutPage;


I smell Microsoft SQL experience!!!  MySQL has an excellent feature for skipping records, namley LIMIT.  Personally, I can't understand how anyone could consider SQL complete without it... but that's just me.

I'd rewrite that whole if block like so:
// Clean the request and make sure it's a number...
$_REQUEST['shoutPage'] = !isset($_REQUEST['shoutPage']) ? 1 : (int) $_REQUEST['shoutPage'];
$context['shouts']['currentPage'] = $_REQUEST['shoutPage'];

$shoutResults = db_query("
SELECT s.userid, s.shoutDate, s.pageText, IFNULL(mem.realName, '$txt[28]') AS realName
FROM {$db_prefix}shout AS s
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = s.userid)
ORDER BY id DESC
LIMIT " . (($_REQUEST['shoutPage'] - 1) * $pageSize) . ", $pageSize", __FILE__, __LINE__);


I also see you don't have any predefinition for $context['shouts'].  I strongly suggest you set it to an empty array before filling it, just to protect against security holes.

$context['shouts'] = array();

Of course, with the limit, this won't work anymore:
$totalShouts = mysql_num_rows($shoutResults)+1;
$totalPages = ((int)($totalShouts/$pageSize))+1;


So, we need a separate query.... but it's worth it with all the memory and resources we save with the limit, imho...
$shoutCount = db_query("
SELECT COUNT(id)
FROM {$db_prefix}shout", __FILE__, __LINE__);
list ($totalShouts) = mysql_fetch_row($shoutCount);
mysql_free_result($shoutCount);
$totalPages = (int) ($totalShouts / $pageSize) + 1;


Of course, this is all moot considering how lovely the constructPageIndex() function is... it's in Subs.php.

-[Unknown]

Vinoth

does it work on RC1 or Beta 5
Vinoth And Sachin ( SpecHackers Team )
The Best  Way to Help Poor Is not Becoming One Of Them.

LancelowDowell

Well, I currently run it in rc1, but I wrote it when I was on beta5.  I don't think I made any changes at all for it.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Vinoth

so could work on beta5 too.
Vinoth And Sachin ( SpecHackers Team )
The Best  Way to Help Poor Is not Becoming One Of Them.

LancelowDowell

Yes, it should work in beta 5.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

Well, I got to play around with the suggestions you made, [Unknown].... 

Just a quick question...  I've always wondered what's up with $txt...  what is $txt[28]?  I understand what it's being used for... I've seen it in several other files, but I haven't had the time to track it down yet.  Also, is there any documentation on how to build mods into packages yet?

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Grudge

Quote from: LancelowDowell on August 12, 2004, 05:15:41 PM
Also, is there any documentation on how to build mods into packages yet?

Download any package from my server and load it up - it's easy to work out. Basically, it's just a tar.gz file with a xml file in it called package-info.xml. You just edit that to reflect the work needed to be done. Package servers are just as easy *really*. If you want your own package server go to http://www.mymods.co.uk/Packages/packages.xml for a good start ;)
I'm only a half geek really...

[Unknown]

The $txt array is a huge array (the memory it takes up is sometimes depressing!) that stores all the language strings used.

It is done this way for localization reasons, as you probably know.  The strings are stored in flat files under Themes/themename/languages.  The function loadLanguage() loads extra language files.

You probably realized that $txt[28] is Guest.  In German, it would be Gast.... etc.

Regrettably, there is not currently any extended documentation on packages yet... just not enough hours in a day.

-[Unknown]

trenchteam

I installed this successfully. but it doesnt appear.  Can someone assist me?  http://www.7milesdown.com/forum

LancelowDowell

Did you stick the include shoutbox.php in your display.template.php file?  Is shoutbox.php in all of your theme directories?  Also, check your forum error log, it might be kicking out an error.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

roboter88

Nice MOD i testing it here

www.beatboxbattle.org/bbn2k4/bbs/

cheers

trenchteam

Quote from: LancelowDowell on August 20, 2004, 10:38:12 PM
Did you stick the include shoutbox.php in your display.template.php file?  Is shoutbox.php in all of your theme directories?  Also, check your forum error log, it might be kicking out an error.


can you give me the code you used to place your shoutbox in your forum.  Im not good with the php mixed with html.  Im not sure where to put it.  Thanks.

roboter88

#33
The download.zip contains a very small readme ...

u must change some files and upload and run a sql statement with phpMyadmin and add a new table to _members table...

Sorry cant sent u my files cause i customized my theme.

BACKUP all files u overwrite and make a DATABASE BAckup if u need more help just ask away :P

l8r

trenchteam

So do I create a seperate SQL database for this?  I was also wondering.  Do i take the code, but it in a notepad document and then upload it to Mysqladmin?  Im not sure how to do this. 

roboter88

#35
No you editing your old existing SMF database.

To do this you need best for phpMyAdmin
QuotephpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields, manage privileges,export data into various formats and is available in 47 languages.  GPL License


Do you have phpMyAdmin?

With this you can manage your MYSQL Database.
eg. Add/Edit/Delete tables

Otherwise go here http://www.phpmyadmin.net/home_page/ and download-
Install is easy - just upload teh extracted directory somewhere to your webspace.

If i remember right all you have to do is editing the config file where u put in the database login(username,host,password,database name).
Host is mostly localhost.

If you done this browse to the directory where you just uploaded phpMyAdmin and now you should see the administrativ backend for your MYSQL database.

Click on "SQL" and run the SQL content as stated in the readme. ( CREATE a new table and INSERT data).
Copy//Past the code from teh readme into the window that pops up after u click teh  SQL link.

At last you have to alter the "*_members" table.

On the left side you see all the tables click on "*_members" and browse down till you find ADD new FIELD - click "GO" and in the new window  you can edit the new table-field as written in teh readme add a table name=shouts typ=int(10) and default=0
That it is - the sql part is done.


About the shoutbox script:

i would request a shouts delete function :)

and i didnt edited the files from the downloaded yet but shouts want show in user profil yet (or i missunderstood something?)...hmmm when i watch at ur site i dont find shouts stats in profil either...where can u see the shouts statistic (if its possibel)?

Here is a nice tutorial about adding custom profil fields.
http://unknown.network32.net/tutorial.smf_custom-profile


Quote
index.php

Find code:

'setreserve2' => array('ManageMembers.php', 'SetReserve2'),

After that add this:

'shout' => array('shout.php', 'Shoutbox'),  //added by dmh 7-26-04
'shoutarchive' => array('shoutArchive.php', 'ShoutboxArchive'), //added by dmh 8-3-04

well i did this in the root index.php still i cant find teh shoutbox admin...where is it located normaly?

@LancelowDowell
QuoteDid you stick the include shoutbox.php in your display.template.php file?
What you mean with "stick" ?
Nothing about that in the readme. hmmm

cheers



LancelowDowell

Yea, I've just been really busy lately and haven't had any time to do any more work on it.  Delete functions are next in line...

If you have a custom display.template.php file, you need to put the shoutbox.php file in that template folder... the way I have it setup needs it wherever the display template is.  Not sure if I put that in the readme file, but I'll have to add that if it's not there....

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

roboter88

#37
The display.template.php is in the theme folder...(eg. classic theme)

But is there an admin or stats display already - cause i cant find....
and teh code counts the stats....


-roboter

Dragon Gamer

ok, i did this too

i'll tell you when i have it up yet. I only dl it so far and i am currently going over the code.
Jason-Marc Labban
Graphic Maker...Sigs, Avatars, Banners and Buttons.



Neo Hacks

Dragon Gamer

Ok i put it up just check http://megagaming.mycubix.com/mega_fourm/index.php

Question ???
How do you take out the date and time from it
I just want to see the name of the members who post, not really when they post or what day.
Jason-Marc Labban
Graphic Maker...Sigs, Avatars, Banners and Buttons.



Neo Hacks

LancelowDowell

To take out the date, find the shoutbox.php file that goes in the themes directory and find this code...


while($row = mysql_fetch_array($shouts))
{
echo '[', timeformat($row["shoutDate"]), '] ', $row['realName'], ': ', doUBBC($row["pageText"], true), '<br/>';
}


and change it to this...


while($row = mysql_fetch_array($shouts))
{
echo $row['realName'], ': ', doUBBC($row["pageText"], true), '<br/>';
}


This way it will show just the name and post.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Dragon Gamer

#41
Thanks a lot.

I removed it, why would you want to put that piece anyway?

just asking really.

So when are you gonna put a delete option.

Is it possible to get the messages to scroll after one has been posted???
Jason-Marc Labban
Graphic Maker...Sigs, Avatars, Banners and Buttons.



Neo Hacks

LancelowDowell

If you want to add it to all pages, just add it in to the index.template file.  Just search for template_menu() in there and add the calls to the shoutbox like you would in the boardindex.template file.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

LancelowDowell

Yea, I'll see about that.  Shouldn't be too hard.....

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

umiya

does this wotk with ssi like the other oen does?

LancelowDowell

No, I didn't modify ssi like Grudge did.  Instead, to get it to work you just need to do to display the shoutbox is to add this line wherever you want it...

if(!include($settings['theme_dir'] . '/shoutbox.php'))
      echo 'Could not load shoutbox!';

You still have to follow the rest of the instructions in the install.txt file, but that will take care of it.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

subliminal

#46
I love this shoutbox! I'm using it on my site but it's for members only. Do I need to change anything for 1.0 RC2?

LancelowDowell

nope, shouldn't have to.  I'm running it on the 1.0 preview just fine.  Only thing to watch out for is you'll have to re-add the array entries in index.php after you upload rc2.

Dave Hurt
Support Specialist
[email protected]
       
Personal Signature:
www.cursedlegacy.net

Midgard

how working shoutbox ??? i can't... what is action url: (index.php?action=shoutbox) ? but don't work.

Advertisement: