SEO-Board: Free, Fast and Search Engine Optimization Friendly Forum Script
»User: »Password:   Remember Me? 
Posted:  14 May 2009 20:53   Last Edited By: steven
Thank you for your wonderful code, it is exactly what I needed. My forum is at http://forums.scriptui.com. I used the light version, removed smilees and made some css changes to match the rest of the website.  I made the following mods. Removed bb codes from RSS feed, inserting bb codes surround selection, notifications and using php mailer so emails are verified on server. I hope to package and share.
Posted:  15 May 2009 06:30
By default when adding bb_codes they get added to the end of the text in the message. Even if text is selected the bb_codes get put at end of text. This is because the javascript code used to create bb_codes looks like this
Code:

e.value+=s;

If you want to be able to select text and format it, then these are my Instructions.
1) In seo-board.js add the following 2 functions (Internet Explorer needs it own function since it doesn't support selectionStart property)
Code:

function surroundSelection(e, a, b){
    if (e.selectionStart!=undefined){
        var selStart = e.selectionStart;
        var selEnd = e.selectionEnd;
        e.value = (e.value).substring(0,selStart)+a+(e.value).substring(selStart,selEnd)+b+(e.value).substring(selEnd)
        return;
    }
}
function surroundSelectionIE(e, a, b){
    if (e.selectionStart==undefined){
        if( document.selection ){
            var range = document.selection.createRange();
            var selEnd = range.duplicate();
            selEnd.moveToElementText(e);
            if (e===range.parentElement()){
                var selStart = selEnd.duplicate();
                 selStart.setEndPoint('EndToStart', range);
                selEnd.setEndPoint('StartToEnd', range);
                e.value = selStart.text+a+range.text+b+selEnd.text;
                return;
            };
        };
    };
}


I'll continue in the next post without bbCodes so that the code is not messed up
Posted:  15 May 2009 06:32   Last Edited By: steven
2) Changes should be made to the  usercreatetopic.htm, usereditpost.htm, userpostreply.htm files

change

<td class=bbbuttons>
<a href="javascript:paste_string(document.PForm.message,'[b][/b]')"><b>{$lang['bold']}</b></a>&nbsp;
<a href="javascript:paste_string(document.PForm.message,'[i][/i]')"><i>{$lang['italics']}</i></a>&nbsp;
<a href="javascript:paste_string(document.PForm.message,'[u][/u]')"><u>{$lang['underline']}</u></a>&nbsp;
<a href="javascript:paste_url(document.PForm.message,'{$lang['enter_url']}','{$lang['enter_desc']}')">{$lang['url']}</a>&nbsp;
<a href="javascript:paste_email(document.PForm.message,'{$lang['enter_email']}','{$lang['enter_desc']}')">{$lang['email']}</a>&nbsp;
<a href="javascript:paste_image(document.PForm.message,'{$lang['enter_image']}')">{$lang['image']}</a>&nbsp;
<a href="#bbcodes" onmousedown="javascript:quote_sel(document.PForm.message); return false;">{$lang['quote']}</a>&nbsp;
<a href="javascript:paste_string(document.PForm.message,'[code][/code]')">{$lang['code']}</a>
</td>


to

<td class=bbbuttons>
<a onmousedown="javascript:surroundSelectionIE(document.PForm.message,'[b]','[/b]')" href="javascript:surroundSelection(document.PForm.message,'[b]','[/b]')"><b>{$lang['bold']}</b></a>&nbsp;
<a onmousedown="javascript:surroundSelectionIE(document.PForm.message,'[i]','[/i]')" href="javascript:surroundSelection(document.PForm.message,'[i]','[/i]')"><i>{$lang['italics']}</i></a>&nbsp;
<a onmousedown="javascript:surroundSelectionIE(document.PForm.message,'[u]','[/u]')" href="javascript:surroundSelection(document.PForm.message,'[u]','[/u]')"><u>{$lang['underline']}</u></a>&nbsp;
<a href="javascript:paste_url(document.PForm.message,'{$lang['enter_url']}','{$lang['enter_desc']}')">{$lang['url']}</a>&nbsp;
<a href="javascript:paste_email(document.PForm.message,'{$lang['enter_email']}','{$lang['enter_desc']}')">{$lang['email']}</a>&nbsp;
<a href="javascript:paste_image(document.PForm.message,'{$lang['enter_image']}')">{$lang['image']}</a>&nbsp;
<a href="#bbcodes" onmousedown="javascript:quote_sel(document.PForm.message); return false;">{$lang['quote']}</a>&nbsp;
<a onmousedown="javascript:surroundSelectionIE(document.PForm.message,'[code]','[/code]')" href="javascript:surroundSelection(document.PForm.message,'[code]','[/code]')">{$lang['code']}</a>
</td>


