Skip to content

Instantly share code, notes, and snippets.

@adamjakab
Created December 9, 2015 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamjakab/f27cf20f59d2361bd693 to your computer and use it in GitHub Desktop.
Save adamjakab/f27cf20f59d2361bd693 to your computer and use it in GitHub Desktop.
WYSIWYG - fix CKEditor version(4+) check
if (preg_match('@version:[\'"](?:CKEditor )?([\d\.]+)(?:.+revision:[\'"]([\d]+))?@', $line, $version)) {
@adamjakab
Copy link
Author

this is line ~81 in: /wysiwyg/editors/ckeditor.inc module: wysiwyg for Drupal 7

@adamjakab
Copy link
Author

opppps, this is better if you don't want warnings for $version[2] when it is missing

/**
 * 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] . (isset($version[2]) ? '.' . $version[2] : '');
    }
    $max_lines--;
  }
  fclose($library);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment