PluginProbe
Taskbuilder – Project Management & Task Management Tool With Kanban Board / 6.0.6
Taskbuilder – Project Management & Task Management Tool With Kanban Board v6.0.6
6.0.6 6.0.5 6.0.2 6.0.3 6.0.4 6.0.1 6.0.0 5.0.8 5.0.9 4.0.9 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 All 58 releases
← All changes | includes/class-wppm-functions.php +192 -14 5.0.46.0.6 View file →
@@ -31,8 +31,10 @@
31 31 'status'=>isset($args['status'])? $args['status']:$default_proj_status,
32 32 'cat_id'=>isset($args['wppm_create_project_category']) ? $args['wppm_create_project_category']:"",
33 33 'users'=>isset($args['user_names']) ? implode(",",$args['user_names']):"",
34 34 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"),
35 + 'project_auth_code'=> self::getRandomString(10)
36 +
35 37 );
36 38 $wpdb->insert($wpdb->prefix .'wppm_project', $values);
37 39 $project_id = $wpdb->insert_id;
38 40 return $project_id;
@@ -38,9 +40,9 @@
38 40 return $project_id;
39 41 }
40 42
41 43 public static function create_task($args){
42 - global $wpdb,$current_user,$wppmfunction;
44 + global $wpdb,$current_user;
43 45 $default_task_status = get_option('wppm_default_task_status');
44 46 $values = array(
45 47 'created_by'=>(isset($args['created_by'])) ? $args['created_by']: $current_user->ID,
46 48 'task_name'=>$args['name'],
@@ -51,10 +53,11 @@
51 53 'status'=>(isset($args['status']))?$args['status']:$default_task_status,
52 54 'priority'=>(isset($args['wppm_create_task_priority']))?$args['wppm_create_task_priority']:"",
53 55 'users'=>(!empty($args['user_names']))?implode(",",$args['user_names']):"",
54 56 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"),
55 - 'task_auth_code'=> $wppmfunction->getRandomString(10),
56 - 'active'=>1
57 + 'task_auth_code'=> self::getRandomString(10),
58 + 'active'=>1,
59 + 'parent_task_id'=>(isset($args['parent_task_id']))?absint($args['parent_task_id']):0
57 60 );
58 61 $wpdb->insert($wpdb->prefix .'wppm_task', $values);
59 62 $task_id = $wpdb->insert_id;
60 63 return $task_id;
@@ -138,8 +141,23 @@
138 141 $auth_code = isset($auth_code) ? $auth_code : "";
139 142 return $auth_code;
140 143 }
141 144
145 + public static function wppm_get_proj_auth_code($id){
146 + global $wpdb;
147 + $id = absint($id);
148 + $auth_code = $wpdb->get_var(
149 + $wpdb->prepare(
150 + "SELECT project_auth_code
151 + FROM {$wpdb->prefix}wppm_project
152 + WHERE id = %d",
153 + ($id)
154 + )
155 + );
156 + $auth_code = isset($auth_code) ? $auth_code : "";
157 + return $auth_code;
158 + }
159 +
142 160 public static function get_task_fields($task_id,$select_field){
143 161 global $wpdb;
144 162 $task_id = absint($task_id);
145 163 $task_field_value = '';
@@ -182,9 +200,10 @@
182 200 'end_date',
183 201 'status',
184 202 'cat_id',
185 203 'users',
186 - 'date_created'
204 + 'date_created',
205 + 'project_auth_code'
187 206 );
188 207
189 208 // Validate column name
190 209 if ( ! in_array( $select_field, $allowed_fields, true ) ) {
@@ -202,9 +221,9 @@
202 221 $task_data = array();
203 222 $task_id = absint($task_id);
204 223 $task = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task WHERE id = %d", $task_id));
205 224 if( $task ){
206 - $task_data = json_decode(json_encode($task), true);
225 + $task_data = json_decode(wp_json_encode($task), true);
207 226 }
208 227 return $task_data;
209 228 }
210 229
@@ -213,9 +232,9 @@
213 232 $task_id = absint($task_id);
214 233 $checklist_data = array();
215 234 $checklist = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id));
216 235 if( $checklist ){
217 - $checklist_data = json_decode(json_encode($checklist), true);
236 + $checklist_data = json_decode(wp_json_encode($checklist), true);
218 237 }
219 238 return $checklist_data;
220 239 }
221 240
@@ -224,13 +243,76 @@
224 243 $checklist_items_data = array();
225 244 $checklist_id = absint($checklist_id);
226 245 $checklist_items = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d", $checklist_id));
227 246 if( $checklist_items ){
228 - $checklist_items_data = json_decode(json_encode($checklist_items), true);
247 + $checklist_items_data = json_decode(wp_json_encode($checklist_items), true);
229 248 }
230 249 return $checklist_items_data;
231 250 }
232 251
252 + public function get_subtasks($task_id){
253 + global $wpdb;
254 + $task_id = absint($task_id);
255 + $subtasks_data = array();
256 + $subtasks = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d ORDER BY id ASC", $task_id));
257 + if( $subtasks ){
258 + $subtasks_data = json_decode(wp_json_encode($subtasks), true);
259 + }
260 + return $subtasks_data;
261 + }
262 +
263 + public function get_subtask_progress($task_id){
264 + global $wpdb;
265 + $task_id = absint($task_id);
266 + $completed_status_id = 4;
267 + $total = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d", $task_id));
268 + $completed = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d AND status = %d", $task_id, $completed_status_id));
269 + return array('total'=>$total,'completed'=>$completed);
270 + }
271 +
272 + // Deletes a task along with its subtasks (and each one's checklists/comments/attachments).
273 + public static function delete_task_and_children($task_id){
274 + global $wpdb;
275 + $task_id = absint($task_id);
276 + $child_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d", $task_id));
277 + foreach($child_ids as $child_id){
278 + self::delete_task_and_children($child_id);
279 + }
280 + $thread_attachment_ids = $wpdb->get_results($wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d", $task_id));
281 + if(!empty($thread_attachment_ids)){
282 + foreach ($thread_attachment_ids as $thread_attachment_id){
283 + $attachment_ids_temp = array();
284 + if($thread_attachment_id->attachment_ids){
285 + $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids);
286 + }
287 + foreach ($attachment_ids_temp as $attachment_id){
288 + $attachment_id = absint($attachment_id);
289 + $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id));
290 + if(!empty($result)){
291 + $attach_result = $wpdb->get_results($wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s", $result->file_path));
292 + if(file_exists($result->file_path) && count($attach_result) < 2){
293 + wp_delete_file($result->file_path);
294 + }
295 + $wpdb->delete($wpdb->prefix.'wppm_attachments', array('id' => $attachment_id));
296 + }
297 + }
298 + }
299 + }
300 + $checklists = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id));
301 + if(!empty($checklists)){
302 + foreach($checklists as $checklist){
303 + $checklist_id = absint($checklist->id);
304 + $wpdb->delete($wpdb->prefix.'wppm_checklist_items', array('checklist_id'=>$checklist_id));
305 + $wpdb->delete($wpdb->prefix.'wppm_checklist', array('id'=>$checklist_id));
306 + }
307 + }
308 + $wpdb->delete($wpdb->prefix.'wppm_task', array('id'=>$task_id));
309 + $wpdb->delete($wpdb->prefix.'wppm_task_meta', array('task_id'=>$task_id));
310 + $wpdb->delete($wpdb->prefix.'wppm_task_comment', array('task_id'=>$task_id));
311 + $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta', array('task_id'=>$task_id));
312 + do_action('wppm_after_delete_task', $task_id);
313 + }
314 +
233 315 public function get_project($project_id){
234 316 global $wpdb;
235 317 $project_data = array();
236 318 $project_id = absint($project_id);
@@ -235,9 +317,9 @@
235 317 $project_data = array();
236 318 $project_id = absint($project_id);
237 319 $project = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id));
238 320 if( $project ){
239 - $project_data = json_decode(json_encode($project), true);
321 + $project_data = json_decode(wp_json_encode($project), true);
240 322 }
241 323 return $project_data;
242 324 }
243 325
@@ -246,9 +328,9 @@
246 328 $attachment_data = array();
247 329 $attachment_id = absint($attachment_id);
248 330 $attachment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id));
249 331 if( $attachment ){
250 - $attachment_data = json_decode(json_encode($attachment), true);
332 + $attachment_data = json_decode(wp_json_encode($attachment), true);
251 333 }
252 334 return $attachment_data;
253 335 }
254 336
@@ -291,8 +373,11 @@
291 373 }
292 374 if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){
293 375 $flag = true;
294 376 }
377 + if($current_user->has_cap('manage_options')){
378 + $flag = true;
379 + }
295 380 if(!empty($project_id)){
296 381 $project_id = absint($project_id);
297 382 $public_proj_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta where project_id= %d AND meta_key='public_project'", $project_id));
298 383 }else{
@@ -499,9 +584,9 @@
499 584
500 585 public function change_start_date($task_id, $task_start_date){
501 586 global $wpdb;
502 587 $values=array(
503 - 'start_date'=>absint($task_start_date)
588 + 'start_date'=>$task_start_date
504 589 );
505 590 $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id)));
506 591 }
507 592
@@ -507,9 +592,9 @@
507 592
508 593 public function change_end_date($task_id, $task_end_date){
509 594 global $wpdb;
510 595 $values=array(
511 - 'end_date'=>absint($task_end_date)
596 + 'end_date'=>$task_end_date
512 597 );
513 598 $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id)));
514 599 }
515 600
@@ -581,9 +666,9 @@
581 666 $task_comment_data = array();
582 667 $comment_id = absint($comment_id);
583 668 $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE id=%d", $comment_id));
584 669 if( $task_comment ){
585 - $task_comment_data = json_decode(json_encode($task_comment), true);
670 + $task_comment_data = json_decode(wp_json_encode($task_comment), true);
586 671 }
587 672 return $task_comment_data;
588 673 }
589 674
@@ -592,9 +677,9 @@
592 677 $project_comment_data = array();
593 678 $comment_id = absint($comment_id);
594 679 $project_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE id=%d", $comment_id));
595 680 if( $project_comment ){
596 - $project_comment_data = json_decode(json_encode($project_comment), true);
681 + $project_comment_data = json_decode(wp_json_encode($project_comment), true);
597 682 }
598 683 return $project_comment_data;
599 684 }
600 685
@@ -1019,9 +1104,9 @@
1019 1104 $task_comment = $wpdb->get_var($wpdb->prepare("SELECT body FROM {$wpdb->prefix}wppm_task_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_task_comment) AND task_id = %d)",$task_id));
1020 1105 return $task_comment;
1021 1106 }
1022 1107
1023 - public function create_duplicate_task($ptask_id, $project_id,$ajax_nonce){
1108 + public function create_duplicate_task($ptask_id, $project_id,$internal_code_flag=false){
1024 1109 include WPPM_ABSPATH . 'includes/admin/tasks/open_task/wppm_set_clone_task.php';
1025 1110 }
1026 1111
1027 1112 public function get_last_comment_proj_user_name($project_id){
@@ -1207,8 +1292,101 @@
1207 1292 if ($minutes > 0 || empty($duration)) $duration[] = $minutes . 'm';
1208 1293
1209 1294 return implode(' ', $duration);
1210 1295
1296 + }
1297 +
1298 + public function wppm_highlight_user_mentions($content, $current_user_id) {
1299 +
1300 + return preg_replace_callback(
1301 + '/<span[^>]*class="wppm-mention"[^>]*data-user-id="(\d+)"[^>]*>(.*?)<\/span>/is',
1302 + function($matches) use ($current_user_id) {
1303 +
1304 + $user_id = intval($matches[1]);
1305 + $text = $matches[2];
1306 +
1307 + // already processed → skip
1308 + if (strpos($matches[0], 'wppm-mention-me') !== false) {
1309 + return $matches[0];
1310 + }
1311 +
1312 + if ($user_id === $current_user_id) {
1313 + return '<span class="wppm-mention wppm-mention-me" data-user-id="' . esc_attr($user_id) . '">' . $text . '</span>';
1314 + }
1315 +
1316 + return '<span class="wppm-mention" data-user-id="' . esc_attr($user_id) . '">' . $text . '</span>';
1317 + },
1318 + $content
1319 + );
1320 + }
1321 + function wppm_clean_mentions_html($content) {
1322 + // Remove dropdown items
1323 + $content = preg_replace('/<div[^>]*class="mention-item"[^>]*>.*?<\/div>/is', '', $content);
1324 +
1325 + // Remove mention dropdown container
1326 + $content = preg_replace('/<div[^>]*id="wppm_mention_list"[^>]*>.*?<\/div>/is', '', $content);
1327 +
1328 + return $content;
1329 + }
1330 +
1331 + function wppm_extract_mentions($comment) {
1332 + preg_match_all('/data-user-id="(\d+)"/', $comment, $matches);
1333 + return $matches[1];
1334 + }
1335 +
1336 + function wppm_get_users_from_mentions($user_ids) {
1337 + $users = [];
1338 + foreach ($user_ids as $user_id) {
1339 + $user = get_user_by('id', intval($user_id));
1340 + if ($user) {
1341 + $users[] = $user;
1342 + }
1343 + }
1344 + return $users;
1345 + }
1346 +
1347 + function wppm_send_mention_email($email_addresses, $comment, $task_id) {
1348 + $page_setting = get_option('wppm-page-settings');
1349 + $from_name = get_option('wppm_en_from_name');
1350 + $from_email = get_option('wppm_en_from_email');
1351 + $view = $page_setting['task-url-page'];
1352 + $subject = esc_html__("You were mentioned in a comment", "taskbuilder");
1353 + $to = isset($email_addresses[0]) ? $email_addresses[0] : '';
1354 + if (!$to) {
1355 + return;
1356 + }
1357 + unset($email_addresses[0]);
1358 + $headers = "From: {$from_name} <{$from_email}>\r\n";
1359 + foreach ($email_addresses as $email_address) {
1360 + $headers .= "BCC: {$email_address}\r\n";
1361 + }
1362 + $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
1363 + $task_url = $this->get_task_url($task_id, $view);
1364 + $message = esc_html__("Hello,", "taskbuilder");
1365 + $message .= "<br><br>";
1366 + $message .= esc_html__("You were mentioned in a comment:", "taskbuilder");
1367 + $message .= "<br><br>";
1368 + $message .= nl2br(esc_html(strip_tags($comment)));
1369 + $message .= "<br><br>";
1370 + $message .= esc_html__("View Task:", "taskbuilder") . " ";
1371 + $message .= '<a class="wppm_link" href="' . esc_url($task_url) . '" target="_blank">' . esc_html__("View Task", "taskbuilder") . '</a>';
1372 + wp_mail($to, $subject, $message, $headers);
1373 + do_action('wppm_after_sent_mention_mail', $email_addresses, $comment, $task_id);
1374 + }
1375 +
1376 + function wppm_insert_notification($user_id, $message, $link,$is_read,$type) {
1377 + global $wpdb;
1378 + $wpdb->insert(
1379 + $wpdb->prefix . 'wppm_notifications',
1380 + [
1381 + 'user_id' => $user_id,
1382 + 'message' => $message,
1383 + 'link' => $link,
1384 + 'is_read' => $is_read,
1385 + 'notification_type'=>$type,
1386 + 'created_at' => current_time('mysql')
1387 + ]
1388 + );
1211 1389 }
1212 1390 }
1213 1391 endif;
1214 1392 $GLOBALS['wppmfunction'] = new WPPM_Functions();