| @@ -6,10 +6,18 @@ | ||
| 6 | 6 | global $current_user, $wppmfunction,$wpdb; |
| 7 | 7 | $current_user_data = get_userdata($current_user->ID); |
| 8 | 8 | $project_id = intval(sanitize_text_field($project_id)); |
| 9 | 9 | $wppm_project_data = $wppmfunction->get_project($project_id); |
| 10 | +$orderby_sql = sanitize_sql_orderby( "id DESC" ); | |
| 11 | +$wppm_proj_comment = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wppm_project_comment where proj_id='".$project_id."' ORDER BY $orderby_sql LIMIT 1;"); | |
| 12 | +$attachments = array(); | |
| 13 | +$auth_id = $wppmfunction->get_project_meta($project_id,'project_auth_code',true); | |
| 14 | +if(!empty($wppm_proj_comment)){ | |
| 15 | + $attachments = explode(',',$wppm_proj_comment->attachment_ids); | |
| 16 | +} | |
| 10 | 17 | preg_match_all("/{[^}]*}/" ,$str,$matches); |
| 11 | 18 | $matches = array_unique($matches[0]); |
| 19 | +$flag =false; | |
| 12 | 20 | foreach($matches as $match){ |
| 13 | 21 | switch($match){ |
| 14 | 22 | //Current User Name |
| 15 | 23 | case '{user_name}': |
| @@ -32,9 +40,14 @@ | ||
| 32 | 40 | $str = preg_replace('/{project_status}/', $this->get_new_project_status_name(sanitize_text_field($wppm_project_data['status'])), $str); |
| 33 | 41 | break; |
| 34 | 42 | // Project Category |
| 35 | 43 | case '{project_category}': |
| 36 | - $str = preg_replace('/{project_category}/', $this->get_project_category_name(sanitize_text_field($wppm_project_data['cat_id'])), $str); | |
| 44 | + if(!empty($wppm_project_data['cat_id'])){ | |
| 45 | + $str = preg_replace('/{project_category}/', $this->get_project_category_name(sanitize_text_field($wppm_project_data['cat_id'])), $str); | |
| 46 | + }else{ | |
| 47 | + $str = ""; | |
| 48 | + } | |
| 49 | + | |
| 37 | 50 | break; |
| 38 | 51 | // Project Name |
| 39 | 52 | case '{project_name}': |
| 40 | 53 | $str = preg_replace('/{project_name}/', sanitize_text_field($wppm_project_data['project_name']), $str); |
| @@ -60,13 +73,48 @@ | ||
| 60 | 73 | // Date created |
| 61 | 74 | case '{date_created}': |
| 62 | 75 | $str = preg_replace('/{date_created}/', get_date_from_gmt(sanitize_text_field($wppm_project_data['date_created'] )), $str); |
| 63 | 76 | break; |
| 77 | + //Last comment user name | |
| 78 | + case '{last_proj_comment_user_name}': | |
| 79 | + $str = preg_replace('/{last_proj_comment_user_name}/', $this->get_last_comment_proj_user_name($project_id), $str); | |
| 80 | + break; | |
| 81 | + //Last comment body | |
| 82 | + case '{proj_comment_body}': | |
| 83 | + $flag= true; | |
| 84 | + if(!empty($this->get_proj_comment_body($project_id))){ | |
| 85 | + $str = preg_replace('/{proj_comment_body}/', $this->get_proj_comment_body($project_id), $str); | |
| 86 | + } else{ | |
| 87 | + $str = ""; | |
| 88 | + } | |
| 89 | + break; | |
| 90 | + | |
| 64 | 91 | // Project Description |
| 65 | 92 | case '{project_description}': |
| 66 | - $str = preg_replace('/{project_description}/', sanitize_text_field($wppm_project_data['description']), $str); | |
| 67 | - | |
| 68 | - | |
| 93 | + $str = preg_replace('/{project_description}/', sanitize_text_field($wppm_project_data['description']), $str); | |
| 94 | + } | |
| 95 | +} | |
| 96 | +if($flag == true){ | |
| 97 | + if(!empty($attachments)){ | |
| 98 | + foreach($attachments as $attach_id){ | |
| 99 | + $upload_dir = wp_upload_dir(); | |
| 100 | + $attach_id = esc_sql($attach_id); | |
| 101 | + $attachment = $wpdb->get_row("select * from {$wpdb->prefix}wppm_attachments where id='".$attach_id."'"); | |
| 102 | + if(!empty($attachment)){ | |
| 103 | + $updated_time = sanitize_text_field($attachment->date_created); | |
| 104 | + $time = strtotime(sanitize_text_field($updated_time)); | |
| 105 | + $month = date("m",$time); | |
| 106 | + $year = date("Y",$time); | |
| 107 | + $findStr = ".txt"; | |
| 108 | + $attachment_name = preg_replace('/' . $findStr . '/', "", sanitize_file_name($attachment->name), 1); | |
| 109 | + $file_url = $upload_dir['basedir'] . '/wppm/'.'/'.$year.'/'.$month.'/'. $attachment_name; | |
| 110 | + $download_url = home_url('/').'?wppm_attachment='.sanitize_text_field($attachment->id).'&pid='.sanitize_text_field($project_id).'&pac='.sanitize_text_field($auth_id); | |
| 111 | + $attach_url[] = '<a style="text-decoration:none;" href="'.$download_url.'" target="_blank">'.sanitize_file_name($attachment->file_name).'</a>'; | |
| 112 | + }else{ | |
| 113 | + $attach_url= array(); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + $str = $str.implode("<br>",$attach_url); | |
| 69 | 117 | } |
| 70 | 118 | } |
| 71 | 119 | $str = apply_filters('wppm_replace_macro',$str,$project_id); |
| 72 | 120 | |