X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fhtmlawed%2Fsrc%2FPlugin%2FFilter%2FFilterhtmlawed.php;h=3a35b72e4348ada67188ac733b5a109d96f400b7;hb=4f1b9b4ab48a8498afac9e2213a02a23ccf4a06c;hp=1542eb75502f694cfa5aee74f90d664740e6845f;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/modules/contrib/htmlawed/src/Plugin/Filter/Filterhtmlawed.php b/web/modules/contrib/htmlawed/src/Plugin/Filter/Filterhtmlawed.php index 1542eb755..3a35b72e4 100644 --- a/web/modules/contrib/htmlawed/src/Plugin/Filter/Filterhtmlawed.php +++ b/web/modules/contrib/htmlawed/src/Plugin/Filter/Filterhtmlawed.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides for use of htmLawed @@ -36,11 +37,13 @@ use Drupal\filter\Plugin\FilterBase; class Filterhtmlawed extends FilterBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ public function process($text, $langcode) { - + // Use htmLawed filter settings for the $config and $spec arguments to htmLawed(); // use default values if needed. $htmLawed_settings = $this->settings; @@ -51,13 +54,13 @@ class Filterhtmlawed extends FilterBase { if (!is_array($config)) { $config = array('safe'=>1, 'elements'=>'a, em, strong, cite, code, ol, ul, li, dl, dt, dd, br, p', 'deny_attribute'=>'id, style'); } - + // If PHP code blocks are to be preserved, hide the special characters // like '<' of '`sme', '`<\?php(.*)$`sme'), array("\"\x83?php\". str_replace(array('<', '>', '&'), array('<', '>', '&'), '$1'). \"?\x84\"", "\"\x83?php\". str_replace(array('<', '>', '&'), array('<', '>', '&'), '$1')"), $text); + $text = preg_replace_callback('`<\?php(.+?)\?>|<\?php(.*?)$`sm', function($m){return "\x83?php". str_replace(array('<', '>', '&'), array('<', '>', '&'), $m[1]). (substr($m[0], -2) == '?>' ? "?\84" : '');}, $text); } - + // If Libraries module (API 3.x) is enabled, use htmLawed library through it; // else use the htmLawed library provided with the htmLawed module. $module_path = drupal_get_path('module', 'htmlawed'); @@ -71,16 +74,16 @@ class Filterhtmlawed extends FilterBase { // htmLawed filtering. $text = htmLawed($text, $config, $htmLawed_settings['spec']); - + // In case Drupal's teaser-break is in use; // since htmLawed corrects HTML comments to use the right format. $text = str_replace('', '', $text); - + // Handle any PHP code preservation. if (!empty($config['save_php'])) { - $text = preg_replace(array('`\x83\?php(.+?)\?\x84`sme', '`\x83\?php(.*)$`sme'), array("''), '$1'). '?>'", "''), '$1')"), $text); + $text = preg_replace_callback('`\x83\?php(.+?)\?\x84|\x83\?php(.*?)$`sm', function($m){return "'), $m[1]). (substr($m[0], -2) == "?\x84" ? "?>" : '');}, $text); } - + // Return value. $result = new FilterProcessResult($text); return $result; @@ -92,7 +95,7 @@ class Filterhtmlawed extends FilterBase { public function settingsForm(array $form, FormStateInterface $form_state) { $htmLawed_settings = $this->settings; $form['config'] = array( - '#prefix' => t('Help', array(':url' => Url::fromUri('base:admin/help/htmlawed')->toString())), + '#prefix' => $this->t('Help', array(':url' => Url::fromUri('base:admin/help/htmlawed')->toString())), '#type' => 'textarea', '#rows' => '2', '#title' => $this->t('Config.'), @@ -125,11 +128,11 @@ class Filterhtmlawed extends FilterBase { /** * {@inheritdoc} - */ + */ public function tips($long = FALSE) { $htmLawed_settings = $this->settings; $help = !$long ? Html::escape($htmLawed_settings['help']) : Html::escape($htmLawed_settings['helplong']); - $help = !empty($help) ? $help : (!$long ? t('HTML markup is restricted/corrected with the htmLawed filter.') : t('HTML markup is restricted/corrected with the @htmLawed filter for compliance with admin. policy and standards and for security. More details about the restrictions in effect may be available elsewhere, such as in the text of the filter-tips of text formats that use htmLawed and on the forms for configuring text formats.', array('@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')))) . (!\Drupal::currentUser()->hasPermission('administer filters') ? '' : t(' For information on configuring the htmLawed filter, visit the htmLawed module @help section.', array('@help' => \Drupal::l(t('help'), Url::fromUri('base:admin/help/htmlawed')))))); + $help = !empty($help) ? $help : (!$long ? $this->t('HTML markup is restricted/corrected with the htmLawed filter.') : $this->t('HTML markup is restricted/corrected with the @htmLawed filter for compliance with admin. policy and standards and for security. More details about the restrictions in effect may be available elsewhere, such as in the text of the filter-tips of text formats that use htmLawed and on the forms for configuring text formats.', array('@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')))) . (!\Drupal::currentUser()->hasPermission('administer filters') ? '' : $this->t(' For information on configuring the htmLawed filter, visit the htmLawed module @help section.', array('@help' => \Drupal::l($this->t('help'), Url::fromUri('base:admin/help/htmlawed')))))); return $help; } }