protected function column_col3()
 {
     $message = $this->message;
     // Sender becomes Receiver
     $message->receiverUsername = $message->senderUsername;
     $message->senderUsername = $_SESSION['Username'];
     $disabledTinyMce = $this->sender->getPreference("PreferenceDisableTinyMCE", $default = "No") == 'Yes';
     if ($disabledTinyMce) {
         $html2text = new Html2Text\Html2Text($message->Message, false, array('do_links' => 'inline', 'width' => 75));
         $message->Message = $html2text->get_text();
         $message->Message = "\n\n>" . str_replace("\n", "\n>", $message->Message);
     } else {
         $purifier = new MOD_htmlpure();
         $purifier = $purifier->getMessagesHtmlPurifier();
         $message->Message = $purifier->purify($message->Message);
         $message->Message = "<p></p><blockquote>" . $message->Message . "</blockquote><p></p>";
     }
     $contact_username = $message->senderUsername;
     $direction_in = true;
     if ($contact_username == $_SESSION['Username']) {
         $contact_username = $message->receiverUsername;
         $direction_in = false;
     }
     parent::column_col3();
 }
 public function __construct($origName, $description)
 {
     $this->name = $origName;
     $html = new \Html2Text\Html2Text($description);
     $description = $html->getText();
     //$description = preg_replace ( '/ \t/m', "\t" , $description);
     $description = str_replace(" \t", "\t", $description);
     $this->description = $description;
 }
    public function testIgnoreSpans()
    {
        $expected_output = <<<EOT
Outside
EOT;
        $html2text = new \Html2Text\Html2Text($this->input);
        $output = $html2text->get_text();
        $this->assertEquals($expected_output, $output);
    }
 public static function html2text($html)
 {
     if (class_exists('Html2Text\\Html2Text', true)) {
         $html = new \Html2Text\Html2Text($html);
         return $html->getText();
     } else {
         return static::makePlain($html);
     }
 }
    public function testDoLinksNextline()
    {
        $expected_output = <<<EOT
Link text
[http://example.com]
EOT;
        $html2text = new \Html2Text\Html2Text($this->input, false, array('do_links' => 'inline'));
        $output = $html2text->get_text();
        $this->assertEquals($expected_output, $output);
    }
    public function testDefinitionList()
    {
        $expected_output = <<<EOT
 \t* Definition Term: Definition Description 


EOT;
        $html2text = new \Html2Text\Html2Text($this->input);
        $output = $html2text->get_text();
        $this->assertEquals($expected_output, $output);
    }
    public function testStrToUpper()
    {
        $expected_output = <<<EOT
WILL BE UTF-8 (ÄÖÜÈÉИЛČΛ) UPPERCASED

Will remain lowercased
EOT;
        $html2text = new \Html2Text\Html2Text($this->input);
        $output = $html2text->get_text();
        $this->assertEquals($expected_output, $output);
    }
Beispiel #8
0
 public function setHtmlMessage($markup)
 {
     $this->htmlMessage = new Mime\Part($markup);
     $this->htmlMessage->type = Mime\Mime::TYPE_HTML;
     $this->htmlMessage->charset = 'utf-8';
     #$this->htmlMessage->encoding    = Mime\Mime::ENCODING_8BIT;
     $this->htmlMessage->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $this->htmlMessage->disposition = Mime\Mime::DISPOSITION_INLINE;
     #$convert_html = mb_convert_encoding($markup, 'HTML-ENTITIES', 'UTF-8');
     $html2text = new \Html2Text\Html2Text($markup);
     $text = $html2text->getText();
     $this->setTextMessage($text);
     $this->isHtml = true;
 }
Beispiel #9
0
 protected function column_col3()
 {
     $message = $this->message;
     // Sender becomes Receiver
     $disabledTinyMce = $this->sender->getPreference("PreferenceDisableTinyMCE", $default = "No") == 'Yes';
     if ($disabledTinyMce) {
         $html2text = new Html2Text\Html2Text($message->Message, false, array('dolinks' => 'inline', 'width' => 75));
         $message->Message = $html2text->get_text();
     } else {
         $purifier = new MOD_htmlpure();
         $purifier = $purifier->getMessagesHtmlPurifier();
         $message->Message = $purifier->purify($message->Message);
     }
     parent::column_col3();
 }
Beispiel #10
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}'");
 }
Beispiel #12
0
 public function summary()
 {
     $html = new \Html2Text\Html2Text($this->body);
     return Str::words($html->getText(), 50);
 }
Beispiel #13
0
 /**
  * @return mixed
  */
 public function getSummary()
 {
     $summary = $this->summary;
     if (empty($summary)) {
         if (!empty($this->content)) {
             $html = new \Html2Text\Html2Text($this->content);
             $summary = $html->getText();
             $summary = preg_replace('/\\s+/', ' ', $summary);
             $summary = trim($summary);
         }
     }
     return $summary;
 }
$serverName = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
define('DOMAIN', str_replace('www.', '', $serverName));
// URI-Redirector Prefix (leave empty for direct links)
define('URI_REDIRECT_PREFIX', "http://www.redirect.am/?");
// --- end of CONFIG
// setup slim & twig
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig(), 'templates.path' => 'app/templates', 'slim.url_scheme' => 'https'));
$app->error(function (\Exception $e) use($app) {
    error_log($e->getMessage());
    $app->callErrorHandler($e);
});
$app->view()->parserOptions = array('cache' => __DIR__ . '/cache');
$app->view()->parserExtensions = array(new \Slim\Views\TwigExtension(), new DisposableEmail\AutoLinkTwigExtension());
// add html2Text filter
$app->view()->getInstance()->addFilter(new Twig_SimpleFilter('html2Text', function ($string) {
    $convert = new \Html2Text\Html2Text($string);
    return $convert->get_text();
}));
// redirect to random address
$app->get('/', function () use($app) {
    $wordLength = rand(3, 8);
    $container = new PronounceableWord_DependencyInjectionContainer();
    $generator = $container->getGenerator();
    $word = $generator->generateWordOfGivenLength($wordLength);
    $nr = rand(51, 91);
    $name = $word . $nr;
    $app->redirect($app->urlFor('read', array('name' => $name)));
})->name('home');
// switch to other account using form
$app->post('/switch', function () use($app) {
    $name = cleanName($app->request->params('name'));
Beispiel #15
0
/**
* This function mails a text $body to the recipient $to.
* You can use more than one recipient when using a semikolon separated string with recipients.
*
* @param string $body Body text of the email in plain text or HTML
* @param mixed $subject Email subject
* @param mixed $to Array with several email addresses or single string with one email address
* @param mixed $from
* @param mixed $sitename
* @param mixed $ishtml
* @param mixed $bouncemail
* @param mixed $attachment
* @return bool If successful returns true
*/
function SendEmailMessage($body, $subject, $to, $from, $sitename, $ishtml = false, $bouncemail = null, $attachments = null, $customheaders = "")
{
    global $maildebug, $maildebugbody;
    require_once APPPATH . '/third_party/html2text/src/Html2Text.php';
    $emailmethod = Yii::app()->getConfig('emailmethod');
    $emailsmtphost = Yii::app()->getConfig("emailsmtphost");
    $emailsmtpuser = Yii::app()->getConfig("emailsmtpuser");
    $emailsmtppassword = Yii::app()->getConfig("emailsmtppassword");
    $emailsmtpdebug = Yii::app()->getConfig("emailsmtpdebug");
    $emailsmtpssl = Yii::app()->getConfig("emailsmtpssl");
    $defaultlang = Yii::app()->getConfig("defaultlang");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    if ($emailcharset != 'utf-8') {
        $body = mb_convert_encoding($body, $emailcharset, 'utf-8');
        $subject = mb_convert_encoding($subject, $emailcharset, 'utf-8');
        $sitename = mb_convert_encoding($sitename, $emailcharset, 'utf-8');
    }
    if (!is_array($to)) {
        $to = array($to);
    }
    if (!is_array($customheaders) && $customheaders == '') {
        $customheaders = array();
    }
    if (Yii::app()->getConfig('demoMode')) {
        $maildebug = gT('Email was not sent because demo-mode is activated.');
        $maildebugbody = '';
        return false;
    }
    if (is_null($bouncemail)) {
        $sender = $from;
    } else {
        $sender = $bouncemail;
    }
    require_once APPPATH . '/third_party/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    if (!$mail->SetLanguage($defaultlang, APPPATH . '/third_party/phpmailer/language/')) {
        $mail->SetLanguage('en', APPPATH . '/third_party/phpmailer/language/');
    }
    $mail->CharSet = $emailcharset;
    if (isset($emailsmtpssl) && trim($emailsmtpssl) !== '' && $emailsmtpssl !== 0) {
        if ($emailsmtpssl === 1) {
            $mail->SMTPSecure = "ssl";
        } else {
            $mail->SMTPSecure = $emailsmtpssl;
        }
    }
    $fromname = '';
    $fromemail = $from;
    if (strpos($from, '<')) {
        $fromemail = substr($from, strpos($from, '<') + 1, strpos($from, '>') - 1 - strpos($from, '<'));
        $fromname = trim(substr($from, 0, strpos($from, '<') - 1));
    }
    $sendername = '';
    $senderemail = $sender;
    if (strpos($sender, '<')) {
        $senderemail = substr($sender, strpos($sender, '<') + 1, strpos($sender, '>') - 1 - strpos($sender, '<'));
        $sendername = trim(substr($sender, 0, strpos($sender, '<') - 1));
    }
    switch ($emailmethod) {
        case "qmail":
            $mail->IsQmail();
            break;
        case "smtp":
            $mail->IsSMTP();
            if ($emailsmtpdebug > 0) {
                $mail->SMTPDebug = $emailsmtpdebug;
            }
            if (strpos($emailsmtphost, ':') > 0) {
                $mail->Host = substr($emailsmtphost, 0, strpos($emailsmtphost, ':'));
                $mail->Port = substr($emailsmtphost, strpos($emailsmtphost, ':') + 1);
            } else {
                $mail->Host = $emailsmtphost;
            }
            $mail->Username = $emailsmtpuser;
            $mail->Password = $emailsmtppassword;
            if (trim($emailsmtpuser) != "") {
                $mail->SMTPAuth = true;
            }
            break;
        case "sendmail":
            $mail->IsSendmail();
            break;
        default:
            //Set to the default value to rule out incorrect settings.
            $emailmethod = "mail";
            $mail->IsMail();
    }
    $mail->SetFrom($fromemail, $fromname);
    $mail->Sender = $senderemail;
    // Sets Return-Path for error notifications
    foreach ($to as $singletoemail) {
        if (strpos($singletoemail, '<')) {
            $toemail = substr($singletoemail, strpos($singletoemail, '<') + 1, strpos($singletoemail, '>') - 1 - strpos($singletoemail, '<'));
            $toname = trim(substr($singletoemail, 0, strpos($singletoemail, '<') - 1));
            $mail->AddAddress($toemail, $toname);
        } else {
            $mail->AddAddress($singletoemail);
        }
    }
    if (is_array($customheaders)) {
        foreach ($customheaders as $key => $val) {
            $mail->AddCustomHeader($val);
        }
    }
    $mail->AddCustomHeader("X-Surveymailer: {$sitename} Emailer (LimeSurvey.sourceforge.net)");
    if (get_magic_quotes_gpc() != "0") {
        $body = stripcslashes($body);
    }
    if ($ishtml) {
        $mail->IsHTML(true);
        if (strpos($body, "<html>") === false) {
            $body = "<html>" . $body . "</html>";
        }
        $mail->msgHTML($body, App()->getConfig("publicdir"));
        // This allow embedded image if we remove the servername from image
        $html = new \Html2Text\Html2Text($body);
        $mail->AltBody = $html->getText();
    } else {
        $mail->IsHTML(false);
        $mail->Body = $body;
    }
    // Add attachments if they are there.
    if (is_array($attachments)) {
        foreach ($attachments as $attachment) {
            // Attachment is either an array with filename and attachment name.
            if (is_array($attachment)) {
                $mail->AddAttachment($attachment[0], $attachment[1]);
            } else {
                // Or a string with the filename.
                $mail->AddAttachment($attachment);
            }
        }
    }
    $mail->Subject = $subject;
    if ($emailsmtpdebug > 0) {
        ob_start();
    }
    $sent = $mail->Send();
    $maildebug = $mail->ErrorInfo;
    if ($emailsmtpdebug > 0) {
        $maildebug .= '<li>' . gT('SMTP debug output:') . '</li><pre>' . strip_tags(ob_get_contents()) . '</pre>';
        ob_end_clean();
    }
    $maildebugbody = $mail->Body;
    //if(!$sent) var_dump($maildebug);
    return $sent;
}
Beispiel #16
0
 public static function sendEmail($subject, $from, $to, $title, $body, $language = 'en', $html = true, $attach = array())
 {
     self::init();
     // Check that $to/$from are both arrays
     $from = is_array($from) ? $from : explode(',', $from);
     $to = is_array($to) ? $to : explode(',', $to);
     //Create the message
     $message = self::getSwift()->setSubject($subject)->setFrom($from)->setTo($to);
     // Purify HTML. All tags for forum posts + <hr> for the footer separation
     $purifier = MOD_htmlpure::get()->getMailHtmlPurifier();
     $body = $purifier->purify($body);
     $html2text = new Html2Text\Html2Text($body, false, array('do_links' => 'table', 'width' => 75));
     $plain = $html2text->getText();
     $message->setBody($plain);
     //        $message->addPart($plain, 'text/plain');
     // Add the html-body only if the member wants HTML mails
     if ($html) {
         // Translate footer text (used in HTML template)
         $words = new MOD_words();
         $footer_message = $words->getPurified('MailFooterMessage', array(date('Y')), $language);
         // Using a html-template
         ob_start();
         require SCRIPT_BASE . 'templates/shared/mail_html.php';
         $mail_html = ob_get_contents();
         ob_end_clean();
         $message->addPart($mail_html, 'text/html');
     }
     return self::sendSwift($message);
 }
Beispiel #17
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);
Beispiel #18
0
 private function _postProcess()
 {
     //Проверяем отправлена ли форма
     if (Tools::isSubmit('submitTutorial')) {
         //Получаем значение поля формы tutorial_url
         $tutorial_url = Tools::getValue('tutorial_url');
         //Проверяем валидность ссылки
         if (Validate::isUrl($tutorial_url)) {
             //Сохраняем настройку
             Configuration::updateValue('TUTORIAL_URL', $tutorial_url);
             //Выводим сообщение об успешном сохранении
             $this->_html .= $this->displayConfirmation($this->l('Настройки обновлены.'));
         } else {
             //Выводим сообщение об ошибке
             $this->_html .= $this->displayError($this->l('Неверная ссылка.'));
         }
     }
     //Проверяем отправлена ли форма с номером каталога
     if (Tools::isSubmit('exportPrintCatalog')) {
         //Получаем значение поля формы num_catalog
         $num_catalog = Tools::getValue('num_catalog');
         //Проверяем валидность номера
         if (Validate::isInt($num_catalog)) {
             //Выполняем запрос
             //SELECT p.id_product, f9.author, pl.name, pl.description, CONCAT_WS(' ',f14.izdat, f10.god, f11.pereplet, f12.stranits, IFNULL(CONCAT('€ ',ROUND(p.price,2)), NULL)) as info, p.reference, /*lcp.id_category, lcp.level_depth,*/ cl.name, /*fp.id_feature, fl.name, fvl.value */
             //SELECT p.id_product, f9.author, pl.name as prod_name, pl.description, CONCAT_WS(' ',f14.izdat, f10.god, f11.pereplet, f12.stranits, IFNULL(CONCAT('€ ',ROUND(p.price,2)), NULL)) as info, p.reference, cl.name as cat_name
             $sql = "\n\t\t\t\t\tSELECT p.id_product, f9.author, pl.name as prod_name, pl.description, f14.izdat, f10.god, f11.pereplet, f12.stranits, p.price, p.reference, cl.name as cat_name\n\t\t\t\t\t\n\t\t\t\t\tFROM " . _DB_PREFIX_ . "product as p\n\t\t\t\t\tINNER JOIN\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tON fp.id_product = p.id_product\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_lang AS fl \n\t\t\t\t\tON fl.id_feature = fp.id_feature\n\t\t\t\t\tINNER JOIN \n\t\t\t\t\t" . _DB_PREFIX_ . "feature_value_lang AS fvl \n\t\t\t\t\tON fp.id_feature_value = fvl.id_feature_value\n\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT fp.id_product, fvl.id_feature_value, IFNULL(CONCAT(fvl.value, ','), NULL) as izdat FROM\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "feature_value_lang AS fvl ON fp.id_feature_value = fvl.id_feature_value\n\t\t\t\t\tWHERE fvl.id_lang =1 AND fp.id_feature = 14) as f14\n\t\t\t\t\tON p.id_product = f14.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT id_product, fvl.id_feature_value, IFNULL(CONCAT(fvl.value, '.'), NULL) as god FROM\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "feature_value_lang AS fvl ON fp.id_feature_value = fvl.id_feature_value\n\t\t\t\t\tWHERE fvl.id_lang =1 AND fp.id_feature = 10) as f10\n\t\t\t\t\tON p.id_product = f10.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT id_product, fvl.id_feature_value, IFNULL(CONCAT(fvl.value, '.'), NULL)  as pereplet FROM\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "feature_value_lang AS fvl ON fp.id_feature_value = fvl.id_feature_value\n\t\t\t\t\tWHERE fvl.id_lang =1 AND fp.id_feature = 11) as f11\n\t\t\t\t\tON p.id_product = f11.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT id_product, fvl.id_feature_value, IFNULL(CONCAT(fvl.value, ' с.'), NULL) as stranits FROM\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "feature_value_lang AS fvl ON fp.id_feature_value = fvl.id_feature_value\n\t\t\t\t\tWHERE fvl.id_lang =1 AND fp.id_feature = 12) as f12\n\t\t\t\t\tON p.id_product = f12.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT id_product, fvl.id_feature_value, fvl.value as author FROM\n\t\t\t\t\t" . _DB_PREFIX_ . "feature_product AS fp\n\t\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "feature_value_lang AS fvl ON fp.id_feature_value = fvl.id_feature_value\n\t\t\t\t\tWHERE fvl.id_lang =1 AND fp.id_feature = 9) as f9\n\t\t\t\t\tON p.id_product = f9.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t" . _DB_PREFIX_ . "product_lang as pl\n\t\t\t\t\tON p.id_product = pl.id_product \n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t" . _DB_PREFIX_ . "category_product as cp\n\t\t\t\t\tON p.id_product = cp.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t(SELECT *\n\t\t\t\t\tFROM (\n\t\t\t\t\tSELECT c.level_depth, c.id_category, cp.id_product\n\t\t\t\t\t    FROM " . _DB_PREFIX_ . "category as c\n\t\t\t\t\t    LEFT JOIN " . _DB_PREFIX_ . "category_product as cp \n\t\t\t\t\t    ON cp.id_category=c.id_category\n\t\t\t\t\tORDER BY level_depth desc\n\t\t\t\t\t) as lcp\n\t\t\t\t\tGROUP BY id_product\n\t\t\t\t\t)as lcp\n\t\t\t\t\tON cp.id_product = lcp.id_product\n\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t" . _DB_PREFIX_ . "category_lang as cl\n\t\t\t\t\tON lcp.id_category = cl.id_category\n\n\t\t\t\t\tWHERE pl.id_lang = 1 AND pl.id_shop = 1 AND fvl.id_lang =1 AND fp.id_feature = 8 AND fvl.value='" . $num_catalog . "'\n\t\t\t\t\tGROUP BY p.id_product\n\t\t\t\t";
             var_dump($sql);
             if ($results = Db::getInstance()->ExecuteS($sql)) {
                 //Формируем CSV файл и выводим в браузер
                 $delimiter = ";";
                 $tmp_file = dirname(__FILE__) . "/Print_catalog_export.csv";
                 $tmp_url = "http" . (!empty($_SERVER['HTTPS']) ? "s" : "") . "://" . $_SERVER['SERVER_NAME'] . "/modules/" . $this->name . "/Print_catalog_export.csv";
                 $f = fopen($tmp_file, 'w');
                 if ($f === false) {
                     $this->_html .= $this->displayError($this->l('Не удалось записать файл.'));
                     break;
                 } else {
                     $this->tmp_url = '<a href="' . $tmp_url . '">Скачать</a>';
                     $num_products = 0;
                     require_once __DIR__ . '/html2text/lib/Html2Text/Html2Text.php';
                     foreach ($results as $line) {
                         //$line['description'] = convert_html_to_text($line['description']);
                         $this->_html .= $line['description'] . "<br/>";
                         $html2text = new \Html2Text\Html2Text($line['description'], false, array('do_links' => 'none', 'width' => 0));
                         $line['description'] = $html2text->get_text();
                         $id_product = $line['id_product'];
                         $price_withtaxes = Product::getPriceStatic($id_product);
                         $line['price'] = "€ " . $price_withtaxes;
                         fputcsv($f, $line, $delimiter);
                         $num_products++;
                     }
                     fclose($f);
                 }
                 //Выводим сообщение об успешном сохранении
                 $this->_html .= $this->displayConfirmation($this->l('Печатный каталог ' . $num_catalog . ' выгружен. ' . $num_products . ' товаров.'));
             } else {
                 //Выводим сообщение об ошибке
                 $this->_html .= $this->displayError($this->l('Не найдены товары для каталога № ' . $num_catalog . '.'));
             }
         } else {
             //Выводим сообщение об ошибке
             $this->_html .= $this->displayError($this->l('Неверный номер каталога.'));
         }
     }
 }
Beispiel #19
0
function fix_newlines($text)
{
    return Html2Text\Html2Text::fixNewlines($text);
}
 protected function createConfirmationEmail($arrSubmissionData)
 {
     $arrRecipient = deserialize($arrSubmissionData[$this->confirmationMailRecipientField]['value'], true);
     $objEmail = new \Email();
     $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
     $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
     $objEmail->subject = \String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags($this->confirmationMailSubject, $arrSubmissionData), false), $arrSubmissionData);
     if ($hasText = strlen($this->confirmationMailText) > 0) {
         $objEmail->text = \String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags($this->confirmationMailText, $arrSubmissionData), false), $arrSubmissionData);
         // convert <br> to new line and strip tags, except links
         $objEmail->text = strip_tags(preg_replace('/<br(\\s+)?\\/?>/i', "\n", $objEmail->text), '<a>');
     }
     if ($this->confirmationMailTemplate != '') {
         $objModel = \FilesModel::findByUuid($this->confirmationMailTemplate);
         if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
             $objFile = new \File($objModel->path, true);
             $objEmail->html = \String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags($objFile->getContent(), $arrSubmissionData), false), $arrSubmissionData);
             // if no text is set, convert html to text
             if (!$hasText) {
                 $objHtml2Text = new \Html2Text\Html2Text($objEmail->html);
                 $objEmail->text = $objHtml2Text->getText();
             }
         }
     }
     // overwrite default from and
     if (!empty($this->confirmationMailSender)) {
         list($senderName, $sender) = \String::splitFriendlyEmail($this->confirmationMailSender);
         $objEmail->from = $this->replaceInsertTags(FormHelper::replaceFormDataTags($sender, $arrSubmissionData), false);
         $objEmail->fromName = $this->replaceInsertTags(FormHelper::replaceFormDataTags($senderName, $arrSubmissionData), false);
     }
     if ($this->confirmationMailAttachment != '') {
         $this->addAttachmentToEmail($objEmail, deserialize($this->confirmationMailAttachment));
     }
     if ($this->sendConfirmationEmail($objEmail, $arrRecipient, $arrSubmissionData)) {
         if (is_array($arrRecipient)) {
             $arrRecipient = array_filter(array_unique($arrRecipient));
             try {
                 $objEmail->sendTo($arrRecipient);
             } catch (Exception $e) {
                 log_message('Error sending submission email for entity ' . $this->strTable . ':' . $this->intId . ' to : ' . implode(',', $arrRecipient) . ' (' . $e . ')', $this->strLogFile);
             }
         }
     }
 }
Beispiel #21
0
/**
 * Convert HTML to plain text
 * @param string $html content to convert
 * @return string
 */
function convert_html_to_text($html)
{
    require APP_PATH . 'third_party/Html2Text.php';
    $html = new \Html2Text\Html2Text($html, array('do_links' => 'table', 'width' => 0));
    return $html->getText();
}
Beispiel #22
0
 public function getPlainText($content, $baseUrl)
 {
     $converter = new \Html2Text\Html2Text($content, array('do_links' => 'table'));
     $converter->setBaseUrl($baseUrl);
     return $converter->getText();
 }
Beispiel #23
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);
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  * The return value is the number of recipients who were accepted for delivery.
  *
  * @param Swift_Mime_Message $message
  * @param string[]           $failedRecipients An array of failures by-reference
  *
  * @return integer
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null, $options = array())
 {
     class_exists('Swift_Mailer');
     // just to pass condition in MessageDataCollector
     $default_options = ['open_tracking' => true, 'click_tracking' => false];
     $options = array_merge($default_options, $options);
     if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) {
         $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
         if ($evt->bubbleCancelled()) {
             return 0;
         }
     }
     // Ajout automatique de la version texte si le mail ne contient que du HTML
     if ($message->getContentType() == 'text/html') {
         $text = new \Html2Text\Html2Text($message->getBody());
         $message->addPart($text->getText(), 'text/plain');
     }
     $fromHeader = $message->getHeaders()->get('From');
     if ($fromHeader->getFieldBody() == '' && $this->getDefaultFrom() != null) {
         $message->setFrom($this->getDefaultFrom());
     }
     $toHeader = $message->getHeaders()->get('To');
     if (!$toHeader) {
         throw new \Swift_TransportException('Cannot send message without a recipient');
     }
     $from = $fromHeader->getFieldBody();
     $to = $toHeader->getFieldBody();
     $message_data = ['from' => $from, 'to' => $to];
     // Ajout d'options dans les trackings
     if ($options['open_tracking'] === true) {
         $message_data['o:tracking-opens'] = 'yes';
     }
     if ($this->isDeliveryEnabled()) {
         $result = $this->mailgun->sendMessage($this->domain, $message_data, $message->toString());
         $success = $result->http_response_code == 200;
     } else {
         $success = true;
     }
     if ($evt) {
         $evt->setResult($success ? Swift_Events_SendEvent::RESULT_SUCCESS : Swift_Events_SendEvent::RESULT_FAILED);
         $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed');
     }
     return 1;
 }
