sfRichTextEditorFCK.class.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfRichTextEditorFCK implements the FCK rich text editor.
  11. *
  12. * <b>Options:</b>
  13. * - tool - Sets the FCKEditor toolbar style
  14. * - config - Sets custom path to the FCKEditor configuration file
  15. *
  16. * @package symfony
  17. * @subpackage helper
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. * @version SVN: $Id: sfRichTextEditorFCK.class.php 17860 2009-05-01 22:33:31Z FabianLange $
  20. */
  21. class sfRichTextEditorFCK extends sfRichTextEditor
  22. {
  23. /**
  24. * Returns the rich text editor as HTML.
  25. *
  26. * @return string Rich text editor HTML representation
  27. */
  28. public function toHTML()
  29. {
  30. $options = $this->options;
  31. // we need to know the id for things the rich text editor
  32. // in advance of building the tag
  33. $id = _get_option($options, 'id', $this->name);
  34. $php_file = sfConfig::get('sf_rich_text_fck_js_dir').DIRECTORY_SEPARATOR.'fckeditor.php';
  35. if (!is_readable(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$php_file))
  36. {
  37. throw new sfConfigurationException('You must install FCKEditor to use this helper (see rich_text_fck_js_dir settings).');
  38. }
  39. // FCKEditor.php class is written with backward compatibility of PHP4.
  40. // This reportings are to turn off errors with public properties and already declared constructor
  41. $error_reporting = error_reporting(E_ALL);
  42. require_once(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$php_file);
  43. // turn error reporting back to your settings
  44. error_reporting($error_reporting);
  45. $fckeditor = new FCKeditor($this->name);
  46. $fckeditor->BasePath = sfContext::getInstance()->getRequest()->getRelativeUrlRoot().'/'.sfConfig::get('sf_rich_text_fck_js_dir').'/';
  47. $fckeditor->Value = $this->content;
  48. if (isset($options['width']))
  49. {
  50. $fckeditor->Width = $options['width'];
  51. }
  52. elseif (isset($options['cols']))
  53. {
  54. $fckeditor->Width = (string)((int) $options['cols'] * 10).'px';
  55. }
  56. if (isset($options['height']))
  57. {
  58. $fckeditor->Height = $options['height'];
  59. }
  60. elseif (isset($options['rows']))
  61. {
  62. $fckeditor->Height = (string)((int) $options['rows'] * 10).'px';
  63. }
  64. if (isset($options['tool']))
  65. {
  66. $fckeditor->ToolbarSet = $options['tool'];
  67. }
  68. if (isset($options['config']))
  69. {
  70. $fckeditor->Config['CustomConfigurationsPath'] = javascript_path($options['config']);
  71. }
  72. $content = $fckeditor->CreateHtml();
  73. if (sfConfig::get('sf_compat_10'))
  74. {
  75. // fix for http://trac.symfony-project.com/ticket/732
  76. // fields need to be of type text to be picked up by fillin. they are hidden by inline css anyway:
  77. // <input type="hidden" id="name" name="name" style="display:none" value="&lt;p&gt;default&lt;/p&gt;">
  78. $content = str_replace('type="hidden"','type="text"',$content);
  79. }
  80. return $content;
  81. }
  82. }