Let me know if it works for you
Steven
Posted:  15 May 2009 07:42
Steven,

thanks for the code. Have you tested it on most popular browsers?

btw. the board was meant for people like you - people who need sth simple and can modify the code without going through megabytes of scripts.
Posted:  15 May 2009 07:59
Yes. Tested On IE, Opera(My Favorite), FireFox And Chrome. But Didn't Test Safari. Maybe I'll Post Notification Code Next Week.
Posted:  17 May 2009 15:47
Has anyone used my mod and is there any interest in my notification mod. I don't want to spend time putting it together for nothing
Posted:  17 May 2009 23:04
Nope. havn't but I did make a new guestbook that can be used with it. http://phpmyguestbook.uni.cc/index.php
Posted:  05 Jun 2009 22:09
Quote:
Has anyone used my mod and is there any interest in my notification mod

What's the notification mod?
If it's piece of code to inform on new answers in thread, please post it, I'm very interested. Thanks in advance.
Posted:  21 Jun 2009 22:09
Mod seems to work great.

Only tested in create message so far, but no reason to suspect it wont work in the edit.

Many thanks - was creating some minor problems for a couple of my users. 
Posted:  30 Aug 2009 16:00   Last Edited By: MusicalBox
Quote:
Has anyone used my mod and is there any interest in my notification mod. I don't want to spend time putting it together for nothing


I am interested as well.

By the way, I included your BBcodes mod on my forum and it works great ! thanks a lot
Posted:  01 Sep 2009 04:38
I am going to try with a few posts to write my notification mod. Overall we will be editing 4 files and adding 2 fields to the database. I hope to be able to finish it tonight but if not please bear with me, and I'll give you the entire mod.

Also I'd appreciate, if you post to the forum if you used the mod, if it was successful and the improvements you made to it. As always sharing is a small thing we could to to combat all the strife in the world we live in. We do it unconditionally and we hope that all you that gain will continue to carry the torch of generosity.

First we have to edit database
Code:

Add 2 fields to seo_board_users table.

1)user_notify_all            type=TINYINT
2)user_notify_active       type=TINYINT

the default should be 0, so that users should only be notified if they ask for it


these fields should hold the persistent information whether the user wants to be notified.
*The notify_all field, states that the user wants to be notified about all new posts
*The notify_active field, states that the user only wants to be notified if it previously posted in that thread.

[I understand that someone might only want all posts from a certain part of the forum, that customization wasn't implemented. If you do implement it, feel free to post.]
Posted:  01 Sep 2009 04:50
Now we will edit HTML file to give user option to change his preference. This part can easily be changed to suit your preference, I will just do in simplest way

Userpanel.htm in the skin folder

After privacy row (should already exist in your code)
Code:

<td class=formfield>{$lang['privacy']}</td>
<td class=formcell1>
<input type=checkbox name=emailpublic value=1 {$emailpublic_check}>{$lang['email_public']}<br>
<input type=checkbox name=viewonline value=1 {$viewonline_check}>{$lang['view_online']}
</td>
</tr>

we will add notification row
Code:

<tr>
<td class=formfield>Notifications</td>
<td class=formcell1>
<input type=checkbox name=usernotify_all value=1 {$notifyAll_check}>Notify me of all new posts.<br>
<input type=checkbox name=usernotify_active value=1 {$notifyActive_check}>Notify me when posts are added to a thread in which I am active.
</td>
</tr>


I didn't internationalize it, but it can easily be done following the style of the privacy row.

As you can see, there are two new check boxes added to html, and they are being set with $notifyAll_check and $notifyActive_check variables. In the next post we will see how we get and set those variables from and to database.
Posted:  01 Sep 2009 05:20   Last Edited By: steven
Now we will write the code that get the information from the database. We wont be writing new lines of code, just adding our variables into the existing code.

usercp.php in the root folder

we will be adding to the UPDATE query (2 places) [Bold Italics is the added code]
Code:

mysql_query("UPDATE {$dbpref}users
SET user_email='$useremail', user_timezone='$usertimezone', user_email_public='$emailpublic', user_allowviewonline='$viewonline', user_bio='$userbio', user_bio_status='$user_bio_status', user_pass='$newpass',
user_notify_all='$usernotify_all' ,user_notify_active='$usernotify_active'
WHERE user_id='$user_id'" );

Code:

mysql_query("UPDATE {$dbpref}users
SET user_email='$useremail', user_timezone='$usertimezone', user_email_public='$emailpublic', user_allowviewonline='$viewonline', user_bio_status='$user_bio_status', user_bio='$userbio',
user_notify_all='$usernotify_all' ,user_notify_active='$usernotify_active'
WHERE user_id='$user_id'" );

and the SELECT query [Bold Italics is the added code]
Code:

$result = mysql_query("SELECT user_email, user_timezone, user_email_public, user_allowviewonline, user_bio, user_bio_status, user_notify_all, user_notify_active FROM {$dbpref}users WHERE user_id = '$user_id'" );

list($useremail, $tz, $emailpublic, $viewonline, $userbio, $userbio_status, $usernotify_all, $usernotify_active) = mysql_fetch_row($result);


*In the update query we are filling the database with the value of the variable $usernotify_all and $usernotify_active.
*In the SELECT query the result array get the value from the database, and list function fills the variables $usernotify_all and $usernotify_active with the information.


There is 1 more edit in this file. This code needs to be added after SELECT query and list function
Code:

$notifyAll_check = ($usernotify_all == 1) ? 'checked' : null;
$notifyActive_check = ($usernotify_active == 1) ? 'checked' : null;

with that the information about users preference is contained in $notifyAll_check and $notifyActive_check variable.

This code should work with the database keeping the persistent info. I'll post the rest of the info for sending the notifications hopefully tomorrow.
Posted:  01 Sep 2009 05:45
When it comes to notifying, there are two times we will notify. 1)When new topic is created. 2)When comment is added to new topic.

First lets add code for when new topic is created. Since this is the first comment on the topic, the only one that needs to be notified is the users who want to be notified about all posts (except for the person actually posting who doesn't need to be notified since he is posting).

vForum.php in the root folder
Code:

$result_email = mysql_query("SELECT DISTINCT user_email FROM {$dbpref}users
                WHERE user_notify_all = 1  AND user_id != $user_id" );
    //if there are results
    if (mysql_num_rows($result_email)){
        require ('./code/mailer.php' );
        //create the message. this message includes the full message and link to webpage
        $message_to_send=r_b($message)."\n\n------------------------------------------------------------------\n\n
                    To reply to this thread visit the message page at \n".get_topic_url($topic_id, 1).'.';
        //loop through array and send email
        while($row = mysql_fetch_array($result_email,MYSQL_NUM)){      
            send_email("[My Forums]$topictitle", $message_to_send, $row[0], "noreply@myforums.com", $adminemail);
        }
    }

of course its necessary to change the name of forum and email address to match your site.

The right location for this info is towards the bottom of the file right before
Code:

header('Location: '.get_topic_url($topic_id, 1));

You can go ahead and test it. New topics should send out an email.
Posted:  01 Sep 2009 06:00   Last Edited By: steven
Now for the edits in the final file. When user replies to existing topic we have to notify anyone who previously commented and wants to be notified for topics in which they participated, and we will notify users who want to know about all new posts

vTopic.php in the root folder
Code:

$result_email = mysql_query("SELECT DISTINCT user_email FROM {$dbpref}users JOIN {$dbpref}posts ON {$dbpref}users.user_id = {$dbpref}posts.post_author_id WHERE (({$dbpref}users.user_notify_active = 1 AND seo_board_posts.topic_id = $t) OR {$dbpref}users.user_notify_all = 1 ) AND {$dbpref}users.user_id != $user_id" );
    //if there are results
    if (mysql_num_rows($result_email)){
        require ('./code/mailer.php' );
        //create the message. this message includes the full message and link to webpage
        $message_to_send=r_b($message)."\n\n------------------------------------------------------------------\n\n
                    To reply to this thread visit the message page at \n".get_topic_url($topic_id, 1).'.';
        //loop through array and send email
        while($row = mysql_fetch_array($result_email,MYSQL_NUM)){       
            send_email("[My Forums]$topictitle", $message_to_send, $row[0], "noreply@myforums.com", $adminemail);
        }
    }

As you can see its similar to previous, except SELECT query is a little more complicated, since it has to JOIN posts to figure out which users have posted in topic.

the location for this addition is right before
Code:

header( 'Location: '.get_topic_url($t, ceil(($num_replies+2)/$postsperpage)));


Thats it i'm done, let me know how it goes.

Note
If you have lots of notifications, you might want to disconnect from user before sending all the emails, so that there shouldn't be a big pause. Also you might want to wait a couple of ticks between emails, since there are reports of failures when trying to send lots of email in a loop without pause.

One more thing. It's intentional that we don't notify edits to a post, since the user shouldn't be getting multiple emails on the same post

Lots of Success
Steven
Posted:  02 Sep 2009 13:43
Steven,
great mod. My only concern is with big boards - lots of webhosts limit the number of emails sent using php's mail function.
At one point I thought I can make a custom rss for every user (he can get notified via a special rss link of new posts he has subscribed or to new posts with certain keywords etc.), but then I thought rss is not that popular and that kind of feature would be awkward.
It would be very handy for the users who are familiar with rss.
Posted:  02 Sep 2009 13:58
I don't really use php mail, rather I use php mailer since my host requires validation. I adapted the send_email function for my need.
Posted:  02 Sep 2009 20:32   Last Edited By: MusicalBox
Hi steven, thanks for this mod. Unfortunatly, something's wrong with my installation. Probably my fault.

Here's the message I get on top of user control panel page

Quote:
Notice: Undefined offset: 12 in /homez.43/sourisep/www/forum/usercp.php on line 226


line 226 looks like this :
Code:

list($useremail, $tz, $emailpublic, $viewonline, $userbio, $userbio_status, $usersignature, $user_signature_status, $user_view_signatures, $user_avatar, $user_view_avatars, $usernotify_all, $usernotify_active) = mysql_fetch_row($result);


You can see this line is different form your's, maybe we don't have the same version of SEO-Board, or maybe (more likely) it's because of other mods I've installed a long time ago.

On the control panel page I can check the checkboxes, but when I confirm the changes and then display the cp page again, the boxes are unchecked.

Do you (or someone else) have an advice to help me correct this problem ?

Just in case you need to see the two fields I added to seo_board_users table, here are captures from phpMyAdmin :

http://i284.photobucket.com/albums/ll26/MusicalBox63/SourisEpineuses/sqlcapture01.jpg

http://i284.photobucket.com/albums/ll26/MusicalBox63/SourisEpineuses/sqlcapture02.jpg

Thanks in advance for any help
Posted:  04 Sep 2009 00:43   Last Edited By: steven
Here is my image
http://scriptui.com/images/cp.jpg

as to line 226, we can't see anything unless we see the previous line that fills $result

and yes I don't have avatars, smilies etc.. so there will be small diffs.

If you want to pay for me to do it let me know and I will contact you

Good Luck
Posted:  04 Sep 2009 21:59   Last Edited By: MusicalBox
Hello again.
After reviewing the codes, I saw I forgot a couple of comas here and there. So the problems mentioned above are now solved. Thx

But now I have another issue.
After a reply to a message on the forum this happens :
Quote:
Fatal error: Call to undefined function: r_b() in /homez.43/sourisep/www/forum/vtopic.php on line 178


And when posting a new message on the board, I get this :

Quote:
Fatal error: Call to undefined function: r_b() in /homez.43/sourisep/www/forum/vforum.php on line 316


Any suggestions ?
Posted:  05 Sep 2009 20:06   Last Edited By: MusicalBox
Nevermind my previous post, I fixed it

Now the mod works at 95%.

So far I see two bugs.

1- When the mod is set to "Notify me when posts are added to a thread in which I am active." The title of the thread doesnt show in the email and part of the link is missing (the part that should include the tittle or ID of the thread.)

2- Now this could be a problem. As an admin I started a new subject in a category where only admins and moderators are alowed to read and post. My TestMember (who has neither admin or moderator rank) received an email notification of that post, with the content of the message.

Good work anyway, I love the mod. And my members were asking for this kind of tool for a long time. I just hope I can figure out how to correct those 2 little bugs
Posted:  06 Sep 2009 07:21
For The First Item, I Would Double Check The Code For The GetTopicUrl Function And See The Variable Used For The Title Url. As For The Moderator Issue, The SQL Code Needs To Be Tweaked And Is Beyond What I Am Willing To Do Without $.    By The Way Remove The r_b Function Its A Private Function Of Mine.
Posted:  18 Jun 2010 02:08
Great work steven hope hristo adds some features you used into next version..