-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcenp-meios.php
212 lines (179 loc) · 6.17 KB
/
cenp-meios.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Cenp Meios
*
* @package CenpMeios
* @author Caio Felipe
* @copyright 2021 DevApps Consultoria e Desenvolvimento de Software
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Cenp Meios
* Plugin URI: https://github.com/devappsteam/cenp-meios
* Description: Efetua a importação do meios de comunicação atráves de uma matriz XLSX e disponibiliza os dados em uma página atraves de shortcode.
* Version: 1.3.2
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: DevApps Consultoria e Desenvolvimento de Software
* Author URI: https://devapps.com.br
* Text Domain: cenp-mean
*
* GitHub Plugin URI: https://github.com/devappsteam/cenp-meios
*
*/
// Verifica o acesso direto ao arquivo.
defined('ABSPATH') || exit;
// Constantes
define('CM_VERSION', '1.3.2');
define('CM_TEXT_DOMAIN', 'cenp-mean');
define('CM_PATH_ROOT', plugin_basename(__FILE__));
define('CM_PATH', plugin_dir_path(__FILE__));
define('CM_TEMPLATE_DIR', 'cenp');
register_activation_hook(
__FILE__,
'activate'
);
if (!class_exists('Cenp_Meios')) {
require_once(dirname(__FILE__) . '/includes/class-main.php');
}
function activate()
{
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
include_once("wp-config.php");
include_once("wp-includes/wp-db.php");
$version = get_option('cm_version', '0.0.1');
$table_region = $wpdb->prefix . "cm_states_region";
$table_spreadsheet = $wpdb->prefix . "cm_spreadsheets";
$table_spreadsheet_means = $wpdb->prefix . "cm_spreadsheets_means";
$table_spreadsheet_means_regions = $wpdb->prefix . "cm_spreadsheets_means_regions";
$table_spreadsheet_regions = $wpdb->prefix . "cm_spreadsheets_regions";
$table_spreadsheet_states = $wpdb->prefix . "cm_spreadsheets_states";
$table_spreadsheet_ranking = $wpdb->prefix . "cm_spreadsheets_ranking";
$table_spreadsheet_ranking_state = $wpdb->prefix . "cm_spreadsheets_ranking_state";
$table_agencies = $wpdb->prefix . "cm_spreadsheets_agencies";
$charset_collate = $wpdb->get_charset_collate();
$wpdb->query("DROP TABLE IF EXISTS `$table_region`;");
$sql = "CREATE TABLE `$table_region`(
`ID` TINYINT NOT NULL AUTO_INCREMENT,
`state` VARCHAR(50) NOT NULL,
`region` TINYINT(1) NOT NULL,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`state` VARCHAR(50) NULL,
`mean` VARCHAR(20) NOT NULL,
`real` DECIMAL(20,2) NOT NULL DEFAULT 0,
`dollar` DECIMAL(20,2) NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet_means`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`mean` VARCHAR(20) NOT NULL,
`real` VARCHAR(20) NOT NULL DEFAULT 0,
`dollar` VARCHAR(20) NOT NULL DEFAULT 0,
`share` VARCHAR(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet_regions`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`region` VARCHAR(20) NOT NULL,
`real` VARCHAR(20) NOT NULL DEFAULT 0,
`dollar` VARCHAR(20) NOT NULL DEFAULT 0,
`share` VARCHAR(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet_means_regions`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`mean` VARCHAR(20) NOT NULL,
`real` VARCHAR(20) NOT NULL DEFAULT 0,
`dollar` VARCHAR(20) NOT NULL DEFAULT 0,
`share` VARCHAR(20) NOT NULL DEFAULT 0,
`region` VARCHAR(5) NOT NULL,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet_states`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`state` VARCHAR(20) NOT NULL,
`real` VARCHAR(20) NOT NULL DEFAULT 0,
`dollar` VARCHAR(20) NOT NULL DEFAULT 0,
`share` VARCHAR(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_spreadsheet_ranking`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`position` VARCHAR(5) NULL,
`name` VARCHAR(150) NULL DEFAULT '',
`state` VARCHAR(5) NULL DEFAULT '',
PRIMARY KEY (`ID`)
) $charset_collate;";
$sql = "CREATE TABLE `$table_spreadsheet_ranking_state`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`position` VARCHAR(5) NULL,
`name` VARCHAR(150) NULL DEFAULT '',
`state` VARCHAR(5) NULL DEFAULT '',
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "CREATE TABLE `$table_agencies`(
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`post_id` BIGINT NOT NULL,
`name` VARCHAR(150) NULL DEFAULT '',
PRIMARY KEY (`ID`)
) $charset_collate;";
dbDelta($sql);
$sql = "INSERT INTO `$table_region` (`state`,`region`) VALUES
('Acre', 1),
('Alagoas', 2),
('Amazonas', 1),
('Amapá', 1),
('Bahia', 2),
('Ceará', 2),
('Distrito Federal',3),
('Espírito Santo', 4),
('Goiás', 3),
('Maranhão', 2),
('Minas Gerais', 4),
('Mato Grosso do Sul', 3),
('Mato Grosso', 3),
('Pará', 1),
('Paraíba', 2),
('Pernambuco', 2),
('Piauí', 2),
('Paraná', 5),
('Rio de Janeiro', 4),
('Rio Grande do Norte', 2),
('Rondônia', 1),
('Roraima', 1),
('Rio Grande do Sul', 5),
('Santa Catarina', 5),
('Sergipe', 2),
('São Paulo', 4),
('Tocantins', 1);";
dbDelta($sql);
if (version_compare($version, CM_VERSION, '<')) {
$sql = "ALTER TABLE `$table_spreadsheet_ranking`
ADD COLUMN `last_position` VARCHAR(5) NULL DEFAULT NULL;";
$wpdb->query($sql);
update_option('cm_version', CM_VERSION);
}
}
function init_cenp_meios()
{
return Cenp_Meios::instance();
}
add_action('plugins_loaded', 'init_cenp_meios', 20);