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 +180 -5 5.0.66.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 ) ) {
@@ -229,8 +248,71 @@
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);
@@ -1022,9 +1104,9 @@
1022 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));
1023 1105 return $task_comment;
1024 1106 }
1025 1107
1026 - 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){
1027 1109 include WPPM_ABSPATH . 'includes/admin/tasks/open_task/wppm_set_clone_task.php';
1028 1110 }
1029 1111
1030 1112 public function get_last_comment_proj_user_name($project_id){
@@ -1210,8 +1292,101 @@
1210 1292 if ($minutes > 0 || empty($duration)) $duration[] = $minutes . 'm';
1211 1293
1212 1294 return implode(' ', $duration);
1213 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 + );
1214 1389 }
1215 1390 }
1216 1391 endif;
1217 1392 $GLOBALS['wppmfunction'] = new WPPM_Functions();