node.module 8.89 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
CHANGES  
Dries committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function node_conf_filters() {
  $output .= form_select(t("Strip HTML tags"), "filter_html", variable_get("filter_html", 0), array("Disabled", "Enabled"), t("Strip HTML and PHP tags."));
  $output .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<A><B><BLOCKQUOTE><DD><DL><DT><I><LI><OL><U><UL>"), 64, 128, t("If enabled, optionally specify tags which should not be stripped.  'STYLE' attributes, 'ON' attributes and unclosed tags are always stripped."));
  $output .= "<HR>";
  $output .= form_select(t("Strip link tags"), "filter_link", variable_get("filter_link", 0), array("Disabled", "Enabled"), t("Substitute special [[link]] tags."));
  $output .= "<HR>";
  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
31 32 33 34 35
  $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
36 37 38 39 40 41
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
42
function node_overview($query = array()) {
Dries's avatar
 
Dries committed
43
  global $user;
Dries's avatar
 
Dries committed
44

Dries's avatar
 
Dries committed
45
  $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
46

Dries's avatar
 
Dries committed
47
  $output .= status($query[0]);
Dries's avatar
 
Dries committed
48
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
49
  $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
50
  while ($node = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
51
    $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->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
52 53 54 55 56 57 58
  }
  $output .= "</TABLE>\n";

  return $output;
}

function node_admin_view($id) {
59
  $node = node_get_object(array("nid" => $id));
Dries's avatar
 
Dries committed
60

Dries's avatar
 
Dries committed
61 62
  $form .= form_item("Title", check_output($node->title));
  $form .= form_item("Author", format_username($node->userid));
Dries's avatar
 
Dries committed
63
  $form .= form_item("Status", node_status($node->status));
Dries's avatar
 
Dries committed
64 65 66 67 68 69
  $form .= form_item("Comment", node_comment_status($node->comment));
  $form .= form_item("Promote", node_promote_status($node->promote));
  $form .= form_item("Moderate", check_output($node->moderate));
  $form .= form_item("Date", format_date($node->timestamp));
  $form .= form_submit("Edit node");
  $form .= form_submit("Delete node");
Dries's avatar
 
Dries committed
70

Dries's avatar
 
Dries committed
71
  return form("admin.php?mod=node&id=$node->nid", $form);
Dries's avatar
 
Dries committed
72 73 74
}

function node_admin_edit($id) {
Dries's avatar
 
Dries committed
75
  global $user;
Dries's avatar
 
Dries committed
76

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

Dries's avatar
 
Dries committed
79 80
  $form .= form_item("Title", check_output($node->title));
  $form .= form_select("Author", "author", $node->author, array($node->author => $node->userid, $user->id => $user->userid));
Dries's avatar
 
Dries committed
81
  $form .= form_select("Status", "status", $node->status, node_status($node->type));
Dries's avatar
 
Dries committed
82 83 84 85 86 87
  $form .= form_select("Comment", "comment", $node->comment, node_comment_status());
  $form .= form_select("Promote", "promote", $node->promote, node_promote_status());
  $form .= form_textfield("Moderate", "moderate", $node->moderate, 35, 255, t("Provide a comma-seperated list of the moderators their usernames."));
  $form .= form_select("Date", "timestamp", $node->timestamp, array($node->timestamp => format_date($node->timestamp) ." (original)", time() => format_date(time()) ." (current)"));
  $form .= form_hidden("nid", $node->nid);
  $form .= form_submit("Save node");
Dries's avatar
 
Dries committed
88
  $form .= form_submit("View node");
Dries's avatar
 
Dries committed
89

Dries's avatar
 
Dries committed
90
  return form("admin.php?mod=node&id=$node->nid", $form);
Dries's avatar
 
Dries committed
91 92 93
}

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

Dries's avatar
 
Dries committed
97 98
function node_query($type = "") {
  global $status;
Dries's avatar
 
Dries committed
99
  $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
100 101 102
  return ($queries[$type] ? $queries[$type] : $queries);
}

Dries's avatar
 
Dries committed
103 104 105 106
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
107 108 109 110
  }
  return "<OL>$output</OL>\n";
}

Dries's avatar
 
Dries committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
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>";
      $form .= form_select(t("Comment"), $name ."_comment", variable_get($name ."_comment", 0), node_comment_status(), t("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(), t("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), t("What to do with new submissions in this category?"));
      $form .= form_select(t("Post threshold"), $name ."_post", variable_get($name ."_post", 4), $threshold_post, t("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, t("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, t("If new submissions are subject to moderation, select a expiration threshold."));
      $form .= form_textfield("Moderate", $name ."_moderate", variable_get($name ."_moderate", ""), 35, 255, t("Provide a comma-seperated list of the moderators' usernames."));
    }
  }

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

  return form($REQUEST_URI, $form);
}

Dries's avatar
 
Dries committed
137
function node_admin() {
Dries's avatar
 
Dries committed
138 139
  global $op, $id, $edit, $type;

Dries's avatar
 
Dries committed
140
  print "<SMALL><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\">overview</A></SMALL><HR>\n";
Dries's avatar
 
Dries committed
141 142

  $id = check_input($edit[nid] ? $edit[nid] : $id);
Dries's avatar
 
Dries committed
143
  $type = ($type ? $type : 0);
Dries's avatar
 
Dries committed
144 145 146 147 148 149

  switch ($op) {
    case "Edit node":
    case "edit":
      print node_admin_edit($id);
      break;
Dries's avatar
 
Dries committed
150 151 152
    case "default":
      print node_setting();
      break;
Dries's avatar
 
Dries committed
153 154 155 156
    case "Delete node":
      print status(node_delete($id));
      print node_overview();
      break;
Dries's avatar
 
Dries committed
157
    case "listing":
Dries's avatar
 
Dries committed
158
      print node_listing(node_query());
Dries's avatar
 
Dries committed
159
      break;
Dries's avatar
 
Dries committed
160 161 162 163 164 165 166 167
    case "Save defaults":
      print status(conf_save($edit));
      print node_default();
      break;
    case "Reset to defaults":
      print status(conf_default($edit));
      print node_default();
      break;
Dries's avatar
 
Dries committed
168
    case "Save node":
Dries's avatar
 
Dries committed
169
      node_save($edit, array(author, comment, moderate, promote, status, timestamp));
Dries's avatar
 
Dries committed
170
      print node_admin_view($id);
Dries's avatar
 
Dries committed
171 172 173 174 175 176
      break;
    case "View node":
    case "view":
      print node_admin_view($id);
      break;
    default:
Dries's avatar
 
Dries committed
177
      print node_overview(node_query($type));
Dries's avatar
 
Dries committed
178 179 180 181
  }
}

?>