(int)$post->ID,
'type' => 'propertyhive_note',
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Notes use the existing serialized related_to comment metadata to include cross-record relationships.
'meta_query' => array(
array(
'key' => 'related_to',
'value' => '"' . (int)$post->ID . '"',
'compare' => 'LIKE',
),
)
);
if ( $propertyhive_pinned_only )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$args['search'] = '"pinned";s:1:"1"';
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$notes = get_comments( $args );
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$pinned_notes = array();
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$unpinned_notes = array();
if ( !empty($notes) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
foreach( $notes as $note )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$comment_content = @unserialize($note->comment_content, ['allowed_classes' => false]);
if ( $comment_content === false )
{
continue;
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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']) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable. Prepared single-row lookup in the plugin email queue; show current delivery status changed asynchronously by the mail worker.
$email_log = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ph_email_log WHERE email_id = %d", (int) $comment_content['email_log_id'] ) );
if ( null !== $email_log )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$next_cron_run = '';
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$email_status = '';
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_suffix = '';
switch ($email_log->status) {
case '':
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$next_cron_run = $next_cron_run ?: propertyhive_human_time_difference( wp_next_scheduled( 'propertyhive_process_email_log' ) );
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$email_status = __( 'queued', 'propertyhive' );
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_suffix = '(' . __( 'Due to be sent', 'propertyhive' ) . ' ' . $next_cron_run . ')';
break;
case 'fail1':
case 'fail2':
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$email_status = '' . __( 'failed', 'propertyhive' ) . '';
break;
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = '';
if ($section == 'property')
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= 'Included in ' . $email_status . ' email mailout to ' . get_the_title($email_log->contact_id) . '. ' . $note_suffix;
}
elseif ($section == 'contact')
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$property_ids = @unserialize($email_log->property_ids, ['allowed_classes' => false]);
if ( $property_ids !== false )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= count($property_ids) . ' propert' . ( (count($property_ids) != 1) ? 'ies' : 'y' ) . ' included in ' . $email_status . ' email mailout. ' . $note_suffix;
}
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= ' View Mailout';
}
else
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$keep_logs_days = '3650';
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = $comment_content['action'] . '
From: ' . $comment_content['original_value'] . '
To: ' . $comment_content['new_value'];
break;
}
case "property_availability_change":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = $comment_content['action'] . '
From: ' . $comment_content['original_value'] . '
To: ' . $comment_content['new_value'];
break;
}
case "viewing_booked":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Viewing booked';
if ( isset($comment_content['property_id']) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$property = new PH_Property((int)$comment_content['property_id']);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= ' on ' . $property->get_formatted_full_address() . '';
}
break;
}
case "added_to_viewing":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Added to viewing';
if ( isset($comment_content['property_id']) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$property = new PH_Property((int)$comment_content['property_id']);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= ' on ' . $property->get_formatted_full_address() . '';
}
break;
}
case "tenancy_booked":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Tenancy created';
if ( isset($comment_content['property_id']) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$property = new PH_Property((int)$comment_content['property_id']);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= ' on ' . $property->get_formatted_full_address() . '';
}
break;
}
case "added_to_tenancy":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Added to tenancy';
if ( isset($comment_content['property_id']) )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$property = new PH_Property((int)$comment_content['property_id']);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body .= ' on ' . $property->get_formatted_full_address() . '';
}
break;
}
case "removed_from_tenancy":
{
if (isset($comment_content['tenancy_id']))
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Removed from tenancy';
}
else
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = '' . get_the_title($comment_content['contact_id']) . ' removed from tenancy';
}
break;
}
default:
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = $comment_content['action'];
break;
}
}
break;
}
case "note":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = $comment_content['note'];
// Regular expression pattern to match {{mention-ID|NAME}} or {{mention-ID}}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$pattern = '/\{\{mention-(\d+)(?:\|([^}]*))?\}\}/';
// Callback function to replace the mentions with HTML links
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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 . '}}';
}
}
};
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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);*/
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = nl2br($note_body);
break;
}
case "unsubscribe":
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Contact unsubscribed themselves from emails';
break;
}
case "status_change": // Believe this is only used by maintenance jobs add on
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = 'Status changed from ' . $comment_content['previous_status'] . ' to ' . $comment_content['new_status'];
break;
}
default:
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_body = apply_filters( 'propertyhive_note_body', $note_body, $note );
}
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$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' )
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$pinned_notes[] = $note_content;
}
else
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$unpinned_notes[] = $note_content;
}
}
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_output = array_merge($pinned_notes, $unpinned_notes);
if ($section != 'enquiry')
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_output = apply_filters( 'propertyhive_notes', $note_output, $post );
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an admin view; PHPCS analyzes the view file standalone even though WordPress includes it inside a method/function scope.
$note_output = apply_filters( 'propertyhive_' . $section . '_notes', $note_output, $post );
}
?>