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