- Patch #27999 by Tobias: made book export functionality configurable.

4.7.x
Dries Buytaert 2005-10-08 14:48:33 +00:00
parent 5a4fa43602
commit 6f30f02c16
2 changed files with 98 additions and 60 deletions

View File

@ -17,7 +17,7 @@ function book_node_info() {
* Implementation of hook_perm(). * Implementation of hook_perm().
*/ */
function book_perm() { function book_perm() {
return array('create book pages', 'maintain books', 'edit own book pages'); return array('create book pages', 'maintain books', 'edit own book pages', 'export books', 'see printer-friendly version');
} }
/** /**
@ -60,11 +60,15 @@ function book_link($type, $node = 0, $main = 0) {
if (book_access('create', $node)) { if (book_access('create', $node)) {
$links[] = l(t('add child page'), "node/add/book/parent/$node->nid"); $links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
} }
if (user_access('see printer-friendly version')) {
$links[] = l(t('printer-friendly version'), 'book/export/html/'. $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/export/html/'. $node->nid, array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
}
if (user_access('export books')) {
$links[] = l(t('export DocBook XML'), 'book/export/docbook/'. $node->nid, array('title' => t('Export this book page and its sub-pages as DocBook XML.'))); $links[] = l(t('export DocBook XML'), 'book/export/docbook/'. $node->nid, array('title' => t('Export this book page and its sub-pages as DocBook XML.')));
$links[] = l(t('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.'))); $links[] = l(t('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.')));
} }
} }
}
return $links; return $links;
} }
@ -110,7 +114,7 @@ function book_menu($may_cache) {
$items[] = array( $items[] = array(
'path' => 'book/export', 'path' => 'book/export',
'callback' => 'book_export', 'callback' => 'book_export',
'access' => user_access('access content'), 'access' => (user_access('export books') || user_access('see printer-friendly version')) && user_access('access content'),
'type' => MENU_CALLBACK); 'type' => MENU_CALLBACK);
} }
else { else {
@ -664,13 +668,19 @@ function book_export($type = 'html', $nid = FALSE) {
$depth = _book_get_depth($nid); $depth = _book_get_depth($nid);
switch ($type) { switch ($type) {
case 'docbook': case 'docbook':
if (user_access('export books')) {
$xml = "<?xml version='1.0'?>\n"; $xml = "<?xml version='1.0'?>\n";
$xml .= "<!DOCTYPE book PUBLIC \"-//OASIS//DTD Docbook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n"; $xml .= "<!DOCTYPE book PUBLIC \"-//OASIS//DTD Docbook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n";
$xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post'); $xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post');
drupal_set_header('Content-Type: text/xml; charset=utf-8'); drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $xml; print $xml;
}
else {
drupal_access_denied();
}
break; break;
case 'html': case 'html':
if (user_access('see printer-friendly version')) {
for ($i = 1; $i < $depth; $i++) { for ($i = 1; $i < $depth; $i++) {
$output .= "<div class=\"section-$i\">\n"; $output .= "<div class=\"section-$i\">\n";
} }
@ -686,15 +696,24 @@ function book_export($type = 'html', $nid = FALSE) {
$html .= "<style type=\"text/css\">\n@import url(misc/print.css);\n</style>\n"; $html .= "<style type=\"text/css\">\n@import url(misc/print.css);\n</style>\n";
$html .= "</head>\n<body>\n". $output . "\n</body>\n</html>\n"; $html .= "</head>\n<body>\n". $output . "\n</body>\n</html>\n";
print $html; print $html;
}
else {
drupal_access_denied();
}
break; break;
case 'opml': case 'opml':
if (user_access('export books')) {
$output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post'); $output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
$ompl = "<?xml version='1.0'?>\n"; $opml = "<?xml version='1.0'?>\n";
$opml .= "<opml version='1.0'>\n"; $opml .= "<opml version='1.0'>\n";
$opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n"; $opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n"; $opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $opml; print $opml;
}
else {
drupal_access_denied();
}
break; break;
default: default:
drupal_not_found(); drupal_not_found();

View File

@ -17,7 +17,7 @@ function book_node_info() {
* Implementation of hook_perm(). * Implementation of hook_perm().
*/ */
function book_perm() { function book_perm() {
return array('create book pages', 'maintain books', 'edit own book pages'); return array('create book pages', 'maintain books', 'edit own book pages', 'export books', 'see printer-friendly version');
} }
/** /**
@ -60,11 +60,15 @@ function book_link($type, $node = 0, $main = 0) {
if (book_access('create', $node)) { if (book_access('create', $node)) {
$links[] = l(t('add child page'), "node/add/book/parent/$node->nid"); $links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
} }
if (user_access('see printer-friendly version')) {
$links[] = l(t('printer-friendly version'), 'book/export/html/'. $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/export/html/'. $node->nid, array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
}
if (user_access('export books')) {
$links[] = l(t('export DocBook XML'), 'book/export/docbook/'. $node->nid, array('title' => t('Export this book page and its sub-pages as DocBook XML.'))); $links[] = l(t('export DocBook XML'), 'book/export/docbook/'. $node->nid, array('title' => t('Export this book page and its sub-pages as DocBook XML.')));
$links[] = l(t('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.'))); $links[] = l(t('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.')));
} }
} }
}
return $links; return $links;
} }
@ -110,7 +114,7 @@ function book_menu($may_cache) {
$items[] = array( $items[] = array(
'path' => 'book/export', 'path' => 'book/export',
'callback' => 'book_export', 'callback' => 'book_export',
'access' => user_access('access content'), 'access' => (user_access('export books') || user_access('see printer-friendly version')) && user_access('access content'),
'type' => MENU_CALLBACK); 'type' => MENU_CALLBACK);
} }
else { else {
@ -664,13 +668,19 @@ function book_export($type = 'html', $nid = FALSE) {
$depth = _book_get_depth($nid); $depth = _book_get_depth($nid);
switch ($type) { switch ($type) {
case 'docbook': case 'docbook':
if (user_access('export books')) {
$xml = "<?xml version='1.0'?>\n"; $xml = "<?xml version='1.0'?>\n";
$xml .= "<!DOCTYPE book PUBLIC \"-//OASIS//DTD Docbook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n"; $xml .= "<!DOCTYPE book PUBLIC \"-//OASIS//DTD Docbook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n";
$xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post'); $xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post');
drupal_set_header('Content-Type: text/xml; charset=utf-8'); drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $xml; print $xml;
}
else {
drupal_access_denied();
}
break; break;
case 'html': case 'html':
if (user_access('see printer-friendly version')) {
for ($i = 1; $i < $depth; $i++) { for ($i = 1; $i < $depth; $i++) {
$output .= "<div class=\"section-$i\">\n"; $output .= "<div class=\"section-$i\">\n";
} }
@ -686,15 +696,24 @@ function book_export($type = 'html', $nid = FALSE) {
$html .= "<style type=\"text/css\">\n@import url(misc/print.css);\n</style>\n"; $html .= "<style type=\"text/css\">\n@import url(misc/print.css);\n</style>\n";
$html .= "</head>\n<body>\n". $output . "\n</body>\n</html>\n"; $html .= "</head>\n<body>\n". $output . "\n</body>\n</html>\n";
print $html; print $html;
}
else {
drupal_access_denied();
}
break; break;
case 'opml': case 'opml':
if (user_access('export books')) {
$output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post'); $output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
$ompl = "<?xml version='1.0'?>\n"; $opml = "<?xml version='1.0'?>\n";
$opml .= "<opml version='1.0'>\n"; $opml .= "<opml version='1.0'>\n";
$opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n"; $opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n"; $opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $opml; print $opml;
}
else {
drupal_access_denied();
}
break; break;
default: default:
drupal_not_found(); drupal_not_found();