You are here

function ad_menu in Advertisement 5

Same name and namespace in other branches
  1. 5.2 ad.module \ad_menu()
  2. 6.3 ad.module \ad_menu()
  3. 6 ad.module \ad_menu()
  4. 6.2 ad.module \ad_menu()
  5. 7.3 ad.module \ad_menu()
  6. 7 ad.module \ad_menu()

Implementation of hook_menu().

File

./ad.module, line 1103
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/statistics',
      'title' => t('Statistics'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'ad_admin_statistics',
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    );
    $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));
      $hostid = preg_replace('/[^0-9a-f]/', '', arg(4));
      $items[] = array(
        'path' => "ad/redirect/{$aid}",
        'access' => user_access('show advertisements'),
        'type' => MENU_CALLBACK,
        'callback' => 'ad_redirect',
        'callback arguments' => array(
          $aid,
          $group,
          $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,
        );
      }
    }
    elseif (arg(0) == 'node' && is_numeric(arg(1)) && ad_adaccess(arg(1), 'manage owners')) {
      $node = node_load(arg(1));
      if ($node->adtype) {
        $items[] = array(
          'path' => "node/{$node->nid}/adowners",
          'access' => ad_adaccess($node->nid, 'manage owners'),
          'title' => t('Ad owners'),
          'callback' => 'ad_owners_overview',
          'callback arguments' => array(
            $node,
          ),
          'type' => MENU_LOCAL_TASK,
          'weight' => 5,
        );
        $items[] = array(
          'path' => "node/{$node->nid}/adowners/list",
          'access' => ad_adaccess($node->nid, 'manage owners'),
          'title' => t('List'),
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => 0,
        );
        if (is_numeric(arg(3))) {
          $uid = arg(3);
          $ad_user = user_load(array(
            'uid' => $uid,
          ));
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/{$uid}/permissions",
            'title' => t('!owner\'s permissions', array(
              '!owner' => $ad_user->name,
            )),
            'access' => ad_adaccess($node->nid, 'manage owners'),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_owner_permissions',
              $node->nid,
              $uid,
            ),
            'type' => MENU_LOCAL_TASK,
            'weight' => 2,
          );
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/{$uid}/remove",
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_owner_remove',
              $node->nid,
              $uid,
            ),
            'type' => MENU_CALLBACK,
            'weight' => 6,
          );
        }
        else {
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/add",
            'access' => ad_adaccess($node->nid, 'manage owners'),
            'title' => t('Add'),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_owners_add_form',
              $node,
            ),
            'type' => MENU_LOCAL_TASK,
            'weight' => 4,
          );
        }
      }
    }
    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;
}