Created
October 18, 2010 13:29
-
-
Save chayner/632217 to your computer and use it in GitHub Desktop.
Patch file to modify the "paging" module in Drupal to work with a specific CCK field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: modules/paging/paging.module | |
| =================================================================== | |
| --- modules/paging/paging.module (revision 221) | |
| +++ modules/paging/paging.module (working copy) | |
| @@ -408,17 +408,18 @@ | |
| * Implementation of hook_nodeapi(). | |
| */ | |
| function paging_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { | |
| + | |
| // Act only when paging is enabled for node's type and when node is being rendered for normal views. | |
| if (variable_get('paging_enabled_' . $node->type, 0) && ($node->build_mode == NODE_BUILD_NORMAL)) { | |
| switch ($op) { | |
| case 'load': | |
| case 'view': | |
| case 'alter': | |
| - // Support for CCK. | |
| - if (isset($node->field_body[0]['view'])) { | |
| - _paging_nodeapi($node, | |
| - $node->field_body[0]['view'], | |
| - $node->field_teaser[0]['view'], | |
| + // Support for CCK -- hard coded with the page_body right now. | |
| + if (isset($node->field_page_body[0]['value'])) { | |
| + _paging_cck_nodeadpi($node, | |
| + $node->field_page_body[0]['value'], | |
| + 'field_page_body', | |
| $op, $teaser, $page); | |
| } | |
| // Support for CCK. | |
| @@ -440,6 +441,107 @@ | |
| } | |
| } | |
| +function _paging_cck_nodeadpi(&$node, &$node_field, $field_name, $op, $teaser, $page) { | |
| + switch ($op) { | |
| + case 'load': | |
| + $paging_separator = variable_get('paging_separator_' . $node->type, '<!--pagebreak-->'); | |
| + $node->pages = explode($paging_separator, $node_field); | |
| + $node->page_count = count($node->pages); | |
| + break; | |
| + case 'view': | |
| + // Fetch a structured array containing page names. | |
| + $node->page_names = paging_fetch_names($node_field); | |
| + | |
| + if (strpos($node_field, '<!--pagebreak-->') !== FALSE) { | |
| + // Element value to distinguish between multiple pagers on one page. | |
| + $element = 1; | |
| + $page = isset($_GET['page']) ? $_GET['page'] : ''; | |
| + | |
| + // Only do paging | |
| + // a) if not in teaser mode; | |
| + // b) if there is more than one page; | |
| + // c) if a printable version is not being requested; or | |
| + // d) if a non-paged version is not being explicitly requested | |
| + // e.g. http://www.example.com/node/1?page=full or node/1/full. | |
| + if (!$teaser && $node->page_count > 1 && arg(2) != 'print' && arg(2) != 'full' && $page != 'full') { | |
| + global $pager_page_array, $pager_total; | |
| + $pager_page_array = explode(',', $page); | |
| + $pager_total[$element] = $node->page_count; | |
| + $page = isset($pager_page_array[$element]) ? $pager_page_array[$element] : 0; | |
| + | |
| + // Put the current page contents into the node body. | |
| + $node->content['field_page_body']['field']['items'][0]['#item']['safe'] = check_markup($node->pages[$page], $node->field_page_body[0]['format'], FALSE); | |
| + | |
| + // Mapping the pages in $node->page_names and $node->page_count to set number of pages as the array length. | |
| + $fake = array_fill(0, ($node->page_count - 1) + 1, ''); | |
| + $length = count($fake) > count($node->page_names) ? count($fake) : count($node->page_names); | |
| + for ($i=0; $i<$length; ++$i) { | |
| + $merged[$i] = $node->page_names[$i]; | |
| + } | |
| + // Fill the empty names with node title and page number. | |
| + $node->page_names = _paging_populate_empty_names($merged, $node->title); | |
| + | |
| + // For use in AJAX. | |
| + $pager_id = 'paging-pager-' . $node->nid; | |
| + | |
| + $return_json = FALSE; | |
| + // Capture pager JSON request | |
| + if (isset($_REQUEST['paging_json_request']) && $_REQUEST['paging_json_request'] == $pager_id) { | |
| + // Unset before calling a pager theming function to prevent unecessarily cluttered link URLs. | |
| + unset($_REQUEST['paging_json_request']); | |
| + $return_json = TRUE; | |
| + } | |
| + | |
| + // Load the page navigation links into $node->paging. Also accessible in node theming. | |
| + $node->paging = paging_pager_style($node, $element); | |
| + | |
| + // Find the position to display the page navigation links at. | |
| + $position = variable_get('paging_pager_widget_position_' . $node->type, 'below'); | |
| + | |
| + if ($position == 'below' || $position == 'both') { | |
| + $node->content['paging']['#value'] = $node->paging; | |
| + // Get possible manual weight for paging field from CCK setting. | |
| + $node->content['paging']['#weight'] = $node->content['field_page_body']['#weight'] + 1; | |
| + } | |
| + | |
| + $node->content['field_page_body']['#weight'] = 0; | |
| + | |
| + $module_path = drupal_get_path('module', 'paging'); | |
| + drupal_add_css($module_path . '/paging.css', 'module'); | |
| + if (variable_get('paging_ajax_enabled_' . $node->type, 0)) { | |
| + _paging_content_wrap($node); | |
| + if ($return_json) { | |
| + $content = array( | |
| + 'paging_above' => $node->content['paging_above'], | |
| + 'body' => $node->content['field_page_body'], | |
| + 'paging' => $node->content['paging'], | |
| + ); | |
| + $response = array( | |
| + 'content' => drupal_render($content), | |
| + ); | |
| + // Exit with replacement data. | |
| + exit(drupal_json($response)); | |
| + } | |
| + // Add scripts for AJAX driven page loading. | |
| + drupal_add_js($module_path . '/paging.js', 'module'); | |
| + } | |
| + | |
| + // Set a global value for block visibility. | |
| + $GLOBALS['_paging_display_block'] = TRUE; | |
| + | |
| + if (variable_get('paging_name_title_' . $node->type, 0) && !empty($page)) { | |
| + // Set the browser title to page's name. | |
| + drupal_set_title($node->page_names[$page]); | |
| + } | |
| + } | |
| + // Remove internal <!--paging_filter--> tag from final output. | |
| + $node->content['field_page_body']['field']['items'][0]['#item']['safe'] = str_replace('<!--pagebreak-->', '', $node->content['field_page_body']['field']['items'][0]['#item']['safe']); | |
| + } | |
| + | |
| + break; | |
| + } | |
| +} | |
| + | |
| /** | |
| * Helper function for paging_nodeapi(). | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment