예제 #1
0
 function doTest($test)
 {
     $this->assertTrue(file_exists(__DIR__ . "/{$test}.html"), "File '{$test}.html' did not exist");
     $this->assertTrue(file_exists(__DIR__ . "/{$test}.txt"), "File '{$test}.txt' did not exist");
     $input = file_get_contents(__DIR__ . "/{$test}.html");
     $expected = Html2Text\Html2Text::fixNewlines(file_get_contents(__DIR__ . "/{$test}.txt"));
     $output = Html2Text\Html2Text::convert($input);
     if ($output != $expected) {
         file_put_contents(__DIR__ . "/{$test}.output", $output);
     }
     $this->assertEquals($output, $expected);
 }
 function testAll()
 {
     $dir = __DIR__ . "/../emails/";
     $found = false;
     $this->assertNotFalse($handle = opendir($dir));
     while (false !== ($entry = readdir($handle))) {
         if ($entry != "." && $entry != "..") {
             if (substr(strtolower($entry), -5) == ".html") {
                 $file = file_get_contents($dir . $entry);
                 $previous = libxml_use_internal_errors(true);
                 $this->assertNotNull(Html2Text\Html2Text::convert($file), "Could not convert '{$entry}'");
                 foreach (libxml_get_errors() as $error) {
                     $this->fail("Could not load '{$entry}': " . $error->message);
                 }
                 libxml_clear_errors();
                 libxml_use_internal_errors($previous);
                 $found = true;
             }
         }
     }
     closedir($handle);
     $this->assertNotFalse($found, "Did not find any email templates to test in '{$dir}'");
 }
예제 #3
0
function ew_SendEmail($sFrEmail, $sToEmail, $sCcEmail, $sBccEmail, $sSubject, $sMail, $sFormat, $sCharset, $sSmtpSecure = "", $arAttachments = array(), $arImages = array(), $arProperties = NULL)
{
    global $Language, $gsEmailErrDesc;
    $res = FALSE;
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = EW_SMTP_SERVER;
    $mail->SMTPAuth = EW_SMTP_SERVER_USERNAME != "" && EW_SMTP_SERVER_PASSWORD != "";
    $mail->Username = EW_SMTP_SERVER_USERNAME;
    $mail->Password = EW_SMTP_SERVER_PASSWORD;
    $mail->Port = EW_SMTP_SERVER_PORT;
    if ($sSmtpSecure != "") {
        $mail->SMTPSecure = $sSmtpSecure;
    }
    if (preg_match('/^(.+)<([\\w.%+-]+@[\\w.-]+\\.[A-Z]{2,6})>$/i', trim($sFrEmail), $m)) {
        $mail->From = $m[2];
        $mail->FromName = trim($m[1]);
    } else {
        $mail->From = $sFrEmail;
        $mail->FromName = $sFrEmail;
    }
    $mail->Subject = $sSubject;
    if (ew_SameText($sFormat, "html")) {
        $mail->IsHTML(TRUE);
        $mail->Body = $sMail;
    } else {
        $mail->IsHTML(FALSE);
        $mail->Body = @Html2Text\Html2Text::convert($sMail);
    }
    if ($sCharset != "" && strtolower($sCharset) != "iso-8859-1") {
        $mail->CharSet = $sCharset;
    }
    $sToEmail = str_replace(";", ",", $sToEmail);
    $arrTo = explode(",", $sToEmail);
    foreach ($arrTo as $sTo) {
        $mail->AddAddress(trim($sTo));
    }
    if ($sCcEmail != "") {
        $sCcEmail = str_replace(";", ",", $sCcEmail);
        $arrCc = explode(",", $sCcEmail);
        foreach ($arrCc as $sCc) {
            $mail->AddCC(trim($sCc));
        }
    }
    if ($sBccEmail != "") {
        $sBccEmail = str_replace(";", ",", $sBccEmail);
        $arrBcc = explode(",", $sBccEmail);
        foreach ($arrBcc as $sBcc) {
            $mail->AddBCC(trim($sBcc));
        }
    }
    if (is_array($arAttachments)) {
        foreach ($arAttachments as $attachment) {
            $filename = @$attachment["filename"];
            $content = @$attachment["content"];
            if ($content != "" && $filename != "") {
                $mail->AddStringAttachment($content, $filename);
            } else {
                if ($filename != "") {
                    $mail->AddAttachment($filename);
                }
            }
        }
    }
    if (is_array($arImages)) {
        foreach ($arImages as $tmpimage) {
            $file = ew_UploadPathEx(TRUE, EW_UPLOAD_DEST_PATH) . $tmpimage;
            $cid = ew_TmpImageLnk($tmpimage, "cid");
            $mail->AddEmbeddedImage($file, $cid, $tmpimage);
        }
    }
    if (is_array($arProperties)) {
        foreach ($arProperties as $key => $value) {
            $mail->set($key, $value);
        }
    }
    $res = $mail->Send();
    $gsEmailErrDesc = $mail->ErrorInfo;
    // Uncomment to debug
    //		var_dump($mail); exit();
    return $res;
}
예제 #4
0
/******************************************************************************
 * Copyright (c) 2010 Jevon Wright and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * or
 *
 * LGPL which is available at http://www.gnu.org/licenses/lgpl.html
 *
 *
 * Contributors:
 *    Jevon Wright - initial API and implementation
 ****************************************************************************/
/**
 * This file allows you to convert through the command line.
 * Usage:
 *   php -f convert.php [input file]
 */
if (count($argv) < 2) {
    throw new \InvalidArgumentException("Expected: php -f convert.php [input file]");
}
if (!file_exists($argv[1])) {
    throw new \InvalidArgumentException("'" . $argv[1] . "' does not exist");
}
$input = file_get_contents($argv[1]);
require_once __DIR__ . "/src/Html2Text.php";
require_once __DIR__ . "/src/Html2TextException.php";
echo Html2Text\Html2Text::convert($input);
예제 #5
0
<?php

require 'vendor/autoload.php';
var_dump($argv);
$html_file = $argv[1];
$text_file = $argv[2];
$html_handle = fopen($html_file, "r") or die("Unable to open file!");
$text_handle = fopen($text_file, "w");
$lines = "";
while (($line = fgets($html_handle)) !== false) {
    $lines .= $line;
}
$txt = Html2Text\Html2Text::convert($lines);
fwrite($text_handle, $txt);
fclose($html_handle);
fclose($text_handle);
예제 #6
0
function convert_html_to_text($html)
{
    return Html2Text\Html2Text::convert($html);
}
예제 #7
0
/**
 * convert HTML-Code to text
 *
 * @param string $input
 * @param boolean $admin
 * @return string text
 */
function html2text($input, $admin = true)
{
    if ($admin) {
        $path = "../";
    } else {
        $path = "";
    }
    // require_once $path . "include/libs/html2text/src/Html2Text.php";
    if (!empty($input)) {
        // https://github.com/soundasleep/html2text/issues/6
        $input = mb_convert_encoding($input, 'HTML-ENTITIES', 'UTF-8');
        $text = Html2Text\Html2Text::convert($input);
        return $text;
    } else {
        return "";
    }
}