Exemplo n.º 1
4
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     if ($view_mode == 'mail') {
         // Convert field labels into headings.
         // @todo Improve drupal_html_to_text() to convert DIVs correctly.
         foreach (Element::children($build) as $key) {
             if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
                 $build[$key] += array('#prefix' => '');
                 $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
                 $build[$key]['#label_display'] = 'hidden';
             }
         }
         $build = array('#markup' => drupal_html_to_text(drupal_render($build)));
     }
     return $build;
 }
Exemplo n.º 2
0
 /**
  * Concatenates and wraps the email body for plain-text mails.
  *
  * @param array $message
  *   A message array, as described in hook_mail_alter().
  *
  * @return array
  *   The formatted $message.
  */
 public function format(array $message)
 {
     // Join the body array into one string.
     $message['body'] = implode("\n\n", $message['body']);
     // Convert any HTML to plain-text.
     $message['body'] = drupal_html_to_text($message['body']);
     // Wrap the mail body for sending.
     $message['body'] = drupal_wrap_mail($message['body']);
     return $message;
 }
 /**
  * Concatenate and wrap the e-mail body for either
  * plain-text or HTML emails.
  *
  * @param $message
  *   A message array, as described in hook_mail_alter().
  *
  * @return
  *   The formatted $message.
  */
 public function format(array $message)
 {
     $this->AllowHtml = $this->smtpConfig->get('smtp_allowhtml');
     // Join the body array into one string.
     $message['body'] = implode("\n\n", $message['body']);
     if ($this->AllowHtml == 0) {
         // Convert any HTML to plain-text.
         $message['body'] = drupal_html_to_text($message['body']);
         // Wrap the mail body for sending.
         $message['body'] = drupal_wrap_mail($message['body']);
     }
     return $message;
 }
Exemplo n.º 4
0
/**
 * Prepare a message based on parameters; called from drupal_mail().
 *
 * Note that hook_mail(), unlike hook_mail_alter(), is only called on the
 * $module argument to drupal_mail(), not all modules.
 *
 * @param $key
 *   An identifier of the mail.
 * @param $message
 *   An array to be filled in. Elements in this array include:
 *   - id: An ID to identify the mail sent. Look at module source code
 *     or drupal_mail() for possible id values.
 *   - to: The address or addresses the message will be sent to. The formatting
 *     of this string will be validated with the
 *     @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
 *   - subject: Subject of the e-mail to be sent. This must not contain any
 *     newline characters, or the mail may not be sent properly. drupal_mail()
 *     sets this to an empty string when the hook is invoked.
 *   - body: An array of lines containing the message to be sent. Drupal will
 *     format the correct line endings for you. drupal_mail() sets this to an
 *     empty array when the hook is invoked.
 *   - from: The address the message will be marked as being from, which is
 *     set by drupal_mail() to either a custom address or the site-wide
 *     default email address when the hook is invoked.
 *   - headers: Associative array containing mail headers, such as From,
 *     Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills
 *     several headers in this array.
 * @param $params
 *   An array of parameters supplied by the caller of drupal_mail().
 */
function hook_mail($key, &$message, $params)
{
    $account = $params['account'];
    $context = $params['context'];
    $variables = array('%site_name' => variable_get('site_name', 'Drupal'), '%username' => format_username($account));
    if ($context['hook'] == 'taxonomy') {
        $entity = $params['entity'];
        $vocabulary = taxonomy_vocabulary_load($entity->vid);
        $variables += array('%term_name' => $entity->name, '%term_description' => $entity->description, '%term_id' => $entity->tid, '%vocabulary_name' => $vocabulary->name, '%vocabulary_description' => $vocabulary->description, '%vocabulary_id' => $vocabulary->vid);
    }
    // Node-based variable translation is only available if we have a node.
    if (isset($params['node'])) {
        $node = $params['node'];
        $variables += array('%uid' => $node->uid, '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), '%node_type' => node_type_get_name($node), '%title' => $node->title, '%teaser' => $node->teaser, '%body' => $node->body);
    }
    $subject = strtr($context['subject'], $variables);
    $body = strtr($context['message'], $variables);
    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
    $message['body'][] = drupal_html_to_text($body);
}
Exemplo n.º 5
0
 /**
  * Escape #text elements for safe iCal use
  *
  * @param $text
  *   Text to escape
  *
  * @return
  *   Escaped text
  *
  */
 public static function date_ical_escape_text($text)
 {
     $text = drupal_html_to_text($text);
     $text = trim($text);
     // TODO Per #38130 the iCal specs don't want : and " escaped
     // but there was some reason for adding this in. Need to watch
     // this and see if anything breaks.
     //$text = str_replace('"', '\"', $text);
     //$text = str_replace(":", "\:", $text);
     $text = preg_replace("/\\\\b/", "\\\\", $text);
     $text = str_replace(",", "\\,", $text);
     $text = str_replace(";", "\\;", $text);
     $text = str_replace("\n", "\\n ", $text);
     return trim($text);
 }
 *   - field-label-[label_display]: The current label position. For example, if
 *     the label position is "above" it would result in "field-label-above".
 *
 * Other variables:
 * - $element['#object']: The entity to which the field is attached.
 * - $element['#view_mode']: View mode, e.g. 'full', 'teaser'...
 * - $element['#field_name']: The field name.
 * - $element['#field_type']: The field type.
 * - $element['#field_language']: The field language.
 * - $element['#field_translatable']: Whether the field is translatable or not.
 * - $element['#label_display']: Position of label display, inline, above, or
 *   hidden.
 * - $field_name_css: The css-compatible field name.
 * - $field_type_css: The css-compatible field type.
 * - $classes_array: Array of html class attribute values. It is flattened
 *   into a string within the variable $classes.
 *
 * @see template_preprocess_field()
 * @see theme_field()
 *
 * @ingroup themeable
 */
//all of the field-banner-xxx items have fieldgroups wrapped around them giving them the necessary <section> tag
//the title and text have another fieldgroup wrapped around them giving them the necessary <div> tag
foreach ($items as $delta => $item) {
    $theContent = render($item);
    //turn the field into htmp with drupal_html_to_text
    //use strip_tags to remove everything but a tags becasue the drupal function cannot do this (apparently)
    $theRevisedContent = strip_tags(drupal_html_to_text($theContent), '<a>');
    echo '<p>' . $theRevisedContent . '</p>';
}
Exemplo n.º 7
0
 /**
  * Tests auto-reply on the site-wide contact form.
  */
 function testAutoReply()
 {
     // Create and login administrative user.
     $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer permissions', 'administer users'));
     $this->drupalLogin($admin_user);
     // Set up three categories, 2 with an auto-reply and one without.
     $foo_autoreply = $this->randomName(40);
     $bar_autoreply = $this->randomName(40);
     $this->addCategory('foo', 'foo', '*****@*****.**', $foo_autoreply, FALSE);
     $this->addCategory('bar', 'bar', '*****@*****.**', $bar_autoreply, FALSE);
     $this->addCategory('no_autoreply', 'no_autoreply', '*****@*****.**', '', FALSE);
     // Log the current user out in order to test the name and email fields.
     $this->drupalLogout();
     user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
     // Test the auto-reply for category 'foo'.
     $email = $this->randomName(32) . '@example.com';
     $subject = $this->randomName(64);
     $this->submitContact($this->randomName(16), $email, $subject, 'foo', $this->randomString(128));
     // We are testing the auto-reply, so there should be one email going to the sender.
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email));
     $this->assertEqual(count($captured_emails), 1);
     $this->assertEqual(trim($captured_emails[0]['body']), trim(drupal_html_to_text($foo_autoreply)));
     // Test the auto-reply for category 'bar'.
     $email = $this->randomName(32) . '@example.com';
     $this->submitContact($this->randomName(16), $email, $this->randomString(64), 'bar', $this->randomString(128));
     // Auto-reply for category 'bar' should result in one auto-reply email to the sender.
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email));
     $this->assertEqual(count($captured_emails), 1);
     $this->assertEqual(trim($captured_emails[0]['body']), trim(drupal_html_to_text($bar_autoreply)));
     // Verify that no auto-reply is sent when the auto-reply field is left blank.
     $email = $this->randomName(32) . '@example.com';
     $this->submitContact($this->randomName(16), $email, $this->randomString(64), 'no_autoreply', $this->randomString(128));
     $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email));
     $this->assertEqual(count($captured_emails), 0);
 }
 *     the label position is "above" it would result in "field-label-above".
 *
 * Other variables:
 * - $element['#object']: The entity to which the field is attached.
 * - $element['#view_mode']: View mode, e.g. 'full', 'teaser'...
 * - $element['#field_name']: The field name.
 * - $element['#field_type']: The field type.
 * - $element['#field_language']: The field language.
 * - $element['#field_translatable']: Whether the field is translatable or not.
 * - $element['#label_display']: Position of label display, inline, above, or
 *   hidden.
 * - $field_name_css: The css-compatible field name.
 * - $field_type_css: The css-compatible field type.
 * - $classes_array: Array of html class attribute values. It is flattened
 *   into a string within the variable $classes.
 *
 * @see template_preprocess_field()
 * @see theme_field()
 *
 * @ingroup themeable
 */
