structure.inc 5.56 KB
Newer Older
Dries's avatar
 
Dries committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

// ----- category -----

function _category_get($field, $value) {
  return db_query("SELECT * FROM category WHERE $field = '$value'");
}

// returns the category object where $field = $value:
function category_get_object($field, $value) {
  return db_fetch_object(_category_get($field, $value));
}

// returns the category array where $field = $value:
function category_get_array($field, $value) {
  return db_fetch_array(_category_get($field, $value));
}

// save a category:
function category_save($edit) {
Dries's avatar
 
Dries committed
21 22
  if (!$edit[cid]) $edit[cid] = db_insert_id(db_query("INSERT INTO category (name) VALUES ('". check_query($edit[name])."')"));
  foreach ($edit as $key=>$value) db_query("UPDATE category SET $key = '". check_query($value) ."' WHERE cid = '$edit[cid]'");
Dries's avatar
 
Dries committed
23 24
}

25

Dries's avatar
 
Dries committed
26 27
// delete category $cid:
function category_del($cid) {
Dries's avatar
 
Dries committed
28 29
  db_query("DELETE FROM category WHERE cid = '". check_query($cid) ."'");
  db_query("UPDATE node SET cid = 0 WHERE cid = '". check_query($cid) ."'");
Dries's avatar
 
Dries committed
30 31
}

32
// return post threshold:
Dries's avatar
 
Dries committed
33
function category_post_threshold($cid) {
Dries's avatar
 
Dries committed
34
  $category = db_fetch_object(db_query("SELECT post AS threshold FROM category WHERE cid = '". check_query($cid) ."'"));
Dries's avatar
 
Dries committed
35
  return $category->threshold;
Dries's avatar
 
Dries committed
36 37
}

38
// return dump threshold:
Dries's avatar
 
Dries committed
39
function category_dump_threshold($cid) {
Dries's avatar
 
Dries committed
40
  $category = db_fetch_object(db_query("SELECT dump AS threshold FROM category WHERE cid = '". check_query($cid) ."'"));
Dries's avatar
 
Dries committed
41
  return $category->threshold;
Dries's avatar
 
Dries committed
42 43
}

44
// return expiration threshold:
Dries's avatar
 
Dries committed
45
function category_expire_threshold($cid) {
Dries's avatar
 
Dries committed
46
  $category = db_fetch_object(db_query("SELECT expire AS threshold FROM category WHERE cid = '". check_query($cid) ."'"));
Dries's avatar
 
Dries committed
47
  return $category->threshold;
Dries's avatar
 
Dries committed
48 49
}

Dries's avatar
 
Dries committed
50 51 52
// return default comment status of category $cid:
function category_comment($cid) {
  $category = category_get_object("cid", $cid);
Dries's avatar
 
Dries committed
53 54 55 56 57 58 59 60 61 62 63 64 65
  return $category->comment ? $category->comment : 0;
}

// return default promote status of category $cid:
function category_promote($cid) {
  $category = category_get_object("cid", $cid);
  return $category->promote ? $category->promote : 0;
}

// return default submission status of category $cid:
function category_submission($cid) {
  $category = category_get_object("cid", $cid);
  return $category->submission ? $category->submission : 0;
Dries's avatar
 
Dries committed
66 67
}

68 69 70 71 72 73
// return linked string with name of category $cid:
function category_name($cid) {
  $category = category_get_object("cid", $cid);
  return ($category) ? "<A HREF=\"index.php?category=$category->cid\">$category->name</A>" : "";
}

Dries's avatar
 
Dries committed
74 75 76
function category_form_select($type, $edit = array(), $size = 1) {
  $result = db_query("SELECT * FROM category WHERE type = '$type'");
  while ($category = db_fetch_object($result)) {
Dries's avatar
CHANGES  
Dries committed
77
    $options .= "<OPTION VALUE=\"$category->cid\"". ($edit[cid] == $category->cid ? "SELECTED" : "") .">". check_form($category->name) ."</OPTION>";
Dries's avatar
 
Dries committed
78
  }
Dries's avatar
 
Dries committed
79
  return "<SELECT NAME=\"edit[cid]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
Dries's avatar
 
Dries committed
80 81 82
}

