mysite_menu($may_cache)
mysite.module, line 51
Implementation of hook_menu().
function mysite_menu($may_cache) {
global $user;
$items = array();
// Run access checks once for the entire menu.
$admin = FALSE;
$view = user_access('view mysite');
if (user_access('administer mysite')) {
$admin = TRUE;
$owner = TRUE;
$create = TRUE;
}
else {
$create = user_access('edit mysite');
$owner = FALSE;
if ($create && $user->uid == arg(1)) {
$owner = TRUE;
}
}
// Load the MySite data for the menu, if needed
$show_pages = FALSE;
if (arg(0) == 'mysite') {
$uid = arg(1);
$mysite = mysite_get($uid);
$show_pages = TRUE;
$access = mysite_menu_check($mysite->status, $owner, $view);
// conditional functions needed by MySite's user interface
// add the css to override form-item and format icons
drupal_add_css(drupal_get_path('module', 'mysite') .'/mysite.css');
// we use the collapse feature in the interface, so make sure it loads.
if (function_exists('jquery_interface_add') && ($admin || $owner)) {
drupal_add_js(drupal_get_path('module', 'mysite') .'/mysite.js', 'module');
// add interface support
jquery_interface_add();
}
}
if ($may_cache) {
$items[] = array('path' => 'admin/settings/mysite',
'title' => t('MySite'),
'description' => t('Adjust the features and settings for the MySite module.'),
'callback' => 'mysite_configure',
'access' => $admin);
// menu items for default settings
$items[] = array('path' => 'admin/settings/mysite/edit',
'title' => t('Default page settings'),
'description' => t('Edit the default MySite content settings.'),
'callback' => 'drupal_goto',
'weight' => -8,
'type' => MENU_LOCAL_TASK,
'callback arguments' => array('mysite/0/edit'),
'access' => $admin);
$items[] = array('path' => 'admin/settings/mysite/content',
'title' => t('Default page content'),
'description' => t('Edit the default MySite content settings.'),
'weight' => -6,
'callback' => 'drupal_goto',
'type' => MENU_LOCAL_TASK,
'callback arguments' => array('mysite/0/content'),
'access' => $admin);
// activate a plugin
$items[] = array('path' => 'admin/settings/mysite/type/activate',
'title' => mysite_sitename(),
'callback' => 'mysite_activate',
'type' => MENU_CALLBACK,
'access' => $admin);
// default page view items
$items[] = array('path' => 'mysite',
'title' => mysite_sitename(),
'callback' => 'mysite_view',
'access' => $view);
// admin tasks
$items[] = array('path' => 'mysite/0/admin',
'title' => t('Settings'),
'callback' => 'drupal_goto',
'type' => MENU_LOCAL_TASK,
'callback arguments' => array('admin/settings/mysite'),
'weight' => -5,
'access' => $admin);
$items[] = array('path' => 'mysite/0/view',
'title' => t('Default pages'),
'callback' => 'mysite_view',
'type' => MENU_LOCAL_TASK,
'weight' => -3,
'access' => $admin);
$items[] = array('path' => 'mysite/0/edit',
'title' => t('Default settings'),
'callback' => 'mysite_edit',
'type' => MENU_LOCAL_TASK,
'access' => $admin);
$items[] = array('path' => 'mysite/0/content',
'title' => t('Default content'),
'callback' => 'mysite_content',
'type' => MENU_LOCAL_TASK,
'access' => $admin);
$items[] = array('path' => 'mysite-all',
'title' => t('View all personal sites'),
'callback' => 'mysite_view_all',
'access' => $view);
$items[] = array('path' => 'mysite-default',
'title' => mysite_sitename(),
'callback' => 'mysite_view_default',
'type' => MENU_CALLBACK,
'access' => $view);
$items[] = array('path' => 'autocomplete/mysite',
'title' => t('MySite autocomplete'),
'callback' => 'mysite_autocomplete',
'type' => MENU_CALLBACK,
'access' => $create);
}
else {
// add a tab to the user page
if (arg(0) == 'user' && is_numeric(arg(1))) {
$items[] = array('path' => 'user/'. arg(1) .'/mysite',
'title' => mysite_sitename(),
'access' => $owner,
'callback' => 'mysite_page',
'callback arguments' => array(arg(1)),
'type' => MENU_LOCAL_TASK, 'weight' => 10);
}
// Ajax handling items
$items[] = array('path' => 'ajax/mysite/'. arg(2) .'/'. arg(3),
'title' => t('Ajax MySite'),
'callback' => 'mysite_ajax',
'callback arguments' => array(arg(2), arg(3)),
'type' => MENU_CALLBACK,
'access' => $create);
$items[] = array('path' => 'ajax/mysite-sort',
'title' => t('Ajax MySite'),
'callback' => 'mysite_ajax_sort',
'type' => MENU_CALLBACK,
'access' => $create);
if (arg(0) == 'mysite' && is_numeric(arg(1))) {
$items[] = array(
'title' => $mysite->title,
'path' => 'mysite/'. arg(1),
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'callback' => 'mysite_view',
'callback arguments' => array(arg(1)),
'access' => $access);
$items[] = array('path' => 'mysite/'. arg(1) .'/delete',
'title' => t('Delete'),
'callback' => 'drupal_get_form',
'callback arguments' => array('mysite_delete_form', arg(1)),
'access' => $owner,
'weight' => 10,
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'mysite/'. arg(1) .'/reset',
'title' => t('Reset'),
'callback' => 'drupal_get_form',
'callback arguments' => array('mysite_reset_form'),
'access' => $owner,
'type' => MENU_CALLBACK);
if ($show_pages) {
// Load data for sub-pages.
$pages = mysite_get_pages($uid);
// Menu actions to implement
$actions = array(
'view' => array('title' => t('View'), 'weight' => -10, 'path' => 'view', 'callback' => 'mysite_page'),
'edit' => array('title' => t('Settings'), 'weight' => -8, 'path' => 'edit', 'callback' => 'mysite_edit'),
'content' => array('title' => t('Content'), 'weight' => -6, 'path' => 'content', 'callback' => 'mysite_content')
);
// prep the submenu tasks
$weight = -10;
$test = arg(2);
$arg = (empty($test)) ? 'view' : $test;
$i = arg(3);
$page = (empty($i)) ? 0 : $i;
$page = ($page == 'add-page') ? 0 : $page;
// We can only remove pages if it is not the default page.
if ($page > 0 && count($pages) > 0) {
$actions['remove'] = array('title' => t('Remove page'), 'weight' => -4, 'path' => 'remove-page', 'callback' => 'mysite_remove_page');
}
if ($arg == 'view') {
$items[] = array(
'title' => t('View'),
'path' => 'mysite/'. arg(1) .'/view',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'callback' => 'mysite_view',
'callback arguments' => array(arg(1)),
'access' => $access
);
if (count($pages) < variable_get('mysite_pages', 5)) {
$items[] = array(
'title' => t('Add new page'),
'path' => 'mysite/'. arg(1) .'/view/add-page',
'type' => MENU_LOCAL_TASK,
'weight' => 100,
'callback' => 'mysite_add_page',
'callback arguments' => array(arg(1)),
'access' => $owner
);
}
}
$content_set = MENU_CALLBACK;
if ($test == 'settings') {
$content_set = MENU_LOCAL_TASK;
}
$items[] = array('path' => 'mysite/'. arg(1) .'/settings/'. arg(3) .'/'. arg(4),
'title' => t('Customize'),
'callback' => 'mysite_content_settings',
'callback arguments' => array(arg(1), arg(4)),
'access' => $owner,
'weight' => 10,
'type' => $content_set
);
foreach ($actions as $action => $settings) {
if ($action == $arg && !empty($pages)) {
$items[] = array(
'title' => $settings['title'],
'path' => 'mysite/'. arg(1) .'/'. $settings['path'],
'type' => MENU_LOCAL_TASK,
'weight' => $settings['weight'],
'callback' => $settings['callback'],
'callback arguments' => array(arg(1)),
'access' => ($arg == 'view') ? $access : $owner
);
foreach ($pages as $key => $value) {
$type = MENU_LOCAL_TASK;
$page_access = $owner;
if ($settings['path'] == 'view') {
$page_access = mysite_menu_check($value['status'], $owner, $view);
if ($key == 0) {
$type = MENU_DEFAULT_LOCAL_TASK;
}
}
$items[] = array(
'title' => $value['title'],
'path' => 'mysite/'. arg(1) .'/'. $settings['path'] .'/'. $key,
'type' => $type,
'weight' => (-10 + $value['page']),
'callback' => $settings['callback'],
'callback arguments' => array(arg(1), arg(3)),
'access' => $page_access
);
$weight++;
}
}
$items[] = array(
'title' => $settings['title'],
'path' => 'mysite/'. arg(1) .'/'. $settings['path'] .'/'. $page,
'type' => MENU_LOCAL_TASK,
'weight' => $settings['weight'],
'callback' => $settings['callback'],
'callback arguments' => array(arg(1), arg(3)),
'access' => $owner
);
if ($arg == 'edit') {
$_mysite_edit = mysite_edit_menu();
foreach ($_mysite_edit as $key => $value) {
foreach ($value as $path => $element) {
$items[] = array('path' => 'mysite/'. arg(1) .'/edit/'. $key .'/'. $path,
'title' => $element['label'],
'callback' => 'mysite_edit',
'callback arguments' => array(arg(1), arg(3), arg(4)),
'access' => $owner,
'type' => MENU_LOCAL_TASK
);
}
}
}
}
}
// theme switching check
if (arg(0) == 'mysite' && is_numeric(arg(1))) {
$types = variable_get('mysite_content', NULL);
$themes = variable_get('mysite_theme_settings', array());
if (!empty($pages[$page]['theme']) && !empty($types['theme']) && !empty($themes[$mysite->theme])) {
global $custom_theme;
$custom_theme = $pages[$page]['theme'];
}
}
$items[] = array('path' => 'mysite/'. arg(1) .'/remove/'. arg(3),
'title' => t('Remove item'),
'callback' => 'mysite_content_remove',
'callback arguments' => array(arg(1), arg(3)),
'access' => $owner,
'weight' => 10,
'type' => MENU_CALLBACK);
$items[] = array('path' => 'mysite/'. arg(1) .'/promote/'. arg(3) .'/'. arg(4),
'title' => t('Promote item'),
'callback' => 'mysite_content_promote',
'callback arguments' => array(arg(1), arg(3), arg(4)),
'access' => $owner,
'weight' => 10,
'type' => MENU_CALLBACK);
$items[] = array('path' => 'mysite/'. arg(1) .'/add',
'title' => t('Add item'),
'callback' => 'mysite_content_add',
'callback arguments' => array(arg(1)),
'access' => $owner,
'weight' => 10,
'type' => MENU_CALLBACK);
}
if ($admin && arg(0) == 'admin' && arg(2) == 'mysite') {
$types = mysite_load_includes('types', NULL, $load_all = TRUE);
$items[] = array('path' => 'admin/settings/mysite/type',
'title' => t('Settings'),
'description' => t('Adjust the features and settings for the MySite module.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access' => $admin,
'weight' => -10);
$items[] = array('path' => 'admin/settings/mysite/type/settings',
'title' => t('MySite'),
'description' => t('Adjust the features and settings for the MySite module.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access' => $admin,
'weight' => -10);
if (is_array($types)) {
foreach ($types as $type) {
$check = module_invoke('mysite_type', $type, FALSE);
if ((function_exists('mysite_type_'. $type .'_title') || function_exists('mysite_type_'. $type .'_settings')) && is_array($check)) {
$items[] = array('path' => 'admin/settings/mysite/type/'. $type,
'title' => t('@type', array('@type' => ucwords($type))),
'description' => t('Settings for the @type plugin', array('@type' => ucwords($type))),
'callback' => 'mysite_type_settings',
'callback arguments' => array($type),
'type' => MENU_LOCAL_TASK,
'access' => $admin,
'weight' => 0);
}
}
}
}
}
return $items;
}