Pathologic was missing because of a .git folder inside.
authorJeff Veit <jeff.veit@gmail.com>
Fri, 23 Jun 2017 00:40:13 +0000 (01:40 +0100)
committerJeff Veit <jeff.veit@gmail.com>
Fri, 23 Jun 2017 00:40:13 +0000 (01:40 +0100)
18 files changed:
web/modules/contrib/pathologic [deleted submodule]
web/modules/contrib/pathologic/README.txt [new file with mode: 0644]
web/modules/contrib/pathologic/config/install/pathologic.settings.yml [new file with mode: 0644]
web/modules/contrib/pathologic/config/schema/pathologic.schema.yml [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.api.php [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.info.yml [new file with mode: 0755]
web/modules/contrib/pathologic/pathologic.install [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.links.menu.yml [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.module [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.module.orig [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic.routing.yml [new file with mode: 0644]
web/modules/contrib/pathologic/pathologic_test/pathologic_test.info.yml [new file with mode: 0755]
web/modules/contrib/pathologic/pathologic_test/pathologic_test.module [new file with mode: 0644]
web/modules/contrib/pathologic/src/PathologicSettingsCommon.php [new file with mode: 0644]
web/modules/contrib/pathologic/src/PathologicSettingsForm.php [new file with mode: 0644]
web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php [new file with mode: 0644]
web/modules/contrib/pathologic/src/Tests/PathologicTest.php [new file with mode: 0644]
web/modules/contrib/pathologic/src/Tests/PathologicUITest.php [new file with mode: 0644]

diff --git a/web/modules/contrib/pathologic b/web/modules/contrib/pathologic
deleted file mode 160000 (submodule)
index 4f9f3fd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 4f9f3fdcf1e0b224c4d8650e383a769f40abf9bf
diff --git a/web/modules/contrib/pathologic/README.txt b/web/modules/contrib/pathologic/README.txt
new file mode 100644 (file)
index 0000000..3b2a5ba
--- /dev/null
@@ -0,0 +1,21 @@
+Pathologic
+----------
+
+Project Page:
+http://drupal.org/project/pathologic
+
+By Garrett Albright
+http://drupal.org/user/191212
+
+Originally sponsored by Precision Intermedia
+http://www.precisionintermedia.com/
+
+Thanks to all who have used this module over the years and provided bug reports
+and suggestions via email and the issue queue! I love you all.
+
+Installation & Configuration
+----------------------------
+
+For full installation and configuration instructions, please see this page in
+the Drupal online manual:
+http://drupal.org/node/257026
diff --git a/web/modules/contrib/pathologic/config/install/pathologic.settings.yml b/web/modules/contrib/pathologic/config/install/pathologic.settings.yml
new file mode 100644 (file)
index 0000000..b3869f0
--- /dev/null
@@ -0,0 +1,3 @@
+scheme_whitelist: ['http', 'https', 'files', 'internal']
+protocol_style: 'full'
+local_paths: ''
diff --git a/web/modules/contrib/pathologic/config/schema/pathologic.schema.yml b/web/modules/contrib/pathologic/config/schema/pathologic.schema.yml
new file mode 100644 (file)
index 0000000..f62b3fd
--- /dev/null
@@ -0,0 +1,33 @@
+pathologic.settings:
+  type: config_object
+  mapping:
+    scheme_whitelist:
+      type: sequence
+      label: 'Scheme whitelist'
+      sequence:
+        - type: string
+          label: 'Scheme'
+    protocol_style:
+      type: string
+      label: 'Protocol style'
+    local_paths:
+      type: string
+      label: 'Also considered local'
+
+filter_settings.filter_pathologic:
+  type: filter
+  label: 'Pathologic'
+  mapping:
+    settings_source:
+      type: string
+      label: 'Settings source'
+    local_settings:
+      type: mapping
+      label: 'Local settings'
+      mapping:
+        protocol_style:
+          type: string
+          label: 'Protocol style'
+        local_paths:
+          type: string
+          label: 'Also considered local'
diff --git a/web/modules/contrib/pathologic/pathologic.api.php b/web/modules/contrib/pathologic/pathologic.api.php
new file mode 100644 (file)
index 0000000..f75dd52
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by Pathologic.
+ *
+ * @ingroup pathologic
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/**
+ * Allow modules to alter a URL Pathologic is about to create.
+ *
+ * This hook is invoked after Pathologic has torn apart a URL it thinks it can
+ * alter properly and is just about to call the url() function to construct the
+ * new URL. Modules can alter the values that Pathologic is about to send to
+ * url(), or even stop Pathologic from altering a URL entirely.
+ *
+ * @param $url_params
+ *   An array with 'path' and 'options' values, which correspond to the $path
+ *   and $options parameters of the url() function. The 'options' array has an
+ *   extra parameter labeled 'use_original' which is set to FALSE by default.
+ *   This parameter is ignored by url(), but if its value is set to TRUE after
+ *   all alter hook invocations, Pathologic will return the original, unaltered
+ *   path it found in the content instead of calling url() and generating a new
+ *   one. Thus, it provides a way for modules to halt the alteration of paths
+ *   which Pathologic has incorrectly decided should be altered.
+ * @param $parts
+ *   This array contains the result of running parse_url() on the path that
+ *   Pathologic found in content, though Pathologic likely altered some of the
+ *   values in this array since. It contains another parameter, 'original',
+ *   which contains the original URL Pathologic found in the content, unaltered.
+ *   You should not alter this value in any way; to alter how Pathologic
+ *   constructs the new URL, alter $url_params instead.
+ * @param $settings
+ *   This contains the settings Pathologic is using to decide how to alter the
+ *   URL; some settings are from the graphical filter form and alterable by the
+ *   user, while others are determined programmatically. If you're looking for
+ *   the filter settings which Pathologic is currently using (if you've altered
+ *   your own field onto the filter settings form, for example), try looking in
+ *   $settings['current_settings'].
+ *
+ * @see url()
+ * @see parse_url()
+ * @see pathologic_replace()
+ * @see http://drupal.org/node/1762022
+ */
+function hook_pathologic_alter(&$url_params, $parts, $settings) {
+  // If we're linking to the "bananas" subdirectory or something under it, then
+  // have Pathologic pass through the original URL, without altering it.
+  if (preg_match('~^bananas(/.*)?$~', $url_params['path'])) {
+    $url_params['options']['use_original'] = TRUE;
+  }
+
+  // If we're linking to a path like "article/something.html", then prepend
+  // "magazine" to the path, but remove the ".html". The end result will look
+  // like "magazine/article/something".
+  if (preg_match('~^article/(.+)\.html$~', $url_params['path'], $matches)) {
+    $url_params['path'] = 'magazine/article/' . $matches[1];
+  }
+
+  // If the URL doesn't have a "foo" query parameter, then add one.
+  if (!is_array($url_params['options']['query'])) {
+    $url_params['options']['query'] = [];
+  }
+  if (empty($url_params['options']['query']['foo'])) {
+    $url_params['options']['query']['foo'] = 'bar';
+  }
+
+  // If it's a path to a local image, make sure it's using our CDN server.
+  if (preg_match('~\.(png|gif|jpe?g)$~', $url_params['path'])) {
+    $url_params['path'] = 'http://cdn.example.com/' . $url_params['path'];
+    $url_params['options']['external'] = TRUE;
+  }
+}
+
+/**
+ * @} End of "addtogroup hooks".
+ */
diff --git a/web/modules/contrib/pathologic/pathologic.info.yml b/web/modules/contrib/pathologic/pathologic.info.yml
new file mode 100755 (executable)
index 0000000..030a92d
--- /dev/null
@@ -0,0 +1,8 @@
+name: Pathologic
+description: 'Helps avoid broken links and incorrect paths in content.'
+core: 8.x
+package: 'Input filters'
+dependencies:
+- filter
+type: module
+configure: pathologic.config_form
diff --git a/web/modules/contrib/pathologic/pathologic.install b/web/modules/contrib/pathologic/pathologic.install
new file mode 100644 (file)
index 0000000..c572b5f
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * @file
+ * .install file for Pathologic.
+ */
+
+/**
+ * Re-enable Pathologic under Drupal 7, preserving settings from Drupal 6.
+ */
+function pathologic_update_7000($sandbox) {
+  // Make sure {d6_upgrade_filter} exists. It won't exist for people upgrading
+  // from beta versions of the D7 version of Pathologic on native D7 sites (not
+  // upgraded from D6).
+  if (db_table_exists('d6_upgrade_filter')) {
+    // Get all Pathologic data from {d6_upgrade_filter}.
+    $rez = db_select('d6_upgrade_filter', 'dup')
+      ->fields('dup')
+      ->condition('module', 'pathologic')
+      ->execute();
+    while ($instance = $rez->fetchObject()) {
+      // Load the format
+      if ($format = filter_format_load($instance->format)) {
+        // Load filters.
+        $format->filters = [];
+        // Add the filters
+        foreach (filter_list_format($instance->format) as $filter_name => $filter) {
+          $format->filters[$filter_name] = (array)$filter;
+        }
+        // Add Pathologic
+        $format->filters['pathologic'] = [
+          'weight' => $instance->weight,
+          'status' => 1,
+          'settings' => [
+            'absolute' => variable_get('filter_pathologic_absolute_' . $instance->format, TRUE),
+            'local_paths' => variable_get('filter_pathologic_local_paths_' . $instance->format, ''),
+          ],
+        ];
+        // Save the format
+        filter_format_save($format);
+        // Unset old variables
+        variable_del('filter_pathologic_absolute_' . $instance->format);
+        variable_del('filter_pathologic_local_paths_' . $instance->format);
+      }
+    }
+    // Delete Pathologic data from {d6_upgrade_filter}…?
+    // No, maybe we don't want to actually do that…?
+  }
+}
+
+/**
+ * Convert obsolete "absolute" setting to modern "protocol_style" setting for
+ * each filter instance.
+ */
+function pathologic_update_7200(&$sandbox) {
+  foreach (filter_formats() as $format) {
+    // @see http://drupal.org/node/1304930
+    if (empty($format->filters)) {
+      $format->filters = [];
+      // Add the filters
+      foreach (filter_list_format($format->format) as $filter_name => $filter) {
+        $format->filters[$filter_name] = (array)$filter;
+      }
+    }
+    if (isset($format->filters['pathologic'])) {
+      $format->filters['pathologic']['settings']['protocol_style'] = $format->filters['pathologic']['settings']['absolute'] ? 'full' : 'path';
+      unset($format->filters['pathologic']['settings']['absolute']);
+      filter_format_save($format);
+    }
+  }
+}
diff --git a/web/modules/contrib/pathologic/pathologic.links.menu.yml b/web/modules/contrib/pathologic/pathologic.links.menu.yml
new file mode 100644 (file)
index 0000000..17e8a00
--- /dev/null
@@ -0,0 +1,5 @@
+pathologic.config_form:
+  title: 'Pathologic configuration'
+  parent: system.admin_config_content
+  description: 'Configure how Pathologic adjusts link and image paths in content.'
+  route_name: pathologic.config_form
diff --git a/web/modules/contrib/pathologic/pathologic.module b/web/modules/contrib/pathologic/pathologic.module
new file mode 100644 (file)
index 0000000..8f77b03
--- /dev/null
@@ -0,0 +1,404 @@
+<?php
+
+/**
+ * @file
+ * Pathologic text filter for Drupal.
+ *
+ * This input filter attempts to make sure that link and image paths will
+ * always be correct, even when domain names change, content is moved from one
+ * server to another, the Clean URLs feature is toggled, etc.
+ *
+ * @todo for Pathlogic 8.x-2.x
+ * - Account for new way dirty URLs are done (no more clean_url variable)
+ * - - We can now tell url() to create clean or dirty URLs regardless of current
+ *     status!
+ * - - (lol jk no more url() - but maybe the equivalent code is still there)
+ * - - Our path parsing code needs to account for both new and old dirty URL
+ *     styles
+ * - - Option to force output of clean or dirty URLs?
+ * - Move _pathologic_filter() code into the actual filter class
+ * - Do DOM object manipulation instead of preg_replace(). It's what core
+ *   filters are doing now.
+ * - UrlHelper::Parse() instead of parse_url()?
+ * - Alter hook alters Drupal\Core\Url object instead of method parameters.
+ */
+
+use Drupal\Component\Utility\Html;
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Url;
+
+/**
+ * Pathologic filter callback.
+ *
+ * @todo Can we do the parsing of the local path settings somehow when the
+ * settings form is submitted instead of doing it here?
+ */
+function _pathologic_filter($text, $settings, $hash) {
+  // Get the base URL and explode it into component parts. We add these parts
+  // to the exploded local paths settings later.
+  global $base_url;
+  $base_url_parts = parse_url($base_url . '/');
+  // Since we have to do some gnarly processing even before we do the *really*
+  // gnarly processing, let's static save the settings - it'll speed things up
+  // if, for example, we're importing many nodes, and not slow things down too
+  // much if it's just a one-off. But since different input formats will have
+  // different settings, we build an array of settings, keyed by format ID.
+  $cached_settings = &drupal_static(__FUNCTION__, []);
+  if (!isset($cached_settings[$hash])) {
+    $settings['local_paths_exploded'] = [];
+    if ($settings['local_paths'] !== '') {
+      // Build an array of the exploded local paths for this format's settings.
+      // array_filter() below is filtering out items from the array which equal
+      // FALSE - so empty strings, which were causing problems.
+      // @see http://drupal.org/node/1727492
+      $local_paths = array_filter(array_map('trim', explode("\n", $settings['local_paths'])));
+      foreach ($local_paths as $local) {
+        $parts = parse_url($local);
+        // Okay, what the hellish "if" statement is doing below is checking to
+        // make sure we aren't about to add a path to our array of exploded
+        // local paths which matches the current "local" path. We consider it
+        // not a match, if…
+        // @todo: This is pretty horrible. Can this be simplified?
+        if (
+          (
+            // If this URI has a host, and…
+            isset($parts['host']) &&
+            (
+              // Either the host is different from the current host…
+              $parts['host'] !== $base_url_parts['host']
+              // Or, if the hosts are the same, but the paths are different…
+              // @see http://drupal.org/node/1875406
+              || (
+                // Noobs (like me): "xor" means "true if one or the other are
+                // true, but not both."
+                (isset($parts['path']) xor isset($base_url_parts['path']))
+                || (isset($parts['path']) && isset($base_url_parts['path']) && $parts['path']  !== $base_url_parts['path'])
+              )
+            )
+          ) ||
+          // Or…
+          (
+            // The URI doesn't have a host…
+            !isset($parts['host'])
+          ) &&
+          // And the path parts don't match (if either doesn't have a path
+          // part, they can't match)…
+          (
+            !isset($parts['path']) ||
+            !isset($base_url_parts['path']) ||
+            $parts['path'] !== $base_url_parts['path']
+          )
+        ) {
+          // Add it to the list.
+          $settings['local_paths_exploded'][] = $parts;
+        }
+      }
+    }
+    // Now add local paths based on "this" server URL.
+    $settings['local_paths_exploded'][] = ['path' => $base_url_parts['path']];
+    $settings['local_paths_exploded'][] = ['path' => $base_url_parts['path'], 'host' => $base_url_parts['host']];
+    // We'll also just store the host part separately for easy access.
+    $settings['base_url_host'] = $base_url_parts['host'];
+
+    $cached_settings[$hash] = $settings;
+  }
+  // Take note of which settings in the settings array should apply.
+  $cached_settings['current_settings'] = &$cached_settings[$hash];
+
+  // Now that we have all of our settings prepared, attempt to process all
+  // paths in href, src, action or longdesc HTML attributes. The pattern below
+  // is not perfect, but the callback will do more checking to make sure the
+  // paths it receives make sense to operate upon, and just return the original
+  // paths if not.
+  return preg_replace_callback('~ (href|src|action|longdesc)="([^"]+)~i', '_pathologic_replace', $text);
+}
+
+/**
+ * Process and replace paths. preg_replace_callback() callback.
+ */
+function _pathologic_replace($matches) {
+  // Get the base path.
+  global $base_path;
+
+  // Get the settings for the filter. Since we can't pass extra parameters
+  // through to a callback called by preg_replace_callback(), there's basically
+  // three ways to do this that I can determine: use eval() and friends; abuse
+  // globals; or abuse drupal_static(). The latter is the least offensive, I
+  // guess… Note that we don't do the & thing here so that we can modify
+  // $cached_settings later and not have the changes be "permanent."
+  $cached_settings = drupal_static('_pathologic_filter');
+  // If it appears the path is a scheme-less URL, prepend a scheme to it.
+  // parse_url() cannot properly parse scheme-less URLs. Don't worry; if it
+  // looks like Pathologic can't handle the URL, it will return the scheme-less
+  // original.
+  // @see https://drupal.org/node/1617944
+  // @see https://drupal.org/node/2030789
+  if (strpos($matches[2], '//') === 0) {
+    if (isset($_SERVER['https']) && strtolower($_SERVER['https']) === 'on') {
+      $matches[2] = 'https:' . $matches[2];
+    }
+    else {
+      $matches[2] = 'http:' . $matches[2];
+    }
+  }
+  // Now parse the URL after reverting HTML character encoding.
+  // @see http://drupal.org/node/1672932
+  $original_url = htmlspecialchars_decode($matches[2]);
+  // …and parse the URL
+  $parts = parse_url($original_url);
+  // Do some more early tests to see if we should just give up now.
+  if (
+    // If parse_url() failed, $parts = FALSE. If the href was just "#", $parts
+    // is an empty array. Give up in both cases.
+    empty($parts)
+    || (
+      // If there's a scheme part and it doesn't look useful, bail out.
+      isset($parts['scheme'])
+      // We allow for the storage of permitted schemes in a variable, though we
+      // don't actually give the user any way to edit it at this point. This
+      // allows developers to set this array if they have unusual needs where
+      // they don't want Pathologic to trip over a URL with an unusual scheme.
+      // @see http://drupal.org/node/1834308
+      // Default value is ['http', 'https', 'files', 'internal']
+      // "files" and "internal" are for Path Filter compatibility.
+      && !in_array($parts['scheme'], \Drupal::config('pathologic.settings')->get('scheme_whitelist'))
+    )
+    // Bail out if it looks like there's only a fragment part.
+    || (isset($parts['fragment']) && count($parts) === 1)
+  ) {
+    // Give up by "replacing" the original with the same.
+    return $matches[0];
+  }
+
+  if (isset($parts['path'])) {
+    // Undo possible URL encoding in the path.
+    // @see http://drupal.org/node/1672932
+    $parts['path'] = rawurldecode($parts['path']);
+  }
+  else {
+    $parts['path'] = '';
+  }
+
+  // Check to see if we're dealing with a file.
+  // @todo Should we still try to do path correction on these files too?
+  if (isset($parts['scheme']) && $parts['scheme'] === 'files') {
+    // Path Filter "files:" support. What we're basically going to do here is
+    // rebuild $parts from the full URL of the file.
+    $new_parts = parse_url(file_create_url(file_default_scheme() . '://' . $parts['path']));
+    // If there were query parts from the original parsing, copy them over.
+    if (!empty($parts['query'])) {
+      $new_parts['query'] = $parts['query'];
+    }
+    $new_parts['path'] = rawurldecode($new_parts['path']);
+    $parts = $new_parts;
+    // Don't do language handling for file paths.
+    $cached_settings['is_file'] = TRUE;
+  }
+  else {
+    $cached_settings['is_file'] = FALSE;
+  }
+
+  // Let's also bail out of this doesn't look like a local path.
+  $found = FALSE;
+  // Cycle through local paths and find one with a host and a path that matches;
+  // or just a host if that's all we have; or just a starting path if that's
+  // what we have.
+  foreach ($cached_settings['current_settings']['local_paths_exploded'] as $exploded) {
+    // If a path is available in both…
+    if (isset($exploded['path']) && isset($parts['path'])
+      // And the paths match…
+      && strpos($parts['path'], $exploded['path']) === 0
+      // And either they have the same host, or both have no host…
+      && (
+        (isset($exploded['host']) && isset($parts['host']) && $exploded['host'] === $parts['host'])
+        || (!isset($exploded['host']) && !isset($parts['host']))
+      )
+    ) {
+      // Remove the shared path from the path. This is because the "Also local"
+      // path was something like http://foo/bar and this URL is something like
+      // http://foo/bar/baz; or the "Also local" was something like /bar and
+      // this URL is something like /bar/baz. And we only care about the /baz
+      // part.
+      $parts['path'] = Unicode::substr($parts['path'], Unicode::strlen($exploded['path']));
+      $found = TRUE;
+      // Break out of the foreach loop
+      break;
+    }
+    // Okay, we didn't match on path alone, or host and path together. Can we
+    // match on just host? Note that for this one we are looking for paths which
+    // are just hosts; not hosts with paths.
+    elseif ((isset($parts['host']) && !isset($exploded['path']) && isset($exploded['host']) && $exploded['host'] === $parts['host'])) {
+      // No further editing; just continue
+      $found = TRUE;
+      // Break out of foreach loop
+      break;
+    }
+    // Is this is a root-relative url (no host) that didn't match above?
+    // Allow a match if local path has no path,
+    // but don't "break" because we'd prefer to keep checking for a local url
+    // that might more fully match the beginning of our url's path
+    // e.g.: if our url is /foo/bar we'll mark this as a match for
+    // http://example.com but want to keep searching and would prefer a match
+    // to http://example.com/foo if that's configured as a local path
+    elseif (!isset($parts['host']) && (!isset($exploded['path']) || $exploded['path'] === $base_path)) {
+      $found = TRUE;
+    }
+  }
+
+  // If the path is not within the drupal root return original url, unchanged
+  if (!$found) {
+    return $matches[0];
+  }
+
+  // Okay, format the URL.
+  // If there's still a slash lingering at the start of the path, chop it off.
+  $parts['path'] = ltrim($parts['path'], '/');
+
+  // Examine the query part of the URL. Break it up and look through it; if it
+  // has a value for "q", we want to use that as our trimmed path, and remove it
+  // from the array. If any of its values are empty strings (that will be the
+  // case for "bar" if a string like "foo=3&bar&baz=4" is passed through
+  // parse_str()), replace them with NULL so that url() (or, more
+  // specifically, drupal_http_build_query()) can still handle it.
+  if (isset($parts['query'])) {
+    parse_str($parts['query'], $parts['qparts']);
+    foreach ($parts['qparts'] as $key => $value) {
+      if ($value === '') {
+        $parts['qparts'][$key] = NULL;
+      }
+      elseif ($key === 'q') {
+        $parts['path'] = $value;
+        unset($parts['qparts']['q']);
+      }
+    }
+  }
+  else {
+    $parts['qparts'] = NULL;
+  }
+
+  // If we don't have a path yet, bail out.
+  if (!isset($parts['path'])) {
+    return $matches[0];
+  }
+
+  // If this looks like a D8-style unclean URL, crop off the "index.php/" from
+  // the beginning.
+  if (strpos($parts['path'], 'index.php/') === 0) {
+    $parts['path'] = substr($parts['path'], 10);
+  }
+
+  // If we didn't previously identify this as a file, check to see if the file
+  // exists now that we have the correct path relative to DRUPAL_ROOT
+  if (!$cached_settings['is_file']) {
+    $cached_settings['is_file'] = !empty($parts['path']) && is_file(DRUPAL_ROOT . '/' . $parts['path']);
+  }
+
+  // Okay, deal with language stuff.
+  // Let's see if we can split off a language prefix from the path.
+  if (\Drupal::moduleHandler()->moduleExists('language')) {
+    // This logic is based on
+    // \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::getLangcode().
+    $languages = \Drupal::languageManager()->getLanguages();
+    $config = \Drupal::config('language.negotiation')->get('url');
+
+    $request_path = urldecode(trim($parts['path'], '/'));
+    $path_args = explode('/', $request_path);
+    $prefix = array_shift($path_args);
+
+    // Search for prefix within added languages.
+    foreach ($languages as $language) {
+      if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
+        $parts['path'] = implode('/', $path_args);
+        $parts['language_obj'] = $language;
+        break;
+      }
+    }
+  }
+
+  // If we get to this point and $parts['path'] is now an empty string (which
+  // will be the case if the path was originally just "/"), then we
+  // want to link to <front>.
+  if ($parts['path'] === '') {
+    $parts['path'] = '<front>';
+  }
+  // Build the parameters we will send to url()
+  $url_params = [
+    'path' => $parts['path'],
+    'options' => [
+      'query' => $parts['qparts'],
+      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
+      // Create an absolute URL if protocol_style is 'full' or 'proto-rel', but
+      // not if it's 'path'.
+      'absolute' => $cached_settings['current_settings']['protocol_style'] !== 'path',
+      // If we seem to have found a language for the path, pass it along to
+      // url(). Otherwise, ignore the 'language' parameter.
+      'language' => isset($parts['language_obj']) ? $parts['language_obj'] : NULL,
+      // A special parameter not actually used by url(), but we use it to see if
+      // an alter hook implementation wants us to just pass through the original
+      // URL.
+      'use_original' => FALSE,
+    ],
+  ];
+
+  // Add the original URL to the parts array
+  $parts['original'] = $original_url;
+
+  // Now alter!
+  // @see http://drupal.org/node/1762022
+  \Drupal::moduleHandler()->alter('pathologic', $url_params, $parts, $cached_settings);
+
+  // If any of the alter hooks asked us to just pass along the original URL,
+  // then do so.
+  if ($url_params['options']['use_original']) {
+    return $matches[0];
+  }
+
+  // Now to build the URL. Drumroll, please…
+  if ($parts['path'] == '<front>') {
+    $url = Url::fromRoute('<front>', [], $url_params['options'])->toString();
+  }
+  else {
+    try {
+      $url = Url::fromUri('base://' . $url_params['path'], $url_params['options'])
+        ->toString();
+    }
+    catch (\Exception $e) {
+      // In case of an error, e.g. completely invalid URL, return it unchanged.
+      return $matches[0];
+    }
+  }
+
+  // If we need to create a protocol-relative URL, then convert the absolute
+  // URL we have now.
+  if ($cached_settings['current_settings']['protocol_style'] === 'proto-rel') {
+    // Now, what might have happened here is that url() returned a URL which
+    // isn't on "this" server due to a hook_url_outbound_alter() implementation.
+    // We don't want to convert the URL in that case. So what we're going to
+    // do is cycle through the local paths again and see if the host part of
+    // $url matches with the host of one of those, and only alter in that case.
+    $url_parts = parse_url($url);
+    if (!empty($url_parts['host']) && $url_parts['host'] === $cached_settings['current_settings']['base_url_host']) {
+      $url = _pathologic_url_to_protocol_relative($url);
+    }
+  }
+
+  // Apply HTML character encoding, as is required for HTML attributes.
+  // @see http://drupal.org/node/1672932
+  $url = Html::escape($url);
+  // $matches[1] will be the tag attribute; src, href, etc.
+  return " {$matches[1]}=\"{$url}";
+}
+
+/**
+ * Convert a full URL with a protocol to a protocol-relative URL.
+ *
+ * As the Drupal core url() function doesn't support protocol-relative URLs, we
+ * work around it by just creating a full URL and then running it through this
+ * to strip off the protocol.
+ *
+ * Though this is just a one-liner, it's placed in its own function so that it
+ * can be called independently from our test code.
+ */
+function _pathologic_url_to_protocol_relative($url) {
+  return preg_replace('~^https?://~', '//', $url);
+}
diff --git a/web/modules/contrib/pathologic/pathologic.module.orig b/web/modules/contrib/pathologic/pathologic.module.orig
new file mode 100644 (file)
index 0000000..968e1b1
--- /dev/null
@@ -0,0 +1,404 @@
+<?php
+
+/**
+ * @file
+ * Pathologic text filter for Drupal.
+ *
+ * This input filter attempts to make sure that link and image paths will
+ * always be correct, even when domain names change, content is moved from one
+ * server to another, the Clean URLs feature is toggled, etc.
+ *
+ * @todo for Pathlogic 8.x-2.x
+ * - Account for new way dirty URLs are done (no more clean_url variable)
+ * - - We can now tell url() to create clean or dirty URLs regardless of current
+ *     status!
+ * - - (lol jk no more url() - but maybe the equivalent code is still there)
+ * - - Our path parsing code needs to account for both new and old dirty URL
+ *     styles
+ * - - Option to force output of clean or dirty URLs?
+ * - Move _pathologic_filter() code into the actual filter class
+ * - Do DOM object manipulation instead of preg_replace(). It's what core
+ *   filters are doing now.
+ * - UrlHelper::Parse() instead of parse_url()?
+ * - Alter hook alters Drupal\Core\Url object instead of method parameters.
+ */
+
+use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Url;
+
+/**
+ * Pathologic filter callback.
+ *
+ * @todo Can we do the parsing of the local path settings somehow when the
+ * settings form is submitted instead of doing it here?
+ */
+function _pathologic_filter($text, $settings, $hash) {
+  // Get the base URL and explode it into component parts. We add these parts
+  // to the exploded local paths settings later.
+  global $base_url;
+  $base_url_parts = parse_url($base_url . '/');
+  // Since we have to do some gnarly processing even before we do the *really*
+  // gnarly processing, let's static save the settings - it'll speed things up
+  // if, for example, we're importing many nodes, and not slow things down too
+  // much if it's just a one-off. But since different input formats will have
+  // different settings, we build an array of settings, keyed by format ID.
+  $cached_settings = &drupal_static(__FUNCTION__, []);
+  if (!isset($cached_settings[$hash])) {
+    $settings['local_paths_exploded'] = [];
+    if ($settings['local_paths'] !== '') {
+      // Build an array of the exploded local paths for this format's settings.
+      // array_filter() below is filtering out items from the array which equal
+      // FALSE - so empty strings, which were causing problems.
+      // @see http://drupal.org/node/1727492
+      $local_paths = array_filter(array_map('trim', explode("\n", $settings['local_paths'])));
+      foreach ($local_paths as $local) {
+        $parts = parse_url($local);
+        // Okay, what the hellish "if" statement is doing below is checking to
+        // make sure we aren't about to add a path to our array of exploded
+        // local paths which matches the current "local" path. We consider it
+        // not a match, if…
+        // @todo: This is pretty horrible. Can this be simplified?
+        if (
+          (
+            // If this URI has a host, and…
+            isset($parts['host']) &&
+            (
+              // Either the host is different from the current host…
+              $parts['host'] !== $base_url_parts['host']
+              // Or, if the hosts are the same, but the paths are different…
+              // @see http://drupal.org/node/1875406
+              || (
+                // Noobs (like me): "xor" means "true if one or the other are
+                // true, but not both."
+                (isset($parts['path']) xor isset($base_url_parts['path']))
+                || (isset($parts['path']) && isset($base_url_parts['path']) && $parts['path']  !== $base_url_parts['path'])
+              )
+            )
+          ) ||
+          // Or…
+          (
+            // The URI doesn't have a host…
+            !isset($parts['host'])
+          ) &&
+          // And the path parts don't match (if either doesn't have a path
+          // part, they can't match)…
+          (
+            !isset($parts['path']) ||
+            !isset($base_url_parts['path']) ||
+            $parts['path'] !== $base_url_parts['path']
+          )
+        ) {
+          // Add it to the list.
+          $settings['local_paths_exploded'][] = $parts;
+        }
+      }
+    }
+    // Now add local paths based on "this" server URL.
+    $settings['local_paths_exploded'][] = ['path' => $base_url_parts['path']];
+    $settings['local_paths_exploded'][] = ['path' => $base_url_parts['path'], 'host' => $base_url_parts['host']];
+    // We'll also just store the host part separately for easy access.
+    $settings['base_url_host'] = $base_url_parts['host'];
+
+    $cached_settings[$hash] = $settings;
+  }
+  // Take note of which settings in the settings array should apply.
+  $cached_settings['current_settings'] = &$cached_settings[$hash];
+
+  // Now that we have all of our settings prepared, attempt to process all
+  // paths in href, src, action or longdesc HTML attributes. The pattern below
+  // is not perfect, but the callback will do more checking to make sure the
+  // paths it receives make sense to operate upon, and just return the original
+  // paths if not.
+  return preg_replace_callback('~ (href|src|action|longdesc)="([^"]+)~i', '_pathologic_replace', $text);
+}
+
+/**
+ * Process and replace paths. preg_replace_callback() callback.
+ */
+function _pathologic_replace($matches) {
+  // Get the base path.
+  global $base_path;
+
+  // Get the settings for the filter. Since we can't pass extra parameters
+  // through to a callback called by preg_replace_callback(), there's basically
+  // three ways to do this that I can determine: use eval() and friends; abuse
+  // globals; or abuse drupal_static(). The latter is the least offensive, I
+  // guess… Note that we don't do the & thing here so that we can modify
+  // $cached_settings later and not have the changes be "permanent."
+  $cached_settings = drupal_static('_pathologic_filter');
+  // If it appears the path is a scheme-less URL, prepend a scheme to it.
+  // parse_url() cannot properly parse scheme-less URLs. Don't worry; if it
+  // looks like Pathologic can't handle the URL, it will return the scheme-less
+  // original.
+  // @see https://drupal.org/node/1617944
+  // @see https://drupal.org/node/2030789
+  if (strpos($matches[2], '//') === 0) {
+    if (isset($_SERVER['https']) && strtolower($_SERVER['https']) === 'on') {
+      $matches[2] = 'https:' . $matches[2];
+    }
+    else {
+      $matches[2] = 'http:' . $matches[2];
+    }
+  }
+  // Now parse the URL after reverting HTML character encoding.
+  // @see http://drupal.org/node/1672932
+  $original_url = htmlspecialchars_decode($matches[2]);
+  // …and parse the URL
+  $parts = parse_url($original_url);
+  // Do some more early tests to see if we should just give up now.
+  if (
+    // If parse_url() failed, $parts = FALSE. If the href was just "#", $parts
+    // is an empty array. Give up in both cases.
+    empty($parts)
+    || (
+      // If there's a scheme part and it doesn't look useful, bail out.
+      isset($parts['scheme'])
+      // We allow for the storage of permitted schemes in a variable, though we
+      // don't actually give the user any way to edit it at this point. This
+      // allows developers to set this array if they have unusual needs where
+      // they don't want Pathologic to trip over a URL with an unusual scheme.
+      // @see http://drupal.org/node/1834308
+      // Default value is ['http', 'https', 'files', 'internal']
+      // "files" and "internal" are for Path Filter compatibility.
+      && !in_array($parts['scheme'], \Drupal::config('pathologic.settings')->get('scheme_whitelist'))
+    )
+    // Bail out if it looks like there's only a fragment part.
+    || (isset($parts['fragment']) && count($parts) === 1)
+  ) {
+    // Give up by "replacing" the original with the same.
+    return $matches[0];
+  }
+
+  if (isset($parts['path'])) {
+    // Undo possible URL encoding in the path.
+    // @see http://drupal.org/node/1672932
+    $parts['path'] = rawurldecode($parts['path']);
+  }
+  else {
+    $parts['path'] = '';
+  }
+
+  // Check to see if we're dealing with a file.
+  // @todo Should we still try to do path correction on these files too?
+  if (isset($parts['scheme']) && $parts['scheme'] === 'files') {
+    // Path Filter "files:" support. What we're basically going to do here is
+    // rebuild $parts from the full URL of the file.
+    $new_parts = parse_url(file_create_url(file_default_scheme() . '://' . $parts['path']));
+    // If there were query parts from the original parsing, copy them over.
+    if (!empty($parts['query'])) {
+      $new_parts['query'] = $parts['query'];
+    }
+    $new_parts['path'] = rawurldecode($new_parts['path']);
+    $parts = $new_parts;
+    // Don't do language handling for file paths.
+    $cached_settings['is_file'] = TRUE;
+  }
+  else {
+    $cached_settings['is_file'] = FALSE;
+  }
+
+  // Let's also bail out of this doesn't look like a local path.
+  $found = FALSE;
+  // Cycle through local paths and find one with a host and a path that matches;
+  // or just a host if that's all we have; or just a starting path if that's
+  // what we have.
+  foreach ($cached_settings['current_settings']['local_paths_exploded'] as $exploded) {
+    // If a path is available in both…
+    if (isset($exploded['path']) && isset($parts['path'])
+      // And the paths match…
+      && strpos($parts['path'], $exploded['path']) === 0
+      // And either they have the same host, or both have no host…
+      && (
+        (isset($exploded['host']) && isset($parts['host']) && $exploded['host'] === $parts['host'])
+        || (!isset($exploded['host']) && !isset($parts['host']))
+      )
+    ) {
+      // Remove the shared path from the path. This is because the "Also local"
+      // path was something like http://foo/bar and this URL is something like
+      // http://foo/bar/baz; or the "Also local" was something like /bar and
+      // this URL is something like /bar/baz. And we only care about the /baz
+      // part.
+      $parts['path'] = Unicode::substr($parts['path'], Unicode::strlen($exploded['path']));
+      $found = TRUE;
+      // Break out of the foreach loop
+      break;
+    }
+    // Okay, we didn't match on path alone, or host and path together. Can we
+    // match on just host? Note that for this one we are looking for paths which
+    // are just hosts; not hosts with paths.
+    elseif ((isset($parts['host']) && !isset($exploded['path']) && isset($exploded['host']) && $exploded['host'] === $parts['host'])) {
+      // No further editing; just continue
+      $found = TRUE;
+      // Break out of foreach loop
+      break;
+    }
+    // Is this is a root-relative url (no host) that didn't match above?
+    // Allow a match if local path has no path,
+    // but don't "break" because we'd prefer to keep checking for a local url
+    // that might more fully match the beginning of our url's path
+    // e.g.: if our url is /foo/bar we'll mark this as a match for
+    // http://example.com but want to keep searching and would prefer a match
+    // to http://example.com/foo if that's configured as a local path
+    elseif (!isset($parts['host']) && (!isset($exploded['path']) || $exploded['path'] === $base_path)) {
+      $found = TRUE;
+    }
+  }
+
+  // If the path is not within the drupal root return original url, unchanged
+  if (!$found) {
+    return $matches[0];
+  }
+
+  // Okay, format the URL.
+  // If there's still a slash lingering at the start of the path, chop it off.
+  $parts['path'] = ltrim($parts['path'], '/');
+
+  // Examine the query part of the URL. Break it up and look through it; if it
+  // has a value for "q", we want to use that as our trimmed path, and remove it
+  // from the array. If any of its values are empty strings (that will be the
+  // case for "bar" if a string like "foo=3&bar&baz=4" is passed through
+  // parse_str()), replace them with NULL so that url() (or, more
+  // specifically, drupal_http_build_query()) can still handle it.
+  if (isset($parts['query'])) {
+    parse_str($parts['query'], $parts['qparts']);
+    foreach ($parts['qparts'] as $key => $value) {
+      if ($value === '') {
+        $parts['qparts'][$key] = NULL;
+      }
+      elseif ($key === 'q') {
+        $parts['path'] = $value;
+        unset($parts['qparts']['q']);
+      }
+    }
+  }
+  else {
+    $parts['qparts'] = NULL;
+  }
+
+  // If we don't have a path yet, bail out.
+  if (!isset($parts['path'])) {
+    return $matches[0];
+  }
+
+  // If this looks like a D8-style unclean URL, crop off the "index.php/" from
+  // the beginning.
+  if (strpos($parts['path'], 'index.php/') === 0) {
+    $parts['path'] = substr($parts['path'], 10);
+  }
+
+  // If we didn't previously identify this as a file, check to see if the file
+  // exists now that we have the correct path relative to DRUPAL_ROOT
+  if (!$cached_settings['is_file']) {
+    $cached_settings['is_file'] = !empty($parts['path']) && is_file(DRUPAL_ROOT . '/' . $parts['path']);
+  }
+
+  // Okay, deal with language stuff.
+  // Let's see if we can split off a language prefix from the path.
+  if (\Drupal::moduleHandler()->moduleExists('language')) {
+    // This logic is based on
+    // \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::getLangcode().
+    $languages = \Drupal::languageManager()->getLanguages();
+    $config = \Drupal::config('language.negotiation')->get('url');
+
+    $request_path = urldecode(trim($parts['path'], '/'));
+    $path_args = explode('/', $request_path);
+    $prefix = array_shift($path_args);
+
+    // Search for prefix within added languages.
+    foreach ($languages as $language) {
+      if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
+        $parts['path'] = implode('/', $path_args);
+        $parts['language_obj'] = $language;
+        break;
+      }
+    }
+  }
+
+  // If we get to this point and $parts['path'] is now an empty string (which
+  // will be the case if the path was originally just "/"), then we
+  // want to link to <front>.
+  if ($parts['path'] === '') {
+    $parts['path'] = '<front>';
+  }
+  // Build the parameters we will send to url()
+  $url_params = [
+    'path' => $parts['path'],
+    'options' => [
+      'query' => $parts['qparts'],
+      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
+      // Create an absolute URL if protocol_style is 'full' or 'proto-rel', but
+      // not if it's 'path'.
+      'absolute' => $cached_settings['current_settings']['protocol_style'] !== 'path',
+      // If we seem to have found a language for the path, pass it along to
+      // url(). Otherwise, ignore the 'language' parameter.
+      'language' => isset($parts['language_obj']) ? $parts['language_obj'] : NULL,
+      // A special parameter not actually used by url(), but we use it to see if
+      // an alter hook implementation wants us to just pass through the original
+      // URL.
+      'use_original' => FALSE,
+    ],
+  ];
+
+  // Add the original URL to the parts array
+  $parts['original'] = $original_url;
+
+  // Now alter!
+  // @see http://drupal.org/node/1762022
+  \Drupal::moduleHandler()->alter('pathologic', $url_params, $parts, $cached_settings);
+
+  // If any of the alter hooks asked us to just pass along the original URL,
+  // then do so.
+  if ($url_params['options']['use_original']) {
+    return $matches[0];
+  }
+
+  // Now to build the URL. Drumroll, please…
+  if ($parts['path'] == '<front>') {
+    $url = Url::fromRoute('<front>', [], $url_params['options'])->toString();
+  }
+  else {
+    try {
+      $url = Url::fromUri('base://' . $url_params['path'], $url_params['options'])
+        ->toString();
+    }
+    catch (\Exception $e) {
+      // In case of an error, e.g. completely invalid URL, return it unchanged.
+      return $matches[0];
+    }
+  }
+
+  // If we need to create a protocol-relative URL, then convert the absolute
+  // URL we have now.
+  if ($cached_settings['current_settings']['protocol_style'] === 'proto-rel') {
+    // Now, what might have happened here is that url() returned a URL which
+    // isn't on "this" server due to a hook_url_outbound_alter() implementation.
+    // We don't want to convert the URL in that case. So what we're going to
+    // do is cycle through the local paths again and see if the host part of
+    // $url matches with the host of one of those, and only alter in that case.
+    $url_parts = parse_url($url);
+    if (!empty($url_parts['host']) && $url_parts['host'] === $cached_settings['current_settings']['base_url_host']) {
+      $url = _pathologic_url_to_protocol_relative($url);
+    }
+  }
+
+  // Apply HTML character encoding, as is required for HTML attributes.
+  // @see http://drupal.org/node/1672932
+  $url = SafeMarkup::checkPlain($url);
+  // $matches[1] will be the tag attribute; src, href, etc.
+  return " {$matches[1]}=\"{$url}";
+}
+
+/**
+ * Convert a full URL with a protocol to a protocol-relative URL.
+ *
+ * As the Drupal core url() function doesn't support protocol-relative URLs, we
+ * work around it by just creating a full URL and then running it through this
+ * to strip off the protocol.
+ *
+ * Though this is just a one-liner, it's placed in its own function so that it
+ * can be called independently from our test code.
+ */
+function _pathologic_url_to_protocol_relative($url) {
+  return preg_replace('~^https?://~', '//', $url);
+}
diff --git a/web/modules/contrib/pathologic/pathologic.routing.yml b/web/modules/contrib/pathologic/pathologic.routing.yml
new file mode 100644 (file)
index 0000000..7339165
--- /dev/null
@@ -0,0 +1,7 @@
+pathologic.config_form:
+  path: 'admin/config/content/pathologic'
+  defaults:
+    _form: '\Drupal\pathologic\PathologicSettingsForm'
+    _title: 'Pathologic configuration'
+  requirements:
+    _permission: 'administer filters'
diff --git a/web/modules/contrib/pathologic/pathologic_test/pathologic_test.info.yml b/web/modules/contrib/pathologic/pathologic_test/pathologic_test.info.yml
new file mode 100755 (executable)
index 0000000..11ef1a0
--- /dev/null
@@ -0,0 +1,9 @@
+name: Pathologic Test
+description: Module which implements hook_pathologic_alter() for testing that functionality.
+core: 8.x
+package: Testing
+dependencies:
+- filter
+- pathologic
+type: module
+hidden: true
diff --git a/web/modules/contrib/pathologic/pathologic_test/pathologic_test.module b/web/modules/contrib/pathologic/pathologic_test/pathologic_test.module
new file mode 100644 (file)
index 0000000..32b5397
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * Implements hook_pathologic_alter(), for testing that functionality.
+ */
+function pathologic_test_pathologic_alter(&$url_params, $parts, $settings) {
+  if (is_array($parts['qparts']) && isset($parts['qparts']['test'])) {
+    if ($parts['qparts']['test'] === 'add_foo_qpart') {
+      // Add a "foo" query part
+      if (empty($url_params['options']['query'])) {
+        $url_params['options']['query'] = [];
+      }
+      $url_params['options']['query']['foo'] = 'bar';
+    }
+    elseif ($parts['qparts']['test'] === 'use_original') {
+      $url_params['options']['use_original'] = TRUE;
+    }
+  }
+}
diff --git a/web/modules/contrib/pathologic/src/PathologicSettingsCommon.php b/web/modules/contrib/pathologic/src/PathologicSettingsCommon.php
new file mode 100644 (file)
index 0000000..d279188
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\pathologic;
+
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+
+class PathologicSettingsCommon {
+
+  use StringTranslationTrait;
+
+  /**
+   * Common elements for the Pathologic configuration form.
+   *
+   * This reduces redundancy in code for form elements that will appear on both
+   * the global settings form and the per-format filter settings form.
+   *
+   * @param array $defaults
+   *   An array of default values for the configuration form fields.
+   * @return
+   *   The common form elements
+   */
+  public function commonSettingsForm(array $defaults) {
+    return [
+      'protocol_style' => [
+        '#type' => 'radios',
+        '#title' => $this->t('Processed URL format'),
+        '#default_value' => $defaults['protocol_style'],
+        '#options' => [
+          'full' => $this->t('Full URL (<code>http://example.com/foo/bar</code>)'),
+          'proto-rel' => $this->t('Protocol relative URL (<code>//example.com/foo/bar</code>)'),
+          'path' => $this->t('Path relative to server root (<code>/foo/bar</code>)'),
+        ],
+        '#description' => t('The <em>Full URL</em> option is best for stopping broken images and links in syndicated content (such as in RSS feeds), but will likely lead to problems if your site is accessible by both HTTP and HTTPS. Paths output with the <em>Protocol relative URL</em> option will avoid such problems, but feed readers and other software not using up-to-date standards may be confused by the paths. The <em>Path relative to server root</em> option will avoid problems with sites accessible by both HTTP and HTTPS with no compatibility concerns, but will absolutely not fix broken images and links in syndicated content.'),
+        '#weight' => 10,
+      ],
+      'local_paths' => [
+        '#type' => 'textarea',
+        '#title' =>  $this->t('All base paths for this site'),
+        '#default_value' => $defaults['local_paths'],
+          '#description' => $this->t('If this site is or was available at more than one base path or URL, enter them here, separated by line breaks. For example, if this site is live at <code>http://example.com/</code> but has a staging version at <code>http://dev.example.org/staging/</code>, you would enter both those URLs here. If confused, please read <a href=":docs" target="_blank">Pathologic&rsquo;s documentation</a> for more information about this option and what it affects.', [':docs' => 'https://www.drupal.org/node/257026']),
+        '#weight' => 20,
+      ],
+    ];
+  }
+  
+}
diff --git a/web/modules/contrib/pathologic/src/PathologicSettingsForm.php b/web/modules/contrib/pathologic/src/PathologicSettingsForm.php
new file mode 100644 (file)
index 0000000..a8fb169
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\pathologic;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\pathologic\PathologicSettingsCommon;
+
+class PathologicSettingsForm extends ConfigFormBase {
+  
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'pathologic_settings';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $config = $this->config('pathologic.settings');
+
+    $form['reminder'] = [
+      '#type' => 'markup',
+      '#markup' => '<p>' . $this->t('Reminder: The settings on this form only affect text formats for which Pathologic is configured to use the global Pathologic settings; if it&rsquo;s configured to use per-format settings, these settings will have no effect.') . '</p>',
+      '#weight' => 0,
+    ];
+    $defaults = [
+      'protocol_style' => $config->get('protocol_style'),
+      'local_paths' => $config->get('local_paths'),
+    ];
+
+    $common = new PathologicSettingsCommon();
+    $form += $common->commonSettingsForm($defaults);
+
+    return parent::buildForm($form, $form_state);       
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $this->config('pathologic.settings')
+      ->set('protocol_style', $form_state->getValue('protocol_style'))
+      ->set('local_paths', $form_state->getValue('local_paths'))
+      ->save();
+
+    parent::submitForm($form, $form_state);
+  }
+
+  /**
+   * @inheritdoc
+   */
+  protected function getEditableConfigNames() {
+    return [
+      'pathologic.settings',
+    ];
+  }
+
+}
diff --git a/web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php b/web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php
new file mode 100644 (file)
index 0000000..50b7162
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+
+namespace Drupal\pathologic\Plugin\Filter;
+
+use Drupal\filter\FilterProcessResult;
+use Drupal\filter\Plugin\FilterBase;
+use Drupal\Component\Utility\Crypt;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\pathologic\PathologicSettingsCommon;
+use Drupal\Core\Url;
+
+/**
+ * Attempts to correct broken paths in content.
+ *
+ * We give the filter a weight of 50 in the annotation below because in almost
+ * all cases Pathologic should be the last filter in the filter list. Is it
+ * possible to put a comment inside an annotation? Man, annotations are such a
+ * stupid idea.
+ *
+ * @Filter(
+ *   id = "filter_pathologic",
+ *   title = @Translation("Correct URLs with Pathologic"),
+ *   type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
+ *   settings = {
+ *     "settings_source" = "global",
+ *     "local_settings" = {
+ *       "protocol_style" = "full",
+ *       "local_paths" = ""
+ *     }
+ *   },
+ *   weight = 50
+ * )
+ */
+class FilterPathologic extends FilterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function settingsForm(array $form, FormStateInterface $form_state) {
+    $form['reminder'] = [
+      '#type' => 'markup',
+      '#markup' => $this->t('In most cases, Pathologic should be the <em>last</em> filter in the &ldquo;Filter processing order&rdquo; list.'),
+      '#weight' => 0,
+    ];
+    $form['settings_source'] = [
+      '#type' => 'radios',
+      '#title' => $this->t('Settings source'),
+      '#description' => $this->t('Select whether Pathologic should use the <a href=":config">global Pathologic settings</a> or custom &ldquo;local&rdquo; settings when filtering text in this text format.', [':config' => Url::fromRoute('pathologic.config_form')->toString()]),
+      '#weight' => 10,
+      '#default_value' => $this->settings['settings_source'],
+      '#options' => [
+        'global' => $this->t('Use global Pathologic settings'),
+        'local' => $this->t('Use custom settings for this text format'),
+      ],
+    ];
+    // Fields in fieldsets are… awkward to implement.
+    // @see https://www.drupal.org/node/2378437
+    $form['local_settings'] = [
+      '#type' => 'fieldset',
+      '#title' => $this->t('Custom settings for this text format'),
+      '#weight' => 20,
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
+      '#description' => $this->t('These settings are ignored if &ldquo;Use global Pathologic settings&rdquo; is selected above.'),
+      // @todo Fix the #states magic (or see if it's a core D8 bug)
+      '#states' => [
+        'visible' => [
+          ':input[name="filters[filter_pathologic][settings][settings_source]"]' => ['value' => 'local'],
+        ],
+      ],
+    ];
+
+    $common = new PathologicSettingsCommon();
+    $form['local_settings'] += $common->commonSettingsForm($this->settings['local_settings']);
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function process($text, $langcode) {
+    $settings = $this->settings;
+    if ($settings['settings_source'] === 'global') {
+      $config = \Drupal::config('pathologic.settings');
+      $settings['protocol_style'] = $config->get('protocol_style');
+      $settings['local_paths'] = $config->get('local_paths');
+    }
+    else {
+      $settings = $settings['local_settings'];
+    }
+    // @todo Move code from .module file to inside here.
+    return new FilterProcessResult(_pathologic_filter($text, $settings, Crypt::hashBase64(serialize($settings))));
+  }
+
+}
diff --git a/web/modules/contrib/pathologic/src/Tests/PathologicTest.php b/web/modules/contrib/pathologic/src/Tests/PathologicTest.php
new file mode 100644 (file)
index 0000000..519def8
--- /dev/null
@@ -0,0 +1,307 @@
+<?php
+
+namespace Drupal\pathologic\Tests;
+
+use Drupal\Component\Utility\SafeMarkup;
+use Drupal\simpletest\WebTestBase;
+use Drupal\pathologic\Plugin\Filter\FilterPathologic;
+use Drupal\Core\Language\Language;
+use Drupal\Core\Url;
+
+/**
+ * Tests Pathologic functionality.
+ *
+ * @group filter
+ */
+class PathologicTest extends WebTestBase {
+
+  public static $modules = ['filter', 'pathologic', 'pathologic_test'];
+
+  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 =[
+      'foo' => [
+        'path' => 'foo',
+        'opts' => []
+      ],
+      'foo/bar' => [
+        'path' => 'foo/bar',
+        'opts' => []
+      ],
+      'foo/bar?baz' => [
+        'path' => 'foo/bar',
+        'opts' => ['query' => ['baz' => NULL]]
+      ],
+      'foo/bar?baz=qux' => [
+        'path' => 'foo/bar',
+        'opts' => ['query' => ['baz' => 'qux']]
+      ],
+      'foo/bar#baz' => [
+        'path' => 'foo/bar',
+        'opts' => ['fragment' => 'baz'],
+      ],
+      'foo/bar?baz=qux&amp;quux=quuux#quuuux' => [
+        'path' => 'foo/bar',
+        'opts' => [
+          'query' => ['baz' => 'qux', 'quux' => 'quuux'],
+          'fragment' => 'quuuux',
+        ],
+      ],
+      'foo%20bar?baz=qux%26quux' => [
+        'path' => 'foo bar',
+        'opts' => [
+          'query' => ['baz' => 'qux&quux'],
+        ],
+      ],
+      '/' => [
+        'path' => '<front>',
+        'opts' => [],
+      ],
+    ];
+
+    foreach (['full', 'proto-rel', 'path'] as $protocol_style) {
+      $format_id = _pathologic_build_format(['settings_source' => 'local', 'local_settings' => ['protocol_style' => $protocol_style]]);
+      $paths = [];
+      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 = [
+        '@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', ['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', ['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', ['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', ['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'), ['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', ['absolute' => TRUE]) . '"><img src="' . _pathologic_content_url('bar.jpeg', ['absolute' => TRUE]) . '" longdesc="' . _pathologic_content_url('baz', ['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', ['absolute' => TRUE, 'query' => ['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', ['absolute' => TRUE])) . '" />',
+      t('Use global settings when so configured on the format')
+    );
+
+    // Test really broken URLs.
+    // @see https://www.drupal.org/node/2602312
+    $original = '<a href="/Epic:failure">foo</a>';
+    $message = t('Fails sensibly when \Drupal\Core\Url::fromUri() throws exception');
+    try {
+      $filtered = check_markup($original, $format_id);
+      $this->assertEqual(
+        $original,
+        $filtered,
+        $message
+      );
+    }
+    catch (\Exception $e) {
+      $this->fail($message);
+    }
+
+  }
+
+}
+
+/**
+ * Wrapper around url() which does HTML entity decoding and encoding.
+ *
+ * Since Pathologic works with paths in content, it needs to decode paths which
+ * have been HTML-encoded, and re-encode them when done. This is a wrapper
+ * around url() which does the same thing so that we can expect the results
+ * from it and from Pathologic to still match in our tests.
+ *
+ * @see url()
+ * @see http://drupal.org/node/1672932
+ * @see http://www.w3.org/TR/xhtml1/guidelines.html#C_12
+ */
+function _pathologic_content_url($path, $options) {
+  // If we should pretend this is a path to a file, make url() behave like clean
+  // URLs are enabled.
+  // @see _pathologic_replace()
+  // @see http://drupal.org/node/1672430
+  if (!empty($options['is_file'])) {
+    $options['script_path'] = '';
+  }
+
+  if (parse_url($path, PHP_URL_SCHEME) === NULL) {
+    if ($path == '<front>') {
+      return SafeMarkup::checkPlain(Url::fromRoute('<front>', [], $options)->toString());
+    }
+    $path = 'base://' . $path;
+  }
+  return SafeMarkup::checkPlain(Url::fromUri(htmlspecialchars_decode($path), $options)->toString());
+}
+
+
+/**
+ * Build a text format with Pathologic configured a certain way.
+ *
+ * @param $settings
+ *   An array of settings for the Pathologic instance on the format.
+ * @return
+ *   A format machine name (consisting of random characters) for the format.
+ */
+function _pathologic_build_format($settings) {
+  $format_id = user_password();
+  $format = entity_create('filter_format', [
+    'format' => $format_id,
+    'name' => $format_id,
+  ]);
+  $format->setFilterConfig('filter_pathologic', [
+    'status' => 1,
+    'settings' => $settings,
+  ]);
+  $format->save();
+  return $format_id;
+}
diff --git a/web/modules/contrib/pathologic/src/Tests/PathologicUITest.php b/web/modules/contrib/pathologic/src/Tests/PathologicUITest.php
new file mode 100644 (file)
index 0000000..bacabd5
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+namespace Drupal\pathologic\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests for the Pathologic UI.
+ *
+ * @group pathologic
+ */
+class PathologicUITest extends WebTestBase {
+
+  public static $modules = ['pathologic', 'node'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
+    $this->drupalLogin($this->drupalCreateUser(['administer filters', 'create page content']));
+  }
+
+  /**
+   * Tests for the Pathologic UI.
+   */
+  public function testPathologicUi() {
+    $this->doTestSettingsForm();
+    $this->doTestFormatsOptions();
+    $this->doTestFixUrl();
+  }
+
+  /**
+   * Test settings form.
+   */
+  public function doTestSettingsForm() {
+    $this->drupalGet('admin/config/content/pathologic');
+    $this->assertText('Pathologic configuration');
+
+    // Test submit form.
+    $this->assertNoFieldChecked('edit-protocol-style-proto-rel');
+    $edit = [
+      'protocol_style' => 'proto-rel',
+      'local_paths' => 'http://example.com/',
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+    $this->assertText('The configuration options have been saved.');
+    $this->assertFieldChecked('edit-protocol-style-proto-rel');
+    $this->assertText('http://example.com/');
+    $this->clickLink('Pathologic’s documentation');
+    $this->assertResponse(200);
+  }
+
+  /**
+   * Test text formats and editors options with pathologic.
+   */
+  public function doTestFormatsOptions() {
+
+    // Test plain text with pathologic configuration.
+    $this->drupalGet('/admin/config/content/formats/manage/plain_text');
+
+    // Select pathologic option.
+    $this->assertText('Correct URLs with Pathologic');
+    $this->assertNoFieldChecked('edit-filters-filter-pathologic-status');
+    $this->drupalPostForm(NULL, [
+      'filters[filter_html_escape][status]' => FALSE,
+      'filters[filter_pathologic][status]' => '1',
+    ], t('Save configuration'));
+
+    $this->drupalGet('/admin/config/content/formats/manage/plain_text');
+    $this->assertRaw('In most cases, Pathologic should be the <em>last</em> filter in the &ldquo;Filter processing order&rdquo; list.');
+    $this->assertText('Select whether Pathologic should use the global Pathologic settings');
+    $this->assertFieldChecked('edit-filters-filter-pathologic-status');
+    $this->drupalPostForm(NULL, [
+      'filters[filter_pathologic][settings][settings_source]' => 'local',
+      'filters[filter_pathologic][settings][local_settings][protocol_style]' => 'full',
+      ], t('Save configuration'));
+
+    $this->drupalGet('/admin/config/content/formats/manage/plain_text');
+    $this->assertFieldChecked('edit-filters-filter-pathologic-settings-settings-source-local');
+    $this->assertFieldChecked('edit-filters-filter-pathologic-settings-local-settings-protocol-style-full');
+    $this->assertText('Custom settings for this text format');
+  }
+
+  /**
+   * Test that a url is fixed with pathologic.
+   */
+  public function doTestFixUrl() {
+    $this->drupalGet('node/add/page');
+    $edit = [
+      'title[0][value]' => 'Test pathologic',
+      'body[0][value]' => '<a href="node/1">Test link</a>',
+    ];
+    $this->drupalPostForm('node/add/page', $edit, t('Save'));
+
+    // Assert that the link is processed with Pathologic.
+    $this->clickLink('Test link');
+    $this->assertTitle('Test pathologic | Drupal');
+  }
+
+}