| 2 |
|
|
| 3 |
/* |
/* |
| 4 |
* Author : Tom MacWright, Young Hahn, Jeff Miccolis |
* Author : Tom MacWright, Young Hahn, Jeff Miccolis |
|
* Revision : $Id: xslt_book.module,v 1.4 2008/08/19 17:47:43 yhahn Exp $ |
|
| 5 |
*/ |
*/ |
| 6 |
|
|
| 7 |
/** |
/** |
| 39 |
$path = drupal_get_path('module', 'xslt_book'); |
$path = drupal_get_path('module', 'xslt_book'); |
| 40 |
drupal_add_css($path ."/xslt_book.css"); |
drupal_add_css($path ."/xslt_book.css"); |
| 41 |
$section = context_get('xslt_book', 'section') ? context_get('xslt_book', 'section') : 1; |
$section = context_get('xslt_book', 'section') ? context_get('xslt_book', 'section') : 1; |
|
|
|
| 42 |
if ($cached = cache_get($node->nid .':'. $section, 'cache_xslt_book')) { |
if ($cached = cache_get($node->nid .':'. $section, 'cache_xslt_book')) { |
| 43 |
$data = unserialize($cached->data); |
$data = $cached->data; |
| 44 |
} |
} |
| 45 |
else { |
else { |
| 46 |
$html = new DomDocument('1.0', 'utf-8'); |
$html = new DOMDocument('1.0', 'utf-8'); |
| 47 |
|
|
| 48 |
set_error_handler('xslt_book_suppress_errors'); |
set_error_handler('xslt_book_suppress_errors'); |
| 49 |
$success = $html->loadXML($node->body); |
$success = $html->loadXML($node->body); |
| 53 |
$count = xslt_book_transform($html, $path .'/count.xslt'); |
$count = xslt_book_transform($html, $path .'/count.xslt'); |
| 54 |
$refs = xslt_book_transform($html, $path .'/references.xslt', array('section' => $section)); |
$refs = xslt_book_transform($html, $path .'/references.xslt', array('section' => $section)); |
| 55 |
$html = xslt_book_transform($html, $path .'/section.xslt', array('section' => $section)); |
$html = xslt_book_transform($html, $path .'/section.xslt', array('section' => $section)); |
| 56 |
$html = xslt_book_transform($html, $path .'/empty.xslt'); |
//$html = xslt_book_transform($html, $path .'/empty.xslt');\ |
| 57 |
if (variable_get('xslt_book_images', false)) { |
if (variable_get('xslt_book_images', FALSE)) { |
| 58 |
$html = xslt_book_images($html); |
$html = xslt_book_images($html); |
| 59 |
} |
} |
| 60 |
restore_error_handler(); |
restore_error_handler(); |
| 66 |
'refs' => $refs, |
'refs' => $refs, |
| 67 |
'count' => $count, |
'count' => $count, |
| 68 |
); |
); |
| 69 |
cache_set($node->nid .':'. $section, $data, 'cache_xslt_book'); |
cache_set($node->nid .':'. $section, $data, 'cache_xslt_book'); |
| 70 |
} |
} |
| 71 |
} |
} |
| 72 |
if ($data) { |
if ($data) { |
| 73 |
unset($node->content['body']); |
unset($node->content['body']); |
| 74 |
$node->content['body'] = array('#value' => $data['body']); |
$node->content['body'] = array('#value' => $data['body']); |
| 75 |
$node->content['references'] = array('#value' => $data['refs'], '#weight' => 150); |
$node->content['references'] = array('#value' => $data['refs'], '#weight' => 150); |
| 166 |
restore_error_handler(); |
restore_error_handler(); |
| 167 |
|
|
| 168 |
// return transformed xml |
// return transformed xml |
| 169 |
if ($html) { |
if ($html) { |
| 170 |
$xml = $xslt->transformToDoc($x); |
$xml = $xslt->transformToDoc($x); |
| 171 |
return $xml->saveHTML(); |
return $xml->saveHTML(); |
| 172 |
} |
} |
| 180 |
*/ |
*/ |
| 181 |
function xslt_book_menu() { |
function xslt_book_menu() { |
| 182 |
$items = array(); |
$items = array(); |
| 183 |
/* TODO |
|
|
Non menu code that was placed in hook_menu under the '!$may_cache' block |
|
|
so that it could be run during initialization, should now be moved to hook_init. |
|
|
Previously we called hook_init twice, once early in the bootstrap process, second |
|
|
just after the bootstrap has finished. The first instance is now called boot |
|
|
instead of init. |
|
|
|
|
|
In Drupal 6, there are now two hooks that can be used by modules to execute code |
|
|
at the beginning of a page request. hook_boot() replaces hook_boot() in Drupal 5 |
|
|
and runs on each page request, even for cached pages. hook_boot() now only runs |
|
|
for non-cached pages and thus can be used for code that was previously placed in |
|
|
hook_menu() with $may_cache = FALSE: |
|
|
|
|
|
Dynamic menu items under a '!$may_cache' block can often be simplified |
|
|
to remove references to arg(n) and use of '%<function-name>' to check |
|
|
conditions. See http://drupal.org/node/103114. |
|
|
|
|
|
The title and description arguments should not have strings wrapped in t(), |
|
|
because translation of these happen in a later stage in the menu system. |
|
|
*/ |
|
| 184 |
$items['admin/settings/xslt-book'] = array( |
$items['admin/settings/xslt-book'] = array( |
| 185 |
'title' => 'XSLT Book Settings', |
'title' => 'XSLT Book Settings', |
| 186 |
'description' => 'Configure XSLT Book nodetypes and settings.', |
'description' => 'Configure XSLT Book nodetypes and settings.', |
| 187 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 188 |
'page arguments' => array('xslt_book_settings_form'), |
'page arguments' => array('xslt_book_settings_form'), |
| 189 |
'access arguments' => array('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 190 |
); |
); |
| 191 |
if (!$may_cache && arg(0) == 'node' && is_numeric(arg(1))) { |
$items['node/'. '%' .'/section'] = array( |
|
$node = node_load(arg(1)); |
|
|
$nodetypes = variable_get('xslt_book_nodetypes', array()); |
|
|
if ($node->nid && $nodetypes[$node->type]) { |
|
|
$items['node/'. '%' .'/section'] = array( |
|
| 192 |
'title' => 'Section', |
'title' => 'Section', |
| 193 |
'page callback' => '_xslt_book_node_page_view', |
'page callback' => '_xslt_book_node_page_view', |
| 194 |
'page arguments' => array($node, arg(3)), |
'page arguments' => array(1, 3), |
| 195 |
'access arguments' => node_access('view', $node), |
'access callback' => 'xslt_book_access', |
| 196 |
'type' => MENU_CALLBACK |
'type' => MENU_LOCAL_TASK |
| 197 |
); |
); |
|
} |
|
|
} |
|
| 198 |
return $items; |
return $items; |
| 199 |
} |
} |
| 200 |
|
|
| 201 |
|
function xslt_book_access() { |
| 202 |
|
if (arg(0) == 'node' && is_numeric(arg(1))) { |
| 203 |
|
$node = node_load(arg(1)); |
| 204 |
|
$nodetypes = variable_get('xslt_book_nodetypes', array()); |
| 205 |
|
if ($node->type && $nodetypes[$node->type]) { |
| 206 |
|
return TRUE; |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
} |
| 210 |
/** |
/** |
| 211 |
* Wrapper callback around node_page_view() |
* Wrapper callback around node_page_view() |
| 212 |
*/ |
*/ |
| 213 |
function _xslt_book_node_page_view($node, $section = 1) { |
function _xslt_book_node_page_view($node, $section = 1) { |
| 214 |
|
$node = node_load(arg(1)); |
| 215 |
menu_set_active_item('node/'. $node->nid); |
menu_set_active_item('node/'. $node->nid); |
| 216 |
if (!context_exists('xslt_book', 'section')) { |
if (!context_get('xslt_book', 'section')) { |
| 217 |
context_set('xslt_book', 'section', $section); |
context_set('xslt_book', 'section', $section); |
| 218 |
} |
} |
| 219 |
return node_page_view($node); |
return node_page_view($node); |
| 264 |
|
|
| 265 |
return system_settings_form($form); |
return system_settings_form($form); |
| 266 |
} |
} |
| 267 |
|
/** |
| 268 |
|
* |
| 269 |
|
* theme registring functions |
| 270 |
|
**/ |
| 271 |
|
function xslt_book_theme() { |
| 272 |
|
return array( |
| 273 |
|
'xslt_book_links' => array( |
| 274 |
|
'file' => 'xslt_book.module', |
| 275 |
|
'arguments' => array( |
| 276 |
|
'nid' => NULL, |
| 277 |
|
'section' => NULL, |
| 278 |
|
'count' => NULL, |
| 279 |
|
), |
| 280 |
|
), |
| 281 |
|
'xslt_book_toc' => array( |
| 282 |
|
'file' => 'xslt_book.module', |
| 283 |
|
'arguments' => array( |
| 284 |
|
'nid' => NULL, |
| 285 |
|
), |
| 286 |
|
), |
| 287 |
|
); |
| 288 |
|
} |
| 289 |
/** |
/** |
| 290 |
* Generates prev/next links for display at the bottom of the node body |
* Generates prev/next links for display at the bottom of the node body |
| 291 |
* @param $nid Node ID |
* @param $nid Node ID |