1<?php
2
3/* Hides the wysiwyg markup from DW editor */
4
5if(!defined('wysiwyg_GUID')) define('wysiwyg_GUID','33008AD8-D1B7-4739-A27F-FB64353077D1');
6
7function get_wysiwyg($name, $markup) {
8  preg_match("/<wysiwyg ".$name." >>>>>".wysiwyg_GUID."(.*?)".wysiwyg_GUID."<<<<< \\/>/",$markup,$matches);
9  return $matches[1];
10}
11
12function save_wysiwyg($pickle, $markup) {
13  // put back the wysiwyg bits
14  if(isset($pickle)) {
15    foreach ($pickle as $name) {
16      foreach ($name as $key => $html) {
17        $markup = insert_wysiwyg($key, $html, $markup);
18      }
19    }
20  }
21  // add the >>>> <<<< bits to new markup
22  $markup = preg_replace("/(?<=<wysiwyg )([^\\s]*) (?=\\/>)/","$1 >>>>>".wysiwyg_GUID."Edit me!".wysiwyg_GUID."<<<<< ",$markup);
23  return $markup;
24}
25
26function load_wysiwyg($markup) {
27  // take out the wysiwyg bits
28  $allPickled = array();
29  $names = nameList_wysiwyg($markup);
30  foreach($names as $name) {
31    $pickle = array();
32    $pickle[$name] = get_wysiwyg($name, $markup);
33    $allPickled[] = $pickle;
34    $markup = hide_wysiwyg($name, $markup);
35  }
36  $ret = array();
37  $ret['markup'] = $markup;
38  $ret['pickle'] = $allPickled;
39  return $ret;
40}
41
42function hide_wysiwyg($name, $markup) {
43  $ret = preg_replace("/(?<=<wysiwyg\\s".$name.") >>>>>".wysiwyg_GUID.".*?".wysiwyg_GUID."<<<<< (?=\\/>)/", " ", $markup);
44  return $ret;
45}
46
47function insert_wysiwyg($name, $html, $markup) {
48  return preg_replace("/(?<=<wysiwyg ".$name.") (?=\\/>)/", " >>>>>".wysiwyg_GUID.$html.wysiwyg_GUID."<<<<< ", $markup);
49}
50
51function nameList_wysiwyg($markup) {
52  $nameList = array();
53  preg_match_all("/<wysiwyg ([^\\s]*).*?\\/>/",$markup,$matches);
54  foreach ($matches[1] as $match) {
55    $nameList[] = $match;
56  }
57  return $nameList;
58}
59
60?>