Beispiel #25
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;
}
Beispiel #26
0
/**
 * Convert HTML to text
 */
function html2text($input, $remove_new_lines = false)
{
    require_once 'lib/Html2Text.php';
    $html = new \Html2Text\Html2Text($input);
    $plain_text = $html->getText();
    if ($remove_new_lines) {
        $plain_text = preg_replace('/\\n/', ' ', $plain_text);
    }
    return $plain_text;
}
Beispiel #27
0
    public static function send($from, $recipients, $subject, $from_name = false, $text_version = false, $html_version = false, $variables = false)
    {
        global $CFG;
        $reply_to = $from;
        $var_string = '';
        if (is_array($variables)) {
            foreach ($variables as $name => $value) {
                $var_string .= '
					' . ucfirst(str_ireplace('_', ' ', $name)) . ': ' . $value . '<br/>';
            }
        }
        $html_version = str_ireplace('[variables]', $var_string, $html_version);
        $text_version = str_ireplace('[variables]', $var_string, $text_version);
        $html_version = str_ireplace('&amp;', '&', $html_version);
        $text_version = str_ireplace('&amp;', '&', $text_version);
        if (is_array($variables)) {
            foreach ($variables as $key => $val) {
                $html_version = str_ireplace('[' . $key . ']', $val, $html_version);
                $text_version = str_ireplace('[' . $key . ']', $val, $text_version);
                $subject = str_ireplace('[' . $key . ']', $val, $subject);
            }
        }
        if (!$text_version) {
            include_once 'Html2Text.php';
            $h2t = new \Html2Text\Html2Text($html_version);
            $h2t->set_base_url($CFG->baseurl);
            $text_version = $h2t->get_text();
        }
        if (!$html_version) {
            $html_version = nl2br($text_version);
        }
        include_once 'phpmailer/PHPMailerAutoload.php';
        $mail = new PHPMailer();
        $mail->isSMTP();
        $mail->CharSet = 'UTF-8';
        $mail->SMTPDebug = 0;
        $mail->Debugoutput = 'html';
        $mail->Host = $CFG->email_smtp_host;
        $mail->Port = $CFG->email_smtp_port;
        $mail->SMTPSecure = $CFG->email_smtp_security;
        $mail->SMTPAuth = true;
        $mail->Username = $CFG->email_smtp_username;
        $mail->Password = $CFG->email_smtp_password;
        $mail->setFrom($CFG->email_smtp_send_from, $from_name);
        $mail->addReplyTo($from);
        if (is_array($recipients)) {
            foreach ($recipients as $name => $email) {
                if (!self::verifyAddress($email)) {
                    unset($recipients[$name]);
                    continue;
                }
                $mail->addAddress($email, $name);
            }
        } else {
            if (self::verifyAddress($recipients)) {
                $mail->addAddress($recipients);
            }
        }
        $mail->Subject = $subject;
        $mail->msgHTML($html_version);
        $mail->AltBody = $text_version;
        if ($mail->send()) {
            return true;
        } else {
            trigger_error('Email could not be sent: ' . print_r($mail->ErrorInfo, true), E_USER_WARNING);
            return false;
        }
    }