// ----- topic -----
Dries's avatar
 
Dries committed
83

Dries's avatar
 
Dries committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
function _topic_get($field, $value) {
  return db_query("SELECT * FROM topic WHERE $field = '$value'");
}

// returns the topic object where $field = $value:
function topic_get_object($field, $value) {
  return db_fetch_object(_topic_get($field, $value));
}

// returns the topic array where $field = $value:
function topic_get_array($field, $value) {
  return db_fetch_array(_topic_get($field, $value));
}

// save a topic:
function topic_save($edit) {
Dries's avatar
 
Dries committed
100 101
  if (!$edit[tid]) $edit[tid] = db_insert_id(db_query("INSERT INTO topic (name) VALUES ('". check_query($edit[name])."')"));
  foreach ($edit as $key=>$value) db_query("UPDATE topic SET $key = '". check_query($value) ."' WHERE tid = '$edit[tid]'");
Dries's avatar
 
Dries committed
102 103 104 105 106 107 108 109 110 111 112 113
}

// returns a sorted tree-representation of all topics:
function topic_tree($parent = 0, $name = "", $tree = array()) {
  $result = db_query("SELECT * FROM topic WHERE pid = '$parent' ORDER BY name");
  while ($topic = db_fetch_object($result)) {
    $tree[$topic->tid] = ($name ? "$name - $topic->name" : $topic->name);
    $tree = topic_tree($topic->tid, $tree[$topic->tid], $tree);
  }
  return $tree;
}

Dries's avatar
 
Dries committed
114 115
// delete topic $tid:
function topic_del($tid) {
Dries's avatar
 
Dries committed
116 117
  db_query("DELETE FROM topic WHERE tid = '". check_query($tid) ."'");
  db_query("UPDATE node SET tid = 0 WHERE tid = '". check_query($tid) ."'");
Dries's avatar
 
Dries committed
118 119
}

120 121 122 123 124 125 126
// return linked string with name of topic $tid:
function topic_name($tid, $name = 0) {
  $topic = topic_get_object("tid", $tid);
  $name = $name ? "<A HREF=\"index.php?topic=$topic->tid\">$topic->name</A> - $name" : "<A HREF=\"index.php?topic=$topic->tid\">$topic->name</A>";
  return ($topic->pid) ? topic_name($topic->pid, $name) : $name;
}

Dries's avatar
 
Dries committed
127 128 129 130 131 132
// return moderators for topic $tid:
function topic_moderate($tid) {
  $topic = topic_get_object("tid", $tid);
  return $topic->moderate;
}

Dries's avatar
 
Dries committed
133 134
// renders a HTML form to select one or more topics:
function topic_form_select($edit = array(), $size = 1) {
Dries's avatar
 
Dries committed
135
  foreach (topic_tree() as $tid=>$name) {
Dries's avatar
CHANGES  
Dries committed
136
    $options .= "<OPTION VALUE=\"$tid\"". ($edit[tid] == $tid ? "SELECTED" : "") .">". check_form($name) ."</OPTION>";
Dries's avatar
 
Dries committed
137
  }
Dries's avatar
 
Dries committed
138
  return "<SELECT NAME=\"edit[tid]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
Dries's avatar
 
Dries committed
139 140 141 142 143 144 145 146
}

// ----- structure -----

// add node $nid to category $cid and topic $tid:
function structure_save($nid, $cid, $tid) {
  category_node($nid, $cid);
  topic_node($nid, $tid);
Dries's avatar
 
Dries committed
147 148
}

Dries's avatar
 
Dries committed
149 150 151 152
// render a HMTL selection form:
function structure_form($type, $edit = array(), $size = 1) {
  $output .= "<B>Category and topic:</B><BR>\n";
  $output .= category_form_select($type, $edit, $size) ." ". topic_form_select($edit, $size) ."<BR>";
Steven Wittens's avatar
Steven Wittens committed
153
  $output .= "<SMALL><I>". t("Select the category and the topic this submission belongs in.") ."</I></SMALL><P>";
Dries's avatar
 
Dries committed
154
  return $output;
Dries's avatar
 
Dries committed
155 156 157
}

?>