HTML_QuickForm でTinyMCEを使う

※書きかけの記事です.このままでは動かないので注意.

HTML_QuickForm にTinyMceのエレメントクラスを加える.
http://svn.civicrm.org/civicrm/branches/gsoc-ui/packages/HTML/QuickForm/tinymce.php

このファイルをPEAR/HTML/QuickForm の下に置く.

※FCKEditorはこれ
http://d.hatena.ne.jp/hurvinek/20090109/1231489762


_persistantFreeze = true;
$this->_type = 'TinyMCE';

if (is_array($options)) {
$this->Config = $options;
}
}

/**
* Set config variable for TinyMCE
*
* @param mixed Key of config setting
* @param mixed Value of config settinh
* @access public
* @return void
*/
function SetConfig($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->Config[$k] = $v;
}
} else {
$this->Config[$key] = $value;
}
}

/**
* Check if the browser is compatible (IE 5.5+, Gecko > 20030210)
*
* @access public
* @return boolean
*/
function IsCompatible()
{
if (isset($_SERVER['HTTP_USER_AGENT']))
{
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if ( ($msie = strpos($agent, 'msie') ) !== false &&
strpos($agent, 'opera') === false &&
strpos($agent, 'mac') === false)
{
return ((float) substr($agent, $msie + 5, 3) >= 5.5);
} elseif ( ($gecko = strpos($agent, 'gecko') ) !== false) {
return ((int) substr($agent, $gecko + 6, 8 ) >= 20030210);
}
}
return false;
}


/**
* Return the htmlarea in HTML
*
* @access public
* @return string
*/
function toHtml()
{
// return frozen state
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
// return textarea if incompatible
} elseif (!$this->IsCompatible()) {
return parent::toHtml();
// return textarea
} else {
$config =& CRM_Core_Config::singleton();

$html .= sprintf( '',
$config->resourceBase . $this->BasePath . 'tiny_mce.js'
);

//FIXME: We might want to pass some parameters to TinyMCE
$html .= sprintf( '' );
// include textarea as well (TinyMCE transforms it)
$html .= parent::toHTML();
return $html;
}
}

/**
* Returns the htmlarea content in HTML
*
* @access public
* @return string
*/
function getFrozenHtml()
{
return $this->getValue();
}
}

?>