function ad_menu in Advertisement 5.2
Same name and namespace in other branches
- 5 ad.module \ad_menu()
- 6.3 ad.module \ad_menu()
- 6 ad.module \ad_menu()
- 6.2 ad.module \ad_menu()
- 7.3 ad.module \ad_menu()
- 7 ad.module \ad_menu()
Implementation of hook_menu().
File
- ./
ad.module, line 1102 - An advertising system for Drupal powered websites.
Code
function ad_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
// menu items
$items[] = array(
'path' => 'admin/content/ad',
'title' => t('Ads'),
'callback' => 'ad_admin_list',
'access' => user_access('administer advertisements'),
'description' => t('Configure and manage your advertising system.'),
);
// tabs
$items[] = array(
'path' => 'admin/content/ad/list',
'title' => t('List'),
'callback' => 'ad_admin_list',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/content/ad/configure',
'title' => t('Settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'ad_admin_configure_settings',
),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items[] = array(
'path' => 'admin/content/ad/groups',
'title' => t('Groups'),
'callback' => 'ad_admin_groups_list',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
// groups sub tabs
$items[] = array(
'path' => 'admin/content/ad/groups/list',
'title' => t('List'),
'callback' => 'ad_admin_groups_list',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items[] = array(
'path' => 'admin/content/ad/groups/add',
'title' => t('Create group'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'ad_admin_group_form',
),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
// configure sub tabs
$items[] = array(
'path' => 'admin/content/ad/configure/global',
'title' => t('Global settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'ad_admin_configure_settings',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items[] = array(
'path' => 'node/add/ad',
'title' => t('Ad'),
'callback' => 'ad_add',
'access' => user_access('create advertisements'),
);
$adtypes = module_invoke_all('adapi', 'type', array());
foreach ($adtypes as $adtype) {
// Ad type global settings.
$settings = "ad_{$adtype}_global_settings";
if (!function_exists($settings)) {
$settings = 'ad_no_global_settings';
}
$items[] = array(
'path' => 'admin/content/ad/configure/' . $adtype,
'title' => t('!adtype ads', array(
'!adtype' => drupal_ucfirst($adtype),
)),
'callback' => 'drupal_get_form',
'callback arguments' => array(
$settings,
),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
// Node add items.
$items[] = array(
'path' => 'node/add/ad/' . $adtype,
'title' => t('!type advertisement', array(
'!type' => t($adtype),
)),
'access' => user_access('create advertisements'),
);
}
}
else {
// callbacks
if (arg(0) == 'ad' && arg(1) == 'redirect' && is_numeric(arg(2))) {
$aid = preg_replace('/[^0-9]/', '', arg(2));
$group = preg_replace('/[^0-9,nt]/', '', arg(3));
$extra = preg_replace('/[^0-9,:a-zA-Z]/', '', arg(4));
$hostid = arg(5);
if (!empty($hostid)) {
$hostid = explode('?', $hostid);
$hostid = preg_replace('/[^0-9a-f]/', '', $hostid[0]);
}
$items[] = array(
'path' => "ad/redirect/{$aid}",
'access' => user_access('show advertisements'),
'type' => MENU_CALLBACK,
'callback' => 'ad_redirect',
'callback arguments' => array(
$aid,
$group,
$extra,
$hostid,
),
);
}
elseif (arg(2) == 'ad' && arg(3) == 'groups' && is_numeric(arg(4))) {
if ($term = taxonomy_get_term(arg(4))) {
$items[] = array(
'path' => "admin/content/ad/groups/{$term->tid}/edit",
'title' => t('edit'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'ad_admin_group_form',
(array) $term,
),
'access' => user_access('administer advertisements'),
'type' => MENU_CALLBACK,
'weight' => 1,
);
$items[] = array(
'path' => "admin/content/ad/groups/{$term->tid}/delete",
'title' => t('delete'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'ad_confirm_group_delete',
(array) $term,
),
'access' => user_access('administer advertisements'),
'type' => MENU_CALLBACK,
'weight' => 2,
);
}
}
if (is_numeric($nid = arg(1)) && is_numeric($cid = arg(3))) {
$items[] = array(
'path' => "node/{$nid}/details/{$cid}",
'title' => t('Click details'),
'callback' => 'ad_click_details',
'callback arguments' => array(
$nid,
$cid,
),
'type' => MENU_CALLBACK,
);
}
}
return $items;
}