-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvisgov_wp.php
358 lines (318 loc) · 10.1 KB
/
visgov_wp.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/*
Plugin Name: Open Maine - Visual Budget Plugin
Plugin URI: https://openmaine.org/
Description: Based on the Visual Budget app developed in Arlington, MA this plugin creates an interactive
visual representation of municipal revenues, funds and spending.
Version: 1.0
Author: Rob Korobkin
Author URI: https://robkorobkin.org
License: GPLv2 or later
Text Domain: visgov_wp
Open Maine - Visual Budget Plugin is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Copyright 2005-2015 Automattic, Inc.
*/
function registerVisGovClient(){
// USE CDNs WHERE AVAILABLE
$app_dir = plugins_url('visgov_wp') . '/';
// LOAD CSS - ALWAYS LOAD
wp_register_style( 'intro-css', '//cdnjs.cloudflare.com/ajax/libs/intro.js/2.5.0/introjs.min.css', false, NULL, 'all' );
wp_register_style( 'bootstrap-css', '//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css', false, NULL, 'all' );
wp_register_style( 'vg-global-css', $app_dir . 'client/css/global.css', array('intro-css', 'bootstrap-css'), NULL, 'all' );
wp_register_style( 'vg-print-css', $app_dir . 'client/css/print.css', array('vg-global-css'), NULL, 'print' );
wp_enqueue_style( 'vg-print-css');
// REGISTER JS LIBRARIES
wp_register_script( 'bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), NULL, true );
wp_register_script( 'mustache-js', '//cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.min.js', false, NULL, true );
wp_register_script( 'd3-js', $app_dir . 'client/_lib/d3.v3.min.js', array('jquery'), NULL, true );
wp_register_script( 'detectmobilebrowser-js', $app_dir . 'client/_lib/detectmobilebrowser.js',false, NULL, true );
wp_register_script( 'jquerycookie-js', $app_dir . 'client/_lib/jquery.cookie.js', array('jquery'), NULL, true );
wp_register_script( 'intro-js', '//cdnjs.cloudflare.com/ajax/libs/intro.js/2.5.0/intro.min.js', array('jquery'), NULL, true );
// REGISTER APP SCRIPTS
wp_register_script( 'vg-treemap-js', $app_dir . 'client/js/treemap.js',false, NULL, true );
wp_register_script( 'vg-chart-js', $app_dir . 'client/js/chart.js',false, NULL, true );
wp_register_script( 'vg-cards-js', $app_dir . 'client/js/cards.js',false, NULL, true );
wp_register_script( 'vg-table-js', $app_dir . 'client/js/table.js',false, NULL, true );
wp_register_script( 'vg-navbar-js', $app_dir . 'client/js/navbar.js',false, NULL, true );
wp_register_script( 'vg-statistic-js', $app_dir . 'client/js/statistics.js',false, NULL, true );
wp_register_script( 'vg-home-js', $app_dir . 'client/js/home.js',false, NULL, true );
// REGISTER MASTER APP FILE
wp_register_script( 'vg-avb-js', $app_dir . 'client/js/avb.js',
array( 'bootstrap-js', 'mustache-js', 'd3-js', 'detectmobilebrowser-js', 'jquerycookie-js', 'intro-js',
'vg-treemap-js', 'vg-chart-js', 'vg-cards-js', 'vg-table-js', 'vg-navbar-js', 'vg-statistic-js', 'vg-home-js'),
NULL, true );
}
add_action( 'wp_enqueue_scripts', 'registerVisGovClient' );
/*******************************************************
* BUDGETS - CUSTOM POST TYPES AND FIELDS
*
*******************************************************/
// include ACF without plugin
// define( 'ACF_LITE', true ); // this would disable ACF
include_once('advanced-custom-fields/acf.php');
function cptui_register_my_cpts_budget() {
$labels = array(
"name" => __( "Budgets", "openmaine" ),
"singular_name" => __( "Budget", "openmaine" ),
);
$args = array(
"label" => __( "Budgets", "openmaine" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "budget", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "thumbnail" ),
);
register_post_type( "budget", $args );
}
add_action( 'init', 'cptui_register_my_cpts_budget' );
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_budget-fields',
'title' => 'Budget Fields',
'fields' => array (
array (
'key' => 'field_599baba6391b3',
'label' => 'Basic',
'name' => '',
'type' => 'tab',
),
array (
'key' => 'field_599bd1af40f31',
'label' => 'Page Title',
'name' => 'page_title',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599ba1af50d17',
'label' => 'Slug',
'name' => 'slug',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599ba04ab1d73',
'label' => 'Budget Sections',
'name' => 'sections',
'type' => 'checkbox',
'choices' => array (
'revenues' => 'Revenues',
'expenses' => 'Expenses',
'assets' => 'Assets',
'funds' => 'Funds & Reserves'
),
'default_value' => '',
'layout' => 'vertical',
),
array (
'key' => 'field_59a8751c46daf',
'label' => 'Loaded Section',
'name' => 'loaded_section',
'type' => 'select',
'choices' => array (
'expenses' => 'Expenses',
'revenues' => 'Revenues',
'funds' => 'Funds & Reserves',
),
'default_value' => 'expenses',
'allow_null' => 0,
'multiple' => 0,
),
array (
'key' => 'field_599baa7d0e0c3',
'label' => 'Include Taxes',
'name' => 'include_taxes',
'type' => 'true_false',
'message' => '',
'default_value' => 0,
),
array (
'key' => 'field_599bca1796814',
'label' => 'Info Source - Name',
'name' => 'info_source_name',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599bc8c68678e',
'label' => 'Info Source - URL',
'name' => 'info_source_url',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599baa3603230',
'label' => 'Home Overlay',
'name' => '',
'type' => 'tab',
),
array (
'key' => 'field_599bab1cb9349',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599b586155f17',
'label' => 'Intro Paragraph',
'name' => 'header_html',
'type' => 'wysiwyg',
'default_value' => '',
'toolbar' => 'full',
'media_upload' => 'yes',
),
array (
'key' => 'field_599bab4a10f27',
'label' => 'Tax Description',
'name' => 'tax_description',
'type' => 'text',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_599baa7d0e0c3',
'operator' => '==',
'value' => '1',
),
),
'allorany' => 'all',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_599bab7854811',
'label' => 'Budget Questions',
'name' => 'budget_questions',
'type' => 'textarea',
'default_value' => '',
'placeholder' => '',
'maxlength' => '',
'rows' => '',
'formatting' => 'br',
),
array (
'key' => 'field_599b587255f18',
'label' => 'Custom JS',
'name' => 'custom_js',
'type' => 'textarea',
'default_value' => '',
'placeholder' => '',
'maxlength' => '',
'rows' => 20,
'formatting' => 'none',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'budget',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
/*******************************************************
* SHORT CODES
*
*******************************************************/
function visgov_wp_template_main($atts){
global $selected_budget, $wpdb;
// FETCH SELECTED BUDGET
if(!isset($atts['budget'])) {
echo "No budget specified.";
return;
}
$sql = $wpdb->prepare(
"SELECT post_id FROM " . $wpdb -> postmeta . " where meta_key='slug' && meta_value=%s",
$atts['budget']
);
$budget_id = $wpdb->get_var($sql);
if($budget_id === NULL) {
echo "Budget not found: " . $atts['budget'];
return;
}
$selected_budget = get_post($budget_id);
$meta = get_post_custom($budget_id);
$selected_budget -> meta = array();
foreach($meta as $k => $v){
if($k[0] == '_') continue;
if($k == "sections") $selected_budget -> meta[$k] = unserialize($v[0]);
else $selected_budget -> meta[$k] = $v[0];
}
// LOAD APP JS
wp_enqueue_script('vg-avb-js');
// RENDER TEMPLATE
include(dirname(__FILE__) . '/index.php');
}
add_shortcode( 'visgov', 'visgov_wp_template_main' );
function visgov_wp_template_glossary(){
wp_enqueue_style( 'vg-print-css');
$_GET["page"] = "glossary";
include(dirname(__FILE__) . '/includes/glossary.php');
}
add_shortcode( 'visgov_glossary', 'visgov_wp_template_glossary' );