View source
<?php
simplecrop_include('field');
simplecrop_include('effects');
simplecrop_include('api');
simplecrop_include('theme');
define('SIMPLECROP_DISPLAY_CROPPED_IMAGE', 'cropped_image');
define('SIMPLECROP_DISPLAY_ORIGINAL_IMAGE', 'original_image');
define('SIMPLECROP_CROP_AREA_MINIMIZE', 'minimize');
define('SIMPLECROP_CROP_AREA_MAXIMIZE', 'maximize');
define('SIMPLECROP_CROP_AREA_NONE', 'none');
function simplecrop_menu() {
$items['simplecrop/ajax'] = array(
'page callback' => 'simplecrop_ajax_rebuild_image',
'delivery callback' => 'ajax_deliver',
'access arguments' => array(
'access content',
),
'theme callback' => 'ajax_base_page_theme',
'file' => 'simplecrop.pages.inc',
'file path' => drupal_get_path('module', 'simplecrop') . '/includes',
'type' => MENU_CALLBACK,
);
return $items;
}
function simplecrop_theme() {
return array(
'simplecrop_widget' => array(
'render element' => 'element',
'template' => 'simplecrop-widget',
'path' => drupal_get_path('module', 'simplecrop') . '/templates',
),
);
}
function simplecrop_image_default_styles() {
$styles['simplecrop'] = array(
'label' => 'SimpleCrop (100x100)',
'effects' => array(
array(
'name' => 'simplecrop',
'weight' => 0,
),
array(
'name' => 'image_scale',
'data' => array(
'width' => 100,
'height' => 100,
'upscale' => 1,
),
'weight' => 1,
),
),
);
return $styles;
}
function simplecrop_filefield_sources_widgets() {
return array(
'simplecrop_widget',
);
}
function simplecrop_file_delete($file) {
if (!empty($file->uri)) {
simplecrop_crop_delete($file->uri);
}
}
function simplecrop_file_move($file, $source) {
$crop = simplecrop_crop_load($source->uri, TRUE);
if (!empty($crop)) {
simplecrop_crop_save($file->uri, $crop->data);
simplecrop_crop_delete($source->uri);
}
}
function simplecrop_form_image_style_form_alter(&$form, &$form_state) {
$style = $form_state['image_style'];
if (!empty($style['effects'])) {
foreach ($style['effects'] as $effect) {
if ($effect['module'] == 'simplecrop') {
$simplecrop_effect_exists = TRUE;
}
}
}
if (!empty($simplecrop_effect_exists)) {
unset($form['effects']['new']['new']['#options']['simplecrop']);
}
$submit_callback = 'simplecrop_image_style_form_force_order';
$form['#submit'][] = $submit_callback;
$form['effects']['new']['add']['#submit'][] = $submit_callback;
}
function simplecrop_image_style_form_force_order($form, &$form_state) {
$submitted_style = $form_state['image_style'];
$style = image_style_load($submitted_style['name'], $submitted_style['isid']);
foreach ($style['effects'] as $effect) {
if ($effect['module'] == 'simplecrop') {
$simplecrop_effect = $effect;
}
if (!isset($min_weight) || $min_weight > $effect['weight']) {
$min_weight = $effect['weight'];
}
}
if (isset($simplecrop_effect) && isset($min_weight) && $simplecrop_effect['weight'] != $min_weight) {
$simplecrop_effect['weight'] = $min_weight - 1;
image_effect_save($simplecrop_effect);
drupal_set_message(t('SimpleCrop effect was forced to be the first to prevent possible crop issues.'));
}
}
function simplecrop_imagestyles_with_crop_effect() {
$styles_with_crop =& drupal_static(__FUNCTION__);
if (isset($styles_with_crop)) {
return $styles_with_crop;
}
$styles = image_styles();
$styles_with_crop = array();
foreach ($styles as $name => $style) {
if (empty($style['effects'])) {
continue;
}
foreach ($style['effects'] as $effect) {
if (!empty($effect['module']) && $effect['module'] == 'simplecrop') {
$styles_with_crop[$name] = $name;
}
}
}
return $styles_with_crop;
}
function simplecrop_include($file) {
module_load_include('inc', 'simplecrop', 'includes/simplecrop.' . $file);
}