forum.module 3.27 KB
Newer Older
Dries's avatar
   
Dries committed
1
2
3
<?php
// $Id$

4
function forum_system($field){
5
  $system["description"] = t("Allows threaded discussions about general topics.");
6
7
8
  return $system[$field];
}

Dries's avatar
   
Dries committed
9
10
11
12
13
14
15
16
17
18
19
20
21
function forum_node($field) {
  $info["name"] = t("discussion forum");
  $info["description"] = t("A forum is a threaded discussion, enabling users to communicate about a particular topic.");

  return $info[$field];
}

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

Dries's avatar
   
Dries committed
22
23
function forum_save($op, $node) {

Dries's avatar
   
Dries committed
24
25
26
27
28
  if ($op == "approve") {
    return array("status" => 1);
  }

  if ($op == "create") {
29
    return array("body" => filter($node->body), "teaser" => filter($node->teaser));
Dries's avatar
   
Dries committed
30
31
  }

Dries's avatar
   
Dries committed
32
33
  if ($op == "decline") {
    return array("status" => 0);
Dries's avatar
   
Dries committed
34
35
36
  }

  if ($op == "update") {
37
    return array("body" => filter($node->body), "teaser" => filter($node->teaser));
Dries's avatar
   
Dries committed
38
39
40
41
42
  }
}

function forum_link($type) {
  if ($type == "page" && user_access("access content")) {
Kjartan's avatar
Kjartan committed
43
    $links[] = lm(t("forum"), array("mod" => "forum"), "", array("title" => t("Read and participate in the discussion forums.")));
Dries's avatar
   
Dries committed
44
45
  }

Dries's avatar
   
Dries committed
46
  if ($type == "menu.create" && user_access("administer nodes")) {
Kjartan's avatar
Kjartan committed
47
    $links[] = lm(t("create forum"), array("mod" => "node", "op" => "add", "type" => "forum"), "", array("title" => t("Add a new discussion forum.")));
Dries's avatar
   
Dries committed
48
49
  }

Dries's avatar
   
Dries committed
50
51
52
53
54
  return $links ? $links : array();
}

function forum_view($node) {
  global $theme;
Kjartan's avatar
Kjartan committed
55
  $output .= "<p>". lm(t("Forum"), array("mod" => "forum")) ." / <b>". l(check_output($node->title), array("id" => $node->nid)) ."</b>:</p><p>". check_output($node->body) ."</p>";
Dries's avatar
   
Dries committed
56
57
  $output .= "<p>". $theme->links(link_node($node, $main)) ."</p>";

Dries's avatar
   
Dries committed
58
59
60
61
62
  $theme->box(t("Discussion forum"), $output);
}

function forum_form(&$node, &$help, &$error) {

63
64
65
66
  if (function_exists("taxonomy_node_form")) {
    $output = implode("", taxonomy_node_form("forum", $node));
  }

Dries's avatar
   
Dries committed
67
  $output .= form_textarea(t("Body"), "body", $node->body, 60, 10);
Dries's avatar
   
Dries committed
68
69
70
71
72
73

  return $output;
}


function forum_num_comments($nid) {
Dries's avatar
   
Dries committed
74
  $value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE nid = '$nid'"));
Dries's avatar
   
Dries committed
75
76
77
78
  return ($value) ? $value->count : 0;
}

function forum_last_comment($nid) {
Dries's avatar
   
Dries committed
79
  $value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE nid = '$nid' ORDER BY timestamp DESC LIMIT 1"));
Dries's avatar
   
Dries committed
80
81
82
83
84
85
86
87
88
89
90
91
92
  return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
}

function forum_page() {
  global $theme;

  if (user_access("access content")) {
    $result = db_query("SELECT nid FROM node WHERE type = 'forum' ORDER BY title");

    $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">";
    $output .= " <tr><th>". t("Forum") ."</th><th>". t("Comments") ."</th><th>". t("Last comment") ."</th></tr>";
    while ($node = db_fetch_object($result)) {
      $node = node_load(array("nid" => $node->nid));
Kjartan's avatar
Kjartan committed
93
      $output .= " <tr><td>". l(check_output($node->title), array("id" => $node->nid)) ."<br /><small>". check_output($node->body, 1) ."</small></td><td align=\"center\">". forum_num_comments($node->nid) ."</td><td align=\"center\">". forum_last_comment($node->nid) ."</td></tr>";
Dries's avatar
   
Dries committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    }
    $output .= "</table>";

    $theme->header();
    $theme->box(t("Discussion forum"), $output);
    $theme->footer();
  }
  else {
    $theme->header();
    $theme->box(t("Access denied"), message_access());
    $theme->footer();
  }
}

Dries's avatar
 
Dries committed
108
?>