From 2858e3f98d04ccae746d30492d7b1931c6f2a0c6 Mon Sep 17 00:00:00 2001 From: Shawn Kwang Date: Wed, 27 Feb 2019 12:43:36 -0600 Subject: [PATCH 1/2] Drupal: Modified bbcode module to change email addresses. Added variable to rewrite email addresses. Addresses will appear as username-[at]-domain.tld. This option overrides the 'convert to link' and 'encode email address' options. https://dev.gridrepublic.org/browse/DBOINCP-487 --- .../boinc/modules/contrib/bbcode/bbcode-filter.inc | 14 ++++++++++---- .../boinc/modules/contrib/bbcode/bbcode.module | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode-filter.inc b/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode-filter.inc index 16992df8d7..0c1a5a1a8d 100644 --- a/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode-filter.inc +++ b/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode-filter.inc @@ -269,6 +269,11 @@ function _bbcode_filter_process(&$body, $format = -1) { $body); } + // Re-write email addresses + if (variable_get("bbcode_rewrite_email_$format", 1)) { + $body = preg_replace('#((?<=^|[\t\r\n >\(\[\]\|]))([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1\\2-[at]-\\3', $body); + } + // Turns web and e-mail addresses into clickable links if (variable_get("bbcode_make_links_$format", 1)) { @@ -290,10 +295,11 @@ function _bbcode_filter_process(&$body, $format = -1) { // matches an email@domain type address at the start of a line, or after a space. // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". - if (variable_get("bbcode_encode_mailto_$format", 1)) - $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); - else - $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1\\2@\\3', $ret); + if (variable_get("bbcode_encode_mailto_$format", 1)) { + $ret = preg_replace_callback("#((?<=^|[\t\r\n >\(\[\]\|]))([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); + } else { + $ret = preg_replace('#((?<=^|[\t\r\n >\(\[\]\|]))([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1\\2@\\3', $ret); + } // Remove our padding $ret = str_replace("\x07", '', $ret); diff --git a/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode.module b/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode.module index 6f5e76f902..42d54e39ba 100644 --- a/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode.module +++ b/drupal/sites/default/boinc/modules/contrib/bbcode/bbcode.module @@ -79,6 +79,13 @@ function bbcode_filter($op, $delta = 0, $format = -1, $text = '') { '#default_value' => variable_get("bbcode_encode_mailto_$format", 1), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Whether to encode email addresses with javascript. With this method you will have clickable mailto links, but it will be a bit harder for spam robots to collect them.')); + $form['bbcode_filter']["bbcode_rewrite_email_$format"] = array( + '#type' => 'select', + '#title' => t('Email address rewrite'), + '#default_value' => variable_get("bbcode_rewrite_email_$format", 1), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Whether to rewrite email addresses, replacing the "@" symbol with "-[at]-". This will be a bit harder for spam robots to collect them. If enabled, the "Convert addresses to links" option is ignored. And the "Email address encoding" is ignored.'), + ); $form['bbcode_filter']["bbcode_paragraph_breaks_$format"] = array( '#type' => 'select', '#title' => t('Smart paragraph and line breaks'), From 7e5d2287869d1e210b0152b9e3c41755a75524ad Mon Sep 17 00:00:00 2001 From: Shawn Kwang Date: Thu, 28 Feb 2019 14:28:39 -0600 Subject: [PATCH 2/2] Drupal: Modified boinc_standard Feature to include new bbcode parameter. Set defaults of bbcode parameters to rewrite email addresses, and not encode them. --- .../boinc_standard/boinc_standard.info | 2 ++ .../boinc_standard.input_formats.inc | 4 +++- .../boinc_standard.strongarm.inc | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drupal/sites/all/features/boinc_standard/boinc_standard.info b/drupal/sites/all/features/boinc_standard/boinc_standard.info index d5776409ed..b4c33314ba 100644 --- a/drupal/sites/all/features/boinc_standard/boinc_standard.info +++ b/drupal/sites/all/features/boinc_standard/boinc_standard.info @@ -179,6 +179,8 @@ features[variable][] = "bbcode_make_links_4" features[variable][] = "bbcode_make_links_6" features[variable][] = "bbcode_paragraph_breaks_4" features[variable][] = "bbcode_paragraph_breaks_6" +features[variable][] = "bbcode_rewrite_email_4" +features[variable][] = "bbcode_rewrite_email_6" features[variable][] = "boinctranslate_filter_debug_4" features[variable][] = "boinctranslate_filter_nodetypes" features[variable][] = "comment_anonymous_page" diff --git a/drupal/sites/all/features/boinc_standard/boinc_standard.input_formats.inc b/drupal/sites/all/features/boinc_standard/boinc_standard.input_formats.inc index 8594514b8f..3702da46c6 100644 --- a/drupal/sites/all/features/boinc_standard/boinc_standard.input_formats.inc +++ b/drupal/sites/all/features/boinc_standard/boinc_standard.input_formats.inc @@ -111,7 +111,9 @@ function boinc_standard_input_formats() { // Spam link deterrent 'bbcode_filter_nofollow' => '0', // Email address encoding - 'bbcode_encode_mailto' => '1', + 'bbcode_encode_mailto' => '0', + // Email address rewrite + 'bbcode_rewrite_email' => '1', // Smart paragraph and line breaks 'bbcode_paragraph_breaks' => '2', // Print debugging info diff --git a/drupal/sites/all/features/boinc_standard/boinc_standard.strongarm.inc b/drupal/sites/all/features/boinc_standard/boinc_standard.strongarm.inc index 4bb81f0b49..275bc2c1e7 100644 --- a/drupal/sites/all/features/boinc_standard/boinc_standard.strongarm.inc +++ b/drupal/sites/all/features/boinc_standard/boinc_standard.strongarm.inc @@ -31,14 +31,14 @@ function boinc_standard_strongarm() { $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ $strongarm->api_version = 1; $strongarm->name = 'bbcode_encode_mailto_4'; - $strongarm->value = '1'; + $strongarm->value = '0'; $export['bbcode_encode_mailto_4'] = $strongarm; $strongarm = new stdClass; $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ $strongarm->api_version = 1; $strongarm->name = 'bbcode_encode_mailto_6'; - $strongarm->value = '1'; + $strongarm->value = '0'; $export['bbcode_encode_mailto_6'] = $strongarm; $strongarm = new stdClass; @@ -83,6 +83,20 @@ function boinc_standard_strongarm() { $strongarm->value = '2'; $export['bbcode_paragraph_breaks_6'] = $strongarm; + $strongarm = new stdClass; + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'bbcode_rewrite_email_4'; + $strongarm->value = '1'; + $export['bbcode_rewrite_email_4'] = $strongarm; + + $strongarm = new stdClass; + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'bbcode_rewrite_email_6'; + $strongarm->value = '1'; + $export['bbcode_rewrite_email_6'] = $strongarm; + $strongarm = new stdClass; $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ $strongarm->api_version = 1;