This module for D7.x gives you basic control over URL target attributes for text filters. The Target URL Filter Module is a simple light weight module based on the core filter_url function to add a URL filter with one of a selection of standard HTML target attributes.

There are more complex modules providing the ability to customize a variety of filters. These don't seem to control link attributes, however. There are also projects like External Links (https://drupal.org/project/extlink) that use JS to add indications to links if they are outside of the current domain. Target Filter URL is much simpler. Plus its functionality is derived through php, so there is no need to worry about javascript errors with infinite scrolls and ajax elements.

If you merely want the ability to control where links created by input filters will open, then this project is what you need. Say you want links that your users include in a text field to open in a _blank tab. This makes that happen. It does not differentiate between domestic URLs within the current domain and links to outside of the domain. Perhaps that is a feature that could be added in the future, but for now this fulfills a basic function providing more control over URLs.

Code-wise this project borrows from the native filter_url function to get things started. It adds a setting to select the target attribute from a list of provided standard HTML target attributes. It then validates this selection to be on the safe side. In the filter process callback _target_filter_url_process we call up a helper function before running preg_replace_callback where links are created. This helper function allows us to insert php keyword use () so that we can inject our variable for the target attribute into the preg_replace_callback, otherwise preg_replace_callback can only take the $match variable generated automatically by the native php function. Everything else is similar to the native filter function in Drupal 7.26 core. Since filter.module is in core, it didn't seem like a patch to the filter.module file would be a good idea even though it could achieve the same function. This project provides the function without touching core code.

Project Page: https://drupal.org/sandbox/jbranson/2195787

Git Clone: git clone --branch 7.x-1.0 http://git.drupal.org/sandbox/j.branson/2195787.git

Requirements
------------
Filter
You need to have the core filter module installed and enabled.
https://api.drupal.org/api/drupal/modules!filter!filter.module/7

Installation
------------
Follow the normal procedure to place the module folder and files in sites/all/modules and then enable through drush or the user interface.

Configuration
------------
With this filter enabled on a text format you should disable the core URL Filter for that format so as to avoid conflict. For more on configuring text formats: https://drupal.org/node/778976

Project Reviews
-------------
https://drupal.org/comment/8488883#comment-8488883
https://drupal.org/comment/8488809#comment-8488809
https://drupal.org/comment/8487823#comment-8487823
https://drupal.org/comment/8499149#comment-8499149
https://drupal.org/comment/8498941#comment-8498941

Comments

PA robot’s picture

Issue summary: View changes

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

chakrapani’s picture

Issue summary: View changes
Status: Needs review » Needs work

Manual review

j.branson’s picture

Status: Needs work » Needs review

Thanks chakrapani, I've made the changes you've noted. It all seems to be working pretty well now. The PAreview conflicts somewhat with the formatting that running 'drush coder-format /target_filter_url' has put in place, but the few remaining errors that it cites seem to be ok. PAreview also indicates that the options for standard html target attributes should be wrapped in t(). That wouldn't work, so I think those errors should fly. I was confused about the version/changelog/license issue, thanks for pointing that out.

Ready for review again!

j.branson’s picture

Category: Feature request » Task
j.branson’s picture

Issue summary: View changes
Issue tags: +PAreview: review bonus

Project Reviews Noted ...I've been building sites for 13 years, using drupal for over two years now and on D.O for a little less than two, but this is the first time I've spent the time to go through other people's code in this fashion and ask that other people go through my code, it's pretty awesome -- a global community in action. Thanks!

gobinathm’s picture

Status: Needs review » Needs work

Please include Git Clone URL in your project application
Please follow the Project Application check list to ensure all requirements are met : http://pareview.sh/pachecklist
Please follow Release naming conventions on your branches https://drupal.org/node/1015226
Pareview still pointing out some issue in module file please have them fixed. http://pareview.sh/pareview/httpgitdrupalorgsandboxjbranson2195787git

have this fixed so that others can go thru Manual review

j.branson’s picture

Issue summary: View changes
Status: Needs work » Needs review

The git clone is now included on the application page. Sorry about that.

I've gone through the PAreview again and fixed the indentations - which were originally auto-formatted by 'drush coder-format', so I think there may be some conflict there with PAreview. I realize this is odd because they run on the same code, but it's what happened. The remaining issues that it cites as far as code formatting I believe are irrelevant. I'm open to the argument that they are not irrelevant, but please let me explain what is happening and why I think it doesn't matter. Here's the PAreview (http://pareview.sh/pareview/httpgitdrupalorgsandboxjbranson2195787git-7x-10)

First) The t() on the options is not necessary in this case because they are standard html target attributes that do not need to run through a translate function, since they don't translate. I am concerned that running the values through translate would actually defeat the entire purpose of the project because it would mislead users as far as what attribute they are adding.

Second) I have no idea why it's kicking up :
FOUND 0 ERROR(S) AND 4 WARNING(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
1 | WARNING | Line exceeds 80 characters; contains 260 characters
3 | WARNING | Line exceeds 80 characters; contains 83 characters
13 | WARNING | Line exceeds 80 characters; contains 138 characters
17 | WARNING | Line exceeds 80 characters; contains 190 characters
There is no white space and the lines are 1, 3, 13 and 17 are short.

Third) For the "247 | ERROR | Space found before comma in function call 267 | ERROR | Space found before comma in function call 286 | ERROR | Space found before comma in function call" This was formatted by drush coder-format and I'm running a php keyword so I think the whole thing is just confusing. As far I can tell, the way I have it formatted meets coding standards. If anything, perhaps the $pattern variable before the callback should be on its own line, but then that means that the rest of the callback function would have to be further indented and PAreview told me to delete indentations. ...In fact, while writing this reply I just tested again with the $pattern variable on it's own line and everything indented accordingly and PAreview gives the same errors and says to change indentation back to fewer indentations. So I reverted back to the commit that I ran through the PAreview included above at the top of this reply. I think it's solid, but if someone knows how to format it better, I'm happy to change it according to your suggestion.

Fourth) PAreview is saying that a parameter mentioned in a comment needs to have a defined type, yet the type is defined in the rest of the comment below. That whole comment is copied from drupal core's filter module, so I doubt it is really a big issue. I can define the parameter type but then it is redundant with the rest of the comment below it...and it is a comment...

Finally, here's where there does seem to be a relevant issue. I've set the branch to 7.x-1.0, I had preferred the 7.x-1.x-dev branch before while I was testing the code, but I guess for release naming convention it should be 1.0. Either way PAreview says:

The following git branches do not match the release branch pattern, you should remove/rename them. See http://drupal.org/node/1015226
* 7.x-1.0
remotes/origin/7.x-1.0
remotes/origin/HEAD -> origin/7.x-1.0

I tried running git origin --delete remotes/origin/7.x-1.0 and it tells me that the reference doesn't exist. There is currently only one branch showing up on the project page and I know I have deleted everything else. Does this have to do with my local repo on my computer? That would be odd. Any pointers?

Thanks for the reviews! I look forward to getting this project up and running for anyone who might want to use it!

j.branson’s picture

Changing staus to needs review. Forgot that in above comment. Thanks again!

deepakaryan1988’s picture

