Based on #153623: FCK Integration I made an integration for wysiwyg - tinymce
Add the following to webfmpopup.module

/**
 * Implementation of hook_wysiwyg_plugin().
 */
function webfmpopup_wysiwyg_plugin($editor) {
  static $integrated;
  switch ($editor) {
    case 'tinymce':
/*      
      if (!imce_access()) {
        return;
      }
*/      
      if (!isset($integrated)) {
        $integrated = TRUE;
        $settings = array(
          'webfmpopup' => array(
            'url' => url('webfm'),
            'appname' => t('editor'),
            'wysiwyg_module' => true,
          ),
        );
        drupal_add_js($settings, 'setting');
        drupal_add_js(drupal_get_path('module', 'webfmpopup') .'/webfmpopup.js');
      }
      return array(
        'webfmpopup' => array(
          'extensions' => array('webfmpopup' => t('webfmpopup')),
          'url' => 'http://drupal.org/project/webfmpopup',
          'options' => array(
            'file_browser_callback' => 'webfmImageBrowser',
            'inline_styles' => TRUE,
          ),
          'load' => FALSE,
        ),
      );
  }
}

Replace content of webfmpopup.js with

/* $Id$ */

function webfmpopup() {}

if (Drupal.jsEnabled) {
  $(window).load(webfmpopupGetMenusAjax);
}

// Add the send to rich text editor link to the right click menu of files.
function webfmpopupGetMenusAjax() {
  Webfm.menuHT.put('file', new Webfm.menuElement("Send to rich text editor", webfmpopup.sendtocaller, ""));
}

// Send the selected file tot he rich text editor.
webfmpopup.sendtocaller = function(obj) {
  
  // the window this popup was called from
  var doc = $(window.opener.document);

  // put the file url in the input with the id specified in the url
  var fpath = obj.filepath;
  var url_id = '#'+get_url_param('url'); 
  doc.find(url_id).val(Drupal.settings.basePath + Drupal.settings.webfmpopup.fileDirectory + fpath);
  doc.find(url_id).change();

  // put the webfm file-id in the input with the id specified in the url
  var fid = $('#'+obj.row_id).find('td').eq(1).find('a').attr('title');
  console.log(fid);
  var webfm_id = '#'+get_url_param('webfmid');
  // ATTIKS doc.find(webfm_id).val(Drupal.settings.basePath + 'webfm_send/' + fid);
  doc.find(webfm_id).val(Drupal.settings.basePath + Drupal.settings.webfmpopup.fileDirectory + fpath);
  doc.find(webfm_id).change();
  
  window.opener.focus();
  window.close();
} 


// read GET parameter from the url 
// for example on the url http://example.com/page.php?some=value&more=evenmore&get_it=yes
// calling get_url_param('get_it') would return 'yes'
function get_url_param(name) { 
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec( window.location.href ); 
	if( results == null ) return ""; 
	else return results[1];
}

//helper function - used as a wysiwyg callback
function webfmImageBrowser(fid, url, type, win) {
  var qstring = "?q=webfmpopup&url=webfmtest&webfmid=" + fid;
  win.open(Drupal.settings.basePath+qstring, '', 'width=760,height=560,resizable=1');
}

Comments

robmilne’s picture

The php function has a http://drupal.org/project/webfmpopup url. Are you planning to create a webfmpopup contrib module? If so I can remove the webfm_popup module that I placed inside webfm rc4.

robmilne’s picture

By the way, commenting out the line of code in the 'sendtocaller' javascript defeats the file security of the module. Besides, it won't work if the files are guarded by a .htaccess file.

attiks’s picture

I'll have a look at RC4 first, i used some other code from 153623 for the popup stuff. In my opinion the popup should be part of the module so all wysiwyg editors can use it.

I commented out the your code because i got some strange results if the file selected was not available in the database.

attiks’s picture

Version: 6.x-2.9-alpha2 » 6.x-2.10-rc4
Status: Active » Needs review

Patch against rc4 attached. I still get the full filename in the wysiwyg if the file doesn't exist in the database.

attiks’s picture

StatusFileSize
new1.88 KB
Niko_K’s picture

Does this code only work with the tinymce plugin for the wysiwyg module or can it also be used with other editors (such as FCKeditor integrated into the wysiwyg module)?

