From 9fad5b84ab7f468f0991a668e0cc0d0e3883d854 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Wed, 16 Nov 2011 09:15:41 +0000 Subject: [PATCH] * ckeditor/aspell: added check for language availability check on extended dict (Lang_Countrycode) first, then fall back to lang -> e.g.: check on en_GB, if not available try using en --- phpgwapi/js/ckeditor3/egw_integration.txt | 92 ++++++++++++++++++- .../server-scripts/spellchecker.php | 63 +++++++++---- 2 files changed, 136 insertions(+), 19 deletions(-) diff --git a/phpgwapi/js/ckeditor3/egw_integration.txt b/phpgwapi/js/ckeditor3/egw_integration.txt index 859fb11d1c..d5671892f3 100644 --- a/phpgwapi/js/ckeditor3/egw_integration.txt +++ b/phpgwapi/js/ckeditor3/egw_integration.txt @@ -1,6 +1,5 @@ --------------- step 1 -------------------------------------- removed _samples directory -removed _source folder --------------- step 2 -------------------------------------- -added aspell as plugin, as it is not available by default anymore. @@ -9,4 +8,95 @@ removed _source folder to allow only configured aspell, tmp dirs and language settings -removed other than php spellchecker pages from phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/ -added toolbar options to reflect the use/change of calls of SpellCheck(er) via toolbar button +-added an availability check on dicts (see below) +Index: phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php +=================================================================== +--- phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php (Revision 37235) ++++ phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php (Arbeitskopie) +@@ -24,17 +24,16 @@ + // will not continue, unless the header get's included and there is a valid eGW session + require('../../../../../../../header.inc.php'); + +-if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'])) +-{ +- $lang = $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']; +-} +-else +-{ +- $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; +-} ++$lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? ++ $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: ++ $GLOBALS['egw_info']['user']['preferences']['common']['lang']); + +-$aspell_opts = '-a '.escapeshellarg('--lang='.$lang).' --encoding=utf-8 -H --rem-sgml-check=alt'; // by FredCK ++$country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; + ++$lang_ext = $lang.'_'.$country; ++$langs = getDictLangs(); ++ ++$aspell_opts = '-a '.escapeshellarg('--lang='.(in_array($lang_ext,$langs)?$lang_ext:$lang)).' --encoding=utf-8 -H --rem-sgml-check=alt'; // by FredCK + $tempfiledir = "./"; + + $spellercss = '../spellerStyle.css'; // by FredCK +@@ -43,6 +42,42 @@ + $textinputs = $_POST['textinputs']; # array + $input_separator = "A"; + ++function getDictLangs() ++{ ++ static $langs; ++ if (is_null($langs)) $langs = egw_cache::getCache(egw_cache::TREE,'spellckecher','aspellDictLangs',$callback=null,$callback_params=array(),$expiration=60*60*1); ++ if (isset($langs) && !empty($langs)) return $langs; ++ $langs = array(); ++ $aspell_prog = getAspellPath(); ++ $cmd = "$aspell_prog dump dicts"; ++ if( $aspellret = shell_exec( $cmd )) { ++ $linesout = explode( "\n", $aspellret ); ++ $index = 0; ++ $text_input_index = -1; ++ # parse each line of aspell return ++ foreach( $linesout as $key=>$val ) { ++ //error_log('spellerpages'.__LINE__.' : '.trim($val)); ++ $langs[] = trim($val); ++ } ++ } ++ egw_cache::setCache(egw_cache::TREE,'spellchecker','aspellDictLangs',$langs,$expiration=60*60*1); ++ return $langs; ++} ++ ++function getAspellPath() ++{ ++ if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && ++ is_executable($GLOBALS['egw_info']['server']['aspell_path'])) ++ { ++ $aspell_prog = $GLOBALS['egw_info']['server']['aspell_path']; ++ } ++ else // little fallback that might save linux users ++ { ++ $aspell_prog = 'aspell'; ++ } ++ return $aspell_prog; ++} ++ + # set the JavaScript variable to the submitted text. + # textinputs is an array, each element corresponding to the (url-encoded) + # value of the text control submitted for spell-checking +@@ -101,15 +136,7 @@ + global $textinputs; + global $input_separator; + $aspell_err = ""; +- if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && +- is_executable($GLOBALS['egw_info']['server']['aspell_path'])) +- { +- $aspell_prog = $GLOBALS['egw_info']['server']['aspell_path']; +- } +- else // little fallback that might save linux users +- { +- $aspell_prog = 'aspell'; +- } ++ $aspell_prog = getAspellPath(); + + # create temp file + // use EGroupware's temp_dir diff --git a/phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php b/phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php index fa063a1329..7d20bba7a5 100644 --- a/phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php +++ b/phpgwapi/js/ckeditor3/plugins/aspell/spellerpages/server-scripts/spellchecker.php @@ -24,17 +24,16 @@ $GLOBALS['egw_info'] = array( // will not continue, unless the header get's included and there is a valid eGW session require('../../../../../../../header.inc.php'); -if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'])) -{ - $lang = $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']; -} -else -{ - $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; -} +$lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ? + $GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']: + $GLOBALS['egw_info']['user']['preferences']['common']['lang']); -$aspell_opts = '-a '.escapeshellarg('--lang='.$lang).' --encoding=utf-8 -H --rem-sgml-check=alt'; // by FredCK +$country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; +$lang_ext = $lang.'_'.$country; +$langs = getDictLangs(); + +$aspell_opts = '-a '.escapeshellarg('--lang='.(in_array($lang_ext,$langs)?$lang_ext:$lang)).' --encoding=utf-8 -H --rem-sgml-check=alt'; // by FredCK $tempfiledir = "./"; $spellercss = '../spellerStyle.css'; // by FredCK @@ -43,6 +42,42 @@ $word_win_src = '../wordWindow.js'; // by FredCK $textinputs = $_POST['textinputs']; # array $input_separator = "A"; +function getDictLangs() +{ + static $langs; + if (is_null($langs)) $langs = egw_cache::getCache(egw_cache::TREE,'spellckecher','aspellDictLangs',$callback=null,$callback_params=array(),$expiration=60*60*1); + if (isset($langs) && !empty($langs)) return $langs; + $langs = array(); + $aspell_prog = getAspellPath(); + $cmd = "$aspell_prog dump dicts"; + if( $aspellret = shell_exec( $cmd )) { + $linesout = explode( "\n", $aspellret ); + $index = 0; + $text_input_index = -1; + # parse each line of aspell return + foreach( $linesout as $key=>$val ) { + //error_log('spellerpages'.__LINE__.' : '.trim($val)); + $langs[] = trim($val); + } + } + egw_cache::setCache(egw_cache::TREE,'spellchecker','aspellDictLangs',$langs,$expiration=60*60*1); + return $langs; +} + +function getAspellPath() +{ + if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && + is_executable($GLOBALS['egw_info']['server']['aspell_path'])) + { + $aspell_prog = $GLOBALS['egw_info']['server']['aspell_path']; + } + else // little fallback that might save linux users + { + $aspell_prog = 'aspell'; + } + return $aspell_prog; +} + # set the JavaScript variable to the submitted text. # textinputs is an array, each element corresponding to the (url-encoded) # value of the text control submitted for spell-checking @@ -101,15 +136,7 @@ function print_checker_results() { global $textinputs; global $input_separator; $aspell_err = ""; - if (!empty($GLOBALS['egw_info']['server']['aspell_path']) && - is_executable($GLOBALS['egw_info']['server']['aspell_path'])) - { - $aspell_prog = $GLOBALS['egw_info']['server']['aspell_path']; - } - else // little fallback that might save linux users - { - $aspell_prog = 'aspell'; - } + $aspell_prog = getAspellPath(); # create temp file // use EGroupware's temp_dir