Extending RichText editor with callbacks?

Hi guys,
I want to add functionality to the RichText editor (i.e. CKEditor) to allow adding inline images. So, I need to integrate it with a file manager that is explained in File Manager Integration.

I’ve already created a very simple uploader (uploader.pl):

#!/usr/bin/perl -wT 
use strict; 
use CGI; 
use CGI::Carp qw ( fatalsToBrowser ); 
use File::Basename; 

$CGI::POST_MAX = 1024 * 5000; 
my $safe_filename_characters = "a-zA-Z0-9_.-"; 
my $upload_dir = "uploads/"; 

my $query = new CGI; 
my $filename = $query->param("upload"); 

if ( !$filename ) 
    print $query->header ( ); 
    print "There was a problem uploading your photo (try a smaller file)."; 

my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); 
$filename = $name . $extension; 
$filename =~ tr/ /_/; 
$filename =~ s/[^$safe_filename_characters]//g; 

if ( $filename =~ /^([$safe_filename_characters]+)$/ ) 
 $filename = $1; 
 die "Filename contains invalid characters"; 

my $upload_filehandle = $query->upload("upload"); 

open ( UPLOADFILE, ">../$upload_dir$filename" ) or die "$!"; 
binmode UPLOADFILE; 

while ( <$upload_filehandle> ) 
     print UPLOADFILE; 


my $CKEditorFuncNum = $query->url_param("CKEditorFuncNum");
my $url = "$upload_dir$filename";
my $re = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, \'$url\', \'\')</script>";

print $query->header("Content-type: text/html; charset=utf-8"); 
print $re;

This script works if I use CKEditor when I use it inside an HTML page, but I don’t know how to integrate it within RT.

My question is, do I need to create an RT extension to handle file browsing/uploading? If yes, do I need to define the uploader as a callback?

Sorry if my question sounds very dumb especially because I’m very new to Perl and RT extensions :blush:

So you want a way to POST/GET to your Perl code? I believe you can create a helper files:


You’ll want to set the RichText config:

config.imageUploadUrl = RT.Config.WebPath + '/Helpers/Upload/RichTextImage';

I solved the problem by converting the script to a mason template and added it to my RT extension. Now, the question is: how can I access the uploaded image(s)?
For example, if I upload foo.jpg to /opt/rt5/static/uploads, what would be the URL to foo.jpg?