function _ad_image_node_form in Advertisement 7
Adapi helper function for displaying a node form.
1 call to _ad_image_node_form()
- ad_image_adapi in image/
ad_image.module - Implementation of hook_adapi().
File
- image/
ad_image.module, line 490 - Enhances the ad module to support banner ads.
Code
function _ad_image_node_form(&$node) {
$form = array();
ad_image_adapi('check_install', $node);
$form['ad_image'] = array(
'#type' => 'fieldset',
'#title' => t('Image'),
'#collapsible' => TRUE,
);
if (!empty($node->remote_image)) {
$file->filename = $node->remote_image;
$file->filepath = $node->remote_image;
$image = ad_image_validate_size($file, $node->nid);
$path = '<img src="' . $node->remote_image . '" alt="' . t('image') . '" /> ';
if ($image === FALSE) {
$path .= t('(invalid image)') . '<br />';
}
}
else {
if (isset($node->files)) {
$files = $node->files;
}
else {
if (!isset($node->vid)) {
$node->vid = '';
}
$files = module_invoke('upload', 'load', $node);
}
}
$num = isset($files) ? sizeof($files) : 0;
if ($num) {
$path = NULL;
$active = 0;
foreach ($files as $file) {
if (is_array($file)) {
$file = (object) $file;
}
if ($file->list && file_exists($file->filepath)) {
$path .= '<img src="' . file_create_url($file->filepath) . '" alt="' . check_plain($file->filename) . '" /> ';
$image = ad_image_validate_size($file, $node->nid);
if ($image === FALSE) {
$path .= t('(invalid image)') . '<br />';
}
else {
if (!$active++) {
$path .= t('(active)') . '<br />';
}
else {
$path .= t('(inactive)') . '<br />';
}
}
}
else {
if (!file_exists($file->filepath)) {
drupal_set_message(t('Unable to locate image %image.', array(
'%image' => "{$file->filepath}",
)));
$path .= t('Unable to locate the uploaded image.');
}
}
}
}
if (!isset($path) || $path == NULL) {
$path = t('No images have been uploaded. Please upload an image via the <em>File attachments</em> form section below.<br />');
// Only set error if node has been previewed or submitted.
if (isset($_POST['edit'])) {
form_set_error('upload', t('It is required that you upload an image for your image advertisement.'));
}
}
else {
if ($num) {
$path .= t('<br />Only the first uploaded image that has <em>List</em> checked in the <em>File attachments</em> form section below will be displayed as an advertisement. The image that will be displayed is marked as <em>active</em> above.');
}
}
$form['ad_image']['image'] = array(
'#type' => 'markup',
'#value' => $path,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$form['ad_image']['url'] = array(
'#type' => 'textfield',
'#title' => t('Destination URL'),
'#required' => FALSE,
'#default_value' => isset($node->url) ? $node->url : '',
'#description' => t('Enter the complete URL where you want people to be redirected when they click on this advertisement. The URL must be valid and begin with http:// or https://, for example %url, unless you !disable. If you do not enter a URL, the advertisement will not be clickable.', array(
'%url' => t('http://www.sample.org/'),
'!disable' => l(t('disable URL validation'), 'admin/content/ad/configure', array(
'fragment' => 'edit-ad-validate-url-wrapper',
)),
)),
);
$form['ad_image']['tooltip'] = array(
'#type' => 'textfield',
'#title' => t('Mouseover'),
'#required' => FALSE,
'#default_value' => isset($node->tooltip) ? $node->tooltip : '',
'#description' => t('Optionally enter text to appear when a mouse pointer hovers over the ad image.'),
);
if (variable_get('ad_image_remote_images', FALSE)) {
$form['ad_image']['remote_image'] = array(
'#type' => 'textfield',
'#title' => t('Remote image path'),
'#required' => FALSE,
'#default_value' => isset($node->remote_image) ? $node->remote_image : '',
'#description' => t('Instead of uploading an image, you may optionally specify a complete URL to a remotely hosted image. For example, %example. If you do not specify a remotely hosted image, you must attach an image to this advertisement in the %attachment section below.', array(
'%example' => 'http://sample.com/images/ad.png',
'%attachment' => t('File attachements'),
)),
);
}
return $form;
}