-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
475 lines (385 loc) · 13.9 KB
/
functions.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<?php
include __DIR__ . '/includes/Marmoset.class.php';
class Marmoset_Theme {
/** Tracked in option tables, used to flush rewrite rules. */
const REWRITE_VERSION = 2;
public $found_members = array();
public $found_stakeholders = array();
public $found_statuses = array();
/**
* The initially-queried status.
*/
public $queried_status;
/**
* The initially-queried queue.
*/
public $queried_queue;
public function init() {
if( !is_admin() ) {
wp_enqueue_script( 'marmoset-js', get_bloginfo('template_directory') . '/marmoset.js', array('jquery-ui-183', 'jquery-hotkeys'), 1311087215, true );
wp_enqueue_style( 'marmoset-960', get_bloginfo('template_directory') . '/960.css' );
wp_enqueue_style( 'colorbox-theme6', get_bloginfo('template_directory') . '/js/colorbox/theme6/colorbox.css' );
wp_enqueue_style( 'marmoset-style', get_bloginfo('template_directory') . '/style.css', 'marmoset-960', 1310760789 );
wp_enqueue_script( 'jquery-ui-183', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js', array('jquery'), '1.8.3', true );
wp_deregister_script( 'jquery-hotkeys' );
wp_enqueue_script( 'jquery-hotkeys', get_bloginfo('template_directory') . '/js/jquery.hotkeys.js', array('jquery'), '0.8', true );
wp_enqueue_script( 'jquery-history', get_bloginfo('template_directory') . '/js/jquery.history.js', array('jquery'), '1', true );
wp_deregister_script( 'jquery-colorbox' );
wp_enqueue_script( 'jquery-colorbox', get_bloginfo('template_directory') . '/js/colorbox/jquery.colorbox-min.js', array('jquery'), '1.3.15', true );
wp_deregister_script( 'jquery-pubsub' );
wp_enqueue_script( 'jquery-pubsub', get_bloginfo('template_directory') . '/js/jq.pubsub.js', array('jquery'), '1', true );
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js', false, '1.4.4', true);
wp_enqueue_script( 'jquery' );
wp_register_script( 'jquery-blockui', 'https://www.plymouth.edu/js/jquery-plugins/jquery.blockui.js', false, '2', true);
wp_enqueue_script( 'jquery-blockui' );
add_filter( 'post_class', array( $this, 'post_class'), 10, 3 );
}
if( is_taxonomy('marm_queue') ) {
add_action( 'wp_footer', array( $this, 'project_filter' ) );
}
foreach( get_terms('marm_queue') as $term ) {
$id = register_sidebar(array(
'name' => 'Project Queue: ' . $term->name,
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
'id' => sprintf( 'queue-%s', $term->slug ),
));
}
if( false === ( $ver = get_option('marm_rewrite_ver') ) ) {
add_option( 'marm_rewrite_ver', self::REWRITE_VERSION, null, true );
$ver = self::REWRITE_VERSION;
flush_rewrite_rules();
}
if( $ver < self::REWRITE_VERSION ) {
update_option( 'marm_rewrite_ver', self::REWRITE_VERSION );
flush_rewrite_rules();
}
}//end init
public function body_class( $classes ) {
if( current_user_can( 'edit_posts' ) ) {
$classes[] = 'user-cap-edit_posts';
}
return $classes;
}//end body_class
public function body_class_completed( $classes ) {
$classes[] = 'marm-completed-list';
return $classes;
}
public function body_class_submit( $classes ) {
$classes[] = 'marm-submit';
return $classes;
}
public function query_vars( $query_vars ) {
$query_vars[] = 'marm_submit';
$query_vars[] = 'marm_widget_area';
return $query_vars;
}//end query_vars
public function rewrite_rules_array( $rules ) {
$new = array(
'submit/?$' => 'index.php?marm_submit=1',
);
return $new + $rules;
}//end query_vars
public function template_redirect() {
global $wp_query;
//
// Potentially override $wp_query->queried_object or we might get the wrong template
//
$taxes = array(
'marm_status' => null,
'marm_queue' => null,
);
if( $wp_query->tax_query->queries ) {
foreach( $wp_query->tax_query->queries as $query ) {
$taxes[ $query['taxonomy'] ] = $query;
}
}
if( $taxes['marm_status'] && $taxes['marm_queue'] ) {
$wp_query->queried_object = Marmoset::get_term_by( $taxes['marm_queue']['field'], reset( $taxes['marm_queue']['terms'] ), 'marm_queue' );
}
$this->queried_status = $taxes['marm_status'];
$this->queried_queue = $taxes['marm_queue'];
//
// Other stuff.
//
if( isset($wp_query->query_vars['marm_submit']) && $wp_query->query_vars['marm_submit'] ) {
add_filter( 'body_class', array( $this, 'body_class_submit' ) );
include TEMPLATEPATH . '/submit.php';
die();
} else {
if( isset($wp_query->query['marm_queue']) && $wp_query->query_vars['marm_queue'] == 'complete' ) {
add_filter( 'body_class', array( $this, 'body_class_completed' ) );
}//end if
add_action( 'wp_footer', array( $this, 'include_submit_form' ) );
}
}//end template_redirect
public function include_submit_form() {
include TEMPLATEPATH . '/includes/submit-form.php';
}
public function project_filter() {
include TEMPLATEPATH . '/includes/project-filter.php';
}//end project_filter
public function post_class( $classes, $class, $ID ) {
$taxonomies = array(
'marm_members',
'marm_queue',
'marm_stakeholders',
'marm_status',
);
foreach( $taxonomies as $taxonomy ) {
$class_prepend = substr( $taxonomy, 5 );
$terms = get_the_terms( (int) $ID, $taxonomy );
if( !empty( $terms ) ) {
foreach( (array) $terms as $order => $term ) {
$class = $class_prepend.'_'.$term->slug;
if( !in_array( $class, $classes ) ) {
$classes[] = $class;
}
}
}
}//end foreach
return $classes;
}//end post_class
/**
* Run from footer.php to apply filtering settings from the query string.
*/
public function project_select() {
$echo = false;
$get_meta = array();
if( isset($_GET['member']) && $_GET['member'] ) {
$_GET['members'] = $_GET['member'];
unset( $_GET['member'] );
}
if( isset($_GET['members']) && $_GET['members'] ) {
$get_meta[] = 'members';
}
if( isset($_GET['status']) && $_GET['status'] ) {
$get_meta[] = 'status';
}
if( isset($_GET['stakeholder']) && $_GET['stakeholder'] ) {
$_GET['stakeholders'] = $_GET['stakeholder'];
unset( $_GET['stakeholder'] );
}
if( isset($_GET['stakeholders']) && $_GET['stakeholders'] ) {
$get_meta[] = 'stakeholders';
}
if( $get_meta ) {
echo '<script>';
foreach( $get_meta as $meta_key ) {
$members = explode( ',', $_GET[ $meta_key ] ); ?>
<?php foreach( (array) $members as $member ) : ?>
marm.toggle_meta_filter('<?php echo $meta_key; ?>', '<?php echo trim($member); ?>', false, false);
<?php endforeach; ?>
<?php
}//end foreach
?>
marm.count_projects();
<?php if( $_GET['unfocused'] == 'false' ) : ?>
marm.hide_unfocused();
<?php endif;
echo '</script>';
}//end if
}//end project_select
/**
* Track the terms found on this page.
*/
public function update_found_terms() {
$stakeholders = Marmoset::get_the_stakeholders();
foreach( $stakeholders as &$stakeholder ) {
if( !$this->stakeholders[$stakeholder->slug] ) {
$this->stakeholders[$stakeholder->slug] = $stakeholder;
}
$this->stakeholders[$stakeholder->slug]->found_count++;
}
$members = Marmoset::get_the_members();
foreach( $members as &$member ) {
if( !$this->members[$member->slug] ) {
$this->members[$member->slug] = $member;
}
$this->members[$member->slug]->found_count++;
}
$status = Marmoset::get_the_status();
if( !$this->statuses[$status->slug] ) {
$this->statuses[$status->slug] = $status;
}
$this->statuses[$status->slug]->found_count++;
}//end update_found_terms
public function output_found_terms() {
echo '<ul>';
$this->output_found_terms_for( 'marm_stakeholders', $this->stakeholders );
$this->output_found_terms_for( 'marm_members', $this->members );
$this->output_found_terms_for( 'marm_status', $this->statuses );
echo '</ul>';
}
public function output_found_terms_for( $taxonomy_slug, $terms ) {
$taxonomy = get_taxonomy( $taxonomy_slug );
// trim marm_ off the front (hacky, needs a fix)
echo '<li class="' . substr( $taxonomy->name, 5 ) . '"><span>' . $taxonomy->labels->name . ':</span>';
echo '<ul>';
usort( $terms, create_function( '$a, $b', 'return strnatcasecmp($a->name, $b->name);' ) );
foreach( $terms as $term ) {
echo '<li class="' . $term->slug . '"><a href="#">' . $term->name . ' (' . $term->found_count . ')</a></li>';
}
echo '</ul><br class="clear"></li>';
}//end output_found_terms_for
public function widgets_init() {
register_sidebar(array(
'name' => 'Default Project Queue',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
'id' => 'default-project-list',
'description' => 'A default project list for queues that have not been customized below.',
));
register_widget( 'Marmoset_Widget_Projects' );
}//end widgets_init
}//end Marmoset_Theme
class Marmoset_Widget_Projects extends WP_Widget {
public function __construct() {
parent::__construct(false, 'Marmoset: Projects');
}
public function widget( $args, $instance ) {
global $marmoset_theme;
extract( $args );
// our focused status, if any
$status = $marmoset_theme->queried_status;
// "focus only" widgets are only shown when the status matches
if( $instance['focus_only'] && ! $status ) {
return;
}
// if a status is specified, ignore statuses that don't match
if( $status && $instance['term_slug'] != reset( $status['terms'] ) ) {
return;
}
$term = Marmoset::get_term_by( 'slug', $instance['term_slug'], 'marm_status' );
$title = $term->name;
$project_args = array(
'marm_status' => $term->slug,
'date_display' => $instance[ 'date_display' ],
'display_overdue' => $instance[ 'display_overdue' ],
'meta_key' => $instance['meta_key'],
'order' => $instance['order'],
);
wp_reset_query();
?>
<div class="grid_16 project-status" data-status="<?php echo $term->slug; ?>">
<h2><?php echo $title; ?></h2>
<div>
<?php Marmoset::get_projects( $project_args ); ?>
</div>
</div>
<div class="clear"></div>
<?php
}
public function form( $instance ) {
$taxonomy = get_taxonomy( 'marm_status' );
$terms = get_terms( $taxonomy->name, 'hide_empty=0' );
$selected_term = $instance['term_slug'];
echo '<ul>';
echo '<li>';
echo '<div class="marmoset-widget-span">Category: </div><select id="' . $this->get_field_id('term_slug') .
'" name="' . $this->get_field_name('term_slug') . '">';
foreach( $terms as $term ) {
echo '<option value="' . $term->slug . '"';
if( $term->slug == $selected_term ) {
echo ' selected="selected"';
}
echo '>';
echo esc_html( $term->name );
echo '</option>';;
}
echo '</select>';
echo '</li>';
$date_options = array(
'complete_date' => 'Complete',
'due_date' => 'Due',
'date_entered' => 'Entered',
'estimated_start_date' => 'Est. Start',
'start_date' => 'Start'
);
echo '<li>';
echo '<div class="marmoset-widget-span">Date:</div>';
echo '<select id=' .$this->get_field_id('date_display').' name="'.$this->get_field_name('date_display').'">';
foreach( $date_options as $value=>$option ) {
echo '<option ';
if( $instance[ 'date_display' ] == $value ) {
echo 'selected=selected';
}
echo ' value=' .$value. ' >' .$option. '</option>';
}
echo '</select>';
echo '<input
id=' .$this->get_field_id( 'display_overdue' ). '
name=' .$this->get_field_name( 'display_overdue' ). '
type="checkbox"
value="true"';
echo ( $instance[ 'display_overdue' ] ) ? ' checked="checked" />' : ' /> ';
echo '<span> Overdue Warning </span>';
echo '</li>';
$sort_by_options = array(
'project_order' => 'Priority',
'complete_date' => 'Complete Date',
'due_date' => 'Due Date',
'date_entered' => 'Date Entered',
'estimated_start_date' => 'Est. Start Date',
'start_date' => 'Start Date',
);
echo '<li>';
echo '<div class="marmoset-widget-span">Sort By:</div>';
echo '<select id=' .$this->get_field_id('meta_key').' name="'.$this->get_field_name('meta_key').'">';
foreach( $sort_by_options as $value=>$option ) {
echo '<option ';
if( $instance[ 'meta_key' ] == $value ) {
echo 'selected=selected';
}
echo ' value=' .$value. ' >' .$option. '</option>';
}
echo '</select>';
$order_dir_options = array('ASC'=>'Ascending', 'DESC' => 'Descending');
echo '<select id=' .$this->get_field_id('order').' name="'.$this->get_field_name('order').'">';
foreach( $order_dir_options as $value=>$option ) {
echo '<option ';
if( $instance[ 'order' ] == $value ) {
echo 'selected=selected';
}
echo ' value=' .$value. ' >' .$option. '</option>';
}
echo '</select>';
echo '</li>';
echo '<li>';
echo '<span>Focus only: </span><input type="checkbox" id="' . $this->get_field_id('focus_only') .
'" name="' . $this->get_field_name('focus_only') . '" ';
if( $instance['focus_only'] ) {
echo 'checked="checked"';
}
echo '>';
echo '</li>';
echo '</ul>';
}//end form
public function update( $new, $old ) {
$instance = $old;
$instance['term_slug'] = $new['term_slug'];
$instance['date_display'] = $new['date_display'];
$instance['display_overdue'] = $new['display_overdue'];
$instance['meta_key'] = $new['meta_key'];
$instance['order'] = $new['order'];
$instance['focus_only'] = (bool)$new['focus_only'];
return $instance;
}//end update
}//end Marmoset_Widget_Projects
global $marmoset_theme;
$marmoset_theme = new Marmoset_Theme;
add_action( 'init', array( $marmoset_theme, 'init' ) );
add_action( 'widgets_init', array( $marmoset_theme, 'widgets_init' ) );
add_action( 'body_class', array( $marmoset_theme, 'body_class' ) );
add_filter( 'query_vars', array( $marmoset_theme, 'query_vars' ) );
add_action( 'template_redirect', array( $marmoset_theme, 'template_redirect' ) );
add_action( 'rewrite_rules_array', array( $marmoset_theme, 'rewrite_rules_array' ) );
add_action( 'post_rewrite_rules', function($r){
var_dump('post rewrite');
return $r;
});