Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Commit

Permalink
Initial convert over to Git
Browse files Browse the repository at this point in the history
  • Loading branch information
spocke committed Jan 13, 2010
0 parents commit d237b5f
Show file tree
Hide file tree
Showing 22 changed files with 2,052 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* crlf=input
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bin
obj
tmp
docs
.settings
*~
*.diff
*.patch
*.bak
*.log
.DS_Store
editor_plugin.js
2 changes: 2 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
ant -q %*
64 changes: 64 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="TinyMCE" default="build" basedir=".">
<property description="Export directory" name="temp_dir" value="tmp" />

<!-- Allow any user specific values to override the defaults -->
<property file="${user.home}/tinymce_spellchecker_php_build.properties" />

<!-- Setup classpath for js-build-tools ant tasks -->
<path id="tasks.classpath">
<pathelement location="."/>

<fileset dir="tools/ant">
<include name="**/*.jar"/>
</fileset>
</path>

<!-- Register new js-build-tools ant tasks -->
<taskdef name="preprocess" classname="com.moxiecode.ant.tasks.PreProcessTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef name="yuicompress" classname="com.moxiecode.ant.tasks.YuiCompressTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef name="moxiedoc" classname="com.moxiecode.ant.tasks.MoxieDocTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />

<!-- Cleanup the build -->
<target name="clean" depends="" description="Cleans up the project from temporary files">
<delete dir="${temp_dir}" quiet="true" />
</target>

<target name="build" depends="" description="Build the editor plugin">
<yuicompress infile="editor_plugin_src.js" outfile="editor_plugin.js" />
</target>

<target name="release" depends="" description="Builds a release package">
<!-- Copy the current repos and start processing it -->
<delete dir="${temp_dir}" quiet="true" />
<copy todir="${temp_dir}/spellchecker_php">
<fileset dir=".">
<include name="**"/>
<exclude name="**/.*"/>
<exclude name="tools/**"/>
<exclude name="build.*"/>
<exclude name="readme.md"/>
</fileset>
</copy>

<!-- Parse minor version, major version and release date from changelog -->
<loadfile property="changelog" srcFile="${temp_dir}/spellchecker_php/changelog.txt" />
<propertyregex property="version" input="${changelog}" regexp="^Version ([0-9xabrc.]+)" select="\1" />
<propertyregex property="release_date" input="${changelog}" regexp="^Version [^\(]+\(([^\)]+)\)" select="\1" />
<propertyregex property="file_version" input="${version}" regexp="\." replace="_" />

<!-- Replace backend with php -->
<replaceregexp match="\&quot;\{backend\}\&quot;" replace="this.url+'/rpc.php'" flags="g" byline="true">
<fileset dir="${temp_dir}">
<include name="**/*.js*" />
</fileset>
</replaceregexp>

<!-- Compress development package -->
<delete file="${temp_dir}/tinymce_spellchecker_php_${file_version}.zip" quiet="true" />
<zip destfile="${temp_dir}/tinymce_spellchecker_php_${file_version}.zip">
<zipfileset dir="${temp_dir}/spellchecker_php" prefix="spellchecker"/>
</zip>
</target>
</project>
23 changes: 23 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Version 2.0.3 (2008-0x-xx)
Added @package phpdoc comments. Patch contributed by Jacob Santos.
Fixed some PHP missing function issue.
Version 2.0.2 (2008-04-30)
Added new EnchantSpell engine class contributed by Michel Weimerskirch.
Added new general.remote_rpc_url option, enables you to proxy requests to another server.
Fixed security hole in PSpellShell.php file if PSpellShell engine was used.
Version 2.0.1 (2008-03-07)
Fixed bug where spellchecker was auto focusing the editor in IE.
Version 2.0 (2008-01-30)
Fixed bug where the suggestions menu was placed at an incorrect location.
Version 2.0rc1 (2008-01-14)
Moved package from beta to release candidate.
Version 2.0b3 (2007-12-xx)
Fixed bug where the suggestions menu could appear at the wrong location.
Version 2.0b2 (2007-11-29)
Fixed bug where the spellchecker was removing the word when it was ignored.
Version 2.0b1 (2007-11-21)
Moved spellchecker from alpha to beta status.
Version 2.0a2 (2007-11-13)
Updated plugin so it works correctly with the TinyMCE 3.0a3 version.
Version 2.0a1 (2007-11-01)
Rewritten version for TinyMCE 3.0 this new version uses JSON RPC.
67 changes: 67 additions & 0 deletions classes/EnchantSpell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
*
* This class was contributed by Michel Weimerskirch.
*
* @package MCManager.includes
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/

