* warning: fopen(sites/all/libraries/jwysiwyg/jquery.wysiwyg.js) [function.fopen]: failed to open stream: No such file or directory in sites\all\modules\wysiwyg\editors\jwysiwyg.inc on line 51.
    * warning: fgets(): supplied argument is not a valid stream resource in sites\all\modules\wysiwyg\editors\jwysiwyg.inc on line 52.
    * warning: fgets(): supplied argument is not a valid stream resource in sites\all\modules\wysiwyg\editors\jwysiwyg.inc on line 53.
    * warning: fclose(): supplied argument is not a valid stream resource in sites\all\modules\wysiwyg\editors\jwysiwyg.inc on line 58.

Is it better if we avoid this error ?

function wysiwyg_jwysiwyg_version($editor) {
  $script = $editor['library path'] . '/jquery.wysiwyg.js';

  if (file_exists($script)) {
    $script = fopen($script, 'r');
    fgets($script);
    $line = fgets($script);
    if (preg_match('@([0-9\.]+)$@', $line, $version)) {
      fclose($script);
      return $version[1];
    }
    fclose($script);
  }
}

Comments

nquocbao’s picture

StatusFileSize
new732 bytes
twod’s picture

Title: Warning error with jwysiwyg » Version callback failed to open stream
Component: Code » Editor - jWysiwyg

You should not be able to get those warnings as the version callback is not called when the editor is not installed. (It counts as installed if wysiwyg_get_path() finds it.).
When do they appear?

nquocbao’s picture

Actually, I don't read the instruction very clear at the 1st time. Usually, to install an editor, you will just download the archive package, create a folder with editor name and then extract the content to that folder.

jWysiwyg structure is different to others. Because the script is located at jwysiwyg/jquery.jwysiwyg.js, while the editor version callback will check at jquery.jwysiwyg.js (the editor folder root), and we get warning message. Installation instruction does mention about that.

It's nothing serious, just a better implement for jwysiwyg version callback.

twod’s picture

Yes I noticed that they include jQuery etc too. I'm not sure jWysiwyg was packaged like that before.

The installation instructions do mention that:

So the actual library can be found at:
sites/all/libraries/jwysiwyg/jquery.wysiwyg.js

If you unpacked it like that, there's no way the editor could be detected as installed, but throw those warnings because the file can't be located.
To make that happen, the path must have been something like sites/all/libraries/jwysiwyg/jwysiwyg/jquery.wysiwyg.js, in which case the editor itself won't load.

Currently, the "is installed"-check is as simple as

if (!($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) {
  continue;
}
</code>
If that passes, the version will be checked with:
<?php
// Detect library version.
if (function_exists($editors[$editor]['version callback'])) {
  $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]);
}
if (empty($editors[$editor]['installed version'])) {
  $editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title']));      $editors[$editor]['installed'] = FALSE;
  continue;
}

If that fails, we'd like to know why. The warning you see indicates that the file could not be found at all. After this patch, it's a near-silent fail which doesn't indicate the path is a problem (might as well be the RegExp check failing).
I think a better approach would be to check the handle returned by fopen and only continue if it was successful. Flooding the logs with the fgets() warnings is unnecessary when they are a secondary problem.

An even better solution (maybe in combination with the above) would be to make the "is installed"-check look for one of the actual files instead of just the folder. With jWysiwyg, this happens to be the same file the version is read from but that's not always the case when multiple library variants are available. The problem with that approach is that we need to know the version before we know which file to check so it's a kind of catch 22...

sun’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new5.95 KB

Good call.

nquocbao’s picture

The patch looks ok. But why 7.x ?

sun’s picture

Status: Needs review » Reviewed & tested by the community

In general, and if possible, like in Drupal core, changes go into HEAD first, and are backported afterwards. Note however that 90% of Wysiwyg module is identical between major versions of Drupal core. Most patches apply cleanly to all branches.

twod’s picture

I'm fine with the patch as it is and I agree that the warnings are not so useful for the end users that we should let them show. Just not sure how the warnings would appear in the first place and if the patch might not just hide that there might be something wrong with the library placement?

sun’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reporting, reviewing, and testing! Committed to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

sun’s picture

Status: Fixed » Needs work
+++ editors/openwysiwyg.inc	30 Mar 2010 19:21:47 -0000
@@ -45,7 +45,10 @@ function wysiwyg_openwysiwyg_editor() {
 function wysiwyg_openwysiwyg_version($editor) {
-  $changelog = $editor['editor path'] . '/changelog';
+  $changelog = $editor['library path'] . '/changelog';
+  if (!file_exists($changelog)) {
+    return;
+  }

This change broke openWYSIWYG. I already felt uncomfortable with that change when I did it. #713942-6: OpenWYSIWYG broken, jWysiwyg needs jQuery 1.3+ explains why.

Sorry.

Powered by Dreditor.

nquocbao’s picture

Status: Needs work » Reviewed & tested by the community

It works now.

sun’s picture

Status: Reviewed & tested by the community » Needs work

um, what works now? Did you want to attach a patch? :)

nquocbao’s picture

StatusFileSize
new465 bytes

Hehe, here is it :D. I hope git patch is ok.

sun’s picture

Status: Needs work » Fixed

git patches are ok, but only if you use git diff --no-prefix

Thanks for reporting, reviewing, and testing! Committed to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

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