uid == arg(2)) {
$owner = TRUE;
}
}
// Load data for sub-pages.
$pages = array(
array('title' => 'Home', 'page' => 0, 'status' => TRUE),
array('title' => 'First', 'page' => 1, 'status' => TRUE),
array('title' => 'Second', 'page' => 2, 'status' => TRUE),
);
// Menu actions to implement
$actions = array(
'view' => array('title' => t('View'), 'weight' => -10, 'path' => 'view'),
'edit' => array('title' => t('Settings'), 'weight' => -8, 'path' => 'edit'),
'content' => array('title' => t('Content'), 'weight' => -6, 'path' => 'content'),
'remove' => array('title' => t('Remove'), 'weight' => -4, 'path' => 'remove'),
);
if (!$may_cache) {
$items[] = array(
'title' => mysite_sitename(),
'path' => 'mysite-new',
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'callback' => 'mysite_pages_list',
'access' => $view
);
$items[] = array(
'title' => mysite_sitename(),
'path' => 'mysite-new/'. arg(1),
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1)),
'access' => $view
);
$items[] = array(
'title' => t('Delete'),
'path' => 'mysite-new/'. arg(1) .'/delete',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1)),
'access' => $owner
);
// 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;
if ($arg == 'view') {
$items[] = array(
'title' => t('View'),
'path' => 'mysite-new/'. arg(1) .'/view',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1)),
'access' => $view
);
$items[] = array(
'title' => t('Add new tab'),
'path' => 'mysite-new/'. arg(1) .'/view/add-page',
'type' => MENU_LOCAL_TASK,
'weight' => 100,
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1)),
'access' => $view
);
}
foreach ($actions as $action => $settings) {
if ($action == $arg && !empty($pages)) {
$items[] = array(
'title' => $settings['title'],
'path' => 'mysite-new/'. arg(1) .'/'. $settings['path'],
'type' => MENU_LOCAL_TASK,
'weight' => $settings['weight'],
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1)),
'access' => $view
);
foreach ($pages as $key => $value) {
$type = MENU_LOCAL_TASK;
if ($settings['path'] == 'view' && $key == 0) {
$type = MENU_DEFAULT_LOCAL_TASK;
}
$items[] = array(
'title' => $value['title'],
'path' => 'mysite-new/'. arg(1) .'/'. $settings['path'] .'/'. $key,
'type' => $type,
'weight' => (-10 + $value['page']),
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1), arg(3)),
'access' => $view
);
$weight++;
}
}
if ($action != $arg) {
$items[] = array(
'title' => $settings['title'],
'path' => 'mysite-new/'. arg(1) .'/'. $settings['path'] .'/'. $page,
'type' => MENU_LOCAL_TASK,
'weight' => $settings['weight'],
'callback' => 'mysite_pages_test',
'callback arguments' => array(arg(1), arg(3)),
'access' => $owner
);
}
}
$items[] = array(
'title' => t('Add content'),
'path' => 'mysite-new/add/',
'type' => MENU_CALLBACK,
'callback' => 'mysite_pages_test',
'access' => $owner
);
$items[] = array(
'title' => t('Remove content'),
'path' => 'mysite-new/remove/',
'type' => MENU_CALLBACK,
'callback' => 'mysite_pages_test',
'access' => $owner
);
}
return $items;
}
/**
* Test router
*/
function mysite_pages_list() {
global $user;
$output = l($user->name, 'mysite-new/'. $user->uid);
return $output;
}
/**
* Test args
*/
function mysite_pages_test($uid = 0, $page = 0, $three = NULL, $four = NULL) {
$output = $uid . '1
';
$output .= $page . '2
';
$output .= $three . '3
';
$output .= $four . '4
';
return $output;
}
/**
* Get the settings for a page, overriding the user defaults from {mysite}
*/
function mysite_pages_get(&$mysite, $page) {
// get the data for this page in the collection
$data = db_fetch_array(db_query("SELECT pmid, tmid, page_title, layout, style, theme, status FROM {mysite_page} WHERE uid = %d AND page = %d", $mysite->uid, $page));
// if found, replace the data we were passed
if (!empty($data)) {
foreach ($data as $key => $value) {
if (!empty($value)) {
$mysite->$key = $value;
}
}
}
}