page.module 6.06 KB
Newer Older
Dries's avatar
   
Dries committed
1
2
3
<?php
// $Id$

Dries's avatar
Dries committed
4
5
6
7
/**
 * Provide online user help
 */
function page_help($section = 'admin/help#page') {
Dries's avatar
   
Dries committed
8
9
10
  $output = "";

  switch ($section) {
Dries's avatar
   
Dries committed
11
    case 'admin/help#page':
Dries's avatar
   
Dries committed
12
      $output .= t("
Dries's avatar
Dries committed
13
14
15
16
17
18
      <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>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>
      ");
Dries's avatar
   
Dries committed
19
      break;
Dries's avatar
   
Dries committed
20
    case 'admin/system/modules#description':
Dries's avatar
Dries committed
21
      $output = t("Enables the creation of pages that can be added to the navigation system.");
Dries's avatar
   
Dries committed
22
      break;
Dries's avatar
   
Dries committed
23
24
25
    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.");
      break;
Dries's avatar
   
Dries committed
26
27
  }

Dries's avatar
   
Dries committed
28
  return $output;
Dries's avatar
   
Dries committed
29
30
}

Dries's avatar
Dries committed
31
32
33
/**
 * Define user permissions.
 */
Dries's avatar
   
Dries committed
34
function page_perm() {
Dries's avatar
Dries committed
35
  return array('create pages', 'maintain personal pages');
Dries's avatar
   
Dries committed
36
37
}

Dries's avatar
Dries committed
38
39
40
/**
 * Define the human-readable name of a node type.
 */
Dries's avatar
   
Dries committed
41
function page_node_name($node) {
Dries's avatar
Dries committed
42
  return t('page');
Dries's avatar
   
Dries committed
43
44
}

Dries's avatar
Dries committed
45
46
47
/**
 * Define access restrictions
 */
Dries's avatar
   
Dries committed
48
function page_access($op, $node) {
Dries's avatar
Dries committed
49
50
  global $user;

Dries's avatar
   
Dries committed
51
52
53
  if ($op == "view") {
    return $node->status;
  }
Dries's avatar
   
Dries committed
54
55

  if ($op == "create") {
Dries's avatar
Dries committed
56
    return user_access('create pages');
Dries's avatar
   
Dries committed
57
58
59
  }

  if ($op == "update") {
Dries's avatar
Dries committed
60
    return user_access('maintain personal pages') && ($user->uid == $node->uid);
Dries's avatar
   
Dries committed
61
62
63
  }

  if ($op == "delete") {
Dries's avatar
Dries committed
64
    return user_access('maintain personal pages') && ($user->uid == $node->uid);
Dries's avatar
   
Dries committed
65
  }
Dries's avatar
   
Dries committed
66
67
}

Dries's avatar
Dries committed
68
69
70
/**
 * Respond to node insertion.
 */
Dries's avatar
   
Dries committed
71
function page_insert($node) {
Dries's avatar
   
Dries committed
72
  db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
Dries's avatar
   
Dries committed
73
74
}

Dries's avatar
Dries committed
75
76
77
/**
 * Respond to node updating.
 */
Dries's avatar
   
Dries committed
78
function page_update($node) {
Dries's avatar
Dries committed
79
80
  db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
}
Dries's avatar
   
Dries committed
81

Dries's avatar
Dries committed
82
83
84
/**
 * Respond to node deletion
 */
Dries's avatar
   
Dries committed
85
function page_delete(&$node) {
Dries's avatar
   
Dries committed
86
  db_query("DELETE FROM {page} WHERE nid = %d", $node->nid);
Dries's avatar
   
Dries committed
87
88
}

Dries's avatar
Dries committed
89
90
91
/**
 * Load node-type-specific information.
 */
Dries's avatar
   
Dries committed
92
function page_load($node) {
Dries's avatar
Dries committed
93
  return db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid));
Dries's avatar
   
Dries committed
94
95
}

Dries's avatar
Dries committed
96
97
98
99
/**
 * Define internal Drupal links.
 */
function page_link($type, $node = 0, $main) {
Dries's avatar
   
Dries committed
100
101
102

  $links = array();

Dries's avatar
Dries committed
103
104
105
  if ($type == 'system') {
    if (page_access('create', $node)) {
      menu("node/add/page", t("page"), "node_page", 0);
Dries's avatar
   
Dries committed
106
107
108
    }
  }

Dries's avatar
Dries committed
109
110
111
112
  if ($type == 'node' && $node->type == 'page') {
    /* Don't display a redundant edit link if they are node administrators */
    if (page_access("update", $node) && !user_access('administer nodes')) {
      $links[] = l(t('edit this page'), "node/edit/$node->nid");
Dries's avatar
   
Dries committed
113
    }
Dries's avatar
   
Dries committed
114
115
  }

Dries's avatar
   
Dries committed
116
  return $links;
Dries's avatar
   
Dries committed
117
118
}

Dries's avatar
Dries committed
119
120
121
/**
 * Prepare a node's body content for viewing
 */
Dries's avatar
   
Dries committed
122
function page_content($node, $main = 0) {
Dries's avatar
Dries committed
123
124
  /* Extract the page body.  If body is dynamic (using PHP code), the body will
     be generated. */
Dries's avatar
   
Dries committed
125

Dries's avatar
Dries committed
126
  if ($node->format == 1) {
Dries's avatar
   
Dries committed
127
    // PHP type
Dries's avatar
   
Dries committed
128
129
    ob_start();
    eval($node->body);
Dries's avatar
   
Dries committed
130
    $node->teaser = $node->body = ob_get_contents();
Dries's avatar
   
Dries committed
131
    ob_end_clean();
Dries's avatar
   
Dries committed
132
  }
Dries's avatar
Dries committed
133
134
135
136
  else {
    // Assume HTML type by default
    $node = node_prepare($node, $main);
  }
Dries's avatar
   
Dries committed
137
  return $node;
Dries's avatar
   
Dries committed
138
139
}

Dries's avatar
Dries committed
140
141
142
/**
 * View a node.
 */
Dries's avatar
   
Dries committed
143
144
function page_view($node, $main = 0, $page = 0) {
  // prepare the node content
Dries's avatar
   
Dries committed
145
  $node = page_content($node, $main);
Dries's avatar
   
Dries committed
146
  // print the node
Dries's avatar
   
Dries committed
147
  return theme("node", $node, $main, $page);
Dries's avatar
   
Dries committed
148
149
}

Dries's avatar
Dries committed
150
151
152
/**
 * Display a node editing form
 */
Dries's avatar
   
Dries committed
153
function page_form(&$node, &$error) {
154
155
156
157
  if (function_exists("taxonomy_node_form")) {
    $output .= implode("", taxonomy_node_form("page", $node));
  }

Dries's avatar
Dries committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  if (($node->format == 1) && (!user_access('create php content'))) {
    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_hidden('format', $node->format);
    $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);
  }
Dries's avatar
   
Dries committed
173
174
175
176

  return $output;
}

Dries's avatar
Dries committed
177
178
179
/**
 * Verify a node editing form.
 */
180
function page_validate(&$node) {
181
  if ($node->format && user_access("create php content")) {
182
183
184
    // Do not filter PHP code, do not auto-extract a teaser
    $node->teaser = $node->body;
  }
Dries's avatar
Dries committed
185
186
187
188

  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));
189
190
191
  }
}

Dries's avatar
   
Dries committed
192
?>