I may be putting this in the totally wrong place, but I think it should go somewhere.

I have made a patch for tinyMCE to use the included advimage plugin instead of the the drupalimage plugin/img_assist.

It creates a new image list that is used instead of img_assist.

In tinymce.module make these changes
Add into tinymce_menu around line 19

    $items[] = array('path' => 'tinymce_advimg', 'title' => t('tinymce Advanced Image List'), 'callback' => 'tinymce_advimg_list', 'access' => user_access('access content'), 'type' => MENU_CALLBACK);

Then add this function to the end of the file

function tinymce_advimg_list() {
	$result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type='image' ORDER BY n.title ASC");
	$content = "var tinyMCEImageList = new Array(\n";
	$aContent = array();
	while ($node = db_fetch_object($result)) {
        $aContent[]= "    [\"".$node->title."\", \"?q=image/view/".$node->nid."\"]";
	}
	$content .= implode(",\n",$aContent).");";
	echo $content;
}

Also the phptemplate/template.php needs the configuration set in the phptemplate_tinymce_theme. Here is mine.

  switch ($theme_name) {
    case 'advanced':
      $init['extended_valid_elements'] = 'a[href|target|name|title|onclick]';
      $init['theme_advanced_buttons3_add_before'] = 'tablecontrols,separator';
      $init['plugins'] = 'table,emotions,print,advimage';
      $init['external_image_list_url'] = "?q=tinymce_advimg";

      break;
  }

You may need to clear your cache in order to get the new file to register.

If someone with CVS access wants to make this a patch that would be fine with me.

Comments

matt westgate’s picture

What's the advantage of using this plugin over the other one?

Does the advimage plugin ship with TinyMCE?

code rader’s picture

Yes, advimage does come with the tinyMCE download. The big advantage I needed it for was I was getting the warning in MSIE that the window had lost communication with the parent. Then it no longer worked. I think it also makes a simpler integration without having to rely on img_assist.

matt westgate’s picture

Version: 4.6.x-1.x-dev » master

I'd like to get some feedback from others about this as well.

Folks, does it meet your needs better than the img_assist integration?

RobRoy’s picture

I tried this and advimage doesn't have any upload functionality. That is the big part of img_assist that I need.

code rader’s picture

I suppose you could still use img_assist for image uploading. I am using just image for that part. I don't think this would keep you from using img_assist, it would just use adimage for the image insert in the editor itself.

bomarmonk’s picture

Yes, I'm still getting the message that my browser window has lost communication with the parent. This only happens with the camera/toolbar button for image assist. If I don't upload the image_asst plugin to tinymce, I can just use the other image assist button at the bottom of my text editor (no errors-- everything works great). However, if I edit in full screen mode, my image assist button isn't there. So there's a definite need to get that image assist camera button/plugin working correctly, or to have the advimage plugin working along side image assist.

bomarmonk’s picture

I tried the advimage patch, but I'm not sure about where to make the template changes. I'm using a theme that runs on phptemplate, but do I just need to add the advimage change to my page.tpl.php file, or do I need to create a seperate template file for tinymce? Sorry if this is already documented somewhere...

code rader’s picture

There should be a engines/phptemplate/template.php

Add that code at the end of the function phptemplate_tinymce_theme.

I hope it works for you.

m3avrck’s picture

What about an option to include default behavior? Using img_assist or advimage?

code rader’s picture

I like the suggestion of having a default behavior. I just think this is a simpler way, but I am biased since it is my code :)

m3avrck’s picture

Status: Needs review » Closed (fixed)

Including either of these plugins with the next 4.7 release is much easier. The issue with dropped communication between windows has been fixed (it was an img_assist) issue.

urbanfalcon’s picture

This can be used as an aid to help users insert images from their attachments list without touching a line of html. However, like all things in the 4.7 build, revisions have to be taken into account:

$items[] = array('path' => 'tinymce_advimg', 
					 'title' => t('Advanced Image List'), 
					 'callback' => 'tinymce_advimg_list', 
					 'access' => user_access('access content'), 
					 'type' => MENU_CALLBACK);

and

function tinymce_advimg_list() {
   $node = node_load(array('nid' => arg(1)));
   $result = db_query("SELECT f.filename as filename, f.filepath FROM {files} f LEFT JOIN {file_revisions} r ON r.fid = f.fid WHERE f.nid='".$node->nid."' AND r.vid='".$node->vid."' ORDER BY filename ASC");
   //$result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type='image' ORDER BY n.title ASC");
   header("Content-type: text/javascript");
   $content .= "var tinyMCEImageList = new Array(\n";
   $aContent = array();
   while ($file = db_fetch_object($result)) {
      $aContent[]= "    [\"".$file->filename."\", \"".$file->filepath."\"]";
      //$aContent[]= "    [\"".$node->title."\", \"?q=image/view/".$node->nid."\"]";
      }
   $content .= implode(",\n", $aContent);
   $content .= ");";
   echo $content;
   }
urbanfalcon’s picture

Status: Closed (fixed) » Active

If you're using comment_upload.module, you'll need to make a few adjustments...note the additions/changes in the following:

  switch ($theme_name) {
    case 'advanced':
    $init['extended_valid_elements'] = 'a[href|target|name|title|onclick]';
    $init['theme_advanced_buttons3_add_before'] = 'tablecontrols,separator';
    $init['plugins'] = 'table,emotions,print,advimage';
    $init['external_image_list_url'] = base_path()."?q=tinymce_advimg/".arg(1)."/".arg(2)
    break;
  }

...and...

function tinymce_advimg_list($nid = null, $cid = null) {
    if (module_exist("comment_upload") && is_numeric($cid)){
      $comment = _comment_load($cid);
      $result = db_query("SELECT f.filename as filename, f.filepath FROM {files} f LEFT JOIN {file_revisions} r ON r.fid = f.fid LEFT JOIN {comment_files} c ON c.fid = f.fid WHERE f.nid='".$comment->nid."' AND c.cid='".$comment->cid."' ORDER BY filename ASC");	      } else {
      $node = node_load(array('nid' => $nid));
      $result = db_query("SELECT f.filename as filename, f.filepath FROM {files} f LEFT JOIN {file_revisions} r ON r.fid = f.fid WHERE f.nid='".$node->nid."' AND r.vid='".$node->vid."' ORDER BY filename ASC");
      }
  header("Content-type: text/javascript");
  $content .= "var tinyMCEImageList = new Array(\n";
  $aContent = array();
  while ($file = db_fetch_object($result)) {
    $aContent[]= "    [\"".$file->filename."\", \"".$file->filepath."\"]";
    }
  $content .= implode(",\n", $aContent);
  $content .= ");";
  echo $content;
  }
urbanfalcon’s picture

Beyond comment_upload, if you want to be able to use recently cached/attached images (before you've actually submitted the edit), then you need to include the references from the session into the array. Notice the changes I made...

function tinymce_advimg_list($nid = null, $cid = null) {
	if (module_exist("comment_upload") && is_numeric($cid)){
		$comment = _comment_load($cid);
		$result = db_query("SELECT f.filename as filename, f.filepath FROM {files} f LEFT JOIN {file_revisions} r ON r.fid = f.fid LEFT JOIN {comment_files} c ON c.fid = f.fid WHERE f.nid='".$comment->nid."' AND c.cid='".$comment->cid."' ORDER BY filename ASC");		
		} else {
		$node = node_load(array('nid' => $nid));
		$result = db_query("SELECT f.filename as filename, f.filepath FROM {files} f LEFT JOIN {file_revisions} r ON r.fid = f.fid WHERE f.nid='".$node->nid."' AND r.vid='".$node->vid."' ORDER BY filename ASC");
		}
	header("Content-type: text/javascript");
    $content .= "var tinyMCEImageList = new Array(\n";
    $options = array();
    while ($file = db_fetch_object($result)) {
		$options[]= '    ["'.$file->filename.'", "'.$file->filepath.'"]';
    	}
	foreach ($_SESSION['file_previews'] as $file) {		
		$options[]= '    ["'.$file->filename.'", "'.$file->_filename.'"]';
    	}		
    $content .= implode(",\n", $options);
	$content .= ");\n";
    echo $content;
	}
CJCJ24’s picture

Wow Cool
thanks for the post and the comment
It will be a big help to all who are using drupal

Keep it up
You can buy youtube likes

nicoloye’s picture

Status: Active » Closed (outdated)