| @@ -1,144 +1,163 @@ | ||
| 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 | -} | |
| 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 = (sanitize_sql_orderby( "id DESC" )); | |
| 14 | +$wppm_task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment where task_id=%d ORDER BY $orderby_sql LIMIT 1",$task_id)); | |
| 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 = absint($attach_id); | |
| 144 | + $attachment = $wpdb->get_row($wpdb->prepare("select * from {$wpdb->prefix}wppm_attachments where id=%d",$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 = wp_date("m",$time); | |
| 149 | + $year = wp_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 | +} | |
| 144 | 163 | $str = apply_filters('wppm_replace_task_macro',$str,$task_id); |