2
votes

I am trying to work with ckeditor and wysiwyg in Drupal 7, but I keep receiving this error:

Notice: Undefined offset: 2 in wysiwyg_ckeditor_version() (line 85 of /var/www/sites/all/modules/wysiwyg/editors/ckeditor.inc).

This is line 85:

return $version[1] . '.' . $version[2];

It is part of a larger function:

/**
* Detect editor version.
*
* @param $editor
*   An array containing editor properties as returned from hook_editor().
*
* @return
*   The installed editor version.
*/
function wysiwyg_ckeditor_version($editor) {
  $library = $editor['library path'] . '/ckeditor.js';
  if (!file_exists($library)) {
    return;
  }
  $library = fopen($library, 'r');
  $max_lines = 8;
  while ($max_lines && $line = fgets($library, 500)) {
    // version:'CKEditor 3.0 SVN',revision:'3665'
    // version:'3.0 RC',revision:'3753'
    // version:'3.0.1',revision:'4391'
    if (preg_match('@version:[\"|\'](?:CKEditor )?([\d\.]+)(?:.+revision:[\"|\']  ([\d]+))?@', $line, $version)) {
      fclose($library);
      // Version numbers need to have three parts since 3.0.1.
      $version[1] = preg_replace('/^(\d+)\.(\d+)$/', '${1}.${2}.0', $version[1]);
      return $version[1] . '.' . $version[2];
    }
    $max_lines--;
  }
  fclose($library);
}

Im sorry I cant provide any more details, but I have very little experience working with Drupal, or code in php for that matter. Does anyone know what my issue is?

It might have something to do with

if (preg_match('@version:[\"|\'](?:CKEditor )?([\d\.]+)(?:.+revision:[\"|\']  ([\d]+))?@', $line, $version)) {

I had to go into the .inc file and change a certain character to [\"|\'] to get ckeditor to be compatible. That is the only thing I could think of that may be affecting the file.

1

1 Answers

4
votes

To resolve the warning issue, you should update the return value on line 85 with the following code:

return $version[1] . ((isset($version[2])) ? '.' . $version[2] : '');