summaryrefslogtreecommitdiff
path: root/modules/page.module
blob: e39a432efe4f9726a9c8dfe54352a1dd1df38148 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// $Id$

function page_help() {
  $output .= "<p>The page module is used to create a <i>site page</i>.  Unlike a story, a site page is a persistent web page on your site which usually shortcuts the typical lifecycle of user generated content (i.e. submit -&gt; moderate -&gt; post -&gt; comment).  A site page is usually linked from the main navigation bar, using whatever text the author wishes.  To create a site page without this navigation link, simply skip the form field which requests link text.  Administrators are the exclusive authors of site pages (i.e. requires the <i>adinister nodes</i> in <a href=\"/admin.php?mod=user&op=permission\">permission</a>).</p>";
  $output .= "<p>Site pages, unlike many other forms of Drupal content, may be made of PHP code in addition to HTML and text. All Drupal objects and functions are available to the Site Page author.</p>";
  return $output;
}

function page_node($field) {
  $info["name"] = t("site page");
  $info["description"] = t("If you just want to add a page with a link in the menu to your site, this would be the best choice.  Unlike a story, a site page by-passes the submission queue.");

  return $info[$field];
}

function page_access($op, $node) {
  if ($op == "view") {
    return $node->status;
  }
}

function page_save($op, $node) {

  if ($op == "approve") {
    return array("status" => 1);
  }

  if ($op == "create") {
    return array("format", "link");
  }

  if ($op == "decline") {
    return array("status" => 0);
  }

  if ($op == "update") {
    return array("format", "link");
  }
}

function page_insert($node) {
  db_query("INSERT INTO page (nid, format, link) VALUES ('$node->nid', '$node->format', '$node->link')");
}

function page_update($node) {
  db_query("UPDATE page SET format = '$node->format', link = '$node->link' WHERE nid = '$node->nid'");
}

function page_delete(&$node) {
  db_query("DELETE FROM page WHERE nid = '$node->nid'");
}

function page_load($node) {
  $page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'"));

  return $page;
}

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

  if ($type == "menu.create" && user_access("administer nodes")) {
    $links[] = "<a href=\"module.php?mod=node&op=add&type=page\" title=\"". t("Add a new site page.") ."\">". t("create site page") ."</a>";
  }

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

function page_body($node) {
  global $theme, $op;

  if ($node->format) {
    /*
    ** Make sure only authorized users can preview static (PHP)
    ** pages.
    */

    if ($op == t("Preview")) {
      if (user_access("administer nodes")) {
        $node->body = stripslashes($node->body);  // see also page_form()
      }
      else {
        return;
      }
    }

    ob_start();
    eval($node->body);
    $output = ob_get_contents();
    ob_end_clean();
  }
  else {
    $output = check_output($node->body, 1);
  }

  return $output;
}

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

  if ($main) {
    $theme->node($node, $main);    
  }
  else {
    /*
    ** Extract the page body.  If body is dynamic (using PHP code), the body
    ** will be generated.
    */
  
    $output .= page_body($node);
  
    /*
    ** Add the node specific links:
    */
  
    $output .= "<div align=\"right\">". $theme->links(link_node($node, $main)) ."</div>";
  
    $theme->box($node->title, $output);
  }
}

function page_form(&$node, &$help, &$error) {
  global $op;

  if ($node->format) {
    if ($op != t("Preview")) {
      $node->body = addslashes($node->body);
    }
  }
  else {
    if ($node->teaser) {
      $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
    }
  }

  $output .= form_textarea("Body", "body", $node->body, 60, 20);
  $output .= form_textfield("Link", "link", $node->link, 60, 64);
  $output .= form_select("Type", "format", $node->format, array(0 => "HTML / text", 1 => "PHP"));

  return $output;
}

?>