Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks, I'm interested in using tinymce (tinymce.moxiecode.com) as an editing interface to a perl guestbook I'm building. I've found plently of references on the net about people who say they've used it with perl, but no practical examples.
Has anyone here used it with perl, and would they be willing to share the code to interface the two together?

Replies are listed 'Best First'.
Re: tinymce and perl
by bradcathey (Prior) on Dec 19, 2007 at 03:33 UTC

    We use TinyMCE in our own home-rolled CMS, and except for the tricky implementation of images and the ugly HTML editing screen, we like it. It's pretty solid. And as far was we are concerned, integrating it with Perl is no big deal. It's basically just working with a large textarea. So, you need to use Perl, or any language, to tap the DB for the content to edit, display it, and then save it back.

    Not that you have to, but we just happen to use CGI::Application for our framework, store all our data in MySQL tables, and use HTML::Template for display. And then typical BREAD-like Perl code to handle all the in-between.

    PERL:

    sub edit { my $self = shift; my $template = $self->load_tmpl( 'edit.tmpl', die_on_bad_params => 0); my $dbh = $self->dbconnect(server =>'master',db => 'admin'); my $stmt = qq/SELECT content, DATE_FORMAT(lastupdated, '%b %e, %Y a +t %r') AS date FROM content/; my $content = $dbh->selectrow_hashref($stmt, undef); $template -> param( content => $content->{'content'}, date => $content->{'date'}); return $template->output; }

    HTML:

    <form class="form" action="/" method="post"> <input type="hidden" name="rm" value="u" /> <script language="javascript" type="text/javascript" src="tiny_m +ce/tiny_mce.js"></script> <script language="javascript" type="text/javascript"> tinyMCE.init({ theme : "advanced", mode : "exact", elements : "content", content_css : "mysite.css", width : "620", height : "600", extended_valid_elements : "a[href|target|name]", plugins : "table", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_buttons3_add_before : "tablecontrols,separator +", theme_advanced_styles : "Header 1=header1;Header 2=header2;He +ader 3=header3;Table Row=tableRow1", // Theme specific setting CSS cl +asses debug : false }); </script> <textarea id="content" name="content" cols="40" rows="40"><tmpl_var + content></textarea> <input type="submit" value="Update Schedule" /> <input type="button" value="Cancel" onclick="window.location='/'" / +> (Last updated: <tmpl_var date>)</p> </form>

    UPDATE: Fixed misleading grammar.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      Also, you might want to look at TinyMCE Perl Compressor - it's a script that I wrote based on the PHP version available on the tinyMCE site - just reduces the impact of downloading all that JS for your users.

      Clint

Re: tinymce and perl
by moritz (Cardinal) on Dec 18, 2007 at 21:06 UTC
    From the example in the documentation it seems that you don't have to change any server side scripts at all (except to emit the changed HTML), because TinyMCE "automagically" modifies text areas - they can still be submitted with a normal HTTP POST.
Re: tinymce and perl
by shmem (Chancellor) on Dec 18, 2007 at 23:11 UTC
    WebGUI, an open source CMS written in perl, uses tinymce.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}