Add support for Wysiwyg API to G2Image

iweb - December 22, 2008 - 12:50
Project:Gallery
Version:6.x-1.x-dev
Component:Filter / G2Image
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Hi all,
apologies if I've put this in the wrong place, but I thought it might be useful for someone.

I've previously used TinyMCE along with the Gallery module, using the G2Image filter. When I switched to WYSIWYG it took me a while to make this work, but I think I've finally managed it.

This is what I did :

gallery/gallery_g2image/gallery_g2image_settings.inc:
in the function _gallery_g2image_settings_validate, change the switch instance for 'tinymce' to:

    case 'tinymce':
      $mode = t('TinyMCE');
      if (module_exists('tinymce')) {
        $path = drupal_get_path('module', 'tinymce');
      } else if (module_exists('wysiwyg')) {
        $path = drupal_get_path('module', 'wysiwyg');
      }
      $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
      break;

and change the function _gallery_g2image_path to:

function _gallery_g2image_path($path = NULL) {
  if (!isset($path)) {
    // Standalone G2Image folder
    $path = drupal_get_path('module', 'gallery_g2image') .'/g2image';
    if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
      $path = NULL;
      // TinyMCE folder for G2Image plugin
      if (module_exists('tinymce')) {
        $path = drupal_get_path('module', 'tinymce');
        $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
        if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
          $path = NULL;
        }
      } else if (module_exists('wysiwyg')) {
      // WYSIWYG folder for G2Image plugin
        $path = drupal_get_path('module', 'wysiwyg');
        $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
        if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
          $path = NULL;
        }
      }
    }
  }

  // Store location of G2Image
  variable_set('gallery_g2image_path', isset($path) ? $path : FALSE);

  return $path;
}

This lets the g2image filter be configured in the gallery settings form correctly when adding it as a tinymce plugin.

I also needed to amend code in the WYSIWYG module - I'll submit this to them, but I've included it so there's a complete solution here.

wysiwyg/editors/tinymce.inc - added the following lines into the wysiwyg_tinymce_plugins function:

    'g2image' => array(
      'path' => $editor['library path'] .'/plugins/g2image',
      'buttons' => array('g2image' => t('g2image')),
      'internal' => TRUE,
      'load' => TRUE,
    ),

#1

sun - December 27, 2008 - 17:23
Title:WYSIWYG, TinyMCE & G2Image filter integration» Add support for Wysiwyg API to G2Image

Better title.

Instead of hacking files in Wysiwyg module, g2image should implement hook_wysiwyg_plugin(). See #287025: IMCE_Wysiwyg API bridge module for a similar implementation.

#2

profix898 - January 10, 2009 - 11:20
Status:active» needs work

I have added iweb's code for now, but I will write a patch to support Wysiwyg API shortly (marking 'code needs work').

#3

mike15 - April 15, 2009 - 06:39

Found out about G2Image from gallery2 module and was wondering if the solution is being or planned to be implemented in the near future?

Thanks in advance.

#4

helmo - April 27, 2009 - 11:59

I implemented a hook_wysiwyg_plugin() as suggested by sun.

This patch should obsolete the need for a code change in wysiwyg/editors/tinymce.inc

AttachmentSize
drupal_gallery_g2image_tinymce.patch 1.18 KB

#5

Cayenne - May 25, 2009 - 05:49

What about those of us in Drupal 5 world? Any hope for us?

#6

Ink_n_Image - June 15, 2009 - 13:02

Thanks so much for this!

It works fine in the editor, however under the gallery settings/G2Image tab it says G2Image is not installed. Is this the way it needs to be for now?

Cheers

#7

Toddv - June 29, 2009 - 03:30

Still having trouble getting the g2image button to appear in wysiwyg/tinymce. Help appreciated

What I did:

I've been a longtime user of gallery, gallery module, and tinymce (now wysiwyg). On various sites I have a number of combinations of these currently. So I was ready for a bit of wrestling to get d6.12, gallery 2.3, gallery module, wysiwyg 2.0, tinymce, and g2Image to play nice with each other.

Starting from the point where everything worked EXCEPT g2image I added a directory structure within wysiwyg like this:
sites>all>modules>wysiwyg (what I added starts here) >tinymce/jscripts/tiny_mce/plugins/g2image/

I had previously put g2image where I would expect to have to put it - within the tinymce directory (..sites/all/libraries/tinymce/jscripts/tiny_mce/plugins/g2image/). But g2 image configuration in gallery module will not find it there.

The directories are empty except then I put the full g2image into the new "plugins" folder.

Now gallery module will configure g2image but still no button.

Using latest versions of d6.12, gallery 2.3, gallery module 6.x-1.- g2 image 3.03, wysiwyg 6.x-2.0 w/ tinymce 3x.

I uninstalled gallery and g2 image, wysiwyg/tinymce, deleted the db tables, and started again. I can get the button to show in the options within wysiwyg configuration but still no g2 button appears on node/edit fields.

