コード例 #1
0
ファイル: Driver.php プロジェクト: jubinpatel/horde
 /**
  * Returns the provided story as a MIME part.
  *
  * @param array $story  A data array representing a story.
  *
  * @return MIME_Part  The MIME message part containing the story parts.
  * @TODO: Refactor to use new Horde MIME library
  */
 protected function getStoryAsMessage($story)
 {
     require_once 'Horde/MIME/Part.php';
     /* Add the story to the message based on the story's body type. */
     switch ($story['body_type']) {
         case 'richtext':
             /* Get a plain text version of a richtext story. */
             $body_html = $story['body'];
             $body_text = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($body_html, 'html2text');
             /* Add description. */
             $body_html = '<p>' . $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['desc'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'callback' => null)) . "</p>\n" . $body_html;
             $body_text = Horde_String::wrap('  ' . $story['description'], 70) . "\n\n" . $body_text;
             /* Add the text version of the story to the base message. */
             $message_text = new MIME_Part('text/plain');
             $message_text->setCharset('UTF-8');
             $message_text->setContents($message_text->replaceEOL($body_text));
             $message_text->setDescription(_("Plaintext Version of Story"));
             /* Add an HTML version of the story to the base message. */
             $message_html = new MIME_Part('text/html', Horde_String::wrap($body_html), 'UTF-8', 'inline');
             $message_html->setDescription(_("HTML Version of Story"));
             /* Add the two parts as multipart/alternative. */
             $basepart = new MIME_Part('multipart/alternative');
             $basepart->addPart($message_text);
             $basepart->addPart($message_html);
             return $basepart;
         case 'text':
             /* This is just a plain text story. */
             $message_text = new MIME_Part('text/plain');
             $message_text->setContents($message_text->replaceEOL($story['description'] . "\n\n" . $story['body']));
             $message_text->setCharset('UTF-8');
             return $message_text;
     }
 }