imageeditor.module in Image Editor 7
Same filename and directory in other branches
Allows online editing of images using different image editing services.
File
imageeditor.moduleView source
<?php
/**
* @file
* Allows online editing of images using different image editing services.
*/
/**
* Implements hook_permission().
*/
function imageeditor_permission() {
return array(
'use imageeditor' => array(
'title' => t('Use Image Editor'),
'description' => t('Allows to use different image editors to create/edit images.'),
),
'administer imageeditor' => array(
'title' => t('Administer Image Editor'),
'description' => t('Set up API keys for different image editors and upload services.'),
),
);
}
/**
* Implements hook_menu().
*/
function imageeditor_menu() {
$items = array();
$items['admin/config/media/imageeditor'] = array(
'title' => 'Image editor',
'description' => 'Configure Image Editor settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'imageeditor_settings_form',
),
'access callback' => 'imageeditor_settings_access',
'file' => 'imageeditor.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/media/imageeditor/imageeditor'] = array(
'title' => 'Image editor',
'description' => 'Configure Image Editor settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'imageeditor_settings_form',
),
'access callback' => 'imageeditor_settings_access',
'file' => 'imageeditor.admin.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[imageeditor_ajax_save_path() . '/%'] = array(
'title' => 'Image Editor Save',
'description' => 'Saving images from Image Editor',
'page callback' => 'imageeditor_save',
'page arguments' => array(
3,
),
'access arguments' => array(
'use imageeditor',
),
'file' => 'imageeditor.pages.inc',
'type' => MENU_CALLBACK,
);
$items[imageeditor_ajax_close_path() . '/%'] = array(
'title' => 'Image Editor Exit',
'description' => 'Exiting from Image Editor',
'page callback' => 'imageeditor_close',
'page arguments' => array(
3,
),
'access arguments' => array(
'use imageeditor',
),
'file' => 'imageeditor.pages.inc',
'type' => MENU_CALLBACK,
);
$items[imageeditor_ajax_upload_path() . '/%'] = array(
'page callback' => 'imageeditor_upload',
'page arguments' => array(
3,
),
'access arguments' => array(
'use imageeditor',
),
'file' => 'imageeditor.pages.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Access callback for admin settings page.
*/
function imageeditor_settings_access() {
if (user_access('administer site configuration') || user_access('administer imageeditor')) {
return TRUE;
}
return FALSE;
}
/**
* API function to initialize required editors and uploaders.
*/
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');
}
/**
* Helper function to initialize plugin.
*/
function imageeditor_initialize_plugin(&$plugin) {
if ($function = ctools_plugin_get_function($plugin, 'initialize_callback')) {
$function($plugin);
}
if (array_key_exists('js', $plugin)) {
drupal_add_js($plugin['path'] . '/' . $plugin['js'], array(
'scope' => 'footer',
));
}
if (array_key_exists('css', $plugin)) {
drupal_add_css($plugin['path'] . '/' . $plugin['css']);
}
}
/**
* Implements hook_theme().
*/
function imageeditor_theme($existing, $type, $theme, $path) {
return array(
'imageeditor_widget_item' => array(
'variables' => array(
'name' => NULL,
'class' => NULL,
'codename' => NULL,
),
),
'imageeditor_admin_item' => array(
'variables' => array(
'name' => NULL,
'class' => NULL,
'codename' => NULL,
),
),
);
}
/**
* Theme function to output Image Editor widget item.
*/
function theme_imageeditor_widget_item($variables) {
return '<span class="imageeditor-widget-item ' . $variables['class'] . '" title="' . $variables['name'] . '" data-codename="' . $variables['codename'] . '"></span>';
}
/**
* Theme function to output Image Editor widget item.
*/
function theme_imageeditor_admin_item($variables) {
return '<span class="imageeditor-admin-item ' . $variables['class'] . '" title="' . $variables['name'] . '" data-codename="' . $variables['codename'] . '"></span>';
}
/**
* Implements hook_ctools_plugin_type().
*/
function imageeditor_ctools_plugin_type() {
return array(
'editor' => array(
'cache' => TRUE,
),
'uploader' => array(
'cache' => TRUE,
),
'overlay' => array(
'cache' => TRUE,
),
);
}
/**
* Implements hook_ctools_plugin_directory().
*/
function imageeditor_ctools_plugin_directory($module, $type) {
if ($module == 'imageeditor') {
return 'plugins/' . $type;
}
}
/**
* Helper function to invoke hooks.
* @param $type
* Either editor, uploader or overlay.
*/
function imageeditor_info($type = 'editor', $codename = NULL) {
ctools_include('plugins');
if ($codename) {
return ctools_get_plugins('imageeditor', $type, $codename);
}
return ctools_get_plugins('imageeditor', $type);
}
function imageeditor_admin_css() {
$path = drupal_get_path('module', 'imageeditor');
drupal_add_css($path . '/css/imageeditor.admin.css');
foreach (array(
'editor',
'uploader',
) as $type) {
foreach (imageeditor_info($type) as $plugin) {
if (array_key_exists('css', $plugin)) {
drupal_add_css($plugin['path'] . '/' . $plugin['css']);
}
}
}
}
/**
* Returns Image Editor temporary directory.
*/
function imageeditor_temporary_directory() {
return file_default_scheme() . '://imageeditor/temp';
}
/**
* Returns Image Editor AJAX save path.
*/
function imageeditor_ajax_save_path() {
return 'imageeditor/ajax/save';
}
/**
* Returns Image Editor AJAX close path.
*/
function imageeditor_ajax_close_path() {
return 'imageeditor/ajax/close';
}
/**
* Returns Image Editor AJAX upload path.
*/
function imageeditor_ajax_upload_path() {
return 'imageeditor/ajax/upload';
}
Functions
Name![]() |
Description |
---|---|
imageeditor_admin_css | |
imageeditor_ajax_close_path | Returns Image Editor AJAX close path. |
imageeditor_ajax_save_path | Returns Image Editor AJAX save path. |
imageeditor_ajax_upload_path | Returns Image Editor AJAX upload path. |
imageeditor_ctools_plugin_directory | Implements hook_ctools_plugin_directory(). |
imageeditor_ctools_plugin_type | Implements hook_ctools_plugin_type(). |
imageeditor_info | Helper function to invoke hooks. |
imageeditor_initialize | API function to initialize required editors and uploaders. |
imageeditor_initialize_plugin | Helper function to initialize plugin. |
imageeditor_menu | Implements hook_menu(). |
imageeditor_permission | Implements hook_permission(). |
imageeditor_settings_access | Access callback for admin settings page. |
imageeditor_temporary_directory | Returns Image Editor temporary directory. |
imageeditor_theme | Implements hook_theme(). |
theme_imageeditor_admin_item | Theme function to output Image Editor widget item. |
theme_imageeditor_widget_item | Theme function to output Image Editor widget item. |