<?php

/**
 * The utility class for mail templating stuff
 *
 * @since      1.0.2
 * @package    Wedima_Site
 * @subpackage Wedima_Site/utils/mail
 * @author     Jitendra Bodmann <jitendra.bodmann@wedima.de>
 */
class Wedima_Site_Mail_Template_Util
{
    /**
     * Loads the email template from public/mail/templates/mail.php
     *
     * @param [type] $message
     * @return void
     */
    static function load_mail_template($message)
    {
        // replace line breaks of plain text with <br> if message is html
        $is_message_html = self::is_html($message);
        $mail_message = $is_message_html ? $message : str_replace(["\r\n", "\n", "\r"], "<br>", $message);
        ob_start();
        include(WEDIMA_SITE_ROOT_DIR . 'utils/mail/templates/mail.php');
        return ob_get_clean();
    }

    /**
     * Check if string contains any html tags
     *
     * @param [type] $string
     * @return boolean
     */
    static function is_html($string)
    {
        return preg_match('/<\s?[^\>]*\/?\s?>/i', $string);
    }
}
