/**
  * @dataProvider data_html2text
  */
 function test_html2text($title, $in, $out)
 {
     $ht = new html2text(null, false, false);
     $ht->set_html($in);
     $res = $ht->get_text();
     $this->assertEquals($out, $res, $title);
 }
function html2plaintext($text, $texthtml0, $wrap)
{
    global $opt, $smiley;
    if ($texthtml0) {
        $text = str_replace(['<p>', "\n", "\r"], '', $text);
        $text = str_replace(['<br />', '</p>'], "\n", $text);
        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
    } else {
        // convert smilies ...
        $countSmileyImage = count($smiley['image']);
        for ($n = 0; $n < $countSmileyImage; $n++) {
            $text = mb_ereg_replace("<img [^>]*?src=[^>]+?" . str_replace('.', '\\.', $smiley['file'][$n]) . "[^>]+?>", "[s![" . $smiley['text'][$n] . "]!s]", $text);
            // the [s[ ]s] is needed to protect the spaces around the smileys
        }
        $h2t = new html2text($text);
        $h2t->set_base_url($opt['page']['default_absolute_url']);
        $h2t->width = $wrap;
        $text = $h2t->get_text();
        $text = str_replace(['[s![', ']!s]'], '', $text);
        // remove e.g. trailing \n created from </p> by html2text
        while (substr($text, -2) == "\n\n") {
            $text = substr($text, 0, strlen($text) - 1);
        }
    }
    return $text;
}
Exemple #3
0
 function test_html2text()
 {
     $data = array(0 => array('title' => 'Test entry', 'in' => '', 'out' => ''), 1 => array('title' => 'Basic HTML entities', 'in' => '&quot;&amp;', 'out' => '"&'), 2 => array('title' => 'HTML entity string', 'in' => '&amp;quot;', 'out' => '&quot;'), 3 => array('title' => 'HTML entity in STRONG tag', 'in' => '<strong>&#347;</strong>', 'out' => 'Ś'), 4 => array('title' => 'STRONG tag to upper-case conversion', 'in' => '<strong>ś</strong>', 'out' => 'Ś'), 5 => array('title' => 'STRONG inside B tag', 'in' => '<b><strong>&#347;</strong></b>', 'out' => 'Ś'));
     $ht = new html2text(null, false, false);
     foreach ($data as $idx => $item) {
         $ht->set_html($item['in']);
         $res = $ht->get_text();
         $this->assertEqual($item['out'], $res, $item['title'] . "({$idx})");
     }
 }
function html2plaintext($text, $texthtml0)
{
    global $opt, $absolute_server_URI;
    if ($texthtml0) {
        $text = str_replace(array('<p>', "\n", "\r"), '', $text);
        $text = str_replace(array('<br />', '</p>'), "\n", $text);
        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
    } else {
        $h2t = new html2text($text);
        $h2t->set_base_url(isset($opt['page']['absolute_url']) ? $opt['page']['absolute_url'] : $absolute_server_URI);
        $text = $h2t->get_text();
        // remove e.g. trailing \n created from </p> by html2text
        while (substr($text, -2) == "\n\n") {
            $text = substr($text, 0, strlen($text) - 1);
        }
    }
    return $text;
}
Exemple #5
0
function htmlmail($to, $subject, $htmlmsg)
{
    require_once 'class.html2text.php';
    $boundary = 'Msg_Boundary--';
    $htmltype = 'text/html; charset="iso-8859-1"';
    $plaintype = str_replace('html', 'plain', $htmltype);
    if (stripos($htmlmsg, '<html') === FALSE) {
        $htmlmsg = "<html>{$htmlmsg}</html>";
    }
    $h2t = new html2text($htmlmsg);
    $plain = $h2t->get_text();
    while (stripos($plain, $boundary) + stripos($htmlmsg, $boundary) > 0) {
        $boundary .= rand();
    }
    // prevent malicious hacking
    $msg = <<<EOF
If you see this message, you may need a newer email program.
--{$boundary}
Content-Type: {$plaintype}
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

{$plain}
--{$boundary}
Mime-Version: 1.0
Content-Type: {$htmltype}
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

{$htmlmsg}
--{$boundary}--
EOF;
    $hdrs = array('From' => 'rC4 <' . SYS_EMAIL . '>', 'Return-Path' => SYS_EMAIL, 'Errors-To' => SYS_EMAIL, 'Content-Type' => "multipart/alternative; boundary=\"{$boundary}\"");
    $smhdrs = '';
    foreach ($hdrs as $key => $value) {
        $smhdrs .= "{$key}: {$value}\n";
    }
    $smhdrs = substr($smhdrs, 0, strlen($smhdrs) - strlen("\n"));
    // omit final EOL
    mail($to, $subject, $msg, $smhdrs, '-f' . SYS_EMAIL);
}
Exemple #6
0
function _ff_getListField_gettopic($fieldname, $fieldvalue, $A, $icon_arr)
{
    global $_CONF, $_USER, $_TABLES, $LANG_ADMIN, $LANG04, $LANG28, $_IMAGE_TYPE;
    global $_FF_CONF, $_SYSTEM, $LANG_GF02, $LANG_GF03;
    USES_lib_html2text();
    $dt = new Date('now', $_USER['tzid']);
    $retval = '';
    switch ($fieldname) {
        case 'author':
            $retval = $A['name'];
            break;
        case 'date':
            $dt->setTimestamp($fieldvalue);
            $retval = $dt->format($_FF_CONF['default_Datetime_format'], true);
            break;
        case 'lastupdated':
            $dt->setTimestamp($fieldvalue);
            $retval = $dt->format($_FF_CONF['default_Datetime_format'], true);
            break;
        case 'subject':
            $testText = FF_formatTextBlock($A['comment'], 'text', 'text', $A['status']);
            $testText = strip_tags($testText);
            $html2txt = new html2text($testText, false);
            $testText = trim($html2txt->get_text());
            $lastpostinfogll = htmlspecialchars(preg_replace('#\\r?\\n#', '<br>', strip_tags(substr($testText, 0, $_FF_CONF['contentinfo_numchars']) . '...')), ENT_QUOTES, COM_getEncodingt());
            $retval = '<span class="' . COM_getTooltipStyle() . '" style="text-decoration:none;" title="' . $A['subject'] . '::' . $lastpostinfogll . '">' . $fieldvalue . '</span>';
            break;
        case 'select':
            $retval = '[&nbsp;<a href="#" onclick="insert_topic(\'' . $A['id'] . '\'); return false;">' . $LANG_GF03['select'] . '</a>&nbsp;]';
            break;
        default:
            $retval = $fieldvalue;
            break;
    }
    return $retval;
}
Exemple #7
0
/**
* Email story to a friend
*
* @param    string  $sid        id of story to email
* @param    string  $to         name of person / friend to email
* @param    string  $toemail    friend's email address
* @param    string  $from       name of person sending the email
* @param    string  $fromemail  sender's email address
* @param    string  $shortmsg   short intro text to send with the story
* @return   string              Meta refresh
*
* Modification History
*
* Date        Author        Description
* ----        ------        -----------
* 4/17/01    Tony Bibbs    Code now allows anonymous users to send email
*                and it allows user to input a message as well
*                Thanks to Yngve Wassvik Bergheim for some of
*                this code
*
*/
function mailstory($sid, $to, $toemail, $from, $fromemail, $shortmsg, $html = 0)
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG08;
    $dt = new Date('now', $_USER['tzid']);
    $storyurl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $sid);
    if ($_CONF['url_rewrite']) {
        $retURL = $storyurl . '?msg=85';
    } else {
        $retURL = $storyurl . '&amp;msg=85';
    }
    // check for correct $_CONF permission
    if (COM_isAnonUser() && ($_CONF['loginrequired'] == 1 || $_CONF['emailstoryloginrequired'] == 1)) {
        echo COM_refresh($retURL);
        exit;
    }
    // check if emailing of stories is disabled
    if ($_CONF['hideemailicon'] == 1) {
        echo COM_refresh($retURL);
        exit;
    }
    // check mail speedlimit
    COM_clearSpeedlimit($_CONF['speedlimit'], 'mail');
    if (COM_checkSpeedlimit('mail') > 0) {
        echo COM_refresh($retURL);
        exit;
    }
    $filter = sanitizer::getInstance();
    if ($html) {
        $filter->setPostmode('html');
    } else {
        $filter->setPostmode('text');
    }
    $allowedElements = $filter->makeAllowedElements($_CONF['htmlfilter_default']);
    $filter->setAllowedElements($allowedElements);
    $filter->setCensorData(true);
    $filter->setReplaceTags(true);
    $filter->setNamespace('glfusion', 'mail_story');
    $sql = "SELECT uid,title,introtext,bodytext,story_image,commentcode,UNIX_TIMESTAMP(date) AS day,postmode FROM {$_TABLES['stories']} WHERE sid = '" . DB_escapeString($sid) . "'" . COM_getTopicSql('AND') . COM_getPermSql('AND');
    $result = DB_query($sql);
    if (DB_numRows($result) == 0) {
        return COM_refresh($_CONF['site_url'] . '/index.php');
    }
    $A = DB_fetchArray($result);
    $result = PLG_checkforSpam($shortmsg, $_CONF['spamx']);
    if ($result > 0) {
        COM_updateSpeedlimit('mail');
        COM_displayMessageAndAbort($result, 'spamx', 403, 'Forbidden');
    }
    USES_lib_html2text();
    $T = new Template($_CONF['path_layout'] . 'email/');
    $T->set_file(array('html_msg' => 'mailstory_html.thtml', 'text_msg' => 'mailstory_text.thtml'));
    // filter any HTML from the short message
    $shortmsg = $filter->filterHTML($shortmsg);
    $html2txt = new html2text($shortmsg, false);
    $shortmsg_text = $html2txt->get_text();
    $story_body = COM_truncateHTML($A['introtext'], 512);
    $html2txt = new html2text($story_body, false);
    $story_body_text = $html2txt->get_text();
    $dt->setTimestamp($A['day']);
    $story_date = $dt->format($_CONF['date'], true);
    $story_title = COM_undoSpecialChars($A['title']);
    $story_url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $sid);
    if ($_CONF['contributedbyline'] == 1) {
        $author = COM_getDisplayName($A['uid']);
    } else {
        $author = '';
    }
    if ($A['story_image'] != '') {
        $story_image = $_CONF['site_url'] . $A['story_image'];
    } else {
        $story_image = '';
    }
    $T->set_var(array('shortmsg_html' => $shortmsg, 'shortmsg_text' => $shortmsg_text, 'story_title' => $story_title, 'story_date' => $story_date, 'story_url' => $story_url, 'author' => $author, 'story_image' => $story_image, 'story_body_html' => $story_body, 'story_body_text' => $story_body_text, 'lang_by' => $LANG01[1], 'site_name' => $_CONF['site_name'], 'from_name' => $from, 'disclaimer' => sprintf($LANG08[23], $from, $fromemail)));
    $T->parse('message_body_html', 'html_msg');
    $message_body_html = $T->finish($T->get_var('message_body_html'));
    $T->parse('message_body_text', 'text_msg');
    $message_body_text = $T->finish($T->get_var('message_body_text'));
    $msgData = array('htmlmessage' => $message_body_html, 'textmessage' => $message_body_text, 'subject' => $story_title, 'from' => array('email' => $_CONF['site_mail'], 'name' => $from), 'to' => array('email' => $toemail, 'name' => $to));
    $mailto = array();
    $mailfrom = array();
    $mailto = COM_formatEmailAddress($to, $toemail);
    $mailfrom = COM_formatEmailAddress($from, $fromemail);
    $subject = COM_undoSpecialChars(strip_tags('Re: ' . $A['title']));
    $rc = COM_mail($mailto, $msgData['subject'], $msgData['htmlmessage'], $mailfrom, true, 0, '', $msgData['textmessage']);
    COM_updateSpeedlimit('mail');
    if ($rc) {
        if ($_CONF['url_rewrite']) {
            $retval = COM_refresh($storyurl . '?msg=27');
        } else {
            $retval = COM_refresh($storyurl . '&amp;msg=27');
        }
    } else {
        // Increment numemails counter for story
        DB_query("UPDATE {$_TABLES['stories']} SET numemails = numemails + 1 WHERE sid = '" . DB_escapeString($sid) . "'");
        if ($_CONF['url_rewrite']) {
            $retval = COM_refresh($storyurl . '?msg=26');
        } else {
            $retval = COM_refresh($storyurl . '&amp;msg=26');
        }
    }
    echo COM_refresh($retval);
    exit;
}
 /**
  * Return the first text part of this message
  *
  * @param rcube_message_part $part Reference to the part if found
  * @return string Plain text message/part content
  */
 function first_text_part(&$part = null)
 {
     // no message structure, return complete body
     if (empty($this->parts)) {
         return $this->body;
     }
     // check all message parts
     foreach ($this->mime_parts as $mime_id => $part) {
         if ($part->mimetype == 'text/plain') {
             return $this->get_part_content($mime_id);
         } else {
             if ($part->mimetype == 'text/html') {
                 $out = $this->get_part_content($mime_id);
                 // remove special chars encoding
                 $trans = array_flip(get_html_translation_table(HTML_ENTITIES));
                 $out = strtr($out, $trans);
                 // create instance of html2text class
                 $txt = new html2text($out);
                 return $txt->get_text();
             }
         }
     }
     $part = null;
     return null;
 }
