You are here

imageeditor_inline.module in Image Editor 7

Allows online editing of inline images using different image editing services.

File

imageeditor_inline/imageeditor_inline.module
View source
<?php

/**
 * @file
 * Allows online editing of inline images using different image editing services.
 */

/**
 * Implements hook_permission().
 */
function imageeditor_inline_permission() {
  return array(
    'use imageeditor_inline' => array(
      'title' => t('Use Image Editor Inline'),
      'description' => t('Allows to use different image editors to create/edit inline images.'),
    ),
    'edit all images' => array(
      'title' => t('Edit any image on the page'),
      'description' => t('Access check feature: Allows to edit any image on the page including images from external sites.'),
    ),
    'edit own images' => array(
      'title' => t('Edit only own images'),
      'description' => t('Access check feature: Allows to edit only images from this site that are managed files, user should be the owner of the image file.'),
    ),
    'administer imageeditor_inline' => array(
      'title' => t('Administer Image Editor Inline'),
      'description' => t('Configure Image Editor Inline settings.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function imageeditor_inline_menu() {
  $items = array();
  $items['admin/config/media/imageeditor/imageeditor_inline'] = array(
    'title' => 'Image editor inline',
    'description' => 'Configure Image Editor Inline settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'imageeditor_inline_settings_form',
    ),
    'access callback' => 'imageeditor_inline_settings_access',
    //'user_access',

    //'access arguments' => array('administer site configuration'),
    'file' => 'imageeditor_inline.admin.inc',
    'type' => MENU_LOCAL_TASK,
  );
  $items['imageeditor_inline/ajax/save'] = array(
    'title' => 'Image Editor Inline Save',
    'description' => 'Saving images from Image Editor Inline',
    'page callback' => 'imageeditor_inline_save',
    'access callback' => 'user_access',
    'access arguments' => array(
      'use imageeditor_inline',
    ),
    'file' => 'imageeditor_inline.pages.inc',
    'type' => MENU_CALLBACK,
  );
  $items['imageeditor_inline/ajax/access_check'] = array(
    'title' => 'Image Editor Inline Access Check',
    'description' => 'Checking access to edit images',
    'page callback' => 'imageeditor_inline_access_check',
    'access callback' => 'user_access',
    'access arguments' => array(
      'use imageeditor_inline',
    ),
    'file' => 'imageeditor_inline.pages.inc',
    'type' => MENU_CALLBACK,
  );
  $items['imageeditor_inline/revert'] = array(
    'title' => 'Image Editor Inline Revert',
    'description' => 'Revert image to the previous version',
    'page callback' => 'imageeditor_inline_revert',
    'access callback' => 'user_access',
    'access arguments' => array(
      'use imageeditor_inline',
    ),
    'theme callback' => 'imageeditor_inline_revert_theme',
    'file' => 'imageeditor_inline.pages.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Access check callback function for settings page.
 */
function imageeditor_inline_settings_access() {
  if (user_access('administer site configuration') || user_access('administer imageeditor_inline')) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}
function imageeditor_inline_revert_theme() {
  return variable_get('admin_theme', 0);
}

/**
 * Implements hook_theme().
 */
function imageeditor_inline_theme($existing, $type, $theme, $path) {
  return array(
    'imageeditor_inline_settings_form' => array(
      'render element' => 'form',
    ),
  );
}

/**
 * Implements hook_page_build().
 */
function imageeditor_inline_page_build(&$page) {
  if (!user_access('use imageeditor_inline')) {
    return;
  }
  static $conf_added;
  if (empty($conf_added)) {
    $conf_added['imageeditor'] = FALSE;
    $conf_added['imageeditor_inline'] = FALSE;
  }
  if (!$conf_added['imageeditor_inline']) {
    $conf_added['imageeditor_inline'] = TRUE;
    $conf_array = array();
    $editors = array();
    foreach (imageeditor_info('editor') as $codename => $editor) {
      if (variable_get('imageeditor_inline_' . $codename . '_enabled', 0)) {
        $editors[$codename] = variable_get('imageeditor_inline_' . $codename . '_position', 0);
      }
    }
    $uploaders = array();
    foreach (imageeditor_info('uploader') as $codename => $uploader) {
      if (variable_get('imageeditor_inline_' . $codename . '_enabled', 0)) {
        $uploaders[$codename] = variable_get('imageeditor_inline_' . $codename . '_position', 0);
      }
    }

    // Image Editor initialization.
    imageeditor_initialize($editors, $uploaders);
    $conf_array['editors'] = $editors;
    $conf_array['uploaders'] = $uploaders;
    $conf_array['save_url'] = url('imageeditor_inline/ajax/save', array(
      'absolute' => TRUE,
    ));
    $conf_array['access_check'] = variable_get('imageeditor_inline_access_check', 0);
    $conf_array['access_check_url'] = url('imageeditor_inline/ajax/access_check', array(
      'absolute' => TRUE,
    ));
    $conf_array['icons_position'] = variable_get('imageeditor_inline_icons_position', 1);
    $conf_array['min_dimention'] = variable_get('imageeditor_inline_min_dimention', 150);
    $conf_array['ignore'] = variable_get('imageeditor_inline_ignore', '.admin-menu-icon, .stack-image, .imageeditor-inline-revert');
    drupal_add_js(array(
      'imageeditor_inline' => $conf_array,
    ), 'setting');
    $path = drupal_get_path('module', 'imageeditor_inline');
    drupal_add_js($path . '/js/imageeditor_inline.js', array(
      'scope' => 'footer',
      'weight' => 10,
    ));
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function imageeditor_inline_ctools_plugin_directory($module, $type) {
  if ($module == 'imageeditor' && $type == 'editor') {
    return 'plugins/editor';
  }
}

/**
* Implements hook_ckeditor_plugin().
*/
function imageeditor_inline_ckeditor_plugin() {
  $path = drupal_get_path('module', 'imageeditor_inline');
  return array(
    'imageeditor' => array(
      'name' => 'imageeditor',
      'desc' => t('Plugin to use Image Editor inside CKEditor'),
      'path' => $path . '/ckeditor/imageeditor/',
    ),
  );
}