Beispiel #28
0
 /**
  * Get the text from an html string
  *
  * @param string $text        	
  * @return string
  *
  */
 private function get_text($text)
 {
     // Strip links first because Html2Text puts them in the output
     $text = preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $text);
     $html2Text = new \Html2Text\Html2Text($text);
     $text = $html2Text->get_text();
     $text = html_entity_decode($text, ENT_QUOTES);
     // Strip multiply spaces and remove line breaks
     $text = preg_replace('/\\s+/m', ' ', $text);
     $text = \Rss\Util\Helpers\Helpers::fix_smartquotes($text);
     $text = trim($text);
     return $text;
 }
 /**
  * @param unknown $text
  * @return Ambigous <string, mixed>
  */
 private function get_text($text)
 {
     // Strip links first
     $text = preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $text);
     $html2Text = new \Html2Text\Html2Text($text);
     $text = $html2Text->get_text();
     // Strip multiply spaces and remove line breaks
     $text = preg_replace('/\\s+/m', ' ', $text);
     $text = \Rss\Util\Helpers\Helpers::fix_smartquotes($text);
     return $text;
 }
$i = 1;
foreach ($trails as $id => $trail) {
    if ($trail['loopcount'] == 1) {
        $distance = $trail['loops'][1]['distance'];
        $steps = $trail['loops'][1]['steps'];
    } else {
        $looptext = $trail['loopcount'] . " loops";
        $distance = 0;
        $steps = 0;
        foreach ($trail['loops'] as $id => $details) {
            $distance = $trail['loops'][$id]['distance'] + $distance;
            $steps = $trail['loops'][$id]['steps'] + $steps;
        }
    }
    $published = $trail['published'] == 'true';
    $html = new \Html2Text\Html2Text(rawurldecode($trail['desc']));
    $desc = $html->getText();
    ?>

<div class="row">
	<span><?php 
    echo $trail['city'];
    ?>
, <?php 
    echo $trail['zip'];
    ?>
</span>
	<span style="float:right">Trail <?php 
    echo $i;
    ?>
 of <?php