2001-12-05 18:46:24 +00:00
<?php
// $Id$
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_help().
2004-03-10 09:32:46 +00:00
*/
2004-05-09 19:28:43 +00:00
function page_help($section) {
2003-08-21 20:50:03 +00:00
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#page':
2004-05-09 19:28:43 +00:00
return t("
2004-03-10 09:32:46 +00:00
<p>The page module is used when you want to create content that optionally inserts a link into your navigation system. You can also, however, create pages that that don't have this link by skipping the link text field in the page form. At this time, not all themes support the link insertion behavior. Some themes, like xtemplate, provide alternative mechanisms for link creation. Pages are also unique in that they shortcut the typical lifecycle of user generated content (i.e. submit -> moderate -> post -> comment). </p>
<p>If you enable the <strong>create PHP content</strong> permission for a role, pages may consist of PHP code in addition to HTML and text.</p>
<h3>User access permissions for pages</h3>
<p><strong>create pages:</strong> Allows a role to create pages. They cannot edit or delete pages, even if they are the authors. You must enable this permission to in order for a role to create a page.</p>
2004-07-13 20:40:46 +00:00
<p><strong>edit own pages:</strong> Allows a role to add/edit pages if they own the page. Use this permission if you want users to be able to edit and maintain their own pages.</p>
2004-03-10 09:32:46 +00:00
");
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2004-05-09 19:28:43 +00:00
return t('Enables the creation of pages that can be added to the navigation system.');
2004-01-27 18:47:07 +00:00
case 'node/add#page':
2004-05-09 19:28:43 +00:00
return t('If you just want to add a page with a link in the menu to your site, this is the best choice. Unlike a story, a static page bypasses the submission queue.');
2003-08-21 20:50:03 +00:00
}
2002-02-25 20:26:38 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_perm().
2004-03-10 09:32:46 +00:00
*/
2002-12-10 20:35:20 +00:00
function page_perm() {
2004-07-13 20:40:46 +00:00
return array('create pages', 'edit own pages');
2002-12-10 20:35:20 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_node_name().
2004-03-10 09:32:46 +00:00
*/
2004-01-27 18:47:07 +00:00
function page_node_name($node) {
2004-03-10 09:32:46 +00:00
return t('page');
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_access().
2004-03-10 09:32:46 +00:00
*/
2001-12-05 18:46:24 +00:00
function page_access($op, $node) {
2004-03-10 09:32:46 +00:00
global $user;
2004-05-09 19:28:43 +00:00
if ($op == 'view') {
2001-12-05 18:46:24 +00:00
return $node->status;
}
2002-12-10 20:35:20 +00:00
2004-05-09 19:28:43 +00:00
if ($op == 'create') {
2004-03-10 09:32:46 +00:00
return user_access('create pages');
2002-12-10 20:35:20 +00:00
}
2004-05-09 19:28:43 +00:00
if ($op == 'update') {
2004-07-13 20:40:46 +00:00
return user_access('edit own pages') && ($user->uid == $node->uid);
2002-12-10 20:35:20 +00:00
}
2004-05-09 19:28:43 +00:00
if ($op == 'delete') {
2004-07-13 20:40:46 +00:00
return user_access('edit own pages') && ($user->uid == $node->uid);
2002-12-10 20:35:20 +00:00
}
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_insert().
2004-03-10 09:32:46 +00:00
*/
2001-12-05 18:46:24 +00:00
function page_insert($node) {
2003-07-10 17:46:44 +00:00
db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_update().
2004-03-10 09:32:46 +00:00
*/
2001-12-05 18:46:24 +00:00
function page_update($node) {
2004-03-10 09:32:46 +00:00
db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
}
2001-12-05 18:46:24 +00:00
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_delete().
2004-03-10 09:32:46 +00:00
*/
2001-12-05 18:46:24 +00:00
function page_delete(&$node) {
2004-05-09 19:28:43 +00:00
db_query('DELETE FROM {page} WHERE nid = %d', $node->nid);
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_load().
2004-03-10 09:32:46 +00:00
*/
2001-12-05 18:46:24 +00:00
function page_load($node) {
2004-05-09 19:28:43 +00:00
return db_fetch_object(db_query('SELECT format, link, description FROM {page} WHERE nid = %d', $node->nid));
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-06-18 15:04:37 +00:00
* Implementation of hook_menu().
2004-03-10 09:32:46 +00:00
*/
2004-06-18 15:04:37 +00:00
function page_menu() {
$items = array();
$items[] = array('path' => 'node/add/page', 'title' => t('page'),
'access' => page_access('create', NULL));
return $items;
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_content().
*
* If body is dynamic (using PHP code), the body will be generated.
2004-03-10 09:32:46 +00:00
*/
2004-06-18 15:04:37 +00:00
function page_content($node, $teaser = FALSE) {
2004-03-10 09:32:46 +00:00
if ($node->format == 1) {
2002-12-31 11:37:29 +00:00
// PHP type
2001-12-06 17:33:05 +00:00
ob_start();
eval($node->body);
2004-07-13 21:52:35 +00:00
$node->body = ob_get_contents();
2001-12-06 17:33:05 +00:00
ob_end_clean();
2004-07-13 21:52:35 +00:00
$node->teaser = node_teaser($node->body);
$node->readmore = (strlen($node->teaser) < strlen($node->body));
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
else {
// Assume HTML type by default
2004-06-18 15:04:37 +00:00
$node = node_prepare($node, $teaser);
2004-03-10 09:32:46 +00:00
}
2003-09-15 15:58:20 +00:00
return $node;
2001-12-05 18:46:24 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_view().
2004-03-10 09:32:46 +00:00
*/
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
function page_view(&$node, $teaser = FALSE, $page = FALSE) {
2003-11-25 19:26:21 +00:00
// prepare the node content
2004-06-18 15:04:37 +00:00
$node = page_content($node, $teaser);
2003-09-20 15:11:41 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_form().
2004-03-10 09:32:46 +00:00
*/
2004-07-04 16:50:02 +00:00
function page_form(&$node) {
2004-05-09 19:28:43 +00:00
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('page', $node));
2002-05-19 23:05:05 +00:00
}
2004-03-10 09:32:46 +00:00
if (($node->format == 1) && (!user_access('create php content'))) {
2004-07-07 20:18:22 +00:00
drupal_set_message(t('the body contents of this page are written in PHP and you do not have sufficient permissions to make changes to the body. You can edit the other elements of the page.'));
2004-03-10 09:32:46 +00:00
$output .= form_hidden('format', $node->format);
$hide_types = true;
}
else {
2004-07-08 15:24:30 +00:00
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, filter_tips_short(), NULL, TRUE);
2004-03-10 09:32:46 +00:00
}
2004-05-09 19:28:43 +00:00
$output .= form_textfield(t('Link name'), 'link', $node->link, 60, 64, t('To make the page show up in the navigation links, enter the name of the link. Otherwise, leave this blank.'));
2004-03-10 09:32:46 +00:00
$output .= form_textfield(t('Link description'), 'description', $node->description, 60, 64, t("The description displayed when hovering over the page's link. Leave blank when you don't want a description."));
2004-05-09 19:28:43 +00:00
$content_type = (user_access('create php content')) ? array(0 => 'HTML', 1 => 'PHP') : false;
2004-03-10 09:32:46 +00:00
if (!$hide_types && $content_type) {
2004-05-09 19:28:43 +00:00
$output .= form_radios(t('Type'), 'format', $node->format, $content_type);
2004-03-10 09:32:46 +00:00
}
2001-12-05 18:46:24 +00:00
return $output;
}
2004-03-10 09:32:46 +00:00
/**
2004-05-09 19:28:43 +00:00
* Implementation of hook_validate().
2004-03-10 09:32:46 +00:00
*/
2003-03-07 22:11:44 +00:00
function page_validate(&$node) {
2004-05-09 19:28:43 +00:00
if ($node->format && user_access('create php content')) {
2003-03-07 22:11:44 +00:00
// Do not filter PHP code, do not auto-extract a teaser
$node->teaser = $node->body;
}
2004-03-10 09:32:46 +00:00
if (($node->format == 1) && (!user_access('create php content'))) {
/* Overwrite the submitted node body since they don't have sufficient privileges. */
2004-05-09 19:28:43 +00:00
$node->body = db_result(db_query('SELECT body FROM {node} WHERE nid = %d', $node->nid));
2003-03-07 22:11:44 +00:00
}
}
2002-12-31 11:37:29 +00:00
?>