first commit
This commit is contained in:
72
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/enchantspell.php
vendored
Normal file
72
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/enchantspell.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/spellchecker.php';
|
||||
|
||||
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
|
||||
*/
|
||||
public 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 {
|
||||
$this->throwError('Language not installed');
|
||||
}
|
||||
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
|
||||
*/
|
||||
public 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 {
|
||||
$this->throwError('Language not installed');
|
||||
}
|
||||
enchant_broker_free($r);
|
||||
|
||||
return $suggs;
|
||||
}
|
||||
}
|
||||
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/index.html
vendored
Normal file
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
95
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/pspell.php
vendored
Normal file
95
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/pspell.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/spellchecker.php';
|
||||
|
||||
/**
|
||||
* @author Moxiecode
|
||||
* @copyright Copyright (c) 2004-2007, Moxiecode Systems AB, All rights reserved
|
||||
*/
|
||||
class Pspell 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
|
||||
*/
|
||||
public function checkWords($lang, $words)
|
||||
{
|
||||
$plink = $this->getPLink($lang);
|
||||
|
||||
$outWords = array();
|
||||
foreach ($words as $word) {
|
||||
if (!pspell_check($plink, trim($word))) {
|
||||
$outWords[] = utf8_encode($word);
|
||||
}
|
||||
}
|
||||
|
||||
return $outWords;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function getSuggestions($lang, $word)
|
||||
{
|
||||
$words = pspell_suggest($this->getPLink($lang), $word);
|
||||
|
||||
for ($i = 0; $i < count($words); ++$i) {
|
||||
$words[$i] = utf8_encode($words[$i]);
|
||||
}
|
||||
|
||||
return $words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a link for pspell.
|
||||
*/
|
||||
private function getPLink($lang)
|
||||
{
|
||||
// Check for native PSpell support
|
||||
if (!function_exists('pspell_new')) {
|
||||
$this->throwError('PSpell support not found in PHP installation.');
|
||||
}
|
||||
|
||||
$pspell_config = pspell_config_create(
|
||||
$lang,
|
||||
$this->_config['PSpell.spelling'],
|
||||
$this->_config['PSpell.jargon'],
|
||||
$this->_config['PSpell.encoding']
|
||||
);
|
||||
|
||||
pspell_config_personal($pspell_config, $this->_config['PSpell.dictionary']);
|
||||
$plink = pspell_new_config($pspell_config);
|
||||
|
||||
if (!$plink) {
|
||||
$this->throwError('No PSpell link found opened.');
|
||||
}
|
||||
|
||||
return $plink;
|
||||
}
|
||||
/**
|
||||
* Add a word to the PSPell personal dictionary
|
||||
* From http://slack5.com/blog/2008/12/tinymce-add-to-dictionary/.
|
||||
*
|
||||
* @param object $lang
|
||||
* @param object $word
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function addToDictionary($lang, $word)
|
||||
{
|
||||
$plink = $this->getPLink($lang);
|
||||
pspell_add_to_personal($plink, $word);
|
||||
pspell_save_wordlist($plink);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
69
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/spellchecker.php
vendored
Normal file
69
components/com_jce/editor/tiny_mce/plugins/spellchecker/classes/spellchecker.php
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Moxiecode
|
||||
* @copyright Copyright (c) 2004-2007, Moxiecode Systems AB, All rights reserved
|
||||
*/
|
||||
class SpellChecker
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param $config Configuration name/value array
|
||||
*/
|
||||
public function SpellChecker(&$config)
|
||||
{
|
||||
$this->_config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple loopback function everything that gets in will be send back.
|
||||
*
|
||||
* @param $args.. Arguments
|
||||
*
|
||||
* @return {Array} Array of all input arguments
|
||||
*/
|
||||
protected function loopback( /* args.. */)
|
||||
{
|
||||
return func_get_args();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function checkWords($lang, $words)
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function getSuggestions($lang, $word)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error message back to the user. This will stop all execution.
|
||||
*
|
||||
* @param {String} $str Message to send back to user
|
||||
*/
|
||||
protected function throwError($str)
|
||||
{
|
||||
die('{"result":null,"id":null,"error":{"errstr":"' . addslashes($str) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
|
||||
}
|
||||
}
|
||||
63
components/com_jce/editor/tiny_mce/plugins/spellchecker/config.php
vendored
Normal file
63
components/com_jce/editor/tiny_mce/plugins/spellchecker/config.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
class WFSpellcheckerPluginConfig
|
||||
{
|
||||
public static function getConfig(&$settings)
|
||||
{
|
||||
$wf = WFApplication::getInstance();
|
||||
$engine = $wf->getParam('spellchecker.engine', 'browser', 'browser');
|
||||
|
||||
switch ($engine) {
|
||||
default:
|
||||
case 'browser':
|
||||
case 'googlespell':
|
||||
$languages = '';
|
||||
|
||||
$settings['spellchecker_browser_state'] = $wf->getParam('spellchecker.browser_state', 0, 0);
|
||||
|
||||
$engine = 'browser';
|
||||
|
||||
break;
|
||||
|
||||
case 'pspell':
|
||||
case 'pspellshell':
|
||||
$languages = (array) $wf->getParam('spellchecker.languages', 'English=en', '');
|
||||
|
||||
if ($engine === 'pspellshell') {
|
||||
$engine = 'pspell';
|
||||
}
|
||||
|
||||
if (!function_exists('pspell_new')) {
|
||||
$engine = 'browser';
|
||||
}
|
||||
|
||||
break;
|
||||
case 'enchantspell':
|
||||
$languages = (array) $wf->getParam('spellchecker.languages', 'English=en', '');
|
||||
|
||||
if (!function_exists('enchant_broker_init')) {
|
||||
$engine = 'browser';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($languages)) {
|
||||
$settings['spellchecker_languages'] = '+'.implode(',', $languages);
|
||||
}
|
||||
|
||||
// only needs to be set if not "browser"
|
||||
if ($engine !== "browser") {
|
||||
$settings['spellchecker_engine'] = $engine;
|
||||
|
||||
$settings['spellchecker_suggestions'] = $wf->getParam('spellchecker.suggestions', 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/css/content.css
vendored
Normal file
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/css/content.css
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.mce-item-hiddenspellword{background:url(../img/wline.gif) bottom left repeat-x;cursor:default}
|
||||
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/css/index.html
vendored
Normal file
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/css/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
2
components/com_jce/editor/tiny_mce/plugins/spellchecker/editor_plugin.js
vendored
Normal file
2
components/com_jce/editor/tiny_mce/plugins/spellchecker/editor_plugin.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/img/index.html
vendored
Normal file
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/img/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
BIN
components/com_jce/editor/tiny_mce/plugins/spellchecker/img/wline.gif
vendored
Normal file
BIN
components/com_jce/editor/tiny_mce/plugins/spellchecker/img/wline.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 B |
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/index.html
vendored
Normal file
1
components/com_jce/editor/tiny_mce/plugins/spellchecker/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
96
components/com_jce/editor/tiny_mce/plugins/spellchecker/spellchecker.php
vendored
Normal file
96
components/com_jce/editor/tiny_mce/plugins/spellchecker/spellchecker.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
require_once WF_EDITOR_LIBRARIES . '/classes/plugin.php';
|
||||
|
||||
class WFSpellCheckerPlugin extends WFEditorPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor activating the default information of the class.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$engine = $this->getEngine();
|
||||
|
||||
if (!$engine) {
|
||||
self::error('No Spellchecker Engine available');
|
||||
}
|
||||
|
||||
$request = WFRequest::getInstance();
|
||||
|
||||
// Setup plugin XHR callback functions
|
||||
$request->setRequest(array($engine, 'checkWords'));
|
||||
$request->setRequest(array($engine, 'getSuggestions'));
|
||||
$request->setRequest(array($engine, 'ignoreWord'));
|
||||
$request->setRequest(array($engine, 'ignoreWords'));
|
||||
$request->setRequest(array($engine, 'learnWord'));
|
||||
|
||||
$this->execute();
|
||||
}
|
||||
|
||||
private function getConfig()
|
||||
{
|
||||
static $config;
|
||||
|
||||
if (empty($config)) {
|
||||
|
||||
$config = array(
|
||||
// PSpell settings
|
||||
'PSpell.mode' => $this->getParam('spellchecker.pspell_mode', 'PSPELL_FAST'),
|
||||
'PSpell.spelling' => $this->getParam('spellchecker.pspell_spelling', ''),
|
||||
'PSpell.jargon' => $this->getParam('spellchecker.pspell_jargon', ''),
|
||||
'PSpell.encoding' => $this->getParam('spellchecker.pspell_encoding', ''),
|
||||
'PSpell.dictionary' => JPATH_BASE . '/' . $this->getParam('spellchecker.pspell_dictionary', ''),
|
||||
);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
private function getEngine()
|
||||
{
|
||||
static $instance;
|
||||
|
||||
if (!is_object($instance)) {
|
||||
$classname = '';
|
||||
$config = array();
|
||||
|
||||
$engine = $this->getParam('spellchecker.engine', 'browser', 'browser');
|
||||
|
||||
if (($engine === 'pspell' || $engine === 'pspellshell') && function_exists('pspell_new')) {
|
||||
$classname = 'PSpell';
|
||||
|
||||
$config = $this->getConfig();
|
||||
}
|
||||
|
||||
if ($engine === 'enchantspell' && function_exists('enchant_broker_init')) {
|
||||
$classname = 'Enchantspell';
|
||||
}
|
||||
|
||||
if (!empty($classname)) {
|
||||
$file = __DIR__ . '/classes/' . strtolower($classname) . '.php';
|
||||
|
||||
if (is_file($file)) {
|
||||
require_once $file;
|
||||
$instance = new $classname($config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
private static function error($str)
|
||||
{
|
||||
die('{"result":null,"id":null,"error":{"errstr":"' . addslashes($str) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
|
||||
}
|
||||
}
|
||||
55
components/com_jce/editor/tiny_mce/plugins/spellchecker/spellchecker.xml
vendored
Normal file
55
components/com_jce/editor/tiny_mce/plugins/spellchecker/spellchecker.xml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" ?>
|
||||
<extension version="3.4" type="plugin" group="jce" method="upgrade">
|
||||
<name>WF_SPELLCHECKER_TITLE</name>
|
||||
<version>2.9.32</version>
|
||||
<creationDate>01-11-2022</creationDate>
|
||||
<author>Ryan Demmer</author>
|
||||
<authorEmail>info@joomlacontenteditor.net</authorEmail>
|
||||
<authorUrl>https://www.joomlacontenteditor.net/</authorUrl>
|
||||
<copyright>Copyright (C) 2006 - 2022 Ryan Demmer. All rights reserved</copyright>
|
||||
<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
|
||||
<description>WF_SPELLCHECKER_DESC</description>
|
||||
<icon>spellchecker</icon>
|
||||
<fields name="spellchecker">
|
||||
<fieldset name="config">
|
||||
<field name="engine" type="list" default="browser" label="WF_SPELLCHECKER_PARAM_ENGINE" description="WF_SPELLCHECKER_PARAM_ENGINE_DESC">
|
||||
<option value="browser">WF_SPELLCHECKER_PARAM_BROWSER</option>
|
||||
<option value="pspell">WF_SPELLCHECKER_PARAM_PSPELL_PHP</option>
|
||||
<option value="enchantspell">WF_SPELLCHECKER_PARAM_ENCHANT</option>
|
||||
</field>
|
||||
|
||||
<field name="browser_state" type="yesno" default="0" label="WF_OPTION_STATE" description="WF_SPELLCHECKER_BROWSER_STATE_DESC" showon="engine:browser">
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field name="suggestions" type="yesno" default="1" label="WF_SPELLCHECKER_SUGGESTIONS" description="WF_SPELLCHECKER_SUGGESTIONS_DESC" showon="engine!:browser">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
|
||||
<!--param name="googlespell_languages" type="list" class="checklist sortable" multiple="multiple" default="English=en" label="WF_SPELLCHECKER_PARAM_LANGUAGES" description="WF_SPELLCHECKER_PARAM_GOOGLESPELL_LANGUAGES_DESC" parent="engine[googlespell]">
|
||||
<option value="English=en">English</option>
|
||||
<option value="Danish=da">Danish</option>
|
||||
<option value="Dutch=nl">Dutch</option>
|
||||
<option value="Finnish=fi">Finnish</option>
|
||||
<option value="French=fr">French</option>
|
||||
<option value="German=de">German</option>
|
||||
<option value="Italian=it">Italian</option>
|
||||
<option value="Polish=pl">Polish</option>
|
||||
<option value="Portuguese=pt">Portuguese(BR)</option>
|
||||
<option value="Spanish=es">Spanish</option>
|
||||
<option value="Swedish=sv">Swedish</option>
|
||||
</param-->
|
||||
|
||||
<field name="languages" type="text" size="100" default="English=en" label="WF_SPELLCHECKER_PARAM_LANGUAGES" description="WF_SPELLCHECKER_PARAM_LANGUAGES_DESC" showon="engine!:browser" />
|
||||
<field name="pspell_mode" type="text" default="PSPELL_FAST" label="WF_SPELLCHECKER_PARAM_PSPELL_MODE" description="WF_SPELLCHECKER_PARAM_PSPELL_MODE_DESC" showon="engine:pspell" />
|
||||
<field name="pspell_spelling" type="text" default="" label="WF_SPELLCHECKER_PARAM_PSPELL_SPELLING" description="WF_SPELLCHECKER_PARAM_PSPELL_SPELLING_DESC" showon="engine:pspell" />
|
||||
<field name="pspell_jargon" type="text" default="" label="WF_SPELLCHECKER_PARAM_PSPELL_JARGON" description="WF_SPELLCHECKER_PARAM_PSPELL_JARGON_DESC" showon="engine:pspell" />
|
||||
<field name="pspell_encoding" type="text" default="" label="WF_SPELLCHECKER_PARAM_PSPELL_ENCODING" description="WF_SPELLCHECKER_PARAM_PSPELL_ENCODING_DESC" showon="engine:pspell" />
|
||||
<field name="pspell_dictionary" type="text" size="100" default="components/com_jce/editor/tiny_mce/plugins/spellchecker/dictionary.pws" label="WF_SPELLCHECKER_PARAM_PSPELL_DICTIONARY" description="WF_SPELLCHECKER_PARAM_PSPELL_DICTIONARY_DESC" showon="engine:pspell" />
|
||||
<field name="pspellshell_aspell" type="text" default="/usr/bin/aspell" label="WF_SPELLCHECKER_PARAM_PSPELLSHELL" description="WF_SPELLCHECKER_PARAM_PSPELLSHELL_DESC" showon="engine:pspell" />
|
||||
<field name="pspellshell_tmp" type="text" default="/tmp" label="WF_SPELLCHECKER_PARAM_PSPELLSHELL_TMP" description="WF_SPELLCHECKER_PARAM_PSPELLSHELL_TMP_DESC" showon="engine:pspell" />
|
||||
</fieldset>
|
||||
</fields>
|
||||
</extension>
|
||||
Reference in New Issue
Block a user