I also edited function wysiwyg_tinymce_plugins($editor)
'G2Image' => array(
'path' => $editor['library path'] .'/plugins/G2Image',
'buttons' => array('G2Image' => t('G2Image')),
'internal' => TRUE,
'load' => TRUE,
),

Which is what got the button to appear in the config list...
Thanks for any advice

#8

Toddv - June 29, 2009 - 20:10

Hot damn! Got it working.
1. The easiest way for me to do it was install all these d6.12, gallery 2.3, gallery module 6.x-1.- g2 image 3.03, wysiwyg 6.x-2.0 w/ tinymce 3x.(current version as of June 28, 2009)

2. I put g2image in two different directories:
a. proper place: ..sites/all/libraries/tinymce/jscripts/tiny_mce/plugins/g2image/
b. But g2 config for g2image (in the admin>gallery>setup pane) wanted a copy here: ../sites/all/modules/wysiwyg/tinymce/jscripts/tiny_mce/plugins/g2image/

When I saved the configuration settings from gallery settings g2 image it wrote the config file in ../sites/all/modules/wysiwyg/tinymce/jscripts/tiny_mce/plugins/g2image/. But wysiwyg looks for the settings in ..sites/all/libraries/tinymce/jscripts/tiny_mce/plugins/g2image/. So I just copied from one to the other.

Running the patch in #4 is what makes it all work.

#9

josh68 - July 1, 2009 - 20:33

Hello Toddv,

I've already spent hours trying to make it work.... with no success.
I've followed your steps but didn't apply the patch yet, I can see the G2Image check box in TinyMCE, but once I check it TinyMCE stops working for editing (text mode rather than wysiwyg mode).

Could you detail the patching step?
I'm under Xp with wamp. I managed to get the patch utility from gnuwin32; in what folder do I run "patch

#10

helmo - July 2, 2009 - 08:08

Please have a look at http://drupal.org/patch/apply

depending on the value of the -p option, you could e.g. with -p3 be in the sites/all/modules/gallery/gallery_g2image/ directory.

#11

iweb - July 2, 2009 - 13:18

I've been looking at this recently with regards to setting up multi-site drupal/gallery2 installs and had to revisit this.

The problem is that the wysiwyg module now expects tinymce to be installed in libraries/tinymce rather than the original modules/wysiwyg/tinymce, so when the gallery module looks for the g2image plugin it can't find it.

I've attached a patch which seems to resolve the problem with the following conditions:

  • If the libraries module (http://drupal.org/project/libraries) is installed, it should just work as is,
  • If the libraries module isn't installed, the tinymce library must be installed under the same branch as the wysiwyg module i.e. if wywiwyg is in [root]/sites/all/modules/wysiwyg then tinymce must be under [root]/sites/all/libraries/tinymce

As far as multi-site setups go, because the config.php file in the g2image plugins directory under tinymce is modified to reflect the location of the site-specific gallery, tinymce must be installed under the site-specific libraries folder. The gallery & wysiwyg modules themselves can either sit in sites/all/modules or site specific modules folders.

I'm going to try and put something in the handbook for how I've got multi-site drupal/galleries configured and working for me.

My patch is the gallery_g2image_settings patch which needs to be applied to gallery_g2image_settings.inc whilst the gallery_g2image.module.patch is the one mentioned in post #4 above.

AttachmentSize
gallery_g2image_settings.patch 4.18 KB
gallery_g2image.module.patch 1.06 KB

#12

MjrNuT - September 23, 2009 - 00:12

I have recently configured my single site this way. wysiwyg w/ tinymce. tinymce in libraries like you've described in your 2nd bullet.

My gallery is embedded (v2.3) so far w/o issue. URL rewrite is working properly. However, I cannot seem to get teh g2image to show as "enabled". Are these patches specific to resolve this? Forgive my lack of knowledge about this if it's staring me in the face.

Moreover, I presume this g2image is preventing me from embedding a photo from the gallery to a blog or page?

My sample URL to a single photo is:

http://www.mysite.com/gallery/v/Myalbum/subalbum/DSCF0372.jpg.html

I've read the description of the syntax use of: [G2: item_id n= number type= type size= number class= name frame= name album_frame= name item_frame= name ]

But I don't see where to obtain the necessary info for each field.

I apologize if this should not have been posted here and look for any assistance/direction.

Thanks

#13

helmo - September 25, 2009 - 11:32

If all is well you should have a G2 icon in your tinymce toolbar, which allows you to lookup an image in a pop-up window.

After hitting the insert button on this pop-up a tag like "[G2:2637]" is added, and is sufficient in my setup to display a thumbnail.
The other parameters are optional, of which size is probably the most commonly used.

#14

patrickkhong - October 1, 2009 - 02:37

will this be implemented in the next wysiwyg version?

#15

MjrNuT - October 7, 2009 - 17:30

I did not have to perform any patches.

I followed this to implement a successful g2image installation. http://drupal.org/node/300305

The OP, imo, lacks some details.

 
 

Drupal is a registered trademark of Dries Buytaert.