summaryrefslogtreecommitdiff
path: root/modules/page/page.module
blob: f9e59ed722347bbb09e8773b1cc625d55c8d8cfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

$GLOBALS[format] = array(0 => "HTML", 1 => "PHP", 2 => "text");

function page_view($node, $main = 0) {
  global $format, $theme;

  switch ($format[$node->format]) {
    case "PHP":
      $output = eval($node->body);
      break;
    case "text":
      $output = nl2br(htmlentities($node->body));
      break;
    default:
      $output = check_output($node->body, 1);
  }

  $theme->box(check_output($node->title), $output);
}

function page_status() {
  return array(dumped, posted);
}

function page_form($edit = array()) {
  global $format, $REQUEST_URI;

  $form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64);
  $form .= structure_form("page", $edit);
  $form .= form_textarea(t("Body"), "body", $edit[body], 50, 10);
  $form .= form_select(t("Type"), "format", $edit[format], $format);
  $form .= form_hidden("nid", $edit[nid]);
  $form .= form_submit(t("Submit"));

  return form($REQUEST_URI, $form);
}

function page_save($edit) {
  global $status, $user;

  if (user_access($user)) {
    node_save($edit, array(author => $user->id, body, cid, comment => category_comment($edit[cid]), format, moderate => topic_moderate($edit[tid]), promote => category_promote($edit[cid]), score => 0, status => $status[posted], tid, timestamp => time(), title, type => "page", votes => 0));
  }
}

function page_query($type = "") {
  global $status;
  $queries =  array(array("recent pages", "WHERE n.type = 'page' ORDER BY n.timestamp DESC"), array("posted pages", "WHERE n.type = 'page' AND n.status = '$status[posted]' ORDER BY n.timestamp DESC"), array("dumped pages", "WHERE n.type = 'page' AND n.status = '$status[dumped]' ORDER BY n.timestamp DESC"));
  return ($queries[$type] ? $queries[$type] : $queries);
}

function page_overview($query = array()) {
  return node_overview($query);
}

function page_admin() {
  global $id, $op, $edit, $type;

  print "<SMALL><A HREF=\"admin.php?mod=page&op=add\">add new page</A> | <A HREF=\"admin.php?mod=page&op=listing\">page listing</A> | <A HREF=\"admin.php?mod=page\">overview</A></SMALL><HR>\n";

  $type = ($type ? $type : 0);

  switch ($op) {
    case "add":
      print page_form();
      break;
    case "edit":
      print page_form(node_get_array(array(nid => $id)));
      break;
    case "listing":
      print node_listing(page_query());
      break;
   case t("Submit"):
      print status(page_save($edit));
      // fall through:
    default:
      print page_overview(page_query($type));
  }
}

?>