I have gone through your project and found no bugs so far. It is very nice project.
And for this
Second) I have no idea why it's kicking up :
FOUND 0 ERROR(S) AND 4 WARNING(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
1 | WARNING | Line exceeds 80 characters; contains 260 characters
3 | WARNING | Line exceeds 80 characters; contains 83 characters
13 | WARNING | Line exceeds 80 characters; contains 138 characters
17 | WARNING | Line exceeds 80 characters; contains 190 characters
There is no white space and the lines are 1, 3, 13 and 17 are short.

You can short it by just hit enter and start on new line. I think it will fix your problem.

chakrapani’s picture

These warning are appearing because each of these lines are more than 80 chars. And yes hitting the enter and starting on new line will fix the issues.
For more details on Line length and wrapping please check: https://drupal.org/coding-standards#linelength

j.branson’s picture

Issue summary: View changes

I've updated the readme.txt file. Clearly you can tell how much I was paying attention....because when I wrote comment #7 and said I don't know why PAreview was kicking up those errors about line length I was looking at .module while PAreview was talking about readme.txt. Idiot's mistake. Thanks for your patience!

The only issue that I see currently is the continued message about branches: The following git branches do not match the release branch pattern, you should remove/rename them. See http://drupal.org/node/1015226
* 7.x-1.0
remotes/origin/7.x-1.0
remotes/origin/HEAD -> origin/7.x-1.0

I've removed the tracking via git branch -d -r origin/7.x-1.0 and deleted the branch both locally and on the drupal.org remote (added 7.x-1.x again as default then delete 7.x-1.0, then readded and deleted 1.x). I checked out a new 7.x-1.0 and pushed it without the -u in the git command so there is no tracking. All of that and I still get the message on the PAreview. I'm at a loss for what to do about this, but I also really don't see why it's an issue if the project page only registers one branch.

Status still set to needs review. Please let me know if there is anything else I should be doing to fix this or if things are good to go. Thanks again for the help.

draenen’s picture

Status: Needs review » Needs work

Manual review on http://simplytest.me works as described.

The only potential code issue I see is the use of anonymous functions for preg_replace_callback() on lines 248, 268, and 287 in target_filter_url.module. While Drupal 7 recommends at least php 5.3 it is not required (and some shared hosts are still running only php 5.2). Consider moving the callbacks to named functions.

j.branson’s picture

The issue is that the preg_replace_callback function only accepts one variable - the pattern match - so it seems like I have to make the function annonymous to get the attribute variable into the callback via the use keyword. Perhaps I'm mistaken though. Can the project page and documentation/readme.txt include a note that it requires 5.3+?

j.branson’s picture

Status: Needs work » Needs review

Added php version 5.3 added to info file. Per #13 above, I think this is the only way to go. Set to needs review. Thanks!

draenen’s picture

Status: Needs review » Reviewed & tested by the community

Cool, I think adding an explicit requirement for 5.3 solves the issue. Most D7 sites should be running 5.3 anyway. Marking this as RTBC.

j.branson’s picture

Issue summary: View changes

Thanks!

j.branson’s picture

Assigned: j.branson » Unassigned
klausi’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Project Application +PAreview: single application approval

It appears you are working in the "7.x-1.0" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
The following git branches do not match the release branch pattern, you should remove/rename them. See http://drupal.org/node/1015226

* 7.x-1.0
  remotes/origin/7.x-1.0
  remotes/origin/HEAD -> origin/7.x-1.0

manual review:

  1. the project page is a bit vague. What is the use case? Why would I like to set link target attributes automatically on all links? Also a list of similar modules and their differences is missing. See https://drupal.org/node/997024
  2. target_filter_url_validate_option(): why is that function needed? The Form API select box will only allow you to submit one out of the options, so this function can be removed?

Since most code is copied from core this project is too short to approve you as git vetted user. We are currently discussing how much code we need, but everything with less than 120 lines of code or less than 5 functions cannot be seriously reviewed. However, we can promote this single project manually to a full project for you.

Thanks for your contribution, j.branson!

I promoted this project manually for you: https://drupal.org/project/target_filter_url

Now that this experimental project has been promoted, you'll need to update the URL of your remote repository or reclone it.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

j.branson’s picture

Thanks Klausi for promoting my first project. I've made the changes you suggested to the project page and set up a stable release. I thought that the form api handled validating options, so I'm not sure why I had the validation redundancy, but it's gone now.

Too bad about full git access, but that makes sense. If I make significant changes to this project can I pick up this project application for further review and possible approval? Otherwise, I'll include a link to this project and the application page in the application of whatever module I submit next for approval. Thanks again!

PA robot’s picture

Status: Fixed » Closed (duplicate)
Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 1: https://drupal.org/node/2224147

Project 2: https://drupal.org/node/2196285

As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).

If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.

I'm a robot and this is an automated message from Project Applications Scraper.

avpaderno’s picture

Related issues: +#2224147: [D7] IMCE Rotate