Add a spellchecker

From PunBB Resource Wiki

Jump to: navigation, search

Contributed by Smartys

Installation

1. Download and unzip phpSpell.

2. Open common/spell_config.php Comment the line that says:

$Spell_Config['DB_Type'] = 'PHPBB';

Add a line that says:

$Spell_Config['DB_Type'] = 'PunBB';

FIND

  if (isset($Spell_Config['DB_Type']) && $Spell_Config['DB_Type'] == 'MySQL') {
    include 'spell_MySQL.php';
  }

AFTER, ADD

  if (isset($Spell_Config['DB_Type']) && $Spell_Config['DB_Type'] == 'PunBB') {
 
    require '../config.php';
    $Spell_Config["DB_Username"] = $db_username;
    $Spell_Config["DB_Password"] = $db_password;
    $Spell_Config["DB_Database"] = $db_name;
    $Spell_Config["DB_Host"] = $db_host;
    // This is used in some others, but it looks like this is unset in the file: odd
    $table_prefix = $db_prefix;
 
    include 'spell_MySQL.php';
  }

3. Change any other settings and save.

4. Create a directory within your forum directory called spelling and upload all the files in the common & native_mysql directories to there

5. Go to http://www.yourwebsite.com/forum_directory/spelling/spell_admin.php

6. Install any dictionaries you want (you have to download them from the site in Step 1 and put them in the spelling folder first).

7. Delete any file ending with .dic on the server (to free up disk space)

8. Delete the spell_admin.php file off the server.

9. Open up include/template/main.tpl (PunBB)

FIND

<pun_head>

AFTER, ADD

<script language='javascript' src='spelling/spellmessage.js'></script>

10. Open up post.php

FIND

<p><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="s" /><input type="submit" name="preview" value="<?php echo $lang_post['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>

REPLACE WITH

<p><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="s" /><input type="submit" name="preview" value="<?php echo $lang_post['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /><input type="button" value="Spell Check" onclick="openspell();" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>

FIND

$form = '<form id="post" method="post" action="post.php?action=post&amp;tid='.$tid.'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';

REPLACE WITH

$form = '<form name="spelling_mod" id="post" method="post" action="post.php?action=post&amp;tid='.$tid.'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';

FIND

$form = '<form id="post" method="post" action="post.php?action=post&amp;fid='.$fid.'" onsubmit="return process_form(this)">';

REPLACE WITH

$form = '<form name="spelling_mod" id="post" method="post" action="post.php?action=post&amp;fid='.$fid.'" onsubmit="return process_form(this)">';

11. Replace spelling/spellmessage.js with the following code

// --------------------------------------------------------------------
// phpSpell Javascript (For the PHPBB Message Document)
//
// This is (c)Copyright 2003, Team phpSpell.
// --------------------------------------------------------------------
        var ie4 = (document.all) ? 1:0;
        var gecko=(navigator.userAgent.indexOf('Gecko') > -1) ? 1:0;
        var op6=(navigator.userAgent.indexOf('Opera/6') > -1) ? 1:0;
        var op7=(navigator.userAgent.indexOf('Opera/7') > -1) ? 1 : (navigator.userAgent.indexOf('Opera 7') > -1) ? 1:0;
        var ns4=(navigator.userAgent.indexOf('Mozilla/4.7') > -1) ? 1:0;
        var sf=(navigator.userAgent.indexOf('Safari') > -1) ? 1:0;
        if (op7) ie4 = 0;
        if (sf) {
          ie4 = 0;
          gecko = 1;
        }
 
 
        var LinkToField = "";
 
        function openspell()
        {
          height = 391;
          width = 555;
          if (ie4) LinkToField = self.spelling_mod.req_message;
          if (gecko) {
            LinkToField = parent.document.spelling_mod.req_message;
            height = height + 6;
          }
          if (op6) {
             LinkToField = document.forms[0].req_message;
             height = height + 10;
             width = width + 10;
          }
          if (op7) LinkToField = document.forms[0].req_message;
 
          if (!(op6 || gecko || ie4 || op7)) {
            alert("phpSpell only supports one of the following browsers:nOpera 6+, Netscape 6+, Mozilla 1+, Internet Explorer 4+, Safari");
          } else {
            if (LinkToField.value.length == 0) return;
            directory = "spelling/";
            k = openspell.arguments.length;
            if (k == 1) directory = "";
            win1=window.open(directory+"phpSpell.html","spellcheckwin",'resizable=no,width='+width+',height='+height);
            if (win1.opener == null) win1.opener = self;
          }
          return (false);
        }
 
        function Opera_Get_Link() {
          return (LinkToField);
        }

12. You're done! If you want to add spell check functionality to the quick reply form or the edit post form, take a look at step 12 and make similar edits in the correct files (viewtopic.php and edit.php)


Notes from a success story by CableGuy...

If you are having trouble getting the .dic file to be acceptable to your server, try dicing it up into smaller chunks. I couldn't get anything but an internal server error until I cut it down to about 20K a crack. Then it worked like a champ. Thanks Smarty for the excellent tutorial!

Notes from a failure by billw...

This is easily the most vexing mod I've encountered. spell_admin.php chokes no matter which database type I define:

You must choose a Database Type in the Spell Configuration file.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox