Get your own copy
Don't hesitate! Just download and test it all by yourself for free!
This option enables you to have an external list of images. This list of images can be generated by a server side page and then inserted into the image dialog windows of TinyMCE. The images can be to internal site images or external URLs.
Change in 3.0: The way that relative URLs are calculated has changed since the 2.x version - you may want to use absolute URLs for this setting.
tinyMCE.init({
...
external_image_list_url : "myexternallist.js"
});
Note: If utilizing the document_base_url option, the path to your file is relative from that base. If not set, your path is relative from the file containing the editor call.
var tinyMCEImageList = new Array(
// Name, URL
["Logo 1", "logo.jpg"],
["Logo 2 Over", "logo_over.jpg"]
);
<?php // this must be the very first line in your PHP file!
// You can't simply echo everything right away because we need to set some headers first!
$output = ''; // Here we buffer the JavaScript code we want to send to the browser.
$delimiter = "n"; // for eye candy... code gets new lines
$output .= 'var tinyMCEImageList = new Array(';
$directory = "../../img"; // Use your correct (relative!) path here
// Since TinyMCE3.x you need absolute image paths in the list...
$abspath = preg_replace('~^/?(.*)/[^/]+$~', '/$1', $_SERVER['SCRIPT_NAME']);
if (is_dir($directory)) {
$direc = opendir($directory);
while ($file = readdir($direc)) {
if (!preg_match('~^.~', $file)) { // no hidden files / directories here...
if (is_file("$directory/$file") && getimagesize("$directory/$file") != FALSE) {
// We got ourselves a file! Make an array entry:
$output .= $delimiter
. '["'
. utf8_encode($file)
. '", "'
. utf8_encode("$abspath/$directory/$file")
. '"],';
}
}
}
$output = substr($output, 0, -1); // remove last comma from array item list (breaks some browsers)
$output .= $delimiter;
closedir($direc);
}
// Finish code: end of array definition. Now we have the JavaScript code ready!
$output .= ');';
// Make output a real JavaScript file!
header('Content-type: text/javascript'); // browser will now recognize the file as a valid JS file
// prevent browser from caching
header('pragma: no-cache');
header('expires: 0'); // i.e. contents have already expired
// Now we can send data to the browser because all headers have been set!
echo $output;
?>
Put this PHP code into your PHP file (the one you set as resource in the external_image_list_url option) and your browser should receive a valid JavaScript file (which of course hasn't got the typical ".js" file extension).
jb2386
I've tried editing this page to fix a bug, but backslashes are being stripped. This causes two problems. To anyone using this code, you'll need to make these changes:
$delimiter = "n"; // for eye candy... code gets new lines
Should have a backslash before the n. It should be like this (assuming the blackslash survives my comment post:
$delimiter = "\n"; // for eye candy... code gets new lines
And this line:
if (!preg_match('~^.~', $file)) { // no hidden files / directories here...
Needs a slash before the full-stop/period, like:
if (!preg_match('~^\.~', $file)) { // no hidden files / directories here...
HerveThouzard
Hello,
There is a mistake in the Php example, this line :
$output .= 'var tinyMCEImageList = new Array(';
Should be :
$output .= 'var tinyMCELinkList = new Array(';
Bye,
Hervé