/**
  * {@inheritdoc}
  */
 public function format(array $message)
 {
     if (is_array($message['body'])) {
         $message['body'] = implode("\n\n", $message['body']);
     }
     if (preg_match('/plain/', $message['headers']['Content-Type'])) {
         if (!($format = \Drupal::config('mimemail.settings')->get('format'))) {
             $format = filter_fallback_format();
         }
         $message['body'] = check_markup($message['body'], $format);
     }
     /*$engine = variable_get('mimemail_engine', 'mimemail');
         //$mailengine = $engine . '_mailengine';
         $engine_prepare_message = $engine . '_prepare_message';
     
         if (function_exists($engine_prepare_message)) {
           $message = $engine_prepare_message($message);
         }
         else {
           $message = mimemail_prepare_message($message);
         }*/
     // @TODO set mimemail_engine. For the moment let's prepare the message.
     $message = $this->prepareMessage($message);
     return $message;
 }
Ejemplo n.º 2
0
 /**
  * Tests that security filters are enforced even when marked to be skipped.
  */
 function testSkipSecurityFilters()
 {
     $text = "Text with some disallowed tags: <script />, <p><object>unicorn</object></p>, <i><table></i>.";
     $expected_filtered_text = "Text with some disallowed tags: , <p>unicorn</p>, .";
     $this->assertEqual(check_markup($text, 'filtered_html', '', array()), $expected_filtered_text, 'Expected filter result.');
     $this->assertEqual(check_markup($text, 'filtered_html', '', array(FilterInterface::TYPE_HTML_RESTRICTOR)), $expected_filtered_text, 'Expected filter result, even when trying to disable filters of the FilterInterface::TYPE_HTML_RESTRICTOR type.');
 }
/**
 * Add link to view full-sized image in colorbox and add caption
 */
function gettysw_preprocess_field(&$vars, $hook)
{
    foreach ($vars['element']['#items'] as $delta => $item) {
        if (!empty($vars['element'][$delta])) {
            if (module_exists('image_field_caption') && isset($item['image_field_caption'])) {
                $vars['items'][$delta]['caption'] = check_markup($item['image_field_caption']['value'], $item['image_field_caption']['format']);
            }
            if ($vars['element']['#field_name'] == 'field_image' && isset($item['uri']) && module_exists('colorbox') && empty($vars['element']['#object']->is_export)) {
                $vars['items'][$delta]['colorbox_link'] = '<a class="colorbox" href="' . file_create_url($item['uri']) . '">Expand Image</a>';
            }
            if ($vars['element']['#field_name'] == 'field_image_reference_info' && $vars['element']['#view_mode'] == 'full') {
                drupal_add_css(drupal_get_path('module', 'lighttable') . '/lighttable.css');
                $vars['content_attributes_array'] = array('id' => 'lighttable');
                foreach ($vars['items'] as $delta => $item) {
                    $fc_item = reset($vars['items'][$delta]['entity']['field_collection_item']);
                    $image_entity = $fc_item['#entity']->field_image_reference[LANGUAGE_NONE][0]['entity'];
                    $file_nodes = file_usage_list($image_entity);
                    $image_node = node_load(key($file_nodes['file']['node']));
                    $vars['items'][$delta]['entity']['field_collection_item']['title'] = array('#markup' => '<span class="field-title">' . $image_node->title . '</span>', '#weight' => -1);
                    $left = $fc_item['#entity']->field_x_pos[LANGUAGE_NONE][0]['value'];
                    $top = $fc_item['#entity']->field_y_pos[LANGUAGE_NONE][0]['value'];
                    $width = $fc_item['#entity']->field_width[LANGUAGE_NONE][0]['value'];
                    $height = $fc_item['#entity']->field_height[LANGUAGE_NONE][0]['value'];
                    $vars['items'][$delta]['#attributes']['style'] = "position: absolute; top: {$top}px; left: {$left}px; width: {$width}px; height: {$height}px;";
                    $vars['items'][$delta]['#attributes']['class'][] = 'lighttable-image-container';
                }
            }
        }
    }
}
Ejemplo n.º 4
0
/**
 * Process variables to format email messages.
 *
 * @see htmlmail.tpl.php
 */
