Commit 7cd8427f authored by Dries's avatar Dries

- Patch #257730 by Senpai: code clean-up for book module.

parent a7d345d7
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// $Id$ // $Id$
/** /**
* @file book-export-html.tpl.php * @file
* Default theme implementation for printed version of book outline. * Default theme implementation for printed version of book outline.
* *
* Available variables: * Available variables:
...@@ -45,9 +45,7 @@ ...@@ -45,9 +45,7 @@
<div class="section-<?php print $i; ?>"> <div class="section-<?php print $i; ?>">
<?php $div_close .= '</div>'; ?> <?php $div_close .= '</div>'; ?>
<?php endfor; ?> <?php endfor; ?>
<?php print $contents; ?> <?php print $contents; ?>
<?php print $div_close; ?> <?php print $div_close; ?>
</body> </body>
</html> </html>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// $Id$ // $Id$
/** /**
* @file book-navigation.tpl.php * @file
* Default theme implementation to navigate books. Presented under nodes that * Default theme implementation to navigate books. Presented under nodes that
* are a part of book outlines. * are a part of book outlines.
* *
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// $Id$ // $Id$
/** /**
* @file book-node-export-html.tpl.php * @file
* Default theme implementation for rendering a single node in a printer * Default theme implementation for rendering a single node in a printer
* friendly outline. * friendly outline.
* *
......
...@@ -46,6 +46,7 @@ function book_admin_settings() { ...@@ -46,6 +46,7 @@ function book_admin_settings() {
); );
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE); $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
$form['#validate'][] = 'book_admin_settings_validate'; $form['#validate'][] = 'book_admin_settings_validate';
return system_settings_form($form); return system_settings_form($form);
} }
...@@ -77,6 +78,7 @@ function book_admin_edit($form_state, $node) { ...@@ -77,6 +78,7 @@ function book_admin_edit($form_state, $node) {
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save book pages'), '#value' => t('Save book pages'),
); );
return $form; return $form;
} }
...@@ -139,6 +141,7 @@ function _book_admin_table($node) { ...@@ -139,6 +141,7 @@ function _book_admin_table($node) {
if ($tree['below']) { if ($tree['below']) {
_book_admin_table_tree($tree['below'], $form); _book_admin_table_tree($tree['below'], $form);
} }
return $form; return $form;
} }
...@@ -246,5 +249,6 @@ function _book_admin_compare($a, $b) { ...@@ -246,5 +249,6 @@ function _book_admin_compare($a, $b) {
if ($weight) { if ($weight) {
return $weight; return $weight;
} }
return strncmp($a['link']['title'], $b['link']['title']); return strncmp($a['link']['title'], $b['link']['title']);
} }
...@@ -49,4 +49,4 @@ ...@@ -49,4 +49,4 @@
} }
#book-admin-edit .form-item { #book-admin-edit .form-item {
float: left; float: left;
} }
\ No newline at end of file
; $Id$ ; $Id$
name = Book name = Book
description = Allows users to structure site pages in a hierarchy or outline. description = Allows users to structure site pages in a hierarchy or outline.
package = Core - optional package = Core - optional
......
...@@ -23,7 +23,7 @@ function book_uninstall() { ...@@ -23,7 +23,7 @@ function book_uninstall() {
} }
function _book_install_type_create() { function _book_install_type_create() {
// Create an additional node type // Create an additional node type.
$book_node_type = array( $book_node_type = array(
'type' => 'book', 'type' => 'book',
'name' => t('Book page'), 'name' => t('Book page'),
...@@ -149,7 +149,7 @@ function book_update_6000() { ...@@ -149,7 +149,7 @@ function book_update_6000() {
} }
elseif ($_SESSION['book_update_6000_orphans']) { elseif ($_SESSION['book_update_6000_orphans']) {
// Do the first batched part of the update - collect orphans. // Do the first batched part of the update - collect orphans.
$update_count = 400; // Update this many at a time $update_count = 400; // Update this many at a time.
$result = db_query_range("SELECT * FROM {book_temp}", $_SESSION['book_update_6000_orphans']['from'], $update_count); $result = db_query_range("SELECT * FROM {book_temp}", $_SESSION['book_update_6000_orphans']['from'], $update_count);
$has_rows = FALSE; $has_rows = FALSE;
...@@ -175,7 +175,6 @@ function book_update_6000() { ...@@ -175,7 +175,6 @@ function book_update_6000() {
$_SESSION['book_update_6000_orphans']['from'] += $update_count; $_SESSION['book_update_6000_orphans']['from'] += $update_count;
} }
else { else {
// Done with this part
if (!empty($_SESSION['book_update_6000_orphans']['book'])) { if (!empty($_SESSION['book_update_6000_orphans']['book'])) {
// The orphans' parent is added last, so it will be processed first. // The orphans' parent is added last, so it will be processed first.
$_SESSION['book_update_6000'][] = $_SESSION['book_update_6000_orphans']['book']; $_SESSION['book_update_6000'][] = $_SESSION['book_update_6000_orphans']['book'];
...@@ -183,17 +182,18 @@ function book_update_6000() { ...@@ -183,17 +182,18 @@ function book_update_6000() {
$_SESSION['book_update_6000_orphans'] = FALSE; $_SESSION['book_update_6000_orphans'] = FALSE;
} }
$ret['#finished'] = FALSE; $ret['#finished'] = FALSE;
return $ret; return $ret;
} }
else { else {
// Do the next batched part of the update // Run the next batched part of the update.
$update_count = 100; // Update this many at a time $update_count = 100; // Update this many at a time
while ($update_count && $_SESSION['book_update_6000']) { while ($update_count && $_SESSION['book_update_6000']) {
// Get the last node off the stack. // Get the last node off the stack.
$book = array_pop($_SESSION['book_update_6000']); $book = array_pop($_SESSION['book_update_6000']);
// Add all of this node's children to the stack // Add all of this node's children to the stack.
$result = db_query("SELECT * FROM {book_temp} WHERE parent = %d", $book['nid']); $result = db_query("SELECT * FROM {book_temp} WHERE parent = %d", $book['nid']);
while ($a = db_fetch_array($result)) { while ($a = db_fetch_array($result)) {
$_SESSION['book_update_6000'][] = $a; $_SESSION['book_update_6000'][] = $a;
...@@ -205,7 +205,7 @@ function book_update_6000() { ...@@ -205,7 +205,7 @@ function book_update_6000() {
$book = array_merge($book, $parent); $book = array_merge($book, $parent);
} }
else { else {
// There is not a parent - this is a new book. // There is no parent - this is a new book.
$book['plid'] = 0; $book['plid'] = 0;
$book['bid'] = $book['nid']; $book['bid'] = $book['nid'];
} }
...@@ -286,5 +286,3 @@ function book_schema() { ...@@ -286,5 +286,3 @@ function book_schema() {
return $schema; return $schema;
} }
This diff is collapsed.
...@@ -40,7 +40,6 @@ function book_render() { ...@@ -40,7 +40,6 @@ function book_render() {
* in a format determined by the $type parameter. * in a format determined by the $type parameter.
*/ */
function book_export($type, $nid) { function book_export($type, $nid) {
$type = drupal_strtolower($type); $type = drupal_strtolower($type);
$export_function = 'book_export_' . $type; $export_function = 'book_export_' . $type;
...@@ -79,6 +78,7 @@ function book_export_html($nid) { ...@@ -79,6 +78,7 @@ function book_export_html($nid) {
$tree = book_menu_subtree_data($node->book); $tree = book_menu_subtree_data($node->book);
$contents = book_export_traverse($tree, 'book_node_export'); $contents = book_export_traverse($tree, 'book_node_export');
} }
return theme('book_export_html', $node->title, $contents, $node->book['depth']); return theme('book_export_html', $node->title, $contents, $node->book['depth']);
} }
else { else {
...@@ -103,7 +103,6 @@ function book_outline($node) { ...@@ -103,7 +103,6 @@ function book_outline($node) {
* @ingroup forms * @ingroup forms
*/ */
function book_outline_form(&$form_state, $node) { function book_outline_form(&$form_state, $node) {
if (!isset($node->book)) { if (!isset($node->book)) {
// The node is not part of any book yet - set default options. // The node is not part of any book yet - set default options.
$node->book = _book_link_defaults($node->nid); $node->book = _book_link_defaults($node->nid);
...@@ -111,6 +110,7 @@ function book_outline_form(&$form_state, $node) { ...@@ -111,6 +110,7 @@ function book_outline_form(&$form_state, $node) {
else { else {
$node->book['original_bid'] = $node->book['bid']; $node->book['original_bid'] = $node->book['bid'];
} }
// Find the depth limit for the parent select. // Find the depth limit for the parent select.
if (!isset($node->book['parent_depth_limit'])) { if (!isset($node->book['parent_depth_limit'])) {
$node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book); $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
...@@ -158,6 +158,7 @@ function book_outline_form_submit($form, &$form_state) { ...@@ -158,6 +158,7 @@ function book_outline_form_submit($form, &$form_state) {
$book_link = $form_state['values']['book']; $book_link = $form_state['values']['book'];
if (!$book_link['bid']) { if (!$book_link['bid']) {
drupal_set_message(t('No changes were made')); drupal_set_message(t('No changes were made'));
return; return;
} }
...@@ -244,7 +245,6 @@ function book_form_update() { ...@@ -244,7 +245,6 @@ function book_form_update() {
// Get the new options and update the cache. // Get the new options and update the cache.
$form['book']['plid'] = _book_parent_select($book_link); $form['book']['plid'] = _book_parent_select($book_link);
cache_set($cid, $form, 'cache_form', $cache->expire); cache_set($cid, $form, 'cache_form', $cache->expire);
// Build and render the new select element, then return it in JSON format. // Build and render the new select element, then return it in JSON format.
$form_state = array(); $form_state = array();
$form['#post'] = array(); $form['#post'] = array();
......
...@@ -68,11 +68,16 @@ class BookTestCase extends DrupalWebTestCase { ...@@ -68,11 +68,16 @@ class BookTestCase extends DrupalWebTestCase {
/** /**
* Check the outline of sub-pages; previous, up, and next; and printer friendly version. * Check the outline of sub-pages; previous, up, and next; and printer friendly version.
* *
* @param Node $node Node to check. * @param Node $node
* @param array $nodes Nodes that should be in outline. * Node to check.
* @param Node $previous Previous link node. * @param array $nodes
* @param Node $up Up link node. * Nodes that should be in outline.
* @param Node $next Next link node. * @param Node $previous
* Previous link node.
* @param Node $up
* Up link node.
* @param Node $next
* Next link node.
*/ */
function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) { function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) {
static $number = 0; static $number = 0;
...@@ -90,9 +95,11 @@ class BookTestCase extends DrupalWebTestCase { ...@@ -90,9 +95,11 @@ class BookTestCase extends DrupalWebTestCase {
if ($previous) { if ($previous) {
$this->assertRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), t('Prevoius page link found.')); $this->assertRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), t('Prevoius page link found.'));
} }
if ($up) { if ($up) {
$this->assertRaw(l('up', 'node/' . $up->nid, array('attributes' => array('class' => 'page-up', 'title' => t('Go to parent page')))), t('Up page link found.')); $this->assertRaw(l('up', 'node/' . $up->nid, array('attributes' => array('class' => 'page-up', 'title' => t('Go to parent page')))), t('Up page link found.'));
} }
if ($next) { if ($next) {
$this->assertRaw(l($next->title . ' ›', 'node/' . $next->nid, array('attributes' => array('class' => 'page-next', 'title' => t('Go to next page')))), t('Next page link found.')); $this->assertRaw(l($next->title . ' ›', 'node/' . $next->nid, array('attributes' => array('class' => 'page-next', 'title' => t('Go to next page')))), t('Next page link found.'));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment