Commit 42461ed5 authored by Dries's avatar Dries
Browse files

Patch 6270 by mathias: misc. fixes

parent 36a0b17f
<?php <?php
// $Id$ // $Id$
function page_help($section = "admin/help#page") { /**
* Provide online user help
*/
function page_help($section = 'admin/help#page') {
$output = ""; $output = "";
switch ($section) { switch ($section) {
case 'admin/help#page': case 'admin/help#page':
$output .= t(" $output .= t("
<p>The page module is used to create a <i>static page</i>. Unlike a story, a static page is a persistent web page on your site which usually shortcuts the typical lifecycle of user generated content (i.e. submit -&gt; moderate -&gt; post -&gt; comment). A static page is usually linked from the main navigation bar, using whatever text the author wishes. To create a static page without this navigation link, simply skip the link text field.</p> <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 -&gt; moderate -&gt; post -&gt; comment). </p>
<p>Site pages, unlike many other forms of Drupal content, may be made of PHP code in addition to HTML and text. All Drupal objects and functions are available to a site administrator.</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>
<p><strong>maintain personal 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>
");
break; break;
case 'admin/system/modules#description': case 'admin/system/modules#description':
$output = t("Enables the creation of a static pages that can be added to the navigation system."); $output = t("Enables the creation of pages that can be added to the navigation system.");
break; break;
case 'node/add#page': case 'node/add#page':
$output = t("If you just want to add a page with a link in the menu to your site, this would be the best choice. Unlike a story, a static page by-passes the submission queue."); $output = t("If you just want to add a page with a link in the menu to your site, this would be the best choice. Unlike a story, a static page by-passes the submission queue.");
...@@ -21,90 +28,118 @@ function page_help($section = "admin/help#page") { ...@@ -21,90 +28,118 @@ function page_help($section = "admin/help#page") {
return $output; return $output;
} }
/**
* Define user permissions.
*/
function page_perm() { function page_perm() {
return array("maintain static pages"); return array('create pages', 'maintain personal pages');
} }
/**
* Define the human-readable name of a node type.
*/
function page_node_name($node) { function page_node_name($node) {
return t("static page"); return t('page');
} }
/**
* Define access restrictions
*/
function page_access($op, $node) { function page_access($op, $node) {
global $user;
if ($op == "view") { if ($op == "view") {
return $node->status; return $node->status;
} }
if ($op == "create") { if ($op == "create") {
return user_access("maintain static pages"); return user_access('create pages');
} }
if ($op == "update") { if ($op == "update") {
return user_access("maintain static pages"); return user_access('maintain personal pages') && ($user->uid == $node->uid);
} }
if ($op == "delete") { if ($op == "delete") {
return user_access("maintain static pages"); return user_access('maintain personal pages') && ($user->uid == $node->uid);
} }
} }
/**
* Respond to node insertion.
*/
function page_insert($node) { function page_insert($node) {
db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description); db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
} }
/**
* Respond to node updating.
*/
function page_update($node) { function page_update($node) {
db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid); db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
} }
/**
* Respond to node deletion
*/
function page_delete(&$node) { function page_delete(&$node) {
db_query("DELETE FROM {page} WHERE nid = %d", $node->nid); db_query("DELETE FROM {page} WHERE nid = %d", $node->nid);
} }
/**
* Load node-type-specific information.
*/
function page_load($node) { function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid)); return db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid));
return $page;
} }
function page_link($type) { /**
* Define internal Drupal links.
*/
function page_link($type, $node = 0, $main) {
$links = array(); $links = array();
if ($type == "page" && user_access("access content")) { if ($type == 'system') {
$result = db_query("SELECT n.nid, n.title, p.link, p.description FROM {page} p INNER JOIN {node} n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link"); if (page_access('create', $node)) {
while ($page = db_fetch_object($result)) { menu("node/add/page", t("page"), "node_page", 0);
$links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description));
} }
} }
if ($type == "system") { if ($type == 'node' && $node->type == 'page') {
if (user_access("maintain static pages")) { /* Don't display a redundant edit link if they are node administrators */
menu("node/add/page", t("static page"), "node_page", 0); if (page_access("update", $node) && !user_access('administer nodes')) {
$links[] = l(t('edit this page'), "node/edit/$node->nid");
} }
} }
return $links; return $links;
} }
/**
* Prepare a node's body content for viewing
*/
function page_content($node, $main = 0) { function page_content($node, $main = 0) {
/* /* Extract the page body. If body is dynamic (using PHP code), the body will
** Extract the page body. If body is dynamic (using PHP code), the body be generated. */
** will be generated.
*/
if ($node->format == 0) { if ($node->format == 1) {
// HTML type
$node = node_prepare($node, $main);
}
else {
// PHP type // PHP type
ob_start(); ob_start();
eval($node->body); eval($node->body);
$node->teaser = $node->body = ob_get_contents(); $node->teaser = $node->body = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
else {
// Assume HTML type by default
$node = node_prepare($node, $main);
}
return $node; return $node;
} }
/**
* View a node.
*/
function page_view($node, $main = 0, $page = 0) { function page_view($node, $main = 0, $page = 0) {
// prepare the node content // prepare the node content
$node = page_content($node, $main); $node = page_content($node, $main);
...@@ -112,26 +147,45 @@ function page_view($node, $main = 0, $page = 0) { ...@@ -112,26 +147,45 @@ function page_view($node, $main = 0, $page = 0) {
return theme("node", $node, $main, $page); return theme("node", $node, $main, $page);
} }
/**
* Display a node editing form
*/
function page_form(&$node, &$error) { function page_form(&$node, &$error) {
if (function_exists("taxonomy_node_form")) { if (function_exists("taxonomy_node_form")) {
$output .= implode("", taxonomy_node_form("page", $node)); $output .= implode("", taxonomy_node_form("page", $node));
} }
$output .= form_textarea(t("Body"), "body", $node->body, 60, 20, filter_tips_short()); if (($node->format == 1) && (!user_access('create php content'))) {
$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 blank.")); drupal_set_message(t('Note: 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.'));
$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.")); $output .= form_hidden('format', $node->format);
$output .= form_radios(t("Type"), "format", $node->format, array(0 => "HTML", 1 => "PHP")); $hide_types = true;
}
else {
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, filter_tips_short());
}
$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 blank."));
$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."));
$content_type = (user_access('create php content')) ? array(0 => "HTML", 1 => "PHP") : false;
if (!$hide_types && $content_type) {
$output .= form_radios(t("Type"), "format", $node->format, $content_type);
}
return $output; return $output;
} }
/**
* Verify a node editing form.
*/
function page_validate(&$node) { function page_validate(&$node) {
if ($node->format && user_access("create php content")) { if ($node->format && user_access("create php content")) {
// Do not filter PHP code, do not auto-extract a teaser // Do not filter PHP code, do not auto-extract a teaser
$node->teaser = $node->body; $node->teaser = $node->body;
} }
else {
$node->format = 0; if (($node->format == 1) && (!user_access('create php content'))) {
/* Overwrite the submitted node body since they don't have sufficient privileges. */
$node->body = db_result(db_query("SELECT body FROM {node} WHERE nid = '%d'", $node->nid));
} }
} }
......
<?php <?php
// $Id$ // $Id$
function page_help($section = "admin/help#page") { /**
* Provide online user help
*/
function page_help($section = 'admin/help#page') {
$output = ""; $output = "";
switch ($section) { switch ($section) {
case 'admin/help#page': case 'admin/help#page':
$output .= t(" $output .= t("
<p>The page module is used to create a <i>static page</i>. Unlike a story, a static page is a persistent web page on your site which usually shortcuts the typical lifecycle of user generated content (i.e. submit -&gt; moderate -&gt; post -&gt; comment). A static page is usually linked from the main navigation bar, using whatever text the author wishes. To create a static page without this navigation link, simply skip the link text field.</p> <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 -&gt; moderate -&gt; post -&gt; comment). </p>
<p>Site pages, unlike many other forms of Drupal content, may be made of PHP code in addition to HTML and text. All Drupal objects and functions are available to a site administrator.</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>
<p><strong>maintain personal 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>
");
break; break;
case 'admin/system/modules#description': case 'admin/system/modules#description':
$output = t("Enables the creation of a static pages that can be added to the navigation system."); $output = t("Enables the creation of pages that can be added to the navigation system.");
break; break;
case 'node/add#page': case 'node/add#page':
$output = t("If you just want to add a page with a link in the menu to your site, this would be the best choice. Unlike a story, a static page by-passes the submission queue."); $output = t("If you just want to add a page with a link in the menu to your site, this would be the best choice. Unlike a story, a static page by-passes the submission queue.");
...@@ -21,90 +28,118 @@ function page_help($section = "admin/help#page") { ...@@ -21,90 +28,118 @@ function page_help($section = "admin/help#page") {
return $output; return $output;
} }
/**
* Define user permissions.
*/
function page_perm() { function page_perm() {
return array("maintain static pages"); return array('create pages', 'maintain personal pages');
} }
/**
* Define the human-readable name of a node type.
*/
function page_node_name($node) { function page_node_name($node) {
return t("static page"); return t('page');
} }
/**
* Define access restrictions
*/
function page_access($op, $node) { function page_access($op, $node) {
global $user;
if ($op == "view") { if ($op == "view") {
return $node->status; return $node->status;
} }
if ($op == "create") { if ($op == "create") {
return user_access("maintain static pages"); return user_access('create pages');
} }
if ($op == "update") { if ($op == "update") {
return user_access("maintain static pages"); return user_access('maintain personal pages') && ($user->uid == $node->uid);
} }
if ($op == "delete") { if ($op == "delete") {
return user_access("maintain static pages"); return user_access('maintain personal pages') && ($user->uid == $node->uid);
} }
} }
/**
* Respond to node insertion.
*/
function page_insert($node) { function page_insert($node) {
db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description); db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
} }
/**
* Respond to node updating.
*/
function page_update($node) { function page_update($node) {
db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid); db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
} }
/**
* Respond to node deletion
*/
function page_delete(&$node) { function page_delete(&$node) {
db_query("DELETE FROM {page} WHERE nid = %d", $node->nid); db_query("DELETE FROM {page} WHERE nid = %d", $node->nid);
} }
/**
* Load node-type-specific information.
*/
function page_load($node) { function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid)); return db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid));
return $page;
} }
function page_link($type) { /**
* Define internal Drupal links.
*/
function page_link($type, $node = 0, $main) {
$links = array(); $links = array();
if ($type == "page" && user_access("access content")) { if ($type == 'system') {
$result = db_query("SELECT n.nid, n.title, p.link, p.description FROM {page} p INNER JOIN {node} n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link"); if (page_access('create', $node)) {
while ($page = db_fetch_object($result)) { menu("node/add/page", t("page"), "node_page", 0);
$links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description));
} }
} }
if ($type == "system") { if ($type == 'node' && $node->type == 'page') {
if (user_access("maintain static pages")) { /* Don't display a redundant edit link if they are node administrators */
menu("node/add/page", t("static page"), "node_page", 0); if (page_access("update", $node) && !user_access('administer nodes')) {
$links[] = l(t('edit this page'), "node/edit/$node->nid");
} }
} }
return $links; return $links;
} }
/**
* Prepare a node's body content for viewing
*/
function page_content($node, $main = 0) { function page_content($node, $main = 0) {
/* /* Extract the page body. If body is dynamic (using PHP code), the body will
** Extract the page body. If body is dynamic (using PHP code), the body be generated. */
** will be generated.
*/
if ($node->format == 0) { if ($node->format == 1) {
// HTML type
$node = node_prepare($node, $main);
}
else {
// PHP type // PHP type
ob_start(); ob_start();
eval($node->body); eval($node->body);
$node->teaser = $node->body = ob_get_contents(); $node->teaser = $node->body = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
else {
// Assume HTML type by default
$node = node_prepare($node, $main);
}
return $node; return $node;
} }
/**
* View a node.
*/
function page_view($node, $main = 0, $page = 0) { function page_view($node, $main = 0, $page = 0) {
// prepare the node content // prepare the node content
$node = page_content($node, $main); $node = page_content($node, $main);
...@@ -112,26 +147,45 @@ function page_view($node, $main = 0, $page = 0) { ...@@ -112,26 +147,45 @@ function page_view($node, $main = 0, $page = 0) {
return theme("node", $node, $main, $page); return theme("node", $node, $main, $page);
} }
/**
* Display a node editing form
*/
function page_form(&$node, &$error) { function page_form(&$node, &$error) {
if (function_exists("taxonomy_node_form")) { if (function_exists("taxonomy_node_form")) {
$output .= implode("", taxonomy_node_form("page", $node)); $output .= implode("", taxonomy_node_form("page", $node));
} }
$output .= form_textarea(t("Body"), "body", $node->body, 60, 20, filter_tips_short()); if (($node->format == 1) && (!user_access('create php content'))) {
$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 blank.")); drupal_set_message(t('Note: 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.'));
$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.")); $output .= form_hidden('format', $node->format);
$output .= form_radios(t("Type"), "format", $node->format, array(0 => "HTML", 1 => "PHP")); $hide_types = true;
}
else {
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, filter_tips_short());
}
$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 blank."));
$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."));
$content_type = (user_access('create php content')) ? array(0 => "HTML", 1 => "PHP") : false;
if (!$hide_types && $content_type) {
$output .= form_radios(t("Type"), "format", $node->format, $content_type);
}
return $output; return $output;
} }
/**
* Verify a node editing form.
*/
function page_validate(&$node) { function page_validate(&$node) {
if ($node->format && user_access("create php content")) { if ($node->format && user_access("create php content")) {
// Do not filter PHP code, do not auto-extract a teaser // Do not filter PHP code, do not auto-extract a teaser
$node->teaser = $node->body; $node->teaser = $node->body;
} }
else {
$node->format = 0; if (($node->format == 1) && (!user_access('create php content'))) {
/* Overwrite the submitted node body since they don't have sufficient privileges. */
$node->body = db_result(db_query("SELECT body FROM {node} WHERE nid = '%d'", $node->nid));
} }
} }
......
<?php <?php
// $Id$ // $Id$
/**
* Provide online user help
*/
function story_help($section = "admin/help#story") { function story_help($section = "admin/help#story") {
$output = ""; $output = "";
...@@ -14,19 +17,26 @@ function story_help($section = "admin/help#story") { ...@@ -14,19 +17,26 @@ function story_help($section = "admin/help#story") {
case 'admin/help#story': case 'admin/help#story':
$output = t(" $output = t("
<p>The story module lets your users submit articles for consideration by the rest of the community, who can vote on them if moderation is enabled. Stories usually follow a publishing flow of <strong>submit -&gt; moderate -&gt; post to the main page -&gt; comments</strong>. Administrators are able to shortcut this flow as desired.</p> <p>The story module lets your users submit articles for consideration by the rest of the community, who can vote on them if moderation is enabled. Stories usually follow a publishing flow of <strong>submit -&gt; moderate -&gt; post to the main page -&gt; comments</strong>. Administrators are able to shortcut this flow as desired.</p>
In <a href=\"%story-config\">administer &raquo; configuration &raquo; modules &raquo; story</a> you can set up an introductory text for story authors, and a floor on the number of words which may be included in a story. This is designed to help discourage the submission of trivially short stories.", array("%story-config" => url("admin/system/modules/story"))); In <a href=\"%story-config\">administer &raquo; configuration &raquo; modules &raquo; story</a> you can set up an introductory text for story authors, and a floor on the number of words which may be included in a story. This is designed to help discourage the submission of trivially short stories.</p>
<h3>User access permissions for stories</h3>
<p><strong>create stories:</strong> Allows a role to create stories. They cannot edit or delete stories, even if they are the authors. You must enable this permission to in order for a role to create a story.</p>
<p><strong>maintain personal stories:</strong> Allows a role to add/edit stories if they own the story. Use this permission if you want users to be able to edit and maintain their own stories.</p>