function bollaert_preprocess_htmlmail(&$variables)
{
    // Run the default preprocess function.
    template_preprocess_htmlmail($variables);
    // Use the 'HTML Email' text format for the message body.
    $variables['body'] = check_markup($variables['body'], 'html_email');
}
Ejemplo n.º 5
0
function commons_origins_preprocess_page(&$variables)
{
    $variables['pre_header_top'] = theme('grid_row', $variables['header_top'], 'header-top', 'full-width', $variables['grid_width']);
    $variables['pre_secondary_links'] = theme('grid_block', theme('links', $variables['secondary_links']), 'secondary-menu');
    $variables['pre_search_box'] = theme('grid_block', $variables['search_box'], 'search-box');
    $variables['pre_primary_links_tree'] = theme('grid_block', $variables['primary_links_tree'], 'primary-menu');
    $variables['pre_breadcrumb'] = theme('grid_block', $variables['breadcrumb'], 'breadcrumbs');
    $variables['pre_preface_top'] = theme('grid_row', $variables['preface_top'], 'preface-top', 'full-width', $variables['grid_width']);
    $variables['pre_sidebar_first'] = theme('grid_row', $variables['sidebar_first'], 'sidebar-first', 'nested', $variables['sidebar_first_width']);
    $variables['pre_preface_bottom'] = theme('grid_row', $variables['preface_bottom'], 'preface-bottom', 'nested');
    $variables['pre_help'] = theme('grid_block', $variables['help'], 'content-help');
    $variables['pre_messages'] = theme('grid_block', $variables['messages'], 'content-messages');
    $variables['pre_tabs'] = theme('grid_block', $variables['tabs'], 'content-tabs');
    $variables['pre_content_bottom'] = theme('grid_row', $variables['content_bottom'], 'content-bottom', 'nested');
    $variables['pre_sidebar_last'] = theme('grid_row', $variables['sidebar_last'], 'sidebar-last', 'nested', $variables['sidebar_last_width']);
    $variables['pre_postscript_top'] = theme('grid_row', $variables['postscript_top'], 'postscript-top', 'nested');
    $variables['pre_postscript_bottom'] = theme('grid_row', $variables['postscript_bottom'], 'postscript-bottom', 'full-width', $variables['grid_width']);
    $variables['pre_footer'] = theme('grid_row', $variables['footer'] . $variables['footer_message'], 'footer', 'full-width', $variables['grid_width']);
    //show group description if group node present
    if (isset($variables['node'])) {
        $node = $variables['node'];
        if (og_is_group_type($node->type)) {
            $variables['group_header_image'] = content_format('field_group_image', $node->field_group_image[0], 'user_picture_meta_default');
            if (!empty($node->body)) {
                $variables['group_header_text'] = check_markup($node->body, $node->format);
            } else {
                $variables['group_header_text'] = check_plain($node->og_description);
            }
        }
    }
}
Ejemplo n.º 6
0
/**
 * HOOK_builder_content_view()
 */
function HOOK_builder_content_view($delta = '', $content = array())
{
    $content = '';
    switch ($delta) {
        case 'node':
            $node_content = '';
            if (!empty($content['settings']['nid'])) {
                $nid = $content['settings']['nid'];
                if ($node = node_load($nid)) {
                    if (isset($content['settings']['hide_node_title']) && $content['settings']['hide_node_title']) {
                        // hide node title.
                        $node->title = FALSE;
                    }
                    $node_view = node_view($node, $content['settings']['view_mode']);
                    $node_content = render($node_view);
                }
            }
            $content['content'] = $node_content;
            break;
        case 'custom_text':
            $custom_text_value = isset($content['settings']['custom_text']['value']) ? $content['settings']['custom_text']['value'] : '';
            if (isset($content['settings']['custom_text']['format'])) {
                $custom_text_value = check_markup($custom_text_value, $content['settings']['custom_text']['format']);
            }
            $content['content'] = $custom_text_value;
            break;
            return $content;
    }
}
Ejemplo n.º 7
0
/**
 * Implements template_preprocess_page().
 */
function asf_preprocess_page(&$variables)
{
    // Add copyright to theme.
    if ($copyright = theme_get_setting('copyright')) {
        $variables['copyright'] = check_markup($copyright['value'], $copyright['format']);
    }
}
Ejemplo n.º 8
0
 /**
  * Test the video ouput.
  *
  * @dataProvider videoFilterTestCases
  */
 public function testVideoFilter($content, $expected)
 {
     if ($expected === FALSE) {
         $expected = $content;
     }
     $filtered_markup = $this->stripWhitespace(check_markup($content, 'test_format'));
     $this->assertEquals($expected, $filtered_markup);
 }
