How to change TinyMCE external_image_list_url from code
when the user is about to add an image to an article i used the image list to enable him add images in a separate section and add them to article from tinyMCE but what will happen if we have a massive amount of images the user will find a long list!! it will not be easy at all? so i wish to find a way to lmake each article has its own images list images_list.php?article_id=333.. .
an accordion is the container of all articles titles in a secti开发者_JAVA百科on when click edit or add ajax with tinymce do the work but how to change the external_image_list_url property of each article?????
when generating the javascript List with a php-file, like this example from moxiecode, you should be able to get your images depending on the article.
Have fun !
Example of a PHP-generated image list file
<?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;
?>
精彩评论