TinyMCE.php
author Dan Fuhry <dan@enanocms.org>
Thu, 02 Jun 2011 06:24:03 -0400
changeset 0 c78d206bf01c
child 2 8c7e79d37074
permissions -rw-r--r--
First commit... it works I guess

<?php
/**!info**
{
  "Plugin Name"  : "TinyMCE",
  "Plugin URI"   : "http://enanocms.org/plugin/tinymce",
  "Description"  : "Support for the TinyMCE graphical editor",
  "Author"       : "Dan Fuhry",
  "Version"      : "0.1",
  "Author URI"   : "http://enanocms.org/",
  "Version list" : ['0.1']
}
**!*/

$plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/init.js"></script>\');');
$plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/editor_hook.js"></script>\');');

function render_text_tinymce($text)
{
	return '?>' . RenderMan::render($text, RENDER_INLINE);
}

$plugins->attachHook('get_page_source', 'get_page_src_tinymce($result["src"]);');

function get_page_src_tinymce(&$text)
{
	// gently process headings to make tinymce format them correctly
	if ( preg_match_all('/^ *?(={1,6}) *(.+?) *\\1 *$/m', $text, $matches) )
	{
		foreach ( $matches[0] as $i => $match )
		{
			$hi = strlen($matches[1][$i]);
			$heading = "<h{$hi}>{$matches[2][$i]}</h{$hi}>";
			$text = str_replace_once($match, $heading, $text);
		}
	}
	return $text;
}