class EnchantSpell extends SpellChecker {
/**
* Spellchecks an array of words.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param Array $words Array of words to check.
* @return Array of misspelled words.
*/
function &checkWords($lang, $words) {
$r = enchant_broker_init();

if (enchant_broker_dict_exists($r,$lang)) {
$d = enchant_broker_request_dict($r, $lang);

$returnData = array();
foreach($words as $key => $value) {
$correct = enchant_dict_check($d, $value);
if(!$correct) {
$returnData[] = trim($value);
}
}

return $returnData;
enchant_broker_free_dict($d);
} else {

}
enchant_broker_free($r);
}

/**
* Returns suggestions for a specific word.
*
* @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
* @param String $word Specific word to get suggestions for.
* @return Array of suggestions for the specified word.
*/
function &getSuggestions($lang, $word) {
$r = enchant_broker_init();
$suggs = array();

if (enchant_broker_dict_exists($r,$lang)) {
$d = enchant_broker_request_dict($r, $lang);
$suggs = enchant_dict_suggest($d, $word);

enchant_broker_free_dict($d);
} else {

}
enchant_broker_free($r);

return $suggs;
}
}

?>
159 changes: 159 additions & 0 deletions classes/GoogleSpell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php
/**
* $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
*
* @package MCManager.includes
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/

class GoogleSpell extends SpellChecker {
/**
* Spellchecks an array of words.
*
* @param {String} $lang Language code like sv or en.
* @param {Array} $words Array of words to spellcheck.
* @return {Array} Array of misspelled words.
*/
function &checkWords($lang, $words) {
$wordstr = implode(' ', $words);
$matches = $this->_getMatches($lang, $wordstr);
$words = array();

for ($i=0; $i<count($matches); $i++)
$words[] = $this->_unhtmlentities(mb_substr($wordstr, $matches[$i][1], $matches[$i][2], "UTF-8"));

return $words;
}

/**
* Returns suggestions of for a specific word.
*
* @param {String} $lang Language code like sv or en.
* @param {String} $word Specific word to get suggestions for.
* @return {Array} Array of suggestions for the specified word.
*/
function &getSuggestions($lang, $word) {
$sug = array();
$osug = array();
$matches = $this->_getMatches($lang, $word);

if (count($matches) > 0)
$sug = explode("\t", utf8_encode($this->_unhtmlentities($matches[0][4])));

// Remove empty
foreach ($sug as $item) {
if ($item)
$osug[] = $item;
}

return $osug;
}

function &_getMatches($lang, $str) {
$server = "www.google.com";
$port = 443;
$path = "/tbproxy/spell?lang=" . $lang . "&hl=en";
$host = "www.google.com";
$url = "https://" . $server;

// Setup XML request
$xml = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>' . $str . '</text></spellrequest>';

$header = "POST ".$path." HTTP/1.0 \r\n";
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type: application/PTI26 \r\n";
$header .= "Content-length: ".strlen($xml)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Request-number: 1 \r\n";
$header .= "Document-type: Request \r\n";
$header .= "Interface-Version: Test 1.4 \r\n";
$header .= "Connection: close \r\n\r\n";
$header .= $xml;

// Use curl if it exists
if (function_exists('curl_init')) {
// Use curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$xml = curl_exec($ch);
curl_close($ch);
} else {
// Use raw sockets
$fp = fsockopen("ssl://" . $server, $port, $errno, $errstr, 30);
if ($fp) {
// Send request
fwrite($fp, $header);

// Read response
$xml = "";
while (!feof($fp))
$xml .= fgets($fp, 128);

fclose($fp);
} else
echo "Could not open SSL connection to google.";
}

// Grab and parse content
$matches = array();
preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER);

return $matches;
}

function _unhtmlentities($string) {
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);

$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);

return strtr($string, $trans_tbl);
}
}

// Patch in multibyte support
if (!function_exists('mb_substr')) {
function mb_substr($str, $start, $len = '', $encoding="UTF-8"){
$limit = strlen($str);

for ($s = 0; $start > 0;--$start) {// found the real start
if ($s >= $limit)
break;

if ($str[$s] <= "\x7F")
++$s;
else {
++$s; // skip length

while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")
++$s;
}
}

if ($len == '')
return substr($str, $s);
else
for ($e = $s; $len > 0; --$len) {//found the real end
if ($e >= $limit)
break;

if ($str[$e] <= "\x7F")
++$e;
else {
++$e;//skip length

while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)
++$e;
}
}

return substr($str, $s, $e - $s);
}
}

?>
Loading

0 comments on commit d237b5f

Please sign in to comment.