forked from kanbanwp/kanban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kanban.php
198 lines (132 loc) · 4.74 KB
/
kanban.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
<?php
/*
Plugin Name: Kanban for WordPress
Plugin URI: http://kanbanwp.com/
Description: A complete kanban board for WordPress. Use agile project management to get more done, right inside your WordPress site!
Version: 0.4.1
Author: Gelform Inc
Author URI: http://gelwp.com
License: GPL2
Text Domain: kanban
Kanban 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
any later version.
Kanban 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 Kanban. if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
Kanban::init();
class Kanban
{
static $instance = false;
static $slug = 'kanban';
static function init ()
{
self::$instance = self::get_instance();
Kanban::$instance->settings = (object) array();
Kanban::$instance->settings->path = dirname(__FILE__);
Kanban::$instance->settings->file = basename(__FILE__, '.php');
Kanban::$instance->settings->basename = strtolower(__CLASS__);
Kanban::$instance->settings->uri = plugin_dir_url(__FILE__);
Kanban::$instance->settings->pretty_name = 'Kanban';
// needs to come first
include_once Kanban::$instance->settings->path . '/includes/class-utils.php';
// Automatically load classes
$files = glob(Kanban::$instance->settings->path . '/includes/class-*.php');
foreach ($files as $file)
{
include_once $file;
}
register_activation_hook( __FILE__, array( __CLASS__, 'on_activation' ) );
}
static function on_activation()
{
// http://wordpress.stackexchange.com/questions/20043/inserting-taxonomy-terms-during-a-plugin-activation
Kanban_Post_Types::custom_post_types();
foreach ( Kanban_Post_Types::$post_types as $post_type_slug => $post_type_data )
{
foreach ($post_type_data['taxonomies'] as $taxonomy_slug => $values)
{
$taxonomy_key = Kanban_Utils::format_key ($post_type_slug, $taxonomy_slug);
foreach ($values as $slug => $value)
{
$term_id_arr = wp_insert_term(
$value,
$taxonomy_key,
array(
'slug' => $slug
)
);
}
}
}
// add current user to board
$current_user_id = get_current_user_id();
$users_field_name = sprintf('%s_user', Kanban::$instance->settings->basename);
$user_settings = Kanban_Settings::get_option($users_field_name, null, array());
if ( !isset($user_settings['allowed_users']) )
{
$user_settings['allowed_users'] = array();
}
if ( !in_array($current_user_id, $user_settings['allowed_users']) )
{
$user_settings['allowed_users'][$current_user_id] = $current_user_id;
}
update_option( $users_field_name, $user_settings);
// add status order
$tax_key = Kanban_Utils::format_key ('task', 'status');
$field_name = sprintf('%s_order', $tax_key);
$settings = Kanban_Settings::get_option($field_name, null, array());
$slugs_in_order = array_keys(Kanban_Post_Types::$post_types['task']['taxonomies']['status']);
$term_ids_in_order = array();
foreach ($slugs_in_order as $order => $slug)
{
$term = get_term_by('slug', $slug, $tax_key);
$term_ids_in_order[$term->term_id] = $order;
}
update_option( $field_name, $term_ids_in_order);
// add estimate order
$tax_key = Kanban_Utils::format_key ('task', 'estimate');
$field_name = sprintf('%s_order', $tax_key);
$settings = Kanban_Settings::get_option($field_name, null, array());
$slugs_in_order = array_keys(Kanban_Post_Types::$post_types['task']['taxonomies']['estimate']);
$term_ids_in_order = array();
foreach ($slugs_in_order as $order => $slug)
{
$term = get_term_by('slug', $slug, $tax_key);
$term_ids_in_order[$term->term_id] = $order;
}
update_option( $field_name, $term_ids_in_order);
// add an example task
$post = array(
'post_status' => 'publish',
'post_type' => Kanban_Post_Types::format_post_type('task'),
'post_author' => $current_user_id
);
$post_id = wp_insert_post($post);
flush_rewrite_rules();
// redirect to welcome page
// @link http://premium.wpmudev.org/blog/tabbed-interface/
set_transient(
sprintf('_%s_welcome_screen_activation_redirect', Kanban::$instance->settings->basename),
true,
30
);
}
public static function get_instance()
{
if ( ! Kanban::$instance )
{
Kanban::$instance = new self();
}
return Kanban::$instance;
}
private function __construct() { }
} // Kanban