You are here

function imageeditor_initialize in Image Editor 7

Same name in this branch
  1. 7 imageeditor.module \imageeditor_initialize()
  2. 7 imageeditor.api.php \imageeditor_initialize()

API function to initialize required editors and uploaders.

2 calls to imageeditor_initialize()
imageeditor_imagefield_element_process in imageeditor_imagefield/imageeditor_imagefield.module
Process function for image editor-enabled fields.
imageeditor_inline_page_build in imageeditor_inline/imageeditor_inline.module
Implements hook_page_build().

File

./imageeditor.module, line 88
Allows online editing of images using different image editing services.

Code

function imageeditor_initialize($editors, $uploaders) {
  global $user, $language;
  static $conf_added;
  $conf_array = array();
  if (empty($conf_added)) {
    $conf_added['imageeditor'] = FALSE;
    foreach (array(
      'editor',
      'uploader',
    ) as $type) {
      foreach (imageeditor_info($type) as $codename => $plugin) {
        $conf_added[$codename] = FALSE;
      }
    }
  }

  // Base settings.
  if (!$conf_added['imageeditor']) {
    $conf_added['imageeditor'] = TRUE;
    drupal_add_library('system', 'jquery.cookie');
    $path = drupal_get_path('module', 'imageeditor');
    drupal_add_js($path . '/js/imageeditor.js', array(
      'scope' => 'footer',
      'weight' => -10,
    ));
    drupal_add_css($path . '/css/imageeditor.widget.css');

    // Overlay settings.
    $codename = variable_get('imageeditor_overlay_type', 'custom');
    $overlay = imageeditor_info('overlay', $codename);
    imageeditor_initialize_plugin($overlay);
  }

  // Editors and uploaders settings.
  foreach (array(
    'editor',
    'uploader',
  ) as $type) {
    foreach (imageeditor_info($type) as $codename => $plugin) {
      if (!$conf_added[$codename] && (array_key_exists($codename, $editors) || array_key_exists($codename, $uploaders))) {
        $conf_added[$codename] = TRUE;
        imageeditor_initialize_plugin($plugin);
        $conf_array[$codename]['html'] = theme('imageeditor_widget_item', array(
          'name' => $plugin['name'],
          'class' => $plugin['class'],
          'codename' => $codename,
        ));
        foreach (array(
          'launch_type',
          'image_url_param',
          'image_creation',
          'parameters',
          'options',
        ) as $key) {
          if (array_key_exists($key, $plugin)) {
            $conf_array[$codename][$key] = $plugin[$key];
          }
        }

        // Editor language settings.
        if (array_key_exists('lang_map', $plugin)) {
          if (property_exists($user, 'language') && !empty($user->language) && array_key_exists($user->language, $plugin['lang_map'])) {
            $conf_array[$codename]['options'][$plugin['lang_option']] = $plugin['lang_map'][$user->language];
          }
          elseif (array_key_exists($language->language, $plugin['lang_map'])) {
            $conf_array[$codename]['options'][$plugin['lang_option']] = $plugin['lang_map'][$language->language];
          }
          else {
            $conf_array[$codename]['options'][$plugin['lang_option']] = $plugin['lang_default'];
          }
        }
      }
    }
  }
  drupal_add_js(array(
    'imageeditor' => $conf_array,
  ), 'setting');
}