Imagelink add links to images automatic. For images without a link, this module will link the image to the original post.

Features:

  • Add <a>...</a> tags out of <img> tags automatic;
  • If a image already linked to somewhere, leave it;

Benefits:

  • If some one(people or robots) copied your posts or reproduced your posts, and your images are all with links, that will:
    • increase your website traffic when people click a image
    • help people and search engines find out the original posts
    • increase incoming links and raise ranks of your website
  • When some subscribed your feed, they can jump to the original post by just click an image, good for user experience;

Support paging mode when use Paging or other similar modules.

Project Page
http://drupal.org/sandbox/lugir/1274966

Git Repository

git clone http://git.drupal.org/sandbox/lugir/1274966.git imagelink

for Drupal 6

Comments

elc’s picture

Assigned: Unassigned » elc
Status: Needs review » Needs work

Greetings, sorry it has taken so long for someone to get to your application. There is a bit of a backlog.

Running module through Coder
Please run code through Coder set on minor and address any issues. It's mostly just spaces and comment blocks.
README.txt
needs to be fleshed out to explain about the module a bit more
See Best practices for creating and maintaining projects
.install file
  • missing any information in @file block
  • Function comments should be in PHPDoc/Doxygen style
  • Weight should be based off something rather than an arbitrarily large number. Are there any modules you know of that use hook_nodeapi('view',..) to alter links like this that you have to be after?
  • During uninstall, why are you changing the weight of the module? It should no longer be used at all and makes no difference to the running of the site.
  • no EOL character at end of file
  • should inform user that it has been installed/enabled since there is no other outwards indication that the module is enabled and working except for hunting down a previously unlinked image in their posts.
.module file
  • missing @file block
  • Why are you adding 'absolute' => TRUE to the URLs? This will interfere with sites which have already taken the time to deal with this themselves. Relative should work just fine.
git branching
Everything in master branch. This is will not allow releases to be created. When you believe you have a release ready; please branch to allow the creation of a release as per Release naming conventions
lugir’s picture

Status: Needs work » Needs review

Hi ELC

Thanks for your review

for your suggestions:

Running module through Coder
I did this and now the coder module said "No Problems Found"

REAMDE.txt
I read the README.txt file of admin_menu module, and use it as a template to improve mine.

.install file
Thanks for all your advises, 'paging' module create a $node->pages array to stored output content,
so i cant effected the output by changing $node->body.
i have updated my module, it don't need set weight for this module and .install file was removed.

.module file

  • Added infomation to @file block
  • Using absolute links is concidering that some rss readers will not convert links,
    if using relative links here, the links added by imagelink will be broken links

git branching
I created a release branching of this module named imagelink-6.x-1.0

Thanks again for all your advises :D

elc’s picture

Status: Needs review » Needs work
coder
you have to set it to "minor" to catch all the foibles .. it's in the settings once the page has come up telling you there are no errors.
git branching
master branch no longer in use? Don't forget to follow the cleanup step in step 5 of Moving from a master to a major version branch. I recommend against the "removing remote master" path, but instead just cleaning out the master and pointing people to the correct location in the README.txt file.
git branch naming
oops .. imagelink-6.x-1.0 isn't a release branch name! 6.x-1.x is, 6.x-1.0 is a release tag, "imagelink-6.x-1.0" is just branch with an unparseable name :(

haven't looked at the rest..

lugir’s picture

Status: Needs work » Needs review

Hi ELC

coder
I have run my code under the "minor" test of coder module, and fix all foibles.

git branch and branch name

  • Cleanup master branch by removed files from it. But don't understand what's "pointing people to the correct location in the README.txt file." mean
  • Changed branch name from imagelink-6.x-1.0 to 6.x-1.x, and add tag name 6.x-1.0 to it
klausi’s picture

Status: Needs review » Needs work
  • "// find all img tags in content": All comments should start capitalized and end with a "."
  • "foreach ($imgs as $key => $img) {": if you don't use $key remove it.
  • $imagelink = '<a href="' . $href . '" title="' . $node->title . '">' . $img . '</a>';: you need to sanitize the node title before you output it in the markup. Otherwise you are vulnerable to XSS, see http://drupal.org/node/28984
lugir’s picture

Status: Needs work » Needs review

Thanks Klausi

Updates:

  • All comments start capitalized and end with a "."
  • Removed unused variables
  • Pass plain-text output thought plain_text() function
elc’s picture

README.txt
In the master's version of README.txt, you would put some text telling people who download it what branches are available. It's only for people who pull your project via git instead of the releases.

I usually put something like ..


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Where is the module?                                                        +
+=============================================================================+

Since branching to support D6 and D7, the master branch that you are looking at
has been cleared of content to avoid old code being used.

If you did a full git clone, then you should have all the code hidden away in
two additional branches:

- 6.x-1.x
- 7.x.1.x

While "git branch" will only show locally tracked branches, in this case
master, the other branches are hidden in the .git repository.

Running "git branch -a" will show something like this:
* master
  remotes/origin/6.x-1.x
  remotes/origin/7.x-1.x
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

To checkout one of those branches so you can use the code, type:
git checkout -b 7.x-1.x remotes/origin/7.x-1.x

This created a local tracking branch called 7.x-1.x which tracks the remote
remotes/origin/7.x-1.x branch. You will also now have all the files to use the
git version of the module.

Have fun!

The README.txt file doesn't have an EOL character at the end of it.

All text files should end in a single newline (\n). This avoids the verbose "\ No newline at end of file" patch warning and makes patches easier to read since it's clearer what is being changed when lines are added to the end of a file.

(not a problem)
I had to go check what a plain_text() function was in the code - check_plain() is the actual function that you used (and the right one).
git tag
Also, now that you've done a few more commits, don't forget to move your tag (since no one has really used it) to the actual release planned release, or tag it with a new one. This is often why people do RC versions before finally committing to a release.
git commit comments
For the standard format, please see
Commit messages - providing history and credit.

I think we're at the end of finding any issues with this project. Since this is quite a simple module and you have a few other projects, I'd like to look through any appropriate ones too as this application queue is not only about making a single project good, but making all future full projects you wish to create in the future as good as they can be.

Are any of the following projects that you are thinking of releasing, or just sandbox play things that should be ignored?

lugir’s picture

Status: Needs review » Needs work

Hi ELC:
Projects in my sandbox are thinking of releasing, and i also have some modules didn't push to the repository which want to be released too, but considering I'm not familiar with the module release process and some code standards before, I have got a lot work to do before them can pass a review.

I think go through the entire module release process with this ImageLink module will be great helpful for all rest of my contributes, and thanks all of your kind helps.
Thanks

lugir’s picture

Status: Needs work » Needs review

Hi ELC:

Here is the updates:

  • Added a README.txt file in branch master to help people find the right place of ImageLink module.
  • Added EOL characters at the end of files.
  • Added a CHANGELOG.txt file to track module history
  • Moved git tag 6.x-1.0 to a recent release-ready commit

And thanks for your help, I have read Commit messages - providing history and credit and I committed it with improved commit messages :D.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Review of the 6.x-1.x branch:

  • Run coder to check your style, some issues were found (please check the Drupal coding standards):
    Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards
    
    sites/all/modules/pareview_temp/test_candidate/imagelink.module:
     +11: [minor] Comment should be read "Implements hook_foo()."
    
    Status Messages:
     Coder found 1 projects, 1 files, 1 minor warnings, 0 warnings were flagged to be ignored
    
  • ./imagelink.module: comment lines should break at 80 characters, see http://drupal.org/node/1354#general
          // If paging module is enabled, then working on $node->pages than $node->body.
            // Add absolute link to image (people will get a break link in some rss reader if use a relative link here).
              // else if 'paging' module is enable, add links to images in $node->pages
    

This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.

manual review:

  • "$imagelink = '<a href="' . $href . '" title="' . check_plain($node->title) . '">' . $img . '</a>';": you should use the l() function to create links.
  • "$replacement = '<a href="' . $href . '" title="' . check_plain($node->title) . '">$0</a>';": same here

But that are minor details, otherwise RTBC for me.

lugir’s picture

Status: Reviewed & tested by the community » Needs review

Hi Klausi:

Thanks for your review :D

  • Changed 'Implementation of hook_foo().' to 'Implements hook_nodeapi().'
  • Broke all comment lines under 80 characters
  • Updated some code, using l() function construct links. But the second one be used in preg_replace(), i'm not sure how to use l() function instead.
klausi’s picture

Status: Needs review » Needs work
  • why did you switch to react on node load and not on view? I think "view" is more correct as you only want to alter the data when it is displayed, not when it is loaded for some different purpose.
  • "'title' => check_plain($node->title),": no need to use check_plain() here, the l() function will use drupal_attributes() which will check_plain() all attributes anyway.
  • "'attribute' => array(" should be "'attributes' => array("
  • "$replacement = '<a href="' . $href . '" title="' . check_plain($node->title) . '">$0</a>';": why can't you use the l() function and pass $0 as the first text parameter?
lugir’s picture

Status: Needs work » Needs review
  • Changed add link action from 'node_load' stage back to 'node_view'.
  • Removed check_plain() which appeared in l() function.
  • Updated functions, use str_replace() instead.
doitDave’s picture

Status: Needs review » Needs work

Automated review (Please keep in mind that this is primarily a high level check that does not replace but, after all, eases the review process. There is no guarantee that no other issues could show up in a more in-depth manual follow-up review.)

Review of the 6.x-1.x branch:

  • Run coder to check your style, some issues were found (please check the Drupal coding standards):
    Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards
    
    sites/all/modules/pareview_temp/test_candidate/imagelink.module:
     +11: [minor] Comment should be read "Implements hook_foo()."
    
    Status Messages:
     Coder found 1 projects, 1 files, 1 minor warnings, 0 warnings were flagged to be ignored
    
  • Comments should be on a separate line before the code line, see http://drupal.org/node/1354#inline
    ./imagelink.module:51:    "(" .                     // Group 1 - Linked Images.
    ./imagelink.module:52:      "<a[^>]+>" .            // Start with <a>,
    ./imagelink.module:53:        "(?:(?!<\/a>).)*?" .  // Not </a> until ...
    ./imagelink.module:54:          "<img[^>]+>" .      // <img> tag,
    ./imagelink.module:55:        ".*?" .               // Any thing until ...
    ./imagelink.module:56:      "<\/a>" .               // </a>
    ./imagelink.module:57:    ")" .                     // Group 1 END.
    ./imagelink.module:59:    "|" .                     // OR
    ./imagelink.module:61:    "(" .                     // Group 2 - Unlinked Images.
    ./imagelink.module:62:      "<img[^>]+>" .          // <img> tag
    ./imagelink.module:63:    ")" .                     // Group 2 END.
    
  • All text files should end in a single newline (\n). See http://drupal.org/node/318#indenting
    
    

This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.

HTH, dave

lugir’s picture

Status: Needs work » Needs review

Oops, forgot run coder test again.

Fixed coder standard, but i can't find which file didn't end with a single line. I have ran PAReview.sh, and it just told "All text files should end in a single newline (\n). See http://drupal.org/node/318#indenting"

But which file?

doitDave’s picture

Status: Needs review » Needs work

Manual review:

  • Yes, you are right, there is no file. Overlooked that. There are weird results concerning newlines sometimes, no one yet figured out why. I propose that you carefully check by re-downloading a snapshot of your latest commit from the repo viewer and if there are single \n then it's ok (as for me).
  • Regarding your repo: There are several tags and D6 branches, I suggest cleaning all that up to avoid confusion (you will create tags later when releasing in the full project).
  • imagelink.install: I understand that you want your module to act later than some unspecified other module. What if, for any reason, some module installs itself with a weight of e.g. 6 and adds further images? The module weight thing is somehow tricky, so I personally would never use absolute values just out of guessing like "seems high enough", you know what I mean?

hth, dave

lugir’s picture

Status: Needs work » Needs review

Hi Dave

  • I did as you said, and that message still there.
  • Delete all tags and an unnecessary branch, now just branch master and 6.x-1.x and no tags.
  • You are right, set an absolute value is not a good way. I looked into source code of paging module, find out it create a intermediate array named $node->pages in node load stage, so any other changes made to $node->content['body']['#value'] in node view stage before it will be overrided. As far as I know, this behavior conflicts with ad module too, i think there are more modules got this conflict. This should be an issues of paging module, not imagelink, so I delete .install file in my module, and imagelink works well with other modules.

Thanks :)

doitDave’s picture

Status: Needs review » Needs work

Hi, I just updated my review environment and re-run it over your file. Only some small things showed:

Review of the 6.x-1.x branch:

  • Drupal Code Sniffer has found some code style issues (please check the Drupal coding standards):
    
    FILE: ...b/dp709/sites/all/modules/pareview_temp/test_candidate/imagelink.module
    --------------------------------------------------------------------------------
    FOUND 12 ERROR(S) AFFECTING 12 LINE(S)
    --------------------------------------------------------------------------------
     64 | ERROR | String concat is not required here; use a single string instead
     65 | ERROR | String concat is not required here; use a single string instead
     66 | ERROR | String concat is not required here; use a single string instead
     67 | ERROR | String concat is not required here; use a single string instead
     68 | ERROR | String concat is not required here; use a single string instead
     69 | ERROR | String concat is not required here; use a single string instead
     70 | ERROR | String concat is not required here; use a single string instead
     71 | ERROR | String concat is not required here; use a single string instead
     73 | ERROR | String concat is not required here; use a single string instead
     75 | ERROR | String concat is not required here; use a single string instead
     76 | ERROR | String concat is not required here; use a single string instead
     77 | ERROR | String concat is not required here; use a single string instead
    --------------------------------------------------------------------------------
    

This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.

HTH, dave

elc’s picture

This module used to be almost RTBC. Somehow it got complicated and very inefficient.

If you want to know if something as simple as "<img" is in the body, use strpos or stripos. These are much faster and use much less memory than preg_match_all for something so simple.

The pattern used for the second call should not be split over multiple lines and using double quotes. That's a double whammy and just insanely inefficient for something that will be called for every single node to be viewed. Think of views.

You're using url and l() together when a single call to l() would suffice. l() actually calls url itself. Using alias = TRUE means that it will only return "node/N" style links which isn't very good for SEO either (which seems to be a goal of the module).

Wowser. The number string replacements, regular expressions and string building used here is very large for this task.

I went a little nuts; here's your module re-written into a single function, with only one expensive function call. O(n) instead of O(5n). I'm sure the regex can be tweaked to make it only return the desired unlinked tags which would simplify the internal function to be without the condition.

function imagelink_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($op == 'view') {
    if (stripos($node->content['body']['#value'], '<img ') !== FALSE) {
      $node->content['body']['#value'] = preg_replace_callback(
        '/(<a[^>]+>(?:(?!<\/a>).)*?<img[^>]+>.*?<\/a>)|(<img[^>]+>)/si',
        create_function(
          '$matches',
          'if (isset($matches[2])) {
             return l($matches[2], \'node/' . $node->nid . '\', array(
               \'attributes\' => array(
                 \'title\' => \'' . $node->title . '\',
               ),
               \'html\' => TRUE,
               \'absolute\' => TRUE,
             ));
           }
           else {
             return $matches[0];
           }'
        ),
        $node->content['body']['#value']
      );
    }
  }
}

Hmm... I think I might have just negated the ability to review this module.

Update: didn't check stripos against !== FALSE.

lugir’s picture

Status: Needs work » Needs review

Hi:

  • I have run dos2unix for all files in this module, is this enough to turn "\r\n" to "\n"?
  • Using stripos() function to detect <img> tags
  • Using the internal function to add links to unlinked images which is provided by ELC. Thanks ELC.

Thanks

elc’s picture

The code I posted was actually a complete replacement for all the code in the module. It wasn't meant to be split into two different functions as it does all the checking in one go.

Also, in posting that I kinda removed anything I can review. I guess I recuse myself from being able to review this application. This module is also pretty small now which doesn't give much for anyone else to review in combination with me rewriting it.

How about changing this over to the http://drupal.org/sandbox/lugir/1170452 project? It looks like you've been following all the suggestions for this module over there (except for version branching .. there's code in the master and the 6.x-1.x branch is called 6.x-1.x-dev which is not a valid branch name for releases .. and having old code in the module commented out .. and setting variables in install instead of as default values, and not deleting variables the correct way .. and INSTALL file is missing .txt extension .. and the admin form should just use drupal_get_form instead of a wrapper function .. and .. well it would be easy to fix up ;) It's a much more substantial module.

lugir’s picture

Status: Needs review » Needs work

heh, I know Taobaoke module need more work to make it following the code standards. Thanks for all your help, I learned a lot of things about contribute to community from imagelink module. I'll improve my code (including Taobaoke module) with all these knowledge :)

ImageLink is a very small module, and for now, most of code in it was re-written by you, but I still want to know is it can be published as a full project? I mean it will help some people who need the ability provided by this module.

Beside this, I'll take your advise and spend more time on Taobaoke module.
Thanks :)

elc’s picture

There is a single project promote available which we're trying to use for useful projects which are quite small, or are features modules. That process would make this project a full project, but not provide the ability to promote other projects from sandbox to full projects. By the sounds of it, this seems very much like it would suit this module. You also then get the experience running a full project for the next app.

If I get a few spare moments, I could run through Taobaoke with a bit more of a fine tooth comb. I'm sure that one could be made ready to breeze through here with a few changes.

jthorson’s picture

Status: Needs work » Closed (duplicate)

It appears that there have been multiple project applications opened under your username:

Taobaoke: http://drupal.org/node/1176740
ImageLink: http://drupal.org/node/1275104
Comment Name: http://drupal.org/node/1242806

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, I have marked your secondary applications as 'closed(duplicate)', and left one application open (chosen at random).

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

Thanks in advance for your patience and understanding!

jthorson’s picture

Issue summary: View changes

Update description

avpaderno’s picture

Issue summary: View changes
Related issues: +#1176740: [D6] Taobaoke
avpaderno’s picture

Title: ImageLink » [D6] ImageLink
avpaderno’s picture

Assigned: elc » Unassigned