| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wppmfunction,$wpdb; |
| 7 |
$current_user_data = get_userdata($current_user->ID); |
| 8 |
$task_id = intval(sanitize_text_field($task_id)); |
| 9 |
$wppm_task_data = $wppmfunction->get_task($task_id); |
| 10 |
$wppm_task_comment = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wppm_task_comment where task_id='".$task_id."' ORDER BY id DESC LIMIT 1;"); |
| 11 |
$wppm_project_data = $wppmfunction->get_project($wppm_task_data['project']); |
| 12 |
$auth_id = sanitize_text_field($wppm_task_data['task_auth_code']); |
| 13 |
$attachments = array(); |
| 14 |
if(!empty($wppm_task_comment)){ |
| 15 |
$attachments = explode(',',$wppm_task_comment->attachment_ids); |
| 16 |
} |
| 17 |
preg_match_all("/{[^}]*}/" ,$str,$matches); |
| 18 |
$matches = array_unique($matches[0]); |
| 19 |
$flag =false; |
| 20 |
foreach($matches as $match){ |
| 21 |
switch($match){ |
| 22 |
// Task ID |
| 23 |
case '{task_id}': |
| 24 |
$str = preg_replace('/{task_id}/', $task_id, $str); |
| 25 |
break; |
| 26 |
//Current User Name |
| 27 |
case '{user_name}': |
| 28 |
$str = preg_replace('/{user_name}/', sanitize_text_field($current_user_data->display_name), $str); |
| 29 |
break; |
| 30 |
// Task Name |
| 31 |
case '{task_name}': |
| 32 |
$str = preg_replace('/{task_name}/', sanitize_text_field($wppm_task_data['task_name']), $str); |
| 33 |
break; |
| 34 |
//Old Task Status |
| 35 |
case '{old_task_status}': |
| 36 |
$str = preg_replace('/{old_task_status}/', $this->get_old_task_status_name($task_id), $str); |
| 37 |
break; |
| 38 |
//New Task Status |
| 39 |
case '{new_task_status}': |
| 40 |
$str = preg_replace('/{new_task_status}/', $this->get_new_task_status_name(sanitize_text_field($wppm_task_data['status'])), $str); |
| 41 |
break; |
| 42 |
//New Task Status |
| 43 |
case '{task_status}': |
| 44 |
$str = preg_replace('/{task_status}/', $this->get_new_task_status_name(sanitize_text_field($wppm_task_data['status'])), $str); |
| 45 |
break; |
| 46 |
//Task Assigned Users |
| 47 |
case '{task_assigned_users}': |
| 48 |
$assigned_users = $this->get_task_assigned_users_names($task_id); |
| 49 |
$str = preg_replace('/{task_assigned_users}/', sanitize_text_field($assigned_users), $str); |
| 50 |
break; |
| 51 |
//Previously Assign Task Users |
| 52 |
case '{previously_assigned_task_users}': |
| 53 |
$previously_assigned_task_users = $this->get_task_previously_assigned_users_names($task_id); |
| 54 |
$str = preg_replace('/{previously_assigned_task_users}/', sanitize_text_field($previously_assigned_task_users), $str); |
| 55 |
break; |
| 56 |
// Task Start Date |
| 57 |
case '{task_start_date}': |
| 58 |
$str = preg_replace('/{task_start_date}/', sanitize_text_field($wppm_task_data['start_date']), $str); |
| 59 |
break; |
| 60 |
// Task End Date |
| 61 |
case '{task_end_date}': |
| 62 |
$str = preg_replace('/{task_end_date}/', sanitize_text_field($wppm_task_data['end_date']), $str); |
| 63 |
break; |
| 64 |
// Task Priority |
| 65 |
case '{task_priority}': |
| 66 |
$str = preg_replace('/{task_priority}/', $this->get_task_priority_name(sanitize_text_field($wppm_task_data['priority'])), $str); |
| 67 |
break; |
| 68 |
// Task Description |
| 69 |
case '{task_description}': |
| 70 |
$str = preg_replace('/{task_description}/', sanitize_text_field($wppm_task_data['description']), $str); |
| 71 |
break; |
| 72 |
// Date created |
| 73 |
case '{task_date_created}': |
| 74 |
$str = preg_replace('/{task_date_created}/', get_date_from_gmt(sanitize_text_field($wppm_task_data['date_created']) ), $str); |
| 75 |
break; |
| 76 |
// Project Name |
| 77 |
case '{project_name}': |
| 78 |
$str = preg_replace('/{project_name}/', sanitize_text_field($wppm_project_data['project_name']), $str); |
| 79 |
break; |
| 80 |
//Last comment user name |
| 81 |
case '{last_comment_user_name}': |
| 82 |
$str = preg_replace('/{last_comment_user_name}/', $this->get_last_comment_user_name($task_id), $str); |
| 83 |
break; |
| 84 |
//Project status |
| 85 |
case '{project_status}'; |
| 86 |
$str = preg_replace('/{project_status}/', $this->get_new_project_status_name((sanitize_text_field($wppm_project_data['status'])), $str)); |
| 87 |
break; |
| 88 |
// Project Category |
| 89 |
case '{project_category}'; |
| 90 |
$str = preg_replace('/{project_category}/', $this->get_project_category_name((sanitize_text_field($wppm_project_data['cat_id'])), $str)); |
| 91 |
break; |
| 92 |
// Project Name |
| 93 |
case '{project_name}': |
| 94 |
$str = preg_replace('/{project_name}/', (sanitize_text_field($wppm_project_data['project_name'])), $str); |
| 95 |
break; |
| 96 |
// Project Start Date |
| 97 |
case 'project_start_date': |
| 98 |
$str = preg_replace('/{project_start_date}/', (sanitize_text_field($wppm_project_data['start_date'])), $str); |
| 99 |
break; |
| 100 |
// Project End Date |
| 101 |
case '{project_end_date}': |
| 102 |
$str = preg_replace('/{project_end_date}/', (sanitize_text_field($wppm_project_data['end_date'])), $str); |
| 103 |
break; |
| 104 |
// Project Description |
| 105 |
case '{project_description}': |
| 106 |
$str = preg_replace('/{project_description}/', (sanitize_text_field($wppm_project_data['description'])), $str); |
| 107 |
break; |
| 108 |
// Project Assigned Users |
| 109 |
case '{project_assigned_users}': |
| 110 |
$assigned_users = $this->get_project_assigned_users_names($wppm_project_data['id']); |
| 111 |
$str = preg_replace('/{project_assigned_users}/', (sanitize_text_field($assigned_users)), $str); |
| 112 |
break; |
| 113 |
//Last comment body |
| 114 |
case '{comment_body}': |
| 115 |
$flag= true; |
| 116 |
$str = preg_replace('/{comment_body}/', $this->get_last_comment_body($task_id), $str); |
| 117 |
break; |
| 118 |
|
| 119 |
} |
| 120 |
} |
| 121 |
if($flag == true){ |
| 122 |
if(!empty($attachments)){ |
| 123 |
foreach($attachments as $attach_id){ |
| 124 |
$upload_dir = wp_upload_dir(); |
| 125 |
$attachment = $wpdb->get_row("select * from {$wpdb->prefix}wppm_attachments where id='".$attach_id."'"); |
| 126 |
if(!empty($attachment)){ |
| 127 |
$updated_time = sanitize_text_field($attachment->date_created); |
| 128 |
$time = strtotime(sanitize_text_field($updated_time)); |
| 129 |
$month = date("m",$time); |
| 130 |
$year = date("Y",$time); |
| 131 |
$findStr = ".txt"; |
| 132 |
$attachment_name = preg_replace('/' . $findStr . '/', "", sanitize_file_name($attachment->name), 1); |
| 133 |
$file_url = $upload_dir['basedir'] . '/wppm/'.'/'.$year.'/'.$month.'/'. $attachment_name; |
| 134 |
$download_url = home_url('/').'?wppm_attachment='.sanitize_text_field($attachment->id).'&tid='.sanitize_text_field($task_id).'&tac='.sanitize_text_field($auth_id); |
| 135 |
$attach_url[] = '<a style="text-decoration:none;" href="'.$download_url.'" target="_blank">'.sanitize_file_name($attachment->file_name).'</a>'; |
| 136 |
}else{ |
| 137 |
$attach_url= array(); |
| 138 |
} |
| 139 |
} |
| 140 |
$str = $str.implode("<br>",$attach_url); |
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
$str = apply_filters('wppm_replace_task_macro',$str,$task_id); |