function ad_add in Advertisement 5.2
Same name and namespace in other branches
- 5 ad.module \ad_add()
Present a list of ad types to choose from.
File
- ./
ad.module, line 1269 - An advertising system for Drupal powered websites.
Code
function ad_add() {
global $user;
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
$adtypes = module_invoke_all('adapi', 'type', array());
if (arg(3) && is_array($adtypes) && in_array(arg(3), array_keys($adtypes))) {
$adtype = arg(3);
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => 'ad',
'adtype' => $adtype,
);
foreach (array(
'title',
'teaser',
'body',
) as $field) {
if ($_GET['edit'][$field]) {
$node[$field] = $_GET['edit'][$field];
}
}
drupal_set_title(t('Submit %name', array(
'%name' => $adtype,
)));
$output = drupal_get_form('ad_node_form', $node);
}
else {
$output = t('Choose from the following available advertisement types:');
$output .= '<dl>';
if (sizeof($adtypes) == 1) {
drupal_goto('node/add/ad/' . $adtypes[0]);
}
else {
if (sizeof($adtypes)) {
foreach ($adtypes as $type) {
$output .= '<dt>' . l(t('!type advertisement', array(
'!type' => $type,
)), "node/add/ad/{$type}") . '</dt>';
// Bugfix #166097: don't array_pop the module_invoke_all directly.
// See: http://drupal.org/node/166097
$help = module_invoke_all('help', 'node/add/ad#' . $type);
$output .= '<dd>' . array_pop($help) . '</dd>';
}
}
else {
$output .= '<dt>' . t('There are no advertisement types available.') . '</dt>';
}
}
$output .= '</dl>';
}
return $output;
}