- 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,9 +60,13 @@ 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");
} }
$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('see printer-friendly version')) {
$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('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('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.'))); }
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 OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.')));
}
} }
} }
@ -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,37 +668,52 @@ 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':
$xml = "<?xml version='1.0'?>\n"; if (user_access('export books')) {
$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 = "<?xml version='1.0'?>\n";
$xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post'); $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";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); $xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post');
print $xml; drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $xml;
}
else {
drupal_access_denied();
}
break; break;
case 'html': case 'html':
for ($i = 1; $i < $depth; $i++) { if (user_access('see printer-friendly version')) {
$output .= "<div class=\"section-$i\">\n"; for ($i = 1; $i < $depth; $i++) {
$output .= "<div class=\"section-$i\">\n";
}
$output .= book_recurse($nid, $depth, 'book_node_visitor_html_pre', 'book_node_visitor_html_post');
for ($i = 1; $i < $depth; $i++) {
$output .= "</div>\n";
}
$html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
$html .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<base href="'. $base_url .'/" />' . "\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";
print $html;
} }
$output .= book_recurse($nid, $depth, 'book_node_visitor_html_pre', 'book_node_visitor_html_post'); else {
for ($i = 1; $i < $depth; $i++) { drupal_access_denied();
$output .= "</div>\n";
} }
$html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
$html .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<base href="'. $base_url .'/" />' . "\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";
print $html;
break; break;
case 'opml': case 'opml':
$output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post'); if (user_access('export books')) {
$ompl = "<?xml version='1.0'?>\n"; $output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
$opml .= "<opml version='1.0'>\n"; $opml = "<?xml version='1.0'?>\n";
$opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n"; $opml .= "<opml version='1.0'>\n";
$opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n"; $opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); $opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
print $opml; drupal_set_header('Content-Type: text/xml; charset=utf-8');
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,9 +60,13 @@ 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");
} }
$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('see printer-friendly version')) {
$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('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('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.'))); }
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 OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.')));
}
} }
} }
@ -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,37 +668,52 @@ 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':
$xml = "<?xml version='1.0'?>\n"; if (user_access('export books')) {
$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 = "<?xml version='1.0'?>\n";
$xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post'); $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";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); $xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post');
print $xml; drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $xml;
}
else {
drupal_access_denied();
}
break; break;
case 'html': case 'html':
for ($i = 1; $i < $depth; $i++) { if (user_access('see printer-friendly version')) {
$output .= "<div class=\"section-$i\">\n"; for ($i = 1; $i < $depth; $i++) {
$output .= "<div class=\"section-$i\">\n";
}
$output .= book_recurse($nid, $depth, 'book_node_visitor_html_pre', 'book_node_visitor_html_post');
for ($i = 1; $i < $depth; $i++) {
$output .= "</div>\n";
}
$html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
$html .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<base href="'. $base_url .'/" />' . "\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";
print $html;
} }
$output .= book_recurse($nid, $depth, 'book_node_visitor_html_pre', 'book_node_visitor_html_post'); else {
for ($i = 1; $i < $depth; $i++) { drupal_access_denied();
$output .= "</div>\n";
} }
$html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
$html .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<base href="'. $base_url .'/" />' . "\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";
print $html;
break; break;
case 'opml': case 'opml':
$output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post'); if (user_access('export books')) {
$ompl = "<?xml version='1.0'?>\n"; $output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
$opml .= "<opml version='1.0'>\n"; $opml = "<?xml version='1.0'?>\n";
$opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n"; $opml .= "<opml version='1.0'>\n";
$opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n"; $opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
drupal_set_header('Content-Type: text/xml; charset=utf-8'); $opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
print $opml; drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $opml;
}
else {
drupal_access_denied();
}
break; break;
default: default:
drupal_not_found(); drupal_not_found();