Exemple #9
0
     $body = file_get_contents('contents.html');
 } else {
     $body = $_POST['Message'];
 }
 $example_code .= "\n\$body = \"" . $body . '";';
 $mail->WordWrap = 80;
 // set word wrap
 $mail->IsHTML(true);
 // send as HTML
 $mail->Body = $body;
 $example_code .= "\n\$mail->WordWrap = 80;";
 $example_code .= "\n\$mail->IsHTML(true); // send as HTML";
 $example_code .= "\n\$mail->Body = \"{$body}\";";
 // for non-HTML mail clients
 $h2t = new html2text($body);
 $mail->AltBody = $h2t->get_text();
 $example_code .= "\n\$h2t =& new html2text(\$body);";
 $example_code .= "\n\$mail->AltBody = \$h2t->get_text();";
 $mail->AddAttachment("images/aikido.gif", "aikido.gif");
 // optional name
 $mail->AddAttachment("images/phpmailer.gif", "phpmailer.gif");
 // optional name
 $example_code .= "\n\$mail->AddAttachment(\"images/aikido.gif\", \"aikido.gif\");  // optional name";
 $example_code .= "\n\$mail->AddAttachment(\"images/phpmailer.gif\", \"phpmailer.gif\");  // optional name";
 try {
     if (!$mail->Send()) {
         $error = "Unable to send to: " . $to . "<br />";
         throw new phpmailerAppException($error);
     } else {
         $results_messages[] = "Message has been sent using " . strtoupper($_POST["test_type"]);
     }
Exemple #10
0
 /**
  * Convert a HTML string into a text one using html2text
  *
  * @param string $html  the tring to be converted
  * @return string       the converted string
  * @access public
  * @static
  */
 static function htmlToText($html)
 {
     require_once 'packages/html2text/class.html2text.inc';
     $converter = new html2text($html);
     return $converter->get_text();
 }
Exemple #11
0
 // we are the cache-owner
 $tplname = 'removelog_cacheowner';
 if ($commit == 1) {
     //send email to logowner
     $email_content = read_file($stylepath . '/email/removed_log.email');
     $message = isset($_POST['logowner_message']) ? $_POST['logowner_message'] : '';
     if ($message != '') {
         //message to logowner
         $message = $removed_message_title . "\n" . $message . "\n" . $removed_message_end;
     }
     $logtext = $log_record['log_text'];
     if ($log_record['text_html'] != 0) {
         $logtext = html_entity_decode($logtext, ENT_COMPAT, 'UTF-8');
         $h2t = new html2text($logtext);
         $h2t->set_base_url($absolute_server_URI);
         $logtext = $h2t->get_text();
     }
     $logtext = $removed_text_title . "\n" . trim($logtext) . "\n" . $removed_text_end;
     //get cache owner name
     $cache_owner_rs = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $log_record['cache_owner_id']);
     $cache_owner_record = sql_fetch_array($cache_owner_rs);
     mysql_free_result($cache_owner_rs);
     //get email address of logowner
     $log_user_rs = sql("SELECT `email`, `username` FROM `user` WHERE `user_id`='&1'", $log_record['log_user_id']);
     $log_user_record = sql_fetch_array($log_user_rs);
     mysql_free_result($log_user_rs);
     // insert log data
     $email_content = mb_ereg_replace('%log_owner%', $log_user_record['username'], $email_content);
     $email_content = mb_ereg_replace('%cache_owner%', $cache_owner_record['username'], $email_content);
     $email_content = mb_ereg_replace('%cache_name%', $log_record['cache_name'], $email_content);
     $email_content = mb_ereg_replace('%cache_wp%', $log_record['wp_oc'], $email_content);
Exemple #12
0
 /**
  * Convert an HTML string into plain text.
  * @param string $html The HTML text to convert
  * @param bool $advanced Should this use the more complex html2text converter or just a simple one?
  * @return string
  */
 public function html2text($html, $advanced = false)
 {
     if ($advanced) {
         require_once 'extras/class.html2text.php';
         $h = new html2text($html);
         return $h->get_text();
     }
     return html_entity_decode(trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\\/\\1>/si', '', $html))), ENT_QUOTES, $this->CharSet);
 }
Exemple #13
0
    function buildmsg()
    {
        global $pref, $brand, $atmail;
        // Save UTF-8 versions of the strings, which are sent to the browser
        $this->RawEmailSubject = $this->EmailSubject;
        // Format the date correctly
        $this->Date = date('r');
        // return an error if To: field contains only , or ;
        if (strlen($this->EmailTo) == 0 || !preg_match('/\\@/', $this->EmailTo) && preg_match('/,/', $this->EmailTo) && $this->EmailBox != "Draft") {
            return $this->smtperror("Please specify an email in the To: field {$this->EmailTo}");
        }
        // Do not test if the email has a @ symbol, if a user specifies an add-recipients > group , the format is
        // Groupname Group , there is no email address with an @
        // return an error if To: field is empty or contains no email addresses
        // if ((strlen($this->EmailTo) == 0 || !(preg_match('/\@/', $this->EmailTo)))
        //     && $this->EmailBox != "Draft" )
        // {
        //             return $this->smtperror("Please specify an email in the To: field $this->EmailTo");
        // }
        // return an error if CC string contains characters but no email addresses
        //if (strlen($this->EmailCC) > 0)
        //{
        //           return $this->smtperror("Please specify an email in the CC: field $this->EmailCC");
        //}
        // return an error if BCC string contains characters but no email addresses
        //if (strlen($this->EmailBcc) > 0)
        //   {
        //           return $this->smtperror("Please specify an email in the BCC: field $this->EmailBcc");
        //   }
        // Read our attachment directory
        $dir = $atmail->tmpdir;
        // If we don't have a valid directory ( e.g new account via webadmin , use user_dir )
        if (!is_dir($atmail->tmpdir)) {
            $dir = $pref['user_dir'];
        }
        if (!file_exists($dir)) {
            mkdir($dir, 0777);
        }
        $dh = opendir($dir);
        if (!is_resource($dh)) {
            catcherror("Cannot read attachment dir: {$this->tmpdir}");
        }
        if (!$atmail->isset_chk($this->Unique)) {
            $this->Unique = "0";
        }
        $acc = preg_quote($this->Account, '/');
        $unique = preg_quote($this->Unique, '/');
        while (false !== ($file = readdir($dh))) {
            if (preg_match("/^{$acc}-{$unique}-cid:(.+?)-name:(.+?)\$/", $file, $m)) {
                $this->inlineimages[] = array('filename' => "{$dir}/{$file}", 'cid' => $m[1], 'name' => $m[2]);
            } elseif (preg_match("/^{$acc}-{$unique}/", $file)) {
                $this->attach($file);
                $this->EmailAttach++;
            }
        }
        closedir($dh);
        // Add our message footer, only for outgoing messages
        if (preg_match('/plain/', $this->ContentType) && $this->EmailBox != 'Drafts') {
            if (isset($brand[$_SERVER['HTTP_HOST']]["footer_msg"])) {
                $pref['footer_msg'] = $brand[$_SERVER['HTTP_HOST']]["footer_msg"];
            }
            // Take away any HTML characters
            $pref['footer_msg'] = str_replace(array('<hr>', '<HR>'), '---- ', $pref['footer_msg']);
            $pref['footer_msg'] = strip_tags($pref['footer_msg']);
            // Clean the footer_msg and make it CLF clean
            $pref['footer_msg'] = str_replace("\r", '', $pref['footer_msg']);
            // Evaluate any $vars
            $pref['domain'] = $this->Pop3host;
            //$pref['footer_msg'] = preg_replace('/(\$[0-9A-Za-z\-_\[\]>]+)/e', '$1', $pref['footer_msg']);
            $pref['footer_msg'] = preg_replace('/(\\$pref[0-9A-Za-z\\-_\\[\\]>]+)/e', '$1', $pref['footer_msg']);
            if (strlen($this->VideoStream) > 0) {
                $this->EmailMessage = "Video mail attached:\nTo view please see: http://{$pref['videomail_server']}/videomail/view/{$this->VideoStream}/\n\n" . $this->EmailMessage;
            }
            // Only add the footer message if it is not already at bottom of email
            if (!empty($pref['footer_msg']) && strpos($this->EmailMessage, $pref['footer_msg']) !== strlen($this->EmailMessage) - strlen($pref['footer_msg'])) {
                $this->EmailMessage .= "\r\n{$pref['footer_msg']}";
            }
        } elseif (preg_match('/html/', $this->ContentType) && $this->EmailBox != 'Drafts') {
            if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'gecko') !== false) {
                // Create links from plain urls
                //$this->EmailMessage = preg_replace('/(?<!href="|\')(http:\/\/[^\s<>\'"]+)(?!/i', '<a href="$1">$1</a>', $this->EmailMessage);
                $this->EmailMessage = preg_replace('/(?<!\'|"|>|&gt;)(http:\\/\\/[^\\s<>\'"]+)/i', '<a href="$1">$1</a>', $this->EmailMessage);
            }
            // Create 'real' newlines from <BR>'s
            $this->EmailMessage = str_replace(array('<BR>', '<br>'), "<br>\r\n", $this->EmailMessage);
            // Evaluate any $vars
            $pref['domain'] = $this->Pop3host;
            if ($brand[$_SERVER['HTTP_HOST']]["footer_msg"]) {
                $pref['footer_msg'] = $brand[$_SERVER['HTTP_HOST']]["footer_msg"];
            }
            // Evaluate any $vars
            $pref['footer_msg'] = preg_replace('/(\\$pref[0-9A-Za-z\\-_\\[\\]>]+)/e', '$1', $pref['footer_msg']);
            // Clean the footer_msg and make it CLF clean
            $pref['footer_msg'] = str_replace("\r", '', $pref['footer_msg']);
            if (!empty($pref['footer_msg']) && strpos($this->EmailMessage, $pref['footer_msg']) !== strlen($this->EmailMessage) - strlen($pref['footer_msg'])) {
                $this->EmailMessage .= "<BR>{$pref['footer_msg']}";
            }
            if (strlen($this->VideoStream) > 0) {
                $this->EmailMessage = <<<EOF
<HTML><table width="100%" style="border: 1px solid #468BC7;">
<tr>
<td style="background-color: #D8E7F5; padding: 3px;" nowrap>
Video Mail Attached. To view in your browser click the link below:<br>
<a href="http://{$pref['videomail_server']}/videomail/view/{$this->VideoStream}/">http://{$pref['videomail_server']}/videomail/view/{$this->VideoStream}/</a>
</td>
</tr>
</table>
<br>
{$this->EmailMessage}
</HTML>
EOF;
            } else {
                // Append <HTML> tags to make Spamassassin score less
                $this->EmailMessage = "<HTML>\n" . $this->EmailMessage . "</HTML>\n";
            }
        }
        /* disabled for now
        		// Create a new PGP object if required
        		if ($this->PGPsign || $this->PGPappend)
        		{
        			$userWrkDir = ($atmail->MailDir) ? $atmail->MailDir : $atmail->tmpdir;
        		    $ownFile = $atmail->tmpdir . ".ht.".$this->SessionID;
        
        			$pgp = new PGP( array('wrkDir' => "$userWrkDir/pgp", 'ownFile' => $ownFile) );
        
        			// Automatically sign the mail with the users PGP key, only if our pass-phrase is available
        			if ($this->PGPsign && file_exists($pgp->ownFile))
        			{
        				$rec = array();
        				$this->EmailMessage = $pgp->encrypt($this->EmailFrom, $rec , $this->EmailMessage, "s");
        			}
        
        			// Automatically append the users PGP key to an outgoing message
        			if ($this->PGPappend)
        			{
        				// Load a temporary var containing for PGP public key
        				$msgTmp = $pgp->retrieveAsciiPub();
        
        				// Turn newlines into <BR>'s for the HTML emails
        				if ( strpos($this->ContentType, 'html') !== false )
        					$msgTmp = nl2br($msgTmp);
        
        				// Append the PGP public key to the email message
        		    	$this->EmailMessage .= $msgTmp;
        			}
        
        		}
                */
        // The from Header is our ReplyTo if specified in the settings, only if we are the default account
        if ($this->ReplyTo && $this->Account == $this->EmailFrom) {
            $this->EmailFrom = $this->ReplyTo;
        }
        $rfc822 = new Mail_RFC822();
        foreach (array('EmailTo', 'EmailCC', 'EmailBCC') as $type) {
            if ($this->{$type} != '') {
                //remove leading semi-colon
                $this->{$type} = preg_replace('/^\\s*;\\s*/', '', $this->{$type});
                $this->{$type} = str_replace(array(';', ' Shared Group', ' Group'), array(',', '@SharedGroup', '@Group'), $this->{$type});
                // Remove "smart quotes" (aka dumb quotes)
                $smartquotes = array('“', '”', '‘', '’', "�", "�", "�", "�", chr(147), chr(148), chr(146), 'R20;', 'R21;', 'R17;', 'R16;');
                $this->{$type} = str_replace($smartquotes, '"', $this->{$type});
                // Optionally encode the users name in the header
                preg_match_all('/(?<=")(.+?)(?=" <)/', $this->{$type}, $m, PREG_SET_ORDER);
                if (is_array($m[0])) {
                    foreach ($m[0] as $match) {
                        $this->{$type} = str_replace($match, $this->encodeUTF8($match), $this->{$type});
                    }
                }
                //$this->$type = preg_replace('/(?<=")(.+?)(?=" <)/e', '$this->encodeUTF8(\'$1\')', $this->$type);
                $groups = $rfc822->parseAddressList($this->{$type}, null, false, true);
                $this->{$type} = '';
                foreach ($groups as $group) {
                    if (is_string($group)) {
                        preg_match('/(.*?)<(.*?)>/', $group, $m);
                        $name = trim($m[1]);
                        $mail = $m[2];
                    } else {
                        $name = $group->personal;
                        // Replace ", ' and , from the name, cleanup and parse the address below
                        //$name = str_replace(array('"', ','), '', $name);
                        $mail = $group->mailbox . '@' . $group->host;
                    }
                    // insert recipients from shared groups
                    if (strpos($mail, 'Shared Group') !== false) {
                        preg_match('/(.*?)Shared Group/', $mail, $match);
                        $this->{$type} .= $match[1] . "SharedGroup, ";
                    } elseif (preg_match('/(.+?)Group$/i', $mail, $match)) {
                        $this->{$type} .= $match[1] . "Group, ";
                    } elseif (strlen($name) > 0) {
                        $address = "{$name} <{$mail}>";
                        $this->{$type} .= $address . ", ";
                        $this->AddRecipients .= "{$mail}, ";
                    } else {
                        $address = "<{$mail}>";
                        $this->{$type} .= $address . ", ";
                        $this->AddRecipients .= "{$mail}, ";
                    }
                }
            }
            // Remove the trailing comma @ the end of the text
            $this->{$type} = preg_replace('/, $/', '', $this->{$type});
        }
        $this->AddRecipients = preg_replace('/, $/', '', $this->AddRecipients);
        // If there is a video-message prepend "VideoMail:" in the subject
        if ($this->VideoStream && !preg_match('/VideoMail:/i', $this->EmailSubject)) {
            $this->EmailSubject = "VideoMail: " . $this->EmailSubject;
        }
        // Decode our RealName and EmailSubject from UTF8 -> Charset
        $this->RealName = GetMail::encode_language($this->Charset, $this->RealName);
        $this->EmailSubject = GetMail::encode_language($this->Charset, $this->EmailSubject);
        // If we are not using the standard charset, encoding the email-subject with the subject ( base64 for quoted printed encoding)
        // Only encode if the output contains non ASCII characters
        $this->EmailMessage = str_replace("\r", '', $this->EmailMessage);
        if (preg_match('/iso/i', $this->Charset)) {
            if ($this->_check_if_contain_utf8($this->EmailSubject)) {
                $this->EmailSubject = MIME_Words::encode_mimeword($this->EmailSubject, "Q", $this->Charset);
            }
            if ($this->_check_if_contain_utf8($self->RealName)) {
                $this->RealName = MIME_Words::encode_mimeword($this->RealName, "Q", $this->Charset);
            }
            $this->EmailMessage = GetMail::encode_language($this->Charset, $this->EmailMessage);
        } else {
            if ($this->_check_if_contain_utf8($this->EmailSubject)) {
                $this->EmailSubject = MIME_Words::encode_mimeword($this->EmailSubject, "B", $this->Charset);
            }
            if ($this->_check_if_contain_utf8($this->RealName)) {
                $this->RealName = MIME_Words::encode_mimeword($this->RealName, "B", $this->Charset);
            }
            $this->EmailMessage = GetMail::encode_language($this->Charset, $this->EmailMessage);
        }
        $this->mime->setSubject($this->EmailSubject);
        $this->RealName = trim($this->RealName);
        if (strlen($this->RealName) > 0 && $pref['allow_FullName']) {
            $this->mime->setFrom("{$this->RealName} <{$this->EmailFrom}>");
        } else {
            $this->mime->setFrom($this->EmailFrom);
        }
        // Convert back any @Mail created links that redirect through parse.php
        // and javascript.opencompose() (only if replying to or forwarding a msg)
        if ($this->ReplyFwd == 'reply' || $this->ReplyFwd == 'forward') {
            $this->_cleanLinks();
        }
        // If user is using the HTML editor, send a HTML message otherwise plain txt
        if (strpos($this->ContentType, 'html') !== false) {
            $this->mime->headers(array('To' => str_replace(array('@SharedGroup', '@Group'), array(' Shared Group', ' Group'), $this->EmailTo), 'Reply-To' => $this->ReplyTo, 'Content-Type' => "multipart/related; charset=\"{$this->Charset}\"", 'X-Mailer' => $this->XMailer, 'X-Origin' => $this->X_Origin, 'X-Atmail-Account' => $this->Account, 'Date' => $this->Date));
            // Now create the text/plain part also
            require_once 'class.html2text.inc';
            $html2text = new html2text($this->EmailMessage);
            $txt = $html2text->get_text();
            $txt = preg_replace('/^\\s*BODY\\s*\\{.+?\\}/s', '', $txt);
            $html = $this->EmailMessage;
            // Cleanup PGP block if one exists
            if (strpos($this->EmailMessage, '-----BEGIN PGP MESSAGE-----') !== false) {
                $html = PGP::cleanPgpBlock($this->EmailMessage, 'message');
                $txt = PGP::cleanPgpBlock($txt, 'message');
            }
            // Cleanup PGP block if one exists
            if (strpos($this->EmailMessage, '-----BEGIN PGP PUBLIC KEY BLOCK-----') !== false) {
                $html = PGP::cleanPgpBlock($this->EmailMessage, 'pubkey');
                $txt = PGP::cleanPgpBlock($txt, 'pubkey');
            }
            // add the text/html part
            $this->mime->setHTMLBody($html);
            $this->mime->setTXTBody($txt);
        } else {
            $this->mime->headers(array('To' => str_replace(array('@SharedGroup', '@Group'), array(' Shared Group', ' Group'), $this->EmailTo), 'Reply-To' => $this->ReplyTo, 'Content-Type' => "text/plain; charset=\"{$this->Charset}\"", 'X-Origin' => $this->X_Origin, 'X-Atmail-Account' => $this->Account, 'Date' => $this->Date));
            $this->mime->setTXTBody($this->EmailMessage);
        }
        // Append our X-Video mail message
        if (strlen($this->VideoStream) > 0) {
            $this->mime->headers(array('X-VideoMail' => "http://{$pref['videomail_server']}/videomail/view/{$this->VideoStream}"));
        }
        // Added support for CC / BCC messages
        if ($this->EmailCC) {
            $this->mime->addCc(str_replace(array('@SharedGroup', '@Group'), array(' Shared Group', ' Group'), $this->EmailCC));
        }
        $messageid = "<{$_SERVER['REMOTE_PORT']}." . time() . "@{$this->Pop3host}>";
        $this->mime->headers(array('Message-ID' => $messageid));
        // Replace the X-Mailer with our custom copy
        $this->mime->headers(array('X-Mailer' => $this->XMailer));
        if ($this->ReadReceipt) {
            // Define the Read-receipt if toggled on - Split over two calls, all in one seemed to fail
            $this->mime->headers(array('X-Confirm-Reading-To' => $this->ReplyTo));
            $this->mime->headers(array('Return-Receipt-To' => $this->ReplyTo));
            $this->mime->headers(array('Disposition-Notification-To' => $this->ReplyTo));
        }
        if ($this->EmailPriority) {
            $this->mime->headers(array('X-Priority' => $this->EmailPriority));
            if ($this->EmailPriority == 5) {
                $this->mime->headers(array('X-MSMail-Priority' => 'Low'));
            }
            if ($this->EmailPriority == 1) {
                $this->mime->headers(array('X-MSMail-Priority' => 'High'));
            }
        }
        $TypeFor = array('txt' => 'text/plain', 'sh' => 'text/x-sh', 'csh' => 'text/x-csh', 'pm' => 'text/x-perl', 'pl' => 'text/x-perl', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'xbm' => 'image/xbm', 'eml' => 'message/rfc822');
        /*
        	    // attach any messages forwarded as attachments
        	    $names = array();
        	    $i = 1;
        	    foreach ($this->emailPaths as $path) {
        	        $fh = fopen($path, 'r');
        	        while (false !== $line = fgets($fh)) {
        	           if (preg_match('/^subject:\s*(.+)/i', $line, $m)) {
        	               $name = GetMail::quote_header($m[1]);
        
        	               while (in_array($name, $names)) {
        	                   if ($i == 1)
        	                       $name = "{$name}_1";
        	                   else
            	                   $name = preg_replace('/_\d+$/', $name, "_$i");
        
            	               $i++;
        	               }
        
        	               $names[] = $name;
        	               $name = "$name.eml";
        	               break;
        	           }
            }
        	        $this->mime->addAttachment($path, 'message/rfc822', $name);
        	    }
        */
        // We have attachments in our folder
        if ($this->EmailAttach) {
            // Loop through each attachment
            foreach ($this->attachname as $file) {
                if (strpos($file, $this->Account) === false) {
                    continue;
                }
                $name = $file;
                // Strip the filename header with our account, rand and pid prefix
                $name = preg_replace("/^{$this->Account}-\\d+-/", '', $name);
                // strip the .safe extension
                $name = preg_replace('/\\.safe$/', '', $name);
                // Find the extension of the file
                if (preg_match('/\\.(\\w+)$/', $name, $match)) {
                    $ext = $match[1];
                }
                // Language encode if we contain different characters
                if ($this->_check_if_contain_utf8($name)) {
                    $name = MIME_Words::encode_mimeword(GetMail::encode_language('UTF-8', $name), "B", 'UTF-8');
                }
                // Attach the file to the message
                $ext = strtolower($ext);
                $type = $TypeFor[$ext] ? $TypeFor[$ext] : 'application/octet-stream';
                $this->mime->addAttachment($atmail->tmpdir . "/{$file}", $type, $name) || catcherror("Cannot attach filename to message : {$name}");
            }
        }
        // Add CID images
        foreach ($this->inlineimages as $image) {
            // Find the extension of the file
            if (preg_match('/\\.(\\w+)$/', $image['name'], $match)) {
                $ext = $match[1];
            }
            $type = $TypeFor[$ext];
            $this->mime->addHtmlImage($image['filename'], $type, $image['name'], true, $image['cid']);
        }
        $this->body = $this->mime->get(array('text_encoding' => 'quoted-printable', 'html_encoding' => 'quoted-printable'));
        $this->headers = trim($this->mime->txtHeaders());
    }
