Wraps all images in content with a

tag, ALT attribute is used to
set he caption text. If the ALT attribute is emmpty then the TITLE attribute
is used as a copy to ALT attribute and caption. If both attributes are empty
use a template string for caption with a sequential numbering. It does all
its work on the server.

Wrapping occurs prior Drupal renders the node content. Original content is
replaced with the new content only before rendering, thus the new content is
NOT saved anywhere. Ok, maybe in Drupals cached files but not anywhere else.

Works with CKEditor, Panels, Panels Everywhere. In CKEditor you just enter
the caption string in the text field "Alternative Text". In plain textarea add
attribute alt="Some description of my image.".
_._
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/MissterX/2319551.git img_capt
cd img_capt
_._
DrupalPractice: PAReview gives 34 WARNINGS which are false positives.
DrupalSecure: two (2) files (img_capt.module & img_capt.drush.inc) - how do I sanitaze base64_encoded string?

Comments

MissterX’s picture

Eh - maybe I should not have assigned this to myself? Bugger...

anil280988’s picture

Assigned: MissterX » Unassigned

Hi MissterX,

There is no need to assign it to anyone. Changing it to Unassigned.
As for the code, few changes are required

Line 3, file README.html
If your are the <a href="/admin/config/media/img_capt/admin">siteadmin, use this link.</a>
The link does not have the Base URL. So it will redirect on the 404 error page (see the screencast: screencast.com/t/nhnLhyDRD)

Line 252, file img_capt.module
Always use t() function for translation.

'#options' => array('TITLE' => 'TITLE', 'ALT' => 'ALT'),

should be

'#options' => array('TITLE' => t('TITLE'), 'ALT' => t('ALT')),

Multiple lines, file img_capt.module

if ($form_state['input']['op'] == t('New setting')) {

}

while comparing $form_state['values'] should be used as $form_state['input'] are raw and unvalidated.
Problem is $form_state['values'] ignores the default value. When the submission fails $form_state['values'] give the NULL value instead of the default value.

Line 3, file README.txt
Follows Guidelines content-wise although "About Image Caption & More" should be "Introduction". Also few Spelling errors are there.

luke_nuke’s picture

Status: Needs review » Needs work

Automated Review

For the beginning, you can addres the errors found by pareview.sh:

http://pareview.sh/pareview/httpgitdrupalorgsandboxmissterx2319551git

It found a lot of unused variables for example.

Manual Review

Individual user account
Yes: No clues that it would be a one of many accounts.
No duplication
Yes: I couldn't find any module that would be essentially the same.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Not sure yet: Are you an author of this "gears.png" graphic?
3rd party code
Yes: Follows the guidelines for 3rd party code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes. Didn't find anything.
Coding style & Drupal API usage
To say more, you need to clean up a code per pareview.sh suggestions where it's possible.

At the beginning of the img_capt_image_caption() function is this:

  $go_on = FALSE;
  if (($library = libraries_load('simple_html_dom')) && !empty($library['loaded'])) {
    $go_on = TRUE;
  }

  if (!$go_on) {
    drupal_set_message($library['error message'], 'error');
  }

But it doesn't stop the function from going on, you need to return something beyond setting a message.

Also, If you are using html docs with images, I would consider to put them all in /docs directory .

This review uses the Project Application Review Template.

MissterX’s picture

