Development

/branches/1.2/lib/helper/sfRichTextEditorTinyMCE.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/helper/sfRichTextEditorTinyMCE.class.php

Revision 17861, 3.9 kB (checked in by FabianLange, 5 years ago)

[1.0, 1.1, 1.2, 1.3] MCE Texteditor now can align images correctly (closes #5745)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfRichTextEditorTinyMCE implements the TinyMCE rich text editor.
13  *
14  * <b>Options:</b>
15  *  - css - Path to the TinyMCE editor stylesheet
16  *
17  *    <b>Css example:</b>
18  *    <code>
19  *    / * user: foo * / => without spaces. 'foo' is the name in the select box
20  *    .foobar
21  *    {
22  *      color: #f00;
23  *    }
24  *    </code>
25  *
26  * @package    symfony
27  * @subpackage helper
28  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
29  * @version    SVN: $Id$
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     // we need to know the id for things the rich text editor
43     // in advance of building the tag
44     $id = _get_option($options, 'id', get_id_from_name($this->name, null));
45
46     // use tinymce's gzipped js?
47     $tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js';
48
49     // tinymce installed?
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     // custom CSS file?
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
Note: See TracBrowser for help on using the browser.