/[drupal]/contributions/modules/tribune/tribune.moderation.inc
ViewVC logotype

Contents of /contributions/modules/tribune/tribune.moderation.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Fri Nov 28 10:22:53 2008 UTC (11 months, 4 weeks ago) by seeschloss
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +42 -20 lines
File MIME type: text/x-php
2.0 dev with tribunes as nodes... somewhat working
1 <?php
2 // vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
3 // $Id: tribune.moderation.inc,v 1.4 2008/08/30 22:51:38 seeschloss Exp $
4
5 function tribune_delete_post($id, $node) {
6 db_query("UPDATE {tribune}
7 SET last_modified = %d, moderated = 1
8 WHERE post_id = %d
9 AND tribune_id = %d",
10 time(),
11 $id,
12 $node->nid);
13 return t("Post number !id was moderated", array("!id" => $id));
14 }
15
16 function tribune_undelete_post($id, $node) {
17 db_query("UPDATE {tribune}
18 SET last_modified = %d, moderated = 0
19 WHERE post_id = %d
20 AND tribune_id = %d",
21 time(),
22 $id,
23 $node->nid);
24 return t("Post number !id was restored", array("!id" => $id));
25 }
26
27 function tribune_moderation_form($form, $node) {
28 $form = array();
29
30 $form['tribune_id'] = array(
31 '#type' => 'value',
32 '#value' => $node->nid,
33 );
34
35 $form['ban_expressions'] = array(
36 '#type' => 'fieldset',
37 '#description' => t("All these boxes can contain any number of regular expressions (parsed with <code>!php_url</code>), one pattern per line. Posts which match any of these patterns will be silently dropped (the patterns are not case-sensitive).<br />For example, <code>Mozilla/4</code> in the 'Banned useragents' box will ban all Internet Explorer users.", array('!php_url' => l('preg_match', 'http://php.net/preg_match'))),
38 );
39 $form['ban_expressions']['banned_useragents'] = array(
40 '#type' => 'textarea',
41 '#title' => t("Banned useragents"),
42 '#default_value' => tribune_get_option($node, 'banned_useragents'),
43 );
44 $form['ban_expressions']['banned_logins'] = array(
45 '#type' => 'textarea',
46 '#title' => t("Banned usernames"),
47 '#default_value' => tribune_get_option($node, 'banned_usernames'),
48 );
49 $form['ban_expressions']['banned_messages'] = array(
50 '#type' => 'textarea',
51 '#title' => t("Banned expressions"),
52 '#default_value' => tribune_get_option($node, 'banned_messages'),
53 );
54 $form['ban_expressions']['submit'] = array(
55 '#type' => 'submit',
56 '#value' => t('Save'),
57 );
58
59 if (tribune_access("delete moderated posts", $node)) {
60 $nb_moderated = db_result(db_query("SELECT COUNT(*) FROM {tribune} WHERE moderated = 1 AND tribune_id = %d", array($node->nid)));;
61 $form['delete_moderated'] = array(
62 '#type' => 'fieldset',
63 '#title' => t("Delete all moderated messages"),
64 '#collapsible' => TRUE,
65 '#collapsed' => TRUE,
66 '#description' => t('All currently moderated messages will be definitively deleted from the database. They will not disappear from the moderators\'s opened tribunes however, this is a limitation of Ajax reloading, but trying to restore them will not do anything. There are currently <strong>!nb</strong> moderated messages.', array('!nb' => $nb_moderated)),
67 );
68 $form['delete_moderated']['delete_moderated'] = array(
69 '#type' => 'submit',
70 '#value' => t('Delete all moderated messages'),
71 '#submit' => array('tribune_delete_moderated_messages'),
72 );
73 }
74
75 if (tribune_access("delete all posts", $node)) {
76 $form['purge_tribune'] = array(
77 '#type' => 'fieldset',
78 '#title' => t("Delete all messages"),
79 '#collapsible' => TRUE,
80 '#collapsed' => TRUE,
81 '#description' => t('<strong>All</strong> the tribune messages will be <strong>definitively</strong> deleted, use with caution.'),
82 );
83 $form['purge_tribune']['purge_tribune'] = array(
84 '#type' => 'submit',
85 '#value' => t('Delete all messages'),
86 '#submit' => array('tribune_delete_all_messages'),
87 );
88 }
89
90 return $form;
91 }
92
93 function tribune_moderation_form_submit($form, $form_values) {
94 $tribune_id = $form_values['values']['tribune_id'];
95
96 tribune_set_option($tribune_id, "banned_useragents", $form_values['values']['banned_useragents']);
97 tribune_set_option($tribune_id, "banned_usernames", $form_values['values']['banned_usernames'] );
98 tribune_set_option($tribune_id, "banned_messages", $form_values['values']['banned_messages'] );
99
100 drupal_set_message(t("The banned patterns have been updated."), "status");
101 }
102
103 function tribune_delete_moderated_messages($form, $form_values) {
104 $tribune_id = $form_values['values']['tribune_id'];
105
106 db_query("DELETE FROM {tribune}
107 WHERE moderated = 1
108 AND tribune_id = %d",
109 array($tribune_id)
110 );
111
112 drupal_set_message(t("All moderated messages have been deleted."), "status");
113 }
114
115 function tribune_delete_all_messages() {
116 $tribune_id = $form_values['values']['tribune_id'];
117
118 db_query("DELETE FROM {tribune}
119 WHERE tribune_id = %d",
120 array($tribune_id)
121 );
122
123 drupal_set_message(t("ALL the messages have been deleted."), "status");
124 }
125

  ViewVC Help
Powered by ViewVC 1.1.2