You are here

function wysiwyg_get_all_editors in Wysiwyg 6.2

Same name and namespace in other branches
  1. 5.2 wysiwyg.module \wysiwyg_get_all_editors()
  2. 5 wysiwyg.module \wysiwyg_get_all_editors()
  3. 6 wysiwyg.module \wysiwyg_get_all_editors()
  4. 7.2 wysiwyg.module \wysiwyg_get_all_editors()

Compile a list holding all supported editors including installed editor version information.

Related topics

2 calls to wysiwyg_get_all_editors()
wysiwyg_get_editor in ./wysiwyg.module
Return library information for a given editor.
wysiwyg_profile_overview in ./wysiwyg.admin.inc
Display overview of setup Wysiwyg Editor profiles; menu callback.

File

./wysiwyg.module, line 962
Integrates client-side editors with Drupal.

Code

function wysiwyg_get_all_editors() {
  static $editors;
  if (isset($editors)) {
    return $editors;
  }
  $editors = wysiwyg_load_includes('editors', 'editor');
  foreach ($editors as $editor => $properties) {

    // Fill in required properties.
    $editors[$editor] += array(
      'title' => '',
      'vendor url' => '',
      'download url' => '',
      'editor path' => wysiwyg_get_path($editors[$editor]['name']),
      'library path' => wysiwyg_get_path($editors[$editor]['name']),
      'libraries' => array(),
      'installed' => FALSE,
      'version callback' => NULL,
      'themes callback' => NULL,
      'settings form callback' => NULL,
      'settings callback' => NULL,
      'plugin callback' => NULL,
      'plugin settings callback' => NULL,
      'versions' => array(),
      'js path' => $editors[$editor]['path'] . '/js',
      'css path' => $editors[$editor]['path'] . '/css',
    );

    // Check whether library is present.
    if (!$editors[$editor]['installed'] && !($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) {

      // Find the latest supported version.
      ksort($editors[$editor]['versions']);
      $version = key($editors[$editor]['versions']);
      foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
        if (version_compare($version, $supported_version, '<')) {
          $version = $supported_version;
        }
      }

      // Apply library version specific definitions and overrides.
      // This is to show the newest installation instructions.
      $editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
      continue;
    }
    $installed_version = NULL;

    // Detect library version.
    if (function_exists($editors[$editor]['version callback'])) {
      $installed_version = $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]);
    }
    if (empty($installed_version)) {
      $editors[$editor]['error'] = t('The version of %editor could not be detected.', array(
        '%editor' => $properties['title'],
      ));
      $editors[$editor]['installed'] = FALSE;
      continue;
    }
    $editors[$editor]['installed version verified'] = TRUE;
    if (!empty($editors[$editor]['verified version range'])) {
      $version_range = $editors[$editor]['verified version range'];
      if (version_compare($installed_version, $version_range[0], '<') || version_compare($installed_version, $version_range[1], '>')) {
        $editors[$editor]['installed version verified'] = FALSE;
      }
    }

    // Determine to which supported version the installed version maps.
    ksort($editors[$editor]['versions']);
    $version = 0;
    foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
      if (version_compare($installed_version, $supported_version, '>=')) {
        $version = $supported_version;
      }
    }
    if (!$version) {
      $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array(
        '%version' => $installed_version,
        '%editor' => $editors[$editor]['title'],
      ));
      $editors[$editor]['installed'] = FALSE;
      continue;
    }

    // Apply library version specific definitions and overrides.
    $editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
    unset($editors[$editor]['versions']);
  }
  drupal_alter('wysiwyg_editor', $editors);
  return $editors;
}