empty the filter cache to correct image paths that are pointing to the old address. Note that this will only work for images that have been inserted using filter tags.', array('!empty-cache' => url('img_assist/cache/clear'))); case 'img_assist/template': return '
'; } } /** * Implementation of hook_theme(). */ function img_assist_theme() { return array( 'img_assist_inline' => array( 'arguments' => array('node' => NULL, 'size' => NULL, 'attributes' => NULL), ), 'img_assist_filter' => array( 'arguments' => array('text' => NULL), ), 'img_assist_popup' => array( 'arguments' => array('content' => NULL, 'attributes' => NULL), ), 'img_assist_page' => array( 'arguments' => array('content' => NULL, 'attributes' => NULL), ), 'img_assist_legacy' => array(), ); } /** * Implementation of hook_menu(). */ function img_assist_menu() { $items['img_assist/cache/clear'] = array( 'title' => 'Empty cache', 'page callback' => 'img_assist_cache_clear', 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, 'file' => 'img_assist.admin.inc', ); $items['img_assist/load'] = array( 'title' => 'Image assist', 'page callback' => 'img_assist_loader', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); // Page callbacks called internally by img_assist/load. $items['img_assist/header'] = array( 'title' => 'Image assist header', 'page callback' => 'img_assist_header', 'page arguments' => array(2), 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); $items['img_assist/thumbs'] = array( 'title' => 'Image assist thumbnails', 'page callback' => 'img_assist_thumbs', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); $items['img_assist/upload'] = array( 'title' => 'Image assist upload', 'page callback' => 'img_assist_upload', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); $items['img_assist/properties'] = array( 'title' => 'Image assist properties', 'page callback' => 'img_assist_properties', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); // Popup images page. $items['img_assist/popup'] = array( 'title' => 'Popup image', 'page callback' => 'img_assist_popup', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Insert callback (only for inserting HTML, not filter tag). $items['img_assist/insert_html'] = array( 'title' => 'Insert callback', 'page callback' => 'img_assist_insert_html', 'access arguments' => array('access img_assist'), 'type' => MENU_CALLBACK, ); $items['admin/settings/img_assist'] = array( 'title' => 'Image assist', 'description' => 'Change settings for the Image assist module.', 'page callback' => 'drupal_get_form', 'page arguments' => array('img_assist_admin_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'img_assist.admin.inc', ); return $items; } /** * Implementation of hook_init(). */ function img_assist_init() { $path = drupal_get_path('module', 'img_assist'); if (arg(0) == 'img_assist') { // Suppress Administration menu. module_invoke('admin_menu', 'suppress'); drupal_add_css($path .'/img_assist_popup.css', 'module', 'all', FALSE); } else { drupal_add_js($path .'/img_assist.js'); if (variable_get('img_assist_page_styling', 'yes') == 'yes') { drupal_add_css($path .'/img_assist.css'); } } } /** * Implementation of hook_perm(). */ function img_assist_perm() { return array('access img_assist', 'access all images', 'access advanced options', 'use original size'); } /** * Implementation of hook_elements(). */ function img_assist_elements() { $type['textarea'] = array( '#process' => 'img_assist_textarea' ); return $type; } /** * Add JavaScript settings for generating the image link underneath textareas. */ function img_assist_textarea($element) { static $initialized = FALSE; if (!user_access('access img_assist')) { return $element; } $link = variable_get('img_assist_link', 'icon'); if ($link == 'icon' || $link == 'text') { if (_img_assist_textarea_match($element['#id']) && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist')) { if (!$initialized) { // Add settings. $settings['link'] = $link; if ($link == 'icon') { $settings['icon'] = drupal_get_path('module', 'img_assist') .'/add-image.jpg'; } drupal_add_js(array('img_assist' => $settings), 'setting'); $initialized = TRUE; } // Attach behavior. // @todo Some browsers do not support underscores in CSS classes. if (!isset($element['#attributes']['class'])) { $element['#attributes']['class'] = 'img_assist'; } else { $element['#attributes']['class'] .= ' img_assist'; } } } return $element; } /** * Implementation of hook_block(). * * Generates a block that references the other places the current image is used. * The block is only visible when looking at the full view of an image. */ function img_assist_block($op = 'list', $delta = 0) { if ($op == 'list') { $blocks[0]['info'] = t('Image reference'); return $blocks; } else if ($op == 'view') { switch ($delta) { case 0: // Since blocks aren't passed node objects (which makes sense) we need // to determine if we are viewing a node and grab its nid. if (arg(0) == 'node' && is_numeric(arg(1))) { $block['subject'] = t('This image appears in...'); $block['content'] = img_assist_get_references(arg(1)); return $block; } break; } } } /** * Implementation of hook_filter(). */ function img_assist_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) { case 'list': return array(0 => t('Inline images')); case 'description': return t('Add images to your posts with Image assist.'); // case 'no cache': // return TRUE; case 'process': $processed = FALSE; foreach (img_assist_get_macros($text) as $unexpanded_macro => $macro) { $expanded_macro = img_assist_render_image($macro); $text = str_replace($unexpanded_macro, $expanded_macro, $text); $processed = TRUE; } return $processed ? theme('img_assist_filter', $text) : $text; default: return $text; } } /** * Implementation of hook_filter_tips(). */ function img_assist_filter_tips($delta, $format, $long = FALSE) { return t('Images can be added to this post.'); } /** * Implementation of hook_nodeapi(). * * - Clear input filter cache. * - Keep track of where images are used. * - Catch nids of recently uploaded images. */ function img_assist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'update': if ($node->type == 'image') { // Clear the input filter cache to force all node content to be rebuilt. // This is to make sure all image paths are up to date. cache_clear_all(NULL, 'cache_filter'); } // break is intentionally left out. case 'insert': // Update the image map. img_assist_map_save($node); break; case 'delete': img_assist_map_delete($node); break; } } /** * @defgroup img_assist_pages Image Assist Pages * @{ * All but img_assist_loader() are in frames. */ /** * Output main img_assist interface HTML. * * @todo Remove hard-coded TinyMCE integration. */ function img_assist_loader() { $path = drupal_get_path('module', 'img_assist'); $caller = arg(2) ? arg(2) : 'textarea'; drupal_add_js($path . '/img_assist_popup.js'); if (module_exists('wysiwyg') && ($editor = wysiwyg_get_editor($caller))) { if ($editor['name'] == 'tinymce') { drupal_add_js($editor['library path'] . '/tiny_mce_popup.js'); } } else { $caller = 'textarea'; } drupal_add_js($path . '/img_assist_' . $caller . '.js'); $output = ''."\n"; $output .= "\n"; $output .= "\n"; $output .= '');
$form[] = array('#value' => $properties_image);
$form[] = array('#value' => ' '. t('Size') .': '. strtr('@widthx@height px', array('@width' => $image_info['width'], '@height' => $image_info['height'])) .' | ');
// Image node properties fieldset.
$form['properties'] = array('#type' => 'fieldset', '#title' => t('Image properties'));
$form['properties'][] = array('#value' => ''); $token_installed = module_exists('token'); if (variable_get('img_assist_load_title', 1)) { $title = img_assist_sanitize($token_installed ? token_replace(variable_get('img_assist_title_pattern', '[title]'), 'node', $node) : $node->title); } if (variable_get('img_assist_load_description', 1)) { $description = img_assist_sanitize($token_installed ? token_replace(variable_get('img_assist_description_pattern', '[body]'), 'node', $node) : $node->body); } $form['title'] = array( '#type' => 'textfield', '#title' => t('Title (optional)'), '#default_value' => isset($title) ? $title : '', '#size' => 50, '#maxlength' => 255, '#description' => NULL, '#attributes' => array('onblur' => 'parent.updateCaption()'), ); $form['desc'] = array( '#type' => 'textfield', '#title' => t('Description (optional)'), '#default_value' => isset($description) ? $description : '', '#size' => 50, '#maxlength' => 255, '#description' => NULL, '#attributes' => array('onblur' => 'parent.updateCaption()'), ); // Size. $form[] = array('#value' => ' | |
');
$form[] = array('#value' => ' ');
$form[] = array('#value' => '');
$form['size_label'] = array(
'#type' => 'select',
'#default_value' => variable_get('img_assist_default_label', '100x100'),
'#options' => $derivatives,
'#attributes' => array('onchange' => 'parent.onChangeSizeLabel()'),
);
$form[] = array('#value' => ' ');
$form[] = array('#value' => '');
$form['width'] = array(
'#type' => 'textfield',
'#default_value' => $default_width,
'#size' => 4,
'#maxlength' => 4,
'#attributes' => array('onblur' => 'parent.onChangeWidth()'),
);
$form[] = array('#value' => ' x ');
$form['height'] = array(
'#type' => 'textfield',
'#default_value' => $default_height,
'#size' => 4,
'#maxlength' => 4,
'#attributes' => array('onblur' => 'parent.onChangeHeight()'),
);
$form[] = array('#value' => ' | ');
// Alignment.
$form['align'] = array(
'#type' => 'select',
'#title' => t('Alignment'),
'#default_value' => variable_get('img_assist_default_alignment', 'left'),
'#options' => array('left' => t('left'), 'right' => t('right'), 'none' => t('none'), 'center' => t('center')),
'#prefix' => ' ',
'#suffix' => ' ',
);
$form[] = array('#value' => ' | |
');
// Link.
if (user_access('access advanced options')) {
$form[] = array('#value' => ' ');
$form['link'] = array(
'#type' => 'select',
'#title' => t('Link'),
'#default_value' => variable_get('img_assist_default_link_behavior', 'none'),
'#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),
'#attributes' => array('onchange' => 'parent.onChangeLink()'),
);
$form['url'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('img_assist_default_link_url', 'http://'),
'#size' => 25,
'#maxlength' => 255,
'#description' => NULL,
);
$form['link_options_visible'] = array(
'#type' => 'hidden',
'#value' => 1,
);
$form[] = array('#value' => ' ');
}
else {
$form['link'] = array(
'#type' => 'hidden',
'#value' => variable_get('img_assist_default_link_behavior', 'none'),
);
$form['url'] = array(
'#type' => 'hidden',
'#value' => variable_get('img_assist_default_link_url', 'http://'),
);
$form['link_options_visible'] = array(
'#type' => 'hidden',
'#value' => 0,
);
}
// Default link url is needed for JS to indicate if an url has been entered.
$form['default_url'] = array(
'#type' => 'hidden',
'#value' => variable_get('img_assist_default_link_url', 'http://'),
);
// Insert Mode (HTML or Filter Tag).
if (user_access('access advanced options')) {
$form[] = array('#value' => '');
$form['insertmode'] = array(
'#type' => 'select',
'#title' => t('Insert mode'),
'#default_value' => variable_get('img_assist_default_insert_mode', 'filtertag'),
'#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
);
$form[] = array('#value' => ' ');
}
else {
$form['insertmode'] = array(
'#type' => 'hidden',
'#value' => variable_get('img_assist_default_insert_mode', 'filtertag'),
);
}
// Hidden Fields.
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$form['update'] = array(
'#type' => 'hidden',
'#value' => $update,
);
$form['aspect'] = array(
'#type' => 'hidden',
'#value' => $aspect_ratio,
);
// Buttons.
$form['buttons'] = array(
'#prefix' => ' ',
);
$form['#attributes']['onsubmit'] = 'return parent.insertImage();';
$form['buttons']['insert'] = array(
'#type' => 'submit',
'#value' => ($update) ? t('Update') : t('Insert'),
'#attributes' => array('style' => 'float: left;'),
);
$form['buttons']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'return parent.cancelAction();', 'style' => 'float: right;'),
);
$form[] = array('#value' => ' |