/**
  * Output property search form
  *
  * @param array $atts
  * @return string
  */
 public static function property_search_form($atts)
 {
     $atts = shortcode_atts(array('id' => 'shortcode'), $atts);
     $form_controls = ph_get_search_form_fields();
     $form_controls = apply_filters('propertyhive_search_form_fields_' . $atts['id'], $form_controls);
     ob_start();
     ph_get_template('global/search-form.php', array('form_controls' => $form_controls, 'id' => $atts['id']));
     return ob_get_clean();
 }
 public function send_emails($contact_id, $applicant_profile, $email_property_ids, $from_name, $from_email_address, $subject, $body, $to_email_address = '')
 {
     global $wpdb;
     $current_user = wp_get_current_user();
     if ($to_email_address == '') {
         $to_email_address = get_post_meta($contact_id, '_email_address', TRUE);
     }
     $subject = str_replace("[property_count]", count($email_property_ids) . ' propert' . (count($email_property_ids) != 1 ? 'ies' : 'y'), $subject);
     $body = str_replace("[contact_name]", get_the_title($contact_id), $body);
     $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . (count($email_property_ids) != 1 ? 'ies' : 'y'), $body);
     if (strpos($body, '[properties]') !== FALSE) {
         ob_start();
         if (!empty($email_property_ids)) {
             foreach ($email_property_ids as $email_property_id) {
                 $property = new PH_Property((int) $email_property_id);
                 ph_get_template('emails/applicant-match-property.php', array('property' => $property));
             }
         }
         $body = str_replace("[properties]", ob_get_clean(), $body);
     }
     // Insert into email log
     $insert = $wpdb->insert($wpdb->prefix . 'ph_email_log', array('contact_id' => $contact_id, 'property_ids' => serialize($email_property_ids), 'applicant_profile_id' => $applicant_profile, 'to_email_address' => $to_email_address, 'from_name' => $from_name, 'from_email_address' => $from_email_address, 'subject' => stripslashes($subject), 'body' => stripslashes($body), 'status' => '', 'send_at' => date("Y-m-d H:i:s"), 'sent_by' => $current_user->ID), array('%d', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d'));
     if ($insert !== FALSE) {
         $email_log_id = $wpdb->insert_id;
         // Insert properties into applicant match history
         $applicant_profile_match_history = get_post_meta($contact_id, '_applicant_profile_' . $applicant_profile . '_match_history', TRUE);
         if (!is_array($applicant_profile_match_history)) {
             $applicant_profile_match_history = array();
         }
         if (is_array($email_property_ids) && !empty($email_property_ids)) {
             foreach ($email_property_ids as $email_property_id) {
                 if (!isset($applicant_profile_match_history[$email_property_id])) {
                     $applicant_profile_match_history[$email_property_id] = array();
                 }
                 $applicant_profile_match_history[$email_property_id][] = array('date' => date("Y-m-d H:i:s"), 'method' => 'email', 'email_log_id' => $email_log_id);
                 // Add note/comment to property
                 $comment = array('note_type' => 'mailout', 'method' => 'email', 'email_log_id' => $email_log_id);
                 $data = array('comment_post_ID' => $email_property_id, 'comment_author' => $current_user->display_name, 'comment_author_email' => '*****@*****.**', 'comment_author_url' => '', 'comment_date' => date("Y-m-d H:i:s"), 'comment_content' => serialize($comment), 'comment_approved' => 1, 'comment_type' => 'propertyhive_note');
                 wp_insert_comment($data);
             }
             update_post_meta($contact_id, '_applicant_profile_' . $applicant_profile . '_match_history', $applicant_profile_match_history);
             // Add note/comment to contact
             $comment = array('note_type' => 'mailout', 'method' => 'email', 'email_log_id' => $email_log_id);
             $data = array('comment_post_ID' => $contact_id, 'comment_author' => $current_user->display_name, 'comment_author_email' => '*****@*****.**', 'comment_author_url' => '', 'comment_date' => date("Y-m-d H:i:s"), 'comment_content' => serialize($comment), 'comment_approved' => 1, 'comment_type' => 'propertyhive_note');
             wp_insert_comment($data);
         }
     }
 }
/**
 * Main function for drawing property enquiry form.
 *
 * @param string $id
 * @return void
 */
function propertyhive_enquiry_form()
{
    $form_controls = ph_get_property_enquiry_form_fields();
    $form_controls = apply_filters('propertyhive_property_enquiry_form_fields', array('form_controls' => $form_controls));
    ph_get_template('global/make-enquiry-form.php', $form_controls);
}
                    <?php 
        }
        // end of the loop.
        ?>

                <?php 
        propertyhive_property_loop_end();
        ?>

            <?php 
    } else {
        ?>

                <?php 
        ph_get_template('search/no-properties-found.php');
        ?>

            <?php 
    }
    ?>

        <?php 
}
?>

        <?php 
/**
 * propertyhive_after_search_results_loop hook
 *
 * @hooked propertyhive_pagination - 10
 /**
  * Preview email template.
  *
  * @return string
  */
 public function preview_emails()
 {
     if (isset($_GET['preview_propertyhive_email'])) {
         if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'propertyhive-matching-properties')) {
             die('Security check');
         }
         // get the preview email content
         $email_property_ids = explode(",", $_POST['email_property_id']);
         $body = stripslashes($_POST['body']);
         $body = str_replace("[contact_name]", get_the_title($_GET['contact_id']), $body);
         $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . (count($email_property_ids) != 1 ? 'ies' : 'y'), $body);
         if (strpos($body, '[properties]') !== FALSE) {
             ob_start();
             if (!empty($email_property_ids)) {
                 foreach ($email_property_ids as $email_property_id) {
                     $property = new PH_Property((int) $email_property_id);
                     ph_get_template('emails/applicant-match-property.php', array('property' => $property));
                 }
             }
             $body = str_replace("[properties]", ob_get_clean(), $body);
         }
         // create a new email
         $email = new PH_Emails();
         // wrap the content with the email template and then add styles
         $message = apply_filters('propertyhive_mail_content', $email->style_inline($email->wrap_message($body)));
         // print the preview email
         echo $message;
         exit;
     }
 }
 /**
  * Output the make enquiry button and lightbox
  *
  * @access public
  * @subpackage  Property
  * @return void
  */
 function propertyhive_make_enquiry_button()
 {
     ph_get_template('global/make-enquiry.php');
 }
 /**
  * Get the email footer.
  */
 public function email_footer($contact_id = '')
 {
     $unsubscribe_link = '#';
     if ($contact_id != '') {
         $unsubscribe_link = site_url() . '?ph_unsubscribe=' . base64_encode($contact_id . '|' . md5(get_post_meta($contact_id, '_email_address', TRUE)));
     }
     ph_get_template('emails/email-footer.php', array('unsubscribe_link' => $unsubscribe_link));
 }