User Tools

Site Tools


nupusi:punbb:tutorials:spellcheck

Adding phpSpell to PunBB

Contributed by Smartys

Step 1.

Download and unzip phpSpell.

Step 2.

Open common/spell_config.php

Comment the line that says 
$Spell_Config['DB_Type'] = 'PHPBB'; 
and 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';
  }

Step 3.

Change any other settings and save.

Step 4.

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

Step 5.

Step 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).

Step 7.

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

Step 8.

Delete the spell_admin.php file off the server.

Step 9.

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

FIND
<pun_head>
AFTER, ADD
<script language='javascript' src='spelling/spellmessage.js'></script>

Step 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)">';

Step 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);
        }

Step 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)

nupusi/punbb/tutorials/spellcheck.txt · Last modified: 2008/12/06 13:56 (external edit)