Source for file htmlarea-defs.php

Documentation is available at htmlarea-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: htmlarea-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for using HTMLArea wysiwyg editor. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package form */
  27. include_once("form-defs.php");
  28.  
  29. // NOTES: How to implement HTMLAreas in your forms:
  30. //
  31. // // Include htmlarea classes at the top of the page..
  32. // include_once("htmlarea-defs.php");
  33. // // Define which plugins to load..
  34. // htmlarea_plugins("ContextMenu,CSS");
  35. // ...
  36. // // Build your form element..
  37. // $Fld = new form_wysiwygfield("my_content", "Article", $my_content);
  38. // // Register plugins this editor will use..
  39. // $Fld->register_plugins("all");
  40. // // Render the field..
  41. // $myfield = $Fld->render();
  42. // ...
  43. // ... more htmlareas as required ...
  44.  
  45. // ----------------------------------------------------------------------
  46.  
  47. /**
  48. * The htmlarea class. This is just an aggregator of functionality to
  49. * initialise and properly render all the bits required to make one
  50. * or more HTMLArea widgets work in the $RESPONSE. NB: this class is
  51. * not required to be used directly, being automatically instantiated
  52. * in this module (see below). It is also automatically rendered
  53. * when the $RESPONSE is delivered back to the user agent.
  54. * @see webpage::generate()
  55. * @access private
  56. * @package form
  57. */
  58. class htmlarea extends HTMLObject {
  59. // Public
  60. // Private
  61. /** Plugins activated. Initially none.
  62. @access private */
  63. var $loaded_plugins = array();
  64. /** Array of all possible allowed plugins
  65. @access private */
  66. var $all_plugins = array(
  67. "ContextMenu",
  68. "CSS",
  69. "TableOperations",
  70. "ListType",
  71. "CharacterMap",
  72. "HtmlTidy",
  73. "EnterParagraphs",
  74. "FullPage"
  75. );
  76. /** Array of default styles we will use for the CSS plugin. This
  77. is the default set of Axyl styles.
  78. @access private */
  79. var $default_css_styles = array(
  80. "&mdash; styles &mdash;:",
  81. "Title: axtitle",
  82. "Heading: axhdg",
  83. "Sub-heading: axsubhdg",
  84. "Light backgnd: axbglite",
  85. "Dark backgnd: axbgdark",
  86. "Highlight: axhl",
  87. "Form label: axfmlbl",
  88. "Number field: axnumbox",
  89. "Text field: axtxtbox",
  90. "Memo field: axmemo",
  91. "Menu: menu",
  92. "Sub-menu: submenu"
  93. );
  94. /** Whether we have initialised or not
  95. @access private */
  96. var $init_done = false;
  97. /** Collected script content
  98. @access private */
  99. var $script = "";
  100. /** Whether we have been activated. Activation occurs
  101. when something calls the 'add_script()' method
  102. @access private */
  103. var $activated = false;
  104. /** Whether we have already been rendered
  105. @access private */
  106. var $rendered = false;
  107. // .....................................................................
  108. /** Constructor for an HTMLArea manager */
  109.  
  110. function htmlarea() {
  111. } // htmlarea
  112. // .....................................................................
  113. /**
  114. * Set the plugins for ALL the Wysiwyg editors. This represents the list
  115. * of plugins which should be loaded. These can then be used by any
  116. * HTMLArea form object to register against.
  117. * NOTE: This can be called multiple times, but will only ever ADD
  118. * extra (new) plugins to what was already there.
  119. * @param string $pluginlist Comma-delimited list of plugins to permit
  120. */
  121. function load_plugins($pluginlist="all") {
  122. debug_trace($this);
  123. if ($pluginlist == "all") {
  124. $this->loaded_plugins = $this->all_plugins;
  125. }
  126. else {
  127. $plugins = explode(",", $pluginlist);
  128. foreach ($plugins as $plugin) {
  129. if (in_array($plugin, $this->all_plugins)
  130. && !in_array($plugin, $this->loaded_plugins)) {
  131. $this->loaded_plugins[] = $plugin;
  132. }
  133. }
  134. }
  135. debug_trace();
  136. } // load_plugins
  137. // .....................................................................
  138. /**
  139. * Internal method to initialise the HTMLArea environment. This sets up
  140. * the URL and i18n settings, and also loads the nominated plugins.
  141. * Plugins must be set up before this is called. This methid is an
  142. * internal one which is usually called late, just prior to render.
  143. * @access private
  144. */
  145. function initialise() {
  146. debug_trace($this);
  147. global $RESPONSE, $LIBDIR;
  148. // One-time-only javascript for all HTMLAreas on page..
  149. if (!$this->init_done) {
  150. $RESPONSE->head->add_named_script(
  151. "_editor_url = \"$LIBDIR/js/htmlarea/\";\n"
  152. . "_editor_lang = \"en\";\n",
  153. "htmlarea settings"
  154. );
  155. $RESPONSE->set_onload("HTMLArea.init();");
  156. $RESPONSE->add_scriptsrc("$LIBDIR/js/htmlarea/htmlarea.js");
  157.  
  158. foreach ($this->loaded_plugins as $plugin) {
  159. $RESPONSE->add_named_script("HTMLArea.loadPlugin(\"$plugin\");\n", "htmlarea");
  160. }
  161. $this->init_done = true;
  162. }
  163. debug_trace();
  164. } // initialise
  165. // .....................................................................
  166. /**
  167. * Script collector for htmlarea-specific javascript.
  168. * @access private
  169. */
  170. function add_script($script) {
  171. debug_trace($this);
  172. $this->script .= $script;
  173. $this->activated = true;
  174. debug_trace();
  175. } // add_script
  176. // .....................................................................
  177. /**
  178. * Render the htmlarea javascript as HTML. Note, this does not render
  179. * the editor widget(s) since these will be rendered as individual
  180. * form elements separately wherever they are intended to go. This
  181. * method renders the environment for those widgets to operate in
  182. * the $RESPONSE, and returns nothing to the caller.
  183. */
  184. function html() {
  185. debug_trace($this);
  186. global $RESPONSE;
  187. if (!$this->rendered && $this->script != "") {
  188. $this->initialise();
  189. $RESPONSE->add_named_script("HTMLArea.onload = function () {\n", "htmlarea");
  190. $RESPONSE->add_named_script($this->script, "htmlarea");
  191. $RESPONSE->add_named_script("}\n", "htmlarea");
  192. $this->rendered = true;
  193. }
  194. debug_trace();
  195. } // html
  196.  
  197. } // htmlarea class
  198. // ----------------------------------------------------------------------
  199.  
  200. /**
  201. * A container class for configuration settings for the HTMLArea
  202. * internal configuration structure. We provide a selection of all the
  203. * possible HTMLArea parameters, which represents a subset. This also
  204. * renders the Javascript definition for the config @see render()
  205. * @package form
  206. */
  207. class htmlarea_config {
  208. /** Width of HTMLarea element (default 'auto') */
  209.  
  210. var $width;
  211. /** Height of HTMLarea element (default 'auto') */
  212.  
  213. var $height;
  214. /** enable creation of a status bar? (default true) */
  215.  
  216. var $statusBar;
  217. /** intercept ^V and use the HTMLArea paste command
  218. If false, then passes ^V through to browser editor widget
  219. (default false) */
  220. var $htmlareaPaste;
  221. /** maximum size of the undo queue (default 20) */
  222.  
  223. var $undoSteps;
  224. /** the next parameter specifies whether the toolbar should
  225. be included in the size or not (default true) */
  226. var $sizeIncludesToolbar;
  227. /** if true then HTMLArea will retrieve the full HTML, starting
  228. with the HTML tag (default false) */
  229. var $fullPage;
  230. /** style included in the iframe document (default nullstring) */
  231.  
  232. var $pageStyle;
  233. /** set to true if you want Word code to be cleaned upon Paste
  234. (default true)*/
  235. var $killWordOnPaste;
  236. /** HTML tags to disallow (these have to be a regexp, or null
  237. if this functionality is not desired) (default null) */
  238. var $htmlRemoveTags;
  239. /** The toolbar. This takes the form of an array of arrays of toolbar
  240. buttons. Each sub-array is a new line of buttons.
  241. (defaulted to all standard buttons) */
  242. var $toolbar;
  243. /** The list of font families to allow user to choose from
  244. (defaulted to standard list of font families) */
  245. var $fontnames;
  246. /** The list of font sizes to allow user to choose from
  247. (defaulted to standard list of font sizes) */
  248. var $fontsizes;
  249. /** The list of block format styles to allow user to choose from
  250. (defaulted to standard list of block formats) */
  251. var $blockformats;
  252. // Private
  253. /** A basic toolbar definition. Use for entering text in given
  254. font, with basic bold/italic/underline styling.
  255. @access private */
  256. var $toolbar_basic = array(
  257. array(
  258. "fontname", "space",
  259. "fontsize", "space",
  260. "formatblock", "space",
  261. "bold", "italic", "underline", "separator",
  262. "undo", "redo", "space", "removeformat", "htmlmode"
  263. ),
  264. array("space")
  265. );
  266. /** A medium toolbar definition, adds colour, links, raw HTML editing,
  267. lists, and horizontal rule, etc.
  268. @access private */
  269. var $toolbar_medium = array(
  270. array(
  271. "fontname", "space",
  272. "fontsize", "space",
  273. "formatblock", "space",
  274. "bold", "italic", "underline", "strikethrough"
  275. ),
  276. array(
  277. "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
  278. "orderedlist", "separator", "unorderedlist", "outdent", "indent"
  279. ),
  280. array(
  281. "copy", "cut", "paste", "separator", "undo", "redo", "space", "removeformat",
  282. "forecolor", "hilitecolor", "separator",
  283. "inserthorizontalrule", "createlink", "htmlmode", "separator",
  284. "popupeditor", "separator", "showhelp", "about"
  285. )
  286. );
  287. /** A fully-populated toolbar definition for power users
  288. @access private */
  289. var $toolbar_full = array(
  290. array(
  291. "fontname", "space",
  292. "fontsize", "space",
  293. "formatblock", "space",
  294. "bold", "italic", "underline", "strikethrough", "separator",
  295. "subscript", "superscript", "separator"
  296. ),
  297. array(
  298. "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
  299. "lefttoright", "righttoleft", "separator",
  300. "orderedlist", "unorderedlist", "outdent", "indent"
  301. ),
  302. array(
  303. "copy", "cut", "paste", "undo", "redo", "space", "removeformat",
  304. "forecolor", "hilitecolor", "separator",
  305. "inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator",
  306. "popupeditor", "killword", "separator", "showhelp", "about"
  307. )
  308. );
  309.  
  310. // .....................................................................
  311. /** Constructor for new HTMLArea configuration object */
  312.  
  313. function htmlarea_config() {
  314. } // HTMLArea_config
  315. // .....................................................................
  316. /**
  317. * Render this config as a string of Javascript which could be put into
  318. * a webapage and used to set the configuration of a real HTMLArea
  319. * object.
  320. */
  321. function render($configvar) {
  322. $s = "";
  323. $s .= "var $configvar = new HTMLArea.Config();\n";
  324. if (isset($this->width) && $this->width != "") {
  325. $s .= "$configvar.width = '$this->width';\n";
  326. }
  327. if (isset($this->height) && $this->height != "") {
  328. $s .= "$configvar.height = '$this->height';\n";
  329. }
  330. if (isset($this->statusBar) && $this->statusBar === false) {
  331. $s .= "$configvar.statusBar=" . ($this->statusBar ? "true" : "false") . ";\n";
  332. }
  333. if (isset($this->htmlareaPaste) && $this->htmlareaPaste === true) {
  334. $s .= "$configvar.htmlareaPaste=" . ($this->htmlareaPaste ? "true" : "false") . ";\n";
  335. }
  336. if (isset($this->undoSteps)) {
  337. $s .= "$configvar.undoSteps=" . $this->undoSteps . ";\n";
  338. }
  339. if (isset($this->sizeIncludesToolbar) && $this->sizeIncludesToolbar === false) {
  340. $s .= "$configvar.sizeIncludesToolbar=" . ($this->sizeIncludesToolbar ? "true" : "false") . ";\n";
  341. }
  342. if (isset($this->pageStyle) && $this->pageStyle != "") {
  343. $s .= "$configvar.pageStyle = '$this->pageStyle';\n";
  344. }
  345. if (isset($this->killWordOnPaste) && $this->killWordOnPaste === false) {
  346. $s .= "$configvar.killWordOnPaste=" . ($this->killWordOnPaste ? "true" : "false") . ";\n";
  347. }
  348. if (isset($this->htmlRemoveTags) && $this->htmlRemoveTags != "") {
  349. $s .= "$configvar.htmlRemoveTags = '$this->htmlRemoveTags';\n";
  350. }
  351. if (isset($this->toolbar)) {
  352. $toolbar = $this->toolbar;
  353. if (is_string($toolbar)) {
  354. switch ($toolbar) {
  355. case "basic":
  356. $toolbar = $this->toolbar_basic;
  357. break;
  358. case "medium":
  359. $toolbar = $this->toolbar_medium;
  360. break;
  361. default:
  362. $toolbar = $this->toolbar_full;
  363. } // switch
  364. }
  365. $toolbar_lines = array();
  366. foreach ($toolbar as $toolbar_line) {
  367. $toolbar_lines[] = "[\"" . implode("\",\"", $toolbar_line) . "\"]";
  368. }
  369. $s .= "$configvar.toolbar = [" . implode(",\n", $toolbar_lines) . "];\n";
  370. }
  371. if (isset($this->fontnames)) {
  372. $fonts = array();
  373. foreach ($this->fontnames as $fontlabel => $fontvalue) {
  374. $fonts[] = "\"$fontlabel\": \"$fontvalue\"";
  375. }
  376. $s .= "$configvar.fontname = {" . implode(",", $fonts) . "};\n";
  377. }
  378. if (isset($this->fontsizes)) {
  379. $sizes = array();
  380. foreach ($this->fontsizes as $sizlabel => $sizvalue) {
  381. $sizes[] = "\"$sizlabel\": \"$sizvalue\"";
  382. }
  383. $s .= "$configvar.fontsize = {" . implode(",", $sizes) . "};\n";
  384. }
  385. if (isset($this->blockformats)) {
  386. $formats = array();
  387. foreach ($this->blockformats as $fmtlabel => $fmtvalue) {
  388. $formats[] = "\"$fmtlabel\": \"$fmtvalue\"";
  389. }
  390. $s .= "$configvar.formatblock = {" . implode(",", $formats) . "};\n";
  391. }
  392. // Return the Javascript code..
  393. return $s;
  394. } // render
  395.  
  396. } // htmlarea_config class
  397. // ----------------------------------------------------------------------
  398.  
  399. /** The global control object which has to be used
  400. * to initialise the plugins, and render the environment
  401. */
  402. global $HTMLAREA;
  403. $HTMLAREA = new htmlarea();
  404.  
  405. // ----------------------------------------------------------------------
  406. // FUNCTIONS
  407.  
  408. /**
  409. * Function to set plugins to be loaded. When you are using one of
  410. * these HTMLArea editors on a webpage, call this to define which of
  411. * the allowed plugins you want loaded. The possibilities currently
  412. * are as follows:
  413. * ContextMenu
  414. * CSS
  415. * TableOperations
  416. * ListType
  417. * CharacterMap
  418. * HtmlTidy
  419. * EnterParagraphs
  420. * FullPage
  421. * @param string $plugins A comma-delimited list of plugins
  422. */
  423. function htmlarea_plugins($plugins) {
  424. global $HTMLAREA;
  425. if (is_object($HTMLAREA) && method_exists($HTMLAREA, "load_plugins")) {
  426. $HTMLAREA->load_plugins($plugins);
  427. }
  428. } // htmlarea_plugins
  429. // ----------------------------------------------------------------------
  430.  
  431. /**
  432. * Wysiwyg Field class
  433. * A field which renders a textarea form element as a Wysiwyg editor.
  434. * This is based on the package 'HTMLarea', by Mihai Bazon.
  435. * This class leverages the standard memofield. In fact we render a standard
  436. * memofield, and the main diference is only the setting of a classid, and
  437. * rendering the javascript for HTMLarea to initialisei itself.
  438. * @package form
  439. */
  440. class form_wysiwygfield extends form_memofield {
  441. /** Unique ID of this form element
  442. @access private */
  443. var $wysiwyg_id = "wysiwyg";
  444. /** Plugins we want to register for this field
  445. @access private */
  446. var $plugins = array();
  447. /** CSS Styles we want to display for this field
  448. @access private */
  449. var $css_styles;
  450. /** The configuration override settings to use. This is
  451. an object of htmlarea_config class.
  452. @access private */
  453. var $config;
  454. // .....................................................................
  455. /** Constructor - create a wysiwyg form element..
  456. * @param string $name The name of the field
  457. * @param string $label The label which can be displayed alongside the field
  458. * @param string $value The value of the field
  459. * @param boolean $editable Editability: EDITABLE or DISPLAY_ONLY (true or false)
  460. * @param string $css CSS class or style to apply to the button
  461. * @param integer $width Width of the memo field in characters
  462. * @param integer $rows Height of the memo field in lines
  463. */
  464. function form_wysiwygfield($name="", $label="", $value="", $editable=EDITABLE, $css="", $width=STD_WIDTH, $rows=5) {
  465. global $HTMLAREA;
  466. $this->form_memofield($name, $label, $value, $editable, $css, $width, $rows);
  467. $this->wysiwyg_id = $name;
  468. $this->setid($this->wysiwyg_id);
  469. // Default CSS styles..
  470. $this->css_styles = $HTMLAREA->default_css_styles;
  471. // Empty config object..
  472. $this->config = new htmlarea_config();
  473. } // form_wysiwygfield
  474. // .....................................................................
  475. /**
  476. * Set the styles to provide for this Wysiwyg editor. Styles are displayed
  477. * when you register the "CSS" plugin. This method either replaces (the
  478. * default action) or appends the given list (or array) of styles to the
  479. * editor. Pass the styles list either as a comma-delimited string, or
  480. * an array. Each style should be in the format 'label : classname' as
  481. * shown in this example: 'Light background : axbglite'
  482. * (You should omit the quotes, which are just to delimit the example)
  483. * @param mixed $new_styles Comma-delimited list or array of style definitions
  484. * @param string $mode If "append" add styles to existing, else replace
  485. */
  486. function set_styles($new_styles, $mode="replace") {
  487. global $HTMLAREA;
  488. if (!is_array($new_styles)) {
  489. $new_styles = explode(",", $new_styles);
  490. }
  491. if ($mode == "replace") {
  492. $this->css_styles = $new_styles;
  493. }
  494. else {
  495. foreach ($new_styles as $style) {
  496. $this->css_styles[] = $style;
  497. }
  498. }
  499. } // set_styles
  500. // .....................................................................
  501. /** Set the HTMLArea page style. This is the overall style setting(s)
  502. * which are applied to the HTMLArea widget and so here is where you
  503. * determine such basic things as the font settings of the content which
  504. * is displayed/edited etc.
  505. * @param string $css_style The style setting for the editor 'page'
  506. */
  507. function set_pagestyle($css_style) {
  508. $this->config->pageStyle = $css_style;
  509. } // set_pagestyle
  510. // .....................................................................
  511. /** Set a new toolbar definition. Toolbars are arrays of arrays of lists
  512. * of HTMLArea widgets. Each array is a line of these widgets. For an
  513. * example see the default setting for the toolbar in this class. You
  514. * can EITHER give a full toolbar definition here as an array of arrays
  515. * of toolbar widgets, OR give a preset toolbar ID string. Presets that
  516. * we have defined so far are:
  517. * "basic" - Just enough to enter text, bold/italic etc.
  518. * "medium" - As above but with colour, links, raw HTML etc.
  519. * "full" - Everything available
  520. * @param mixed $new_toolbat Array of toolbar lines, or preset toolbar id
  521. */
  522. function set_toolbar($new_toolbar) {
  523. $this->config->toolbar = $new_toolbar;
  524. } // set_toolbar
  525. // .....................................................................
  526. /** Set a new list of selectable font families. This array should be an
  527. * associative one in the form:
  528. * "Arial" => "arial,helvetica,sans-serif",
  529. * "Courier New" => "courier new,courier,monospace",
  530. * ...
  531. * @param array $new_fontnames Array of font family names to use
  532. */
  533. function set_fontnames($new_fontnames) {
  534. if (is_array($new_fontnames)) {
  535. $this->config->fontnames = $new_fontnames;
  536. }
  537. } // set_fontnames
  538. // .....................................................................
  539. /** Set a new list of selectable font sizes. The sizes array should be
  540. * an associative one in the form:
  541. * "1 (8 pt)" => "1",
  542. * "2 (10 pt)" => "2",
  543. * ...
  544. * @param array $new_blocksizes Array of font sizes to use
  545. */
  546. function set_fontsizes($new_fontsizes) {
  547. if (is_array($new_fontsizes)) {
  548. $this->config->fontsizes = $new_fontsizes;
  549. }
  550. } // set_fontsizes
  551. // .....................................................................
  552. /** Set a new list of selectable block formats. The array should be an
  553. * associative one in the form:
  554. * "Heading 1" => "h1",
  555. * "Heading 2" => "h2",
  556. * ...
  557. * @param array $new_blockformats Array of block formats to use
  558. */
  559. function set_blockformats($new_blockformats) {
  560. if (is_array($new_blockformats)) {
  561. $this->config->blockformats = $new_blockformats;
  562. }
  563. } // set_blockformats
  564. // .....................................................................
  565. /** Set the HTMLArea sizing. The default is 'auto' for both width
  566. * and height, which gives you an editing area filling the are that
  567. * the original memofield widget would have filled.
  568. * @param string $width Width of the HTMLArea editor
  569. * @param string $height Height of the HTMLArea editor
  570. * @param boolean $inctoolbar Whether sizing includes the toolbar
  571. */
  572. function set_metrics($width="", $height="", $inctoolbar=true) {
  573. if ($width != "") {
  574. $this->config->width = $width;
  575. }
  576. if ($height != "") {
  577. $this->config->height = $height;
  578. }
  579. $this->config->sizeIncludesToolbar = ($inctoolbar === true);
  580. } // set_metrics
  581. // .....................................................................
  582. /** Set the regular expression to use for removing dis-allowed HTML
  583. * tags from the editor content. This allows you to specify a regex
  584. * matching those tags you don't want to ever appear in the content.
  585. * @param string $regex Regular expression matching disallowed tags
  586. */
  587. function set_remove_regex($regex="") {
  588. $this->config->htmlRemoveTags = $regex;
  589. } // set_remove_regex
  590. // .....................................................................
  591. /** Set the HTMLArea undo steps maximum. The default number is 20. Use
  592. * this method to change that.
  593. * @param integer $steps Number of undo steps to record.
  594. */
  595. function set_undo_steps($steps=20) {
  596. $this->config->undoSteps = $steps;
  597. } // set_undo_steps
  598. // .....................................................................
  599. /** Set the HTMLArea statusbar display mode, true or false.
  600. * @param boolean $mode Whether to display the statusbar or not
  601. */
  602. function set_statusbar($mode=true) {
  603. $this->config->statusBar = $mode;
  604. } // set_statusbar
  605. // .....................................................................
  606. /** Set the HTMLArea Paste mode. If set to true, then the HTMLArea
  607. * widget will intercept ^V and use the HTMLArea paste command. If
  608. * false, then it passes ^V through to browser editor widget
  609. * @param boolean $mode Whether to intercept ^V or not
  610. */
  611. function set_paste_intercept($mode=true) {
  612. $this->config->htmlareaPaste = $mode;
  613. } // set_paste_intercept
  614. // .....................................................................
  615. /**
  616. * Set the plugins to register for this Wysiwyg editor. This is a subset
  617. * of the allowed plugins which were given in the original call to the
  618. * @see htmlarea_plugins() function. If you want to just register all
  619. * of the possibilities, then just leave the argument list empty, or
  620. * explicitly set it to "all" (the default).
  621. * @param string $pluginlist Comma-delimited list of plugins to register
  622. */
  623. function register_plugins($pluginlist="all") {
  624. global $HTMLAREA;
  625. if ($pluginlist == "all") {
  626. $this->plugins = $HTMLAREA->loaded_plugins;
  627. }
  628. else {
  629. $plugins = explode(",", $pluginlist);
  630. $this->plugins = array();
  631. foreach ($plugins as $plugin) {
  632. if (in_array($plugin, $HTMLAREA->loaded_plugins)) {
  633. $this->plugins[] = $plugin;
  634. }
  635. }
  636. }
  637. } // register_plugins
  638. // .....................................................................
  639. /**
  640. * Register with HTMLArea for this editor to work. We produce the required
  641. * javascript. This is an internal method usually executed just prior to
  642. * rendering.
  643. * @access private
  644. */
  645. function register() {
  646. global $HTMLAREA, $RESPONSE, $LIBDIR;
  647. if (isset($RESPONSE) && file_exists($RESPONSE->site_docroot."$LIBDIR/js/htmlarea/htmlarea.js")) {
  648. $wysiwyged = $this->wysiwyg_id . "_ed";
  649. $wysiwygconfig = $this->wysiwyg_id . "_config";
  650.  
  651. $ssheet = new stylesheet($RESPONSE->site_docroot . $RESPONSE->head->stylesheet);
  652. if ($ssheet->opened) {
  653. //$bodystyle = $ssheet->style("body");
  654. //$parastyle = $ssheet->style("p");
  655. //$this->set_pagestyle("body {" . $bodystyle . "} p {" . $parastyle . "}");
  656. $this->set_pagestyle("@import url( " . $RESPONSE->site_url . $RESPONSE->head->stylesheet . " );");
  657. }
  658.  
  659. // HTMLArea editor widget for this field..
  660. $RESPONSE->add_named_script("var $wysiwyged=null;\n", "htmlarea objects");
  661. $HTMLAREA->add_script(
  662. $this->config->render($wysiwygconfig)
  663. . "$wysiwyged=new HTMLArea(\"$this->wysiwyg_id\",$wysiwygconfig);\n"
  664. );
  665.  
  666. // Register plugins with this field..
  667. foreach ($this->plugins as $plugin) {
  668. switch ($plugin) {
  669. case "CSS":
  670. if (count($this->css_styles > 0)) {
  671. $HTMLAREA->add_script(
  672. "$wysiwyged.registerPlugin(CSS, {\n"
  673. . "combos : [\n"
  674. . " { label: \"\",\n"
  675. . " options: {\n"
  676. );
  677. $css_styles = array();
  678. foreach ($this->css_styles as $style) {
  679. $style = preg_replace("/[\"',]/", "", $style);
  680. $stylebits = explode(":", $style);
  681. $css_styles[] = " \"" . trim($stylebits[0]) . "\" : \"" . trim($stylebits[1]) . "\"";
  682. $style_list = implode(",\n", $css_styles);
  683. if (!strstr($css_styles[0], "&mdash; styles &mdash;")) {
  684. $style_list = " \"&mdash; styles &mdash;\" : \"\",\n" . $style_list;
  685. }
  686. } // foreach
  687. $HTMLAREA->add_script($style_list);
  688. $HTMLAREA->add_script(
  689. " }\n"
  690. . " }\n"
  691. . "]\n"
  692. . "});\n"
  693. );
  694. }
  695. break;
  696. default:
  697. $HTMLAREA->add_script("$wysiwyged.registerPlugin($plugin);\n");
  698. } // switch
  699. }
  700. // Generate section for field..
  701. $HTMLAREA->add_script("$wysiwyged.generate();\n");
  702. } // if not already done
  703. } // register
  704. // ....................................................................
  705. /**
  706. * This renders the field as HTML.
  707. * @return string The wysiwyg HTMLArea editor field as HTML.
  708. */
  709. function html($name="") {
  710. if ($name != "") {
  711. $this->name = $name;
  712. $this->wysiwyg_id = $name;
  713. $this->setid($this->wysiwyg_id);
  714. }
  715. $this->register();
  716. return form_memofield::html();
  717. } // html
  718.  
  719. } // class form_wysiwygfield
  720. // ----------------------------------------------------------------------
  721.  
  722. ?>

Documentation generated by phpDocumentor 1.3.0RC3