Pathologic has hardcoded in a white-list of schemes to pass onto hook_pathologic_alter() functions. Problem is, if you want to use hook_pathologic_alter() to alter a link other than http, https, file, internal, currently that's not possible.
These can be found in pathologic.module line ~190 in `_pathologic_replace()`
$parts = parse_url($original_url);
// Do some more early tests to see if we should just give up now.
if (
// If parse_url() failed, give up.
$parts === FALSE ||
// If there's a scheme part and it doesn't look useful, bail out.
// "files" and "internal" are for Path Filter compatibility.
(isset($parts['scheme']) && !in_array($parts['scheme'], array('http', 'https', 'files', 'internal')))
) {
// Give up by "replacing" the original with the same.
return $matches[0];
}
My site heavily relies on UUIDs and I'd like to use them for links using a schema path. I know in the documentation you mention you don't like the use of things like internal: and such...but I personally do, so I'd like to use uuid:. Don't feel like writing an entire input filter, if I can continue to use pathologic to do it via hooks. Much easier for dev/administrative maintenance.
Problem is, when I use uuid:, pathologic won't pass on this schema to hook_pathologic_alter() since it's not whitelisted.
To change this, we can change the whitelist to be a variable_get() to provide more flexibility.
Would look something like this
$parts = parse_url($original_url);
// Do some more early tests to see if we should just give up now.
if (
// If parse_url() failed, give up.
$parts === FALSE ||
// If there's a scheme part and it doesn't look useful, bail out.
// "files" and "internal" are for Path Filter compatibility.
(isset($parts['scheme']) && !in_array($parts['scheme'], variable_get('pathologic_schema_whitelist', array('http', 'https', 'files', 'internal'))))
) {
// Give up by "replacing" the original with the same.
return $matches[0];
}
Included is a patch which is the same code. I've tried to reformat the code for readability & comments, while staying under 80 chars per line. Matter of taste, but take a look.
Comment | File | Size | Author |
---|---|---|---|
#4 | pathologic-configurable-schema-whitelist-1834308-4.patch | 763 bytes | j0rd |
#1 | pathologic-configurable-schema-whitelist-1834308-1.patch | 763 bytes | j0rd |
pathologic-configurable-schema-whitelist.patch | 1.04 KB | j0rd | |
Comments
Comment #1
j0rd CreditAttribution: j0rd commentedOoops. Looks like that first patch was created against 2.4 and not 2.6
Here's a patch for 2.6
Comment #2
Garrett Albright CreditAttribution: Garrett Albright commentedCould you elaborate on what a link with a "uuid" schema (or some other schema other than those four currently in the code) would look like? Does it eventually turn into a normal "http" schema?
I'm wondering on whether this is really a job for Pathologic, or if you'd be better served by having another filter which runs before which converts those paths to standard paths which then get run through Pathologic.
Comment #3
j0rd CreditAttribution: j0rd commented@Garrett my use case for UUID schema doesn't really matter, as that's my particular use case. Point of this patch is to allow the use of hook_pathologic_alter() to alter links of any kind of a site owners choosing. Currently it's hardcoded to 4 protocols, but it could be easily changed to allow the site developer to choose which protocols he's interested in. The end users of pathologic will not notice a difference, but will be provided with additional flexibility with the module.
hook_pathologic_alter is a great and easy entry point to alter the links on your site. Since I'm already using pathologic, I'd like to use this entry point to edit my links. I could create my own input filter, but seems like a better idea to use this hook.
my uuid links look like this uuid://node/72b833e4-2320-bb14-7d38-f9a998cecae2 or uuid://comment/598c7e22-2d5a-4f14-ddf5-1df60dfeb530 or uuid://file/10086ef9-21a8-ac84-e5eb-e0571d50fc74, which I then translate into url_aliases from their NIDs.
Essentially on my site, since I have a development / staging / production server, I can't rely on nid/cid/fid since those change between servers, thus I'm relying on UUIDs instead, which are common between all servers (and a shared apache solr server). There is a UUID link module, but I don't like it. I'd prefer to write my own with a pathologic extension as I use this quite heavily already.
http://drupal.org/project/uuid
Comment #4
j0rd CreditAttribution: j0rd commentedRe-ported patch to 2.10
Comment #5
Garrett Albright CreditAttribution: Garrett Albright commentedOkay, fair enough. I applied the patch, made some style tweaks, added a comment, and committed it. You should see it in the next dev release; please give it a try.
One thing to note is that I changed the variable name to "pathologic_scheme_whitelist" - not sure where you kept getting "schema" from.
Comment #6
j0rd CreditAttribution: j0rd commentedSuper, thanks a bunch. I'll be sure to update my code when I pull next release.