Commit 7231c88a authored by Dries's avatar Dries

- Added support for 403 handling. Patch by JonBob. As a side benefit,

  administrators will be able to define a custom 403 page, just as they
  can define 404 pages now.

  This needs to be documented in the "Changes since / migrating to ..."
  pages.
parent 79766787
......@@ -4,6 +4,11 @@ Drupal x.x.x, xxxx-xx-xx
- profile module:
* made it possible to administer profile fields.
* made it possible to browse the profiles by field.
- menu module:
* made it possible to customize menus.
- refactored 403 (forbidden) handling and added support for custom 403 pages.
- usability:
* slightly reorganized navigation menus.
Drupal 4.4.0, 2004-04-01 (release candidate)
--------------------------------------------
......@@ -40,7 +45,7 @@ Drupal 4.4.0, 2004-04-01 (release candidate)
* made themes degrade gracefully in absence of CSS.
* grouped form elements using '<fieldset>' and '<legend>' tags.
* added '<label>' tags to form elements.
- refactored 404 (file not found) handling to support custom 404 pages.
- refactored 404 (file not found) handling and added support for custom 404 pages.
- documentation:
* added PHPDoc/Doxygen comments.
- improved the filter system to prevent conflicts between filters:
......
......@@ -80,7 +80,6 @@ function drupal_get_breadcrumb() {
if (!isset($breadcrumb)) {
$breadcrumb = menu_get_active_breadcrumb();
array_pop($breadcrumb);
}
return $breadcrumb;
......@@ -253,23 +252,39 @@ function drupal_goto($url = NULL, $query = NULL, $fragment = NULL) {
* Generates a 404 error if the request can not be handled.
*/
function drupal_not_found() {
header("HTTP/1.0 404 Not Found");
watchdog("httpd", "404 error: '". check_query($_GET["q"]) ."' not found");
header('HTTP/1.0 404 Not Found');
watchdog('httpd', '404 error: "'. check_query($_GET['q']) .'" not found');
$path = drupal_get_normal_path(variable_get('site_404', ''));
$status = MENU_FALLTHROUGH;
if ($path) {
menu_set_active_item($path);
$status = menu_execute_active_handler();
}
if ($path && menu_active_handler_exists()) {
menu_execute_active_handler();
}
else {
if ($status != MENU_FOUND) {
print theme('page', '', t('Page not found'));
}
}
/**
* Generates a 403 error if the request is not allowed.
*/
function drupal_access_denied() {
header('HTTP/1.0 403 Forbidden');
$path = drupal_get_normal_path(variable_get('site_403', ''));
$status = MENU_FALLTHROUGH;
if ($path) {
menu_set_active_item($path);
$status = menu_execute_active_handler();
}
if ($status != MENU_FOUND) {
print theme('page', message_access(), t('Access denied'));
}
}
/**
* Flexible and powerful HTTP client implementation. Allows to GET, POST, PUT
* or any other HTTP requests. Handles redirects.
......
......@@ -307,7 +307,7 @@ function file_transfer($source, $headers) {
// Transfer file in 1024 byte chunks to save memory usage.
$fd = fopen($source, 'rb');
while (!feof($fd)) {
print fgets($fd, 1024);
print fread($fd, 1024);
}
fclose($fd);
exit();
......@@ -323,7 +323,7 @@ function file_download() {
foreach ($list as $module) {
$headers = module_invoke($module, 'file_download', $file);
if ($headers === -1) {
print theme('page', message_access());
drupal_access_denied();
}
elseif (is_array($headers)) {
file_transfer($file, $headers);
......
......@@ -15,6 +15,10 @@
define('MENU_LOCKED', 2);
define('MENU_CUSTOM', 3);
define('MENU_FALLTHROUGH', 0);
define('MENU_DENIED', 1);
define('MENU_FOUND', 2);
/** @} */
/**
......@@ -23,7 +27,10 @@
* @ingroup menu
* @param $path Location then menu item refers to.
* @param $title The title of the menu item to show in the rendered menu.
* @param $callback The function to call when this is the active menu item.
* @param $callback
* - string - The function to call when this is the active menu item.
* - MENU_FALLTHROUGH - Use the callback defined by the menu item's parent.
* - MENU_DENIED - Deny access to this menu item by this user.
* @param $weight Heavier menu items sink down the menu.
* @param $visibility
* - MENU_SHOW - Show the menu item (default).
......@@ -31,11 +38,9 @@
* - MENU_HIDE_NOCHILD - Hide the menu item when it has no children.
* @param $status
* - MENU_NORMAL - The menu item can be moved (default).
* - MENU_MODIFIED - The administrator has moved or otherwise changed the menu item.
* - MENU_LOCKED - The administrator may not modify the item.
* - MENU_CUSTOM - The menu item was created by the administrator.
*/
function menu($path, $title, $callback = NULL, $weight = 0, $visibility = MENU_SHOW, $status = MENU_NORMAL) {
function menu($path, $title, $callback = MENU_FALLTHROUGH, $weight = 0, $visibility = MENU_SHOW, $status = MENU_NORMAL) {
global $_menu;
// add the menu to the flat list of menu items:
......@@ -90,7 +95,13 @@ function menu_get_trail($path) {
$trail = array();
$mid = menu_get_active_item();
// Find the ID of the given path.
while ($path && !$menu['path index'][$path]) {
$path = substr($path, 0, strrpos($path, '/'));
}
$mid = $menu['path index'][$path];
// Follow the parents up the chain to get the trail.
while ($mid && $menu['items'][$mid]) {
array_unshift($trail, $mid);
$mid = $menu['items'][$mid]['pid'];
......@@ -171,9 +182,13 @@ function menu_get_active_breadcrumb() {
$links[] = l(t('Home'), '');
$trail = menu_get_trail($_GET['q']);
// The last item in the trail is the page title; don't display it here.
array_pop($trail);
foreach ($trail as $mid) {
// Don't show menu items without valid link targets.
if ($menu['items'][$mid]['path'] != '') {
// Don't show hidden menu items or items without valid link targets.
if (isset($menu['visible'][$mid]) && $menu['items'][$mid]['path'] != '') {
$links[] = _menu_render_item($mid);
}
}
......@@ -188,20 +203,26 @@ function menu_execute_active_handler() {
$menu = menu_get_menu();
$path = $_GET['q'];
while ($path && (!$menu['path index'][$path] || !$menu['items'][$menu['path index'][$path]]['callback'])) {
while ($path && (!$menu['path index'][$path] || $menu['items'][$menu['path index'][$path]]['callback'] === MENU_FALLTHROUGH)) {
$path = substr($path, 0, strrpos($path, '/'));
}
$mid = $menu['path index'][$path];
if ($menu['items'][$mid]['callback'] === MENU_DENIED) {
return MENU_DENIED;
}
if ($menu['items'][$mid]['callback']) {
if (is_string($menu['items'][$mid]['callback'])) {
$arg = substr($_GET['q'], strlen($menu['items'][$mid]['path']) + 1);
if (isset($arg)) {
return call_user_func_array($menu['items'][$mid]['callback'], explode('/', $arg));
call_user_func_array($menu['items'][$mid]['callback'], explode('/', $arg));
}
else {
return call_user_func($menu['items'][$mid]['callback']);
call_user_func($menu['items'][$mid]['callback']);
}
return MENU_FOUND;
}
return MENU_FALLTHROUGH;
}
/**
......@@ -211,11 +232,18 @@ function menu_active_handler_exists() {
$menu = menu_get_menu();
$path = $_GET['q'];
while ($path && (!$menu['path index'][$path] || !$menu['items'][$menu['path index'][$path]]['callback'])) {
while ($path && (!$menu['path index'][$path] || $menu['items'][$menu['path index'][$path]]['callback'] === MENU_FALLTHROUGH)) {
$path = substr($path, 0, strrpos($path, '/'));
}
$mid = $menu['path index'][$path];
if ($menu['items'][$mid]['callback'] === MENU_FALLTHROUGH) {
return FALSE;
}
if ($menu['items'][$mid]['callback'] === MENU_DENIED) {
return FALSE;
}
return function_exists($menu['items'][$mid]['callback']);
}
......@@ -298,7 +326,7 @@ function menu_build() {
while ($item = db_fetch_object($result)) {
// First, add any custom items added by the administrator.
if ($item->status == MENU_CUSTOM) {
$_menu['items'][$item->mid] = array('pid' => $item->pid, 'path' => $item->path, 'title' => $item->title, 'callback' => NULL, 'weight' => $item->weight, 'visibility' => MENU_SHOW, 'status' => MENU_CUSTOM);
$_menu['items'][$item->mid] = array('pid' => $item->pid, 'path' => $item->path, 'title' => $item->title, 'callback' => MENU_FALLTHROUGH, 'weight' => $item->weight, 'visibility' => MENU_SHOW, 'status' => MENU_CUSTOM);
$_menu['path index'][$item->path] = $item->mid;
}
// Don't display non-custom menu items if no module declared them.
......@@ -371,9 +399,12 @@ function menu_build_visible_tree($pid = 0) {
$children = array_merge($children, menu_build_visible_tree($mid));
}
}
if (($parent['visibility'] == MENU_SHOW) ||
($parent['visibility'] == MENU_HIDE_NOCHILD && count($children) > 1)) {
if ((($parent['visibility'] == MENU_SHOW) ||
($parent['visibility'] == MENU_HIDE_NOCHILD && count($children) > 1)) && $parent['callback'] !== MENU_DENIED) {
$_menu['visible'][$pid] = array('title' => $parent['title'], 'path' => $parent['path'], 'children' => $children);
foreach ($children as $mid) {
$_menu['visible'][$mid]['pid'] = $pid;
}
return array($pid);
}
else {
......
......@@ -7,11 +7,15 @@
fix_gpc_magic();
if (menu_active_handler_exists()) {
menu_execute_active_handler();
}
else {
drupal_not_found();
$status = menu_execute_active_handler();
switch ($status) {
case MENU_FOUND:
break;
case MENU_DENIED:
drupal_access_denied();
break;
default:
drupal_not_found();
}
drupal_page_footer();
......
......@@ -12,9 +12,12 @@ function admin_help($section) {
}
}
/**
* Implementation of hook_link().
*/
function admin_link($type) {
if ($type == "system" && user_access("access administration pages")) {
menu("admin", t("administer"), "admin_admin", 9);
if ($type == 'system') {
menu('admin', t('administer'), user_access('access administration pages') ? 'admin_admin' : MENU_DENIED, 9);
}
}
......
......@@ -85,27 +85,28 @@ function aggregator_perm() {
return array('administer news feeds', 'access news feeds');
}
/**
* Implementation of hook_link().
*/
function aggregator_link($type) {
if ($type == 'page' && user_access('access news feeds')) {
return array(l(t('news feeds'), 'aggregator', array('title' => t('Read the latest news from syndicated web sites.'))));
}
if ($type == 'system') {
if (user_access('administer news feeds')) {
menu('admin/syndication', t('syndication'), 'aggregator_help_page', 5);
menu('admin/syndication/news', t('RSS/RDF'), 'aggregator_admin');
menu('admin/syndication/news/add/feed', t('new feed'), 'aggregator_admin', 2);
menu('admin/syndication/news/add/bundle', t('new bundle'), 'aggregator_admin', 3);
menu('admin/syndication/news/tag', t('tag items'), 'aggregator_admin', 4);
menu('admin/syndication/news/help', t('help'), 'aggregator_help_page', 9);
}
if (user_access('access news feeds')) {
menu('aggregator', t('news aggregator'), 'aggregator_page', 5);
menu('aggregator/feeds', t('news by source'), 'aggregator_page');
menu('aggregator/bundles', t('news by topic'), 'aggregator_page');
menu('aggregator/sources', t('news sources'), 'aggregator_page');
}
$access = user_access('administer news feeds');
menu('admin/syndication', t('syndication'), $access ? 'aggregator_help_page' : MENU_DENIED, 5);
menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin' : MENU_DENIED);
menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin' : MENU_DENIED, 2);
menu('admin/syndication/news/add/bundle', t('new bundle'), $access ? 'aggregator_admin' : MENU_DENIED, 3);
menu('admin/syndication/news/tag', t('tag items'), $access ? 'aggregator_admin' : MENU_DENIED, 4);
menu('admin/syndication/news/help', t('help'), $access ? 'aggregator_help_page' : MENU_DENIED, 9);
$access = user_access('access news feeds');
menu('aggregator', t('news aggregator'), $access ? 'aggregator_page' : MENU_DENIED, 5);
menu('aggregator/feeds', t('news by source'), $access ? 'aggregator_page' : MENU_DENIED);
menu('aggregator/bundles', t('news by topic'), $access ? 'aggregator_page' : MENU_DENIED);
menu('aggregator/sources', t('news sources'), $access ? 'aggregator_page' : MENU_DENIED);
}
}
......
......@@ -85,27 +85,28 @@ function aggregator_perm() {
return array('administer news feeds', 'access news feeds');
}
/**
* Implementation of hook_link().
*/
function aggregator_link($type) {
if ($type == 'page' && user_access('access news feeds')) {
return array(l(t('news feeds'), 'aggregator', array('title' => t('Read the latest news from syndicated web sites.'))));
}
if ($type == 'system') {
if (user_access('administer news feeds')) {
menu('admin/syndication', t('syndication'), 'aggregator_help_page', 5);
menu('admin/syndication/news', t('RSS/RDF'), 'aggregator_admin');
menu('admin/syndication/news/add/feed', t('new feed'), 'aggregator_admin', 2);
menu('admin/syndication/news/add/bundle', t('new bundle'), 'aggregator_admin', 3);
menu('admin/syndication/news/tag', t('tag items'), 'aggregator_admin', 4);
menu('admin/syndication/news/help', t('help'), 'aggregator_help_page', 9);
}
if (user_access('access news feeds')) {
menu('aggregator', t('news aggregator'), 'aggregator_page', 5);
menu('aggregator/feeds', t('news by source'), 'aggregator_page');
menu('aggregator/bundles', t('news by topic'), 'aggregator_page');
menu('aggregator/sources', t('news sources'), 'aggregator_page');
}
$access = user_access('administer news feeds');
menu('admin/syndication', t('syndication'), $access ? 'aggregator_help_page' : MENU_DENIED, 5);
menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin' : MENU_DENIED);
menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin' : MENU_DENIED, 2);
menu('admin/syndication/news/add/bundle', t('new bundle'), $access ? 'aggregator_admin' : MENU_DENIED, 3);
menu('admin/syndication/news/tag', t('tag items'), $access ? 'aggregator_admin' : MENU_DENIED, 4);
menu('admin/syndication/news/help', t('help'), $access ? 'aggregator_help_page' : MENU_DENIED, 9);
$access = user_access('access news feeds');
menu('aggregator', t('news aggregator'), $access ? 'aggregator_page' : MENU_DENIED, 5);
menu('aggregator/feeds', t('news by source'), $access ? 'aggregator_page' : MENU_DENIED);
menu('aggregator/bundles', t('news by topic'), $access ? 'aggregator_page' : MENU_DENIED);
menu('aggregator/sources', t('news sources'), $access ? 'aggregator_page' : MENU_DENIED);
}
}
......
......@@ -182,18 +182,18 @@ function archive_block($op = "list", $delta = 0) {
}
}
/**
* Implementation of hook_link().
*/
function archive_link($type) {
$links = array();
if ($type == "page" && user_access("access content")) {
$links[] = l(t("archives"), "archive", array("title" => t("Read the older content in our archive.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('archives'), 'archive', array('title' => t('Read the older content in our archive.')));
}
if ($type == "system") {
if (user_access("access content")) {
menu("archive", t("archives"), "archive_page", 0, MENU_HIDE);
}
if ($type == 'system') {
menu('archive', t('archives'), user_access('access content') ? 'archive_page' : MENU_DENIED, 0, MENU_HIDE);
}
return $links;
......
......@@ -182,18 +182,18 @@ function archive_block($op = "list", $delta = 0) {
}
}
/**
* Implementation of hook_link().
*/
function archive_link($type) {
$links = array();
if ($type == "page" && user_access("access content")) {
$links[] = l(t("archives"), "archive", array("title" => t("Read the older content in our archive.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('archives'), 'archive', array('title' => t('Read the older content in our archive.')));
}
if ($type == "system") {
if (user_access("access content")) {
menu("archive", t("archives"), "archive_page", 0, MENU_HIDE);
}
if ($type == 'system') {
menu('archive', t('archives'), user_access('access content') ? 'archive_page' : MENU_DENIED, 0, MENU_HIDE);
}
return $links;
......
......@@ -61,13 +61,15 @@ function block_perm() {
return array("administer blocks");
}
/**
* Implementation of hook_link().
*/
function block_link($type) {
if ($type == "system" && user_access("administer blocks")) {
menu("admin/system/block", t("blocks"), "block_admin", 3);
menu("admin/system/block/add", t("new block"), "block_admin", 2);
menu("admin/system/block/preview", t("preview placement"), "block_admin", 3);
menu("admin/system/block/help", t("help"), "block_help_page", 9);
if ($type == 'system') {
menu('admin/system/block', t('blocks'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 2);
menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
menu('admin/system/block/help', t('help'), user_access('administer blocks') ? 'block_help_page' : MENU_DENIED, 9);
}
}
......
......@@ -61,13 +61,15 @@ function block_perm() {
return array("administer blocks");
}
/**
* Implementation of hook_link().
*/
function block_link($type) {
if ($type == "system" && user_access("administer blocks")) {
menu("admin/system/block", t("blocks"), "block_admin", 3);
menu("admin/system/block/add", t("new block"), "block_admin", 2);
menu("admin/system/block/preview", t("preview placement"), "block_admin", 3);
menu("admin/system/block/help", t("help"), "block_help_page", 9);
if ($type == 'system') {
menu('admin/system/block', t('blocks'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 2);
menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
menu('admin/system/block/help', t('help'), user_access('administer blocks') ? 'block_help_page' : MENU_DENIED, 9);
}
}
......
......@@ -211,31 +211,30 @@ function blog_view($node, $main = 0, $page = 0) {
return theme("node", $node, $main, $page);
}
/**
* Implementation of hook_link().
*/
function blog_link($type, $node = 0, $main) {
global $user;
$links = array();
if ($type == "system") {
if (user_access("maintain personal blog")) {
menu("node/add/blog", t("blog entry"), "node_page", 0);
menu("blog/". $user->uid, t("my blog"), "blog_page", 1, MENU_SHOW, MENU_LOCKED);
}
if (user_access("access content")) {
menu("blog", t("blogs"), "blog_page", 0, MENU_HIDE);
}
if ($type == 'system') {
menu('node/add/blog', t('blog entry'), user_access('maintain personal blog') ? 'node_page' : MENU_DENIED, 0);
menu('blog/'. $user->uid, t('my blog'), user_access('maintain personal blog') ? 'blog_page' : MENU_DENIED, 1, MENU_SHOW, MENU_LOCKED);
menu('blog', t('blogs'), user_access('access content') ? 'blog_page' : MENU_DENIED, 0, MENU_HIDE);
}
if ($type == "page" && user_access("access content")) {
$links[] = l(t("blogs"), "blog", array("title" => t("Read the latest blog entries.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('blogs'), 'blog', array('title' => t('Read the latest blog entries.')));
}
if ($type == "node" && $node->type == "blog") {
if (blog_access("update", $node)) {
$links[] = l(t("edit this blog entry"), "node/edit/$node->nid", array("title" => t("Edit this blog entry.")));
if ($type == 'node' && $node->type == 'blog') {
if (blog_access('update', $node)) {
$links[] = l(t('edit this blog entry'), "node/edit/$node->nid", array('title' => t('Edit this blog entry.')));
}
elseif (arg(0) != 'blog' && arg(1) != $node->uid) {
$links[] = l(t("%username's blog", array("%username" => $node->name)), "blog/$node->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $node->name))));
$links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
}
}
......
......@@ -211,31 +211,30 @@ function blog_view($node, $main = 0, $page = 0) {
return theme("node", $node, $main, $page);
}
/**
* Implementation of hook_link().
*/
function blog_link($type, $node = 0, $main) {
global $user;
$links = array();
if ($type == "system") {
if (user_access("maintain personal blog")) {
menu("node/add/blog", t("blog entry"), "node_page", 0);
menu("blog/". $user->uid, t("my blog"), "blog_page", 1, MENU_SHOW, MENU_LOCKED);
}
if (user_access("access content")) {
menu("blog", t("blogs"), "blog_page", 0, MENU_HIDE);
}
if ($type == 'system') {
menu('node/add/blog', t('blog entry'), user_access('maintain personal blog') ? 'node_page' : MENU_DENIED, 0);
menu('blog/'. $user->uid, t('my blog'), user_access('maintain personal blog') ? 'blog_page' : MENU_DENIED, 1, MENU_SHOW, MENU_LOCKED);
menu('blog', t('blogs'), user_access('access content') ? 'blog_page' : MENU_DENIED, 0, MENU_HIDE);
}
if ($type == "page" && user_access("access content")) {
$links[] = l(t("blogs"), "blog", array("title" => t("Read the latest blog entries.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('blogs'), 'blog', array('title' => t('Read the latest blog entries.')));
}
if ($type == "node" && $node->type == "blog") {
if (blog_access("update", $node)) {
$links[] = l(t("edit this blog entry"), "node/edit/$node->nid", array("title" => t("Edit this blog entry.")));
if ($type == 'node' && $node->type == 'blog') {
if (blog_access('update', $node)) {
$links[] = l(t('edit this blog entry'), "node/edit/$node->nid", array('title' => t('Edit this blog entry.')));
}
elseif (arg(0) != 'blog' && arg(1) != $node->uid) {
$links[] = l(t("%username's blog", array("%username" => $node->name)), "blog/$node->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $node->name))));
$links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
}
}
......
......@@ -47,40 +47,38 @@ function book_access($op, $node) {
}
}
/**
* Implementation of hook_link().
*/
function book_link($type, $node = 0, $main = 0) {
$links = array();
if ($type == "page" && user_access("access content")) {
$links[] = l(t("books"), "book", array("title" => t("Read and contribute to the collaborative books.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('books'), 'book', array('title' => t('Read and contribute to the collaborative books.')));
}
if ($type == "node" && $node->type == "book") {
if (book_access("update", $node)) {
$links[] = l(t("edit this page"), "node/edit/$node->nid", array("title" => t("Suggest an update for this book page.")));
if ($type == 'node' && $node->type == 'book') {
if (book_access('update', $node)) {
$links[] = l(t('edit this page'), "node/edit/$node->nid", array('title' => t('Suggest an update for this book page.')));
}
if (!$main) {
$links[] = l(t("printer-friendly version"), "book/print/$node->nid", array("title" => t("Show a printer-friendly version of this book page and its sub-pages.")));
$links[] = l(t('printer-friendly version'), "book/print/$node->nid", array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
}
}
if ($type == "system") {
if (user_access("maintain books")) {
menu("node/add/book", t("book page"), "node_page", 0);
}
if (user_access("administer nodes")) {
menu("admin/node/book", t("books"), "book_admin", 4);
menu("admin/node/book/orphan", t("orphan pages"), "book_admin_orphan", 8);
menu("admin/node/book/help", t("help"), "book_help_page", 9);
if ($type == 'system') {
menu('node/add/book', t('book page'), user_access('maintain books') ? 'node_page' : MENU_DENIED, 0);
$result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title");
while ($book = db_fetch_object($result)) {
menu("admin/node/book/$book->nid", t("'%title' book", array("%title" => $book->title)), "book_admin");
}
}
if (user_access("access content")) {
menu("book", t("books"), "book_page", 0, MENU_HIDE);
menu('admin/node/book', t('books'), user_access('administer nodes') ? 'book_admin' : MENU_DENIED, 4);
menu('admin/node/book/orphan', t('orphan pages'), user_access('administer nodes') ? 'book_admin_orphan' : MENU_DENIED, 8);
menu('admin/node/book/help', t('help'), user_access('administer nodes') ? 'book_help_page' : MENU_DENIED, 9);
$result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title");
while ($book = db_fetch_object($result)) {
menu("admin/node/book/$book->nid", t('"%title" book', array('%title' => $book->title)), user_access('administer nodes') ? 'book_admin' : MENU_DENIED);
}
menu('book', t('books'), user_access('access content') ? 'book_page' : MENU_DENIED, 0, MENU_HIDE);
}
return $links;
......@@ -677,7 +675,7 @@ function book_page() {
}
}
else {
print theme("page", message_access());
drupal_access_denied();
}
}
......
......@@ -47,40 +47,38 @@ function book_access($op, $node) {
}
}
/**
* Implementation of hook_link().
*/
function book_link($type, $node = 0, $main = 0) {
$links = array();
if ($type == "page" && user_access("access content")) {
$links[] = l(t("books"), "book", array("title" => t("Read and contribute to the collaborative books.")));
if ($type == 'page' && user_access('access content')) {
$links[] = l(t('books'), 'book', array('title' => t('Read and contribute to the collaborative books.')));
}
if ($type == "node" && $node->type == "book") {
if (book_access("update", $node)) {
$links[] = l(t("edit this page"), "node/edit/$node->nid", array("title" => t("Suggest an update for this book page.")));
if ($type == 'node' && $node->type == 'book') {
if (book_access('update', $node)) {
$links[] = l(t('edit this page'), "node/edit/$node->nid", array('title' => t('Suggest an update for this book page.')));
}
if (!$main) {
$links[] = l(t("printer-friendly version"), "book/print/$node->nid", array("title" => t("Show a printer-friendly version of this book page and its sub-pages.")));
$links[] = l(t('printer-friendly version'), "book/print/$node->nid", array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
}
}
if ($type == "system") {
if (user_access("maintain books")) {
menu("node/add/book", t("book page"), "node_page", 0);
}
if (user_access("administer nodes")) {
menu("admin/node/book", t("books"), "book_admin", 4);
menu("admin/node/book/orphan", t("orphan pages"), "book_admin_orphan", 8);
menu("admin/node/book/help", t("help"), "book_help_page", 9);
if ($type == 'system') {
menu('node/add/book', t('book page'), user_access('maintain books') ? 'node_page' : MENU_DENIED, 0);
$result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title");
while ($book = db_fetch_object($result)) {
menu("admin/node/book/$book->nid", t("'%title' book", array("%title" => $book->title)), "book_admin");
}
}
if (user_access("access content")) {
menu("book", t("books"),<