| 1 |
<?php // $Id: Exp $ |
<?php // $Id: wghtml_node_module.php,v 1.1 2005/10/09 15:59:51 djnz Exp $ |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Implementation of hook_help(). |
* Implementation of hook_help |
|
* |
|
|
* Throughout Drupal, hook_help() is used to display help text at the top of |
|
|
* pages. Some other parts of Drupal pages get explanatory text from these hooks |
|
|
* as well. We use it here to provide a description of the module on the |
|
|
* module administration page. |
|
| 5 |
*/ |
*/ |
| 6 |
function wghtml_help($section) { |
function wghtml_help($section) { |
| 7 |
switch ($section) { |
switch ($section) { |
| 8 |
case 'admin/modules#description': |
case 'admin/help#wghtml': |
| 9 |
// This description is shown in the listing at admin/modules. |
// This description is shown in the listing at admin/modules. |
| 10 |
return t('wgHTML imports HTML pages to Drupal..'); |
return t('Import HTML pages to nodes.'); |
| 11 |
case 'node/add#wghtml': |
case 'node/add#wghtml': |
| 12 |
// This description shows up when users click "create content." |
// This description shows up when users click "create content." |
| 13 |
return t('wgHTML content is created automagically. The results of manually creating a wgHTML node are unpredicatable - don\'t do it.'); |
return t('wgHTML content is created automagically. The results of manually creating a wgHTML node are unpredicatable - don\'t do it.'); |
| 14 |
} |
} |
| 15 |
} |
} |
| 16 |
|
|
| 17 |
function wghtml_node_name($node) { |
/** |
| 18 |
return t('HTML page'); |
* Implementation of hook_node_info |
| 19 |
|
*/ |
| 20 |
|
function wghtml_node_info() { |
| 21 |
|
return array( |
| 22 |
|
'wghtml' => array( |
| 23 |
|
'name' => t('Imported HTML page'), |
| 24 |
|
'module' => 'wghtml', |
| 25 |
|
'description' => t('wgHTML content is created automagically. The results of manually creating a wgHTML node are unpredicatable - don\'t do it.'), |
| 26 |
|
) |
| 27 |
|
); |
| 28 |
} |
} |
| 29 |
|
|
| 30 |
/** |
/** |
| 31 |
* Implementation of hook_access(). |
* Implementation of hook_perm |
| 32 |
* |
*/ |
| 33 |
* Node modules may implement node_access() to determine the operations |
function wghtml_perm() { |
| 34 |
* users may perform on nodes. This example uses a very common access pattern. |
return array('edit wgHTML nodes'); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
/** |
| 38 |
|
* Implementation of hook_access |
| 39 |
*/ |
*/ |
| 40 |
function wghtml_access($op, $node) { |
function wghtml_access($op, $node) { |
| 41 |
return true; |
|
| 42 |
|
if ( $op == 'create' ) { |
| 43 |
|
return FALSE; // wgHTML nodes are created automagically |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
if ($op == 'update' || $op == 'delete') { |
| 47 |
|
return user_access('edit wgHTML nodes'); |
| 48 |
|
} |
| 49 |
} |
} |
| 50 |
|
|
| 51 |
/** |
/** |
| 52 |
* Implementation of hook_load(). |
* Implementation of hook_load(). |
|
* |
|
|
* Now that we've defined how to manage the node data in the database, we |
|
|
* need to tell Drupal how to get the node back out. This hook is called |
|
|
* every time a node is loaded, and allows us to do some loading of our own. |
|
| 53 |
*/ |
*/ |
| 54 |
function wghtml_load($node) { |
function wghtml_load(&$node) { |
| 55 |
$page =& _wghtml_get_object(); |
$page =& _wghtml_get_object(); |
| 56 |
|
|
| 57 |
// see if the page needs loading |
// see if the page needs loading |
| 58 |
if ( $page->pageId!==$node->nid ) { |
if ( empty($page->pageId) || $page->pageId!==$node->nid ) { |
| 59 |
$page->get_page_from_id($node->nid); |
$page->get_page_from_id($node->nid); |
| 60 |
} |
} |
| 61 |
// note we do not return a reference: there may be many nodes loaded with different pages |
$node->wghtml = $page; |
|
return array('wghtmlPage' => $page); |
|
| 62 |
} |
} |
| 63 |
|
|
| 64 |
/** |
/** |
| 65 |
* Implementation of hook_view(). |
* Implementation of hook_view |
|
* |
|
|
* This is a typical implementation that simply runs the node text through |
|
|
* the output filters. |
|
| 66 |
*/ |
*/ |
| 67 |
function wghtml_view(&$node, $teaser = FALSE, $page = FALSE) { |
function wghtml_view(&$node, $teaser = 0, $page = 0) { |
| 68 |
// substitute the cached body for the one stored in the node which is tag stripped |
$node = node_prepare($node, $teaser); |
| 69 |
// REVISIT - why not just store the HTML? |
if ( !empty($node->wghtml) ) { |
| 70 |
$node->body = $node->wghtmlPage->body; |
$node->content['wghtml_before'] = array( |
| 71 |
|
'#value' => theme('wghtml_view_before', $node), |
| 72 |
|
'#weight' => -1, |
| 73 |
|
); |
| 74 |
|
$node->content['wghtml_after'] = array( |
| 75 |
|
'#value' => theme('wghtml_view_after', $node), |
| 76 |
|
'#weight' => 1, |
| 77 |
|
); |
| 78 |
|
} |
| 79 |
|
return $node; |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
/** |
/** |
| 83 |
* A custom theme function. |
* Theme functions. |
|
* |
|
|
* By using this function to format our node-specific information, themes |
|
|
* can override this presentation if they wish. We also wrap the default |
|
|
* presentation in a CSS class that is prefixed by the module name. This |
|
|
* way, style sheets can modify the output without requiring theme code. |
|
| 84 |
*/ |
*/ |
| 85 |
function theme_wgthml_view($node) { |
function theme_wghtml_view_before($node) { |
|
$output = '<div class="node_example_order_info">'; |
|
|
$output .= t('The order is for %quantity %color items.', array('%quantity' => $node->quantity, '%color' => $node->color)); |
|
|
$output .= '</div>'; |
|
|
return $output; |
|
| 86 |
} |
} |
| 87 |
|
|
| 88 |
|
function theme_wghtml_view_after($node) { |
| 89 |
|
return "\n<div style=\"text-align: right; font-size: 80%; \">".$node->wghtml->status."</div>\n"; |
| 90 |
|
} |
|
|
|
| 91 |
|
|
| 92 |
/** |
/** |
| 93 |
* Action hook for show action |
* Action hook for show action |
| 100 |
$page->get_page($file); |
$page->get_page($file); |
| 101 |
|
|
| 102 |
// now load the node: the node load hook will add the page to the node |
// now load the node: the node load hook will add the page to the node |
| 103 |
$node = module_invoke('node', 'load', array('nid'=>$page->pageId)); |
$node = module_invoke('node', 'load', $page->pageId); |
| 104 |
$output = module_invoke('node', 'view', $node); |
return node_page_view($node); |
|
echo theme('page', $output); |
|
|
|
|
|
return; |
|
| 105 |
|
|
| 106 |
if ( empty($page->error) ) { |
if ( empty($page->error) ) { |
| 107 |
drupal_set_title($page->title); |
drupal_set_title($page->title); |