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

Dries's avatar
 
Dries committed
3 4 5 6 7 8 9 10 11 12
class Node {
  function Node($node) {
    global $user;
    $this->userid = $node[userid] ? $node[userid] : $user->userid;
    $this->title = $node[title];
    $this->timestamp = $node[timestamp] ? $node[timestamp] : time();
    $this->cid = $node[cid];
    $this->tid = $node[tid];
  }
}
Dries's avatar
 
Dries committed
13

Dries's avatar
 
Dries committed
14
function node_overview($query = array()) {
Dries's avatar
 
Dries committed
15
  global $user;
Dries's avatar
 
Dries committed
16

Dries's avatar
 
Dries committed
17
  $result = db_query("SELECT n.*, u.userid, c.name AS category FROM node n LEFT JOIN users u ON n.author = u.id LEFT JOIN category c ON n.cid = c.cid $query[1] LIMIT 50");
Dries's avatar
 
Dries committed
18

Dries's avatar
 
Dries committed
19
  $output .= status($query[0]);
Dries's avatar
 
Dries committed
20
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
21
  $output .= " <TR><TH>title</TH><TH>category</TH><TH>status</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
Dries's avatar
 
Dries committed
22
  while ($node = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
23
    $output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". check_output($node->category ? $node->category : $node->type) ."</TD><TD>". node_status($node, $node->status) ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp, "small") ."</TD><TD>". (user_access($user, "node") ? "<A HREF=\"admin.php?mod=node&op=edit&id=$node->nid\">edit node</A>" : "edit node") ."</TD><TD>". (user_access($user, $node->type) ? "<A HREF=\"admin.php?mod=$node->type&op=edit&id=$node->nid\">edit $node->type</A>" : "edit $node->type") ."</TD></TR>\n";
Dries's avatar
 
Dries committed
24 25 26 27 28 29 30 31 32 33
  }
  $output .= "</TABLE>\n";

  return $output;
}

function node_admin_view($id) {
  $node = node_get_object("nid", $id);

  $output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
Dries's avatar
 
Dries committed
34 35
  $output .= form_item("Title", check_output($node->title));
  $output .= form_item("Author", format_username($node->userid));
Dries's avatar
 
Dries committed
36
  $output .= form_item("Status", node_status($node, $node->status));
Dries's avatar
 
Dries committed
37 38
  $output .= form_item("Comment", node_comment_status($node->comment));
  $output .= form_item("Promote", node_promote_status($node->promote));
Dries's avatar
 
Dries committed
39
  $output .= form_item("Moderate", check_output($node->moderate));
Dries's avatar
 
Dries committed
40 41 42
  $output .= form_item("Date", format_date($node->timestamp));
  $output .= form_submit("Edit node");
  $output .= form_submit("Delete node");
Dries's avatar
 
Dries committed
43 44 45 46 47 48
  $output .= "</FORM>\n";

  return $output;
}

function node_admin_edit($id) {
Dries's avatar
 
Dries committed
49
  global $user;
Dries's avatar
 
Dries committed
50 51 52 53

  $node = node_get_object("nid", $id);

  $output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
Dries's avatar
 
Dries committed
54
  $output .= form_item("Title", check_output($node->title));
Dries's avatar
 
Dries committed
55 56 57 58
  $output .= form_select("Author", "author", $node->author, array($node->author => $node->userid, $user->id => $user->userid));
  $output .= form_select("Status", "status", $node->status, node_status($node));
  $output .= form_select("Comment", "comment", $node->comment, node_comment_status());
  $output .= form_select("Promote", "promote", $node->promote, node_promote_status());
Dries's avatar
 
Dries committed
59
  $output .= form_textfield("Moderate", "moderate", $node->moderate, 35, 255, t("A comma-seperated list of usernames."));
Dries's avatar
 
Dries committed
60
  $output .= form_select("Date", "timestamp", $node->timestamp, array($node->timestamp => format_date($node->timestamp) ." (original)", time() => format_date(time()) ." (current)"));
Dries's avatar
 
Dries committed
61 62 63
  $output .= form_hidden("nid", $node->nid);
  $output .= form_submit("View node");
  $output .= form_submit("Save node");
Dries's avatar
 
Dries committed
64 65 66 67 68 69
  $output .= "</FORM>\n";

  return $output;
}

function node_delete($id) {
Dries's avatar
 
Dries committed
70
  return (node_del("nid", $id) ? "node has been deleted." : "failed to delete node: node must be dumped first.");
Dries's avatar
 
Dries committed
71 72
}

Dries's avatar
 
Dries committed
73 74
function node_query($type = "") {
  global $status;
Dries's avatar
 
Dries committed
75
  $queries =  array(array("recent nodes", "ORDER BY n.timestamp DESC"), array("posted nodes", "WHERE n.status = '$status[posted]' ORDER BY n.timestamp DESC"), array("queued nodes", "WHERE n.status = '$status[queued]' ORDER BY n.timestamp DESC"), array("dumped nodes", "WHERE n.status = '$status[dumped]' ORDER BY n.timestamp DESC"));
Dries's avatar
 
Dries committed
76 77 78
  return ($queries[$type] ? $queries[$type] : $queries);
}

Dries's avatar
 
Dries committed
79 80 81 82
function node_listing($queries) {
  global $mod;
  foreach ($queries as $key=>$array) {
    $output .= "<LI><A HREF=\"admin.php?mod=$mod&type=$key\">$array[0]</A></LI>\n";
Dries's avatar
 
Dries committed
83 84 85 86
  }
  return "<OL>$output</OL>\n";
}

Dries's avatar
 
Dries committed
87
function node_admin() {
Dries's avatar
 
Dries committed
88 89 90
  global $op, $id, $edit, $type;

  print "<SMALL><A HREF=\"admin.php?mod=node&op=listing\">node listings</A> | <A HREF=\"admin.php?mod=node\">overview</A></SMALL><HR>\n";
Dries's avatar
 
Dries committed
91 92

  $id = check_input($edit[nid] ? $edit[nid] : $id);
Dries's avatar
 
Dries committed
93
  $type = ($type ? $type : 0);
Dries's avatar
 
Dries committed
94 95 96 97 98 99 100 101 102 103

  switch ($op) {
    case "Edit node":
    case "edit":
      print node_admin_edit($id);
      break;
    case "Delete node":
      print status(node_delete($id));
      print node_overview();
      break;
Dries's avatar
 
Dries committed
104
    case "listing":
Dries's avatar
 
Dries committed
105
      print node_listing(node_query());
Dries's avatar
 
Dries committed
106
      break;
Dries's avatar
 
Dries committed
107
    case "Save node":
Dries's avatar
 
Dries committed
108
      node_save($edit);
Dries's avatar
 
Dries committed
109
      print node_admin_view($id);
Dries's avatar
 
Dries committed
110 111 112 113 114 115
      break;
    case "View node":
    case "view":
      print node_admin_view($id);
      break;
    default:
Dries's avatar
 
Dries committed
116
      print node_overview(node_query($type));
Dries's avatar
 
Dries committed
117 118 119 120
  }
}

?>