TinyMCE.php
changeset 0 c78d206bf01c
child 2 8c7e79d37074
equal deleted inserted replaced
-1:000000000000 0:c78d206bf01c
       
     1 <?php
       
     2 /**!info**
       
     3 {
       
     4   "Plugin Name"  : "TinyMCE",
       
     5   "Plugin URI"   : "http://enanocms.org/plugin/tinymce",
       
     6   "Description"  : "Support for the TinyMCE graphical editor",
       
     7   "Author"       : "Dan Fuhry",
       
     8   "Version"      : "0.1",
       
     9   "Author URI"   : "http://enanocms.org/",
       
    10   "Version list" : ['0.1']
       
    11 }
       
    12 **!*/
       
    13 
       
    14 $plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/init.js"></script>\');');
       
    15 $plugins->attachHook('compile_template', '$template->add_header_js(\'<script type="text/javascript" src="\' . cdnPath . \'/plugins/tinymce/editor_hook.js"></script>\');');
       
    16 
       
    17 function render_text_tinymce($text)
       
    18 {
       
    19 	return '?>' . RenderMan::render($text, RENDER_INLINE);
       
    20 }
       
    21 
       
    22 $plugins->attachHook('get_page_source', 'get_page_src_tinymce($result["src"]);');
       
    23 
       
    24 function get_page_src_tinymce(&$text)
       
    25 {
       
    26 	// gently process headings to make tinymce format them correctly
       
    27 	if ( preg_match_all('/^ *?(={1,6}) *(.+?) *\\1 *$/m', $text, $matches) )
       
    28 	{
       
    29 		foreach ( $matches[0] as $i => $match )
       
    30 		{
       
    31 			$hi = strlen($matches[1][$i]);
       
    32 			$heading = "<h{$hi}>{$matches[2][$i]}</h{$hi}>";
       
    33 			$text = str_replace_once($match, $heading, $text);
       
    34 		}
       
    35 	}
       
    36 	return $text;
       
    37 }