function ocupload_form_template in One Click Upload 7.2
Same name and namespace in other branches
- 7 ocupload.inc \ocupload_form_template()
Form add/edit template.
1 string reference to 'ocupload_form_template'
- ocupload_menu in ./
ocupload.module - Implements hook_menu().
File
- ./
ocupload.inc, line 55 - One Click Upload includes.
Code
function ocupload_form_template($form, &$form_state, $template = NULL) {
if (!$template) {
$template = (object) array(
'tid' => 0,
'mask' => '',
'path' => 'public://inline',
'filename' => '',
'max_filesize' => 0,
'template' => '<a href="!filepath">!filename</a>',
'template_select' => '<a href="!filepath">!text</a>',
'image_style' => '',
'image_style_original' => '',
'link_to_original' => 0,
'link_template' => '<a href="!filepath" target="_blank">!image</a>',
'link_only_big' => 0,
'max_dimensions' => '',
'field' => '',
'transliterate' => 1,
);
drupal_set_title(t('Add template'));
}
$token_tree_link = t('Can use tokens');
if (module_exists('token')) {
$token_tree_link = theme('token_tree_link', array(
'text' => $token_tree_link,
'token_types' => array(
'user',
),
));
}
$form['tid'] = array(
'#type' => 'value',
'#value' => $template->tid,
);
$form['mask'] = array(
'#type' => 'textfield',
'#title' => t('File extensions'),
'#description' => t('Comma separated list of file extensions which should be handled within this template. Example: <code>jpg,gif,png</code>'),
'#default_value' => $template->mask,
'#size' => 40,
'#required' => TRUE,
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Upload path'),
'#description' => t('Do not include preceding or trailing slashes. Example: <code>public://images</code>') . '<br />' . $token_tree_link . '.',
'#default_value' => $template->path,
'#size' => 40,
'#required' => TRUE,
);
$form['filename'] = array(
'#type' => 'textfield',
'#title' => t('Filename'),
'#description' => t('New filename without extension. Leave blank if you don\'t want to rename files.') . ' ' . $token_tree_link . '.',
'#default_value' => $template->filename,
'#size' => 40,
);
$form['max_filesize'] = array(
'#type' => 'textfield',
'#title' => t('Maximum upload size'),
'#default_value' => $template->max_filesize ? format_size($template->max_filesize, 'en') : 0,
'#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size.'),
'#size' => 10,
);
$form['template'] = array(
'#type' => 'textfield',
'#title' => t('Template to insert into editor'),
'#default_value' => $template->template,
'#maxlength' => NULL,
'#size' => 100,
'#required' => TRUE,
);
$form['template_select'] = array(
'#type' => 'textfield',
'#title' => t('Template to replace selected text'),
'#default_value' => $template->template_select,
'#maxlength' => NULL,
'#size' => 100,
'#required' => TRUE,
);
$form['help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['help']['text'] = array(
'#markup' => '
!filefid — ' . t('file id') . '<br />
!filepath — ' . t('full path to file') . '<br />
!filename — ' . t('file name after upload') . '<br />
!originalname — ' . t('original file name') . '<br />
!fileext — ' . t('file extension') . '<br />
!filesize — ' . t('file size') . '<br />
!text — ' . t('selected text') . '<br />
',
);
if (module_exists('image')) {
$form['image_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Options for images'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['image_settings']['image_style'] = array(
'#type' => 'select',
'#title' => t('Use image style'),
'#options' => image_style_options(),
'#default_value' => $template->image_style,
);
$form['image_settings']['link_to_original'] = array(
'#type' => 'checkbox',
'#title' => t('Add link to original image'),
'#default_value' => $template->link_to_original,
'#states' => array(
'invisible' => array(
'select[name="image_style"]' => array(
'value' => '',
),
),
),
);
$form['image_settings']['link_template'] = array(
'#type' => 'textfield',
'#title' => t('Link template'),
'#default_value' => $template->link_template,
'#maxlength' => NULL,
'#states' => array(
'visible' => array(
'input[name="link_to_original"]' => array(
'checked' => TRUE,
),
),
),
);
$form['image_settings']['link_only_big'] = array(
'#type' => 'checkbox',
'#title' => t('Add link only for those images which size exceeds the size, specified in the style'),
'#default_value' => $template->link_only_big,
'#states' => array(
'visible' => array(
'input[name="link_to_original"]' => array(
'checked' => TRUE,
),
),
),
);
$form['image_settings']['use_image_style_original'] = array(
'#type' => 'checkbox',
'#title' => t('Use image style for original image'),
'#default_value' => (bool) $template->image_style_original,
'#states' => array(
'visible' => array(
'input[name="link_to_original"]' => array(
'checked' => TRUE,
),
),
),
);
$form['image_settings']['image_style_original'] = array(
'#type' => 'select',
'#title' => t('Image style for original image'),
'#options' => image_style_options(FALSE),
'#default_value' => $template->image_style_original,
'#states' => array(
'visible' => array(
'input[name="use_image_style_original"]' => array(
'checked' => TRUE,
),
),
),
);
$form['image_settings']['max_dimensions'] = array(
'#type' => 'textfield',
'#title' => 'Maximum image resolution',
'#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
'#default_value' => $template->max_dimensions,
'#size' => 10,
);
}
$options = array();
foreach (field_info_field_map() as $field_name => $field_info) {
if ($field_info['type'] == 'file' || $field_info['type'] == 'image') {
$options[$field_name] = $field_name;
}
}
$form['field'] = array(
'#type' => 'select',
'#title' => t('Entity field'),
'#description' => t('The entity file or image field in which uploaded files will be stored.'),
'#options' => $options,
'#empty_option' => t('<none>'),
'#default_value' => $template->field,
);
$transliteration_module_exists = module_exists('transliteration');
$transliteration_module_link = l('Transliteration', 'https://www.drupal.org/project/transliteration', array(
'external' => TRUE,
));
$form['transliterate'] = array(
'#type' => 'checkbox',
'#title' => t('Transliterate file names (highly recommended)'),
'#description' => t('Transliterate file names before saving. Highly recommended to avoid file URL issues, and requires the !transliteration module.', array(
'!transliteration' => $transliteration_module_link,
)),
'#default_value' => $transliteration_module_exists && $template->transliterate,
'#disabled' => !$transliteration_module_exists,
);
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#description' => t('Checked roles are allowed to upload files of this type.'),
'#options' => array_map('check_plain', user_roles()),
'#default_value' => array_keys(user_roles(FALSE, 'upload files use template ' . $template->tid)),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $template->tid ? t('Save template') : t('Add template'),
);
return $form;
}