1. ", * "filter_html_help" = 1, * "filter_html_nofollow" = 0 * }, * weight = -10 * ) */ class FilterHtml extends FilterBase { /** * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state) { $form['allowed_html'] = array( '#type' => 'textfield', '#title' => t('Allowed HTML tags'), '#default_value' => $this->settings['allowed_html'], '#maxlength' => 1024, '#description' => t('A list of HTML tags that can be used. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'), '#attached' => array( 'library' => array( array('filter', 'drupal.filter.filter_html.admin'), ), ), ); $form['filter_html_help'] = array( '#type' => 'checkbox', '#title' => t('Display basic HTML help in long filter tips'), '#default_value' => $this->settings['filter_html_help'], ); $form['filter_html_nofollow'] = array( '#type' => 'checkbox', '#title' => t('Add rel="nofollow" to all links'), '#default_value' => $this->settings['filter_html_nofollow'], ); return $form; } /** * {@inheritdoc} */ public function process($text, $langcode, $cache, $cache_id) { return _filter_html($text, $this); } /** * {@inheritdoc} */ public function tips($long = FALSE) { global $base_url; if (!($allowed_html = $this->settings['allowed_html'])) { return; } $output = t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)); if (!$long) { return $output; } $output = '

      ' . $output . '

      '; if (!$this->settings['filter_html_help']) { return $output; } $output .= '

      ' . t('This site allows HTML content. While learning all of HTML may feel intimidating, learning how to use a very small number of the most basic HTML "tags" is very easy. This table provides examples for each tag that is enabled on this site.') . '

      '; $output .= '

      ' . t('For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/html/')) . '

      '; $tips = array( 'a' => array(t('Anchors are used to make links to other pages.'), '' . check_plain(config('system.site')->get('name')) . ''), 'br' => array(t('By default line break tags are automatically added, so use this tag to add additional ones. Use of this tag is different because it is not used with an open/close pair like all the others. Use the extra " /" inside the tag to maintain XHTML 1.0 compatibility'), t('Text with
      line break')), 'p' => array(t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '

      ' . t('Paragraph one.') . '

      ' . t('Paragraph two.') . '

      '), 'strong' => array(t('Strong', array(), array('context' => 'Font weight')), '' . t('Strong', array(), array('context' => 'Font weight')) . ''), 'em' => array(t('Emphasized'), '' . t('Emphasized') . ''), 'cite' => array(t('Cited'), '' . t('Cited') . ''), 'code' => array(t('Coded text used to show programming source code'), '' . t('Coded') . ''), 'b' => array(t('Bolded'), '' . t('Bolded') . ''), 'u' => array(t('Underlined'), '' . t('Underlined') . ''), 'i' => array(t('Italicized'), '' . t('Italicized') . ''), 'sup' => array(t('Superscripted'), t('Superscripted')), 'sub' => array(t('Subscripted'), t('Subscripted')), 'pre' => array(t('Preformatted'), '
      ' . t('Preformatted') . '
      '), 'abbr' => array(t('Abbreviation'), t('Abbrev.')), 'acronym' => array(t('Acronym'), t('TLA')), 'blockquote' => array(t('Block quoted'), '
      ' . t('Block quoted') . '
      '), 'q' => array(t('Quoted inline'), '' . t('Quoted inline') . ''), // Assumes and describes tr, td, th. 'table' => array(t('Table'), '
      ' . t('Table header') . '
      ' . t('Table cell') . '
      '), 'tr' => NULL, 'td' => NULL, 'th' => NULL, 'del' => array(t('Deleted'), '' . t('Deleted') . ''), 'ins' => array(t('Inserted'), '' . t('Inserted') . ''), // Assumes and describes li. 'ol' => array(t('Ordered list - use the <li> to begin each list item'), '
      1. ' . t('First item') . '
      2. ' . t('Second item') . '
      '), 'ul' => array(t('Unordered list - use the <li> to begin each list item'), '
      • ' . t('First item') . '
      • ' . t('Second item') . '
      '), 'li' => NULL, // Assumes and describes dt and dd. 'dl' => array(t('Definition lists are similar to other HTML lists. <dl> begins the definition list, <dt> begins the definition term and <dd> begins the definition description.'), '
      ' . t('First term') . '
      ' . t('First definition') . '
      ' . t('Second term') . '
      ' . t('Second definition') . '
      '), 'dt' => NULL, 'dd' => NULL, 'h1' => array(t('Heading'), '

      ' . t('Title') . '

      '), 'h2' => array(t('Heading'), '

      ' . t('Subtitle') . '

      '), 'h3' => array(t('Heading'), '

      ' . t('Subtitle three') . '

      '), 'h4' => array(t('Heading'), '

      ' . t('Subtitle four') . '

      '), 'h5' => array(t('Heading'), '
      ' . t('Subtitle five') . '
      '), 'h6' => array(t('Heading'), '
      ' . t('Subtitle six') . '
      ') ); $header = array(t('Tag Description'), t('You Type'), t('You Get')); preg_match_all('/<([a-z0-9]+)[^a-z0-9]/i', $allowed_html, $out); foreach ($out[1] as $tag) { if (!empty($tips[$tag])) { $rows[] = array( array('data' => $tips[$tag][0], 'class' => array('description')), array('data' => '' . check_plain($tips[$tag][1]) . '', 'class' => array('type')), array('data' => $tips[$tag][1], 'class' => array('get')) ); } else { $rows[] = array( array('data' => t('No help provided for tag %tag.', array('%tag' => $tag)), 'class' => array('description'), 'colspan' => 3), ); } } $table = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, ); $output .= drupal_render($table); $output .= '

      ' . t('Most unusual characters can be directly entered without any problems.') . '

      '; $output .= '

      ' . t('If you do encounter problems, try using HTML character entities. A common example looks like &amp; for an ampersand & character. For a full list of entities see HTML\'s entities page. Some of the available characters include:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '

      '; $entities = array( array(t('Ampersand'), '&'), array(t('Greater than'), '>'), array(t('Less than'), '<'), array(t('Quotation mark'), '"'), ); $header = array(t('Character Description'), t('You Type'), t('You Get')); unset($rows); foreach ($entities as $entity) { $rows[] = array( array('data' => $entity[0], 'class' => array('description')), array('data' => '' . check_plain($entity[1]) . '', 'class' => array('type')), array('data' => $entity[1], 'class' => array('get')) ); } $table = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, ); $output .= drupal_render($table); return $output; } }