-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.php
287 lines (242 loc) · 10.8 KB
/
plugin.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
<?php
/**
* Registers custom post type: "Task" with custom taxonoimes: "Type", "Status", "Priority", "Milestone", "Assigned" and "Project".
*/
/**
* Plugin Name: Task Tracker
* Plugin URI: --
* Description: Turns WP into a Task Tracking system.
* Version: .1
* Author: Zane M. Kolnik
* Author URI: http://zanematthew.com/
* License: GP
*/
require_once 'wordpress-helper-functions.php';
require_once 'interface.php';
require_once 'abstract.php';
/**
* Our class
*/
class CustomPostType extends CustomPostTypeBase {
// @todo do we need this?
static $instance;
public $dependencies = array();
/**
* Every thing that is "custom" to our CPT goes here.
* @uses wp_localize_script()
* @uses wp_register_style()
* @uses wp_register_script()
* @uses wp_enqueue_script()
* @uses plugin_dir_url()
* @uses admin_url()
* @uses register_activation_hook()
*/
public function __construct() {
wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
self::$instance = $this;
$this->dependencies['script'] = array(
'jquery',
'jquery-ui-core',
'jquery-ui-dialog'
);
$this->dependencies['style'] = array(
'tt-base-style',
'inplace-edit-style'
);
parent::__construct();
add_action( 'init', array( &$this, 'registerPostType' ) );
add_action( 'init', array( &$this, 'registerTaxonomy' ) );
add_action( 'wp_footer', array( &$this, 'createPostTypeDiv' ) );
add_action( 'wp_footer', array( &$this, 'createDeleteDiv' ) );
register_activation_hook( __FILE__, array( &$this, 'registerActivation') );
if ( !is_admin() ) {
wp_register_style( 'tt-base-style', plugin_dir_url( __FILE__ ) . 'theme/css/style.css', '', 'all' );
wp_register_style( 'qtip-nightly-style', plugin_dir_url( __FILE__ ) . 'library/js/qtip-nightly/jquery.qtip.min.css', '', 'all' );
wp_register_style( 'inplace-edit-style', plugin_dir_url( __FILE__ ) . 'library/js/inplace-edit/inplace-edit.css', '', 'all' );
wp_register_script( 'tt-script', plugin_dir_url( __FILE__ ) . 'theme/js/script.js', $this->dependencies['script'], '1.0' );
wp_register_script( 'qtip-nightly', plugin_dir_url( __FILE__ ) . 'library/js/qtip-nightly/jquery.qtip.min.js', $this->dependencies['script'], '0.0.1' );
wp_register_script( 'jquery-ui-effects', plugin_dir_url( __FILE__ ) . 'library/js/jquery-ui/jquery-ui-1.8.13.effects.min.js', $this->dependencies['script'], '1.8.13' );
wp_register_script( 'inplace-edit-script', plugin_dir_url( __FILE__ ) . 'library/js/inplace-edit/inplace-edit.js', $this->dependencies['script'], '0.1' );
// We register then enqueue because we plan on moving the enqueue some where else later
// where I don't know?
wp_register_script( 'hash-script', plugin_dir_url( __FILE__ ) . 'theme/js/hash.js', array('jquery'), '1.0' );
wp_enqueue_script( 'hash-script' );
wp_register_script( 'cud-script', plugin_dir_url( __FILE__ ) . 'theme/js/cud.js', array('jquery'), '1.0' );
wp_enqueue_script( 'cud-script' );
wp_register_script( 'login-script', plugin_dir_url( __FILE__ ) . 'theme/js/login.js', array('jquery','tt-script'), '1.0' );
wp_enqueue_script( 'login-script' );
}
$this->loginSetup();
} // End 'construct'
/**
* Runs on plugin activation and inserts base terms along with term
* descriptions and one sample Task.
*
* @uses wp_insert_term
* @uses get_current_user_id
* @uses wp_insert_post
* @uses wp_set_post_terms
* @uses term_exists
*/
public function registerActivation(){
// Dont forget registration hook is called
// BEFORE! taxonomies are regsitered! therefore
// these terms and taxonomies are NOT derived from our object!
$taxonomies = array( 'priority', 'status', 'type' );
$this->registerTaxonomy( $taxonomies );
// Priority
wp_insert_term( 'High', 'priority', array( 'description' => '', 'slug' => 'high' ) );
wp_insert_term( 'Low', 'priority', array( 'description' => '', 'slug' => 'low' ) );
wp_insert_term( 'Medium', 'priority', array( 'description' => '', 'slug' => 'medium' ) );
// Status
wp_insert_term( 'Aborted', 'status', array( 'description' => 'A Task that will NOT be completed.', 'slug' => 'aborted' ) );
wp_insert_term( 'Closed', 'status', array( 'description' => 'A Task that has been resolved and reviewed is completed.', 'slug' => 'closed' ) );
wp_insert_term( 'New', 'status', array( 'description' => 'A New Task is a Task that is waiting to be worked on.', 'slug' => 'new' ) );
wp_insert_term( 'Open', 'status', array( 'description' => 'A Task that is currently being worked on.', 'slug' => 'open' ) );
wp_insert_term( 'Resolved', 'status', array( 'description' => 'The Task has been finished, but needs to be approved before it is closed.', 'slug' => 'resolved' ) );
// Type
wp_insert_term( 'Car', 'type', array( 'description' => 'Anything related to your car, cleaning, vacuming, oil change and so on.') );
wp_insert_term( 'Computer', 'type', array( 'description' => 'Checking emails, programming, writing papers.' ) );
wp_insert_term( 'Freelance', 'type', array( 'description' => 'What ever makes you some extra side cash.' ) );
wp_insert_term( 'House', 'type', array( 'description' => 'House work, be it laundry, vacuuming or just cleaning.' ) );
wp_insert_term( 'Personal', 'type', array( 'description' => 'Anything you can think of.' ) );
wp_insert_term( 'Photography', 'type', array( 'description' => 'Taking photos, grooming your photo library or some quick editing.' ) );
// insert sample task
$author_ID = get_current_user_id();
$post = array(
'post_title' => 'Your first Task!',
'post_content' => 'This is a sample Task make it short and sweet, hopefully this system will help you get a tad more stuff done :D',
'post_author' => $author_ID,
'post_type' => 'task',
'post_status' => 'publish'
);
$post_id = wp_insert_post( $post, true );
if ( isset( $post_id ) ) {
$term_id = term_exists( 'medium', 'priority' );
wp_set_post_terms( $post_id, $term_id, 'priority' );
$term_id = term_exists( 'new', 'status' );
wp_set_post_terms( $post_id, $term_id, 'status' );
$term_id = term_exists( 'personal', 'type' );
wp_set_post_terms( $post_id, $term_id, 'type' );
}
} // End 'registerActivation'
/**
* To be used in AJAX submission, gets the $_POST data and logs the user in.
*
* @uses check_ajax_referer()
* @uses wp_signon()
* @uses is_wp_error()
*
* @todo move this to the abtract!
*/
public function siteLoginSubmit() {
check_ajax_referer( 'tt-ajax-forms', 'security' );
$creds = array();
$creds['user_login'] = $_POST['user_name'];
$creds['user_password'] = $_POST['password'];
if ( $_POST['remember'] == 'on' ) {
$creds['remember'] = true;
} else {
$creds['remember'] = false;
}
$user = wp_signon( $creds, false );
if ( is_wp_error( $user ) )
$user->get_error_message();
die();
} // siteLoginSubmit
/**
* Login set-up
*
* Note this does NOT hook into the default WordPress login! In essence
* you will need custom mark-up. Telling it which template to call
* and create you own, see theme/default/login.php
*
* @uses add_action()
* @uses wp_enqueue_style()
* @uses wp_enqueue_script()
* @uses plugin_dir_url()
*/
public function loginSetup() {
add_action( 'wp_footer', array( &$this, 'createLoginDiv' ) );
add_action( 'wp_ajax_siteLoginSubmit', array( &$this, 'siteLoginSubmit' ) );
add_action( 'wp_ajax_nopriv_siteLoginSubmit', array( &$this, 'siteLoginSubmit' ) );
$dependencies['style'] = array(
'tt-base-style',
'wp-jquery-ui-dialog'
);
wp_enqueue_style( 'wp-jquery-ui-dialog' );
wp_enqueue_style( 'tt-login-style', plugin_dir_url( __FILE__ ) . 'theme/css/login.css', $dependencies['style'], 'all' );
wp_enqueue_script( 'jquery-ui-effects' );
} // End 'loginSetup'
/**
*
*/
public function createLoginDiv(){ ?>
<div id="login_dialog" class="dialog-container">
<div id="login_target" style="display: none;">login hi</div>
</div>
<?php }
public function createPostTypeDiv(){
if ( is_user_logged_in() ) : ?>
<div id="create_ticket_dialog" class="dialog-container">
<div id="create_ticket_target" style="display: none;">hi</div>
</div>
<?php endif;
}
public function createDeleteDiv(){
if ( is_user_logged_in() ) : ?>
<div id="delete_dialog" class="dialog-container">
<p>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
<div id="delete_target" style="display: none">delete hi</div>
</div>
<?php endif;
}
} // End 'CustomPostType'
$_GLOBALS['task'] = new CustomPostType();
$_GLOBALS['task']->post_type = array(
array(
'name' => 'Task',
'type' => 'task',
'supports' => array(
'title',
'editor',
'author',
'comments'
),
// @todo automate mother fuckergrrrrr
'taxonomies' => array(
'assigned',
'milestone',
'priority',
'project',
'status',
'type'
)
)
);
$_GLOBALS['task']->taxonomy = array(
array(
'name' => 'assigned',
'post_type' => 'task'
),
array(
'name' => 'milestone',
'post_type' => 'task'
),
array(
'name' => 'priority',
'post_type' => 'task'
),
array(
'name' => 'project',
'post_type' => 'task'
),
array(
'name' => 'status',
'post_type' => 'task'
),
array(
'name' => 'type',
'post_type' => 'task'
)
);