Closed (fixed)
Project:
Path Filter
Version:
6.x-2.0-beta3
Component:
Code
Priority:
Critical
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
31 May 2007 at 15:22 UTC
Updated:
31 Oct 2009 at 16:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
Dave Cohen commentedI had the same problem, and solved it slightly differently, before I saw your post here. I'm attaching my patch so the community can compare the approaches and maybe come up with the best possible.
If I understand your patch correctly, it will work only on nodes, while mine automatically converts URLs in any form. For example, when defining a block. My approach is rather simple, and does not distinguish between forms that actually use pathfilter and those that don't. Also, I don't convert the URLs back when editing a node the way your patch does.
Comment #2
harking commentedHi Dave,
If your patch works on all inputs it would probably be best to use that instead. For our installs we would need to convert the internal link back to the full path so that our WYSIWYG editor can handle the images/links correctly.
I'll have to play around with it some more.
Comment #3
alexanderpas commented+1 for this feature,
marking #283275: transparent link change into internal links. as duplicate
Comment #4
alexanderpas commentedthe following issue might be of infuence on this issue #127484: [Push #2] pathfilter for files directory
Comment #5
alexanderpas commentedif we go for an setting where it would work on all input's, we need a blacklist/whitelist where (not) to use it.
also #0, your code has something.com, please use example.com per http://drupal.org/coding-standards (Example URLs)
also #1 has a closing [code]?>[/code], please remove this, see http://drupal.org/coding-standards (PHP Code Tags)
Comment #6
harking commentedMy Patch has been updated to support the 6.x version of the module as of 3/9/2009.
@Alexander Pas: All cases of something.com have been replaced with example.com
@Dave Cohen: I had some time to look over your patch and it would also work well but would need a blacklist as Alex mentioned. I'm also concerned about the way the content is modified, but it looks like the only way to modify some of the forms is during the validation callback.
I was able to make a similar callback in D6 using $form_state['validate_handlers'][] = 'callback_function_name', in hook_form_alter of the module.
Thanks to the new filters ability for blocks in Drupal 6, `internal:` is now supported on blocks that select an input filter with PathFilter enabled. However, the auto-internalization of URLs does not occur in my patch since there is no easy way to get at the data before it is saved.
In addition, a bug was fixed in my patch that was only inserting `internal:` for one link per line.
After looking at #127484: [Push #2] pathfilter for files directory I think it should be able to merge into this fairly easily. We'll just check for `file:` replacements before `internal:` replacements as it is more specific.
Hopefully we can get some feedback from jbrown or RobRoy as to which patch they like more.
Comment #7
harking commentedComment #8
alexanderpas commented_normalize_and_internalizeand_internal_replacement_redo not have pathfilter prefix.also, you might want to think about the function names....
function_does_this_and_thatshould preferably be split intofunction_does_thisandfunction_does_thatBTW, i think #127484: [Push #2] pathfilter for files directory should go in first.
Comment #9
alexanderpas commented#402296: Call for Action: Get Pathfilter Additional Functionality in before D7 makes pathfilter obsolete (Pathfilter in Core???)
Comment #10
mrfelton commentedSo, I took the patch at #6 and updated it to work with the latest CVS. I had to make some changes in order to get it to work correctly (or at least, to make it do what my understanding of this patch is). For a start, I added support for translating to and from 'files:' style paths (#127484: [Push #2] pathfilter for files directory). Secondly, I use drupal_get_normal_path(), in order to ensure that the path that gets re-saved to the node uses the system path where possible, and not a path alias, since that is kinda the whole point of this module.
Now, I'm not sure why the original patch included class.pathparser.php - I think I managed to do just fine with PHP's native parse_url() function - correct me if I'm wrong.
Personally I don't really like the way this patch works (any of the versions on this thread) as they seem to a lot of unnecessary work. This version runs on every single property of a node - why? The input filter isn't set to run on every node property... The version at #1 runs for every single form textarea field! It just doesn't seem right somehow. I know there was talk about a whitelist/blacklist type functionally, and I think that is certainly a must if a patch more like the one at #1 is to be used.
I think we need to remember, Path Filter is an input filter - that is to say that users choose where they want this functionality to be performed and where they do not. None of these variations seem to respect that, but that is not to say that this module should not be performing more functionality than that of a simple input filter. Is the purpose of this module to provide a sitewide mechanism for entering internal links? Or, is to provide an input filter? or, is it/can it be/should it be both, or a combination of the two?
As I understood it, the original reason for this patch was to ensure that WYSIWYG text editors can work in harmony with the input filter...
ps. my patch is very very untested - actually, I literally only tested it with the following paths:
EDIT: Sorry, got those examples the wrong way round... 'internal:node/[nid]' translates to http://www.example.com/content/page1 on editing, and back again on saving etc.
Comment #11
harking commented@mrfelton
We've update our patch. This is the version that is currently used in about 20 development and 7 production Drupal 6 sites.
The class.pathparser.php was unneeded and caused more problems than it was solving (was only there to remove extra slashes in a URL), so we removed it.
The new patch only modifies teaser, node body, or any fields with "format" set. It still does not run with block fields, due to not being able to hook in on save of a block.
The original reason for the patch was to allow users to only have to worry about getting the URL correct, and not have the extra burden of "internal:"izing their URLs so to not break when the site moved locations.
We should probably update our patch to work with the "files:" as you have and also update it for the latest development version.
Comment #12
mrfelton commented@harking: Thanks for posting this. However, there are quite a few major changes in the way the latest -dev version works (for both Drupal 5 and 6) so an update of this patch is a must before this can be considered for inclusion. Not only has the files: syntax been introduced, but preg_replace is no longer used as the means for performing the replacement, preg_replace_callback() is used instead as it is a) faster, and b) more flexible.
I also really think you need to look at using drupal_get_normal_path() when you are internalizing urls in order to be sure you are storing the actual internal path, and not a path alias (check my version of the patch).
EDIT: Also, you really shouldn't use a function name like _replace_links - you need to work within the pathfilter namespace, so that should be _pathfilter_replace_links()
Comment #13
harking commentedI'll look at updating our patch for the 2.0 beta release.
Comment #14
harking commentedI've updated the patch for 2.0-beta1,
Hopefully it will make it into 2.0 final. A very fun module to work on, I see it going into core in the future. :)
Comment #15
harking commentedComment #16
harking commentedComment #17
harking commentedI've updated the patch to include a snippet in the README about the new feature and where it can be enabled/disabled.
Comment #18
adavis.co.uk commentedIt would be great if this module could also handle file paths embedded in CSS style statements i.e. background-image:url(internal:/sites/default/files/images/homepage_1100.jpg)
Comment #19
mrfelton commented@adavis.co.uk: Please create a seperate ticket for your feature request. It has nothing todo with this ticket.
Comment #20
adavis.co.uk commentedIt would be great if this module could also handle file paths embedded in CSS style statements i.e. background-image:url(internal:/sites/default/files/images/homepage_1100.jpg)
Comment #21
harking commented@adavis.co.uk : Please don't just change the title.
I've made a new issue from your request. See #592628: Path Filter to handle style file references
Comment #22
mrfelton commentedI think I found a problem with this.
1. Create the following node
2. Save and view the node. Note that the link is to the nodes alias (/test-node in my case). Fine.
3. Look in the node_revisions table of your database and notice that it's been saved as internal:node/176. Fine.
4. Edit the node again - note that the link is now showing as a full, absolute url to the. Again, this is expected right?
5. But, now, save the node again (don't make any changes)
6. View the node and note that it's still linking to the node by its path alias, /test-node.
7. However, look in the database and you'll see that this time it's been saved as 'internal:test-node' - we have now lost the original link, which used the node id - the main purpose of the module!
It should always save the node in the format 'internal:node/[nid]' - and not the alias to the node. Otherwise, if the alias to the node changes, the link will be broken.
Comment #23
mrfelton commentedComment #24
harking commentedExcellent catch. I'll get it updated to always use the node format if available.
Comment #25
harking commented@mrfelton
I've updated the patch so that if a node with an alias is entered, when rendered it will be aliased. When the node is then loaded back again to be edited, the original non-alias is kept.
Example:
1. Create new node with a link to another page on the site which has an alias such as 'internal:node/3'
2. Save the page and view it. Link should now point to '/path_to_site/alias_to_node_3'
3. Edit the new node again. Text still contains link to node id '/path_to_site/node/3' as expected. The 'internal:' has been replaced so to allow WYSIWYG editor to edit page, and not require user to know where to insert 'internal:'.
4. Upon save again, Link still points to '/path_to_site/alias_node_3/' as expected.
To do this I've modified the currying calls to accept a second parameter so that I could get some DRY on in the _pathfilter_process_internal() function. It now accepts another parameter that determines whether the alias will be used for node/# when replacing.
Finally, I've cleaned up the formatting to two space indents to go along with the Drupal coding standards.
Comment #26
mrfelton commentedI've commited this to CVS now and will release a new beta shortly.
Comment #27
mrfelton commentedMarked #109992: Replace regular internal paths with URL aliases as a duplicate.
Comment #28
hass commentedDoes this filter change user entered code on submit? I was told Drupal doesn't change on input and only on output... only to make sure content is saved as entered. Sounds like you solved #517174: Auto-update could prefix urls and integrate with other modules?
Comment #29
mrfelton commentedIf you have the 'Enable automatic url processing for attributes' checkbox ticked in the input filters configuration page (new in 6.x-2.x), then it does alter user entered code on submit. In this case, it will transform links into the internal: on submit, thus taking the job of adding internal: away from the user. Upon editing the node again, all internal: links are changed back to absolute paths/urls to ensure that WYSIWYG editors work correctly with any referenced nodes/files, and on submit they are once again converted to internal: links.
Comment #30
mrfelton commented@hass: I'm not really sure I understand the problem being described at #517174: Auto-update could prefix urls and integrate with other modules
Comment #31
hass commented#517174: Was the idea to build this feature for pathologic and pathfilter... :-). If linkchecker updates broken links with 301 urls it saves the nodes. Than your filter need to hook in between and change from "base path/path" to "internal:path". I hope this works now...
The pathologic maintainer don't liked to implement such a conversion filter on save... for the reason that this is not a Drupal way.