Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
75a6f4de
Commit
75a6f4de
authored
Nov 04, 2007
by
Gábor Hojtsy
Browse files
#160200
by dvessel and chx: better theming support for book module
parent
98a5fb14
Changes
6
Hide whitespace changes
Inline
Side-by-side
modules/book/book-all-books-block.tpl.php
0 → 100644
View file @
75a6f4de
<?php
// $Id$
/**
* @file book-all-books-block.tpl.php
* Default theme implementation for rendering book outlines within a block.
* This template is used only when the block is configured to "show block on
* all pages" which presents Multiple independent books on all pages.
*
* Available variables:
* - $book_menus: Array of book outlines rendered as an unordered list. It is
* keyed to the parent book ID which is also the ID of the parent node
* containing an entire outline.
*
* @see template_preprocess_book_all_books_block()
*/
?>
<?php
foreach
(
$book_menus
as
$book_id
=>
$menu
)
:
?>
<div
id=
"book-block-menu-
<?php
print
$book_id
;
?>
"
class=
"book-block-menu"
>
<?php
print
$menu
;
?>
</div>
<?php
endforeach
;
?>
modules/book/book-export-html.tpl.php
0 → 100644
View file @
75a6f4de
<?php
// $Id$
/**
* @file book-export-html.tpl.php
* Default theme implementation for printed version of book outline.
*
* Available variables:
* - $title: Top level node title.
* - $head: Header tags.
* - $language: Language code. e.g. "en" for english.
* - $language_rtl: TRUE or FALSE depending on right to left language scripts.
* - $base_url: URL to home page.
* - $content: Nodes within the current outline rendered through
* book-node-export-html.tpl.php.
*
* @see template_preprocess_book_export_html()
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"
<?php
print
$language
->
language
;
?>
"
xml:lang=
"
<?php
print
$language
->
language
;
?>
"
>
<head>
<title>
<?php
print
$title
;
?>
</title>
<?php
print
$head
;
?>
<base
href=
"
<?php
print
$base_url
;
?>
"
/>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"misc/print.css"
/>
<?php
if
(
$language_rtl
)
:
?>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"misc/print-rtl.css"
/>
<?php
endif
;
?>
</head>
<body>
<?php
/**
* The given node is /embedded to its absolute depth in a top level
* section/. For example, a child node with depth 2 in the hierarchy is
* contained in (otherwise empty) <div> elements corresponding to
* depth 0 and depth 1. This is intended to support WYSIWYG output - e.g.,
* level 3 sections always look like level 3 sections, no matter their
* depth relative to the node selected to be exported as printer-friendly
* HTML.
*/
$div_close
=
''
;
?>
<?php
for
(
$i
=
1
;
$i
<
$depth
;
$i
++
)
:
?>
<div
class=
"section-
<?php
print
$i
;
?>
"
>
<?php
$div_close
.
=
'</div>'
;
?>
<?php
endfor
;
?>
<?php
print
$contents
;
?>
<?php
print
$div_close
;
?>
</body>
</html>
modules/book/book-navigation.tpl.php
0 → 100644
View file @
75a6f4de
<?php
// $Id$
/**
* @file book-navigation.tpl.php
* Default theme implementation to navigate books. Presented under nodes that
* are a part of book outlines.
*
* Available variables:
* - $tree: The immediate children of the current node rendered as an
* unordered list.
* - $current_depth: Depth of the current node within the book outline.
* Provided for context.
* - $prev_url: URL to the previous node.
* - $prev_title: Title of the previous node.
* - $parent_url: URL to the parent node.
* - $parent_title: Title of the parent node. Not printed by default. Provided
* as an option.
* - $next_url: URL to the next node.
* - $next_title: Title of the next node.
* - $has_links: Flags TRUE whenever the previous, parent or next data has a
* value.
* - $book_id: The book ID of the current outline being viewed. Same as the
* node ID containing the entire outline. Provided for context.
* - $book_url: The book/node URL of the current outline being viewed.
* Provided as an option. Not used by default.
* - $book_title: The book/node title of the current outline being viewed.
* Provided as an option. Not used by default.
*
* @see template_preprocess_book_navigation()
*/
?>
<?php
if
(
$tree
||
$has_links
)
:
?>
<div
id=
"book-navigation-
<?php
print
$book_id
;
?>
"
class=
"book-navigation"
>
<?php
print
$tree
;
?>
<?php
if
(
$has_links
)
:
?>
<div
class=
"page-links clear-block"
>
<?php
if
(
$prev_url
)
:
?>
<a
href=
"
<?php
print
$prev_url
;
?>
"
class=
"page-previous"
title=
"
<?php
print
t
(
'Go to previous page'
);
?>
"
>
<?php
print
t
(
'‹ '
)
.
$prev_title
;
?>
</a>
<?php
endif
;
?>
<?php
if
(
$parent_url
)
:
?>
<a
href=
"
<?php
print
$parent_url
;
?>
"
class=
"page-up"
title=
"
<?php
print
t
(
'Go to parent page'
);
?>
"
>
<?php
print
t
(
'up'
);
?>
</a>
<?php
endif
;
?>
<?php
if
(
$next_url
)
:
?>
<a
href=
"
<?php
print
$next_url
;
?>
"
class=
"page-next"
title=
"
<?php
print
t
(
'Go to next page'
);
?>
"
>
<?php
print
$next_title
.
t
(
' ›'
);
?>
</a>
<?php
endif
;
?>
</div>
<?php
endif
;
?>
</div>
<?php
endif
;
?>
modules/book/book-node-export-html.tpl.php
0 → 100644
View file @
75a6f4de
<?php
// $Id$
/**
* @file book-node-export-html.tpl.php
* Default theme implementation for rendering a single node in a printer
* friendly outline.
*
* @see book-node-export-html.tpl.php
* Where it is collected and printed out.
*
* Available variables:
* - $depth: Depth of the current node inside the outline.
* - $title: Node title.
* - $content: Node content.
* - $children: All the child nodes recursively rendered through this file.
*
* @see template_preprocess_book_node_export_html()
*/
?>
<div
id=
"node-
<?php
print
$node
->
nid
;
?>
"
class=
"section-
<?php
print
$depth
;
?>
"
>
<h1
class=
"book-heading"
>
<?php
print
$title
;
?>
</h1>
<?php
print
$content
;
?>
<?php
print
$children
;
?>
</div>
modules/book/book.module
View file @
75a6f4de
...
...
@@ -13,10 +13,11 @@ function book_theme() {
return
array
(
'book_navigation'
=>
array
(
'arguments'
=>
array
(
'book_link'
=>
NULL
),
'template'
=>
'book-navigation'
,
),
'book_export_html'
=>
array
(
'arguments'
=>
array
(
'title'
=>
NULL
,
'content'
=>
NULL
),
'
fil
e'
=>
'book
.pages.inc
'
,
'arguments'
=>
array
(
'title'
=>
NULL
,
'content
s'
=>
NULL
,
'depth
'
=>
NULL
),
'
templat
e'
=>
'book
-export-html
'
,
),
'book_admin_table'
=>
array
(
'arguments'
=>
array
(
'form'
=>
NULL
),
...
...
@@ -26,6 +27,11 @@ function book_theme() {
),
'book_all_books_block'
=>
array
(
'arguments'
=>
array
(
'book_menus'
=>
array
()),
'template'
=>
'book-all-books-block'
,
),
'book_node_export_html'
=>
array
(
'arguments'
=>
array
(
'node'
=>
NULL
,
'children'
=>
NULL
),
'template'
=>
'book-node-export-html'
,
),
);
}
...
...
@@ -191,18 +197,18 @@ function book_block($op = 'list', $delta = 0, $edit = array()) {
$block
[
'subject'
]
=
t
(
'Book navigation'
);
$book_menus
=
array
();
$pseudo_tree
=
array
(
0
=>
array
(
'below'
=>
FALSE
));
foreach
(
book_get_books
()
as
$book
)
{
foreach
(
book_get_books
()
as
$book_id
=>
$book
)
{
if
(
$book
[
'bid'
]
==
$current_bid
)
{
// If the current page is a node associated with a book, the menu
// needs to be retrieved.
$book_menus
[]
=
menu_tree_output
(
menu_tree_all_data
(
$node
->
book
[
'menu_name'
],
$node
->
book
));
$book_menus
[
$book_id
]
=
menu_tree_output
(
menu_tree_all_data
(
$node
->
book
[
'menu_name'
],
$node
->
book
));
}
else
{
// Since we know we will only display a link to the top node, there
// is no reason to run an additional menu tree query for each book.
$book
[
'in_active_trail'
]
=
FALSE
;
$pseudo_tree
[
0
][
'link'
]
=
$book
;
$book_menus
[]
=
menu_tree_output
(
$pseudo_tree
);
$book_menus
[
$book_id
]
=
menu_tree_output
(
$pseudo_tree
);
}
}
$block
[
'content'
]
=
theme
(
'book_all_books_block'
,
$book_menus
);
...
...
@@ -239,19 +245,6 @@ function book_block($op = 'list', $delta = 0, $edit = array()) {
}
}
/**
* Generate the HTML output for the block showing all book menus.
*
* @ingroup themeable
*/
function
theme_book_all_books_block
(
$book_menus
)
{
$output
=
''
;
foreach
(
$book_menus
as
$menu
)
{
$output
.
=
'<div class="book-block-menu">'
.
$menu
.
"</div>
\n
"
;
}
return
$output
;
}
/**
* Generate the HTML output for a link to a book title when used as a block title.
*
...
...
@@ -283,7 +276,7 @@ function book_get_books() {
while
(
$link
=
db_fetch_array
(
$result2
))
{
$link
[
'href'
]
=
$link
[
'link_path'
];
$link
[
'options'
]
=
unserialize
(
$link
[
'options'
]);
$all_books
[]
=
$link
;
$all_books
[
$link
[
'bid'
]
]
=
$link
;
}
}
}
...
...
@@ -782,46 +775,59 @@ function _book_link_defaults($nid) {
}
/**
* Pr
epares the links to the children of the page and the previous/up/next
navigation.
* Pr
ocess variables for book-
navigation.
tpl.php.
*
* The
se navigation elements are added to the content of a node
in the
book
*
outline when it is viewed as a page and in similar contexts.
* The
$variables array conta
in
s
the
following arguments:
*
- $book_link
*
* @
ingroup themeable
* @
see book-navigation.tpl.php
*/
function
theme_book_navigation
(
$book_link
)
{
$output
=
''
;
$links
=
''
;
function
template_preprocess_book_navigation
(
&
$variables
)
{
$book_link
=
$variables
[
'book_link'
];
// Provide extra variables for themers. Not needed by default.
$variables
[
'book_id'
]
=
$book_link
[
'bid'
];
$variables
[
'book_title'
]
=
check_plain
(
$book_link
[
'link_title'
]);
$variables
[
'book_url'
]
=
'node/'
.
$book_link
[
'bid'
];
$variables
[
'current_depth'
]
=
$book_link
[
'depth'
];
$variables
[
'tree'
]
=
''
;
if
(
$book_link
[
'mlid'
])
{
$tree
=
book_children
(
$book_link
);
$
variables
[
'
tree
'
]
=
book_children
(
$book_link
);
if
(
$prev
=
book_prev
(
$book_link
))
{
drupal_add_link
(
array
(
'rel'
=>
'prev'
,
'href'
=>
url
(
$prev
[
'href'
])));
$links
.
=
l
(
t
(
'‹ '
)
.
$prev
[
'title'
],
$prev
[
'href'
],
array
(
'attributes'
=>
array
(
'class'
=>
'page-previous'
,
'title'
=>
t
(
'Go to previous page'
))));
$prev_href
=
url
(
$prev
[
'href'
]);
drupal_add_link
(
array
(
'rel'
=>
'prev'
,
'href'
=>
$prev_href
));
$variables
[
'prev_url'
]
=
$prev_href
;
$variables
[
'prev_title'
]
=
check_plain
(
$prev
[
'title'
]);
}
if
(
$book_link
[
'plid'
]
&&
$parent
=
book_link_load
(
$book_link
[
'plid'
]))
{
drupal_add_link
(
array
(
'rel'
=>
'up'
,
'href'
=>
url
(
$parent
[
'href'
])));
$links
.
=
l
(
t
(
'up'
),
$parent
[
'href'
],
array
(
'attributes'
=>
array
(
'class'
=>
'page-up'
,
'title'
=>
t
(
'Go to parent page'
))));
$parent_href
=
url
(
$parent
[
'href'
]);
drupal_add_link
(
array
(
'rel'
=>
'up'
,
'href'
=>
$parent_href
));
$variables
[
'parent_url'
]
=
$parent_href
;
$variables
[
'parent_title'
]
=
check_plain
(
$parent
[
'title'
]);
}
if
(
$next
=
book_next
(
$book_link
))
{
drupal_add_link
(
array
(
'rel'
=>
'next'
,
'href'
=>
url
(
$next
[
'href'
])));
$links
.
=
l
(
$next
[
'title'
]
.
t
(
' ›'
),
$next
[
'href'
],
array
(
'attributes'
=>
array
(
'class'
=>
'page-next'
,
'title'
=>
t
(
'Go to next page'
))));
$next_href
=
url
(
$next
[
'href'
]);
drupal_add_link
(
array
(
'rel'
=>
'next'
,
'href'
=>
$next_href
));
$variables
[
'next_url'
]
=
$next_href
;
$variables
[
'next_title'
]
=
check_plain
(
$next
[
'title'
]);
}
}
if
(
isset
(
$tree
)
||
isset
(
$links
))
{
$output
=
'<div class="book-navigation">'
;
if
(
isset
(
$tree
))
{
$output
.
=
$tree
;
}
if
(
isset
(
$links
))
{
$output
.
=
'<div class="page-links clear-block">'
.
$links
.
'</div>'
;
}
$output
.
=
'</div>'
;
$variables
[
'has_links'
]
=
FALSE
;
// Link variables to filter for values and set state of the flag variable.
$links
=
array
(
'prev_url'
,
'prev_title'
,
'parent_url'
,
'parent_title'
,
'next_url'
,
'next_title'
);
foreach
(
$links
as
$link
)
{
if
(
isset
(
$variables
[
$link
]))
{
// Flag when there is a value.
$variables
[
'has_links'
]
=
TRUE
;
}
else
{
// Set empty to prevent notices.
$variables
[
$link
]
=
''
;
}
}
return
$output
;
}
/**
...
...
@@ -864,51 +870,57 @@ function book_toc($bid, $exclude = array(), $depth_limit) {
return
$toc
;
}
/**
* Process variables for book-export-html.tpl.php.
*
* The $variables array contains the following arguments:
* - $title
* - $contents
* - $depth
*
* @see book-export-html.tpl.php
*/
function
template_preprocess_book_export_html
(
&
$variables
)
{
global
$base_url
,
$language
;
$variables
[
'title'
]
=
check_plain
(
$variables
[
'title'
]);
$variables
[
'base_url'
]
=
$base_url
;
$variables
[
'language'
]
=
$language
;
$variables
[
'language_rtl'
]
=
(
defined
(
'LANGUAGE_RTL'
)
&&
$language
->
direction
==
LANGUAGE_RTL
)
?
TRUE
:
FALSE
;
$variables
[
'head'
]
=
drupal_get_html_head
();
}
/**
* Traverse the book tree to build printable or exportable output.
*
* During the traversal, the $visit_
pre
() callback is applied to each
* During the traversal, the $visit_
func
() callback is applied to each
* node, and is called recursively for each child of the node (in weight,
* title order). Finally, the output of the $visit_post() callback is
* appended before returning the generated output.
* title order).
*
* @param $tree
* A subtree of the book menu hierarchy, rooted at the current page.
* @param $visit_
pre
* @param $visit_
func
* A function callback to be called upon visiting a node in the tree.
* @param $visit_post
* A function callback to be called after visiting a node in the tree,
* but before recursively visiting children.
* @return
* The output generated in visiting each node.
*/
function
book_export_traverse
(
$tree
,
$visit_
pre
,
$visit_post
)
{
function
book_export_traverse
(
$tree
,
$visit_
func
)
{
$output
=
''
;
foreach
(
$tree
as
$data
)
{
// Note- access checking is already performed when building the tree.
$node
=
node_load
(
$data
[
'link'
][
'nid'
],
FALSE
);
if
(
$node
)
{
$depth
=
$node
->
book
[
'depth'
];
if
(
function_exists
(
$visit_pre
))
{
$output
.
=
call_user_func
(
$visit_pre
,
$node
,
$depth
);
}
else
{
// Use the default function.
$output
.
=
book_node_visitor_html_pre
(
$node
,
$depth
);
}
if
(
$node
=
node_load
(
$data
[
'link'
][
'nid'
],
FALSE
))
{
$children
=
''
;
if
(
$data
[
'below'
])
{
$
output
.
=
book_export_traverse
(
$data
[
'below'
],
$visit_
pre
,
$visit_post
);
$
children
=
book_export_traverse
(
$data
[
'below'
],
$visit_
func
);
}
if
(
function_exists
(
$visit_
post
))
{
$output
.
=
call_user_func
(
$visit_
post
,
$node
,
$
depth
);
if
(
function_exists
(
$visit_
func
))
{
$output
.
=
call_user_func
(
$visit_
func
,
$node
,
$
children
);
}
else
{
// Use the default function.
$output
.
=
book_node_
visitor_html_
po
s
t
(
$node
,
$
depth
);
$output
.
=
book_node_
ex
po
r
t
(
$node
,
$
children
);
}
}
}
...
...
@@ -918,47 +930,37 @@ function book_export_traverse($tree, $visit_pre, $visit_post) {
/**
* Generates printer-friendly HTML for a node.
*
* This function is a 'pre-node' visitor function.
*
* @see book_export_traverse().
*
* @param $node
* The node to generate output for.
* @param $depth
* The depth of the given node in the hierarchy. This
* is used only for generating output.
* @param $children
* All the rendered child nodes within the current node.
* @return
* The HTML generated for the given node.
*/
function
book_node_
visitor_html_pre
(
$node
,
$depth
)
{
function
book_node_
export
(
$node
,
$children
=
''
)
{
$node
->
build_mode
=
NODE_BUILD_PRINT
;
$node
=
node_build_content
(
$node
,
FALSE
,
FALSE
);
$node
->
body
=
drupal_render
(
$node
->
content
);
$output
=
"<div id=
\"
node-"
.
$node
->
nid
.
"
\"
class=
\"
section-
$depth
\"
>
\n
"
;
$output
.
=
"<h1 class=
\"
book-heading
\"
>"
.
check_plain
(
$node
->
title
)
.
"</h1>
\n
"
;
$output
.
=
drupal_render
(
$node
->
content
);
return
$output
;
return
theme
(
'book_node_export_html'
,
$node
,
$children
);
}
/**
*
Finishes up generation of printer-friendly HTML after visiting a node
.
*
Process variables for book-node-export-html.tpl.php
.
*
* This function is a 'post-node' visitor function.
* The $variables array contains the following arguments:
* - $node
* - $children
*
* @see book_export_traverse().
*
* @param $node
* The node to generate output for.
* @param $depth
* The depth of the given node in the hierarchy. This
* is used only for generating output.
* @return
* The HTML appended after the given node.
* @see book-node-export-html.tpl.php
*/
function
book_node_visitor_html_post
(
$node
,
$depth
)
{
return
"</div>
\n
"
;
function
template_preprocess_book_node_export_html
(
&
$variables
)
{
$variables
[
'depth'
]
=
$variables
[
'node'
]
->
book
[
'depth'
];
$variables
[
'title'
]
=
check_plain
(
$variables
[
'node'
]
->
title
);
$variables
[
'content'
]
=
$variables
[
'node'
]
->
body
;
}
/**
...
...
modules/book/book.pages.inc
View file @
75a6f4de
...
...
@@ -73,47 +73,19 @@ function book_export($type, $nid) {
*/
function
book_export_html
(
$nid
)
{
if
(
user_access
(
'access printer-friendly version'
))
{
$
content
=
''
;
$
export_data
=
array
()
;
$node
=
node_load
(
$nid
);
if
(
isset
(
$node
->
book
))
{
$depth
=
$node
->
book
[
'depth'
];
for
(
$i
=
1
;
$i
<
$depth
;
$i
++
)
{
$content
.
=
"<div class=
\"
section-
$i
\"
>
\n
"
;
}
$tree
=
book_menu_subtree_data
(
$node
->
book
);
$content
.
=
book_export_traverse
(
$tree
,
'book_node_visitor_html_pre'
,
'book_node_visitor_html_post'
);
for
(
$i
=
1
;
$i
<
$depth
;
$i
++
)
{
$content
.
=
"</div>
\n
"
;
}
$contents
=
book_export_traverse
(
$tree
,
'book_node_export'
);
}
return
theme
(
'book_export_html'
,
check_plain
(
$node
->
title
)
,
$content
);
return
theme
(
'book_export_html'
,
$node
->
title
,
$content
s
,
$node
->
book
[
'depth'
]
);
}
else
{
drupal_access_denied
();
}
}
/**
* How the book's HTML export should be themed
*
* @ingroup themeable
*/
function
theme_book_export_html
(
$title
,
$content
)
{
global
$base_url
,
$language
;
$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>"
.
$title
.
"</title>
\n
"
;
$html
.
=
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
;
$html
.
=
'<base href="'
.
$base_url
.
'/" />'
.
"
\n
"
;
$html
.
=
'<link type="text/css" rel="stylesheet" href="misc/print.css" />'
;
if
(
defined
(
'LANGUAGE_RTL'
)
&&
$language
->
direction
==
LANGUAGE_RTL
)
{
$html
.
=
'<link type="text/css" rel="stylesheet" href="misc/print-rtl.css" />'
;
}
$html
.
=
"</head>
\n
<body>
\n
"
.
$content
.
"
\n
</body>
\n
</html>
\n
"
;
return
$html
;
}
/**
* Menu callback; show the outline form for a single node.
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment