node.module 18.6 KB
Newer Older
Dries's avatar
 
Dries committed
1
2
<?php

Dries's avatar
   
Dries committed
3
4
5
class Node {
  function Node($node) {
    global $user;
Dries's avatar
   
Dries committed
6
7
8
    $this->uid = $node[uid] ? $node[uid] : $user->uid;
    $this->nid = $node[nid];
    $this->type = $node[type];
Dries's avatar
   
Dries committed
9
    $this->comment = $node[comment] ? $node[comment] :  variable_get($node[type]."_comment", 0);
Dries's avatar
   
Dries committed
10
    $this->name = $node[name] ? $node[name] : $user->name;
Dries's avatar
   
Dries committed
11
    $this->title = $node[title];
12
    $this->attributes = $node[attributes];
Dries's avatar
   
Dries committed
13
14
15
    $this->timestamp = $node[timestamp] ? $node[timestamp] : time();
  }
}
Dries's avatar
 
Dries committed
16

Dries's avatar
   
Dries committed
17
18
19
20
21
22
23
24
25
function node_help() {
  global $mod;
 ?>
  <P>Todo.</P>
 <?php

  if ($mod == "node") {
    foreach (module_list() as $name) {
      if (module_hook($name, "status") && $name != "node") {
Dries's avatar
   
Dries committed
26
        print "<h3>". ucfirst($name) ." type</h3>";
Dries's avatar
   
Dries committed
27
28
29
30
31
32
        print module_invoke($name, "help");
      }
    }
  }
}

Dries's avatar
   
Dries committed
33
function node_perm() {
Dries's avatar
   
Dries committed
34
  return array("administer nodes", "access content", "post content");
Dries's avatar
   
Dries committed
35
36
}

Dries's avatar
   
Dries committed
37
function node_conf_options() {
Dries's avatar
   
Dries committed
38
  $output .= form_select("Default number of nodes to display", "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 =>  5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), "The default maximum number of nodes to display on the main page.");
Dries's avatar
   
Dries committed
39
40
  $output .= form_select("Prompt for confirmation when deleting nodes", "default_nodes_confirm_delete", variable_get("default_nodes_confirm_delete", 1), array("Disabled", "Enabled"), "Prompt for confirmation when deleting nodes.");

Dries's avatar
   
Dries committed
41
42
43
  return $output;
}

Dries's avatar
CHANGES    
Dries committed
44
function node_conf_filters() {
Dries's avatar
   
Dries committed
45
46
  $output .= form_select("Enable HTML tags", "filter_html", variable_get("filter_html", 0), array("Disabled", "Enabled"), "Allow HTML and PHP tags in user-contributed content.");
  $output .= form_textfield("Allowed HTML tags", "allowed_html", variable_get("allowed_html", "<A><B><BLOCKQUOTE><DD><DL><DT><I><LI><OL><U><UL>"), 64, 128, "If enabled, optionally specify tags which should not be stripped.  'STYLE' attributes, 'ON' attributes and unclosed tags are always stripped.");
Dries's avatar
   
Dries committed
47
  $output .= "<hr />";
Dries's avatar
   
Dries committed
48
  $output .= form_select("Enable link tags", "filter_link", variable_get("filter_link", 0), array("Disabled", "Enabled"), "Substitute special [[link]] tags.");
Dries's avatar
   
Dries committed
49
  $output .= "<hr />";
Dries's avatar
CHANGES    
Dries committed
50
51
52
53
54
55
56
57
58
59
60
  return $output;
}

function node_filter_html($text) {
  $text = eregi_replace("([ \f\r\t\n\'\"])style=[^>]+", "\\1", $text);
  $text = eregi_replace("([ \f\r\t\n\'\"])on[a-z]+=[^>]+", "\\1", $text);
  $text = strip_tags($text, variable_get("allowed_html", ""));
  return $text;
}

function node_filter_link($text) {
Dries's avatar
   
Dries committed
61
62
63
64
65
  $src = array("/\[\[(([^\|]*?)(\|([^\|]*?))?)\]\]/e");  // [link|description]
  $dst = array(format_tag('\\2', '\\4'));                // [link|description]
  return preg_replace($src, $dst, $text);
}

Dries's avatar
CHANGES    
Dries committed
66
67
68
69
70
71
function node_filter($text) {
  if (variable_get("filter_html", 0)) $text = node_filter_html($text);
  if (variable_get("filter_link", 0)) $text = node_filter_link($text);
  return $text;
}

Dries's avatar
Dries committed
72
73
function node_cron() {
  db_query("UPDATE node SET status = '". node_status("posted") ."', timestamp_posted = '' WHERE timestamp_posted > 0 AND timestamp_posted < ". time());
Dries's avatar
   
Dries committed
74
75
  db_query("UPDATE node SET status = '". node_status("queued") ."', timestamp_queued = '' WHERE timestamp_queued > 0 AND timestamp_queued < ". time());
  db_query("UPDATE node SET status = '". node_status("dumped") ."', timestamp_hidden = '' WHERE timestamp_hidden > 0 AND timestamp_hidden < ". time());
Dries's avatar
Dries committed
76
77
}

Dries's avatar
   
Dries committed
78
function node_link($type, $node = 0) {
Dries's avatar
   
Dries committed
79

Dries's avatar
   
Dries committed
80
  if ($type == "admin" && user_access("administer nodes")) {
Dries's avatar
   
Dries committed
81
82
83
    $links[] = "<a href=\"admin.php?mod=node\">content</a>";
  }

Dries's avatar
   
Dries committed
84
  if ($type == "node") {
Kjartan's avatar
Kjartan committed
85
86
87
    if ($node->links) {
      $links = $node->links;
    }
Dries's avatar
   
Dries committed
88
89
90
91
92
93
94
95
96
97
98
99
    if ($node->body) {
      $links[] = "<a href=\"node.php?id=". $node->nid ."\">". t("read more") ."</a>";
    }
    if ($node->comment) {
      $links[] = "<a href=\"node.php?id=". $node->nid ."\">". format_plural(node_get_comments($node->nid), "comment", "comments") ."</a>";
    }
  }

  return $links ? $links : array();
}

function node_links($nid, $type) {
Dries's avatar
   
Dries committed
100
101
  global $op;

Dries's avatar
   
Dries committed
102
  $link[] = ($op == "view") ? "view node" : "<A HREF=\"node.php?id=$nid\">view node</A>";
Dries's avatar
   
Dries committed
103
104
105
106
  $link[] = ($op == "content") ? "edit content" : "<A HREF=\"admin.php?mod=node&type=$type&op=content&id=$nid\">edit content</A>";
  $link[] = ($op == "option") ? "edit options" : "<A HREF=\"admin.php?mod=node&op=option&id=$nid\">edit options</A>";
  $link[] = ($op == "status") ? "edit status" : "<A HREF=\"admin.php?mod=node&op=status&id=$nid\">edit status</A>";
  $link[] = ($op == "attribute") ? "edit attribute" : "<A HREF=\"admin.php?mod=node&op=attribute&id=$nid\">edit attributes</A>";
Dries's avatar
   
Dries committed
107
  $link[] = "<a href=\"admin.php?mod=node&op=". (variable_get("default_nodes_confirm_delete", 1) ? "confirm+" : "") ."delete&id=$nid\">delete node</a>";
Dries's avatar
   
Dries committed
108
109
110
  return $link;
}

Dries's avatar
   
Dries committed
111
function node_overview($query) {
Dries's avatar
   
Dries committed
112
  global $user;
Dries's avatar
 
Dries committed
113

114
  $color = array("#ffffff", "#e5e5e5");
Dries's avatar
   
Dries committed
115
  $query = node_query($query ? $query : 0);
Dries's avatar
Dries committed
116

Dries's avatar
   
Dries committed
117
  $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN user u ON n.author = u.uid  $query[1] LIMIT 50");
Dries's avatar
 
Dries committed
118

Dries's avatar
   
Dries committed
119
  $output .= status($query[0]);
Dries's avatar
   
Dries committed
120
121
  $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
  $output .= " <tr><th>title</th><th>type</th><th>status</th><th>meta attributes</th><th>author</th><th>date</th></tr>\n";
Dries's avatar
Dries committed
122

Dries's avatar
 
Dries committed
123
  while ($node = db_fetch_object($result)) {
Dries's avatar
   
Dries committed
124
    $bg = $color[$i++ % sizeof($color)];
Dries's avatar
Dries committed
125

Dries's avatar
   
Dries committed
126
    $output .= " <tr bgcolor=\"$bg\"><td><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></td><td align=\"center\">$node->type</td><td>". node_status($node->status) ."</td><td>". check_output($node->attributes) ."</td><td>". format_name($node) ."</td><td>". format_date($node->timestamp, "small") ."</td></tr>\n";
Dries's avatar
   
Dries committed
127
    $output .= " <tr bgcolor=\"$bg\"><td align=\"right\" colspan=\"6\"><small>". implode(", ", node_links($node->nid, $node->type)) ."</small></td>\n";
Dries's avatar
 
Dries committed
128
  }
Dries's avatar
   
Dries committed
129
  $output .= "</table>\n";
Dries's avatar
 
Dries committed
130
131
132
133

  return $output;
}

Dries's avatar
Dries committed
134
135
function node_edit_option($id) {

136
  $node = node_get_object(array("nid" => $id));
Dries's avatar
 
Dries committed
137

Dries's avatar
   
Dries committed
138
  $form .= form_item("Title", check_output($node->title));
Dries's avatar
   
Dries committed
139
  $form .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
Dries's avatar
   
Dries committed
140
141
  $form .= form_select("Comment", "comment", $node->comment, node_comment_status(), "Allow users to post comments to this node.");
  $form .= form_select("Promote", "promote", $node->promote, node_promote_status(), "Promote this node on the main page.");
Dries's avatar
Dries committed
142
143
  $form .= form_hidden("nid", $node->nid);
  $form .= form_submit("Save node");
Dries's avatar
 
Dries committed
144

Dries's avatar
   
Dries committed
145
  return form("admin.php?mod=node&id=$node->nid", $form);
Dries's avatar
 
Dries committed
146
147
}

Dries's avatar
Dries committed
148
function node_edit_attribute($id) {
Dries's avatar
 
Dries committed
149

150
  $node = node_get_object(array("nid" => $id));
Dries's avatar
 
Dries committed
151

Dries's avatar
   
Dries committed
152
  $form .= form_item("Title", check_output($node->title));
Dries's avatar
   
Dries committed
153
  $form .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
Dries's avatar
   
Dries committed
154
  $form .= form_textfield("Attributes", "attributes", $node->attributes, 64, 128, "A comma-seperated list of attributes.  Example: 'Software, Webserver, Apache'.");
Dries's avatar
   
Dries committed
155
156
  $form .= form_hidden("nid", $node->nid);
  $form .= form_submit("Save node");
Dries's avatar
 
Dries committed
157

Dries's avatar
   
Dries committed
158
  return form("admin.php?mod=node&id=$node->nid", $form);
Dries's avatar
 
Dries committed
159
160
}

Dries's avatar
Dries committed
161
162
163
164
165
function node_edit_status($id) {
  global $REQUEST_URI;

  $node = node_get_object(array("nid" => $id));

Dries's avatar
   
Dries committed
166
  $form .= form_item("Title", check_output($node->title));
Dries's avatar
   
Dries committed
167
  $form .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
Dries's avatar
Dries committed
168
169
170
171
172
173
174
175
176
177
  $form .= form_select("Current status", "status", $node->status, node_status($node->type));
  $form .= form_textfield("Automatically post document", "timestamp_posted", ($node->timestamp_posted ? format_date($node->timestamp_posted) : ""), 30, 55, "The date at which your document will be automatically posted.  Leave empty if you don't want to schedule this document, or fill out a string containing an English date format.  Example input: '". date("j F Y G:i") ."', '". date("m/d/y H:i") ."', '". date("F j, Y H:i") ."', ...");
  $form .= form_textfield("Automatically queue document", "timestamp_queued", ($node->timestamp_queued ? format_date($node->timestamp_queued) : ""), 30, 55, "The date at which your document will be automatically queued.  Leave empty if you don't want to schedule this document, or fill out a string containing an English date format.  Example input: '". date("j F Y G:i") ."', '". date("m/d/y H:i") ."', '". date("F j, Y H:i") ."', ...");
  $form .= form_textfield("Automatically hide document", "timestamp_hidden", ($node->timestamp_hidden ? format_date($node->timestamp_hidden) : ""), 30, 55, "The date at which your document will be automatically hidden.  Leave empty if you don't want to schedule this document, or fill out a string containing an English date format.  Example input: '". date("j F Y G:i") ."', '". date("m/d/y H:i") ."', '". date("F j, Y H:i") ."', ...");
  $form .= form_hidden("nid", $node->nid);
  $form .= form_submit("Save node");

  return form($REQUEST_URI, $form);
}

Dries's avatar
   
Dries committed
178
179
180
181
182
183
184
185
186
187
function node_edit_content($edit, $type) {
  $edit[type] = $type;
  return node_invoke($edit, "form");
}

function node_save_content($edit, $type) {
  $edit[type] = $type;
  return node_invoke($edit, "save");
}

Dries's avatar
 
Dries committed
188
function node_delete($id) {
Dries's avatar
   
Dries committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  return (node_del(array("nid" => $id)) ? "node has been deleted." : "failed to delete node.");
}
  

function node_delete_confirmation($id) {
 
  $node = node_get_object(array("nid" => $id));

  $form .= form_item(t("Do you really want to delete this node"), check_output($node->title));
  $form .= form_submit("Delete node");
  $form .= form_submit("Keep node");
 
  return form("admin.php?mod=node&id=$node->nid", $form);

Dries's avatar
 
Dries committed
203
204
}

Dries's avatar
   
Dries committed
205
function node_query($type = -1) {
Dries's avatar
   
Dries committed
206
  $queries[] = array("all nodes: recent additions", "ORDER BY timestamp DESC");
Dries's avatar
   
Dries committed
207
208
209
210
211
212
  $queries[] = array("all nodes: status set to 'posted'", "WHERE n.status = ". node_status("posted") ." ORDER BY n.timestamp DESC");
  $queries[] = array("all nodes: status set to 'queued'", "WHERE n.status = ". node_status("queued") ." ORDER BY n.timestamp DESC");
  $queries[] = array("all nodes: status set to 'dumped'", "WHERE n.status = ". node_status("dumped") ." ORDER BY n.timestamp DESC");
  $queries[] = array("all nodes: scheduled to be posted", "WHERE timestamp_posted > 0 ORDER BY n.timestamp DESC");
  $queries[] = array("all nodes: scheduled to be queued", "WHERE timestamp_queued > 0 ORDER BY n.timestamp DESC");
  $queries[] = array("all nodes: scheduled to be hidden", "WHERE timestamp_hidden > 0 ORDER BY n.timestamp DESC");
Dries's avatar
Dries committed
213
214

  foreach (module_list() as $name) {
Kjartan's avatar
Kjartan committed
215
    if (module_hook($name, "status")) {
Dries's avatar
   
Dries committed
216
      $queries[] = array("$name: recent additions", "WHERE type = '$name' ORDER BY timestamp DESC");
Kjartan's avatar
Kjartan committed
217
218
219
      $statuses = module_invoke($name, "status");
      if (is_array($statuses)) {
        foreach (array_reverse($statuses) as $key=>$status) {
Kjartan's avatar
Kjartan committed
220
          $queries[] = array("$name: status set to '$status'", "WHERE type = '$name' AND n.status = '". node_status($status) ."' ORDER BY timestamp DESC");
Kjartan's avatar
Kjartan committed
221
        }
Dries's avatar
   
Dries committed
222
223
224
        $queries[] = array("$name: scheduled to be posted", "WHERE type = '$name' AND timestamp_posted > 0 ORDER BY timestamp DESC");
        $queries[] = array("$name: scheduled to be queued", "WHERE type = '$name' AND timestamp_queued > 0 ORDER BY timestamp DESC");
        $queries[] = array("$name: scheduled to be hidden", "WHERE type = '$name' AND timestamp_hidden > 0 ORDER BY timestamp DESC");
Kjartan's avatar
Kjartan committed
225
      }
Dries's avatar
Dries committed
226
227
228
    }
  }

Dries's avatar
   
Dries committed
229
  return ($type < 0 ? $queries : $queries[$type]);
Dries's avatar
   
Dries committed
230
231
}

Dries's avatar
   
Dries committed
232
233
234
function node_listing($queries) {
  global $mod;
  foreach ($queries as $key=>$array) {
Dries's avatar
   
Dries committed
235
    $output .= "<LI><A HREF=\"admin.php?mod=$mod&query=$key\">$array[0]</A></LI>\n";
Dries's avatar
   
Dries committed
236
237
238
239
  }
  return "<OL>$output</OL>\n";
}

Dries's avatar
   
Dries committed
240
241
242
243
244
245
246
247
248
249
function node_setting() {
  global $REQUEST_URI;

  $threshold_post = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 45 => 45, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100);
  $threshold_dump = array(-1 => -1, -2 => -2, -3 => -3, -4 => -4, -5 => -5, -6 => -6, -7 => -7, -8 => -8, -9 => -9, -10 => -10, -11 => -11, -12 => -12, -13 => -13, -14 => -14, -15 => -15, -20 => -20, -25 => -25, -30 => -30);
  $threshold_expire = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 45 => 45, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100);

  foreach (module_list() as $name) {
    if (module_hook($name, "user")) {
      $form .= "<H3>Default settings for $name nodes</H3>";
Dries's avatar
Dries committed
250
251
252
253
254
255
      $form .= form_select(t("Comment"), $name ."_comment", variable_get($name ."_comment", 0), node_comment_status(), "By default, allow or dissallow users to post comments in this category.");
      $form .= form_select(t("Promote"), $name ."_promote", variable_get($name ."_promote", 0), node_promote_status(), "By default, promote new submissions in this category to the front page.");
      $form .= form_select(t("Status"), $name ."_status", variable_get($name ."_status", node_status("queued")), node_status($name), "What to do with new submissions in this category?");
      $form .= form_select(t("Post threshold"), $name ."_post", variable_get($name ."_post", 4), $threshold_post, "If new submissions are subject to moderation, select a post threshold.");
      $form .= form_select(t("Dump threshold"), $name ."_dump", variable_get($name ."_dump", -2), $threshold_dump, "If new submissions are subject to moderation, select a dump threshold.");
      $form .= form_select(t("Expiration threshold"), $name ."_expire", variable_get($name ."_expire", 8), $threshold_expire, "If new submissions are subject to moderation, select a expiration threshold.");
Dries's avatar
   
Dries committed
256
257
258
259
260
261
262
263
264
    }
  }

  $form .= form_submit("Save settings");
  $form .= form_submit("Reset to defaults");

  return form($REQUEST_URI, $form);
}

Dries's avatar
Dries committed
265
266
267
268
269
270
271
function node_admin_save($edit) {
  if (isset($edit[status])) {
    $edit[timestamp_posted] = (strtotime($edit[timestamp_posted]) > time()) ? strtotime($edit[timestamp_posted]) : 0;
    $edit[timestamp_queued] = (strtotime($edit[timestamp_queued]) > time()) ? strtotime($edit[timestamp_queued]) : 0;
    $edit[timestamp_hidden] = (strtotime($edit[timestamp_hidden]) > time()) ? strtotime($edit[timestamp_hidden]) : 0;
    node_save($edit, array(status, timestamp_posted, timestamp_queued, timestamp_hidden));
  }
272
273
  else if (isset($edit[attributes])) {
    node_save($edit, array(attributes));
Dries's avatar
Dries committed
274
275
  }
  else {
Dries's avatar
   
Dries committed
276
    node_save($edit, array(comment, promote));
Dries's avatar
Dries committed
277
278
279
  }
}

Dries's avatar
   
Dries committed
280
function node_module_find() {
Dries's avatar
Dries committed
281
282
283
284
285
286
287
288
  global $REQUEST_URI;

  foreach (module_list() as $name) {
    if (module_hook($name, "user")) {
      $options .= "<OPTION VALUE=\"$name\">$name</OPTION>\n";
    }
  }

Dries's avatar
   
Dries committed
289
290
291
292
293
  $output .= "<form action=\"$REQUEST_URI\" method=\"POST\">\n";
  $output .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" type=\"text\">\n";
  $output .= " <select name=\"type\">$options</select>\n";
  $output .= " <input type=\"submit\" value=\"Search\">\n";
  $output .= "</form>\n";
Dries's avatar
Dries committed
294
295
296
297

  return $output;
}

Dries's avatar
   
Dries committed
298
299
function node_edit($node) {
  $output .= form_item("Title", $node->title);
Dries's avatar
   
Dries committed
300
  $output .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
Dries's avatar
   
Dries committed
301
  return $output;
Dries's avatar
Dries committed
302
303
}

Dries's avatar
 
Dries committed
304
function node_admin() {
Dries's avatar
   
Dries committed
305
  global $op, $id, $edit, $query, $type, $keys;
Dries's avatar
   
Dries committed
306

Dries's avatar
   
Dries committed
307
  if (user_access("administer nodes")) {
Dries's avatar
   
Dries committed
308
309
310

    foreach (module_list() as $name) {
      if (module_hook($name, "status") && $name != "node") {
Dries's avatar
   
Dries committed
311
        $link[] = "<a href=\"admin.php?mod=node&type=$name&op=add\">add $name</a>";
Dries's avatar
   
Dries committed
312
      }
Dries's avatar
Dries committed
313
314
    }

Dries's avatar
   
Dries committed
315
    print "<small>". implode(" | ", $link) ." | <a href=\"admin.php?mod=node&op=default\">node settings</a> | <a href=\"admin.php?mod=node&op=listing\">node listings</a> | <a href=\"admin.php?mod=node&op=search\">search node</a> | <a href=\"admin.php?mod=node\">overview</a> | <a href=\"admin.php?mod=node&op=help\">help</a></small><hr />\n";
Dries's avatar
   
Dries committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

    $id = check_input($edit[nid] ? $edit[nid] : $id);

    switch ($op) {
      case "add":
        print module_invoke($type, "form");
        break;
      case "help":
        print node_help();
        break;
      case "search":
        print node_module_find($id);
        print search_data($keys, $type);
        break;
      case "status":
        print node_edit_status($id);
        break;
      case "option":
        print node_edit_option($id);
        break;
      case "attribute":
        print node_edit_attribute($id);
        break;
      case "content":
        print node_edit_content(node_get_array(array("nid" => $id)), $type);
        break;
      case "default":
        break;
Dries's avatar
   
Dries committed
344
345
346
347
      case "confirm delete":
        print node_delete_confirmation($id);
        break;
      case "Delete node":
Dries's avatar
   
Dries committed
348
349
350
351
352
353
354
355
      case "delete":
        print status(node_delete($id));
        print node_overview($query);
        break;
      case "listing":
        print node_listing(node_query());
        break;
      case "Save settings":
Dries's avatar
   
Dries committed
356
        print status(system_save($edit));
Dries's avatar
   
Dries committed
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
        print node_setting();
        break;
      case "Reset to defaults":
        print status(conf_default($edit));
        print node_setting();
        break;
      case "Save node":
        print node_admin_save($edit);
        print node_overview($query);
        break;
      case "edit":
        print node_edit(node_get_object(array("nid" => $id)));
        break;
      case "view":
        print node_module_view(node_get_array(array("nid" => $id)), $type);
        break;
Dries's avatar
   
Dries committed
373
      case t("Preview"):
Dries's avatar
   
Dries committed
374
375
        print node_edit_content($edit, $type);
        break;
Dries's avatar
   
Dries committed
376
      case t("Submit"):
Dries's avatar
   
Dries committed
377
378
379
380
381
382
383
384
         print status(node_save_content($edit, $type));
        // fall through:
      default:
        print node_overview($query);
    }
  }
  else {
    print message_access();
Dries's avatar
 
Dries committed
385
386
387
  }
}

Dries's avatar
   
Dries committed
388
389
390
391
function node_block() {
  global $theme;

  $block[0][subject] = t("Syndicate");
Dries's avatar
   
Dries committed
392
  $block[0][content] = "<div align=\"center\"><a href=\"module.php?mod=node&op=feed\"><img src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" border=\"0\" alt=\"XML\" /></a></div>\n";
Dries's avatar
   
Dries committed
393
394
395
396
397
398
  $block[0][info] = "Syndicate";

  return $block;
}

function node_feed() {
Dries's avatar
   
Dries committed
399

Dries's avatar
   
Dries committed
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
  $result = db_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '". node_status("posted") ."' ORDER BY timestamp DESC LIMIT 15");

  while ($node = db_fetch_object($result)) {
    $item = node_get_object(array("nid" => $node->nid, "type" => $node->type));

    $title = $item->title;
    $link = path_uri() ."node.php?id=$item->nid";
    $description = module_invoke($item->type, "summary", $item);

    $items .= format_rss_item($title, $link, $description);
  }

  $output .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
  $output .= "<rss version=\"0.91\">\n";
  $output .= format_rss_channel(variable_get("site_name", "drupal"), path_uri() ."module.php?mod=node&op=feed", variable_get("site_slogan", ""), $items);
  $output .= "</rss>\n";

Dries's avatar
   
Dries committed
417
418
  header("Content-Type: text/xml");

Dries's avatar
   
Dries committed
419
420
421
422
423
424
425
426
427
428
429
430
  print $output;

}

function node_page() {
  global $op;

  if ($op == "feed") {
    node_feed();
  }
}

Dries's avatar
 
Dries committed
431
?>