text2html() public static method

Shortcut function to convert text -> HTML for purposes of composition.
public static text2html ( string $msg ) : string
$msg string The message text.
return string HTML text.
Ejemplo n.º 1
0
 /**
  */
 protected function _addIdentityJs()
 {
     global $injector, $page_output;
     $identities = array();
     $identity = $injector->getInstance('IMP_Identity');
     $sigs = $identity->hasSignature(true);
     foreach (array_keys(iterator_to_array($identity)) as $ident) {
         $sm = $identity->getValue(IMP_Mailbox::MBOX_SENT, $ident);
         $entry = array('sm_name' => $sm ? $sm->form_to : '', 'sm_save' => (bool) $identity->saveSentmail($ident), 'sm_title' => $sm ? $sm->display_notranslate : '', 'sm_display' => $sm ? $sm->display_html : '', 'bcc' => strval($identity->getBccAddresses($ident)));
         if ($sigs) {
             $sig = $identity->getSignature('text', $ident);
             $html_sig = $identity->getSignature('html', $ident);
             if (!strlen($html_sig) && strlen($sig)) {
                 $html_sig = IMP_Compose::text2html($sig);
             }
             $sig_dom = new Horde_Domhtml($html_sig, 'UTF-8');
             $html_sig = '';
             foreach ($sig_dom->getBody()->childNodes as $child) {
                 $html_sig .= $sig_dom->dom->saveXml($child);
             }
             $entry['sig'] = trim($sig);
             $entry['hsig'] = $html_sig;
         }
         $identities[] = $entry;
     }
     $page_output->addInlineJsVars(array('ImpCompose.identities' => $identities));
 }
Ejemplo n.º 2
0
 /**
  * Helper for html2Text() and text2Html().
  *
  * @internal
  */
 protected function _convertText($mode)
 {
     global $injector;
     $compose = null;
     $result = new stdClass();
     $result->text = array();
     foreach (json_decode($this->vars->data, true) as $key => $val) {
         $tmp = null;
         if (empty($val['changed'])) {
             if (!$compose) {
                 $compose = $this->_base->initCompose();
             }
             switch ($compose->compose->replyType()) {
                 case IMP_Compose::FORWARD_BODY:
                 case IMP_Compose::FORWARD_BOTH:
                     $data = $compose->compose->forwardMessageText($compose->contents, array('format' => $mode));
                     $tmp = $data['body'];
                     break;
                 case IMP_Compose::REPLY_ALL:
                 case IMP_Compose::REPLY_LIST:
                 case IMP_Compose::REPLY_SENDER:
                     $data = $compose->compose->replyMessageText($compose->contents, array('format' => $mode));
                     $tmp = $data['body'];
                     break;
             }
         }
         if (is_null($tmp)) {
             switch ($mode) {
                 case 'html':
                     $tmp = IMP_Compose::text2html($val['text']);
                     break;
                 case 'text':
                     $tmp = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($val['text'], 'Html2text', array('wrap' => false));
                     break;
             }
         }
         $result->text[$key] = $tmp;
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Returns the full signature based on the current settings for the
  * signature itself, the dashes and the position.
  *
  * @param string $type    Either 'text' or 'html'.
  * @param integer $ident  The identity to retrieve the signature from.
  *
  * @return string  The full signature.
  * @throws Horde_Exception
  */
 public function getSignature($type = 'text', $ident = null)
 {
     if (is_null($ident)) {
         $ident = $this->getDefault();
     }
     $convert = false;
     $key = $ident . '|' . $type;
     $val = null;
     if (isset($this->_cached['signatures'][$key])) {
         return $this->_cached['signatures'][$key];
     }
     if ($type == 'html') {
         $val = $this->getValue('signature_html', $ident);
         if (!strlen($val)) {
             $convert = true;
             $val = null;
         }
     }
     if (is_null($val)) {
         $val = $this->getValue('signature', $ident);
         if (strlen($val) && $type == 'text') {
             $val = str_replace("\r\n", "\n", $val);
             $val = $this->getValue('sig_dashes', $ident) ? "\n-- \n" . $val : "\n\n" . $val;
         }
     }
     if ($val && $type == 'html') {
         if ($convert) {
             $val = IMP_Compose::text2html(trim($val));
         }
         $val = '<div>' . $val . '</div>';
     }
     $this->_cached['signatures'][$key] = $val;
     return $val;
 }
Ejemplo n.º 4
0
 /**
  * Convert compose data to/from text/HTML.
  *
  * @param string $data  The message text.
  * @param string $to    Either 'text' or 'html'.
  *
  * @return string  The converted text.
  */
 public function convertComposeText($data, $to)
 {
     switch ($to) {
         case 'html':
             return IMP_Compose::text2html($data);
         case 'text':
             return $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($data, 'Html2text', array('wrap' => false));
     }
 }