attiks’s picture

This code is kind of old, it's functionality is included in the web file manager, I assume it works with all wysiwyg complaint editors

dawehner’s picture

a general question

wouldn't it be cool if there would be a integration into http://drupal.org/project/wysiwyg

The advantage you can support every wyswyg-editor with writing one plugin.

attiks’s picture

Status: Needs review » Closed (fixed)

As far as I know the integration is allready done, there's a webfm popup module included.

I'm closing is this issue

jm.federico’s picture

OK, so I'm opening this with a new patch for webfm_popup.js

What I'm fixing here is that WebFM was sending the real path to TinyMCE, insted of the WebFM path which is what we want, this is how things should be:

Be aware that it seems like all of the TinyMCE patches have security issues and they don't respect permissions, haven't really tested that, but it is better than nothing.

// $Id: $

function webfm_popup() {}

if (Drupal.jsEnabled) {
  $(window).load(webfm_popupGetMenusAjax);
}

// Add the send to rich text editor link to the right click menu of files.
function webfm_popupGetMenusAjax() {
  Webfm.menuHT.put('file', new Webfm.menuElement("Send to rich text editor", webfm_popup.sendtocaller, ""));
}

// Send the selected file to the rich text editor.
webfm_popup.sendtocaller = function(obj) {
  // the window this popup was called from
  var win = window.opener.Drupal.settings.wysiwygDialogWindow || window.opener;
  var doc = $(win.document);


  // put the file url in the input with the id specified in the url
  var fpath = obj.filepath;
  var url_id = '#'+get_url_param('url');
//  doc.find(url_id).val(Drupal.settings.basePath + Drupal.settings.webfm_popup.fileDirectory + fpath);
//  doc.find(url_id).change();

  // put the webfm file-id in the input with the id specified in the url
  var fid = $('#'+obj.row_id).find('td').eq(1).find('a').attr('title');
//  console.log(fid);
//  var webfm_id = '#'+get_url_param('webfmid');
//  doc.find(webfm_id).val(Drupal.settings.basePath + 'webfm_send/' + fid);
  doc.find(url_id).val(Drupal.settings.basePath + 'webfm_send/' + fid);
//  doc.find(webfm_id).change();
  doc.find(url_id).change();

  window.opener.focus();
  window.close();
}

// read GET parameter from the url
// for example on the url http://example.com/page.php?some=value&more=evenmore&get_it=yes
// calling get_url_param('get_it') would return 'yes'
function get_url_param(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) return "";
	else return results[1];
}

function webfmImageBrowser(field_name, url, type, win) {
  Drupal.settings.wysiwygDialogWindow = win;
  window.open(getBasePath() + 'webfm_popup?url=' + field_name, 'ImageBrowser',
    'width=750,height=500,toolbar=0,resizable=1,location=0,status=0,menubar=0');
}
jm.federico’s picture

Status: Closed (fixed) » Needs review
jm.federico’s picture

StatusFileSize
new1.14 KB

Ok People,

Patch against 2.12
Works with Wysiwyg Module + Tinymce

robmilne’s picture

Status: Needs review » Fixed

In head

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

albertogreco’s picture

Status: Closed (fixed) » Needs review

Tank you very much for your work.
There is an error again in the last patch.
The function getBasePath() is undefuned.
If I change it with Drupal.settings.basePath all works very fine for me.

So the lines:

function webfmImageBrowser(field_name, url, type, win) {
  Drupal.settings.wysiwygDialogWindow = win;
  window.open(getBasePath() + 'webfm_popup?url=' + field_name, 'ImageBrowser',
    'width=750,height=500,toolbar=0,resizable=1,location=0,status=0,menubar=0');
}

became as:

function webfmImageBrowser(field_name, url, type, win) {
  Drupal.settings.wysiwygDialogWindow = win;
  window.open(Drupal.settings.basePath + 'webfm_popup?url=' + field_name, 'ImageBrowser',
    'width=750,height=500,toolbar=0,resizable=1,location=0,status=0,menubar=0');
}
nhck’s picture

Version: 6.x-2.10-rc4 » 6.x-2.x-dev
Status: Needs review » Closed (fixed)

This is already fixed in the dev release.