-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpgp.php
175 lines (163 loc) · 6.2 KB
/
wpgp.php
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php /* -*- Mode: php; c-basic-offset:4; -*- */
/* Copyright (C) 2011 Governo do Estado do Rio Grande do Sul
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Plugin Name: WpGP
Plugin URI: http://trac.gabinetedigital.rs.gov.br
Description: Wordpress Government Participation Plugin
Version: 0.2.0
Author URI: http://gabinetedigital.rs.gov.br
License: AGPL3
*/
define('WPGP_GOVR_THEME_TABLE','wpgp_govr_themes');
define('WPGP_GOVR_CONTRIB_TABLE','wpgp_govr_contribs');
define('WPGP_GOVR_CONTRIBC_TABLE', 'wpgp_govr_contrib_children');
define('WPGP_GOVR_USER_VOTES', 'wpgp_govr_user_votes');
define('WPGP_GOVP_SESSION_TABLE','wpgp_govp_sessions');
define('WPGP_GOVP_CONTRIB_TABLE','wpgp_govp_contribs');
define('WPGP_GOVP_CONTRIBC_TABLE', 'wpgp_govp_contrib_children');
define('WPGP_GOVP_THEME_TABLE','wpgp_govp_themes');
define('WPGP_GOVE_AUDIENCE_TABLE', 'wpgp_gove_audiences');
define('WPGP_RESULTS_PER_PAGE', 50);
include_once('wpgp.templating.php');
include_once('wpgp.util.php');
include_once('wpgp.db.govr.php');
include_once('wpgp.db.govp.php');
include_once('wpgp.db.gove.php');
include_once('wpgp.admin.panel.php');
include_once('wpgp.ajax.govr.php');
include_once('wpgp.ajax.govp.php');
include_once('wpgp.ajax.gove.php');
include_once('wpgp.xmlrpc.php');
function wpgp_install() {
add_role('wpgp_moderator', 'Moderador',
array('read' => true,
'moderate_contrib' => true));
$role_object = get_role('administrator');
$role_object->add_cap('moderate_contrib');
global $wpdb;
$sql = "CREATE TABLE " . WPGP_GOVR_THEME_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
name varchar(1000) NOT NULL,
created_at DATETIME,
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE " . WPGP_GOVR_CONTRIB_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
title varchar(256) NOT NULL,
category varchar(256) NOT NULL,
theme_id int NOT NULL,
content text NOT NULL,
user_id int(11) NOT NULL,
original text,
created_at datetime,
answered_at datetime,
status enum('pending','blocked','approved','responded') default 'pending',
deleted int default 0,
parent int default 0,
created_by_moderation int default 0,
score float default 0,
answer text,
data varchar(256),
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE ". WPGP_GOVR_CONTRIBC_TABLE. " (
inverse_id int not null,
children_id int not null,
PRIMARY KEY (inverse_id,children_id),
KEY contrib_children_inverse_fk (children_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE ". WPGP_GOVR_USER_VOTES . " (
user_id int not null,
contrib_id int not null,
date datetime,
PRIMARY KEY (user_id,contrib_id),
KEY user_votes_user_fk (contrib_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE ". WPGP_GOVP_SESSION_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
name varchar(1000) NOT NULL,
active int default 0,
created_at DATETIME,
pairwise_url varchar(1000),
pairwise_db_host varchar(1000),
pairwise_db_name varchar(1000),
pairwise_db_user varchar(1000),
pairwise_db_pass varchar(1000),
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE " . WPGP_GOVP_THEME_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
session_id int NOT NULL,
name varchar(1000) NOT NULL,
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE " . WPGP_GOVP_CONTRIB_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
title varchar(1000) NOT NULL,
theme_id int NOT NULL,
content text NOT NULL,
user_id int(11) NOT NULL,
original text,
created_at datetime,
status enum('pending','approved') default 'pending',
deleted int default 0,
parent int default 0,
created_by_moderation int default 0,
score float default 0,
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE ". WPGP_GOVP_CONTRIBC_TABLE. " (
inverse_id int not null,
children_id int not null,
PRIMARY KEY (inverse_id,children_id),
KEY contrib_children_inverse_fk (children_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE ". WPGP_GOVE_AUDIENCE_TABLE . " (
id int NOT NULL AUTO_INCREMENT,
title varchar(256) NOT NULL,
subject TEXT,
description TEXT,
date datetime NOT NULL,
created_at datetime,
started_at datetime,
visible boolean,
started boolean,
data varchar(256),
UNIQUE KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
error_log($sql);
$wpdb->query ($sql);
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
function wpgp_uninstall() {
remove_role('wpgp_moderator');
$role_object = get_role('administrator');
$role_object->remove_cap('moderate_contrib');
/* //...really, don't drop it */
/* global $wpdb; */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVR_THEME_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVR_CONTRIB_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVP_SESSION_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVP_CONTRIB_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVP_THEME_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVR_CONTRIBC_TABLE); */
/* $wpdb->query ("DROP TABLE IF EXISTS ".WPGP_GOVP_CONTRIBC_TABLE); */
}
register_activation_hook(__FILE__, 'wpgp_install');
register_deactivation_hook(__FILE__, 'wpgp_uninstall');
?>