sfRichTextEditorFCK.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 9190 2008-05-22 17:42:21Z 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. // fix for http://trac.symfony-project.com/ticket/732
  74. // fields need to be of type text to be picked up by fillin. they are hidden by inline css anyway:
  75. // <input type="hidden" id="name" name="name" style="display:none" value="&lt;p&gt;default&lt;/p&gt;">
  76. $content = str_replace('type="hidden"','type="text"',$content);
  77. return $content;
  78. }
  79. }