Index: modules/img_assist/img_assist.module =================================================================== RCS file: /cvs/drupal/contributions/modules/img_assist/img_assist.module,v retrieving revision 1.54 diff -u -r1.54 img_assist.module --- modules/img_assist/img_assist.module 30 Nov 2005 02:48:56 -0000 1.54 +++ modules/img_assist/img_assist.module 13 Dec 2005 17:33:11 -0000 @@ -89,6 +89,7 @@ return t('Add images to your posts using img_assist.'); case 'process': + echo "YEP"; 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); @@ -135,30 +136,81 @@ if (!$upload_enabled && !$image_enabled) { drupal_set_message(t('Neither Upload module or Image module are enabled. Img_assist needs one of these modules enabled in order to work. Please do that now.'), 'error'); } - - $group = form_radios(t('Display img_assist on'), 'img_assist_all', variable_get('img_assist_all', 1), array(t('on specific pages'), t('on all textareas'))); + $form['img_assist_access'] = array( + '#title' => t('Access settings'), + '#type' => 'fieldset', + '#collapsible' => true, + '#collapsed' => true, + ); + $form['img_assist_access']['img_assist_all'] = array( + '#type' => 'radios', + '#title' => t('Display img_assist on'), + '#default_value' => variable_get('img_assist_all', 1), + '#options' => array(t('on specific pages'), t('on all textareas')), + ); if (!variable_get('img_assist_all', 1)) { - $group .= form_textarea(t('Pages'), 'img_assist_pages', variable_get('img_assist_pages', img_assist_help('admin/settings/img_assist#pages')), 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page.")); - } - $output = form_group_collapsible(t('Access settings'), $group, TRUE); - - $group = form_checkboxes(t('Hide \'inline image link\' for the following node types'), 'img_assist_no_nodes', variable_get('img_assist_no_nodes', array()), $nodetypes, t('Check the node types you do not want the ability to add images to.'), NULL, TRUE); - $group .= form_textarea(t('Image HTML template'), 'img_assist_img_html', variable_get('img_assist_img_html', img_assist_help('img_assist/template')), 50, 10, t('Enter the HTML wrap around your image tag. You can use the following variables: %image-class - CSS class name of the image. The default is "image", %img-link - a link to the original image, %node-link - a link to the original node containing the image, %nid - a nid of the original node containing the image, and %caption - a user-defined caption.')); - $group .= form_radios(t('Preload image captions'), 'img_assist_load_caption', variable_get('img_assist_load_caption', 1), array(t('Disabled'), t('Enabled')), t('If enabled, The body text from the image will be loaded as the caption by default.')); - $output .= form_group_collapsible(t('Image output settings'), $group, TRUE); + $form['img_assist_access']['img_assist_pages'] = array( + '#type' => 'textarea', + '#title' => t('Pages'), + '#default_value' => variable_get('img_assist_pages', img_assist_help('admin/settings/img_assist#pages')), + '#cols' => 40, + '#rows' => 5, + '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page."), + ); + } + $form['img_assist_output'] = array( + '#title' => t('Image output settings'), + '#type' => 'fieldset', + '#collapsible' => true, + '#collapsed' => true, + ); + $form['img_assist_output']['img_assist_no_nodes'] = array( + '#type' => 'checkboxes', + '#title' => t('Hide \'inline image link\' for the following node types'), + '#default_value' => variable_get('img_assist_no_nodes', array()), + '#options' => array_keys(node_get_types()), + '#description' => t('Check the node types you do not want the ability to add images to.'), + '#required' => TRUE, + ); + $form['img_assist_output']['img_assist_img_html'] = array( + '#type' => 'textarea', + '#title' => t('Image HTML template'), + '#default_value' => variable_get('img_assist_img_html', img_assist_help('img_assist/template')), + '#cols' => 50, + '#rows' => 10, + '#description' => t('Enter the HTML wrap around your image tag. You can use the following variables: %image-class - CSS class name of the image. The default is "image", %img-link - a link to the original image, %node-link - a link to the original node containing the image, %nid - a nid of the original node containing the image, and %caption - a user-defined caption.'), + ); + $form['img_assist_output']['img_assist_load_caption'] = array( + '#type' => 'radios', + '#title' => t('Preload image captions'), + '#default_value' => variable_get('img_assist_load_caption', 1), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('If enabled, The body text from the image will be loaded as the caption by default.'), + ); if (module_exist('taxonomy')) { $vocs[0] = '<'. t('none') .'>'; foreach (taxonomy_get_vocabularies() as $vid => $voc) { $vocs[$vid] = $voc->name; } - - if ($voc) { - $preview = form_select(t('Image preview filter'), 'img_assist_preview_filter', variable_get('img_assist_preview_filter', array()), $vocs, t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of img_assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'), '', 1); - } + } + $form['img_assist_preview_settings'] = array( + '#title' => t('Preview settings'), + '#type' => 'fieldset', + '#collapsible' => true, + '#collapsed' => true, + ); + if ($voc) { + $form['img_assist_preview_settings']['img_assist_preview_filter'] = array( + '#type' => 'select', + '#title' => t('Image preview filter'), + '#default_value' => variable_get('img_assist_preview_filter', array()), + '#options' => $vocs, + '#description' => t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of img_assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'), + '#multiple' => 1, + ); } - - $group = $preview; if (function_exists('_image_get_sizes')) { foreach (_image_get_sizes() as $size) { if ($size['label']) { @@ -167,13 +219,39 @@ } } if ($derivatives) { - $group .= form_select(t('Default derivative selection'), 'default_label', variable_get('default_label', '_original'), $derivatives, t('Select a derivative to be highlighted by default when an image is selected in the img_assist preview pane.')); - } - $group .= form_textfield(t('Default width of image thumbnail previews'), 'img_assist_default_preview_width', variable_get('img_assist_default_preview_width', 75), 6, 6, t('Enter, in pixels, the default width of an image to display in the preview pane. The smaller this number, the more images you will be able to see without scrolling.')); - $group .= form_textfield(t('Max number of images to preview'), 'img_assist_preview_count', variable_get('img_assist_preview_count', 25), 6, 6, t('Enter the threshold of the number of images to display in the directory preview pane. If there are more images for a given view, they will be displayed as hyperlinks.')); - $output .= form_group_collapsible(t('Preview settings'), $group, TRUE); + $form['img_assist_preview_settings']['default_label'] = array( + '#type' => 'select', + '#title' => t('Default derivative selection'), + '#default_value' => variable_get('default_label', '_original'), + '#options' => $derivatives, + '#description' => t('Select a derivative to be highlighted by default when an image is selected in the img_assist preview pane.'), + ); + } + $form['img_assist_preview_settings']['img_assist_default_preview_width'] = array( + '#type' => 'textfield', + '#title' => t('Default width of image thumbnail previews'), + '#default_value' => variable_get('img_assist_default_preview_width', 75), + '#size' => 6, + '#maxlength' => 6, + '#description' => t('Enter, in pixels, the default width of an image to display in the preview pane. The smaller this number, the more images you will be able to see without scrolling.'), + ); + $form['img_assist_preview_settings']['img_assist_preview_count'] = array( + '#type' => 'textfield', + '#title' => t('Max number of images to preview'), + '#default_value' => variable_get('img_assist_preview_count', 25), + '#size' => 6, + '#maxlength' => 6, + '#description' => t('Enter the threshold of the number of images to display in the directory preview pane. If there are more images for a given view, they will be displayed as hyperlinks.'), + ); + return $form; +} - return $output; +/** + * Implementation of hook_elements(). + */ +function img_assist_elements() { + $type['textarea'] = array('#process' => array('img_assist_textarea' => array())); + return $type; } /** @@ -181,12 +259,14 @@ * * Add image links underneath textareas. */ -function img_assist_textarea($op, $name) { - if ($op == 'post' && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist/add/image')) { - $anchor = '
'; +function img_assist_textarea($element) { + if (_img_assist_page_match() && !strstr($_GET['q'], 'img_assist/add/image')) { + $anchor = '
'; $image = ''; - return $anchor. $image . '
'; + $element['#suffix'] .= $anchor. $image . '
'; } + return $element; + } /******************************************************************** @@ -201,7 +281,6 @@ $textarea = $_GET['textarea'] ? $_GET['textarea'] : variable_get('img_assist_textarea', $textarea); variable_set('img_assist_textarea', $textarea); - $head = ''; $editor = ''; if ($_GET['editor']) { @@ -257,7 +336,7 @@ var f = myDoc.getElementsByTagName('form'); for (var i=0; iname, 'taxonomy', $tid[$i], $vid, '', 0, '<'. t('none') .'>'); + $form[$voc->name] = _taxonomy_term_select($voc->name, 'taxonomy', $tid[$i], $vid, '', 0, '<'. t('none') .'>'); $i++; } - $filterbar .= ''. form_submit(t('Go')); - $filterbar = form($filterbar). ''; + $form['submit'] = array( + '#type' => 'submit', + '#prefix' => '', + '#suffix' => '', + '#value' => t('Go') + ); + $filterbar .= drupal_get_form('img_assist_filters', $form). ''; } $resize = '[-] [+]'; @@ -707,7 +791,15 @@ $output .= l("filepath)."\" $dim border=\"1\" />", "img_assist/load/properties/$dsp_img->fid", array('target' => 'img_assist_properties'), NULL, NULL, FALSE, TRUE); $output .= "
". l($img->title, "node/$dsp_img->nid", array('target' => '_blank')). " ($dsp_img->width x $dsp_img->height)\n"; if ($image_module_image) { - $output .= form(form_select(t('Select a derivative'), 'label', $selected, $options, NULL, 'onchange=parent.img_assist_properties.location.href=this.options[selectedIndex].value')); + $form['label'] = array( + '#type' => 'select', + '#title' => t('Select a derivative'), + '#default_value' => $selected, + '#options' => $options, + '#description' => NULL, + '#attributes' => array('onchange' => 'parent.img_assist_properties.location.href=this.options[selectedIndex].value'), + ); + $output .= drupal_get_form('img_assist_load_preview', $form); } /* If the directory view is the one invoking this function */ @@ -731,7 +823,7 @@ $img_assist_editor = variable_get('img_assist_editor', ''); $on_submit_hook = $img_assist_editor. '_img_assist_on_submit'; - $on_click = function_exists($on_submit_hook) ? $on_submit_hook() : 'create_image(this.form);'; + $on_click = function_exists($on_submit_hook) ? $on_submit_hook() : 'create_image(document.forms[0]);'; if (!$id) { $id = arg(3); @@ -752,69 +844,112 @@ } } - // This isn't too much of a hack in my opinion as there aren't any security - // breeches with this user permission, it's just an advanced option that's - // confusing for beginners. - $ft_hide = ''; - if (!user_access('choose format type')) { - $ft_hide = 'style="display:none;"'; - } - - $preview = form_button(t('Show code'), 'preview', 'button', array('onClick' => 'img_preview(this.form)')). ' '; - $alt = form_textfield(t('Image description for the visually impaired'), 'alt', $img->title, 55, 255); - $dim_txt = t('Image size in pixels'); - $width_txt = t('Width'); - $width = form_textfield(null, 'width', $img->width, 3, 5, null, array('onKeyUp' => "resizew(this.form, $img->width, $img->height)")); - $height_txt = t('Height'); - $height = form_textfield(null, 'height', $img->height, 3, 5, null, array('onKeyUp' => "resizeh(this.form, $img->width, $img->height)")); - $aspect = form_checkbox(t('Maintain aspect ratio'), 'aspect', 1, 1, null); - $caption = form_textarea(t('Image caption (optional)'), 'caption', $img->caption, 70, 2); - $id_field = form_hidden('fid', $img->fid); - $id_field .= form_hidden('nid', $img->nid); - $id_field .= form_hidden('filepath', file_create_url($img->filepath)); - $id_field .= form_hidden('nodePath', url("node/$img->nid")); - $id_field .= form_hidden('origWidth', $img->width); - $id_field .= form_hidden('origHeight', $img->height); - $format_type = ' '. t('filter'); - $format_type .= '  '. t('html'). ''; - $submit = $preview . form_button(t('Insert image'), 'op', 'button', array('onClick' => $on_click. 'javascript:top.window.close();')). ' '; - $thumb = form_group(t('Image to use'), $label); + $form['imgtouse'] = array( + '#type' => 'fieldset', + '#title' => t('Image to use'), + '#prefix' => '' + ); + $form['imgtouse']['alt'] = array( + '#type' => 'textfield', + '#title' => t('Image description for the visually impaired'), + '#default_value' => $img->title, + '#size' => 55, + '#maxlength' => 255, + ); + $form['imgtouse']['caption'] = array( + '#type' => 'textarea', + '#title' => t('Image caption (optional)'), + '#default_value' => $img->caption, + '#cols' => 70, + '#rows' => 2, + ); + $form['imgsize'] = array( + '#type' => 'fieldset', + '#title' => t('Image size in pixels'), + '#prefix' => '
', + '#suffix' => '', + '#suffix' => '
' + ); + $form['imgsize']['width'] = array( + '#type' => 'textfield', + '#title' => t('Width'), + '#default_value' => $img->width, + '#size' => 3, + '#maxlength' => 5, + '#description' => null, + '#attributes' => array('onKeyUp' => "resizew(this.form, $img->width, $img->height)"), + ); + $form['imgsize']['height'] = array( + '#type' => 'textfield', + '#title' => t('Height'), + '#default_value' => $img->height, + '#size' => 3, + '#maxlength' => 5, + '#description' => null, + '#attributes' => array('onKeyUp' => "resizeh(this.form, $img->width, $img->height)"), + ); + $form['imgsize']['aspect'] = array( + '#type' => 'checkbox', + '#title' => t('Maintain aspect ratio'), + '#return_value' => 1, + '#default_value' => 1, + '#description' => null, + ); + $form['id_field']['fid'] = array( + '#type' => 'hidden', + '#value' => $img->fid, + ); + $form['id_field']['nid'] = array( + '#type' => 'hidden', + '#value' => $img->nid, + ); + $form['id_field']['filepath'] = array( + '#type' => 'hidden', + '#value' => file_create_url($img->filepath), + ); + $form['id_field']['nodePath'] = array( + '#type' => 'hidden', + '#value' => url("node/$img->nid"), + ); + $form['id_field']['origWidth'] = array( + '#type' => 'hidden', + '#value' => $img->width, + ); + $form['id_field']['origHeight'] = array( + '#type' => 'hidden', + '#value' => $img->height, + ); + if (user_access('choose format type')) { + $form['formatType'] = array( + '#type' => 'radios', + '#title' => t('format type'), + '#options' => array('filter' => t('filter'), 'html' => t('html')), + ); + } + $form['preview'] = array( + '#type' => 'button', + '#value' => t('Show code'), + '#button_type' => 'button', + '#attributes' => array('onClick' => "img_preview(document.forms[0]);") + ); + $form['insert'] = array( + '#type' => 'button', + '#value' => t('Insert image'), + '#weight' => 19, + '#attributes' => array('onClick' => $on_click . "javascript:top.window.close();"), + ); -$output = << - $alt - - - - $thumb - - -
- $dim_txt - - - - -
$width_txt$width
$height_txt$height
 $aspect
-
- - - - $caption - -

$format_type $id_field $submit

- - +$output = drupal_get_form('img_assist_load_properties', $form); +$output .= << // Preset the output format type based on parent context. - document.forms[0].formatType[1].checked = 1; + document.forms[0]['edit[formatType]'][1].checked = 1; if (parent.hasInputFormat && parent.editor == '') { - document.forms[0].formatType[0].checked = 1; + document.forms[0]['edit[formatType]'][0].checked = 1; } EOD; - - return ($id > 0 ? form($output) : t('

Once you\'ve clicked on an above image, you can modify its properties in this pane.

')); + return ($id > 0 ? $output : t('

Once you\'ve clicked on an above image, you can modify its properties in this pane.

')); } /********************************************************************