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

natrak's avatar
Fixes    
natrak committed
3
include_once "includes/common.inc";
Dries's avatar
   
Dries committed
4

Dries's avatar
CHANGES    
Dries committed
5
page_header();
Dries's avatar
   
Dries committed
6

Dries's avatar
   
Dries committed
7
function node_render($node) {
Dries's avatar
   
Dries committed
8
  global $id, $cid, $op, $moderate, $pid, $edit, $theme, $mode, $order, $threshold, $PHP_SELF;
Dries's avatar
   
Dries committed
9

Dries's avatar
   
Dries committed
10
  if (user_access("access content")) {
Dries's avatar
   
Dries committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

    if ($node->comment) {
      switch($op) {
        case t("Preview comment"):
          $theme->header();
          comment_preview($edit);
          $theme->footer();
          break;
        case t("Post comment"):
          comment_post($edit);
          $theme->header();
          node_view($node);
          comment_render($edit[id], $cid);
          $theme->footer();
          break;
        case t("Add comment"):
          $theme->header();
Dries's avatar
   
Dries committed
28
          comment_reply(check_query($cid), check_query($id));
Dries's avatar
   
Dries committed
29
30
31
32
          $theme->footer();
          break;
        case "reply":
          $theme->header();
Dries's avatar
   
Dries committed
33
          comment_reply(check_query($pid), check_query($id));
Dries's avatar
   
Dries committed
34
35
36
          $theme->footer();
          break;
        case t("Update settings"):
Dries's avatar
   
Dries committed
37
          comment_settings(check_query($mode), check_query($order), check_query($threshold));
Dries's avatar
   
Dries committed
38
39
40
41
42
          $theme->header();
          node_view($node);
          comment_render($id, $cid);
          $theme->footer();
          break;
Dries's avatar
   
Dries committed
43
44
45
        case t("Update ratings"):
          node_moderate($moderate["node"]);
          comment_moderate($moderate["comment"]);
Dries's avatar
   
Dries committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
          $theme->header();
          node_view($node);
          comment_render($id, $cid);
          $theme->footer();
          break;
        default:
          $theme->header();
          node_view($node);
          comment_render($id, $cid);
          $theme->footer();
      }
    }
    else {
      $theme->header();
      node_view($node);
      $theme->footer();
Dries's avatar
   
Dries committed
62
63
64
65
    }
  }
  else {
    $theme->header();
Dries's avatar
   
Dries committed
66
    $theme->box(t("Access denied"), message_access());
Dries's avatar
   
Dries committed
67
68
69
70
    $theme->footer();
  }
}

Dries's avatar
   
Dries committed
71
72
73
function node_failure() {
  global $theme;
  $theme->header();
Dries's avatar
   
Dries committed
74
  $theme->box(t("Not found"), t("The node you are looking for does not exist yet or is no longer accessible.") ."\n");
Dries's avatar
   
Dries committed
75
76
77
  $theme->footer();
}

Dries's avatar
   
Dries committed
78
function node_history($node) {
Dries's avatar
   
Dries committed
79
  if ($node->status == node_status("expired") || $node->status == node_status("posted")) {
Dries's avatar
   
Dries committed
80
    $output .= "<dt><b>". format_date($node->timestamp) ." by ". format_name($node) .":</b></dt><dd>". check_output($node->log, 1) ."<p /></dd>";
Dries's avatar
   
Dries committed
81
82
  }
  if ($node->pid) {
83
    $output .= node_history(node_get_object(array("nid" => $node->pid)));
Dries's avatar
   
Dries committed
84
85
  }
  return $output;
Dries's avatar
   
Dries committed
86
87
}

Dries's avatar
   
Dries committed
88
$number = ($title ? db_num_rows(db_query("SELECT nid FROM node WHERE title = '$title' AND status = '". node_status("posted") ."'")) : 1);
Dries's avatar
   
Dries committed
89

Dries's avatar
   
Dries committed
90
if ($number > 1) {
Dries's avatar
   
Dries committed
91
  $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.title = '$title' AND n.status = '". node_status("posted") ."' ORDER BY timestamp DESC");
Dries's avatar
   
Dries committed
92
93

  while ($node = db_fetch_object($result)) {
Dries's avatar
   
Dries committed
94
    if (node_access($node)) {
Dries's avatar
   
Dries committed
95
      $output .= "<p><b><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></b><br /><small>$node->type - ". format_name($node) ." - ". format_date($node->timestamp, "small") ."</small></p>";
Dries's avatar
   
Dries committed
96
    }
Dries's avatar
   
Dries committed
97
  }
Dries's avatar
   
Dries committed
98

Dries's avatar
   
Dries committed
99
  $theme->header();
Dries's avatar
   
Dries committed
100
  $theme->box(t("Result"), $output);
Dries's avatar
   
Dries committed
101
102
  $theme->footer();
}
Dries's avatar
   
Dries committed
103
elseif ($number) {
104
  $node = ($title ? node_get_object(array("title" => $title, "status" => node_status("posted"))) : node_get_object(array("nid" => ($edit[id] ? $edit[id] : $id))));
Dries's avatar
   
Dries committed
105
  if ($node && node_access($node)) {
Dries's avatar
   
Dries committed
106
107
108
    switch ($op) {
      case "history":
        $theme->header();
109
        $theme->box(t("History"), node_control($node) ."<dl>". node_history($node) ."</dl>");
Dries's avatar
   
Dries committed
110
111
112
        $theme->footer();
        break;
      default:
Dries's avatar
   
Dries committed
113
        node_render($node);
Dries's avatar
   
Dries committed
114
115
    }
  }
Dries's avatar
   
Dries committed
116
117
118
119
120
121
  else {
    node_failure();
  }
}
else {
  node_failure();
Dries's avatar
   
Dries committed
122
}
Dries's avatar
   
Dries committed
123

Dries's avatar
CHANGES    
Dries committed
124
page_footer();
Dries's avatar
   
Dries committed
125

Dries's avatar
   
Dries committed
126
?>