Ejemplo n.º 9
0
 function testPathologic()
 {
     global $script_path;
     // Start by testing our function to build protocol-relative URLs
     $this->assertEqual(_pathologic_url_to_protocol_relative('http://example.com/foo/bar'), '//example.com/foo/bar', t('Protocol-relative URL creation with http:// URL'));
     $this->assertEqual(_pathologic_url_to_protocol_relative('https://example.org/baz'), '//example.org/baz', t('Protocol-relative URL creation with https:// URL'));
     // Build some paths to check against
     $test_paths = array('foo' => array('path' => 'foo', 'opts' => array()), 'foo/bar' => array('path' => 'foo/bar', 'opts' => array()), 'foo/bar?baz' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => NULL))), 'foo/bar?baz=qux' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => 'qux'))), 'foo/bar#baz' => array('path' => 'foo/bar', 'opts' => array('fragment' => 'baz')), 'foo/bar?baz=qux&amp;quux=quuux#quuuux' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => 'qux', 'quux' => 'quuux'), 'fragment' => 'quuuux')), 'foo%20bar?baz=qux%26quux' => array('path' => 'foo bar', 'opts' => array('query' => array('baz' => 'qux&quux'))), '/' => array('path' => '<front>', 'opts' => array()));
     foreach (array('full', 'proto-rel', 'path') as $protocol_style) {
         $format_id = _pathologic_build_format(['settings_source' => 'local', 'local_settings' => ['protocol_style' => $protocol_style]]);
         $paths = array();
         foreach ($test_paths as $path => $args) {
             $args['opts']['absolute'] = $protocol_style !== 'path';
             $paths[$path] = _pathologic_content_url($args['path'], $args['opts']);
             if ($protocol_style === 'proto-rel') {
                 $paths[$path] = _pathologic_url_to_protocol_relative($paths[$path]);
             }
         }
         $t10ns = array('@clean' => empty($script_path) ? t('Yes') : t('No'), '@ps' => $protocol_style);
         $this->assertEqual(check_markup('<a href="foo"><img src="foo/bar" /></a>', $format_id), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar'] . '" /></a>', t('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="index.php?q=foo"></a><a href="index.php?q=foo/bar&baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="index.php/foo"></a><a href="index.php/foo/bar?baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<form action="foo/bar?baz"><IMG LONGDESC="foo/bar?baz=qux" /></a>', $format_id), '<form action="' . $paths['foo/bar?baz'] . '"><IMG LONGDESC="' . $paths['foo/bar?baz=qux'] . '" /></a>', t('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo/bar#baz">', $format_id), '<a href="' . $paths['foo/bar#baz'] . '">', t('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="#foo">', $format_id), '<a href="#foo">', t('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         // @see https://drupal.org/node/2208223
         $this->assertEqual(check_markup('<a href="#">', $format_id), '<a href="#">', t('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo/bar?baz=qux&amp;quux=quuux#quuuux">', $format_id), '<a href="' . $paths['foo/bar?baz=qux&amp;quux=quuux#quuuux'] . '">', t('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo%20bar?baz=qux%26quux">', $format_id), '<a href="' . $paths['foo%20bar?baz=qux%26quux'] . '">', t('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="/"></a>', $format_id), '<a href="' . $paths['/'] . '"></a>', t('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns));
     }
     global $base_path;
     $this->assertEqual(check_markup('<a href="' . $base_path . 'foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => FALSE)) . '">bar</a>', t('Paths beginning with $base_path (like WYSIWYG editors like to make)'));
     global $base_url;
     $this->assertEqual(check_markup('<a href="' . $base_url . '/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => FALSE)) . '">bar</a>', t('Paths beginning with $base_url'));
     // @see http://drupal.org/node/1617944
     $this->assertEqual(check_markup('<a href="//example.com/foo">bar</a>', $format_id), '<a href="//example.com/foo">bar</a>', t('Off-site schemeless URLs (//example.com/foo) ignored'));
     // Test internal: and all base paths
     $format_id = _pathologic_build_format(['settings_source' => 'local', 'local_settings' => ['local_paths' => "http://example.com/qux\nhttp://example.org\n/bananas", 'protocol_style' => 'full']]);
     // @see https://drupal.org/node/2030789
     $this->assertEqual(check_markup('<a href="//example.org/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '">bar</a>', t('On-site schemeless URLs processed'));
     $this->assertEqual(check_markup('<a href="internal:foo">', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '">', t('Path Filter compatibility (internal:)'));
     $this->assertEqual(check_markup('<a href="files:image.jpeg">look</a>', $format_id), '<a href="' . _pathologic_content_url(file_create_url(file_default_scheme() . '://image.jpeg'), array('absolute' => TRUE)) . '">look</a>', t('Path Filter compatibility (files:)'));
     $this->assertEqual(check_markup('<a href="http://example.com/qux/foo"><img src="http://example.org/bar.jpeg" longdesc="/bananas/baz" /></a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '"><img src="' . _pathologic_content_url('bar.jpeg', array('absolute' => TRUE)) . '" longdesc="' . _pathologic_content_url('baz', array('absolute' => TRUE)) . '" /></a>', t('"All base paths for this site" functionality'));
     $this->assertEqual(check_markup('<a href="webcal:foo">bar</a>', $format_id), '<a href="webcal:foo">bar</a>', t('URLs with likely protocols are ignored'));
     // Test hook_pathologic_alter() implementation.
     $this->assertEqual(check_markup('<a href="foo?test=add_foo_qpart">', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE, 'query' => array('test' => 'add_foo_qpart', 'foo' => 'bar'))) . '">', t('hook_pathologic_alter(): Alter $url_params'));
     $this->assertEqual(check_markup('<a href="bar?test=use_original">', $format_id), '<a href="bar?test=use_original">', t('hook_pathologic_alter(): Passthrough with use_original option'));
     // Test paths to existing files when clean URLs are disabled.
     // @see http://drupal.org/node/1672430
     $script_path = '';
     $filtered_tag = check_markup('<img src="misc/druplicon.png" />', $format_id);
     $this->assertTrue(strpos($filtered_tag, 'q=') === FALSE, t('Paths to files don\'t have ?q= when clean URLs are off'));
     $format_id = _pathologic_build_format(['settings_source' => 'global', 'local_settings' => ['protocol_style' => 'rel']]);
     $this->config('pathologic.settings')->set('protocol_style', 'proto-rel')->set('local_paths', 'http://example.com/')->save();
     $this->assertEqual(check_markup('<img src="http://example.com/foo.jpeg" />', $format_id), '<img src="' . _pathologic_url_to_protocol_relative(_pathologic_content_url('foo.jpeg', array('absolute' => TRUE))) . '" />', t('Use global settings when so configured on the format'));
 }
Ejemplo n.º 10
0
function pirateparty_preprocess_node(&$vars, $hook)
{
    $account = user_load($vars['uid']);
    $vars['user_signature'] = '';
    if (isset($account->signature, $account->signature_format)) {
        $vars['user_signature'] = check_markup($account->signature, $account->signature_format);
        $vars['submitted'] = t('Written by !username on !datetime', array('!username' => $vars['name'], '!datetime' => $vars['date']));
    }
}
Ejemplo n.º 11
0
 /**
  * Returns an Ajax response to render a text field without transformation filters.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity of which a formatted text field is being rerendered.
  * @param string $field_name
  *   The name of the (formatted text) field that that is being rerendered
  * @param string $langcode
  *   The name of the language for which the formatted text field is being
  *   rerendered.
  * @param string $view_mode_id
  *   The view mode the formatted text field should be rerendered in.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   The Ajax response.
  */
 public function getUntransformedText(EntityInterface $entity, $field_name, $langcode, $view_mode_id)
 {
     $response = new AjaxResponse();
     // Direct text editing is only supported for single-valued fields.
     $field = $entity->getTranslation($langcode)->{$field_name};
     $editable_text = check_markup($field->value, $field->format, $langcode, array(FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE));
     $response->addCommand(new GetUntransformedTextCommand($editable_text));
     return $response;
 }
Ejemplo n.º 12
0
 /**
  * Tests text without format.
  *
  * Tests if text with no format is filtered the same way as text in the
  * fallback format.
  */
 function testCheckMarkupNoFormat()
 {
     // Create some text. Include some HTML and line breaks, so we get a good
     // test of the filtering that is applied to it.
     $text = "<strong>" . $this->randomMachineName(32) . "</strong>\n\n<div>" . $this->randomMachineName(32) . "</div>";
     // Make sure that when this text is run through check_markup() with no text
     // format, it is filtered as though it is in the fallback format.
     $this->assertEqual(check_markup($text), check_markup($text, filter_fallback_format()), 'Text with no format is filtered the same as text in the fallback format.');
 }
Ejemplo n.º 13
0
/**
 * Implements hook_preprocess_flexslider().
 */
function smc_base_preprocess_flexslider(&$variables)
{
    if (!empty($variables['items'])) {
        foreach ($variables['items'] as $index => &$item) {
            if (!empty($item['item']['image_field_caption'])) {
                $item['caption'] = check_markup($item['item']['image_field_caption']['value'], $item['item']['image_field_caption']['format']);
            }
        }
    }
}
Ejemplo n.º 14
0
/**
 * Implements template_preprocess_page().
 */
function nbadraft_preprocess_page(&$variables)
{
    // Add copyright to theme.
    if ($copyright = theme_get_setting('copyright')) {
        $variables['copyright'] = check_markup($copyright['value'], $copyright['format']);
    }
    if (drupal_is_front_page()) {
        $variables['main_form'] = drupal_render(drupal_get_form('nbadraft_main_form'));
    }
}
 /**
  * Converts a template into rendered content.
  *
  * @param array $template
  *   Array of template sections.
  *
  * @return array
  *   Array of template content indexed by section ID.
  */
 private function renderTemplate($template)
 {
     $content = array();
     foreach ($template as $key => $part) {
         if (isset($part['format'])) {
             $content[$key] = check_markup($part['value'], $part['format']);
         }
     }
     return $content;
 }
Ejemplo n.º 16
0
 /**
  * Returns an Ajax response to generate preview of embedded items.
  *
  * Expects the the HTML element as GET parameter.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\filter\FilterFormatInterface $filter_format
  *   The filter format.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Throws an exception if 'value' parameter is not found in the request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   The preview of the embedded item specified by the data attributes.
  */
 public function preview(Request $request, FilterFormatInterface $filter_format)
 {
     $text = $request->get('value');
     if ($text == '') {
         throw new NotFoundHttpException();
     }
     $output = check_markup($text, $filter_format->id());
     $response = new AjaxResponse();
     $response->addCommand(new EmbedInsertCommand($output));
     return $response;
 }
Ejemplo n.º 17
0
/**
 * Preprocess variables for page template.
 */
function sunshine_preprocess_page(&$variables)
{
    /**
     * insert variables into page template.
     */
    $variables['no_panels'] = False;
    $variables['always_show_page_title'] = True;
    // Add copyright to theme.
    if ($copyright = theme_get_setting('copyright')) {
        $variables['copyright'] = check_markup($copyright['value'], $copyright['format']);
    }
}
Ejemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     if (is_array($this->format)) {
         $format = $this->getValue($values, 'format');
     } else {
         $format = $this->format;
     }
     if ($value) {
         $value = str_replace('<!--break-->', '', $value);
         return check_markup($value, $format);
     }
 }
/**
 * Add link to view full-sized image in colorbox and add caption
 */
function gettysw_preprocess_field(&$vars, $hook)
{
    foreach ($vars['element']['#items'] as $delta => $item) {
        if (!empty($vars['element'][$delta])) {
            if (module_exists('image_field_caption') && isset($item['image_field_caption'])) {
                $vars['items'][$delta]['caption'] = check_markup($item['image_field_caption']['value'], $item['image_field_caption']['format']);
            }
            if ($vars['element']['#field_name'] == 'field_image' && isset($item['uri']) && module_exists('colorbox')) {
                $vars['items'][$delta]['colorbox_link'] = '<a class="colorbox" href="' . file_create_url($item['uri']) . '">View full-size image</a>';
            }
        }
    }
}
Ejemplo n.º 20
0
/**
 * Implements template_preprocess_page().
 */
function radix_stanley_preprocess_page(&$variables)
{
    // Format and add main menu to theme.
    $variables['main_menu'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
    $variables['main_menu']['#theme_wrappers'] = array('menu_tree__navbar_right');
    // Add copyright to theme.
    if ($copyright = theme_get_setting('copyright')) {
        $variables['copyright'] = check_markup($copyright['value'], $copyright['format']);
    }
    // Use a different template per content type.
    if (isset($variables['node'])) {
        $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
    }
}
Ejemplo n.º 21
0
/**
 * Example of how to implement _tableofcontents_process_text
 * In this example, this function would be a menu callback.
 */
function youexamplemodule_page()
{
    // TOC will be added to the top of the text area
    $text = '[toc]';
    // generate text some how, from a node or manually
    $text .= 'some text of some kind';
    // format is the input format that has TOC enabled
    $format = 'full_html';
    // check the markup of the format
    $output = check_markup($text, $format);
    // process the text of the page to add a TOC
    _tableofcontents_process_text($output);
    // return / print / do what you want with the output
    return $output;
}
Ejemplo n.º 22
0
 /**
  * Implements \Drupal\Core\TypedData\TypedDataInterface::getValue().
  */
 public function getValue()
 {
     if ($this->processed !== NULL) {
         return $this->processed;
     }
     $item = $this->getParent();
     $text = $item->{$this->definition->getSetting('text source')};
     // Avoid running check_markup() on empty strings.
     if (!isset($text) || $text === '') {
         $this->processed = '';
     } else {
         $this->processed = check_markup($text, $item->format, $item->getLangcode());
     }
     return $this->processed;
 }
 /**
  * Test that a user can change their signature format and that it is respected
  * upon display.
  */
 function testUserSignature()
 {
     $node = $this->drupalCreateNode(array('body' => array(0 => array('value' => $this->randomMachineName(32), 'format' => 'full_html'))));
     // Verify that user signature field is not displayed on registration form.
     $this->drupalGet('user/register');
     $this->assertNoText(t('Signature'));
     // Log in as a regular user and create a signature.
     $this->drupalLogin($this->web_user);
     $signature_text = "<h1>" . $this->randomMachineName() . "</h1>";
     $edit = array('signature[value]' => $signature_text);
     $this->drupalPostForm('user/' . $this->web_user->id() . '/edit', $edit, t('Save'));
     // Verify that values were stored.
     $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
     // Verify that the user signature's text format's cache tag is absent.
     $this->drupalGet('node/' . $node->id());
     $this->assertTrue(!in_array('filter_format:filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));
     // Create a comment.
     $edit = array();
     $edit['subject[0][value]'] = $this->randomMachineName(8);
     $edit['comment_body[0][value]'] = $this->randomMachineName(16);
     $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Preview'));
     $this->drupalPostForm(NULL, array(), t('Save'));
     // Get the comment ID. (This technique is the same one used in the Comment
     // module's CommentTestBase test case.)
     preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
     $comment_id = $match[1];
     // Log in as an administrator and edit the comment to use Full HTML, so
     // that the comment text itself is not filtered at all.
     $this->drupalLogin($this->admin_user);
     $edit['comment_body[0][format]'] = $this->full_html_format->format;
     $this->drupalPostForm('comment/' . $comment_id . '/edit', $edit, t('Save'));
     // Assert that the signature did not make it through unfiltered.
     $this->drupalGet('node/' . $node->id());
     $this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
     $this->assertRaw(check_markup($signature_text, $this->filtered_html_format->format), 'Filtered signature text found.');
     // Verify that the user signature's text format's cache tag is present.
     $this->drupalGet('node/' . $node->id());
     $this->assertTrue(in_array('filter_format:filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));
     // Verify the signature field is available on Manage form display page.
     \Drupal::config('user.settings')->set('signatures', 0)->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $this->drupalGet('admin/config/people/accounts/form-display');
     $this->assertNoText('Signature settings');
     $this->drupalPostForm('admin/config/people/accounts', array('user_signatures' => TRUE), t('Save configuration'));
     $this->drupalGet('admin/config/people/accounts/form-display');
     $this->assertText('Signature settings');
 }
Ejemplo n.º 24
0
 public function setNotices()
 {
     $query = "SELECT * FROM {node} n LEFT JOIN {content_field_issue_2q} f ON n.vid = f.vid \n       LEFT JOIN node_revisions r ON n.vid = r.vid \n       LEFT JOIN content_type_chgk_issue node_data_field_reporter ON n.vid = node_data_field_reporter.vid \n        WHERE (n.type ='chgk_issue') AND (f.field_issue_2q_value = 1 ) \n        AND (n.status = 1) AND (n.title = '" . $this->getTextId() . "')";
     $res = db_query($query);
     $notices = $this->db->getQuestionNotices($this->getTextId());
     $texts = array();
     foreach ($notices as $n) {
         if ($n->status == 'accepted') {
             $this->incorrect = TRUE;
         }
         $b = trim($n->body) . " (" . $n->reporter . ")";
         $texts[] = check_markup($b, $n->format);
     }
     $this->question->Notices .= implode("<hr/>", $texts);
     #     print_r($notices);
     #    $this->quesiton->notices=$this->getIssues('question_issues_plain');
 }
Ejemplo n.º 25
0
 /**
  * Tests the ability to apply only a subset of filters.
  */
 function testCheckMarkupFilterSubset()
 {
     $text = "Text with <marquee>evil content and</marquee> a URL: https://www.drupal.org!";
     $expected_filtered_text = "Text with evil content and a URL: <a href=\"https://www.drupal.org\">https://www.drupal.org</a>!";
     $expected_filter_text_without_html_generators = "Text with evil content and a URL: https://www.drupal.org!";
     $actual_filtered_text = check_markup($text, 'filtered_html', '', array());
     $this->verbose("Actual:<pre>{$actual_filtered_text}</pre>Expected:<pre>{$expected_filtered_text}</pre>");
     $this->assertIdentical($actual_filtered_text, $expected_filtered_text, 'Expected filter result.');
     $actual_filtered_text_without_html_generators = check_markup($text, 'filtered_html', '', array(FilterInterface::TYPE_MARKUP_LANGUAGE));
     $this->verbose("Actual:<pre>{$actual_filtered_text_without_html_generators}</pre>Expected:<pre>{$expected_filter_text_without_html_generators}</pre>");
     $this->assertIdentical($actual_filtered_text_without_html_generators, $expected_filter_text_without_html_generators, 'Expected filter result when skipping FilterInterface::TYPE_MARKUP_LANGUAGE filters.');
     // Related to @see FilterSecurityTest.php/testSkipSecurityFilters(), but
     // this check focuses on the ability to filter multiple filter types at once.
     // Drupal core only ships with these two types of filters, so this is the
     // most extensive test possible.
     $actual_filtered_text_without_html_generators = check_markup($text, 'filtered_html', '', array(FilterInterface::TYPE_HTML_RESTRICTOR, FilterInterface::TYPE_MARKUP_LANGUAGE));
     $this->verbose("Actual:<pre>{$actual_filtered_text_without_html_generators}</pre>Expected:<pre>{$expected_filter_text_without_html_generators}</pre>");
     $this->assertIdentical($actual_filtered_text_without_html_generators, $expected_filter_text_without_html_generators, 'Expected filter result when skipping FilterInterface::TYPE_MARKUP_LANGUAGE filters, even when trying to disable filters of the FilterInterface::TYPE_HTML_RESTRICTOR type.');
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $config = \Drupal::config('twitter_pull.twittersettings_config');
     $settings = array();
     $settings['oauth_access_token'] = $config->get('oauth_access_token');
     $settings['oauth_access_token_secret'] = $config->get('oauth_access_token_secret');
     $settings['consumer_key'] = $config->get('consumer_key');
     $settings['consumer_secret'] = $config->get('consumer_secret');
     $screen_name = $config->get('screen_name');
     $tweet_count = $config->get('tweet_count');
     $twitter = new TwitterOAuth($settings['consumer_key'], $settings['consumer_secret'], $settings['oauth_access_token'], $settings['oauth_access_token_secret']);
     $tweets = $twitter->get("statuses/user_timeline", array("screen_name" => $screen_name, "count" => $tweet_count));
     foreach ($tweets as $tweet) {
         $tweet->text = check_markup($tweet->text, 'full_html');
         $cleanTweets[] = $tweet;
     }
     $params = array('tweets' => $cleanTweets);
     $tweet_template = array('#theme' => 'twitter_pull_tweet_listing', '#params' => $params);
     return $tweet_template;
 }
Ejemplo n.º 27
0
 /**
  * Implements \Drupal\Core\TypedData\TypedDataInterface::getValue().
  */
 public function getValue($langcode = NULL)
 {
     if ($this->processed !== NULL) {
         return $this->processed;
     }
     $item = $this->getParent();
     $text = $item->{$this->definition->getSetting('text source')};
     // Avoid running check_markup() or
     // \Drupal\Component\Utility\String::checkPlain() on empty strings.
     if (!isset($text) || $text === '') {
         $this->processed = '';
     } elseif ($item->getFieldDefinition()->getSetting('text_processing')) {
         $this->processed = check_markup($text, $item->format, $item->getLangcode());
     } else {
         // Escape all HTML and retain newlines.
         // @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter
         $this->processed = SafeMarkup::set(nl2br(String::checkPlain($text)));
     }
     return $this->processed;
 }
Ejemplo n.º 28
0
/**
 * Implements template_preprocess_page().
 */
function locke_preprocess_page(&$variables, $hook)
{
    // Add copyright to theme.
    if ($copyright = theme_get_setting('copyright')) {
        $variables['copyright'] = check_markup($copyright['value'], $copyright['format']);
    }
    // Setup the search box functionality
    $search_box_form = drupal_get_form('search_form');
    $search_box_form['basic']['keys']['#title'] = '';
    $search_box_form['basic']['keys']['#attributes'] = array('placeholder' => 'Search');
    $search_box_form['basic']['submit']['#value'] = t('Go');
    $search_box = drupal_render($search_box_form);
    $variables['search_box'] = user_access('search content') ? $search_box : NULL;
    // Setup the contact information
    $variables['contact_information']['site_name'] = variable_get('site_name');
    $variables['contact_information']['address'] = _filter_autop(theme_get_setting('address'));
    $variables['contact_information']['phone'] = theme_get_setting('phone');
    $variables['contact_information']['fax'] = theme_get_setting('fax');
    // Setup the social links
    $social_links = array();
    if (module_exists('openacademy_news')) {
        $social_links[] = l('Read', 'rss.xml', array('attributes' => array('class' => 'rss-link')));
    }
    if ($twitter_link = theme_get_setting('twitter_link')) {
        $social_links[] = l('Follow', $twitter_link, array('attributes' => array('class' => 'twitter-link')));
    }
    if ($youtube_link = theme_get_setting('youtube_link')) {
        $social_links[] = l('Watch', $youtube_link, array('attributes' => array('class' => 'youtube-link')));
    }
    if ($facebook_link = theme_get_setting('facebook_link')) {
        $social_links[] = l('Friend', $facebook_link, array('attributes' => array('class' => 'facebook-link')));
    }
    $variables['social_links'] = theme('item_list', array('items' => $social_links));
    // Define the university seal
    if (theme_get_setting('seal_path') && !theme_get_setting('default_seal')) {
        $seal_path = theme_get_setting('seal_path');
        $variables['seal'] = file_create_url($seal_path);
    } else {
        $variables['seal'] = '/' . path_to_theme() . '/assets/images/seal.png';
    }
}
Ejemplo n.º 29
0
 public function testAreaText()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     // add a text header
     $string = $this->randomMachineName();
     $view->displayHandlers->get('default')->overrideOption('header', array('area' => array('id' => 'area', 'table' => 'views', 'field' => 'area', 'content' => $string)));
     // Execute the view.
     $this->executeView($view);
     $view->display_handler->handlers['header']['area']->options['format'] = $this->randomString();
     $build = $view->display_handler->handlers['header']['area']->render();
     $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.');
     $view->display_handler->handlers['header']['area']->options['format'] = filter_default_format();
     $build = $view->display_handler->handlers['header']['area']->render();
     $this->assertEqual(check_markup($string), drupal_render($build), 'Existent format should return something');
     // Empty results, and it shouldn't be displayed .
     $this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
     // Empty results, and it should be displayed.
     $view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
     $build = $view->display_handler->handlers['header']['area']->render(TRUE);
     $this->assertEqual(check_markup($string), drupal_render($build), 'No result, but empty enabled lead to a full header');
 }
Ejemplo n.º 30
0
/**
 * The node is being indexed.
 *
 * If you want additional information to be indexed which is not already
 * visible through node "view", then you should return it here.
 *
 * @param $node
 *   The node the action is being performed on.
 * @return
 *   Array of additional information to be indexed.
 */
function hook_node_update_index($node)
{
    $text = '';
    $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
    foreach ($comments as $comment) {
        $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format);
    }
    return $text;
}