Added support for the new CKEditor 3.2.1

This commit is contained in:
Andreas Stöckel 2010-05-25 07:47:57 +00:00
parent ed9847b625
commit 12c03a226d

View File

@ -539,10 +539,13 @@ class html
*/ */
static function htmlarea_availible() static function htmlarea_availible()
{ {
require_once(EGW_INCLUDE_ROOT.'/phpgwapi/js/fckeditor/fckeditor.php'); /* require_once(EGW_INCLUDE_ROOT.'/phpgwapi/js/fckeditor/fckeditor.php');
// use FCKeditor's own check // use FCKeditor's own check
return FCKeditor_IsCompatibleBrowser(); return FCKeditor_IsCompatibleBrowser();*/
//CKeditor3 will check availability for us
return true;
} }
/** /**
@ -552,10 +555,10 @@ class html
*/ */
static function htmlarea($name,$content='',$style='',$base_href='',$plugins='',$custom_toolbar='',$set_width_height_in_config=false) static function htmlarea($name,$content='',$style='',$base_href='',$plugins='',$custom_toolbar='',$set_width_height_in_config=false)
{ {
if (!self::htmlarea_availible()) /*if (!self::htmlarea_availible())
{ {
return self::textarea($name,$content,'style="'.$style.'"'); return self::textarea($name,$content,'style="'.$style.'"');
} }*/
return self::fckEditor($name, $content, ($style ? $style : 'extended'), array('toolbar_expanded' =>'true'), '400px', '100%', $base_href); return self::fckEditor($name, $content, ($style ? $style : 'extended'), array('toolbar_expanded' =>'true'), '400px', '100%', $base_href);
} }
@ -568,12 +571,12 @@ class html
* @param array $_options (toolbar_expanded true/false) * @param array $_options (toolbar_expanded true/false)
* @param string $_height='400px' * @param string $_height='400px'
* @param string $_width='100%' * @param string $_width='100%'
* @param string $_base_href='' if passed activates the browser for image at absolute path passed * @param string $_start_path='' if passed activates the browser for image at absolute path passed
* @param boolean $_purify=true run $_content through htmlpurifier before handing it to fckEditor * @param boolean $_purify=true run $_content through htmlpurifier before handing it to fckEditor
* @return string the necessary html for the textarea * @return string the necessary html for the textarea
*/ */
static function fckEditor($_name, $_content, $_mode, $_options=array('toolbar_expanded' =>'true'), static function fckEditor($_name, $_content, $_mode, $_options=array('toolbar_expanded' =>'true'),
$_height='400px', $_width='100%',$_base_href='',$_purify=true) $_height='400px', $_width='100%',$_start_path='',$_purify=true)
{ {
if (!self::htmlarea_availible() || $_mode == 'ascii') if (!self::htmlarea_availible() || $_mode == 'ascii')
{ {
@ -582,79 +585,85 @@ class html
// run content through htmlpurifier // run content through htmlpurifier
if ($_purify && !empty($_content)) $_content = self::purify($_content); if ($_purify && !empty($_content)) $_content = self::purify($_content);
include_once(EGW_INCLUDE_ROOT."/phpgwapi/js/fckeditor/fckeditor.php"); include_once(EGW_INCLUDE_ROOT."/phpgwapi/js/ckeditor3/ckeditor.php");
$oFCKeditor = new FCKeditor($_name) ; //Get the ckeditor base url
$oFCKeditor->BasePath = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/fckeditor/' ; $basePath = 'phpgwapi/js/ckeditor3/';
$oFCKeditor->Config['CustomConfigurationsPath'] = $oFCKeditor->BasePath . 'fckeditor.egwconfig.js' ;
$oFCKeditor->Value = $_content;
$oFCKeditor->Width = str_replace('px','',$_width); // FCK adds px if width contains no %
$oFCKeditor->Height = str_replace('px','',$_height);
// by default switch all browsers and uploads off $oCKeditor = new CKeditor($basePath);
$oFCKeditor->Config['LinkBrowser'] = $oFCKeditor->Config['LinkUpload'] = false; $oCKeditor->returnOutput = true;
$oFCKeditor->Config['FlashBrowser'] = $oFCKeditor->Config['FlashUpload'] = false;
$oFCKeditor->Config['ImageBrowser'] = $oFCKeditor->Config['ImageUpload'] = false;
if (!$GLOBALS['egw_info']['server']['usecookies']) //Only heights with "px" set are supported
{ $pxheight = (strpos('px', $_height) === false) ? 400 : str_replace('px', '', $_height);
$extra = egw_session::EGW_SESSION_NAME.'='.$GLOBALS['egw']->session->sessionid.
'&kp3='.$GLOBALS['egw']->session->kp3.'&domain='.$GLOBALS['egw']->session->account_domain; $oCKeditor->config['customConfig'] = 'ckeditor.egwconfig.js';
} $oCKeditor->config['height'] = $pxheight;
// Activate the image browser+upload, if $_base_href exists and is browsable by the webserver
if ($_base_href && is_dir($_SERVER['DOCUMENT_ROOT'].$_base_href) && file_exists($_SERVER['DOCUMENT_ROOT'].$_base_href.'/.')) $oCKeditor->config['resize_enabled'] = false;
{ //switching the encoding as html entities off, as we correctly handle charsets and it messes up the wiki totally
// Only images for now $oCKeditor->config['entities'] = true;
if (substr($_base_href,-1) != '/') $_base_href .= '/' ; $oCKeditor->config['entities_latin'] = true;
// store the path and application in the session, to make sure it can't be called with arbitrary pathes $oCKeditor->config['entities_processNumerical'] = true;
$GLOBALS['egw']->session->appsession($_base_href,'FCKeditor',$GLOBALS['egw_info']['flags']['currentapp']);
$oCKeditor->config['editingBlock'] = true;
$oCKeditor->config['filebrowserBrowseUrl'] = 'index.php?menuaction=filemanager.filemanager_select.select&mode=open&method=ckeditor_return&path='.urlencode($_start_path);
$oCKeditor->config['filebrowserWindowWidth'] = 640;
$oCKeditor->config['filebrowserWindowHeight'] = 580;
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?ServerPath='.$_base_href.'&Type=Image&Connector='.$oFCKeditor->BasePath.'editor/filemanager/connectors/php/connector.php?'.$extra;
$oFCKeditor->Config['ImageBrowser'] = true;
$oFCKeditor->Config['ImageUpload'] = is_writable($_SERVER['DOCUMENT_ROOT'].$_base_href);
}
// By default the editor start expanded // By default the editor start expanded
if ($_options['toolbar_expanded'] == 'false') if ($_options['toolbar_expanded'] == 'false')
{ $oCKeditor->config['toolbarStartupExpanded'] = false;
$oFCKeditor->Config['ToolbarStartExpanded'] = $_options['toolbar_expanded'];
}
// switching the encoding as html entities off, as we correctly handle charsets and it messes up the wiki totally
$oFCKeditor->Config['ProcessHTMLEntities'] = false;
// Now setting the admin settings // Now setting the admin settings
$spell = ''; /* $spell = '';
if (isset($GLOBALS['egw_info']['server']['enabled_spellcheck'])) if (isset($GLOBALS['egw_info']['server']['enabled_spellcheck']))
{ {
$spell = '_spellcheck'; $spell = '_spellcheck';
$oFCKeditor->Config['SpellChecker'] = 'SpellerPages'; $oFCKeditor->Config['SpellChecker'] = 'SpellerPages';
$oFCKeditor->Config['SpellerPagesServerScript'] = 'server-scripts/spellchecker.php?'.$extra; $oFCKeditor->Config['SpellerPagesServerScript'] = 'server-scripts/spellchecker.php?'.$extra;
$oFCKeditor->Config['FirefoxSpellChecker'] = false; $oFCKeditor->Config['FirefoxSpellChecker'] = false;
} }*/
// Now setting the user preferences // Now setting the user preferences
if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode'])) if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode']))
{ {
$oFCKeditor->Config['EnterMode'] = $GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode']; switch ($GLOBALS['egw_info']['user']['preferences']['common']['rte_enter_mode'])
{
case 'p':
$oCKeditor->config['enterMode'] = '@@CKEDITOR.ENTER_P';
break;
case 'br':
$oCKeditor->config['enterMode'] = '@@CKEDITOR.ENTER_BR';
break;
case 'div':
$oCKeditor->config['enterMode'] = '@@CKEDITOR.ENTER_DIV';
break;
}
} }
if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_skin'])) if (isset($GLOBALS['egw_info']['user']['preferences']['common']['rte_skin']))
{ {
$oFCKeditor->Config['SkinPath'] = $oFCKeditor->BasePath.'editor/skins/'.$GLOBALS['egw_info']['user']['preferences']['common']['rte_skin'].'/'; $oCKeditor->config['skin'] = $GLOBALS['egw_info']['user']['preferences']['common']['rte_skin'];
} }
//$oCKeditor->config['spellchecker'] = 'SpellCheck';
switch($_mode) { switch($_mode) {
case 'simple': case 'simple':
$oFCKeditor->ToolbarSet = 'egw_simple'.$spell; $oCKeditor->config['toolbar'] = 'egw_simple';
$oFCKeditor->Config['ContextMenu'] = false; $oCKeditor->config['menu_groups'] = '';
break; break;
default: default:
case 'extended': case 'extended':
$oFCKeditor->ToolbarSet = 'egw_extended'.$spell; $oCKeditor->config['toolbar'] = 'egw_extended';
break; break;
case 'advanced': case 'advanced':
$oFCKeditor->ToolbarSet = 'egw_advanced'.$spell; $oCKeditor->config['toolbar'] = 'egw_advanced';
break; break;
} }
return $oFCKeditor->CreateHTML();
return $oCKeditor->editor($_name, $_content);
} }
/** /**
@ -1427,8 +1436,11 @@ class html
} }
$result = $purifier->purify( $html );
//error_log(__METHOD__.$purifier->version); //error_log(__METHOD__.$purifier->version);
return $purifier->purify( $html ); return $result;
} }
/** /**