(int)$post->ID, 'type' => 'propertyhive_note', 'meta_query' => array( array( 'key' => 'related_to', 'value' => '"' . (int)$post->ID . '"', 'compare' => 'LIKE', ), ) ); if ( isset($_POST['pinned']) && (int)$_POST['pinned'] == 1 ) { $args['search'] = '"pinned";s:1:"1"'; } $notes = get_comments( $args ); $pinned_notes = array(); $unpinned_notes = array(); if ( !empty($notes) ) { foreach( $notes as $note ) { $comment_content = @unserialize($note->comment_content, ['allowed_classes' => false]); if ( $comment_content === false ) { continue; } $note_body = 'Unknown note type'; switch ( $comment_content['note_type'] ) { case "mailout": { if ( isset($comment_content['method']) && $comment_content['method'] == 'email' && isset($comment_content['email_log_id']) ) { $email_log = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "ph_email_log WHERE email_id = '" . $comment_content['email_log_id'] . "'" ); if ( null !== $email_log ) { $next_cron_run = ''; $email_status = ''; $note_suffix = ''; switch ($email_log->status) { case '': $next_cron_run = $next_cron_run ?: propertyhive_human_time_difference( wp_next_scheduled( 'propertyhive_process_email_log' ) ); $email_status = __( 'queued', 'propertyhive' ); $note_suffix = '(' . __( 'Due to be sent', 'propertyhive' ) . ' ' . $next_cron_run . ')'; break; case 'fail1': case 'fail2': $email_status = '' . __( 'failed', 'propertyhive' ) . ''; break; } $note_body = ''; if ($section == 'property') { $note_body .= 'Included in ' . $email_status . ' email mailout to ' . get_the_title($email_log->contact_id) . '. ' . $note_suffix; } elseif ($section == 'contact') { $property_ids = @unserialize($email_log->property_ids, ['allowed_classes' => false]); if ( $property_ids !== false ) { $note_body .= count($property_ids) . ' propert' . ( (count($property_ids) != 1) ? 'ies' : 'y' ) . ' included in ' . $email_status . ' email mailout. ' . $note_suffix; } } $note_body .= ' View Mailout'; } else { $keep_logs_days = (string)apply_filters( 'propertyhive_keep_email_logs_days', '3650' ); // 10 years // Revert back to 3650 days if anything other than numbers has been passed // This prevent SQL injection and errors if ( !preg_match("/^\d+$/", $keep_logs_days) ) { $keep_logs_days = '3650'; } $note_body = 'The details of the email have since been deleted as we remove details of emails sent more then ' . $keep_logs_days . ' days ago'; } } break; } case "action": { switch ( $comment_content['action'] ) { case "property_price_change": { $note_body = $comment_content['action'] . '
From: ' . $comment_content['original_value'] . '
To: ' . $comment_content['new_value']; break; } case "property_availability_change": { $note_body = $comment_content['action'] . '
From: ' . $comment_content['original_value'] . '
To: ' . $comment_content['new_value']; break; } case "viewing_booked": { $note_body = 'Viewing booked'; if ( isset($comment_content['property_id']) ) { $property = new PH_Property((int)$comment_content['property_id']); $note_body .= ' on ' . $property->get_formatted_full_address() . ''; } break; } case "added_to_viewing": { $note_body = 'Added to viewing'; if ( isset($comment_content['property_id']) ) { $property = new PH_Property((int)$comment_content['property_id']); $note_body .= ' on ' . $property->get_formatted_full_address() . ''; } break; } case "tenancy_booked": { $note_body = 'Tenancy created'; if ( isset($comment_content['property_id']) ) { $property = new PH_Property((int)$comment_content['property_id']); $note_body .= ' on ' . $property->get_formatted_full_address() . ''; } break; } case "added_to_tenancy": { $note_body = 'Added to tenancy'; if ( isset($comment_content['property_id']) ) { $property = new PH_Property((int)$comment_content['property_id']); $note_body .= ' on ' . $property->get_formatted_full_address() . ''; } break; } case "removed_from_tenancy": { if (isset($comment_content['tenancy_id'])) { $note_body = 'Removed from tenancy'; } else { $note_body = '' . get_the_title($comment_content['contact_id']) . ' removed from tenancy'; } break; } default: { $note_body = $comment_content['action']; break; } } break; } case "note": { $note_body = $comment_content['note']; // Regular expression pattern to match {{mention-ID|NAME}} or {{mention-ID}} $pattern = '/\{\{mention-(\d+)(?:\|([^}]*))?\}\}/'; // Callback function to replace the mentions with HTML links $callback = function($matches) { $post_id = $matches[1]; $title = isset($matches[2]) ? $matches[2] : ''; $edit_url = get_edit_post_link($post_id); $post_title = get_the_title($post_id); if ( get_post_type($post_id) == 'property' ) { $property = new PH_Property((int)$post_id); $post_title = $property->get_formatted_full_address(); } // If the post exists, create the link if ( $edit_url && $post_title ) { return '' . esc_html($post_title) . ''; } else { if ( !empty($title) ) { return $title; } else { return '{{mention-' . $post_id . '}}'; } } }; $note_body = preg_replace_callback($pattern, $callback, $note_body); /*$pattern = '/\{\{mention-(\d+)(\|.*)?\}\}/'; $replacement = function($matches) { $post_id = $matches[1]; $title = trim(trim($matches[2], '|')); $edit_url = get_edit_post_link($post_id); $post_title = get_the_title($post_id); if ( get_post_type($post_id) == 'property' ) { $property = new PH_Property((int)$post_id); $post_title = $property->get_formatted_full_address(); } // If the post exists, create the link if ( $edit_url && $post_title ) { return '' . esc_html($post_title) . ''; } else { if ( !empty($title) ) { return $title; } else { return '{{mention-' . $post_id . '}}'; } } }; $note_body = preg_replace_callback($pattern, $replacement, $note_body);*/ $note_body = nl2br($note_body); break; } case "unsubscribe": { $note_body = 'Contact unsubscribed themselves from emails'; break; } case "status_change": // Believe this is only used by maintenance jobs add on { $note_body = 'Status changed from ' . $comment_content['previous_status'] . ' to ' . $comment_content['new_status']; break; } default: { $note_body = apply_filters( 'propertyhive_note_body', $note_body, $note ); } } $note_content = array( 'id' => $note->comment_ID, 'post_id' => $note->comment_post_ID, 'type' => $comment_content['note_type'], 'author' => $note->comment_author, 'body' => $note_body, 'timestamp' => strtotime($note->comment_date), 'internal' => true, 'pinned' => ( isset($comment_content['pinned']) && $comment_content['pinned'] == '1' ) ? '1' : '0', ); if ( $note_content['pinned'] == '1' ) { $pinned_notes[] = $note_content; } else { $unpinned_notes[] = $note_content; } } } $note_output = array_merge($pinned_notes, $unpinned_notes); if ($section != 'enquiry') { $note_output = apply_filters( 'propertyhive_notes', $note_output, $post ); $note_output = apply_filters( 'propertyhive_' . $section . '_notes', $note_output, $post ); } ?>