summaryrefslogtreecommitdiff
path: root/modules/page/page.module
blob: 01deece17627ddf13b80b8cdd26fa507fdb9c080 (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
<?php

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

class Page {
  function Page($page) {
    $this = new Node($page);
    $this->body = $page["body"];
    $this->format = $page["format"];
  }
}

function page_link($type) {
  if ($type == "page") {
    $result = db_query("SELECT nid,link FROM page WHERE link != '' ORDER BY link");
    while ($page = db_fetch_object($result)) {
      $links[] = "<a href=\"node.php?id=$page->nid\">$page->link</a>";
    }
  }

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

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

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

}

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

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

  if ($op != t("Preview") && $format[$edit["format"]] == "PHP") {
    $edit["body"] = addslashes($edit["body"]);
  }

  if ($edit["title"]) {
    $form = page_view(new Page(node_preview($edit)));
  }

  $form .= form_textfield("Subject", "title", $edit["title"], 50, 64);
  $form .= form_textfield("Link", "link", $edit["link"], 50, 64);
  $form .= form_textarea("Body", "body", $edit["body"], 70, 30);
  $form .= form_select("Type", "format", $edit["format"], $format);
  $form .= form_hidden("nid", $edit["nid"]);

  if ($edit["title"]) {
    $form .= form_submit(t("Preview"));
    $form .= form_submit(t("Submit"));
  }
  else {
    $form .= form_submit(t("Preview"));
  }

  return form($form);
}

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

  node_save($edit, array(author => $user->uid, link, body, comment => variable_get("page_comment", 0), format, moderate => variable_get("page_moderate", ""), promote => variable_get("page_promote", 0), score => 0, status => $status["posted"], timestamp => time(), title, type => "page", votes => 0));
}

?>