?>

<?php 
foreach ($items as $delta => $item) {
    $theContent = render($item);
    //turn the field into htmp with drupal_html_to_text
    //use strip_tags to remove everything but a tags becasue the drupal function cannot do this (apparently)
    $theRevisedContent = strip_tags(drupal_html_to_text($theContent), '<a><br><h4><p><ul><li>');
    echo '<p>' . $theRevisedContent . '</p>';
}
			</tr>
			<tr>
			</tr>

			<tr>
				<td>&nbsp;</td>
				<td colspan="2"><table width="100%" border="0" style="border-collapse:collapse;">
					<tr>
						<td valign="top">
									<?php 
$i = 1;
$others = array();
foreach ($nodes as $node) {
    $node = is_array($node) ? $node[0] : $node;
    $content = is_array($node) ? $node[0]->content : isset($node->body) ? $node->body['und'][0]['value'] : $node->content;
    $content = count((array) $nodes) == 1 ? $content : substr(drupal_html_to_text($content), 0, 170);
    if ($i < 3) {
        print '<table border="0" cellpadding="3" class="boxNews">';
    } else {
        if ($i < 5) {
            $style = $i % 2 != 0 ? 'float:left' : 'float:right';
            print '<table border="0" style="' . $style . ';" cellpadding="3" class="boxNews">';
        } elseif ($i >= 5) {
            $others[$i][] = $node->nid;
            $others[$i][] = $node->title;
            $others[$i][] = $content;
        }
    }
    if ($i < 5) {
        print '       <tr>';
        print $i < 3 ? '<td colspan="2">' : '<td colspan="3" valign="top">';
Exemplo n.º 10
0
/**
 * Prepare a message based on parameters; called from drupal_mail().
 *
 * Note that hook_mail(), unlike hook_mail_alter(), is only called on the
 * $module argument to drupal_mail(), not all modules.
 *
 * @param $key
 *   An identifier of the mail.
 * @param $message
 *   An array to be filled in. Elements in this array include:
 *   - id: An ID to identify the mail sent. Look at module source code
 *     or drupal_mail() for possible id values.
 *   - to: The address or addresses the message will be sent to. The
 *     formatting of this string must comply with RFC 2822.
 *   - subject: Subject of the email to be sent. This must not contain any
 *     newline characters, or the mail may not be sent properly. drupal_mail()
 *     sets this to an empty string when the hook is invoked.
 *   - body: An array of lines containing the message to be sent. Drupal will
 *     format the correct line endings for you. drupal_mail() sets this to an
 *     empty array when the hook is invoked.
 *   - from: The address the message will be marked as being from, which is
 *     set by drupal_mail() to either a custom address or the site-wide
 *     default email address when the hook is invoked.
 *   - headers: Associative array containing mail headers, such as From,
 *     Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills
 *     several headers in this array.
 * @param $params
 *   An array of parameters supplied by the caller of drupal_mail().
 */
function hook_mail($key, &$message, $params)
{
    $account = $params['account'];
    $context = $params['context'];
    $variables = array('%site_name' => \Drupal::config('system.site')->get('name'), '%username' => user_format_name($account));
    if ($context['hook'] == 'taxonomy') {
        $entity = $params['entity'];
        $vocabulary = entity_load('taxonomy_vocabulary', $entity->id());
        $variables += array('%term_name' => $entity->name, '%term_description' => $entity->description, '%term_id' => $entity->id(), '%vocabulary_name' => $vocabulary->name, '%vocabulary_description' => $vocabulary->description, '%vocabulary_id' => $vocabulary->id());
    }
    // Node-based variable translation is only available if we have a node.
    if (isset($params['node'])) {
        /** @var \Drupal\node\NodeInterface $node */
        $node = $params['node'];
        $variables += array('%uid' => $node->getOwnerId(), '%url' => url('node/' . $node->id(), array('absolute' => TRUE)), '%node_type' => node_get_type_label($node), '%title' => $node->getTitle(), '%teaser' => $node->teaser, '%body' => $node->body);
    }
    $subject = strtr($context['subject'], $variables);
    $body = strtr($context['message'], $variables);
    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
    $message['body'][] = drupal_html_to_text($body);
}
 if ($wikiTitleLength > 75) {
     $wikiTitle = substr($wikiTitle, 0, 75) . "...";
 } else {
     $wikiTitle = $wikiTitle;
 }
 $node_title = '<a href="/node/' . $results->nid . '">' . $wikiTitle . '</a>';
 $node_title = trim($node_title);
 if (!empty($node_title)) {
     $exploded_title = explode(">", $node_title);
     if (isset($exploded_title)) {
         $node_nid_cuwa_array = explode('/', $exploded_title[0]);
         if (isset($node_nid_cuwa_array[2])) {
             $node_nid_cuwa_value = substr($node_nid_cuwa_array[2], 0, -1);
         }
         if (!empty($exploded_title[1])) {
             $node_title_cuwa = drupal_html_to_text($exploded_title[1], $allowed_tags = NULL);
         }
         $node_title_cuwa = rawurlencode(rawurldecode($node_title_cuwa));
     }
     ?>
     <?php 
     //cuwa page
     $im_cuwa_x1 = '';
     $im_cuwa_x2 = '';
     $im_cuwa_x3 = '';
     if (isset($_SESSION['ldap_user_role'])) {
         if ($_SESSION['ldap_user_role'] == 'store_director') {
             $im_cuwa_x1 = 1;
             $im_cuwa_x2 = 1;
         }
         if ($_SESSION['ldap_user_role'] == 'store_manager') {
Exemplo n.º 12
0
 /**
  * Generates a summary up to ${char_count} characters in length.
  * 
  * @access public
  * @param int $char_count
  * @return string
  */
 public function get_summary($char_count)
 {
     if ($this->body) {
         return drupal_html_to_text(text_summary($this->body, NULL, $char_count), array('p'));
     }
 }
 /**
  * Tests that drupal_html_to_text() wraps before 1000 characters.
  *
  * RFC 3676 says, "The Text/Plain media type is the lowest common
  * denominator of Internet email, with lines of no more than 998 characters."
  *
  * RFC 2046 says, "SMTP [RFC-821] allows a maximum of 998 octets before the
  * next CRLF sequence."
  *
  * RFC 821 says, "The maximum total length of a text line including the
  * <CRLF> is 1000 characters."
  */
 public function testVeryLongLineWrap()
 {
     $input = 'Drupal<br /><p>' . str_repeat('x', 2100) . '</><br />Drupal';
     $output = drupal_html_to_text($input);
     $eol = Settings::get('mail_line_endings', PHP_EOL);
     $maximum_line_length = 0;
     foreach (explode($eol, $output) as $line) {
         // We must use strlen() rather than drupal_strlen() in order to count
         // octets rather than characters.
         $maximum_line_length = max($maximum_line_length, strlen($line . $eol));
     }
     $verbose = 'Maximum line length found was ' . $maximum_line_length . ' octets.';
     // @todo This should assert that $maximum_line_length <= 1000.
     $this->pass($verbose);
 }
 /**
  * Return the summary or the trimmed body.
  */
 private function rssSummaryOrTrimmed($body, $summary)
 {
     if (!empty($summary)) {
         return drupal_html_to_text($summary);
     }
     return text_summary($body, 'plain_text');
 }