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"
  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", "separator",
  275. "copy", "cut", "paste", "space", "undo", "redo", "space", "removeformat"
  276. ),
  277. array(
  278. "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
  279. "orderedlist", "unorderedlist", "outdent", "indent", "separator",
  280. "forecolor", "hilitecolor", "separator",
  281. "inserthorizontalrule", "createlink", "htmlmode", "separator",
  282. "popupeditor", "separator", "showhelp", "about"
  283. ),
  284.  
  285. );
  286. /** A fully-populated toolbar definition for power users
  287. @access private */
  288. var $toolbar_full = array(
  289. array(
  290. "fontname", "space",
  291. "fontsize", "space",
  292. "formatblock", "space",
  293. "bold", "italic", "underline", "strikethrough", "separator",
  294. "subscript", "superscript", "separator",
  295. "copy", "cut", "paste"
  296. ),
  297. array(
  298. "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
  299. "lefttoright", "righttoleft", "separator",
  300. "orderedlist", "unorderedlist", "outdent", "indent"
  301. ),
  302. array(
  303. "undo", "redo", "space", "removeformat", "forecolor", "hilitecolor", "separator",
  304. "inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator",
  305. "popupeditor", "killword", "separator", "showhelp", "about"
  306. )
  307. );
  308.  
  309. // .....................................................................
  310. /** Constructor for new HTMLArea configuration object */
  311.  
  312. function htmlarea_config() {
  313. } // HTMLArea_config
  314. // .....................................................................
  315. /**
  316. * Render this config as a string of Javascript which could be put into
  317. * a webapage and used to set the configuration of a real HTMLArea
  318. * object.
  319. */
  320. function render($configvar) {
  321. $s = "";
  322. $s .= "var $configvar = new HTMLArea.Config();\n";
  323. if (isset($this->width) && $this->width != "") {
  324. $s .= "$configvar.width = '$this->width';\n";
  325. }
  326. if (isset($this->height) && $this->height != "") {
  327. $s .= "$configvar.height = '$this->height';\n";
  328. }
  329. if (isset($this->statusBar) && $this->statusBar === false) {
  330. $s .= "$configvar.statusBar=" . ($this->statusBar ? "true" : "false") . ";\n";
  331. }
  332. if (isset($this->htmlareaPaste) && $this->htmlareaPaste === true) {
  333. $s .= "$configvar.htmlareaPaste=" . ($this->htmlareaPaste ? "true" : "false") . ";\n";
  334. }
  335. if (isset($this->undoSteps)) {
  336. $s .= "$configvar.undoSteps=" . $this->undoSteps . ";\n";
  337. }
  338. if (isset($this->sizeIncludesToolbar) && $this->sizeIncludesToolbar === false) {
  339. $s .= "$configvar.sizeIncludesToolbar=" . ($this->sizeIncludesToolbar ? "true" : "false") . ";\n";
  340. }
  341. if (isset($this->pageStyle) && $this->pageStyle != "") {
  342. $s .= "$configvar.pageStyle = '$this->pageStyle';\n";
  343. }
  344. if (isset($this->killWordOnPaste) && $this->killWordOnPaste === false) {
  345. $s .= "$configvar.killWordOnPaste=" . ($this->killWordOnPaste ? "true" : "false") . ";\n";
  346. }
  347. if (isset($this->htmlRemoveTags) && $this->htmlRemoveTags != "") {
  348. $s .= "$configvar.htmlRemoveTags = '$this->htmlRemoveTags';\n";
  349. }
  350. if (isset($this->toolbar)) {
  351. $toolbar = $this->toolbar;
  352. if (is_string($toolbar)) {
  353. switch ($toolbar) {
  354. case "basic":
  355. $toolbar = $this->toolbar_basic;
  356. break;
  357. case "medium":
  358. $toolbar = $this->toolbar_medium;
  359. break;
  360. default:
  361. $toolbar = $this->toolbar_full;
  362. } // switch
  363. }
  364. $toolbar_lines = array();
  365. foreach ($toolbar as $toolbar_line) {
  366. $toolbar_lines[] = "[\"" . implode("\",\"", $toolbar_line) . "\"]";
  367. }
  368. $s .= "$configvar.toolbar = [" . implode(",\n", $toolbar_lines) . "];\n";
  369. }
  370. if (isset($this->fontnames)) {
  371. $fonts = array();
  372. foreach ($this->fontnames as $fontlabel => $fontvalue) {
  373. $fonts[] = "\"$fontlabel\": \"$fontvalue\"";
  374. }
  375. $s .= "$configvar.fontname = {" . implode(",", $fonts) . "};\n";
  376. }
  377. if (isset($this->fontsizes)) {
  378. $sizes = array();
  379. foreach ($this->fontsizes as $sizlabel => $sizvalue) {
  380. $sizes[] = "\"$sizlabel\": \"$sizvalue\"";
  381. }
  382. $s .= "$configvar.fontsize = {" . implode(",", $sizes) . "};\n";
  383. }
  384. if (isset($this->blockformats)) {
  385. $formats = array();
  386. foreach ($this->blockformats as $fmtlabel => $fmtvalue) {
  387. $formats[] = "\"$fmtlabel\": \"$fmtvalue\"";
  388. }
  389. $s .= "$configvar.formatblock = {" . implode(",", $formats) . "};\n";
  390. }
  391. // Return the Javascript code..
  392. return $s;
  393. } // render
  394.  
  395. } // htmlarea_config class
  396. // ----------------------------------------------------------------------
  397.  
  398. /** The global control object which has to be used
  399. * to initialise the plugins, and render the environment
  400. */
  401. global $HTMLAREA;
  402. $HTMLAREA = new htmlarea();
  403.  
  404. // ----------------------------------------------------------------------
  405. // FUNCTIONS
  406.  
  407. /**
  408. * Function to set plugins to be loaded. When you are using one of
  409. * these HTMLArea editors on a webpage, call this to define which of
  410. * the allowed plugins you want loaded. The possibilities currently
  411. * are as follows:
  412. * ContextMenu
  413. * CSS
  414. * TableOperations
  415. * ListType
  416. * CharacterMap
  417. * HtmlTidy
  418. * EnterParagraphs
  419. * FullPage
  420. * @param string $plugins A comma-delimited list of plugins
  421. */
  422. function htmlarea_plugins($plugins) {
  423. global $HTMLAREA;
  424. if (is_object($HTMLAREA) && method_exists($HTMLAREA, "load_plugins")) {
  425. $HTMLAREA->load_plugins($plugins);
  426. }
  427. } // htmlarea_plugins
  428. // ----------------------------------------------------------------------
  429.  
  430. /**
  431. * Wysiwyg Field class
  432. * A field which renders a textarea form element as a Wysiwyg editor.
  433. * This is based on the package 'HTMLarea', by Mihai Bazon.
  434. * This class leverages the standard memofield. In fact we render a standard
  435. * memofield, and the main diference is only the setting of a classid, and
  436. * rendering the javascript for HTMLarea to initialisei itself.
  437. * @package form
  438. */
  439. class form_wysiwygfield extends form_memofield {
  440. /** Unique ID of this form element
  441. @access private */
  442. var $wysiwyg_id = "wysiwyg";
  443. /** Plugins we want to register for this field
  444. @access private */
  445. var $plugins = array();
  446. /** CSS Styles we want to display for this field
  447. @access private */
  448. var $css_styles;
  449. /** The configuration override settings to use. This is
  450. an object of htmlarea_config class.
  451. @access private */
  452. var $config;
  453. // .....................................................................
  454. /** Constructor - create a wysiwyg form element..
  455. * @param string $name The name of the field
  456. * @param string $label The label which can be displayed alongside the field
  457. * @param string $value The value of the field
  458. * @param boolean $editable Editability: EDITABLE or DISPLAY_ONLY (true or false)
  459. * @param string $css CSS class or style to apply to the button
  460. * @param integer $width Width of the memo field in characters
  461. * @param integer $rows Height of the memo field in lines
  462. */
  463. function form_wysiwygfield($name="", $label="", $value="", $editable=EDITABLE, $css="", $width=STD_WIDTH, $rows=5) {
  464. global $HTMLAREA;
  465. $this->form_memofield($name, $label, $value, $editable, $css, $width, $rows);
  466. $this->wysiwyg_id = $name;
  467. $this->setid($this->wysiwyg_id);
  468. // Default CSS styles..
  469. $this->css_styles = $HTMLAREA->default_css_styles;
  470. // Empty config object..
  471. $this->config = new htmlarea_config();
  472. } // form_wysiwygfield
  473. // .....................................................................
  474. /**
  475. * Set the styles to provide for this Wysiwyg editor. Styles are displayed
  476. * when you register the "CSS" plugin. This method either replaces (the
  477. * default action) or appends the given list (or array) of styles to the
  478. * editor. Pass the styles list either as a comma-delimited string, or
  479. * an array. Each style should be in the format 'label : classname' as
  480. * shown in this example: 'Light background : axbglite'
  481. * (You should omit the quotes, which are just to delimit the example)
  482. * @param mixed $new_styles Comma-delimited list or array of style definitions
  483. * @param string $mode If "append" add styles to existing, else replace
  484. */
  485. function set_styles($new_styles, $mode="replace") {
  486. global $HTMLAREA;
  487. if (!is_array($new_styles)) {
  488. $new_styles = explode(",", $new_styles);
  489. }
  490. if ($mode == "replace") {
  491. $this->css_styles = $new_styles;
  492. }
  493. else {
  494. foreach ($new_styles as $style) {
  495. $this->css_styles[] = $style;
  496. }
  497. }
  498. } // set_styles
  499. // .....................................................................
  500. /** Set the HTMLArea page style. This is the overall style setting(s)
  501. * which are applied to the HTMLArea widget and so here is where you
  502. * determine such basic things as the font settings of the content which
  503. * is displayed/edited etc.
  504. * @param string $css_style The style setting for the editor 'page'
  505. */
  506. function set_pagestyle($css_style) {
  507. $this->config->pageStyle = $css_style;
  508. } // set_pagestyle
  509. // .....................................................................
  510. /** Set a new toolbar definition. Toolbars are arrays of arrays of lists
  511. * of HTMLArea widgets. Each array is a line of these widgets. For an
  512. * example see the default setting for the toolbar in this class. You
  513. * can EITHER give a full toolbar definition here as an array of arrays
  514. * of toolbar widgets, OR give a preset toolbar ID string. Presets that
  515. * we have defined so far are:
  516. * "basic" - Just enough to enter text, bold/italic etc.
  517. * "medium" - As above but with colour, links, raw HTML etc.
  518. * "full" - Everything available
  519. * @param mixed $new_toolbat Array of toolbar lines, or preset toolbar id
  520. */
  521. function set_toolbar($new_toolbar) {
  522. $this->config->toolbar = $new_toolbar;
  523. } // set_toolbar
  524. // .....................................................................
  525. /** Set a new list of selectable font families. This array should be an
  526. * associative one in the form:
  527. * "Arial" => "arial,helvetica,sans-serif",
  528. * "Courier New" => "courier new,courier,monospace",
  529. * ...
  530. * @param array $new_fontnames Array of font family names to use
  531. */
  532. function set_fontnames($new_fontnames) {
  533. if (is_array($new_fontnames)) {
  534. $this->config->fontnames = $new_fontnames;
  535. }
  536. } // set_fontnames
  537. // .....................................................................
  538. /** Set a new list of selectable font sizes. The sizes array should be
  539. * an associative one in the form:
  540. * "1 (8 pt)" => "1",
  541. * "2 (10 pt)" => "2",
  542. * ...
  543. * @param array $new_blocksizes Array of font sizes to use
  544. */
  545. function set_fontsizes($new_fontsizes) {
  546. if (is_array($new_fontsizes)) {
  547. $this->config->fontsizes = $new_fontsizes;
  548. }
  549. } // set_fontsizes
  550. // .....................................................................
  551. /** Set a new list of selectable block formats. The array should be an
  552. * associative one in the form:
  553. * "Heading 1" => "h1",
  554. * "Heading 2" => "h2",
  555. * ...
  556. * @param array $new_blockformats Array of block formats to use
  557. */
  558. function set_blockformats($new_blockformats) {
  559. if (is_array($new_blockformats)) {
  560. $this->config->blockformats = $new_blockformats;
  561. }
  562. } // set_blockformats
  563. // .....................................................................
  564. /** Set the HTMLArea sizing. The default is 'auto' for both width
  565. * and height, which gives you an editing area filling the are that
  566. * the original memofield widget would have filled.
  567. * @param string $width Width of the HTMLArea editor
  568. * @param string $height Height of the HTMLArea editor
  569. * @param boolean $inctoolbar Whether sizing includes the toolbar
  570. */
  571. function set_metrics($width="", $height="", $inctoolbar=true) {
  572. if ($width != "") {
  573. $this->config->width = $width;
  574. }
  575. if ($height != "") {
  576. $this->config->height = $height;
  577. }
  578. $this->config->sizeIncludesToolbar = ($inctoolbar === true);
  579. } // set_metrics
  580. // .....................................................................
  581. /** Set the regular expression to use for removing dis-allowed HTML
  582. * tags from the editor content. This allows you to specify a regex
  583. * matching those tags you don't want to ever appear in the content.
  584. * @param string $regex Regular expression matching disallowed tags
  585. */
  586. function set_remove_regex($regex="") {
  587. $this->config->htmlRemoveTags = $regex;
  588. } // set_remove_regex
  589. // .....................................................................
  590. /** Set the HTMLArea undo steps maximum. The default number is 20. Use
  591. * this method to change that.
  592. * @param integer $steps Number of undo steps to record.
  593. */
  594. function set_undo_steps($steps=20) {
  595. $this->config->undoSteps = $steps;
  596. } // set_undo_steps
  597. // .....................................................................
  598. /** Set the HTMLArea statusbar display mode, true or false.
  599. * @param boolean $mode Whether to display the statusbar or not
  600. */
  601. function set_statusbar($mode=true) {
  602. $this->config->statusBar = $mode;
  603. } // set_statusbar
  604. // .....................................................................
  605. /** Set the HTMLArea Paste mode. If set to true, then the HTMLArea
  606. * widget will intercept ^V and use the HTMLArea paste command. If
  607. * false, then it passes ^V through to browser editor widget
  608. * @param boolean $mode Whether to intercept ^V or not
  609. */
  610. function set_paste_intercept($mode=true) {
  611. $this->config->htmlareaPaste = $mode;
  612. } // set_paste_intercept
  613. // .....................................................................
  614. /**
  615. * Set the plugins to register for this Wysiwyg editor. This is a subset
  616. * of the allowed plugins which were given in the original call to the
  617. * @see htmlarea_plugins() function. If you want to just register all
  618. * of the possibilities, then just leave the argument list empty, or
  619. * explicitly set it to "all" (the default).
  620. * @param string $pluginlist Comma-delimited list of plugins to register
  621. */
  622. function register_plugins($pluginlist="all") {
  623. global $HTMLAREA;
  624. if ($pluginlist == "all") {
  625. $this->plugins = $HTMLAREA->loaded_plugins;
  626. }
  627. else {
  628. $plugins = explode(",", $pluginlist);
  629. $this->plugins = array();
  630. foreach ($plugins as $plugin) {
  631. if (in_array($plugin, $HTMLAREA->loaded_plugins)) {
  632. $this->plugins[] = $plugin;
  633. }
  634. }
  635. }
  636. } // register_plugins
  637. // .....................................................................
  638. /**
  639. * Register with HTMLArea for this editor to work. We produce the required
  640. * javascript. This is an internal method usually executed just prior to
  641. * rendering.
  642. * @access private
  643. */
  644. function register() {
  645. global $HTMLAREA, $RESPONSE, $LIBDIR;
  646. if (isset($RESPONSE) && file_exists($RESPONSE->site_docroot."$LIBDIR/js/htmlarea/htmlarea.js")) {
  647. $wysiwyged = $this->wysiwyg_id . "_ed";
  648. $wysiwygconfig = $this->wysiwyg_id . "_config";
  649.  
  650. $ssheet = new stylesheet($RESPONSE->site_docroot . $RESPONSE->head->stylesheet);
  651. if ($ssheet->opened) {
  652. //$bodystyle = $ssheet->style("body");
  653. //$parastyle = $ssheet->style("p");
  654. //$this->set_pagestyle("body {" . $bodystyle . "} p {" . $parastyle . "}");
  655. $this->set_pagestyle("@import url( " . $RESPONSE->site_url . $RESPONSE->head->stylesheet . " );");
  656. }
  657.  
  658. // HTMLArea editor widget for this field..
  659. $RESPONSE->add_named_script("var $wysiwyged=null;\n", "htmlarea objects");
  660. $HTMLAREA->add_script(
  661. $this->config->render($wysiwygconfig)
  662. . "$wysiwyged=new HTMLArea(\"$this->wysiwyg_id\",$wysiwygconfig);\n"
  663. );
  664.  
  665. // Register plugins with this field..
  666. foreach ($this->plugins as $plugin) {
  667. switch ($plugin) {
  668. case "CSS":
  669. if (count($this->css_styles > 0)) {
  670. $HTMLAREA->add_script(
  671. "$wysiwyged.registerPlugin(CSS, {\n"
  672. . "combos : [\n"
  673. . " { label: \"\",\n"
  674. . " options: {\n"
  675. );
  676. $css_styles = array();
  677. foreach ($this->css_styles as $style) {
  678. $style = preg_replace("/[\"',]/", "", $style);
  679. $stylebits = explode(":", $style);
  680. $css_styles[] = " \"" . trim($stylebits[0]) . "\" : \"" . trim($stylebits[1]) . "\"";
  681. $style_list = implode(",\n", $css_styles);
  682. if (!strstr($css_styles[0], "&mdash; styles &mdash;")) {
  683. $style_list = " \"&mdash; styles &mdash;\" : \"\",\n" . $style_list;
  684. }
  685. } // foreach
  686. $HTMLAREA->add_script($style_list);
  687. $HTMLAREA->add_script(
  688. " }\n"
  689. . " }\n"
  690. . "]\n"
  691. . "});\n"
  692. );
  693. }
  694. break;
  695. default:
  696. $HTMLAREA->add_script("$wysiwyged.registerPlugin($plugin);\n");
  697. } // switch
  698. }
  699. // Generate section for field..
  700. $HTMLAREA->add_script("$wysiwyged.generate();\n");
  701. } // if not already done
  702. } // register
  703. // ....................................................................
  704. /**
  705. * This renders the field as HTML.
  706. * @return string The wysiwyg HTMLArea editor field as HTML.
  707. */
  708. function html($name="") {
  709. if ($name != "") {
  710. $this->name = $name;
  711. $this->wysiwyg_id = $name;
  712. $this->setid($this->wysiwyg_id);
  713. }
  714. $this->register();
  715. return form_memofield::html();
  716. } // html
  717.  
  718. } // class form_wysiwygfield
  719. // ----------------------------------------------------------------------
  720.  
  721. ?>

Documentation generated by phpDocumentor 1.3.0RC3