Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public static function html2text($html)
 {
     if (class_exists('Html2Text\\Html2Text', true)) {
         $html = new \Html2Text\Html2Text($html);
         return $html->getText();
     } else {
         return static::makePlain($html);
     }
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
 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);
             }
         }
     }
 }
Ejemplo n.º 8
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();
}
Ejemplo n.º 9
0
 public function getPlainText($content, $baseUrl)
 {
     $converter = new \Html2Text\Html2Text($content, array('do_links' => 'table'));
     $converter->setBaseUrl($baseUrl);
     return $converter->getText();
 }
 /**
  * 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;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
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 
    echo $count;
Ejemplo n.º 13
0
 public function summary()
 {
     $html = new \Html2Text\Html2Text($this->body);
     return Str::words($html->getText(), 50);
 }
Ejemplo n.º 14
0
        foreach ($trail['loops'] as $id => $details) {
            $distance = $trail['loops'][$id]['distance'] + $distance;
            $steps = $trail['loops'][$id]['steps'] + $steps;
        }
    }
    function limit_text($text, $limit)
    {
        if (str_word_count($text, 0) > $limit) {
            $words = str_word_count($text, 2);
            $pos = array_keys($words);
            $text = substr($text, 0, $pos[$limit]) . '...';
        }
        return $text;
    }
    $html = new \Html2Text\Html2Text(rawurldecode($trail['desc']));
    $metaDesc = str_replace("\n", ' ', $html->getText());
} else {
    header("HTTP/1.0 404 Not Found");
}
if ($userActive) {
    header("Cache-Control: no-cache, must-revalidate");
    // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
} else {
    //get the last-modified-date of this very file
    $lastModified = $trail['ModifiedTime'];
    //get a unique hash of this file (etag)
    $etagFile = md5_file(__FILE__);
    //get the HTTP_IF_MODIFIED_SINCE header if set
    $ifModifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
Ejemplo n.º 15
0
 /**
  * Sends email with PHPMailer
  * All email addresses can be in format: just email, array with `name` and `email` keys.
  * 
  * @param strintg $email Email address to send to
  * @param strintg $subject EMail subject
  * @param strintg $body EMail body
  * @param strintg $from From email address
  * @param strintg $replyto Reply to email address
  * @param strintg $ccemail CC email address
  * @param strintg $bccemail BCC email address
  * 
  * @return boolean Success or not
  */
 public function sendEmail($email, $subject, $body, $from, $replyto = '', $ccemail = '', $bccemail = '', $textemail = false)
 {
     $this->checkArguments($email, $subject, $body, $from, $replyto, $ccemail, $bccemail);
     // create PHPMailer object
     $mail = new \PHPMailer();
     $mail->SMTPDebug = 0;
     $mail->CharSet = 'UTF-8';
     // select mailsystem, get it from options
     if ($this->options['mailsystem'] == 'mail') {
         $mail->IsMail();
         $this->logQ("Sending with mail", 'mailsend|phpmailer');
     } else {
         $mail->IsSMTP();
         $this->logQ("Sending with SMTP", 'mailsend|phpmailer');
         if ($this->options['smtp_auth'] === 'no' || $this->options['smtp_auth'] === 'n' || is_bool($this->options['smtp_auth']) && !$this->options['smtp_auth']) {
             $mail->SMTPAuth = false;
             $this->logQ("SMTP Auth is Off", 'mailsend|phpmailer');
         } else {
             $mail->SMTPAuth = true;
             $mail->Username = $this->options['smtp_user'];
             $mail->Password = $this->options['smtp_password'];
             $this->logQ("SMTP Auth is On and user " . $mail->Username, 'mailsend|phpmailer');
         }
         if (isset($this->options['smtp_secure']) && ($this->options['smtp_secure'] && is_bool($this->options['smtp_secure']) || $this->options['smtp_secure'] === 'y' || $this->options['smtp_secure'] === 'yes')) {
             $mail->SMTPSecure = $this->options['smtp_secure_proto'] != '' ? $this->options['smtp_secure_proto'] : "tls";
             $this->logQ("SMTP secure is On with proto " . $mail->SMTPSecure, 'mailsend|phpmailer');
         }
         $mail->Host = $this->options['smtp_host'];
         $mail->Port = $this->options['smtp_port'];
         $this->logQ("SMTP host " . $mail->Host . ":" . $mail->Port, 'mailsend|phpmailer');
     }
     // set up email credentials
     if (is_array($replyto)) {
         $mail->AddReplyTo($replyto['address'], $replyto['name']);
     } elseif ($replyto != '') {
         $mail->AddReplyTo($replyto, '');
     }
     if (is_array($from)) {
         $mail->SetFrom($from['address'], $from['name']);
         $mail->From = $from['address'];
         $mail->FromName = $from['name'];
     } else {
         $mail->SetFrom($from);
         $mail->From = $from;
     }
     $mail->Subject = $subject;
     if ($textemail) {
         $mail->Body = $body;
     } else {
         $mail->MsgHTML($body);
         // prepare text version automatically
         $h2t = new \Html2Text\Html2Text($body);
         $mail->AltBody = $h2t->getText();
     }
     if (is_array($email)) {
         $mail->AddAddress($email['address'], $email['name']);
     } else {
         $mail->AddAddress($email);
     }
     if (is_array($ccemail)) {
         $mail->AddCC($ccemail['address'], $ccemail['name']);
     } elseif ($ccemail != '') {
         $mail->AddCC($ccemail);
     }
     if (is_array($bccemail)) {
         $mail->AddCC($bccemail['address'], $bccemail['name']);
     } elseif ($bccemail != '') {
         $mail->AddCC($bccemail);
     }
     $att = 1;
     $success = false;
     // try to send 5 times. for case when SMTP is not very stable
     do {
         if (!$mail->Send()) {
             $att++;
             sleep(1);
         } else {
             $success = true;
         }
     } while (!$success && $att < 5);
     if (!$success) {
         $this->logQ('EMail sending error: ' . $mail->ErrorInfo, 'mailererror');
         throw new \Exception(sprintf('EMail sending error: %s', $mail->ErrorInfo));
     }
     return true;
 }