anil289888
Thanks for your time and your review.
The screencast link did not work :(

  • Fixed:
    • Base URL
    • t() (my bad - missed it)
    • $form_state['input']['op'] - my bad, forgot to change
    • spelling error
    • changed heading to "Introduction"

Luke_Nuke
Thanks for your time and your review.
I did a PAReview prior creating this issue, please read the last two
lines of description above. I'm especially interested in the last one
concerning security.

  • Fixed:
    • Coding style & Drupal API usage, oops - deleted by misstake :(
    • moved README.html to docs/
    • added paragraph "License of image gear.png" in README.txt
      the image is public domain
MissterX’s picture

Issue summary: View changes
MissterX’s picture

PAReview performed after cleanup

$form_state['input']

The first 10 warnings are concerning that $form_state['input'] is referenced in code. Usage of that piece of code are based on Form element #default_value and AJAX, it seams to behave the same in D8: Checkboxes default value is ignored by forms system during processing of AJAX request.

The code in this module does not utilize values in $form_state['input'], it merrily unsets the textfield value prior setting the value in correct manner via $form_state['values']['text-field-name']

WARNING | Unused variable ...

Four warnings, this warning is OK but it also is a false positive, it would be 100% OK if the values were mentioned only at lines 608 - 619 but they are filled with values at line 625. DrupalPractice sniffer is not expected to discover this, since line 625 could be a typing error which it is not in this case.

Drush command

Drush command drush img-capt is extended with the same functionality as the admin GUI:

  • Overview of all configurations
  • Show all settings in a specific configuration
  • Alter setting in a specific configuration, one by one
  • Create new configuration, when creating a new configuration which already exists all its settings are reset to default values.
  • Delete a specific configuration except the "Default" configuration

README.txt / README.html

Work in progress. Meanwhile drush help img-capt should describe most of the functionallity. The admin GUI should be selfexplained. Updated, now drush can "accept" negative argument.

Neither DrupalPractice sniffer nor the coder module reported anything for the other files.

rayzzz.com’s picture

Automated Review

So far fix all problems listed here http://pareview.sh/pareview/httpgitdrupalorgsandboxmissterx2319551git

Manual Review

Individual user account
Yes
No duplication
Yes
Master Branch
Yes
Licensing
YES
3rd party code
Yes
README.txt/README.md
Yes
Code long/complex enough for review
Yes
Secure code
Yes
Coding style & Drupal API usage
Everything seems to be OK, but you should fix all errors listed on http://pareview.sh/pareview/httpgitdrupalorgsandboxmissterx2319551git

MissterX’s picture

If anybody has info on how to fix the warnings, yes they are warnings and not errors, please post (link?). Meanwhile read post #6 above.

MissterX’s picture

Code changed by syggestion of IRC user ciss. Thank you!

Pareview gives

  • 0 warnings
  • 0 errors
  • 0 suggestion(s)
MissterX’s picture

Status: Needs work » Needs review

Code fixed, removed pareview warnings about false positives.

PA robot’s picture

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.

perennial.sky’s picture

Hello MIssterX,

I saw your code, just found some issue

1. Variable name always be meaningful, please change some variable name you are using variable name link $s, $c_t.

2. Don't use #prefix and #suffix for a whole form if you want a wrapper in some form element then use #container.

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...

3. Please use isset while taking data from any object or array,

if any node doesn't have anything in bode field then it will through an error

if ($setting['content_type'] == $node->type) {
$doc = $node->content['body'][0]['#markup'];
$node->content['body'][0]['#markup'] = img_capt_image_caption($doc, $node->type);
break;

4. please put module configuration link in module info file.

perennial.sky’s picture

Status: Needs review » Needs work
MissterX’s picture

Hello akashjain132,

Code is changed, I give you +karma for issue no 2.
Thanks!

MissterX’s picture

Status: Needs work » Needs review

See comment #12.

shaxa’s picture

1.
/**
* Implements hook_help_desc().
*/
function img_capt_help_desc() {

I don't think there is a hook_help_desc. So please add appropriate comments.

2.
$path = drupal_get_path('module', 'img_capt');
drupal_add_css($path . '/css/admin-page.css');
drupal_add_css($path . '/css/caption.css');
$help_file = file_get_contents(drupal_get_path('module', 'img_capt') . '/docs/README.html');

First you use $path then you call drupal_get_path again maybe you forgot it.

3. Think about setting the permission "img_capt" maybe in the install hook for administrators

4. In project issue and sandbox add info that there is "libraries" dependancy

5.
else {
$loaded_setting = '0';
}
if ($loaded_setting == '0') {
$loaded_setting = 'Default';
}
Why not else { $loaded_setting = 'Default'; don't loose bytes in such things

6. Do not use:
drupal_add_css($path . '/css/admin-page.css');
drupal_add_css($path . '/css/caption.css');

to add css or drupal_add_js to add js in forms because on submit you loose them and if you have an error you wont have styling so
better use $form['#attached']['css'] and $form['#attached']['js']

7. There is no such thing:

/**
* Implements hook_admin_validate().
*/

8. img_capt_admin_validate is only called by img_capt_ajax_load_setting so you dont need to repeat this:
if (!user_access('administer img_capt')) {
drupal_access_denied();
drupal_exit();
}

9. Consider passing your $form_state by reference on all form functions for proper function declaration.

These are the things i saw on first glance for the first 2-3 hundred rows so please check and fix them and then i can continue with review
if needed.

k_zoltan’s picture

Status: Needs review » Needs work

Based on @ShaxA review this module need some more love (work).

If you are still working on this module please perform the necesarry changes, othervise please help the webmasters work by closing this ticket.

PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

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