* 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
Comment #1
nquocbao commentedComment #2
twodYou 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?
Comment #3
nquocbao commentedActually, 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.
Comment #4
twodYes I noticed that they include jQuery etc too. I'm not sure jWysiwyg was packaged like that before.
The installation instructions do mention that:
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 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...
Comment #5
sunGood call.
Comment #6
nquocbao commentedThe patch looks ok. But why 7.x ?
Comment #7
sunIn 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.
Comment #8
twodI'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?
Comment #9
sunThanks 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.
Comment #10
sunThis 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.
Comment #11
nquocbao commentedIt works now.
Comment #12
sunum, what works now? Did you want to attach a patch? :)
Comment #13
nquocbao commentedHehe, here is it :D. I hope git patch is ok.
Comment #14
sungit 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.