TinyMCE.php
author Dan Fuhry <dan@enanocms.org>
Thu, 02 Jun 2011 06:26:40 -0400
changeset 1 5f58dd1540b4
parent 0 c78d206bf01c
child 2 8c7e79d37074
permissions -rw-r--r--
Should probably include a copy of the LGPL too.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     1
<?php
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     2
/**!info**
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     3
{
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     4
  "Plugin Name"  : "TinyMCE",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     5
  "Plugin URI"   : "http://enanocms.org/plugin/tinymce",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     6
  "Description"  : "Support for the TinyMCE graphical editor",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     7
  "Author"       : "Dan Fuhry",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     8
  "Version"      : "0.1",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     9
  "Author URI"   : "http://enanocms.org/",
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    10
  "Version list" : ['0.1']
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    11
}
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    12
**!*/
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    13
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    14
$plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/init.js"></script>\');');
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    15
$plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/editor_hook.js"></script>\');');
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    16
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    17
function render_text_tinymce($text)
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    18
{
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    19
	return '?>' . RenderMan::render($text, RENDER_INLINE);
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    20
}
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    21
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    22
$plugins->attachHook('get_page_source', 'get_page_src_tinymce($result["src"]);');
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    23
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    24
function get_page_src_tinymce(&$text)
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    25
{
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    26
	// gently process headings to make tinymce format them correctly
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    27
	if ( preg_match_all('/^ *?(={1,6}) *(.+?) *\\1 *$/m', $text, $matches) )
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    28
	{
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    29
		foreach ( $matches[0] as $i => $match )
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    30
		{
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    31
			$hi = strlen($matches[1][$i]);
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    32
			$heading = "<h{$hi}>{$matches[2][$i]}</h{$hi}>";
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    33
			$text = str_replace_once($match, $heading, $text);
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    34
		}
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    35
	}
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    36
	return $text;
c78d206bf01c First commit... it works I guess
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    37
}