Exemple #14
0
/**
 * Given HTML text, make it into plain text using external function
 *
 * @uses $CFG
 * @param string $html The text to be converted.
 * @return string
 */
function html_to_text($html)
{
    global $CFG;
    require_once $CFG->libdir . '/html2text.php';
    $h2t = new html2text($html);
    $result = $h2t->get_text();
    return $result;
}
Exemple #15
0
/**
 * Given HTML text, make it into plain text using external function
 *
 * @uses $CFG
 * @param string $html The text to be converted.
 * @return string
 */
function html_to_text($html)
{
    global $CFG;
    require_once $CFG->libdir . '/html2text.php';
    $h2t = new html2text($html);
    $result = $h2t->get_text();
    // html2text does not fix HTML entities so handle those here.
    $result = trim(html_entity_decode($result, ENT_NOQUOTES, 'UTF-8'));
    return $result;
}
Exemple #16
0
 function html_to_text($html)
 {
     include_once ROOT . "/library/html2text/class.html2text.inc";
     $h2t = new html2text($html);
     return $h2t->get_text();
 }
Exemple #17
0
/**
 * Get a blog and add tags from the silcc API
 */
function silcc_submit_post($post_id)
{
    global $wpdb;
    $post_id = (int) $post_id;
    $blog = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID = '{$post_id}' ");
    if (!$blog) {
        // it was deleted
        return;
    }
    // This is where we extract the text to tag
    // TODO: Make sure this text is not HTML (To avoid HTML tagging)
    // Include the html to text conversion library
    require dirname(__FILE__) . "/class.html2text.inc";
    $html_text = stripslashes($blog->post_content);
    $html_to_text_class = new html2text($html_text);
    $text_content = $html_to_text_class->get_text();
    $tags = array();
    if (!is_null($text_content)) {
        if (strlen($text_content) > 240) {
            $tags = tagthe_http_get($text_content);
        } else {
            if (strlen($text_content) > 0 && strlen($text_content) < 240) {
                $query_string = '' . urlencode($text_content) . '&';
                $response = silcc_http_get($query_string);
                $clean_response = str_replace('[', '', $response);
                $clean_response = str_replace(']', '', $clean_response);
                $clean_response = str_replace(' ', '', $clean_response);
                $clean_response = str_replace('"', '', $clean_response);
                $tags = explode(',', $clean_response);
            }
        }
    }
    wp_set_post_terms($post_id, $tags);
    if (count($tags) > 0) {
        silcc_update_options(count($tags));
    }
}
Exemple #18
0
 $pagetitle = $story->DisplayElements('title');
 $outputHandle = outputHandler::getInstance();
 $permalink = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
 $outputHandle->addLink('canonical', $permalink);
 if ($story->DisplayElements('trackbackcode') == 0) {
     if ($_CONF['trackback_enabled']) {
         $trackbackurl = TRB_makeTrackbackUrl($story->getSid());
         $outputHandle->addRaw(LB . '<!--' . LB . TRB_trackbackRdf($permalink, $pagetitle, $trackbackurl) . LB . '-->' . LB);
     }
     $pingback = true;
 }
 USES_lib_html2text();
 $metaDesc = $story->DisplayElements('introtext');
 $metaDesc = strip_tags($metaDesc);
 $html2txt = new html2text($metaDesc, false);
 $metaDesc = trim($html2txt->get_text());
 $shortComment = '';
 $metaArray = explode(' ', $metaDesc);
 $wordCount = count($metaArray);
 $lengthCount = 0;
 $tailString = '';
 foreach ($metaArray as $word) {
     $lengthCount = $lengthCount + strlen($word);
     $shortComment .= $word . ' ';
     if ($lengthCount >= 100) {
         $tailString = '...';
         break;
     }
 }
 $metaDesc = trim($shortComment) . $tailString;
 $outputHandle->addMeta('property', 'og:site_name', urlencode($_CONF['site_name']));
 function gen_form($attrib)
 {
     $rcmail = rcmail::get_instance();
     $this->include_script('jquery.maskedinput.js');
     $this->api->output->add_label('sieverules.norulename', 'sieverules.ruleexists', 'sieverules.noheader', 'sieverules.headerbadchars', 'sieverules.noheadervalue', 'sieverules.sizewrongformat', 'sieverules.noredirect', 'sieverules.redirectaddresserror', 'sieverules.noreject', 'sieverules.vacnodays', 'sieverules.vacdayswrongformat', 'sieverules.vacnomsg', 'sieverules.notifynomethod', 'sieverules.missingfoldername', 'sieverules.notifynomsg', 'sieverules.filterdeleteconfirm', 'sieverules.ruledeleteconfirm', 'sieverules.actiondeleteconfirm', 'sieverules.notifyinvalidmethod', 'sieverules.nobodycontentpart', 'sieverules.badoperator', 'sieverules.baddateformat', 'sieverules.badtimeformat', 'sieverules.vactoexp_err', 'editorwarning');
     $ext = $this->sieve->get_extensions();
     $iid = get_input_value('_iid', RCUBE_INPUT_GPC);
     if ($iid == '') {
         $iid = sizeof($this->script);
     }
     if (substr($iid, 0, 2) == 'ex') {
         $cur_script = $this->examples[substr($iid, 2)];
         $this->api->output->set_env('eid', $iid);
         $iid = sizeof($this->script);
         $this->api->output->set_env('iid', $iid);
         $example = true;
     } else {
         $cur_script = $this->script[$iid];
         $this->api->output->set_env('iid', $iid);
         $example = false;
         if (isset($this->script[$iid])) {
             $this->api->output->add_script("if (parent." . JS_OBJECT_NAME . ".sieverules_examples) parent." . JS_OBJECT_NAME . ".sieverules_examples.clear_selection();");
             $this->api->output->add_script("parent." . JS_OBJECT_NAME . ".sieverules_list.highlight_row(" . $iid . ");");
         }
     }
     if (sizeof($rcmail->config->get('sieverules_predefined_rules')) > 0) {
         $predefined = array();
         foreach ($rcmail->config->get('sieverules_predefined_rules') as $idx => $data) {
             array_push($predefined, array($data['type'], $data['header'], $data['operator'], $data['extra'], $data['target']));
         }
         $this->api->output->set_env('predefined_rules', $predefined);
     }
     list($form_start, $form_end) = get_form_tags($attrib, 'plugin.sieverules.save');
     $out = $form_start;
     $hidden_iid = new html_hiddenfield(array('name' => '_iid', 'value' => $iid));
     $out .= $hidden_iid->show();
     // 'any' flag
     if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not']) {
         $any = true;
     }
     // filter disable
     $field_id = 'rcmfd_disable';
     $input_disable = new html_checkbox(array('name' => '_disable', 'id' => $field_id, 'value' => 1));
     $out .= html::span('disableLink', html::label($field_id, Q($this->gettext('disablerule'))) . "&nbsp;" . $input_disable->show($cur_script['disabled']));
     // filter name input
     $field_id = 'rcmfd_name';
     $input_name = new html_inputfield(array('name' => '_name', 'id' => $field_id));
     $out .= html::label($field_id, Q($this->gettext('filtername')));
     $out .= "&nbsp;" . $input_name->show($cur_script['name']);
     $out .= "<br /><br />";
     if (sizeof($cur_script['tests']) == 1 && $cur_script['tests'][0]['type'] == 'true' && !$cur_script['tests'][0]['not']) {
         $join_any = true;
     }
     $field_id = 'rcmfd_join_all';
     $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'allof', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'allof\')'));
     $join_type = $input_join->show($cur_script['join'] && !$join_any ? 'allof' : '');
     $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filterallof')));
     $field_id = 'rcmfd_join_anyof';
     $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'anyof', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'anyof\')'));
     $join_type .= "&nbsp;" . $input_join->show($cur_script['join'] && !$join_any ? '' : 'anyof');
     $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filteranyof')));
     $field_id = 'rcmfd_join_any';
     $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'any', 'onclick' => JS_OBJECT_NAME . '.sieverules_rule_join_radio(\'any\')'));
     $join_type .= "&nbsp;" . $input_join->show($join_any ? 'any' : '');
     $join_type .= "&nbsp;" . html::label($field_id, Q($this->gettext('filterany')));
     $rules_table = new html_table(array('id' => 'rules-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 5));
     $rules_table = $this->_rule_row($ext, $rules_table, null, $rcmail->config->get('sieverules_predefined_rules'), $attrib);
     if (!$join_any) {
         if (!isset($cur_script)) {
             $rules_table = $this->_rule_row($ext, $rules_table, array(), $rcmail->config->get('sieverules_predefined_rules'), $attrib);
         } else {
             foreach ($cur_script['tests'] as $rules) {
                 $rules_table = $this->_rule_row($ext, $rules_table, $rules, $rcmail->config->get('sieverules_predefined_rules'), $attrib);
             }
         }
     }
     $this->api->output->set_env('sieverules_rules', $rules_table->size());
     $out .= html::tag('fieldset', null, html::tag('legend', null, Q($this->gettext('messagesrules'))) . Q(!$rcmail->config->get('sieverules_use_elsif', true) ? $this->gettext('sieveruleexp_stop') : $this->gettext('sieveruleexp')) . "<br /><br />" . $join_type . "<br /><br />" . $rules_table->show($attrib));
     $rcmail->imap_connect();
     $actions_table = new html_table(array('id' => 'actions-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 3));
     $actions_table = $this->_action_row($ext, $actions_table, 'rowid', null, $attrib, $example);
     if (!isset($cur_script)) {
         $actions_table = $this->_action_row($ext, $actions_table, 0, array(), $attrib, $example);
     } else {
         foreach ($cur_script['actions'] as $idx => $actions) {
             $actions_table = $this->_action_row($ext, $actions_table, $idx, $actions, $attrib, $example);
         }
     }
     $this->api->output->set_env('sieverules_actions', $actions_table->size());
     $out .= html::tag('fieldset', null, html::tag('legend', null, Q($this->gettext('messagesactions'))) . Q($this->gettext('sieveactexp')) . "<br /><br />" . $actions_table->show($attrib));
     $out .= $form_end;
     // output sigs for vacation messages
     $user_identities = $rcmail->user->list_identities();
     if (count($user_identities)) {
         foreach ($user_identities as $sql_arr) {
             // add signature to array
             if (!empty($sql_arr['signature'])) {
                 $identity_id = $sql_arr['identity_id'];
                 $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
                 if ($sql_arr['html_signature'] == 1) {
                     $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
                     $a_signatures[$identity_id]['text'] = trim($h2t->get_text());
                 }
             }
         }
         $this->api->output->set_env('signatures', $a_signatures);
     }
     return $out;
 }
Exemple #20
0
/**
* Send an email notification for a new submission.
*
* @param    string  $table  Table where the new submission can be found
* @param    string  $story  Story object that was submitted.
*
*/
function sendNotification($table, $story)
{
    global $_CONF, $_USER, $_TABLES, $LANG01, $LANG08, $LANG24, $LANG29, $LANG_ADMIN;
    $dt = new Date('now', $_USER['tzid']);
    $title = COM_undoSpecialChars($story->displayElements('title'));
    $postmode = $story->displayElements('postmode');
    $introtext = COM_undoSpecialChars($story->displayElements('introtext') . "\n" . $story->displayElements('bodytext'));
    if ($postmode == 'html') {
        USES_lib_html2text();
        $introtext = str_replace("\\r", "", $introtext);
        $introtext = $introtext;
        $html2txt = new html2text($introtext, false);
        $introtext = trim($html2txt->get_text());
    }
    $storyauthor = COM_getDisplayName($story->displayelements('uid'));
    $topic = DB_getItem($_TABLES['topics'], 'topic', 'tid = \'' . DB_escapeString($story->displayElements('tid')) . '\'');
    $mailbody = "{$LANG08['31']}: {$title}\n" . "{$LANG24['7']}: {$storyauthor}\n" . "{$LANG08['32']}: " . $dt->format($_CONF['date'], true) . "\n" . "{$LANG_ADMIN['topic']}: {$topic}\n\n";
    if ($_CONF['emailstorieslength'] > 0) {
        if ($_CONF['emailstorieslength'] > 1) {
            $introtext = MBYTE_substr($introtext, 0, $_CONF['emailstorieslength']) . '...';
        }
        $mailbody .= $introtext . "\n\n";
    }
    if ($table == $_TABLES['storysubmission']) {
        $mailbody .= "{$LANG01['10']} <{$_CONF['site_admin_url']}/moderation.php>\n\n";
    } else {
        $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
        $mailbody .= $LANG08[33] . ' <' . $articleUrl . ">\n\n";
    }
    $mailsubject = $_CONF['site_name'] . ' ' . $LANG29[35];
    $mailbody .= "\n------------------------------\n";
    $mailbody .= "\n{$LANG08['34']}\n";
    $mailbody .= "\n------------------------------\n";
    $to = array();
    $to = COM_formatEmailAddress('', $_CONF['site_mail']);
    COM_mail($to, $mailsubject, $mailbody);
}
Exemple #21
0
function gfm_getoutput($id)
{
    global $_TABLES, $LANG_GF01, $LANG_GF02, $_CONF, $_FF_CONF, $_USER;
    $dt = new Date('now', $_USER['tzid']);
    $id = COM_applyFilter($id, true);
    $result = DB_query("SELECT * FROM {$_TABLES['ff_topic']} WHERE id=" . (int) $id);
    $A = DB_fetchArray($result);
    if ($A['pid'] == 0) {
        $pid = $id;
    } else {
        $pid = $A['pid'];
    }
    $permalink = $_CONF['site_url'] . '/forum/viewtopic.php?topic=' . $id . '#' . $id;
    $A['name'] = COM_checkWords($A['name']);
    $A['name'] = @htmlspecialchars($A['name'], ENT_QUOTES, COM_getEncodingt());
    $A['subject'] = COM_checkWords($A['subject']);
    $A['subject'] = @htmlspecialchars($A["subject"], ENT_QUOTES, COM_getEncodingt());
    $A['comment'] = _ff_FormatForEmail($A['comment'], $A['postmode']);
    $notifymsg = sprintf($LANG_GF02['msg27'], '<a href="' . $_CONF['site_url'] . '/forum/notify.php">' . $_CONF['site_url'] . '/forum/notify.php</a>');
    $dt->setTimestamp($A['date']);
    $date = $dt->format('F d Y @ h:i a');
    if ($A['pid'] == '0') {
        $postid = $A['id'];
    } else {
        $postid = $A['pid'];
    }
    $T = new Template($_CONF['path'] . 'plugins/forum/templates');
    $T->set_file('email', 'notifymessage.thtml');
    $T->set_var(array('post_id' => $postid, 'topic_id' => $A['id'], 'post_subject' => $A['subject'], 'post_date' => $date, 'post_name' => $A['name'], 'post_comment' => $A['comment'], 'notify_msg' => $notifymsg, 'site_name' => $_CONF['site_name'], 'online_version' => sprintf($LANG_GF02['view_online'], $permalink), 'permalink' => $permalink));
    $T->parse('output', 'email');
    $message = $T->finish($T->get_var('output'));
    $T = new Template($_CONF['path'] . 'plugins/forum/templates');
    $T->set_file('email', 'notifymessage_text.thtml');
    $T->set_var(array('post_id' => $postid, 'topic_id' => $A['id'], 'post_subject' => $A['subject'], 'post_date' => $date, 'post_name' => $A['name'], 'post_comment' => $A['comment'], 'notify_msg' => $notifymsg, 'site_name' => $_CONF['site_name'], 'online_version' => sprintf($LANG_GF02['view_online'], $_CONF['site_url'] . '/forum/viewtopic.php?showtopic=' . $postid . '&lastpost=true#' . $A['id'])));
    $T->parse('output', 'email');
    $msgText = $T->finish($T->get_var('output'));
    $html2txt = new html2text($msgText, false);
    $messageText = $html2txt->get_text();
    return array($message, $messageText);
}
Exemple #22
0
function html_to_plaintext($html)
{
    $h2t = new html2text($html);
    return $h2t->get_text();
}
 public function free_categorizeSave($PostedDatas = null, $category, $ForceCat = 0, $ForceExt = 0)
 {
     include_once dirname(__FILE__) . "/class.html2text.inc";
     $sock = new sockets();
     if (!isset($GLOBALS["uuid"])) {
         $sock = new sockets();
         $GLOBALS["uuid"] = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes"));
     }
     $uuid = $GLOBALS["uuid"];
     $f = array();
     $ExtractAllUris = $this->ExtractAllUris($PostedDatas);
     if (count($ExtractAllUris) > 0) {
         while (list($num, $ligne) = each($ExtractAllUris)) {
             $f[] = $num;
         }
         $PostedDatas = null;
     }
     $h2t = new html2text($PostedDatas);
     $h2t->get_text();
     while (list($num, $ligne) = each($h2t->_link_array)) {
         if (trim($ligne) == null) {
             continue;
         }
         $ligne = strtolower($ligne);
         $ligne = str_replace("(whois)", "", $ligne);
         $ligne = str_replace("||", "", $ligne);
         $ligne = str_replace("^", "", $ligne);
         $ligne = trim($ligne);
         if (preg_match("#^([0-9\\.]+):[0-9]+#", $ligne, $re)) {
             $websitesToscan[] = $re[1];
             continue;
         }
         if (strpos(" {$ligne}", "http") == 0) {
             $ligne = "http://{$ligne}";
         }
         $hostname = parse_url($ligne, PHP_URL_HOST);
         if (preg_match("#^www\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         if (preg_match("#^\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         if (preg_match("#^\\*\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         writelogs("{$ligne} = {$hostname}", __FUNCTION__, __FILE__, __LINE__);
         $websitesToscan[] = $ligne;
     }
     $PostedDatas = str_replace("<", "\n<", $PostedDatas);
     $PostedDatas = str_replace(' rel="nofollow"', "", $PostedDatas);
     $PostedDatas = str_replace("\r", "\n", $PostedDatas);
     $PostedDatas = str_replace("https:", "http:", $PostedDatas);
     if ($PostedDatas != null) {
         $f = explode("\n", $PostedDatas);
     }
     if (!is_numeric($ForceExt)) {
         $ForceExt = 0;
     }
     if (!is_numeric($ForceCat)) {
         $ForceCat = 0;
     }
     $ipClass = new IP();
     while (list($num, $www) = each($f)) {
         $www = trim($www);
         if ($www == null) {
             continue;
         }
         if (preg_match("#--------------#", $www)) {
             continue;
         }
         if (preg_match("#No extension#", $www)) {
             continue;
         }
         if (preg_match("#no website#i", $www)) {
             continue;
         }
         if (preg_match("#^analyze\\s+[0-9]+\\s+#", $www)) {
             continue;
         }
         if (preg_match("#(false|true):\\s+(.+?)\\s+already#i", $www, $re)) {
             $www = $re[2];
         }
         writelogs("Scanning {$www}", __FUNCTION__, __FILE__, __LINE__);
         if (preg_match("#^(.+?)\"\\s+#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#^([0-9\\.]+):[0-9]+#", $www, $re)) {
             $www = $re[1];
         }
         $www = str_replace("(whois)", "", $www);
         $www = str_replace("\r", "", $www);
         $www = str_replace("||", "", $www);
         $www = str_replace("^", "", $www);
         $www = trim(strtolower($www));
         if ($ipClass->isValid($www)) {
             $www = ip2long($www) . ".addr";
             $websitesToscan[] = $www;
             continue;
         }
         if ($www == null) {
             continue;
         }
         $www = stripslashes($www);
         if (preg_match("#href=\"(.+?)\">#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match('#<a rel=.+?href="(.+?)"#', $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#<a href.*?http://(.+?)([\\/\"'>])#i", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#<span>www\\.(.+?)\\.([a-z]+)</span>#i", $www, $re)) {
             $www = $re[1] . "." . $re[2];
         }
         $www = str_replace("http://", "", $www);
         if (preg_match("#\\/\\/.+?@(.+)#", $www, $re)) {
             $websitesToscan[] = $re[1];
         }
         if (preg_match("#http.*?:\\/\\/(.+?)[\\/\\s]+#", $www, $re)) {
             $websitesToscan[] = $re[1];
             continue;
         }
         if (preg_match("#^www\\.(.+)#", $www, $re)) {
             $www = $re[1];
         }
         $www = str_replace("<a href=", "", $www);
         $www = str_replace("<img src=", "", $www);
         $www = str_replace("title=", "", $www);
         if (preg_match("#^(.*?)\\/#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#\\.php\$#", $www, $re)) {
             echo "{$www} php script...\n";
             continue;
         }
         $www = str_replace("/", "", $www);
         $www = trim($www);
         if ($ForceExt == 0) {
             if (!preg_match("#\\.([a-z0-9]+)\$#", $www, $re)) {
                 echo "`{$www}` No extension !!?? \n";
                 continue;
             }
             if (strlen($re[1]) < 2) {
                 if (!is_numeric($re[1])) {
                     echo "{$www} bad extension `.{$re[1]}` [{$ForceExt}]\n";
                     continue;
                 }
             }
         }
         $www = str_replace('"', "", $www);
         writelogs("Success pass {$www}", __FUNCTION__, __FILE__, __LINE__);
         $websitesToscan[] = $www;
     }
     while (list($num, $www) = each($websitesToscan)) {
         $cleaned[$www] = $www;
     }
     $websitesToscan = array();
     while (list($num, $www) = each($cleaned)) {
         $websitesToscan[] = $www;
     }
     while (list($num, $www) = each($websitesToscan)) {
         writelogs("Scanning {$www}", __FUNCTION__, __FILE__, __LINE__);
         $www = strtolower($www);
         $www = replace_accents($www);
         if ($www == "www") {
             continue;
         }
         if ($www == "ssl") {
             continue;
         }
         $www = str_replace("http://", "", $www);
         $www = str_replace("https://", "", $www);
         $www = str_replace("ftp://", "", $www);
         $www = str_replace("ftps://", "", $www);
         if (preg_match("#.+?@(.+)#", $www, $ri)) {
             $www = $ri[1];
         }
         if (preg_match("#^www\\.(.+?)\$#i", $www, $ri)) {
             $www = $ri[1];
         }
         if ($ForceCat == 0) {
             if ($this->already_Cats($www)) {
                 continue;
             }
         }
         if (strpos($www, '"') > 0) {
             $www = substr($www, 0, strpos($www, '"'));
         }
         if (strpos($www, "'") > 0) {
             $www = substr($www, 0, strpos($www, "'"));
         }
         if (strpos($www, ">") > 0) {
             $www = substr($www, 0, strpos($www, ">"));
         }
         if (strpos($www, "?") > 0) {
             $www = substr($www, 0, strpos($www, "?"));
         }
         if (strpos($www, "\\") > 0) {
             $www = substr($www, 0, strpos($www, "\\"));
         }
         if (strpos($www, "/") > 0) {
             $www = substr($www, 0, strpos($www, "/") - 1);
         }
         if (preg_match("#^\\.(.+)#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#^\\*\\.(.+)#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#\\.html\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.htm\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.gif\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.png\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.jpeg\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.jpg\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.php\$#i", $www, $re)) {
             continue;
         }
         if (preg_match("#\\.js\$#i", $www, $re)) {
             continue;
         }
         if ($ForceExt == 0) {
             if (!preg_match("#\\.[a-z0-9]+\$#", $www, $re)) {
                 echo "{$www} bad extension `{$www}` \n";
                 continue;
             }
         }
         if (strpos(" ", trim($www)) > 0) {
             continue;
         }
         $sites[$www] = $www;
     }
     $this->CheckTable_dansguardian();
     if (count($sites) == 0) {
         echo "NO websites\n";
         return;
     }
     echo "\n----------------\nanalyze " . count($sites) . " websites into {$category}\n";
     while (list($num, $www) = each($sites)) {
         $www = trim($www);
         if ($www == null) {
             continue;
         }
         if (preg_match("#^www\\.(.+?)\$#", $www, $re)) {
             $www = $re[1];
         }
         writelogs("Analyze {$www}", __FUNCTION__, __FILE__, __LINE__);
         $md5 = md5($category . $www);
         if ($ForceCat == 0) {
             $cats = $this->GET_CATEGORIES($www, true, true, true);
             if ($cats != null) {
                 echo "FALSE: {$www} already categorized ({$cats})\n";
                 continue;
             }
         }
         $category_table = "category_" . $this->category_transform_name($category);
         $this->CreateCategoryTable($_POST["category"]);
         $this->QUERY_SQL("INSERT IGNORE INTO {$category_table} (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')");
         if (!$this->ok) {
             echo "categorize {$www} failed {$this->mysql_error} line " . __LINE__ . " in file " . __FILE__ . "\n";
             continue;
         }
         $this->categorize_logs($category, "{add}", $www);
         echo "TRUE: {$www} Added\n";
         $this->QUERY_SQL("INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')");
         if (!$this->ok) {
             echo $this->mysql_error . "\n";
         }
     }
     $sock = new sockets();
     $sock->getFrameWork("cmd.php?export-community-categories=yes");
 }
Exemple #24
0
/**
 * Given HTML, converts and formats it as text
 *
 * @param string $html The html to be formatted
 * @return string The formatted text
 */
function html2text($html)
{
    require_once 'html2text/class.html2text.php';
    $h2t = new html2text($html);
    $h2t->set_base_url(get_config('wwwroot'));
    return $h2t->get_text();
}
 /**
  * Return the first text part of this message
  *
  * @return string Plain text message/part content
  */
 function first_text_part()
 {
     // no message structure, return complete body
     if (empty($this->parts)) {
         return $this->body;
     }
     $out = null;
     // check all message parts
     foreach ($this->mime_parts as $mime_id => $part) {
         $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary);
         if ($mimetype == 'text/plain') {
             $out = $this->imap->get_message_part($this->uid, $mime_id, $part);
             break;
         } else {
             if ($mimetype == 'text/html') {
                 $html_part = $this->imap->get_message_part($this->uid, $mime_id, $part);
                 // remove special chars encoding
                 $trans = array_flip(get_html_translation_table(HTML_ENTITIES));
                 $html_part = strtr($html_part, $trans);
                 // create instance of html2text class
                 $txt = new html2text($html_part);
                 $out = $txt->get_text();
                 break;
             }
         }
     }
     return $out;
 }
Exemple #26
0
 function clean_html_to_text($msg = null)
 {
     if (!$msg) {
         $msg =& $this->html;
     }
     $msg = $this->strip_style($msg);
     // strip out leading whitespace
     $msg = preg_replace('/^ +/m', '', $msg);
     // Intelligently convert HTML to text
     require_once 'class.html2text.inc';
     $html2text = new html2text($msg);
     $msg = $html2text->get_text();
     $msg = ltrim($msg);
     $lines = preg_split("/\r|\n/", $msg);
     $msg = '> ';
     foreach ($lines as $line) {
         $line = ltrim($line);
         if (strlen($line) > 75) {
             $msg .= wordwrap($line, 75, "\n" . "> ", 1);
         } else {
             $msg .= "{$line}\n> ";
         }
     }
     return $msg;
 }
Exemple #27
0
 function send_mail_phpmailer($email, $subject, $message = "", $from = "", $reply_to = "", $html_template = "", $templatevars = null, $from_name = "", $cc = "", $bcc = "")
 {
     # if ($use_phpmailer==true) this function is used instead.
     # Mail templates can include lang, server, site_text, and POST variables by default
     # ex ( [lang_mycollections], [server_REMOTE_ADDR], [text_footer] , [message]
     # additional values must be made available through $templatevars
     # For example, a complex url or image path that may be sent in an
     # email should be added to the templatevars array and passed into send_mail.
     # available templatevars need to be well-documented, and sample templates
     # need to be available.
     # Include footer
     global $email_footer, $storagedir;
     $phpversion = phpversion();
     if ($phpversion >= '5.3') {
         if (file_exists(dirname(__FILE__) . "/../lib/phpmailer_v5.2.6/class.phpmailer.php")) {
             include_once dirname(__FILE__) . "/../lib/phpmailer_v5.2.6/class.phpmailer.php";
             include_once dirname(__FILE__) . "/../lib/phpmailer_v5.2.6/extras/class.html2text.php";
         }
     } else {
         // less than 5.3
         if (file_exists(dirname(__FILE__) . "/../lib/phpmailer/class.phpmailer.php")) {
             include_once dirname(__FILE__) . "/../lib/phpmailer/class.phpmailer.php";
             include_once dirname(__FILE__) . "/../lib/phpmailer/class.html2text.php";
         }
     }
     global $email_from;
     if ($from == "") {
         $from = $email_from;
     }
     if ($reply_to == "") {
         $reply_to = $email_from;
     }
     global $applicationname;
     if ($from_name == "") {
         $from_name = $applicationname;
     }
     #check for html template. If exists, attempt to include vars into message
     if ($html_template != "") {
         # Attempt to verify users by email, which allows us to get the email template by lang and usergroup
         $to_usergroup = sql_query("select lang,usergroup from user where email ='" . escape_check($email) . "'", "");
         if (count($to_usergroup) != 0) {
             $to_usergroupref = $to_usergroup[0]['usergroup'];
             $to_usergrouplang = $to_usergroup[0]['lang'];
         } else {
             $to_usergrouplang = "";
         }
         if ($to_usergrouplang == "") {
             global $defaultlanguage;
             $to_usergrouplang = $defaultlanguage;
         }
         if (isset($to_usergroupref)) {
             $modified_to_usergroupref = hook("modifytousergroup", "", $to_usergroupref);
             if ($modified_to_usergroupref !== null) {
                 $to_usergroupref = $modified_to_usergroupref;
             }
             $results = sql_query("select language,name,text from site_text where page='all' and name='{$html_template}' and specific_to_group='{$to_usergroupref}'");
         } else {
             $results = sql_query("select language,name,text from site_text where page='all' and name='{$html_template}' and specific_to_group is null");
         }
         global $site_text;
         for ($n = 0; $n < count($results); $n++) {
             $site_text[$results[$n]["language"] . "-" . $results[$n]["name"]] = $results[$n]["text"];
         }
         $language = $to_usergrouplang;
         if (array_key_exists($language . "-" . $html_template, $site_text)) {
             $template = $site_text[$language . "-" . $html_template];
         } else {
             global $languages;
             # Can't find the language key? Look for it in other languages.
             reset($languages);
             foreach ($languages as $key => $value) {
                 if (array_key_exists($key . "-" . $html_template, $site_text)) {
                     $template = $site_text[$key . "-" . $html_template];
                     break;
                 }
             }
             // Fall back to language file if not in site text
             global $lang;
             if (isset($lang[$html_template])) {
                 $template = $lang[$html_template];
             }
         }
         if (isset($template) && $template != "") {
             preg_match_all('/\\[[^\\]]*\\]/', $template, $test);
             foreach ($test[0] as $variable) {
                 $variable = str_replace("[", "", $variable);
                 $variable = str_replace("]", "", $variable);
                 # get lang variables (ex. [lang_mycollections])
                 if (substr($variable, 0, 5) == "lang_") {
                     global $lang;
                     ${$variable} = $lang[substr($variable, 5)];
                 } else {
                     if (substr($variable, 0, 7) == "server_") {
                         ${$variable} = $_SERVER[substr($variable, 7)];
                     } else {
                         if (substr($variable, 0, 15) == "embed_thumbnail") {
                             $thumbcid = uniqid('thumb');
                             ${$variable} = "<img style='border:1px solid #d1d1d1;' src='cid:{$thumbcid}' />";
                         } else {
                             if (substr($variable, 0, 15) == "img_storagedir_") {
                                 ${$variable} = "<img src='cid:" . basename(substr($variable, 15)) . "'/>";
                                 $images[] = dirname(__FILE__) . substr($variable, 15);
                             } else {
                                 if (substr($variable, 0, 4) == "img_") {
                                     $image_path = substr($variable, 4);
                                     if (substr($image_path, 0, 1) == "/") {
                                         // absolute paths
                                         $images[] = $image_path;
                                     } else {
                                         // relative paths
                                         $image_path = str_replace("../", "", $image_path);
                                         $images[] = dirname(__FILE__) . "/../" . $image_path;
                                     }
                                     ${$variable} = "<img src='cid:" . basename($image_path) . "'/>";
                                     $images[] = $image_path;
                                 } else {
                                     if (substr($variable, 0, 7) == "attach_") {
                                         ${$variable} = "";
                                         $attachments[] = substr($variable, 7);
                                     } else {
                                         if (substr($variable, 0, 5) == "text_") {
                                             ${$variable} = text(substr($variable, 5));
                                         } else {
                                             ${$variable} = getval($variable, "");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 # avoid resetting templatevars that may have been passed here
                 if (!isset($templatevars[$variable])) {
                     $templatevars[$variable] = ${$variable};
                 }
             }
             if (isset($templatevars)) {
                 foreach ($templatevars as $key => $value) {
                     $template = str_replace("[" . $key . "]", nl2br($value), $template);
                 }
             }
             $body = $template;
         }
     }
     if (!isset($body)) {
         $body = $message;
     }
     global $use_smtp, $smtp_secure, $smtp_host, $smtp_port, $smtp_auth, $smtp_username, $smtp_password;
     $mail = new PHPMailer();
     // use an external SMTP server? (e.g. Gmail)
     if ($use_smtp) {
         $mail->IsSMTP();
         // enable SMTP
         $mail->SMTPDebug = 0;
         // debugging: 1 = errors and messages, 2 = messages only
         $mail->SMTPAuth = $smtp_auth;
         // authentication enabled/disabled
         $mail->SMTPSecure = $smtp_secure;
         // '', 'tls' or 'ssl'
         $mail->Host = $smtp_host;
         // hostname
         $mail->Port = $smtp_port;
         // port number
         $mail->Username = $smtp_username;
         // username
         $mail->Password = $smtp_password;
         // password
     }
     $reply_tos = explode(",", $reply_to);
     // only one from address is possible, so only use the first one:
     if (strstr($reply_tos[0], "<")) {
         $rtparts = explode("<", $reply_tos[0]);
         $mail->From = str_replace(">", "", $rtparts[1]);
         $mail->FromName = $rtparts[0];
     } else {
         $mail->From = $reply_tos[0];
         $mail->FromName = $from_name;
     }
     // if there are multiple addresses, that's what replyto handles.
     for ($n = 0; $n < count($reply_tos); $n++) {
         if (strstr($reply_tos[$n], "<")) {
             $rtparts = explode("<", $reply_tos[$n]);
             $mail->AddReplyto(str_replace(">", "", $rtparts[1]), $rtparts[0]);
         } else {
             $mail->AddReplyto($reply_tos[$n], $from_name);
         }
     }
     # modification to handle multiple comma delimited emails
     # such as for a multiple $email_notify
     $emails = $email;
     $emails = explode(',', $emails);
     $emails = array_map('trim', $emails);
     foreach ($emails as $email) {
         if (strstr($email, "<")) {
             $emparts = explode("<", $email);
             $mail->AddAddress(str_replace(">", "", $emparts[1]), $emparts[0]);
         } else {
             $mail->AddAddress($email);
         }
     }
     if ($cc != "") {
         # modification for multiple is also necessary here, though a broken cc seems to be simply removed by phpmailer rather than breaking it.
         $ccs = $cc;
         $ccs = explode(',', $ccs);
         $ccs = array_map('trim', $ccs);
         global $userfullname;
         foreach ($ccs as $cc) {
             if (strstr($cc, "<")) {
                 $ccparts = explode("<", $cc);
                 $mail->AddCC(str_replace(">", "", $ccparts[1]), $ccparts[0]);
             } else {
                 $mail->AddCC($cc, $userfullname);
             }
         }
     }
     if ($bcc != "") {
         # modification for multiple is also necessary here, though a broken cc seems to be simply removed by phpmailer rather than breaking it.
         $bccs = $bcc;
         $bccs = explode(',', $bccs);
         $bccs = array_map('trim', $bccs);
         global $userfullname;
         foreach ($bccs as $bccemail) {
             if (strstr($bccemail, "<")) {
                 $bccparts = explode("<", $bccemail);
                 $mail->AddBCC(str_replace(">", "", $bccparts[1]), $bccparts[0]);
             } else {
                 $mail->AddBCC($bccemail, $userfullname);
             }
         }
     }
     $mail->CharSet = "utf-8";
     if (is_html($body)) {
         $mail->IsHTML(true);
     } else {
         $mail->IsHTML(false);
     }
     $mail->Subject = $subject;
     $mail->Body = $body;
     if (isset($embed_thumbnail) && isset($templatevars['thumbnail'])) {
         $mail->AddEmbeddedImage($templatevars['thumbnail'], $thumbcid, $thumbcid, 'base64', 'image/jpeg');
     }
     if (isset($images)) {
         foreach ($images as $image) {
             $mail->AddEmbeddedImage($image, basename($image), basename($image), 'base64', 'image/gif');
         }
     }
     if (isset($attachments)) {
         foreach ($attachments as $attachment) {
             $mail->AddAttachment($attachment, basename($attachment));
         }
     }
     if (is_html($body)) {
         $h2t = new html2text($body);
         $text = $h2t->get_text();
         $mail->AltBody = $text;
     }
     if (!$mail->Send()) {
         echo "Message could not be sent. <p>";
         echo "Mailer Error: " . $mail->ErrorInfo;
         exit;
     }
     hook("aftersendmailphpmailer", "", $email);
 }
Exemple #28
0
function _ff_getListField_forum($fieldname, $fieldvalue, $A, $icon_arr)
{
    global $_CONF, $_USER, $_TABLES, $LANG_ADMIN, $LANG04, $LANG28, $_IMAGE_TYPE;
    global $_FF_CONF, $_SYSTEM, $LANG_GF02;
    if (!isset($A['status'])) {
        $A['status'] = 0;
    }
    USES_lib_html2text();
    $retval = '';
    $dt = new Date('now', $_USER['tzid']);
    switch ($fieldname) {
        case 'date':
        case 'lastupdated':
            $dt->setTimestamp($fieldvalue);
            $retval = $dt->format($_FF_CONF['default_Datetime_format'], true);
            break;
        case 'subject':
            $testText = FF_formatTextBlock($A['comment'], 'text', 'text', $A['status']);
            $testText = strip_tags($testText);
            $html2txt = new html2text($testText, false);
            $testText = trim($html2txt->get_text());
            $lastpostinfogll = @htmlspecialchars(preg_replace('#\\r?\\n#', '<br>', strip_tags(substr($testText, 0, $_FF_CONF['contentinfo_numchars']) . '...')), ENT_QUOTES, COM_getEncodingt());
            $retval = '<a class="' . COM_getTooltipStyle() . '" style="text-decoration:none;" href="' . $_CONF['site_url'] . '/forum/viewtopic.php?showtopic=' . ($A['pid'] == 0 ? $A['id'] : $A['pid']) . '&amp;topic=' . $A['id'] . '#' . $A['id'] . '" title="' . $A['subject'] . '::' . $lastpostinfogll . '" rel="nofollow">' . $fieldvalue . '</a>';
            break;
        case 'bookmark':
            $bm_icon_on = '<img src="' . _ff_getImage('star_on_sm') . '" title="' . $LANG_GF02['msg204'] . '" alt=""/>';
            $retval = '<span id="forumbookmark' . $A['topic_id'] . '"><a href="#" onclick="ajax_toggleForumBookmark(' . $A['topic_id'] . ');return false;">' . $bm_icon_on . '</a></span>';
            break;
        case 'replies':
        case 'views':
            if ($fieldvalue != '') {
                $retval = $fieldvalue;
            } else {
                $retval = '0';
            }
            break;
        default:
            $retval = $fieldvalue;
            break;
    }
    return $retval;
}
Exemple #29
0
/**
 * Given HTML text, make it into plain text using external function
 *
 * @param string $html The text to be converted.
 * @param integer $width Width to wrap the text at. (optional, default 75 which
 *      is a good value for email. 0 means do not limit line length.)
 * @param boolean $dolinks By default, any links in the HTML are collected, and
 *      printed as a list at the end of the HTML. If you don't want that, set this
 *      argument to false.
 * @return string plain text equivalent of the HTML.
 */
function html_to_text($html, $width = 75, $dolinks = true)
{
    global $CFG;
    require_once $CFG->libdir . '/html2text.php';
    $h2t = new html2text($html, false, $dolinks, $width);
    $result = $h2t->get_text();
    return $result;
}
function sc_log_attempts($type, $param1 = null, $param2 = null)
{
    global $thisfile_sc, $SITEURL, $sc_language;
    require_once GSPLUGINPATH . 'getsimple_contact/inc/class.phpmailer.php';
    require_once GSPLUGINPATH . 'getsimple_contact/inc/class.html2text.php';
    $settings = sc_get_settings();
    $ip = $_SERVER['REMOTE_ADDR'];
    $host = gethostbyaddr($ip);
    $date = date('Y. m. d. H:i');
    if ($type == 'invalid_form_data') {
        $enabled = '';
        $posted = '';
        foreach ($param1 as $key => $value) {
            $enabled .= $value . ', ';
        }
        foreach ($param2 as $key => $value) {
            $posted .= $key . ', ';
        }
    } else {
        $enabled = '';
        $posted = '';
    }
    $enabled = substr($enabled, 0, -2);
    $posted = substr($posted, 0, -2);
    $subject = sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_SUBJECT_START') . get_site_name(false) . sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_SUBJECT_END');
    $log = sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_START') . get_site_name(false) . ' - ' . get_page_clean_title(false) . sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_END') . '<br/><br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_DETAILS') . '<br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_DATE') . $date . '<br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_SITE') . $SITEURL . '<br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_IP') . $ip . '<br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_HOST') . $host . '<br/>';
    $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_TYPE') . $type . '<br/>';
    if ($type == 'invalid_form_data') {
        $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_WHITELIST') . $enabled . '<br/>';
        $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_POSTED') . $posted . '<br/>';
    } else {
        if ($type == 'invalid_token') {
            $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_CORRECT_TOKEN') . $param1 . '<br/>';
            $log .= sc_i18n($thisfile_sc, $sc_language, 'SC_FE_LOG_MESSAGE_FALSE_TOKEN') . $param2 . '<br/>';
        }
    }
    $nonHTML = new html2text($log);
    $mail = new PHPMailer();
    if ($settings['smtp_status'] == 1) {
        $mail->IsSMTP();
        $mail->SMTPDebug = 0;
        $mail->Host = $settings['smtp_host'];
        $mail->Port = $settings['smtp_port'];
        if ($settings['smtp_auth'] == 1) {
            $mail->SMTPAuth = true;
            $mail->Username = $settings['smtp_username'];
            $mail->Password = sc_decrypt_smtp_password($settings['smtp_password']);
            if ($settings['smtp_host'] == 'smtp.gmail.com' && $settings['smtp_port'] == 465) {
                $mail->SMTPSecure = 'ssl';
            } else {
                if ($settings['smtp_host'] == 'smtp.gmail.com' && $settings['smtp_port'] == 587) {
                    $mail->SMTPSecure = 'tls';
                }
            }
        }
    } else {
        $mail->setLanguage('en_US', GSPLUGINPATH . 'getsimple_contact/lang/');
    }
    $mail->CharSet = 'UTF-8';
    $mail->From = $settings['superadmin_email'];
    $mail->FromName = $settings['superadmin_name'];
    $mail->addAddress($settings['superadmin_email'], $settings['superadmin_name']);
    $mail->WordWrap = 50;
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $log;
    $mail->AltBody = $nonHTML->get_text();
    $mail->send();
}