There we go.
Notice, I had to remove the lines that had code string replace in order to get it to post in the forum. You’ll not want to copy past this directly. But you can see what I did.
The RTE also adds so i’ve got a plugin emtpypstripper.php (google it) that is working for me and I just added $result = str_replace(’ ’, ’ ‘, $result);
before output.
/**
* Save RTE field
*
* Use to clean up RTE content prior to DB insertion
*
* @param string $data the RTE html content
*
* @return string the cleaned up RTE html content
*/
public function save_field($data)
{
if (ee()->session->userdata('rte_enabled') != 'y'
OR ee()->config->item('rte_enabled') != 'y')
{
return $data;
}
// If the editor was saved empty, save nothing to database
// so it behaves as expected with conditional tags
if ($this->is_empty($data))
{
return NULL;
}
// I don't see any reason to have going on. EE keeps adding it in. Maybe via the js RTE.
// Oh and if you are doing layout by then you're doing it wrong.
$data = str_replace(' ', ' ', $data);
$data = htmlspecialchars_decode($data, ENT_QUOTES);
// decode double encoded code chunks
if (preg_match_all("/\[code\](.+?)\[\/code\]/si", $data, $matches))
{
$i = 0;
foreach ($matches[1] as $chunk)
{
$chunk = trim($chunk);
$chunk = html_entity_decode($chunk, ENT_QUOTES, 'UTF-8');
$i++;
}
}
return $data;
}
// ------------------------------------------------------------------------
/**
* Display an RTE field
*
* @param string $data the RTE html content
* @param string $field_name the field name for the RTE field
* @param array $settings field settings:
* field_ta_rows - the number of textarea rows
* field_text_direction - ltr or rtl
* field_fmt - xhtml, br or none
*
* @return string
*/
public function display_field($data, $field_name, $settings)
{
ee()->load->helper('form');
$field = array(
'name' => $field_name,
'id' => $field_name,
'rows' => $settings['field_ta_rows'],
'dir' => $settings['field_text_direction']
);
// form prepped nonsense
$data = htmlspecialchars_decode($data, ENT_QUOTES);
$code_marker = unique_marker('code');
$code_chunks = array();
// removed xhtml. Don't want that.
$field_ft = '';
// remove code chunks
if (preg_match_all("/\[code\](.+?)\[\/code\]/si", $data, $matches))
{
foreach ($matches[1] as $i => $chunk)
{
$code_chunks[] = trim($chunk);
$data = str_replace($matches[0][$i], $code_marker.$i, $data);
}
}
// Check the RTE module and user's preferences
if (ee()->session->userdata('rte_enabled') == 'y'
AND ee()->config->item('rte_enabled') == 'y')
{
$field['class'] = 'WysiHat-field';
foreach ($code_chunks as &$chunk)
{
$chunk = htmlentities($chunk, ENT_QUOTES, 'UTF-8');
}
// Removed xhtml. Don't want it on RTE.
}
// put code chunks back
foreach ($code_chunks as $i => $chunk)
{
}
// Swap {filedir_x} with the real URL. It will be converted back
// upon submit by the RTE Image tool.
ee()->load->model('file_upload_preferences_model');
$dirs = ee()->file_upload_preferences_model->get_file_upload_preferences(ee()->session->userdata('group_id'));
foreach($dirs as $d)
{
// tag to replace
$filedir = "{filedir_{$d['id']}}";
$data = str_replace($filedir, $d['url'], $data);
}
$data = htmlspecialchars($data, ENT_QUOTES);
// Get rid of
$data = str_replace(' ', ' ', $data);
$field['value'] = $data;
return form_textarea($field);
}