| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
class sfRichTextEditorTinyMCE extends sfRichTextEditor |
|---|
| 32 |
{ |
|---|
| 33 |
|
|---|
| 34 |
* Returns the rich text editor as HTML. |
|---|
| 35 |
* |
|---|
| 36 |
* @return string Rich text editor HTML representation |
|---|
| 37 |
*/ |
|---|
| 38 |
public function toHTML() |
|---|
| 39 |
{ |
|---|
| 40 |
$options = $this->options; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
// in advance of building the tag |
|---|
| 44 |
$id = _get_option($options, 'id', get_id_from_name($this->name, null)); |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
$tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js'; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
$js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.$tinymce_file; |
|---|
| 51 |
if (!is_readable(sfConfig::get('sf_web_dir').$js_path)) |
|---|
| 52 |
{ |
|---|
| 53 |
throw new sfConfigurationException('You must install TinyMCE to use this helper (see rich_text_js_dir settings).'); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
sfContext::getInstance()->getResponse()->addJavascript($js_path); |
|---|
| 57 |
|
|---|
| 58 |
require_once dirname(__FILE__).'/JavascriptBaseHelper.php'; |
|---|
| 59 |
|
|---|
| 60 |
$tinymce_options = ''; |
|---|
| 61 |
$style_selector = ''; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
if ($css_file = _get_option($options, 'css')) |
|---|
| 65 |
{ |
|---|
| 66 |
$css_path = stylesheet_path($css_file); |
|---|
| 67 |
|
|---|
| 68 |
sfContext::getInstance()->getResponse()->addStylesheet($css_path); |
|---|
| 69 |
|
|---|
| 70 |
$css = file_get_contents(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$css_path); |
|---|
| 71 |
$styles = array(); |
|---|
| 72 |
preg_match_all('#^/\*\s*user:\s*(.+?)\s*\*/\s*\015?\012\s*\.([^\s]+)#Smi', $css, $matches, PREG_SET_ORDER); |
|---|
| 73 |
foreach ($matches as $match) |
|---|
| 74 |
{ |
|---|
| 75 |
$styles[] = $match[1].'='.$match[2]; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
$tinymce_options .= ' content_css: "'.$css_path.'",'."\n"; |
|---|
| 79 |
$tinymce_options .= ' theme_advanced_styles: "'.implode(';', $styles).'"'."\n"; |
|---|
| 80 |
$style_selector = 'styleselect,separator,'; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
$culture = sfContext::getInstance()->getUser()->getCulture(); |
|---|
| 84 |
|
|---|
| 85 |
$tinymce_js = ' |
|---|
| 86 |
tinyMCE.init({ |
|---|
| 87 |
mode: "exact", |
|---|
| 88 |
language: "'.strtolower(substr($culture, 0, 2)).'", |
|---|
| 89 |
elements: "'.$id.'", |
|---|
| 90 |
plugins: "table,advimage,advlink,flash", |
|---|
| 91 |
theme: "advanced", |
|---|
| 92 |
theme_advanced_toolbar_location: "top", |
|---|
| 93 |
theme_advanced_toolbar_align: "left", |
|---|
| 94 |
theme_advanced_path_location: "bottom", |
|---|
| 95 |
theme_advanced_buttons1: "'.$style_selector.'justifyleft,justifycenter,justifyright,justifyfull,separator,bold,italic,strikethrough,separator,sub,sup,separator,charmap", |
|---|
| 96 |
theme_advanced_buttons2: "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,image,flash,separator,cleanup,removeformat,separator,code", |
|---|
| 97 |
theme_advanced_buttons3: "tablecontrols", |
|---|
| 98 |
extended_valid_elements: "img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style]", |
|---|
| 99 |
relative_urls: false, |
|---|
| 100 |
debug: false |
|---|
| 101 |
'.($tinymce_options ? ','.$tinymce_options : '').' |
|---|
| 102 |
'.(isset($options['tinymce_options']) ? ','.$options['tinymce_options'] : '').' |
|---|
| 103 |
});'; |
|---|
| 104 |
|
|---|
| 105 |
if (isset($options['tinymce_options'])) |
|---|
| 106 |
{ |
|---|
| 107 |
unset($options['tinymce_options']); |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
return |
|---|
| 111 |
content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')). |
|---|
| 112 |
content_tag('textarea', $this->content, array_merge(array('name' => $this->name, 'id' => $id), _convert_options($options))); |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|