Esempio n. 1
1
function sl_send_email($to, $subject, $html, $plain = null, $attachment = null)
{
    if (empty($to)) {
        return false;
    }
    $hash = md5(date('r', time()));
    $headers['From'] = 'The LoveMachine <*****@*****.**>';
    $headers['To'] = $to;
    if (!empty($html)) {
        if (empty($plain)) {
            $h2t = new html2text($html, 75);
            $plain = $h2t->convert();
        }
        $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\"";
        $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--";
        if ($attachment != null && !empty($attachment['name']) && !empty($attachment['content'])) {
            $headers["Content-Type"] = "multipart/mixed; boundary=\"PHP-mixed-{$hash}\"";
            //encode it with MIME base64,
            //and split it into smaller chunks
            $attachmentContent = chunk_split(base64_encode($attachment['content']));
            $body = "\n--PHP-mixed-{$hash}\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$hash}\"\n\n" . $body . "\n--PHP-mixed-{$hash}  \nContent-Type: {$attachment['type']}; name=\"{$attachment['name']}\"  \nContent-Transfer-Encoding: base64  \nContent-Disposition: attachment  \n\n{$attachmentContent}\n--PHP-mixed-{$hash}-- \n";
        }
    } else {
        $body = $plain;
    }
    send_authmail(array('sender' => 'authuser', 'server' => 'gmail-ssl'), $to, $subject, $body, $headers);
    return true;
}
Esempio n. 2
0
 /**
  * @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);
 }
Esempio n. 3
0
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;
}
Esempio n. 4
0
 public function convert()
 {
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'html2text.php';
     $Converter = new html2text(true, 0, false);
     $markdown = str_replace('__AK:AMP__', '&', $Converter->load_string(str_replace('&', '__AK:AMP__', $this->source)));
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'smartypants.php';
     $Smartypants = new SmartyPantsTypographer_Parser();
     $markdown = Ak::html_entity_decode(strip_tags($Smartypants->transform($markdown)));
     return trim($this->_simplifyMarkdown($markdown));
 }
Esempio n. 5
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})");
     }
 }
Esempio n. 6
0
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;
}
Esempio n. 7
0
function sl_send_email($to, $subject, $html, $plain = null, $mailq = 'gmail-ssl')
{
    if (empty($to)) {
        return false;
    }
    $hash = md5(date('r', time()));
    if (!empty($html)) {
        if (empty($plain)) {
            $h2t = new html2text($html, 75);
            $plain = $h2t->convert();
        }
        $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\"";
        $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--";
    } else {
        $body = $plain;
    }
    send_authmail(array('sender' => 'loveuser', 'server' => $mailq), $to, $subject, $body, $headers);
    return true;
}
Esempio n. 8
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);
}
Esempio n. 9
0
 /**
  * Override parent function to make links unique
  * @see html2text::_build_link_list()
  */
 function _build_link_list($link, $display)
 {
     // If links already exists, return its existing reference
     if (array_key_exists($link, $this->links)) {
         return $display . ' [' . $this->links[$link] . ']';
     } else {
         $result = parent::_build_link_list($link, $display);
         preg_match('/\\[(\\d+)\\]$/', $result, $m);
         $reference = $m[1];
         $this->links[$link] = $reference;
         return $result;
     }
 }
Esempio n. 10
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;
}
Esempio n. 11
0
 /**
  * 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;
 }
Esempio n. 12
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;
}
 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");
 }
Esempio n. 14
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));
    }
}
Esempio n. 15
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();
}
Esempio n. 16
0
 // Set page title
 $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;
Esempio n. 17
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);
 }
Esempio n. 18
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);
 }
Esempio n. 19
0
 function html_to_text($html)
 {
     include_once ROOT . "/library/html2text/class.html2text.inc";
     $h2t = new html2text($html);
     return $h2t->get_text();
 }
Esempio n. 20
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;
}
Esempio n. 21
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;
}
Esempio n. 22
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;
 }
Esempio n. 23
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;
}
Esempio n. 24
0
 /**
  * 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;
 }
Esempio n. 25
0
 function convert()
 {
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'html2text.php';
     $Converter = new html2text(true, 0, false);
     return $Converter->load_string($this->source);
 }
Esempio n. 26
0
 if ($_POST['Message'] == '') {
     $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"]);
Esempio n. 27
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();
 }
Esempio n. 28
0
 public function renderFormatedString($str, $format, $return = false)
 {
     if ($format == 'plain_text') {
         if (class_exists('html2text')) {
             $str = html2text::convert($str);
         } else {
             $str = strip_tags($str);
         }
         if ($return === false) {
             if (!headers_sent()) {
                 header('Content-Type: text/plain');
             }
             echo $str;
         } else {
             return $str;
         }
     }
 }
Esempio n. 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;
}
Esempio n. 30
0
     $tplname = 'removelog_logowner';
 } else {
     // 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);